Philipp Hörist pushed to branch master at gajim / gajim
Commits: 668962c5 by Daniel Brötzmann at 2020-08-14T19:51:00+02:00 StatusChange: Fix selecting activity/mood on preset change
- - - - - 63ce3aa4 by Daniel Brötzmann at 2020-08-14T19:51:00+02:00 StatusChange: Use module methods and respect global status sync
- - - - -
1 changed file:
- gajim/gtk/status_change.py
Changes:
===================================== gajim/gtk/status_change.py ===================================== @@ -18,7 +18,6 @@ from gi.repository import Gtk from gajim.common import app from gajim.common.const import ACTIVITIES from gajim.common.const import MOODS -from gajim.common.const import PEPEventType from gajim.common.helpers import from_one_line from gajim.common.helpers import to_one_line from gajim.common.helpers import remove_invalid_xml_chars @@ -77,7 +76,7 @@ class StatusChange(Gtk.ApplicationWindow, TimeoutWindow): 'mood': '', } self._get_current_status_data() - self._preset_messages_dict = {} + self._presets = {} self._get_presets()
if self._status: @@ -91,11 +90,13 @@ class StatusChange(Gtk.ApplicationWindow, TimeoutWindow): self._apply_speller() self._message_buffer.set_text(from_one_line(self._status_message))
+ self._activity_btns = {} + self._mood_btns = {} if show_pep: - self._draw_activity() self._init_activities() - self._draw_mood() + self._draw_activity() self._init_moods() + self._draw_mood() else: self._ui.pep_grid.set_no_show_all(True) self._ui.pep_grid.hide() @@ -138,11 +139,11 @@ class StatusChange(Gtk.ApplicationWindow, TimeoutWindow): are synchronized. If not, no status message/pep data will be displayed. ''' if self.account: - self._status_message = app.connections[self.account].status_message - activity_data = app.connections[self.account].pep.get( - PEPEventType.ACTIVITY) - mood_data = app.connections[self.account].pep.get( - PEPEventType.MOOD) + client = app.get_client(self.account) + self._status_message = client.status_message + activity_data = client.get_module( + 'UserActivity').get_current_activity() + mood_data = client.get_module('UserMood').get_current_mood() if activity_data: self._pep_dict['activity'] = activity_data.activity self._pep_dict['subactivity'] = activity_data.subactivity @@ -154,10 +155,15 @@ class StatusChange(Gtk.ApplicationWindow, TimeoutWindow): subactivities = [] moods = [] for account in app.connections: - status_messages.append(app.connections[account].status_message) - activity_data = app.connections[account].pep.get( - PEPEventType.ACTIVITY) - mood_data = app.connections[account].pep.get(PEPEventType.MOOD) + client = app.get_client(account) + if not app.config.get_per('accounts', client.account, + 'sync_with_global_status'): + continue + + status_messages.append(client.status_message) + activity_data = client.get_module( + 'UserActivity').get_current_activity() + mood_data = client.get_module('UserMood').get_current_mood() if activity_data: activities.append(activity_data.activity) subactivities.append(activity_data.subactivity) @@ -169,7 +175,7 @@ class StatusChange(Gtk.ApplicationWindow, TimeoutWindow): equal_subactivities = all(x == subactivities[0] for x in subactivities) equal_moods = all(x == moods[0] for x in moods) - if equal_messages: + if status_messages and equal_messages: self._status_message = status_messages[0] if activities and equal_activities: self._pep_dict['activity'] = activities[0] @@ -179,7 +185,7 @@ class StatusChange(Gtk.ApplicationWindow, TimeoutWindow): self._pep_dict['mood'] = moods[0]
def _get_presets(self): - self._preset_messages_dict = {} + self._presets = {} for msg_name in app.config.get_per('statusmsg'): if msg_name.startswith('_last_'): continue @@ -187,7 +193,7 @@ class StatusChange(Gtk.ApplicationWindow, TimeoutWindow): for opt in ['message', 'activity', 'subactivity', 'mood']: opts.append(app.config.get_per('statusmsg', msg_name, opt)) opts[0] = from_one_line(opts[0]) - self._preset_messages_dict[msg_name] = opts + self._presets[msg_name] = opts self._build_preset_popover()
def _build_preset_popover(self): @@ -199,7 +205,7 @@ class StatusChange(Gtk.ApplicationWindow, TimeoutWindow): preset_box.get_style_context().add_class('margin-3') self._ui.preset_popover.add(preset_box)
- for preset in self._preset_messages_dict: + for preset in self._presets: button_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
preset_button = Gtk.Button() @@ -222,7 +228,6 @@ class StatusChange(Gtk.ApplicationWindow, TimeoutWindow): preset_box.show_all()
def _init_activities(self): - radio_btns = {} group = None
for category in ACTIVITIES: @@ -236,10 +241,10 @@ class StatusChange(Gtk.ApplicationWindow, TimeoutWindow): # Other act = category + '_other' if group: - radio_btns[act] = Gtk.RadioButton() - radio_btns[act].join_group(group) + self._activity_btns[act] = Gtk.RadioButton() + self._activity_btns[act].join_group(group) else: - radio_btns[act] = group = Gtk.RadioButton() + self._activity_btns[act] = group = Gtk.RadioButton()
icon = Gtk.Image.new_from_icon_name(icon_name, Gtk.IconSize.MENU) icon_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, @@ -249,11 +254,11 @@ class StatusChange(Gtk.ApplicationWindow, TimeoutWindow): label='<b>%s</b>' % ACTIVITIES[category]['category']) label.set_use_markup(True) icon_box.pack_start(label, False, False, 0) - radio_btns[act].add(icon_box) - radio_btns[act].join_group(self._ui.no_activity_button) - radio_btns[act].connect( + self._activity_btns[act].add(icon_box) + self._activity_btns[act].join_group(self._ui.no_activity_button) + self._activity_btns[act].connect( 'toggled', self._on_activity_toggled, [category, 'other']) - category_box.pack_start(radio_btns[act], False, False, 0) + category_box.pack_start(self._activity_btns[act], False, False, 0)
activities = list(ACTIVITIES[category].keys()) activities.sort() @@ -264,10 +269,10 @@ class StatusChange(Gtk.ApplicationWindow, TimeoutWindow): act = category + '_' + activity
if group: - radio_btns[act] = Gtk.RadioButton() - radio_btns[act].join_group(group) + self._activity_btns[act] = Gtk.RadioButton() + self._activity_btns[act].join_group(group) else: - radio_btns[act] = group = Gtk.RadioButton() + self._activity_btns[act] = group = Gtk.RadioButton()
icon_name = get_activity_icon_name(category, activity) icon = Gtk.Image.new_from_icon_name( @@ -277,11 +282,13 @@ class StatusChange(Gtk.ApplicationWindow, TimeoutWindow): spacing=6) icon_box.pack_start(icon, False, False, 0) icon_box.pack_start(label, False, False, 0) - radio_btns[act].join_group(self._ui.no_activity_button) - radio_btns[act].connect('toggled', self._on_activity_toggled, - [category, activity]) - radio_btns[act].add(icon_box) - category_box.pack_start(radio_btns[act], False, False, 0) + self._activity_btns[act].join_group( + self._ui.no_activity_button) + self._activity_btns[act].connect( + 'toggled', self._on_activity_toggled, [category, activity]) + self._activity_btns[act].add(icon_box) + category_box.pack_start( + self._activity_btns[act], False, False, 0)
if not self._pep_dict['activity']: self._ui.no_activity_button.set_active(True) @@ -291,8 +298,9 @@ class StatusChange(Gtk.ApplicationWindow, TimeoutWindow): self._pep_dict['activity']]: self._pep_dict['subactivity'] = 'other'
- radio_btns[self._pep_dict['activity'] + '_' + self._pep_dict[ - 'subactivity']].set_active(True) + self._activity_btns[ + self._pep_dict['activity'] + '_' + self._pep_dict[ + 'subactivity']].set_active(True)
self._ui.activity_notebook.set_current_page( ACTIVITY_PAGELIST.index(self._pep_dict['activity'])) @@ -309,6 +317,11 @@ class StatusChange(Gtk.ApplicationWindow, TimeoutWindow): self._ui.activity_button_label.set_text( ACTIVITIES[self._pep_dict['activity']][ self._pep_dict['subactivity']]) + self._activity_btns[ + self._pep_dict['activity'] + '_' + self._pep_dict[ + 'subactivity']].set_active(True) + self._ui.activity_notebook.set_current_page( + ACTIVITY_PAGELIST.index(self._pep_dict['activity'])) else: icon_name = get_activity_icon_name(self._pep_dict['activity']) self._ui.activity_image.set_from_icon_name( @@ -326,7 +339,6 @@ class StatusChange(Gtk.ApplicationWindow, TimeoutWindow):
x_position = 1 y_position = 0 - mood_buttons = {}
# Order them first moods = [] @@ -337,16 +349,16 @@ class StatusChange(Gtk.ApplicationWindow, TimeoutWindow): for mood in moods: image = Gtk.Image.new_from_icon_name( 'mood-%s' % mood, Gtk.IconSize.MENU) - mood_buttons[mood] = Gtk.RadioButton() - mood_buttons[mood].join_group(self._ui.no_mood_button) - mood_buttons[mood].set_mode(False) - mood_buttons[mood].add(image) - mood_buttons[mood].set_relief(Gtk.ReliefStyle.NONE) - mood_buttons[mood].set_tooltip_text(MOODS[mood]) - mood_buttons[mood].connect( + self._mood_btns[mood] = Gtk.RadioButton() + self._mood_btns[mood].join_group(self._ui.no_mood_button) + self._mood_btns[mood].set_mode(False) + self._mood_btns[mood].add(image) + self._mood_btns[mood].set_relief(Gtk.ReliefStyle.NONE) + self._mood_btns[mood].set_tooltip_text(MOODS[mood]) + self._mood_btns[mood].connect( 'clicked', self._on_mood_button_clicked, mood) self._ui.moods_grid.attach( - mood_buttons[mood], x_position, y_position, 1, 1) + self._mood_btns[mood], x_position, y_position, 1, 1)
# Calculate the next position x_position += 1 @@ -355,7 +367,7 @@ class StatusChange(Gtk.ApplicationWindow, TimeoutWindow): y_position += 1
if self._pep_dict['mood'] in MOODS: - mood_buttons[self._pep_dict['mood']].set_active(True) + self._mood_btns[self._pep_dict['mood']].set_active(True) self._ui.mood_label.set_text(MOODS[self._pep_dict['mood']]) else: self._ui.mood_label.set_text(_('No mood selected')) @@ -366,18 +378,21 @@ class StatusChange(Gtk.ApplicationWindow, TimeoutWindow): 'mood-%s' % self._pep_dict['mood'], Gtk.IconSize.MENU) self._ui.mood_button_label.set_text( MOODS[self._pep_dict['mood']]) + self._mood_btns[self._pep_dict['mood']].set_active(True) + self._ui.mood_label.set_text(MOODS[self._pep_dict['mood']]) else: self._ui.mood_image.set_from_pixbuf(None) self._ui.mood_button_label.set_text(_('No mood')) + self._ui.mood_label.set_text(_('No mood selected'))
def _on_preset_select(self, widget): self.stop_timeout() self._ui.preset_popover.popdown() name = widget.get_name() - self._message_buffer.set_text(self._preset_messages_dict[name][0]) - self._pep_dict['activity'] = self._preset_messages_dict[name][1] - self._pep_dict['subactivity'] = self._preset_messages_dict[name][2] - self._pep_dict['mood'] = self._preset_messages_dict[name][3] + self._message_buffer.set_text(self._presets[name][0]) + self._pep_dict['activity'] = self._presets[name][1] + self._pep_dict['subactivity'] = self._presets[name][2] + self._pep_dict['mood'] = self._presets[name][3] self._draw_activity() self._draw_mood()
@@ -421,7 +436,7 @@ class StatusChange(Gtk.ApplicationWindow, TimeoutWindow): app.config.set_per('statusmsg', preset_name, 'mood', mood) self._get_presets()
- if preset_name in self._preset_messages_dict: + if preset_name in self._presets: NewConfirmationDialog( _('Overwrite'), _('Overwrite Status Message?'),
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/dea55bc1e993c37b8d90d731f7ce8508...