From adb326a5f24145bfcd6e2cbb57ea9ec99579b072 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Fri, 20 Oct 2017 17:22:44 +0200 Subject: [PATCH] Refactor StatusComboBox - Move as much code as possible into Glade file - Pull icons from the IconsTheme (because of HiDPI scaling) --- gajim/data/gui/roster_window.ui | 92 +++++++++++++++++++++++++++ gajim/gtkgui_helpers.py | 6 ++ gajim/roster_window.py | 106 +++++++++++--------------------- 3 files changed, 135 insertions(+), 69 deletions(-) diff --git a/gajim/data/gui/roster_window.ui b/gajim/data/gui/roster_window.ui index cac95c47e..a50d4efb8 100644 --- a/gajim/data/gui/roster_window.ui +++ b/gajim/data/gui/roster_window.ui @@ -3,6 +3,80 @@ + + + + + + + + + + + + + + online + online + online + True + + + chat + chat + chat + True + + + away + away + away + True + + + xa + xa + xa + True + + + dnd + dnd + dnd + True + + + invisible + invisible + invisible + True + + + SEPARATOR + None + None + True + + + Change Status Messageā€¦ + gajim-kbd_input + status + False + + + SEPARATOR + None + None + True + + + offline + offline + offline + True + + + RosterWindow 85 @@ -89,7 +163,25 @@ True False + status_liststore + + + + 3 + 1 + + + + + 5 + end + + + 3 + 0 + + False diff --git a/gajim/gtkgui_helpers.py b/gajim/gtkgui_helpers.py index 90eb5a129..aaf448576 100644 --- a/gajim/gtkgui_helpers.py +++ b/gajim/gtkgui_helpers.py @@ -639,6 +639,12 @@ def get_pep_as_pixbuf(pep_class): return icon return None +def get_iconset_name_for(name): + iconset = app.config.get('iconset') + if not iconset: + return '-'.join([app.config.DEFAULT_ICONSET, name]) + return '-'.join([iconset, name]) + def load_icons_meta(): """ Load and return - AND + small icons to put on top left of an icon for meta diff --git a/gajim/roster_window.py b/gajim/roster_window.py index 3e1c0d193..ab2eb18e5 100644 --- a/gajim/roster_window.py +++ b/gajim/roster_window.py @@ -220,8 +220,8 @@ class RosterWindow: pass return its2 - - def _iter_is_separator(self, model, titer, dummy): + @staticmethod + def _iter_is_separator(model, titer): """ Return True if the given iter is a separator @@ -233,6 +233,25 @@ class RosterWindow: return True return False + @staticmethod + def _status_cell_data_func(cell_layout, cell, tree_model, iter_): + if isinstance(cell, Gtk.CellRendererPixbuf): + icon_name = tree_model[iter_][1] + if icon_name is None: + return + if tree_model[iter_][2] == 'status': + cell.set_property('icon_name', icon_name) + else: + iconset_name = gtkgui_helpers.get_iconset_name_for(icon_name) + cell.set_property('icon_name', iconset_name) + else: + show = tree_model[iter_][0] + id_ = tree_model[iter_][2] + if id_ not in ('status', 'desync'): + show = helpers.get_uf_show(show) + cell.set_property('text', show) + + ############################################################################# ### Methods for adding and removing roster window items @@ -2324,9 +2343,9 @@ class RosterWindow: else: uf_show = helpers.get_uf_show(show) liststore.prepend(['SEPARATOR', None, '', True]) - status_combobox_text = uf_show + ' (' + _("desync'ed") +')' - liststore.prepend([status_combobox_text, - app.interface.jabber_state_images['16'][show], show, False]) + status_combobox_text = uf_show + ' (' + _("desync'ed") + ')' + liststore.prepend( + [status_combobox_text, show, 'desync', False]) self.status_combobox.set_active(0) self.combobox_callback_active = True if app.interface.systray_enabled: @@ -2630,14 +2649,15 @@ class RosterWindow: def _nec_our_show(self, obj): model = self.status_combobox.get_model() + iter_ = model.get_iter_from_string('7') if obj.show == 'offline': # sensitivity for this menuitem if app.get_number_of_connected_accounts() == 0: - model[self.status_message_menuitem_iter][3] = False + model[iter_][3] = False self.application.set_account_actions_state(obj.conn.name) else: # sensitivity for this menuitem - model[self.status_message_menuitem_iter][3] = True + model[iter_][3] = True self.on_status_changed(obj.conn.name, obj.show) def _nec_connection_type(self, obj): @@ -4608,15 +4628,7 @@ class RosterWindow: # Update the roster self.setup_and_draw_roster() # Update the status combobox - model = self.status_combobox.get_model() - titer = model.get_iter_first() - while titer: - if model[titer][2] != '': - # If it's not change status message iter - # eg. if it has show parameter not '' - model[titer][1] = app.interface.jabber_state_images['16'][ - model[titer][2]] - titer = model.iter_next(titer) + self.status_combobox.queue_draw() # Update the systray if app.interface.systray_enabled: app.interface.systray.set_img() @@ -5733,64 +5745,20 @@ class RosterWindow: # accounts to draw next time we draw accounts. self.accounts_to_draw = [] - # uf_show, img, show, sensitive - liststore = Gtk.ListStore(str, Gtk.Image, str, bool) + # StatusComboBox self.status_combobox = self.xml.get_object('status_combobox') + pixbuf_renderer, text_renderer = self.status_combobox.get_cells() + self.status_combobox.set_cell_data_func( + pixbuf_renderer, self._status_cell_data_func) + self.status_combobox.set_cell_data_func( + text_renderer, self._status_cell_data_func) + self.status_combobox.set_row_separator_func(self._iter_is_separator) - cell = cell_renderer_image.CellRendererImage(0, 1) - self.status_combobox.pack_start(cell, False) - - # img to show is in in 2nd column of liststore - self.status_combobox.add_attribute(cell, 'image', 1) - # if it will be sensitive or not it is in the fourth column - # all items in the 'row' must have sensitive to False - # if we want False (so we add it for img_cell too) - self.status_combobox.add_attribute(cell, 'sensitive', 3) - - cell = Gtk.CellRendererText() - cell.set_property('ellipsize', Pango.EllipsizeMode.END) - cell.set_property('xpad', 5) # padding for status text - self.status_combobox.pack_start(cell, True) - # text to show is in in first column of liststore - self.status_combobox.add_attribute(cell, 'text', 0) - # if it will be sensitive or not it is in the fourth column - self.status_combobox.add_attribute(cell, 'sensitive', 3) - - self.status_combobox.set_row_separator_func(self._iter_is_separator, None) - - for show in ('online', 'chat', 'away', 'xa', 'dnd', 'invisible'): - uf_show = helpers.get_uf_show(show) - liststore.append([uf_show, - app.interface.jabber_state_images['16'][show], show, True]) - # Add a Separator (self._iter_is_separator() checks on string SEPARATOR) - liststore.append(['SEPARATOR', None, '', True]) - - path = gtkgui_helpers.get_icon_path('gajim-kbd_input') - img = Gtk.Image() - img.set_from_file(path) - # sensitivity to False because by default we're offline - self.status_message_menuitem_iter = liststore.append( - [_('Change Status Messageā€¦'), img, '', False]) - # Add a Separator (self._iter_is_separator() checks on string SEPARATOR) - liststore.append(['SEPARATOR', None, '', True]) - - uf_show = helpers.get_uf_show('offline') - liststore.append([uf_show, app.interface.jabber_state_images['16'][ - 'offline'], 'offline', True]) - - status_combobox_items = ['online', 'chat', 'away', 'xa', 'dnd', - 'invisible', 'separator1', 'change_status_msg', 'separator2', - 'offline'] - self.status_combobox.set_model(liststore) - - # default to offline - number_of_menuitem = status_combobox_items.index('offline') - self.status_combobox.set_active(number_of_menuitem) - + self.status_combobox.set_active(9) # holds index to previously selected item so if # "change status message..." is selected we can fallback to previously # selected item and not stay with that item selected - self.previous_status_combobox_active = number_of_menuitem + self.previous_status_combobox_active = 9 # Enable/Disable checkboxes at start if app.config.get('showoffline'):