[plugin_installer] Use IntEnum

This commit is contained in:
Philipp Hörist
2017-02-20 16:46:54 +01:00
parent c0b3f36b24
commit b520fa803a

View File

@@ -43,20 +43,22 @@ from plugins.helpers import log_calls, log
from htmltextview import HtmlTextView from htmltextview import HtmlTextView
from dialogs import WarningDialog, HigDialog, YesNoDialog from dialogs import WarningDialog, HigDialog, YesNoDialog
from plugins.gui import GajimPluginConfigDialog from plugins.gui import GajimPluginConfigDialog
from enum import IntEnum
log = logging.getLogger('gajim.plugin_system.plugin_installer') log = logging.getLogger('gajim.plugin_system.plugin_installer')
(
C_PIXBUF, class Column(IntEnum):
C_DIR, PIXBUF = 0
C_NAME, DIR = 1
C_LOCAL_VERSION, NAME = 2
C_VERSION, LOCAL_VERSION = 3
C_UPGRADE, VERSION = 4
C_DESCRIPTION, UPGRADE = 5
C_AUTHORS, DESCRIPTION = 6
C_HOMEPAGE AUTHORS = 7
) = range(9) HOMEPAGE = 8
def convert_version_to_list(version_str): def convert_version_to_list(version_str):
version_list = version_str.split('.') version_list = version_str.split('.')
@@ -225,18 +227,18 @@ class PluginInstaller(GajimPlugin):
col = Gtk.TreeViewColumn(_('Plugin')) col = Gtk.TreeViewColumn(_('Plugin'))
cell = Gtk.CellRendererPixbuf() cell = Gtk.CellRendererPixbuf()
col.pack_start(cell, False) col.pack_start(cell, False)
col.add_attribute(cell, 'pixbuf', C_PIXBUF) col.add_attribute(cell, 'pixbuf', Column.PIXBUF)
col.pack_start(renderer, True) col.pack_start(renderer, True)
col.add_attribute(renderer, 'text', C_NAME) col.add_attribute(renderer, 'text', Column.NAME)
col.set_resizable(True) col.set_resizable(True)
col.set_property('expand', True) col.set_property('expand', True)
col.set_sizing(Gtk.TreeViewColumnSizing.GROW_ONLY) col.set_sizing(Gtk.TreeViewColumnSizing.GROW_ONLY)
self.available_treeview.append_column(col) self.available_treeview.append_column(col)
col = Gtk.TreeViewColumn(_('Installed\nversion'), renderer, col = Gtk.TreeViewColumn(_('Installed\nversion'), renderer,
text=C_LOCAL_VERSION) text=Column.LOCAL_VERSION)
self.available_treeview.append_column(col) self.available_treeview.append_column(col)
col = Gtk.TreeViewColumn(_('Available\nversion'), renderer, col = Gtk.TreeViewColumn(_('Available\nversion'), renderer,
text=C_VERSION) text=Column.VERSION)
col.set_property('expand', False) col.set_property('expand', False)
self.available_treeview.append_column(col) self.available_treeview.append_column(col)
@@ -244,7 +246,7 @@ class PluginInstaller(GajimPlugin):
renderer.set_property('activatable', True) renderer.set_property('activatable', True)
renderer.connect('toggled', self.available_plugins_toggled_cb) renderer.connect('toggled', self.available_plugins_toggled_cb)
col = Gtk.TreeViewColumn(_('Install /\nUpgrade'), renderer, col = Gtk.TreeViewColumn(_('Install /\nUpgrade'), renderer,
active=C_UPGRADE) active=Column.UPGRADE)
self.available_treeview.append_column(col) self.available_treeview.append_column(col)
if GObject.signal_lookup('error_signal', self.window) is 0: if GObject.signal_lookup('error_signal', self.window) is 0:
@@ -283,12 +285,12 @@ class PluginInstaller(GajimPlugin):
del self.page_num del self.page_num
def available_plugins_toggled_cb(self, cell, path): def available_plugins_toggled_cb(self, cell, path):
is_active = self.available_plugins_model[path][C_UPGRADE] is_active = self.available_plugins_model[path][Column.UPGRADE]
self.available_plugins_model[path][C_UPGRADE] = not is_active self.available_plugins_model[path][Column.UPGRADE] = not is_active
dir_list = [] dir_list = []
for i in range(len(self.available_plugins_model)): for i in range(len(self.available_plugins_model)):
if self.available_plugins_model[i][C_UPGRADE]: if self.available_plugins_model[i][Column.UPGRADE]:
dir_list.append(self.available_plugins_model[i][C_DIR]) dir_list.append(self.available_plugins_model[i][Column.DIR])
if not dir_list: if not dir_list:
self.inslall_upgrade_button.set_property('sensitive', False) self.inslall_upgrade_button.set_property('sensitive', False)
else: else:
@@ -310,8 +312,8 @@ class PluginInstaller(GajimPlugin):
self.inslall_upgrade_button.set_property('sensitive', False) self.inslall_upgrade_button.set_property('sensitive', False)
dir_list = [] dir_list = []
for i in range(len(self.available_plugins_model)): for i in range(len(self.available_plugins_model)):
if self.available_plugins_model[i][C_UPGRADE]: if self.available_plugins_model[i][Column.UPGRADE]:
dir_list.append(self.available_plugins_model[i][C_DIR]) dir_list.append(self.available_plugins_model[i][Column.DIR])
ftp = Ftp(self) ftp = Ftp(self)
ftp.remote_dirs = dir_list ftp.remote_dirs = dir_list
@@ -319,7 +321,7 @@ class PluginInstaller(GajimPlugin):
def on_some_ftp_error(self, widget, error_text): def on_some_ftp_error(self, widget, error_text):
for i in range(len(self.available_plugins_model)): for i in range(len(self.available_plugins_model)):
self.available_plugins_model[i][C_UPGRADE] = False self.available_plugins_model[i][Column.UPGRADE] = False
self.progressbar.hide() self.progressbar.hide()
def warn(): def warn():
WarningDialog(_('Ftp error'), error_text, self.window) WarningDialog(_('Ftp error'), error_text, self.window)
@@ -355,10 +357,10 @@ class PluginInstaller(GajimPlugin):
gajim.plugin_manager.add_plugin(plugins[0]) gajim.plugin_manager.add_plugin(plugins[0])
plugin = gajim.plugin_manager.plugins[-1] plugin = gajim.plugin_manager.plugins[-1]
for row in range(len(self.available_plugins_model)): for row in range(len(self.available_plugins_model)):
if plugin.name == self.available_plugins_model[row][C_NAME]: if plugin.name == self.available_plugins_model[row][Column.NAME]:
self.available_plugins_model[row][C_LOCAL_VERSION] = \ self.available_plugins_model[row][Column.LOCAL_VERSION] = \
plugin.version plugin.version
self.available_plugins_model[row][C_UPGRADE] = False self.available_plugins_model[row][Column.UPGRADE] = False
if is_active: if is_active:
GLib.idle_add(gajim.plugin_manager.activate_plugin, plugin) GLib.idle_add(gajim.plugin_manager.activate_plugin, plugin)
# get plugin icon # get plugin icon
@@ -384,17 +386,17 @@ class PluginInstaller(GajimPlugin):
sw.add(self.plugin_description_textview) sw.add(self.plugin_description_textview)
sw.show_all() sw.show_all()
if iter: if iter:
self.plugin_name_label.set_text(model.get_value(iter, C_NAME)) self.plugin_name_label.set_text(model.get_value(iter, Column.NAME))
self.plugin_version_label.set_text(model.get_value(iter, C_VERSION)) self.plugin_version_label.set_text(model.get_value(iter, Column.VERSION))
self.plugin_authors_label.set_text(model.get_value(iter, C_AUTHORS)) self.plugin_authors_label.set_text(model.get_value(iter, Column.AUTHORS))
self.plugin_homepage_linkbutton.set_uri(model.get_value(iter, self.plugin_homepage_linkbutton.set_uri(model.get_value(iter,
C_HOMEPAGE)) Column.HOMEPAGE))
self.plugin_homepage_linkbutton.set_label(model.get_value(iter, self.plugin_homepage_linkbutton.set_label(model.get_value(iter,
C_HOMEPAGE)) Column.HOMEPAGE))
label = self.plugin_homepage_linkbutton.get_children()[0] label = self.plugin_homepage_linkbutton.get_children()[0]
label.set_ellipsize(Pango.EllipsizeMode.END) label.set_ellipsize(Pango.EllipsizeMode.END)
self.plugin_homepage_linkbutton.set_property('sensitive', True) self.plugin_homepage_linkbutton.set_property('sensitive', True)
desc = _(model.get_value(iter, C_DESCRIPTION)) desc = _(model.get_value(iter, Column.DESCRIPTION))
if not desc.startswith('<body '): if not desc.startswith('<body '):
desc = '<body xmlns=\'http://www.w3.org/1999/xhtml\'>' + \ desc = '<body xmlns=\'http://www.w3.org/1999/xhtml\'>' + \
desc + ' </body>' desc + ' </body>'