settings: undefined,\r
plugins: undefined,\r
utils: undefined, // TODO: Re-usable methods\r
- gateway: undefined, // TODO: Access to gateway\r
user: undefined, // TODO: Limited user methods\r
server: undefined, // TODO: Limited server methods\r
- command: undefined, // The control box\r
\r
// TODO: think of a better term for this as it will also refer to queries\r
channels: undefined, // TODO: Limited access to panels list\r
\r
+ // Event managers for plugins\r
+ components: {\r
+ EventComponent: function(event_source) {\r
+ function proxyEvent(event_name, event_data) {\r
+ this.trigger(event_name, event_data);\r
+ }\r
+\r
+ _.extend(this, Backbone.Events);\r
+\r
+ // Proxy the events to this dispatcher\r
+ event_source.on('all', proxyEvent, this);\r
+\r
+ // Clean up this object\r
+ this.dispose = function () {\r
+ event_source.off('all', proxyEvent);\r
+ this.off();\r
+ };\r
+ },\r
+\r
+ Irc: function() {\r
+ var obj = new this.EventComponent(_kiwi.gateway);\r
+ var funcs = {\r
+ kiwi: 'kiwi', raw: 'raw', kick: 'kick', topic: 'topic',\r
+ part: 'part', join: 'join', action: 'action', ctcp: 'ctcp',\r
+ notice: 'notice', msg: 'privmsg'\r
+ };\r
+\r
+ _.each(funcs, function(gateway_fn, func_name) {\r
+ obj[func_name] = _kiwi.gateway[gateway_fn];\r
+ });\r
+\r
+ return obj;\r
+ },\r
+ ControlInput: function() {\r
+ var obj = new this.EventComponent(_kiwi.app.controlbox);\r
+ var funcs = {\r
+ processInput: 'run'\r
+ };\r
+\r
+ _.each(funcs, function(controlbox_fn, func_name) {\r
+ obj[func_name] = _kiwi.app.controlbox[controlbox_fn];\r
+ });\r
+\r
+ return obj;\r
+ }\r
+ },\r
+\r
// Entry point to start the kiwi application\r
start: function (opts) {\r
opts = opts || {};\r
\r
\r
this.initializeGlobals = function () {\r
- _kiwi.global.control = this.controlbox;\r
- _kiwi.global.gateway = _kiwi.gateway;\r
_kiwi.global.panels = this.panels;\r
\r
- _kiwi.global.components = {\r
- Applet: _kiwi.model.Applet,\r
- Panel: _kiwi.model.Panel\r
- };\r
+ _kiwi.global.components.Applet = _kiwi.model.Applet;\r
+ _kiwi.global.components.Panel =_kiwi.model.Panel;\r
};\r
\r
\r
\r
// For ease of access. The socket.io object\r
this.socket = this.get('socket');\r
+\r
+ this.applyEventHandlers();\r
};\r
\r
\r
+ this.applyEventHandlers = function () {\r
+ /*\r
+ TODO: Impliment event 'groups' to remove a listener group\r
+ kiwi.gateway.on('msg:#channel', my_function);\r
+ kiwi.gateway.on('msg:somenick', my_function);\r
+\r
+ kiwi.gateway.on('notice:#channel', my_function);\r
+ kiwi.gateway.on('action:somenick', my_function);\r
+\r
+ kiwi.gateway.on('join:#channel', my_function);\r
+ kiwi.gateway.on('part:#channel', my_function);\r
+ kiwi.gateway.on('quit', my_function);\r
+ */\r
+ var that = this;\r
+ \r
+ // Some easier handler events\r
+ this.on('onmsg', function (event) {\r
+ var source,\r
+ is_pm = (event.channel == that.get('nick'));\r
+\r
+ source = is_pm ? event.nick : event.channel;\r
+ \r
+ that.trigger('msg:' + source, event);\r
+\r
+ if (is_pm) {\r
+ that.trigger('pm', event);\r
+ that.trigger('pm:' + source, event);\r
+ }\r
+ }, this);\r
+\r
+\r
+ this.on('onnotice', function (event) {\r
+ // The notice towards a channel or a query window?\r
+ var source = event.target || event.nick;\r
+\r
+ this.trigger('notice', event);\r
+ this.trigger('notice:' + source, event);\r
+ }, this);\r
+\r
+\r
+ this.on('onaction', function (event) {\r
+ var source,\r
+ is_pm = (event.channel == that.get('nick'));\r
+\r
+ source = is_pm ? event.nick : event.channel;\r
+ \r
+ that.trigger('action:' + source, event);\r
+\r
+ if (is_pm) {\r
+ that.trigger('action', event);\r
+ that.trigger('action:' + source, event);\r
+ }\r
+ }, this);\r
+\r
+\r
+ this.on('ontopic', function (event) {\r
+ that.trigger('topic', event);\r
+ that.trigger('topic:' + event.channel, event);\r
+ });\r
+ };\r
+\r
+\r
+\r
/**\r
* Connects to the server\r
* @param {String} host The hostname or IP address of the IRC server to connect to\r