Refactor StatusComboBox
- Move as much code as possible into Glade file - Pull icons from the IconsTheme (because of HiDPI scaling)
This commit is contained in:
parent
749fcc1b48
commit
adb326a5f2
|
@ -3,6 +3,80 @@
|
||||||
<interface>
|
<interface>
|
||||||
<requires lib="gtk+" version="3.12"/>
|
<requires lib="gtk+" version="3.12"/>
|
||||||
<object class="GtkAccelGroup" id="accelgroup1"/>
|
<object class="GtkAccelGroup" id="accelgroup1"/>
|
||||||
|
<object class="GtkListStore" id="status_liststore">
|
||||||
|
<columns>
|
||||||
|
<!-- column-name statustext -->
|
||||||
|
<column type="gchararray"/>
|
||||||
|
<!-- column-name icon-name -->
|
||||||
|
<column type="gchararray"/>
|
||||||
|
<!-- column-name show -->
|
||||||
|
<column type="gchararray"/>
|
||||||
|
<!-- column-name sensible -->
|
||||||
|
<column type="gboolean"/>
|
||||||
|
</columns>
|
||||||
|
<data>
|
||||||
|
<row>
|
||||||
|
<col id="0">online</col>
|
||||||
|
<col id="1">online</col>
|
||||||
|
<col id="2">online</col>
|
||||||
|
<col id="3">True</col>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<col id="0">chat</col>
|
||||||
|
<col id="1">chat</col>
|
||||||
|
<col id="2">chat</col>
|
||||||
|
<col id="3">True</col>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<col id="0">away</col>
|
||||||
|
<col id="1">away</col>
|
||||||
|
<col id="2">away</col>
|
||||||
|
<col id="3">True</col>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<col id="0">xa</col>
|
||||||
|
<col id="1">xa</col>
|
||||||
|
<col id="2">xa</col>
|
||||||
|
<col id="3">True</col>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<col id="0">dnd</col>
|
||||||
|
<col id="1">dnd</col>
|
||||||
|
<col id="2">dnd</col>
|
||||||
|
<col id="3">True</col>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<col id="0">invisible</col>
|
||||||
|
<col id="1">invisible</col>
|
||||||
|
<col id="2">invisible</col>
|
||||||
|
<col id="3">True</col>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<col id="0">SEPARATOR</col>
|
||||||
|
<col id="1">None</col>
|
||||||
|
<col id="2">None</col>
|
||||||
|
<col id="3">True</col>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<col id="0" translatable="yes">Change Status Message…</col>
|
||||||
|
<col id="1">gajim-kbd_input</col>
|
||||||
|
<col id="2">status</col>
|
||||||
|
<col id="3">False</col>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<col id="0">SEPARATOR</col>
|
||||||
|
<col id="1">None</col>
|
||||||
|
<col id="2">None</col>
|
||||||
|
<col id="3">True</col>
|
||||||
|
</row>
|
||||||
|
<row>
|
||||||
|
<col id="0">offline</col>
|
||||||
|
<col id="1">offline</col>
|
||||||
|
<col id="2">offline</col>
|
||||||
|
<col id="3">True</col>
|
||||||
|
</row>
|
||||||
|
</data>
|
||||||
|
</object>
|
||||||
<object class="GtkApplicationWindow" id="roster_window">
|
<object class="GtkApplicationWindow" id="roster_window">
|
||||||
<property name="name">RosterWindow</property>
|
<property name="name">RosterWindow</property>
|
||||||
<property name="width_request">85</property>
|
<property name="width_request">85</property>
|
||||||
|
@ -89,7 +163,25 @@
|
||||||
<object class="GtkComboBox" id="status_combobox">
|
<object class="GtkComboBox" id="status_combobox">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
|
<property name="model">status_liststore</property>
|
||||||
<signal name="changed" handler="on_status_combobox_changed" swapped="no"/>
|
<signal name="changed" handler="on_status_combobox_changed" swapped="no"/>
|
||||||
|
<child>
|
||||||
|
<object class="GtkCellRendererPixbuf"/>
|
||||||
|
<attributes>
|
||||||
|
<attribute name="sensitive">3</attribute>
|
||||||
|
<attribute name="icon-name">1</attribute>
|
||||||
|
</attributes>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkCellRendererText">
|
||||||
|
<property name="xpad">5</property>
|
||||||
|
<property name="ellipsize">end</property>
|
||||||
|
</object>
|
||||||
|
<attributes>
|
||||||
|
<attribute name="sensitive">3</attribute>
|
||||||
|
<attribute name="text">0</attribute>
|
||||||
|
</attributes>
|
||||||
|
</child>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
|
|
|
@ -639,6 +639,12 @@ def get_pep_as_pixbuf(pep_class):
|
||||||
return icon
|
return icon
|
||||||
return None
|
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():
|
def load_icons_meta():
|
||||||
"""
|
"""
|
||||||
Load and return - AND + small icons to put on top left of an icon for meta
|
Load and return - AND + small icons to put on top left of an icon for meta
|
||||||
|
|
|
@ -220,8 +220,8 @@ class RosterWindow:
|
||||||
pass
|
pass
|
||||||
return its2
|
return its2
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
def _iter_is_separator(self, model, titer, dummy):
|
def _iter_is_separator(model, titer):
|
||||||
"""
|
"""
|
||||||
Return True if the given iter is a separator
|
Return True if the given iter is a separator
|
||||||
|
|
||||||
|
@ -233,6 +233,25 @@ class RosterWindow:
|
||||||
return True
|
return True
|
||||||
return False
|
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
|
### Methods for adding and removing roster window items
|
||||||
|
@ -2324,9 +2343,9 @@ class RosterWindow:
|
||||||
else:
|
else:
|
||||||
uf_show = helpers.get_uf_show(show)
|
uf_show = helpers.get_uf_show(show)
|
||||||
liststore.prepend(['SEPARATOR', None, '', True])
|
liststore.prepend(['SEPARATOR', None, '', True])
|
||||||
status_combobox_text = uf_show + ' (' + _("desync'ed") +')'
|
status_combobox_text = uf_show + ' (' + _("desync'ed") + ')'
|
||||||
liststore.prepend([status_combobox_text,
|
liststore.prepend(
|
||||||
app.interface.jabber_state_images['16'][show], show, False])
|
[status_combobox_text, show, 'desync', False])
|
||||||
self.status_combobox.set_active(0)
|
self.status_combobox.set_active(0)
|
||||||
self.combobox_callback_active = True
|
self.combobox_callback_active = True
|
||||||
if app.interface.systray_enabled:
|
if app.interface.systray_enabled:
|
||||||
|
@ -2630,14 +2649,15 @@ class RosterWindow:
|
||||||
|
|
||||||
def _nec_our_show(self, obj):
|
def _nec_our_show(self, obj):
|
||||||
model = self.status_combobox.get_model()
|
model = self.status_combobox.get_model()
|
||||||
|
iter_ = model.get_iter_from_string('7')
|
||||||
if obj.show == 'offline':
|
if obj.show == 'offline':
|
||||||
# sensitivity for this menuitem
|
# sensitivity for this menuitem
|
||||||
if app.get_number_of_connected_accounts() == 0:
|
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)
|
self.application.set_account_actions_state(obj.conn.name)
|
||||||
else:
|
else:
|
||||||
# sensitivity for this menuitem
|
# 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)
|
self.on_status_changed(obj.conn.name, obj.show)
|
||||||
|
|
||||||
def _nec_connection_type(self, obj):
|
def _nec_connection_type(self, obj):
|
||||||
|
@ -4608,15 +4628,7 @@ class RosterWindow:
|
||||||
# Update the roster
|
# Update the roster
|
||||||
self.setup_and_draw_roster()
|
self.setup_and_draw_roster()
|
||||||
# Update the status combobox
|
# Update the status combobox
|
||||||
model = self.status_combobox.get_model()
|
self.status_combobox.queue_draw()
|
||||||
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)
|
|
||||||
# Update the systray
|
# Update the systray
|
||||||
if app.interface.systray_enabled:
|
if app.interface.systray_enabled:
|
||||||
app.interface.systray.set_img()
|
app.interface.systray.set_img()
|
||||||
|
@ -5733,64 +5745,20 @@ class RosterWindow:
|
||||||
# accounts to draw next time we draw accounts.
|
# accounts to draw next time we draw accounts.
|
||||||
self.accounts_to_draw = []
|
self.accounts_to_draw = []
|
||||||
|
|
||||||
# uf_show, img, show, sensitive
|
# StatusComboBox
|
||||||
liststore = Gtk.ListStore(str, Gtk.Image, str, bool)
|
|
||||||
self.status_combobox = self.xml.get_object('status_combobox')
|
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.set_active(9)
|
||||||
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)
|
|
||||||
|
|
||||||
# holds index to previously selected item so if
|
# holds index to previously selected item so if
|
||||||
# "change status message..." is selected we can fallback to previously
|
# "change status message..." is selected we can fallback to previously
|
||||||
# selected item and not stay with that item selected
|
# 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
|
# Enable/Disable checkboxes at start
|
||||||
if app.config.get('showoffline'):
|
if app.config.get('showoffline'):
|
||||||
|
|
Loading…
Reference in New Issue