diff --git a/gajim/app_actions.py b/gajim/app_actions.py index da01dac4f..bca0703a9 100644 --- a/gajim/app_actions.py +++ b/gajim/app_actions.py @@ -313,10 +313,7 @@ def on_file_transfers(action, param): def on_history(action, param): - if 'logs' in interface.instances: - interface.instances['logs'].window.present() - else: - interface.instances['logs'] = HistoryWindow() + on_browse_history(action, param) def on_open_event(action, param): @@ -369,3 +366,19 @@ def join_groupchat(_action, param): account, jid = param.get_strv() room_jid = jid.split('?')[0] app.interface.join_gc_minimal(account, room_jid) + + +def on_browse_history(_action, param): + jid, account = None, None + if param is not None: + dict_ = param.unpack() + jid = dict_.get('jid') + account = dict_.get('account') + + window = app.get_app_window(HistoryWindow) + if window is None: + HistoryWindow(jid, account) + else: + window.present() + if jid is not None and account is not None: + window.open_history(jid, account) diff --git a/gajim/application.py b/gajim/application.py index bc3e3ec82..e8c1f78f4 100644 --- a/gajim/application.py +++ b/gajim/application.py @@ -418,6 +418,11 @@ class GajimApplication(Gtk.Application): act.connect("activate", app_actions.open_link) self.add_action(act) + act = Gio.SimpleAction.new('browse-history', + GLib.VariantType.new('a{sv}')) + act.connect("activate", app_actions.on_browse_history) + self.add_action(act) + for action in general_actions: action_name, func = action act = Gio.SimpleAction.new(action_name, None) diff --git a/gajim/chat_control.py b/gajim/chat_control.py index e2153c91f..f69294bf9 100644 --- a/gajim/chat_control.py +++ b/gajim/chat_control.py @@ -110,7 +110,7 @@ class ChatControl(ChatControlBase): # Menu for the HeaderBar self.control_menu = gui_menu_builder.get_singlechat_menu( - self.control_id) + self.control_id, self.account, self.contact.jid) settings_menu = self.xml.get_object('settings_menu') settings_menu.set_menu_model(self.control_menu) diff --git a/gajim/chat_control_base.py b/gajim/chat_control_base.py index 6f8958019..b9c61385f 100644 --- a/gajim/chat_control_base.py +++ b/gajim/chat_control_base.py @@ -388,11 +388,6 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): action.connect("change-state", self.change_encryption) self.parent_win.window.add_action(action) - action = Gio.SimpleAction.new( - 'browse-history-%s' % self.control_id, GLib.VariantType.new('s')) - action.connect('activate', self._on_history) - self.parent_win.window.add_action(action) - action = Gio.SimpleAction.new( 'send-file-%s' % self.control_id, None) action.connect('activate', self._on_send_file) @@ -413,21 +408,6 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): # Actions - def _on_history(self, action, param): - """ - When history menuitem is pressed: call history window - """ - jid = param.get_string() - if jid == 'none': - jid = self.contact.jid - - if 'logs' in app.interface.instances: - app.interface.instances['logs'].window.present() - app.interface.instances['logs'].open_history(jid, self.account) - else: - from gajim.gtk.history import HistoryWindow - app.interface.instances['logs'] = HistoryWindow(jid, self.account) - def change_encryption(self, action, param): encryption = param.get_string() if encryption == 'disabled': @@ -1039,20 +1019,6 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): start, end = buffer_.get_bounds() buffer_.delete(start, end) - def _on_history_menuitem_activate(self, widget=None, jid=None): - """ - When history menuitem is pressed: call history window - """ - if not jid: - jid = self.contact.jid - - if 'logs' in app.interface.instances: - app.interface.instances['logs'].window.present() - app.interface.instances['logs'].open_history(jid, self.account) - else: - from gajim.gtk.history import HistoryWindow - app.interface.instances['logs'] = HistoryWindow(jid, self.account) - def _on_send_file(self, action, param): # get file transfer preference ft_pref = app.config.get_per('accounts', self.account, diff --git a/gajim/data/gui/history_window.ui b/gajim/data/gui/history_window.ui index 58ff88463..767d21fad 100644 --- a/gajim/data/gui/history_window.ui +++ b/gajim/data/gui/history_window.ui @@ -278,101 +278,218 @@ - + + 600 + True False - Conversation History - center - False - - - - - - + 18 + 18 + 18 + 18 + vertical + 24 - - 600 + True False - 18 - 18 - 18 - 18 - vertical - 24 + 6 + 12 - + True False - 6 - 12 - - - True - False - start - Chat - - - - 0 - 0 - - - - + start + Chat + + + + 0 + 0 + + + + + True + True + Record history for this chat + + + + 3 + 0 + + + + + True + False + 6 + Record History + + + + 2 + 0 + + + + + 400 + True + False + True + liststore1 + Ttitle + True + 1 + 1 + + + True True - Record history for this chat - + - - 3 - 0 - - - + + + 1 + 0 + + + + + False + True + 0 + + + + + True + False + vertical + + + True + False + + True False - 6 - Record History + + + 300 + True + True + edit-find-symbolic + False + False + + + + False + True + 0 + + + + + True + True + True + start + search_menu + + + True + False + 6 + + + True + False + 3 + 3 + + + False + True + 0 + + + + + True + False + pan-down-symbolic + + + False + True + 1 + + + + + + + False + True + 1 + + - 2 - 0 + False + True + 2 - - 400 + True False - True - liststore1 - Ttitle - True - 1 - 1 - - - + vertical + + True True - + True + more_menu + + + True + False + view-more-symbolic + + + + False + True + 0 + - 1 - 0 + False + True + end + 1 + False @@ -381,193 +498,62 @@ - + True - False + True + True vertical - - True - False - - - True - False - - - 300 - True - True - edit-find-symbolic - False - False - - - - False - True - 0 - - - - - True - True - True - start - search_menu - - - True - False - 6 - - - True - False - 3 - 3 - - - False - True - 0 - - - - - True - False - pan-down-symbolic - - - False - True - 1 - - - - - - - False - True - 1 - - - - - - False - True - 2 - - + + True + True + in - + True - False - vertical - - - True - True - True - more_menu - - - True - False - view-more-symbolic - - - - - False - True - 0 - + True + True + True + + + - - False - True - end - 1 - - - False - True - 0 + True + True - + True True - True - vertical + etched-in + 200 - - True - True - in - - - True - True - True - True - - - - - - - - - True - True - - - - - True - True - etched-in - 200 - - - - - - True - True - + - True - True - 1 + True + True - False + True True - 2 + 1 + + False + True + 2 + diff --git a/gajim/groupchat_control.py b/gajim/groupchat_control.py index 584c6d29b..865e60723 100644 --- a/gajim/groupchat_control.py +++ b/gajim/groupchat_control.py @@ -494,7 +494,9 @@ class GroupchatControl(ChatControlBase): # GC Roster tooltip self.gc_tooltip = GCTooltip() - self.control_menu = gui_menu_builder.get_groupchat_menu(self.control_id) + self.control_menu = gui_menu_builder.get_groupchat_menu(self.control_id, + self.account, + self.room_jid) settings_menu = self.xml.get_object('settings_menu') settings_menu.set_menu_model(self.control_menu) @@ -2714,8 +2716,11 @@ class GroupchatControl(ChatControlBase): self.handlers[id_] = item item = xml.get_object('history_menuitem') - id_ = item.connect('activate', self.on_history, nick) - self.handlers[id_] = item + item.set_action_name('app.browse-history') + dict_ = {'jid': GLib.Variant('s', fjid), + 'account': GLib.Variant('s', self.account)} + variant = GLib.Variant('a{sv}', dict_) + item.set_action_target_value(variant) item = xml.get_object('add_to_roster_menuitem') our_jid = app.get_jid_from_account(self.account) @@ -2981,10 +2986,6 @@ class GroupchatControl(ChatControlBase): app.interface.instances[self.account]['infos'][contact.jid] = \ vcard.VcardWindow(contact, self.account, gc_contact) - def on_history(self, widget, nick): - jid = app.construct_fjid(self.room_jid, nick) - self._on_history_menuitem_activate(widget=widget, jid=jid) - def on_add_to_roster(self, widget, jid): AddNewContactWindow(self.account, jid) diff --git a/gajim/gtk/history.py b/gajim/gtk/history.py index 72cee6414..d2223befa 100644 --- a/gajim/gtk/history.py +++ b/gajim/gtk/history.py @@ -69,14 +69,17 @@ class Column(IntEnum): LOG_LINE_ID = 5 -class HistoryWindow: - """ - Class for browsing logs of conversations with contacts - """ - +class HistoryWindow(Gtk.ApplicationWindow): def __init__(self, jid=None, account=None): + Gtk.ApplicationWindow.__init__(self) + self.set_application(app.app) + self.set_position(Gtk.WindowPosition.CENTER) + self.set_show_menubar(False) + self.set_title(_('Conversation History')) + self._ui = get_builder('history_window.ui') - self._ui.history_window.set_application(app.app) + + self.add(self._ui.history_box) self.history_textview = conversation_textview.ConversationTextview( account, used_in_history_window=True) @@ -130,15 +133,18 @@ class HistoryWindow: else: self._load_history(None) - resize_window(self._ui.history_window, + resize_window(self, app.config.get('history_window_width'), app.config.get('history_window_height')) - move_window(self._ui.history_window, + move_window(self, app.config.get('history_window_x-position'), app.config.get('history_window_y-position')) self._ui.connect_signals(self) - self._ui.history_window.show_all() + self.connect('delete-event', self._on_delete) + self.connect('destroy', self._on_destroy) + self.connect('key-press-event', self._on_key_press) + self.show_all() # PluginSystem: adding GUI extension point for # HistoryWindow instance object @@ -255,21 +261,20 @@ class HistoryWindow: break return account - def on_history_window_delete_event(self, widget, *args): + def _on_delete(self, widget, *args): self.save_state() - def on_history_window_destroy(self, widget): + def _on_destroy(self, widget): # PluginSystem: removing GUI extension points connected with # HistoryWindow instance object app.plugin_manager.remove_gui_extension_point( 'history_window', self) self.history_textview.del_handlers() - del app.interface.instances['logs'] - def on_history_window_key_press_event(self, widget, event): + def _on_key_press(self, widget, event): if event.keyval == Gdk.KEY_Escape: self.save_state() - self._ui.history_window.destroy() + self.destroy() def on_jid_entry_match_selected(self, widget, model, iter_, *args): self._jid_entry_search(model[iter_][1]) @@ -799,8 +804,8 @@ class HistoryWindow: self._ui.results_scrolledwindow.set_property('visible', False) def save_state(self): - x, y = self._ui.history_window.get_window().get_root_origin() - width, height = self._ui.history_window.get_size() + x, y = self.get_window().get_root_origin() + width, height = self.get_size() app.config.set('history_window_x-position', x) app.config.set('history_window_y-position', y) diff --git a/gajim/gui_menu_builder.py b/gajim/gui_menu_builder.py index bd24b53d3..f84d6c804 100644 --- a/gajim/gui_menu_builder.py +++ b/gajim/gui_menu_builder.py @@ -272,7 +272,12 @@ control=None, gc_contact=None, is_anonymous=True): rename_menuitem.connect('activate', roster.on_rename, 'contact', jid, account) - history_menuitem.connect('activate', roster.on_history, contact, account) + + history_menuitem.set_action_name('app.browse-history') + dict_ = {'jid': GLib.Variant('s', contact.jid), + 'account': GLib.Variant('s', account)} + variant = GLib.Variant('a{sv}', dict_) + history_menuitem.set_action_target_value(variant) if control: convert_to_gc_menuitem.connect('activate', @@ -605,7 +610,7 @@ def show_save_as_menu(sha, name): menu.popup_at_pointer() -def get_singlechat_menu(control_id): +def get_singlechat_menu(control_id, account, jid): singlechat_menu = [ (_('Send File…'), [ ('win.send-file-httpupload-', _('Upload File…')), @@ -616,7 +621,7 @@ def get_singlechat_menu(control_id): ('win.toggle-audio-', _('Audio Session')), ('win.toggle-video-', _('Video Session')), ('win.information-', _('Information')), - ('win.browse-history-', _('History')), + ('app.browse-history', _('History')), ] def build_menu(preset): @@ -624,8 +629,14 @@ def get_singlechat_menu(control_id): for item in preset: if isinstance(item[1], str): action_name, label = item - if action_name == 'win.browse-history-': - menu.append(label, action_name + control_id + '::none') + if action_name == 'app.browse-history': + menuitem = Gio.MenuItem.new(label, action_name) + dict_ = {'account': GLib.Variant('s', account), + 'jid': GLib.Variant('s', jid)} + variant_dict = GLib.Variant('a{sv}', dict_) + menuitem.set_action_and_target_value(action_name, + variant_dict) + menu.append_item(menuitem) else: menu.append(label, action_name + control_id) else: @@ -638,7 +649,7 @@ def get_singlechat_menu(control_id): return build_menu(singlechat_menu) -def get_groupchat_menu(control_id): +def get_groupchat_menu(control_id, account, jid): groupchat_menu = [ (_('Manage Room'), [ ('win.change-subject-', _('Change Subject')), @@ -653,7 +664,7 @@ def get_groupchat_menu(control_id): ('win.notify-on-message-', _('Notify on all messages')), ('win.minimize-', _('Minimize on close')), ('win.execute-command-', _('Execute command')), - ('win.browse-history-', _('History')), + ('app.browse-history', _('History')), ('win.disconnect-', _('Disconnect')), ] @@ -662,8 +673,14 @@ def get_groupchat_menu(control_id): for item in preset: if isinstance(item[1], str): action_name, label = item - if action_name == 'win.browse-history-': - menu.append(label, action_name + control_id + '::none') + if action_name == 'app.browse-history': + menuitem = Gio.MenuItem.new(label, action_name) + dict_ = {'account': GLib.Variant('s', account), + 'jid': GLib.Variant('s', jid)} + variant_dict = GLib.Variant('a{sv}', dict_) + menuitem.set_action_and_target_value(action_name, + variant_dict) + menu.append_item(menuitem) else: menu.append(label, action_name + control_id) else: diff --git a/gajim/message_window.py b/gajim/message_window.py index 18c15ec44..1132548f7 100644 --- a/gajim/message_window.py +++ b/gajim/message_window.py @@ -355,9 +355,10 @@ class MessageWindow: if keyval == Gdk.KEY_h: # CTRL + h if Gtk.Settings.get_default().get_property( 'gtk-key-theme-name') != 'Emacs': - arg = GLib.Variant('s', 'none') - self.window.lookup_action( - 'browse-history-%s' % control.control_id).activate(arg) + dict_ = {'jid': GLib.Variant('s', control.contact.jid), + 'account': GLib.Variant('s', control.account)} + variant = GLib.Variant('a{sv}', dict_) + app.app.activate_action('browse-history', variant) return True elif control.type_id == message_control.TYPE_CHAT and \ keyval == Gdk.KEY_f: # CTRL + f diff --git a/gajim/roster_window.py b/gajim/roster_window.py index 7caa9c379..221f061ce 100644 --- a/gajim/roster_window.py +++ b/gajim/roster_window.py @@ -78,7 +78,6 @@ from gajim.gtk.bookmarks import ManageBookmarksWindow from gajim.gtk.account_wizard import AccountCreationWizard from gajim.gtk.service_registration import ServiceRegistration from gajim.gtk.discovery import ServiceDiscoveryWindow -from gajim.gtk.history import HistoryWindow from gajim.gtk.accounts import AccountsWindow from gajim.gtk.tooltips import RosterTooltip from gajim.gtk.adhoc_commands import CommandWindow @@ -3041,16 +3040,6 @@ class RosterWindow: def on_edit_groups(self, widget, list_): dialogs.EditGroupsDialog(list_) - def on_history(self, widget, contact, account): - """ - When history menuitem is activated: call log window - """ - if 'logs' in app.interface.instances: - app.interface.instances['logs'].window.present() - app.interface.instances['logs'].open_history(contact.jid, account) - else: - app.interface.instances['logs'] = HistoryWindow(contact.jid, account) - def on_disconnect(self, widget, jid, account): """ When disconnect menuitem is activated: disconnect from room @@ -3756,6 +3745,9 @@ class RosterWindow: self.on_info(widget, contact, account) elif event.get_state() & Gdk.ModifierType.CONTROL_MASK and event.keyval == \ Gdk.KEY_h: + if app.config.get('one_message_window') == 'always_with_roster': + # Let MessageWindow handle this + return treeselection = self.tree.get_selection() model, list_of_paths = treeselection.get_selected_rows() if len(list_of_paths) != 1: @@ -3767,7 +3759,10 @@ class RosterWindow: account = model[path][Column.ACCOUNT] contact = app.contacts.get_first_contact_from_jid(account, jid) - self.on_history(widget, contact, account) + dict_ = {'jid': GLib.Variant('s', jid), + 'account': GLib.Variant('s', account)} + app.app.activate_action('browse-history', + GLib.Variant('a{sv}', dict_)) def on_roster_window_popup_menu(self, widget): event = Gdk.Event.new(Gdk.EventType.KEY_PRESS) @@ -5392,7 +5387,12 @@ class RosterWindow: menu.append(item) history_menuitem = Gtk.MenuItem.new_with_mnemonic(_('_History')) - history_menuitem.connect('activate', self.on_history, contact, account) + history_menuitem.set_action_name('app.browse-history') + dict_ = {'jid': GLib.Variant('s', contact.jid), + 'account': GLib.Variant('s', account)} + variant = GLib.Variant('a{sv}', dict_) + history_menuitem.set_action_target_value(variant) + menu.append(history_menuitem) event_button = gtkgui_helpers.get_possible_button_event(event)