Use always an action to open the history window

- Make all menus and shortcuts use the 'app.browse-history' action
- HistoryWindow: Inherit from Gtk.ApplicationWindow
This commit is contained in:
Philipp Hörist 2018-11-04 22:19:58 +01:00
parent 3e387f5215
commit b6c4fcfb54
10 changed files with 306 additions and 312 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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,

View File

@ -278,19 +278,7 @@
</object>
</child>
</object>
<object class="GtkApplicationWindow" id="history_window">
<property name="can_focus">False</property>
<property name="title" translatable="yes">Conversation History</property>
<property name="window_position">center</property>
<property name="show_menubar">False</property>
<signal name="delete-event" handler="on_history_window_delete_event" swapped="no"/>
<signal name="destroy" handler="on_history_window_destroy" swapped="no"/>
<signal name="key-press-event" handler="on_history_window_key_press_event" swapped="no"/>
<child type="titlebar">
<placeholder/>
</child>
<child>
<object class="GtkBox" id="vbox">
<object class="GtkBox" id="history_box">
<property name="width_request">600</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
@ -568,6 +556,4 @@
</packing>
</child>
</object>
</child>
</object>
</interface>

View File

@ -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)

View File

@ -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)

View File

@ -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:

View File

@ -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

View File

@ -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)