From 55694b60bf10b31d0e78a5b1aade51cfcef10bbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Sat, 5 Jan 2019 23:59:30 +0100 Subject: [PATCH] Dont save Gajim settings in bookmarks - Remove print status from bookmarks - Remove minimize on join from bookmarks - Add options to the groupchat menu for both settings Fixes #9463 --- gajim/chat_control_base.py | 18 ---- gajim/common/config.py | 3 +- gajim/common/modules/bookmarks.py | 34 ++----- gajim/data/gui/manage_bookmarks_window.ui | 99 +------------------ gajim/groupchat_control.py | 48 +++++----- gajim/gtk/bookmarks.py | 111 ++++++++-------------- gajim/gtk/discovery.py | 1 - gajim/gtk/join_groupchat.py | 1 - gajim/gui_menu_builder.py | 3 +- 9 files changed, 76 insertions(+), 242 deletions(-) diff --git a/gajim/chat_control_base.py b/gajim/chat_control_base.py index 6d095cf66..9916780fa 100644 --- a/gajim/chat_control_base.py +++ b/gajim/chat_control_base.py @@ -1065,24 +1065,6 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): return _on_ok(self.contact) - def on_minimize_menuitem_toggled(self, widget): - """ - When a groupchat is minimized, unparent the tab, put it in roster etc - """ - old_value = True - non_minimized_gc = app.config.get_per('accounts', self.account, - 'non_minimized_gc').split() - if self.contact.jid in non_minimized_gc: - old_value = False - minimize = widget.get_active() - if not minimize and not self.contact.jid in non_minimized_gc: - non_minimized_gc.append(self.contact.jid) - if minimize and self.contact.jid in non_minimized_gc: - non_minimized_gc.remove(self.contact.jid) - if old_value != minimize: - app.config.set_per('accounts', self.account, 'non_minimized_gc', - ' '.join(non_minimized_gc)) - def on_notify_menuitem_toggled(self, widget): app.config.set_per('rooms', self.contact.jid, 'notify_on_all_messages', widget.get_active()) diff --git a/gajim/common/config.py b/gajim/common/config.py index 6ceff36e0..8a365e36c 100644 --- a/gajim/common/config.py +++ b/gajim/common/config.py @@ -346,7 +346,6 @@ class Config: 'no_log_for': [opt_str, '', _('Space separated list of JIDs for which you do not want to store logs. You can also add account name to log nothing for this account.')], 'sync_logs_with_server': [opt_bool, True, _('On startup, Gajim will download logs stored on server, provided the server supports XEP-0313')], 'allow_no_log_for': [opt_str, '', _('Space separated list of JIDs for which you accept to not log conversations if he does not want to.')], - 'non_minimized_gc': [opt_str, ''], 'attached_gpg_keys': [opt_str, ''], 'keep_alives_enabled': [opt_bool, True, _('Whitespace sent after inactivity')], 'ping_alives_enabled': [opt_bool, True, _('XMPP ping sent after inactivity')], @@ -442,6 +441,8 @@ class Config: 'notify_on_all_messages': [opt_bool, False, _('State whether a notification is created for every message in this room')], 'print_status': [opt_bool, False, _('Show a status message for all status (away, dnd, etc.) changes of users in a group chat')], 'print_join_left': [opt_bool, False, _('Show a status message for every join or leave in a group chat')], + 'minimize_on_autojoin': [opt_bool, True, _('If the group chat is minimized into the roster on autojoin')], + 'minimize_on_close': [opt_bool, True, _('If the group chat is minimized into the roster on close')], }, {}), 'plugins': ({ 'active': [opt_bool, False, _('State whether plugins should be activated on startup (this is saved on Gajim exit). This option SHOULD NOT be used to (de)activate plug-ins. Use GUI instead.')], diff --git a/gajim/common/modules/bookmarks.py b/gajim/common/modules/bookmarks.py index 671384044..1d721f66b 100644 --- a/gajim/common/modules/bookmarks.py +++ b/gajim/common/modules/bookmarks.py @@ -39,8 +39,6 @@ from gajim.common.modules.util import to_xs_boolean log = logging.getLogger('gajim.c.m.bookmarks') -NS_GAJIM_BM = 'xmpp:gajim.org/bookmarks' - class BookmarksData(AbstractPEPData): @@ -222,18 +220,6 @@ class Bookmarks(AbstractPEPModule): if not autojoin_val: # not there (it's optional) autojoin_val = False - minimize_val = conf.getTag('minimize', namespace=NS_GAJIM_BM) - if not minimize_val: - minimize_val = False - else: - minimize_val = minimize_val.getData() - - print_status = conf.getTag('print_status', namespace=NS_GAJIM_BM) - if not print_status: # not there, try old Gajim behaviour - print_status = None - else: - print_status = print_status.getData() - try: jid = helpers.parse_jid(conf.getAttr('jid')) except helpers.InvalidFormat: @@ -245,12 +231,10 @@ class Bookmarks(AbstractPEPModule): 'name': conf.getAttr('name'), 'password': conf.getTagData('password'), 'nick': conf.getTagData('nick'), - 'print_status': print_status } try: bookmark['autojoin'] = from_xs_boolean(autojoin_val) - bookmark['minimize'] = from_xs_boolean(minimize_val) except ValueError as error: log.warning(error) continue @@ -269,8 +253,6 @@ class Bookmarks(AbstractPEPModule): conf_node.setAttr('jid', jid) conf_node.setAttr('autojoin', to_xs_boolean(bm['autojoin'])) conf_node.setAttr('name', bm['name']) - conf_node.setTag('minimize', namespace=NS_GAJIM_BM).setData( - to_xs_boolean(bm['minimize'])) # Only add optional elements if not empty # Note: need to handle both None and '' as empty # thus shouldn't use "is not None" @@ -278,10 +260,6 @@ class Bookmarks(AbstractPEPModule): conf_node.setTagData('nick', bm['nick']) if bm.get('password', None): conf_node.setTagData('password', bm['password']) - if bm.get('print_status', None): - conf_node.setTag( - 'print_status', - namespace=NS_GAJIM_BM).setData(bm['print_status']) return storage_node def _build_node(self, _data): @@ -351,19 +329,21 @@ class Bookmarks(AbstractPEPModule): if jid not in app.gc_connected[self._account]: # we are not already connected log.info('Autojoin Bookmark: %s', jid) + + minimize = app.config.get_per('rooms', jid, + 'minimize_on_autojoin', True) + print(minimize) app.interface.join_gc_room( self._account, jid, bookmark['nick'], - bookmark['password'], minimize=bookmark['minimize']) + bookmark['password'], minimize=minimize) - def add_bookmark(self, name, jid, autojoin, - minimize, password, nick): + def add_bookmark(self, name, jid, autojoin, password, nick): self.bookmarks[jid] = { 'name': name, 'autojoin': autojoin, - 'minimize': minimize, 'password': password, 'nick': nick, - 'print_status': None} + } self.store_bookmarks() app.nec.push_incoming_event( diff --git a/gajim/data/gui/manage_bookmarks_window.ui b/gajim/data/gui/manage_bookmarks_window.ui index 9742f5340..87f015e99 100644 --- a/gajim/data/gui/manage_bookmarks_window.ui +++ b/gajim/data/gui/manage_bookmarks_window.ui @@ -1,5 +1,5 @@ - + @@ -15,6 +15,9 @@ 300 dialog + + + True @@ -31,7 +34,7 @@ False vertical - + True True in @@ -324,95 +327,6 @@ - - - True - True - - - True - False - center - 12 - - - True - False - start - Minimize on Auto Join - - - False - True - 0 - - - - - True - True - end - - - - False - True - end - 1 - - - - - - - - - True - True - - - True - False - Status messages displayed in chat window - center - 18 - - - True - False - start - Status Messages - - - False - True - 0 - - - - - True - False - liststore1 - - - - - 0 - - - - - False - True - end - 1 - - - - - - @@ -481,8 +395,5 @@ - - - diff --git a/gajim/groupchat_control.py b/gajim/groupchat_control.py index 4ad117a1f..d123504bf 100644 --- a/gajim/groupchat_control.py +++ b/gajim/groupchat_control.py @@ -375,14 +375,22 @@ class GroupchatControl(ChatControlBase): act.connect("activate", func) self.parent_win.window.add_action(act) - non_minimized_gc = app.config.get_per( - 'accounts', self.account, 'non_minimized_gc').split() - value = self.contact.jid not in non_minimized_gc + minimize = app.config.get_per( + 'rooms', self.contact.jid, 'minimize_on_close', True) act = Gio.SimpleAction.new_stateful( - 'minimize-' + self.control_id, None, - GLib.Variant.new_boolean(value)) - act.connect('change-state', self._on_minimize) + 'minimize-on-close-' + self.control_id, None, + GLib.Variant.new_boolean(minimize)) + act.connect('change-state', self._on_minimize_on_close) + self.parent_win.window.add_action(act) + + minimize = app.config.get_per( + 'rooms', self.contact.jid, 'minimize_on_autojoin', True) + + act = Gio.SimpleAction.new_stateful( + 'minimize-on-autojoin-' + self.control_id, None, + GLib.Variant.new_boolean(minimize)) + act.connect('change-state', self._on_minimize_on_autojoin) self.parent_win.window.add_action(act) # Enable notify on all for private rooms @@ -684,7 +692,6 @@ class GroupchatControl(ChatControlBase): con.get_module('Bookmarks').add_bookmark(self.name, self.room_jid, True, - True, password, self.nick) self.update_actions() @@ -696,22 +703,15 @@ class GroupchatControl(ChatControlBase): con = app.connections[self.account] con.get_module('MUC').request_voice(self.room_jid) - def _on_minimize(self, action, param): - """ - When a groupchat is minimized, unparent the tab, put it in roster etc - """ + def _on_minimize_on_close(self, action, param): action.set_state(param) - non_minimized_gc = app.config.get_per( - 'accounts', self.account, 'non_minimized_gc').split() + minimize = app.config.set_per( + 'rooms', self.contact.jid, 'minimize_on_close', param.get_boolean()) - minimize = param.get_boolean() - if minimize: - non_minimized_gc.remove(self.contact.jid) - else: - non_minimized_gc.append(self.contact.jid) - - app.config.set_per('accounts', self.account, - 'non_minimized_gc', ' '.join(non_minimized_gc)) + def _on_minimize_on_autojoin(self, action, param): + action.set_state(param) + minimize = app.config.set_per( + 'rooms', self.contact.jid, 'minimize_on_autojoin', param.get_boolean()) def _on_notify_on_all_messages(self, action, param): action.set_state(param) @@ -2310,10 +2310,8 @@ class GroupchatControl(ChatControlBase): def minimizable(self): if self.force_non_minimizable: return False - if self.contact.jid not in app.config.get_per('accounts', self.account, - 'non_minimized_gc').split(' '): - return True - return False + return app.config.get_per('rooms', self.contact.jid, + 'minimize_on_close', True) def minimize(self, status='offline'): # Minimize it diff --git a/gajim/gtk/bookmarks.py b/gajim/gtk/bookmarks.py index 5d0859439..6f1a022b7 100644 --- a/gajim/gtk/bookmarks.py +++ b/gajim/gtk/bookmarks.py @@ -12,6 +12,8 @@ # You should have received a copy of the GNU General Public License # along with Gajim. If not, see . +from enum import IntEnum + from gi.repository import Gtk from gi.repository import Gdk @@ -26,6 +28,16 @@ from gajim.gtk.dialogs import ErrorDialog from gajim.gtk.util import get_builder +class Row(IntEnum): + ACCOUNT_JID = 0 + ROOM_NAME = 1 + ROOM_JID = 2 + AUTOJOIN = 3 + PASSWORD = 4 + NICK = 5 + LABEL = 6 + + class ManageBookmarksWindow: def __init__(self): self.xml = get_builder('manage_bookmarks_window.ui') @@ -34,10 +46,8 @@ class ManageBookmarksWindow: self.ignore_events = False - # Account-JID, RoomName, Room-JID, Autojoin, Minimize, Password, Nick, - # Show_Status - self.treestore = Gtk.TreeStore(str, str, str, bool, bool, str, - str, str, str) + # Account-JID, RoomName, Room-JID, Autojoin, Password, Nick, Name + self.treestore = Gtk.TreeStore(str, str, str, bool, str, str, str) self.treestore.set_sort_column_id(1, Gtk.SortType.ASCENDING) # Store bookmarks in treeview. @@ -45,45 +55,26 @@ class ManageBookmarksWindow: connected_only=True, private_storage_only=True): iter_ = self.treestore.append(None, [ None, account, None, None, - None, None, None, None, account_label]) + None, None, account_label]) con = app.connections[account] bookmarks = con.get_module('Bookmarks').get_sorted_bookmarks() for jid, bookmark in bookmarks.items(): - print_status = bookmark.get('print_status', '') - if print_status not in ('', 'all', 'in_and_out', 'none'): - print_status = '' self.treestore.append(iter_, [account, bookmark['name'], jid, bookmark['autojoin'], - bookmark['minimize'], bookmark['password'], bookmark['nick'], - print_status, bookmark['name']]) - self.print_status_combobox = self.xml.get_object( - 'print_status_combobox') - model = Gtk.ListStore(str, str) - - self.option_list = { - '': _('Default'), 'all': Q_('?print_status:All'), - 'in_and_out': _('Enter and leave only'), - 'none': Q_('?print_status:None')} - for opt, label in sorted(self.option_list.items()): - model.append([label, opt]) - - self.print_status_combobox.set_model(model) - self.print_status_combobox.set_active(1) - self.view = self.xml.get_object('bookmarks_treeview') self.view.set_model(self.treestore) self.view.expand_all() renderer = Gtk.CellRendererText() - column = Gtk.TreeViewColumn('Bookmarks', renderer, text=8) + column = Gtk.TreeViewColumn('Bookmarks', renderer, text=Row.LABEL) self.view.append_column(column) self.selection = self.view.get_selection() @@ -103,7 +94,6 @@ class ManageBookmarksWindow: self.pass_entry = self.xml.get_object('pass_entry') self.pass_entry.connect('changed', self.on_pass_entry_changed) self.autojoin_checkbutton = self.xml.get_object('autojoin_checkbutton') - self.minimize_checkbutton = self.xml.get_object('minimize_checkbutton') self.settings_box = self.xml.get_object('settings_box') self.remove_bookmark_button = self.xml.get_object( 'remove_bookmark_button') @@ -142,7 +132,7 @@ class ManageBookmarksWindow: nick = app.nicks[account] label = _('New Group Chat') iter_ = self.treestore.append(add_to, [ - account, label, '@', False, False, '', nick, 'in_and_out', label]) + account, label, '@', False, '', nick, label]) self.view.expand_row(model.get_path(add_to), True) self.view.set_cursor(model.get_path(iter_)) @@ -208,14 +198,13 @@ class ManageBookmarksWindow: for bm in account.iterchildren(): # create the bookmark-dict bmdict = { - 'name': bm[1], - 'autojoin': bm[3], - 'minimize': bm[4], - 'password': bm[5], - 'nick': bm[6], - 'print_status': bm[7]} + 'name': bm[Row.ROOM_NAME], + 'autojoin': bm[Row.AUTOJOIN], + 'password': bm[Row.PASSWORD], + 'nick': bm[Row.NICK], + } - jid = bm[2] + jid = bm[Row.ROOM_JID] con.get_module('Bookmarks').bookmarks[jid] = bmdict con.get_module('Bookmarks').store_bookmarks() @@ -247,8 +236,8 @@ class ManageBookmarksWindow: return # Fill in the data for childs - self.title_entry.set_text(model[iter_][1]) - room_jid = model[iter_][2] + self.title_entry.set_text(model[iter_][Row.ROOM_NAME]) + room_jid = model[iter_][Row.ROOM_JID] room_jid_s = room_jid.split('@') if len(room_jid_s) == 1: room = '' @@ -260,13 +249,11 @@ class ManageBookmarksWindow: self.room_entry.handler_unblock(self.room_entry_changed_id) self.server_entry.set_text(server) - self.autojoin_checkbutton.set_active(model[iter_][3]) - self.minimize_checkbutton.set_active(model[iter_][4]) + self.autojoin_checkbutton.set_active(model[iter_][Row.AUTOJOIN]) # sensitive only if auto join is checked - self.minimize_checkbutton.set_sensitive(model[iter_][3]) - if model[iter_][5] is not None: - password = model[iter_][5] + if model[iter_][Row.PASSWORD] is not None: + password = model[iter_][Row.PASSWORD] else: password = None @@ -274,16 +261,12 @@ class ManageBookmarksWindow: self.pass_entry.set_text(password) else: self.pass_entry.set_text('') - nick = model[iter_][6] + nick = model[iter_][Row.NICK] if nick: self.nick_entry.set_text(nick) else: self.nick_entry.set_text('') - print_status = model[iter_][7] - opts = sorted(self.option_list.keys()) - self.print_status_combobox.set_active(opts.index(print_status)) - def on_title_entry_changed(self, widget): if self.ignore_events: return @@ -291,7 +274,7 @@ class ManageBookmarksWindow: if iter_: # After removing a bookmark, we got nothing selected if model.iter_parent(iter_): # Don't clear the title field for account nodes - model[iter_][1] = self.title_entry.get_text() + model[iter_][Row.ROOM_NAME] = self.title_entry.get_text() def on_nick_entry_changed(self, widget): if self.ignore_events: @@ -306,9 +289,9 @@ class ManageBookmarksWindow: _('Invalid nickname'), _('Character not allowed'), transient_for=self.window) - self.nick_entry.set_text(model[iter_][6]) + self.nick_entry.set_text(model[iter_][Row.NICK]) return True - model[iter_][6] = nick + model[iter_][Row.NICK] = nick def on_server_entry_focus_out(self, widget, event): if self.ignore_events: @@ -337,9 +320,9 @@ class ManageBookmarksWindow: _('Invalid server'), _('Character not allowed'), transient_for=self.window) - self.server_entry.set_text(model[iter_][2].split('@')[1]) + self.server_entry.set_text(model[iter_][Row.ROOM_JID].split('@')[1]) return True - model[iter_][2] = room_jid + model[iter_][Row.ROOM_JID] = room_jid def on_room_entry_changed(self, widget): if self.ignore_events: @@ -368,39 +351,21 @@ class ManageBookmarksWindow: _('Character not allowed'), transient_for=self.window) return True - model[iter_][2] = room_jid + model[iter_][Row.ROOM_JID] = room_jid def on_pass_entry_changed(self, widget): if self.ignore_events: return (model, iter_) = self.selection.get_selected() if iter_: - model[iter_][5] = self.pass_entry.get_text() + model[iter_][Row.PASSWORD] = self.pass_entry.get_text() def on_autojoin_checkbutton_toggled(self, widget, *args): if self.ignore_events: return (model, iter_) = self.selection.get_selected() if iter_: - model[iter_][3] = self.autojoin_checkbutton.get_active() - self.minimize_checkbutton.set_sensitive(model[iter_][3]) - - def on_minimize_checkbutton_toggled(self, widget, *args): - if self.ignore_events: - return - (model, iter_) = self.selection.get_selected() - if iter_: - model[iter_][4] = self.minimize_checkbutton.get_active() - - def on_print_status_combobox_changed(self, widget): - if self.ignore_events: - return - active = widget.get_active() - model = widget.get_model() - print_status = model[active][1] - (model2, iter_) = self.selection.get_selected() - if iter_: - model2[iter_][7] = print_status + model[iter_][Row.AUTOJOIN] = self.autojoin_checkbutton.get_active() def clear_fields(self): widgets = [ @@ -409,8 +374,6 @@ class ManageBookmarksWindow: for field in widgets: field.set_text('') self.autojoin_checkbutton.set_active(False) - self.minimize_checkbutton.set_active(False) - self.print_status_combobox.set_active(1) def set_sensitive_all(self, sensitive): widgets = [ diff --git a/gajim/gtk/discovery.py b/gajim/gtk/discovery.py index 249c65636..168e1ecf1 100644 --- a/gajim/gtk/discovery.py +++ b/gajim/gtk/discovery.py @@ -1717,7 +1717,6 @@ class MucBrowser(AgentBrowser): con.get_module('Bookmarks').add_bookmark(room_jid.split('@')[0], room_jid, False, - False, '' '') diff --git a/gajim/gtk/join_groupchat.py b/gajim/gtk/join_groupchat.py index 0bbbd0b94..2add5d935 100644 --- a/gajim/gtk/join_groupchat.py +++ b/gajim/gtk/join_groupchat.py @@ -266,7 +266,6 @@ class JoinGroupchatWindow(Gtk.ApplicationWindow): con.get_module('Bookmarks').add_bookmark(name, self.room_jid, autojoin, - True, password, nickname) diff --git a/gajim/gui_menu_builder.py b/gajim/gui_menu_builder.py index c924cda0a..44c993466 100644 --- a/gajim/gui_menu_builder.py +++ b/gajim/gui_menu_builder.py @@ -663,7 +663,8 @@ def get_groupchat_menu(control_id, account, jid): ('win.print-join-left-', _('Show join/leave')), ('win.print-status-', _('Show status changes')), ('win.notify-on-message-', _('Notify on all messages')), - ('win.minimize-', _('Minimize on close')), + ('win.minimize-on-close-', _('Minimize on close')), + ('win.minimize-on-autojoin-', _('Minimize on autojoin')), ]), (_('Sync Threshold'), []), ('win.change-nick-', _('Change Nick')),