plugin installer can reload itself
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
[info]
|
[info]
|
||||||
name: Plugin Installer
|
name: Plugin Installer
|
||||||
short_name: plugin_installer
|
short_name: plugin_installer
|
||||||
version: 0.10.2
|
version: 0.10.3
|
||||||
description: Install and upgrade plugins from ftp
|
description: Install and upgrade plugins from ftp
|
||||||
authors: Denis Fomin <fominde@gmail.com>
|
authors: Denis Fomin <fominde@gmail.com>
|
||||||
Yann Leboulanger <asterix@lagaule.org>
|
Yann Leboulanger <asterix@lagaule.org>
|
||||||
|
|||||||
@@ -68,6 +68,8 @@ class PluginInstaller(GajimPlugin):
|
|||||||
self.progressbar = None
|
self.progressbar = None
|
||||||
self.available_plugins_model = None
|
self.available_plugins_model = None
|
||||||
self.upgrading = False # True when opened from upgrade popup dialog
|
self.upgrading = False # True when opened from upgrade popup dialog
|
||||||
|
self.timeout_id = 0
|
||||||
|
self.connected_ids = {}
|
||||||
icon = gtk.Image()
|
icon = gtk.Image()
|
||||||
self.def_icon = icon.render_icon(gtk.STOCK_PREFERENCES,
|
self.def_icon = icon.render_icon(gtk.STOCK_PREFERENCES,
|
||||||
gtk.ICON_SIZE_MENU)
|
gtk.ICON_SIZE_MENU)
|
||||||
@@ -80,7 +82,7 @@ class PluginInstaller(GajimPlugin):
|
|||||||
if 'plugins' in gajim.interface.instances:
|
if 'plugins' in gajim.interface.instances:
|
||||||
self.on_activate(None)
|
self.on_activate(None)
|
||||||
if self.config['check_update']:
|
if self.config['check_update']:
|
||||||
gobject.timeout_add_seconds(30, self.check_update)
|
self.timeout_id = gobject.timeout_add_seconds(30, self.check_update)
|
||||||
|
|
||||||
@log_calls('PluginInstallerPlugin')
|
@log_calls('PluginInstallerPlugin')
|
||||||
def warn_update(self, plugins):
|
def warn_update(self, plugins):
|
||||||
@@ -132,6 +134,7 @@ class PluginInstaller(GajimPlugin):
|
|||||||
ftp = Ftp(self)
|
ftp = Ftp(self)
|
||||||
ftp.run = _run
|
ftp.run = _run
|
||||||
ftp.start()
|
ftp.start()
|
||||||
|
self.timeout_id = 0
|
||||||
|
|
||||||
@log_calls('PluginInstallerPlugin')
|
@log_calls('PluginInstallerPlugin')
|
||||||
def deactivate(self):
|
def deactivate(self):
|
||||||
@@ -139,9 +142,14 @@ class PluginInstaller(GajimPlugin):
|
|||||||
if hasattr(self, 'page_num'):
|
if hasattr(self, 'page_num'):
|
||||||
self.notebook.remove_page(self.page_num)
|
self.notebook.remove_page(self.page_num)
|
||||||
self.notebook.set_current_page(0)
|
self.notebook.set_current_page(0)
|
||||||
|
for id_, widget in self.connected_ids.items():
|
||||||
|
widget.disconnect(id_)
|
||||||
del self.page_num
|
del self.page_num
|
||||||
if hasattr(self, 'ftp'):
|
if hasattr(self, 'ftp'):
|
||||||
del self.ftp
|
del self.ftp
|
||||||
|
if self.timeout_id > 0:
|
||||||
|
gobject.source_remove(self.timeout_id)
|
||||||
|
self.timeout_id = 0
|
||||||
|
|
||||||
def on_activate(self, widget):
|
def on_activate(self, widget):
|
||||||
if 'plugins' not in gajim.interface.instances:
|
if 'plugins' not in gajim.interface.instances:
|
||||||
@@ -152,10 +160,11 @@ class PluginInstaller(GajimPlugin):
|
|||||||
self.installed_plugins_model = gajim.interface.instances[
|
self.installed_plugins_model = gajim.interface.instances[
|
||||||
'plugins'].installed_plugins_model
|
'plugins'].installed_plugins_model
|
||||||
self.notebook = gajim.interface.instances['plugins'].plugins_notebook
|
self.notebook = gajim.interface.instances['plugins'].plugins_notebook
|
||||||
self.id_n = self.notebook.connect('switch-page',
|
id_ = self.notebook.connect('switch-page', self.on_notebook_switch_page)
|
||||||
self.on_notebook_switch_page)
|
self.connected_ids[id_] = self.notebook
|
||||||
self.window = gajim.interface.instances['plugins'].window
|
self.window = gajim.interface.instances['plugins'].window
|
||||||
self.window.connect('destroy', self.on_win_destroy)
|
id_ = self.window.connect('destroy', self.on_win_destroy)
|
||||||
|
self.connected_ids[id_] = self.window
|
||||||
self.GTK_BUILDER_FILE_PATH = self.local_file_path('config_dialog.ui')
|
self.GTK_BUILDER_FILE_PATH = self.local_file_path('config_dialog.ui')
|
||||||
self.xml = gtk.Builder()
|
self.xml = gtk.Builder()
|
||||||
self.xml.set_translation_domain('gajim_plugins')
|
self.xml.set_translation_domain('gajim_plugins')
|
||||||
@@ -216,8 +225,11 @@ class PluginInstaller(GajimPlugin):
|
|||||||
gobject.signal_new('plugin_downloaded', self.window,
|
gobject.signal_new('plugin_downloaded', self.window,
|
||||||
gobject.SIGNAL_RUN_LAST, gobject.TYPE_STRING,
|
gobject.SIGNAL_RUN_LAST, gobject.TYPE_STRING,
|
||||||
(gobject.TYPE_PYOBJECT,))
|
(gobject.TYPE_PYOBJECT,))
|
||||||
self.window.connect('error_signal', self.on_some_ftp_error)
|
id_ = self.window.connect('error_signal', self.on_some_ftp_error)
|
||||||
self.window.connect('plugin_downloaded', self.on_plugin_downloaded)
|
self.connected_ids[id_] = self.window
|
||||||
|
id_ = self.window.connect('plugin_downloaded',
|
||||||
|
self.on_plugin_downloaded)
|
||||||
|
self.connected_ids[id_] = self.window
|
||||||
|
|
||||||
selection = self.available_treeview.get_selection()
|
selection = self.available_treeview.get_selection()
|
||||||
selection.connect('changed',
|
selection.connect('changed',
|
||||||
@@ -273,13 +285,18 @@ class PluginInstaller(GajimPlugin):
|
|||||||
WarningDialog(_('Ftp error'), error_text, self.window)
|
WarningDialog(_('Ftp error'), error_text, self.window)
|
||||||
|
|
||||||
def on_plugin_downloaded(self, widget, plugin_dirs):
|
def on_plugin_downloaded(self, widget, plugin_dirs):
|
||||||
|
dialog = HigDialog(None, gtk.MESSAGE_INFO, gtk.BUTTONS_OK,
|
||||||
|
'', _('All selected plugins downloaded'))
|
||||||
|
dialog.set_modal(False)
|
||||||
|
dialog.set_transient_for(self.window)
|
||||||
|
|
||||||
for _dir in plugin_dirs:
|
for _dir in plugin_dirs:
|
||||||
is_active = False
|
is_active = False
|
||||||
plugins = None
|
plugins = None
|
||||||
plugin_dir = os.path.join(gajim.PLUGINS_DIRS[1], _dir)
|
plugin_dir = os.path.join(gajim.PLUGINS_DIRS[1], _dir)
|
||||||
plugin = gajim.plugin_manager.get_plugin_by_path(plugin_dir)
|
plugin = gajim.plugin_manager.get_plugin_by_path(plugin_dir)
|
||||||
if plugin:
|
if plugin:
|
||||||
if plugin.active and plugin.name != self.name:
|
if plugin.active:
|
||||||
is_active = True
|
is_active = True
|
||||||
gobject.idle_add(gajim.plugin_manager.deactivate_plugin,
|
gobject.idle_add(gajim.plugin_manager.deactivate_plugin,
|
||||||
plugin)
|
plugin)
|
||||||
@@ -301,30 +318,23 @@ class PluginInstaller(GajimPlugin):
|
|||||||
self.available_plugins_model[row][C_LOCAL_VERSION] = \
|
self.available_plugins_model[row][C_LOCAL_VERSION] = \
|
||||||
plugin.version
|
plugin.version
|
||||||
self.available_plugins_model[row][C_UPGRADE] = False
|
self.available_plugins_model[row][C_UPGRADE] = False
|
||||||
if is_active and plugin.name != self.name:
|
if is_active:
|
||||||
gobject.idle_add(gajim.plugin_manager.activate_plugin, plugin)
|
gobject.idle_add(gajim.plugin_manager.activate_plugin, plugin)
|
||||||
if plugin.name != 'Plugin Installer':
|
# get plugin icon
|
||||||
# get plugin icon
|
icon_file = os.path.join(plugin.__path__, os.path.split(
|
||||||
icon_file = os.path.join(plugin.__path__, os.path.split(
|
plugin.__path__)[1]) + '.png'
|
||||||
plugin.__path__)[1]) + '.png'
|
icon = self.def_icon
|
||||||
icon = self.def_icon
|
if os.path.isfile(icon_file):
|
||||||
if os.path.isfile(icon_file):
|
icon = gtk.gdk.pixbuf_new_from_file_at_size(icon_file, 16, 16)
|
||||||
icon = gtk.gdk.pixbuf_new_from_file_at_size(icon_file, 16,
|
if not hasattr(plugin, 'activatable'):
|
||||||
16)
|
# version 0.15
|
||||||
if not hasattr(plugin, 'activatable'):
|
plugin.activatable = False
|
||||||
# version 0.15
|
max_row = [plugin, plugin.name, is_active, plugin.activatable, icon]
|
||||||
plugin.activatable = False
|
# support old plugin system
|
||||||
max_row = [plugin, plugin.name, is_active, plugin.activatable,
|
row_len = len(self.installed_plugins_model[0])
|
||||||
icon]
|
row = max_row[0: row_len]
|
||||||
# support old plugin system
|
self.installed_plugins_model.append(row)
|
||||||
row_len = len(self.installed_plugins_model[0])
|
|
||||||
row = max_row[0: row_len]
|
|
||||||
self.installed_plugins_model.append(row)
|
|
||||||
|
|
||||||
dialog = HigDialog(None, gtk.MESSAGE_INFO, gtk.BUTTONS_OK,
|
|
||||||
'', _('All selected plugins downloaded'))
|
|
||||||
dialog.set_modal(False)
|
|
||||||
dialog.set_transient_for(self.window)
|
|
||||||
dialog.popup()
|
dialog.popup()
|
||||||
|
|
||||||
def available_plugins_treeview_selection_changed(self, treeview_selection):
|
def available_plugins_treeview_selection_changed(self, treeview_selection):
|
||||||
@@ -381,7 +391,11 @@ class PluginInstaller(GajimPlugin):
|
|||||||
if module_name == '__init__':
|
if module_name == '__init__':
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
module = __import__('%s.%s' % (mod, module_name))
|
full_module_name = '%s.%s' % (mod, module_name)
|
||||||
|
if full_module_name in sys.modules:
|
||||||
|
module = reload(sys.modules[full_module_name])
|
||||||
|
else:
|
||||||
|
module = __import__(full_module_name)
|
||||||
except ValueError, value_error:
|
except ValueError, value_error:
|
||||||
pass
|
pass
|
||||||
except ImportError, import_error:
|
except ImportError, import_error:
|
||||||
|
|||||||
Reference in New Issue
Block a user