From 765905f5b8bea25358ab0e2eb6f1cafbebc98707 Mon Sep 17 00:00:00 2001 From: Giovanni Campagna Date: Tue, 2 Aug 2011 23:33:25 +0200 Subject: [PATCH] gajim: port to new extension API main() has been replaced by init(), enable() and disable() when disabling, all sources and notifications associated with gajim contacts are automatically closed --- extensions/gajim/extension.js | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/extensions/gajim/extension.js b/extensions/gajim/extension.js index 9f97e9a6..3b5e6988 100644 --- a/extensions/gajim/extension.js +++ b/extensions/gajim/extension.js @@ -263,17 +263,33 @@ function GajimClient() { GajimClient.prototype = { _init: function() { this._sources = {}; - this._cacheDir = GLib.get_user_cache_dir() + '/gnome-shell/gajim-avatars'; - GLib.mkdir_with_parents(this._cacheDir, 0x1c0); // 0x1c0 = octal 0700 - - this._proxy = new Gajim(DBus.session, 'org.gajim.dbus', '/org/gajim/dbus/RemoteObject'); - this._proxy.connect('NewMessage', Lang.bind(this, this._messageReceived)); }, proxy : function() { return this._proxy; }, + enable: function() { + this._cacheDir = GLib.get_user_cache_dir() + '/gnome-shell/gajim-avatars'; + GLib.mkdir_with_parents(this._cacheDir, 0x1c0); // 0x1c0 = octal 0700 + + this._proxy = new Gajim(DBus.session, 'org.gajim.dbus', '/org/gajim/dbus/RemoteObject'); + this._newMessageId = this._proxy.connect('NewMessage', Lang.bind(this, this._messageReceived)); + }, + + disable: function() { + if (this._newMessageId) { + this._proxy.disconnect(this._newMessageId); + this._newMessageId = 0; + } + this._proxy = null; + + for (let id in this._sources) + this._sources[id].destroy(); + + this._sources = { }; + }, + _messageReceived : function(emitter, data) { let author = data[1][0]; let message = data[1][1]; @@ -308,6 +324,6 @@ GajimClient.prototype = { }; -function main() { - let client = new GajimClient(); +function init() { + return new GajimClient(); }