Commit f19c134a authored by Daniel Brötzmann's avatar Daniel Brötzmann

[plugin_installer] Replace progressbar by spinner, code cleanup

parent 204743e4
......@@ -16,7 +16,7 @@
<property name="halign">start</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_auto_update_feedback_toggled" swapped="no"/>
<signal name="toggled" handler="_on_auto_update_feedback_toggled" swapped="no"/>
</object>
<packing>
<property name="left_attach">0</property>
......@@ -32,7 +32,7 @@
<property name="halign">start</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_auto_update_toggled" swapped="no"/>
<signal name="toggled" handler="_on_auto_update_toggled" swapped="no"/>
</object>
<packing>
<property name="left_attach">0</property>
......@@ -48,7 +48,7 @@
<property name="halign">start</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_check_update_toggled" swapped="no"/>
<signal name="toggled" handler="_on_check_update_toggled" swapped="no"/>
</object>
<packing>
<property name="left_attach">0</property>
......
......@@ -24,23 +24,18 @@
<column type="gchararray"/>
</columns>
</object>
<object class="GtkWindow" id="AvailablePlugins">
<property name="can_focus">False</property>
<child>
<placeholder/>
</child>
<child>
<object class="GtkBox" id="available_plugins_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">18</property>
<property name="margin_right">18</property>
<property name="margin_top">18</property>
<property name="margin_bottom">18</property>
<property name="border_width">18</property>
<property name="spacing">18</property>
<child>
<object class="GtkBox">
<property name="width_request">200</property>
<object class="GtkOverlay">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkBox" id="plugins_box">
<property name="width_request">180</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
......@@ -56,20 +51,23 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">plugin_store</property>
<property name="search_column">2</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection">
<signal name="changed" handler="available_plugins_treeview_selection_changed" swapped="no"/>
<signal name="changed" handler="_available_plugins_treeview_selection_changed" swapped="no"/>
</object>
</child>
<child>
<object class="GtkTreeViewColumn">
<property name="resizable">True</property>
<property name="sizing">fixed</property>
<property name="fixed_width">200</property>
<property name="fixed_width">180</property>
<property name="min_width">150</property>
<property name="max_width">300</property>
<property name="title" translatable="yes">Plugin</property>
<property name="expand">True</property>
<property name="clickable">True</property>
<property name="sort_indicator">True</property>
<property name="sort_column_id">1</property>
<child>
<object class="GtkCellRendererPixbuf" id="pixbufrenderer"/>
<attributes>
......@@ -77,7 +75,9 @@
</attributes>
</child>
<child>
<object class="GtkCellRendererText" id="plugintextrenderer"/>
<object class="GtkCellRendererText" id="plugintextrenderer">
<property name="ellipsize">end</property>
</object>
<attributes>
<attribute name="text">2</attribute>
</attributes>
......@@ -108,12 +108,14 @@
</child>
<child>
<object class="GtkTreeViewColumn">
<property name="title" translatable="yes">Install /
Update</property>
<property name="title" translatable="yes">Install</property>
<property name="clickable">True</property>
<property name="alignment">0.5</property>
<property name="sort_indicator">True</property>
<property name="sort_column_id">5</property>
<child>
<object class="GtkCellRendererToggle" id="togglerenderer">
<signal name="toggled" handler="available_plugins_toggled_cb" swapped="no"/>
<signal name="toggled" handler="_available_plugin_toggled" swapped="no"/>
</object>
<attributes>
<attribute name="active">5</attribute>
......@@ -146,7 +148,7 @@ Update</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">Install/Update Plugin</property>
<property name="icon_name">software-update-available-symbolic</property>
<signal name="clicked" handler="on_install_upgrade_clicked" swapped="no"/>
<signal name="clicked" handler="_on_install_upgrade_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
......@@ -163,18 +165,18 @@ Update</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkProgressBar" id="progressbar">
<property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="ellipsize">end</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
<property name="index">-1</property>
</packing>
</child>
<child type="overlay">
<object class="GtkSpinner" id="spinner">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="active">True</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
......@@ -208,7 +210,7 @@ Update</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="plugin_description">
<object class="GtkLabel" id="plugin_description_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
......@@ -339,6 +341,4 @@ Update</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
......@@ -118,7 +118,7 @@ class PluginInstaller(GajimPlugin):
'auto_update_feedback': (True, '')}
self.gui_extension_points = {'plugin_window': (self.on_activate, None)}
self.window = None
self.progressbar = None
self.spinner = None
self.available_plugins_model = None
self.timeout_id = 0
self.connected_ids = {}
......@@ -134,7 +134,7 @@ class PluginInstaller(GajimPlugin):
if is_checked:
self.config['auto_update'] = True
get_action('plugins').activate()
page = self.notebook.page_num(self.available_plugins_box)
page = self.notebook.page_num(self._ui.available_plugins_box)
self.notebook.set_current_page(page)
if plugins:
plugins_str = '\n' + '\n'.join(plugins)
......@@ -163,7 +163,7 @@ class PluginInstaller(GajimPlugin):
def deactivate(self):
if hasattr(self, 'available_page'):
self.notebook.remove_page(
self.notebook.page_num(self.available_plugins_box))
self.notebook.page_num(self._ui.available_plugins_box))
self.notebook.set_current_page(0)
for id_, widget in list(self.connected_ids.items()):
widget.disconnect(id_)
......@@ -183,52 +183,41 @@ class PluginInstaller(GajimPlugin):
self.installed_plugins_model = plugin_win.installed_plugins_model
self.notebook = plugin_win.plugins_notebook
id_ = self.notebook.connect(
'switch-page', self.on_notebook_switch_page)
'switch-page', self._on_notebook_switch_page)
self.connected_ids[id_] = self.notebook
self.window = plugin_win.window
id_ = self.window.connect('destroy', self.on_win_destroy)
id_ = self.window.connect('destroy', self._on_destroy)
self.connected_ids[id_] = self.window
path = self.local_file_path('installer.ui')
self._ui = get_builder(
path, widgets=['refresh', 'available_plugins_box', 'plugin_store'])
widgets_to_extract = (
'available_plugins_box', 'install_plugin_button',
'plugin_name_label', 'plugin_version_label',
'plugin_authors_label', 'plugin_description',
'plugin_homepage_linkbutton', 'progressbar',
'available_plugins_treeview', 'available_text',
'available_text_label')
for widget_name in widgets_to_extract:
setattr(self, widget_name, self._ui.get_object(widget_name))
self.available_page = self.notebook.append_page(
self.available_plugins_box, Gtk.Label.new(_('Available')))
self._ui = get_builder(self.local_file_path('installer.ui'))
self.spinner = self._ui.spinner
self.available_plugins_model = self._ui.plugin_store
self.available_plugins_model.set_sort_column_id(
2, Gtk.SortType.ASCENDING)
self.available_page = self.notebook.append_page(
self._ui.available_plugins_box, Gtk.Label.new(_('Available')))
self._ui.connect_signals(self)
self.window.show_all()
def on_win_destroy(self, widget):
def _on_destroy(self, widget):
if hasattr(self, 'thread'):
del self.thread
if hasattr(self, 'available_page'):
del self.available_page
def available_plugins_toggled_cb(self, cell, path):
def _available_plugin_toggled(self, cell, path):
is_active = self.available_plugins_model[path][Column.UPGRADE]
self.available_plugins_model[path][Column.UPGRADE] = not is_active
dir_list = []
for i in range(len(self.available_plugins_model)):
if self.available_plugins_model[i][Column.UPGRADE]:
dir_list.append(self.available_plugins_model[i][Column.DIR])
self.install_plugin_button.set_property('sensitive', bool(dir_list))
self._ui.install_plugin_button.set_property(
'sensitive', bool(dir_list))
def on_notebook_switch_page(self, widget, page, page_num):
def _on_notebook_switch_page(self, widget, page, page_num):
tab_label_text = self.notebook.get_tab_label_text(page)
if tab_label_text != (_('Available')):
return
......@@ -236,8 +225,8 @@ class PluginInstaller(GajimPlugin):
self.available_plugins_model.clear()
self.start_download(upgrading=True)
def on_install_upgrade_clicked(self, widget):
self.install_plugin_button.set_property('sensitive', False)
def _on_install_upgrade_clicked(self, widget):
self._ui.install_plugin_button.set_property('sensitive', False)
dir_list = []
for i in range(len(self.available_plugins_model)):
if self.available_plugins_model[i][Column.UPGRADE]:
......@@ -264,10 +253,10 @@ class PluginInstaller(GajimPlugin):
if self.available_plugins_model:
for i in range(len(self.available_plugins_model)):
self.available_plugins_model[i][Column.UPGRADE] = False
self.progressbar.hide()
self._ui.spinner.hide()
text = GLib.markup_escape_text(reason)
WarningDialog(_('Error in download'),
_('An error occurred when downloading\n\n'
WarningDialog(_('Error While Downloading'),
_('An error occurred while downloading\n\n'
'<tt>[%s]</tt>' % (str(text))), self.window)
def start_download(self, secure=True, remote_dirs=False, upgrading=False,
......@@ -343,36 +332,38 @@ class PluginInstaller(GajimPlugin):
if auto_update and not self.config['auto_update_feedback']:
log.info('Updates downloaded, will install on next restart')
def available_plugins_treeview_selection_changed(self, treeview_selection):
def _available_plugins_treeview_selection_changed(self, treeview_selection):
model, iter_ = treeview_selection.get_selected()
if not iter_:
self.plugin_name_label.set_text('')
self.plugin_version_label.set_text('')
self.plugin_authors_label.set_text('')
self.plugin_homepage_linkbutton.set_text('')
self.install_plugin_button.set_sensitive(False)
self._ui.plugin_name_label.set_text('')
self._ui.plugin_description_label.set_text('')
self._ui.plugin_version_label.set_text('')
self._ui.plugin_authors_label.set_text('')
self._ui.plugin_homepage_linkbutton.set_text('')
self._ui.install_plugin_button.set_sensitive(False)
return
self.plugin_name_label.set_text(model.get_value(iter_, Column.NAME))
self.plugin_version_label.set_text(
self._ui.plugin_name_label.set_text(
model.get_value(iter_, Column.NAME))
self._ui.plugin_version_label.set_text(
model.get_value(iter_, Column.VERSION))
self.plugin_authors_label.set_text(
self._ui.plugin_authors_label.set_text(
model.get_value(iter_, Column.AUTHORS))
homepage = model.get_value(iter_, Column.HOMEPAGE)
markup = '<a href="%s">%s</a>' % (homepage, homepage)
self.plugin_homepage_linkbutton.set_markup(markup)
self.plugin_description.set_text(
self._ui.plugin_homepage_linkbutton.set_markup(markup)
self._ui.plugin_description_label.set_text(
model.get_value(iter_, Column.DESCRIPTION))
def select_root_iter(self):
selection = self.available_plugins_treeview.get_selection()
selection = self._ui.available_plugins_treeview.get_selection()
model, iter_ = selection.get_selected()
if not iter_:
iter_ = self.available_plugins_model.get_iter_first()
selection.select_iter(iter_)
self.plugin_name_label.show()
self.plugin_homepage_linkbutton.show()
self._ui.plugin_name_label.show()
self._ui.plugin_homepage_linkbutton.show()
path = self.available_plugins_model.get_path(iter_)
self.available_plugins_treeview.scroll_to_cell(path)
self._ui.available_plugins_treeview.scroll_to_cell(path)
class DownloadAsync(threading.Thread):
......@@ -381,7 +372,7 @@ class DownloadAsync(threading.Thread):
threading.Thread.__init__(self)
self.plugin = plugin
self.window = plugin.window
self.progressbar = plugin.progressbar
self.spinner = plugin.spinner
self.model = plugin.available_plugins_model
self.remote_dirs = remote_dirs
self.upgrading = upgrading
......@@ -399,18 +390,15 @@ class DownloadAsync(threading.Thread):
self.model.append(row_data)
return False
def progressbar_pulse(self):
self.progressbar.pulse()
return True
def run(self):
try:
if self.check_update:
self.run_check_update()
else:
if not self.auto_update:
GLib.idle_add(self.progressbar.show)
self.pulse = GLib.timeout_add(150, self.progressbar_pulse)
GLib.idle_add(self._show_spinner, True)
self.pulse = GLib.timeout_add(
150, self._show_spinner, False)
self.run_download_plugin_list()
except urllib.error.URLError as exc:
if isinstance(exc.reason, ssl.SSLError):
......@@ -424,7 +412,13 @@ class DownloadAsync(threading.Thread):
finally:
if self.pulse:
GLib.source_remove(self.pulse)
GLib.idle_add(self.progressbar.hide)
GLib.idle_add(self._show_spinner, False)
def _show_spinner(self, show):
if show:
self.spinner.show()
else:
self.spinner.hide()
self.pulse = None
def parse_manifest(self, buf):
......@@ -547,7 +541,7 @@ class DownloadAsync(threading.Thread):
if V(plugin['version']) > V(plugin['local_version']):
plugin['upgrade'] = True
GLib.idle_add(
self.plugin.install_plugin_button.set_property,
self.plugin._ui.install_plugin_button.set_property,
'sensitive', True)
GLib.idle_add(self.model_append, plugin)
if nb_plugins:
......@@ -581,10 +575,8 @@ class DownloadAsync(threading.Thread):
class PluginInstallerPluginConfigDialog(GajimPluginConfigDialog):
def init(self):
glade_file_path = self.plugin.local_file_path('config.ui')
self._ui = get_builder(glade_file_path)
self.get_child().pack_start(self._ui.config_grid, True, True, 0)
self._ui = get_builder(self.plugin.local_file_path('config.ui'))
self.get_child().add(self._ui.config_grid)
self._ui.connect_signals(self)
def on_run(self):
......@@ -596,7 +588,7 @@ class PluginInstallerPluginConfigDialog(GajimPluginConfigDialog):
self._ui.auto_update_feedback.set_active(
self.plugin.config['auto_update_feedback'])
def on_check_update_toggled(self, widget):
def _on_check_update_toggled(self, widget):
self.plugin.config['check_update'] = widget.get_active()
if not self.plugin.config['check_update']:
self.plugin.config['auto_update'] = False
......@@ -607,10 +599,10 @@ class PluginInstallerPluginConfigDialog(GajimPluginConfigDialog):
self._ui.auto_update_feedback.set_active(
self.plugin.config['auto_update_feedback'])
def on_auto_update_toggled(self, widget):
def _on_auto_update_toggled(self, widget):
self.plugin.config['auto_update'] = widget.get_active()
self._ui.auto_update_feedback.set_sensitive(
self.plugin.config['auto_update'])
def on_auto_update_feedback_toggled(self, widget):
def _on_auto_update_feedback_toggled(self, widget):
self.plugin.config['auto_update_feedback'] = widget.get_active()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment