gajim.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2026
October
September
August
July
June
May
April
March
February
January
2025
December
November
October
September
August
July
June
May
April
March
February
January
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
List overview
Download
Commits
January 2022
----- 2026 -----
October 2026
September 2026
August 2026
July 2026
June 2026
May 2026
April 2026
March 2026
February 2026
January 2026
----- 2025 -----
December 2025
November 2025
October 2025
September 2025
August 2025
July 2025
June 2025
May 2025
April 2025
March 2025
February 2025
January 2025
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
commits@gajim.org
1 participants
161 discussions
Start a n
N
ew thread
[Git][gajim/gajim][master] Main: Typing
by Daniel Brötzmann (@wurstsalat)
10 Jan '22
10 Jan '22
Daniel Brötzmann pushed to branch master at gajim / gajim Commits: 74ee7e1e by wurstsalat at 2022-01-10T17:36:00+01:00 Main: Typing - - - - - 1 changed file: - gajim/gtk/main.py Changes: ===================================== gajim/gtk/main.py ===================================== @@ -14,6 +14,7 @@ from __future__ import annotations +from typing import Any from typing import Optional from typing import Generator @@ -31,6 +32,11 @@ from gajim.common import ged from gajim.common.const import Display from gajim.common.const import Direction +from gajim.common.events import ApplicationEvent +from gajim.common.events import AccountEnabled +from gajim.common.events import AccountDisabled +from gajim.common.events import ShowChanged +from gajim.common.events import SignedIn from gajim.common.helpers import ask_for_status_message from gajim.common.i18n import _ from gajim.common.ged import EventHelper @@ -39,7 +45,6 @@ from .adhoc import AdHocCommand from .account_side_bar import AccountSideBar from .app_side_bar import AppSideBar -from .workspace_side_bar import Workspace from .workspace_side_bar import WorkspaceSideBar from .main_stack import MainStack from .chat_list import ChatList @@ -59,7 +64,7 @@ class MainWindow(Gtk.ApplicationWindow, EventHelper): - def __init__(self): + def __init__(self) -> None: Gtk.ApplicationWindow.__init__(self) EventHelper.__init__(self) self.set_application(app.app) @@ -134,7 +139,7 @@ def __init__(self): app.interface.systray.connect_unread_changed( self._chat_page.get_chat_list_stack()) - def _start_timers(self): + def _start_timers(self) -> None: GLib.timeout_add_seconds(UNLOAD_CHAT_TIME, self._chat_page.unload_idle_chats) @@ -159,11 +164,11 @@ def _prepare_window(self) -> None: app.settings.get('trayicon') != 'always'): self.show_all() - def _on_account_enabled(self, event): + def _on_account_enabled(self, event: AccountEnabled) -> None: self._account_side_bar.add_account(event.account) self._main_stack.add_account_page(event.account) - def _on_account_disabled(self, event): + def _on_account_disabled(self, event: AccountDisabled) -> None: workspace_id = self._workspace_side_bar.get_first_workspace() self.activate_workspace(workspace_id) self._account_side_bar.remove_account(event.account) @@ -171,17 +176,17 @@ def _on_account_disabled(self, event): self._main_stack.remove_chats_for_account(event.account) @staticmethod - def _on_our_show(event): + def _on_our_show(event: ShowChanged) -> None: if event.show == 'offline': app.app.set_account_actions_state(event.account) app.app.update_app_actions_state() @staticmethod - def _on_signed_in(event): + def _on_signed_in(event: SignedIn) -> None: app.app.set_account_actions_state(event.account, True) app.app.update_app_actions_state() - def _add_actions(self): + def _add_actions(self) -> None: actions = [ ('add-workspace', 's', self._add_workspace), ('edit-workspace', 's', self._edit_workspace), @@ -200,7 +205,7 @@ def _add_actions(self): act.connect('activate', func) self.add_action(act) - def _add_actions2(self): + def _add_actions2(self) -> None: actions = [ 'change-nickname', 'change-subject', @@ -243,7 +248,7 @@ def _add_actions2(self): def _on_action(self, action: Gio.SimpleAction, - _param: Optional[GLib.Variant]) -> None: + _param: Optional[GLib.Variant]) -> Optional[int]: control = self.get_active_control() if control is None: @@ -287,7 +292,10 @@ def _on_action(self, return None - def _on_window_motion_notify(self, _widget, _event): + def _on_window_motion_notify(self, + _widget: Gtk.ApplicationWindow, + _event: Gdk.EventMotion + ) -> None: control = self.get_active_control() if control is None: return @@ -297,7 +305,10 @@ def _on_window_motion_notify(self, _widget, _event): client.get_module('Chatstate').set_mouse_activity( control.contact, control.msg_textview.has_text()) - def _on_window_delete(self, _widget, _event): + def _on_window_delete(self, + _widget: Gtk.ApplicationWindow, + _event: Gdk.Event + ) -> bool: # Main window X button was clicked if app.settings.get('quit_on_main_window_x_button'): self.quit() @@ -313,7 +324,7 @@ def _on_window_delete(self, _widget, _event): self.iconify() return True - def _on_ok(is_checked): + def _on_ok(is_checked: bool) -> None: if is_checked: app.settings.set('quit_on_main_window_x_button', True) self.quit() @@ -329,7 +340,7 @@ def _on_ok(is_checked): callback=_on_ok)]).show() return True - def _set_startup_finished(self): + def _set_startup_finished(self) -> None: self._startup_finished = True self._chat_page.set_startup_finished() @@ -563,7 +574,10 @@ def mark_as_read(self, account: str, jid: JID, chat_list_stack = self._chat_page.get_chat_list_stack() chat_list_stack.mark_as_read(account, jid) - def _on_window_active(self, window, _param): + def _on_window_active(self, + window: Gtk.ApplicationWindow, + _param: Any + ) -> None: is_active = window.get_property('is-active') if not is_active: return @@ -596,7 +610,7 @@ def block_contact(self, account: str, jid: str) -> None: return # TODO: Keep "confirm_block" setting? - def _block_contact(report=None): + def _block_contact(report: Optional[str] = None) -> None: client.get_module('Blocking').block([contact.jid], report) self._chat_page.remove_chat(account, contact.jid) @@ -657,7 +671,7 @@ def _load_chats(self) -> None: self._set_startup_finished() - def _on_event(self, event): + def _on_event(self, event: ApplicationEvent) -> None: if event.name == 'update-roster-avatar': return @@ -688,7 +702,7 @@ def _on_event(self, event): self._main_stack.process_event(event) - def quit(self): + def quit(self) -> None: accounts = list(app.connections.keys()) get_msg = False for acct in accounts: @@ -704,7 +718,7 @@ def quit(self): 'last_main_window_visible', self.get_property('visible')) app.settings.save() - def on_continue2(message): + def on_continue2(message: Optional[str]) -> None: if 'file_transfers' not in app.interface.instances: app.app.start_shutdown(message=message) return @@ -733,7 +747,7 @@ def on_continue2(message): return app.app.start_shutdown(message=message) - def on_continue(message): + def on_continue(message: Optional[str]) -> None: if message is None: # user pressed Cancel to change status message dialog return View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/74ee7e1e5674ccc339161aebaaaa67e3…
-- View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/74ee7e1e5674ccc339161aebaaaa67e3…
You're receiving this email because of your account on
dev.gajim.org
.
1
0
0
0
[Git][gajim/gajim][master] Add new PM chat to the same workspace the MUC resides in
by Daniel Brötzmann (@wurstsalat)
10 Jan '22
10 Jan '22
Daniel Brötzmann pushed to branch master at gajim / gajim Commits: 74a94b6a by wurstsalat at 2022-01-10T17:17:23+01:00 Add new PM chat to the same workspace the MUC resides in - - - - - 2 changed files: - gajim/gtk/chat_list_stack.py - gajim/gtk/main.py Changes: ===================================== gajim/gtk/chat_list_stack.py ===================================== @@ -182,7 +182,7 @@ def add_chat(self, workspace_id: str, account: str, jid: JID, type_: str, chat_list.add_chat(account, jid, type_, pinned) def select_chat(self, account: str, jid: JID) -> None: - chat_list = self._find_chat(account, jid) + chat_list = self.find_chat(account, jid) if chat_list is None: return @@ -241,7 +241,7 @@ def remove_chats_for_account(self, account: str) -> None: chat_list.remove_chats_for_account(account) self.store_open_chats(workspace_id) - def _find_chat(self, account: str, jid: JID) -> Optional[ChatList]: + def find_chat(self, account: str, jid: JID) -> Optional[ChatList]: for chat_list in self._chat_lists.values(): if chat_list.contains_chat(account, jid): return chat_list @@ -292,7 +292,7 @@ def process_event(self, event: ApplicationEvent) -> None: if event.name not in HANDLED_EVENTS: return - chat_list = self._find_chat(event.account, event.jid) + chat_list = self.find_chat(event.account, event.jid) if chat_list is None: return chat_list.process_event(event) ===================================== gajim/gtk/main.py ===================================== @@ -349,7 +349,7 @@ def show_account_page(self, account: str) -> None: self._account_side_bar.activate_account_page(account) self._main_stack.show_account(account) - def get_active_workspace(self) -> Optional[Workspace]: + def get_active_workspace(self) -> Optional[str]: return self._workspace_side_bar.get_active_workspace() def is_chat_active(self, account: str, jid: JID) -> bool: @@ -458,6 +458,8 @@ def add_chat(self, workspace: str = 'default') -> None: if workspace == 'current': workspace_id = self.get_active_workspace() + if workspace_id is None: + workspace_id = self._workspace_side_bar.get_first_workspace() else: workspace_id = self._workspace_side_bar.get_first_workspace() self._chat_page.add_chat_for_workspace(workspace_id, @@ -466,11 +468,18 @@ def add_chat(self, type_, select=select) - def add_private_chat(self, account: str, jid: JID, + def add_private_chat(self, + account: str, + jid: JID, select: bool = False) -> None: - workspace_id = self.get_active_workspace() - if workspace_id is None: + # Try to add private chat to the same workspace the MUC resides in + chat_list_stack = self._chat_page.get_chat_list_stack() + chat_list = chat_list_stack.find_chat(account, jid.new_as_bare()) + if chat_list is not None: + workspace_id = chat_list.workspace_id + else: workspace_id = self._workspace_side_bar.get_first_workspace() + self._chat_page.add_chat_for_workspace(workspace_id, account, jid, @@ -659,8 +668,7 @@ def _on_event(self, event): return if event.properties.is_muc_pm: self.add_private_chat(event.account, - event.properties.jid, - 'pm') + event.properties.jid) else: jid = event.properties.jid.new_as_bare() self.add_chat(event.account, jid, 'contact') View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/74a94b6a7e97febb7c78967d3f581e7f…
-- View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/74a94b6a7e97febb7c78967d3f581e7f…
You're receiving this email because of your account on
dev.gajim.org
.
1
0
0
0
[Git][gajim/gajim][master] Chat menu: Remove Ad-Hoc-MUC, improve Add Contact
by Daniel Brötzmann (@wurstsalat)
10 Jan '22
10 Jan '22
Daniel Brötzmann pushed to branch master at gajim / gajim Commits: e6379163 by wurstsalat at 2022-01-10T16:34:04+01:00 Chat menu: Remove Ad-Hoc-MUC, improve Add Contact - - - - - 1 changed file: - gajim/gtk/menus.py Changes: ===================================== gajim/gtk/menus.py ===================================== @@ -53,6 +53,7 @@ def get_singlechat_menu(control_id: str, ) -> Gio.Menu: client = app.get_client(account) is_self_contact = jid.bare == client.get_own_jid().bare + contact = client.get_module('Contacts').get_contact(jid) singlechat_menu: list[tuple[str, Any]] = [ (_('Send File'), [ @@ -61,17 +62,21 @@ def get_singlechat_menu(control_id: str, ]) ] - additional_menu = [ + additional_menu: list[tuple[str, Any]] = [ ('win.send-marker-', _('Send Read Markers')), (_('Send Chatstate'), ['chatstate']), - ('win.invite-contacts-', _('Invite Contacts…')), - ('win.add-to-roster-', _('Add to Contact List…')), ('win.block-contact-', _('Block Contact…')), ('win.start-call-', _('Start Call…')), ('win.information-', _('Information')), ('app.remove-history', _('Remove History')) ] + if not contact.is_in_roster: + if (type_.is_chat or + (type_.is_privatechat and contact.real_jid is not None)): + additional_menu.append( + ('win.add-to-roster-', _('Add to Contact List…'))) + if is_self_contact: singlechat_menu.append(('profile', _('Profile'))) else: View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/e637916305c8023d43b3645aec0390ee…
-- View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/e637916305c8023d43b3645aec0390ee…
You're receiving this email because of your account on
dev.gajim.org
.
1
0
0
0
[Git][gajim/gajim][master] Contacts: Return always BareContact for get_real_contact()
by Philipp Hörist (@lovetox)
10 Jan '22
10 Jan '22
Philipp Hörist pushed to branch master at gajim / gajim Commits: 734ef1da by lovetox at 2022-01-10T14:18:26+01:00 Contacts: Return always BareContact for get_real_contact() - - - - - 1 changed file: - gajim/common/modules/contacts.py Changes: ===================================== gajim/common/modules/contacts.py ===================================== @@ -659,7 +659,8 @@ def get_real_contact(self) -> Optional[BareContact]: jid = self._presence.real_jid if jid is None: return None - return self._client.get_module('Contacts').get_contact(jid) + return self._client.get_module('Contacts').get_contact( + jid.new_as_bare()) @property def affiliation(self) -> Affiliation: View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/734ef1da0cc1f3ed99a15c10d9b891d2…
-- View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/734ef1da0cc1f3ed99a15c10d9b891d2…
You're receiving this email because of your account on
dev.gajim.org
.
1
0
0
0
[Git][gajim/gajim][master] 3 commits: SideBarSwitcher: Refactor
by Philipp Hörist (@lovetox)
10 Jan '22
10 Jan '22
Philipp Hörist pushed to branch master at gajim / gajim Commits: 8bdfd833 by lovetox at 2022-01-09T23:52:04+01:00 SideBarSwitcher: Refactor - Add type annotations - Add posibility to hide all rows at start - - - - - bee1a5a7 by lovetox at 2022-01-10T14:14:37+01:00 Contacts: Add new methods - get_address() - get_real_contact() - resource property - - - - - 0f0c2db4 by lovetox at 2022-01-10T14:14:43+01:00 ContactInfo: Refactor Dialog - Add type annotations - Simplify code and make it more readable - - - - - 6 changed files: - gajim/common/modules/contacts.py - gajim/data/gui/contact_info.ui - gajim/gtk/builder.pyi - gajim/gtk/contact_info.py - gajim/gtk/sidebar_switcher.py - pyrightconfig.json Changes: ===================================== gajim/common/modules/contacts.py ===================================== @@ -213,6 +213,9 @@ def is_groupchat(self) -> bool: def is_pm_contact(self) -> bool: return False + def get_address(self, _prefer_real: bool = True) -> JID: + return self._jid + def force_chatstate_update(self) -> None: for contact in self._resources.values(): contact.notify('chatstate-update') @@ -417,6 +420,10 @@ def supports(self, requested_feature: str) -> bool: return False return CommonContact.supports(self, requested_feature) + @property + def resource(self) -> str: + return self._jid.resource + @property def identity_type(self) -> Optional[str]: disco_info = app.storage.cache.get_last_disco_info(self._jid) @@ -592,6 +599,16 @@ def __init__(self, logger: logging.Logger, jid: JID, account: str) -> None: self._presence = UNKNOWN_MUC_PRESENCE + @property + def resource(self) -> str: + return self._jid.resource + + def get_address(self, prefer_real: bool = True) -> JID: + jid = self._presence.real_jid + if jid is None or not prefer_real: + return self._jid + return jid + def supports(self, requested_feature: str) -> bool: if not self.is_available: return False @@ -638,6 +655,12 @@ def name(self) -> str: def real_jid(self) -> Optional[JID]: return self._presence.real_jid + def get_real_contact(self) -> Optional[BareContact]: + jid = self._presence.real_jid + if jid is None: + return None + return self._client.get_module('Contacts').get_contact(jid) + @property def affiliation(self) -> Affiliation: return self._presence.affiliation ===================================== gajim/data/gui/contact_info.ui ===================================== @@ -2,6 +2,174 @@ <!-- Generated with glade 3.38.2 --> <interface> <requires lib="gtk+" version="3.24"/> + <!-- n-columns=2 n-rows=6 --> + <object class="GtkGrid" id="devices_grid"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="row-spacing">6</property> + <property name="column-spacing">12</property> + <property name="column-homogeneous">True</property> + <child> + <object class="GtkLabel"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="label" translatable="yes">Status</property> + <property name="xalign">1</property> + <style> + <class name="dim-label"/> + </style> + </object> + <packing> + <property name="left-attach">0</property> + <property name="top-attach">1</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="priority_label"> + <property name="can-focus">False</property> + <property name="no-show-all">True</property> + <property name="label" translatable="yes">Priority</property> + <property name="xalign">1</property> + <style> + <class name="dim-label"/> + </style> + </object> + <packing> + <property name="left-attach">0</property> + <property name="top-attach">2</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="software_label"> + <property name="can-focus">False</property> + <property name="no-show-all">True</property> + <property name="label" translatable="yes">Software</property> + <property name="xalign">1</property> + <style> + <class name="dim-label"/> + </style> + </object> + <packing> + <property name="left-attach">0</property> + <property name="top-attach">3</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="system_label"> + <property name="can-focus">False</property> + <property name="no-show-all">True</property> + <property name="label" translatable="yes">Operating System</property> + <property name="xalign">1</property> + <style> + <class name="dim-label"/> + </style> + </object> + <packing> + <property name="left-attach">0</property> + <property name="top-attach">4</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="time_label"> + <property name="can-focus">False</property> + <property name="no-show-all">True</property> + <property name="label" translatable="yes">Local Time</property> + <property name="xalign">1</property> + <style> + <class name="dim-label"/> + </style> + </object> + <packing> + <property name="left-attach">0</property> + <property name="top-attach">5</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="status_value"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="xalign">0</property> + </object> + <packing> + <property name="left-attach">1</property> + <property name="top-attach">1</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="priority_value"> + <property name="can-focus">False</property> + <property name="no-show-all">True</property> + <property name="xalign">0</property> + </object> + <packing> + <property name="left-attach">1</property> + <property name="top-attach">2</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="software_value"> + <property name="can-focus">False</property> + <property name="no-show-all">True</property> + <property name="xalign">0</property> + </object> + <packing> + <property name="left-attach">1</property> + <property name="top-attach">3</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="system_value"> + <property name="can-focus">False</property> + <property name="no-show-all">True</property> + <property name="xalign">0</property> + </object> + <packing> + <property name="left-attach">1</property> + <property name="top-attach">4</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="time_value"> + <property name="can-focus">False</property> + <property name="no-show-all">True</property> + <property name="xalign">0</property> + </object> + <packing> + <property name="left-attach">1</property> + <property name="top-attach">5</property> + </packing> + </child> + <child> + <object class="GtkBox" id="resource_box"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="margin-bottom">12</property> + <property name="spacing">12</property> + <child> + <object class="GtkLabel" id="resource_label"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <style> + <class name="bold16"/> + </style> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <placeholder/> + </child> + </object> + <packing> + <property name="left-attach">0</property> + <property name="top-attach">0</property> + <property name="width">2</property> + </packing> + </child> + </object> <object class="GtkListStore" id="groups_model"> <columns> <!-- column-name is_in_group --> @@ -20,6 +188,8 @@ <property name="height-request">450</property> <property name="visible">True</property> <property name="can-focus">False</property> + <property name="hexpand">True</property> + <property name="vexpand">True</property> <property name="orientation">vertical</property> <child> <object class="GtkRevealer" id="header_revealer"> @@ -171,8 +341,7 @@ <object class="GtkGrid" id="group_chat_grid"> <property name="can-focus">False</property> <property name="no-show-all">True</property> - <property name="halign">center</property> - <property name="row-spacing">6</property> + <property name="row-spacing">12</property> <property name="column-spacing">12</property> <property name="column-homogeneous">True</property> <child> @@ -180,6 +349,7 @@ <property name="visible">True</property> <property name="can-focus">False</property> <property name="halign">end</property> + <property name="margin-end">18</property> <property name="label" translatable="yes">Role</property> <style> <class name="dim-label"/> @@ -206,6 +376,7 @@ <property name="visible">True</property> <property name="can-focus">False</property> <property name="halign">end</property> + <property name="margin-end">18</property> <property name="label" translatable="yes">Affiliation</property> <style> <class name="dim-label"/> @@ -711,42 +882,15 @@ <property name="visible">True</property> <property name="can-focus">False</property> <child> - <object class="GtkBox"> + <object class="GtkBox" id="devices_box"> <property name="visible">True</property> <property name="can-focus">False</property> <property name="halign">center</property> <property name="border-width">18</property> - <property name="spacing">12</property> - <child> - <!-- n-columns=1 n-rows=1 --> - <object class="GtkGrid" id="devices_grid"> - <property name="visible">True</property> - <property name="can-focus">False</property> - <property name="row-spacing">6</property> - <property name="column-spacing">12</property> - <child> - <placeholder/> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> - </child> + <property name="orientation">vertical</property> + <property name="spacing">24</property> <child> - <object class="GtkSpinner" id="devices_spinner"> - <property name="visible">True</property> - <property name="can-focus">False</property> - <property name="halign">end</property> - <property name="valign">start</property> - <property name="active">True</property> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">1</property> - </packing> + <placeholder/> </child> </object> </child> ===================================== gajim/gtk/builder.pyi ===================================== @@ -595,6 +595,18 @@ class ChatPanedBuilder(Builder): class ContactInfoBuilder(Builder): + devices_grid: Gtk.Grid + priority_label: Gtk.Label + software_label: Gtk.Label + system_label: Gtk.Label + time_label: Gtk.Label + status_value: Gtk.Label + priority_value: Gtk.Label + software_value: Gtk.Label + system_value: Gtk.Label + time_value: Gtk.Label + resource_box: Gtk.Box + resource_label: Gtk.Label groups_model: Gtk.ListStore main_grid: Gtk.Grid header_revealer: Gtk.Revealer @@ -627,8 +639,7 @@ class ContactInfoBuilder(Builder): scrolledwindow_annotation: Gtk.ScrolledWindow textview_annotation: Gtk.TextView devices_stack: Gtk.Stack - devices_grid: Gtk.Grid - devices_spinner: Gtk.Spinner + devices_box: Gtk.Box class GroupchatInfoScrolledBuilder(Builder): ===================================== gajim/gtk/contact_info.py ===================================== @@ -1,4 +1,3 @@ -# # This file is part of Gajim. # # Gajim is free software; you can redistribute it and/or modify @@ -13,26 +12,36 @@ # You should have received a copy of the GNU General Public License # along with Gajim. If not, see <
http://www.gnu.org/licenses/
>. -import logging +from __future__ import annotations + +from typing import Optional +from typing import Union +import logging from enum import IntEnum from gi.repository import Gtk -from gi.repository import GLib from gi.repository import Gdk +from gi.repository import GObject +from nbxmpp.task import Task from nbxmpp.errors import StanzaError -from nbxmpp.structs import AnnotationNote +from nbxmpp.structs import AnnotationNote, SoftwareVersionResult from nbxmpp.modules.vcard4 import VCard from gajim.common import app from gajim.common import ged from gajim.common.const import AvatarSize +from gajim.common.events import SubscribedPresenceReceived +from gajim.common.events import UnsubscribedPresenceReceived from gajim.common.helpers import get_uf_affiliation from gajim.common.helpers import get_uf_role from gajim.common.helpers import get_uf_show from gajim.common.i18n import _ from gajim.common.ged import EventHelper +from gajim.common.modules.contacts import BareContact +from gajim.common.modules.contacts import ResourceContact +from gajim.common.modules.contacts import GroupchatParticipant from .dialogs import ConfirmationDialog from .dialogs import DialogButton @@ -44,13 +53,21 @@ log = logging.getLogger('gajim.gui.contact_info') +ContactT = Union[BareContact, GroupchatParticipant] +DeviceContactT = Union[ResourceContact, GroupchatParticipant] + + class Column(IntEnum): IN_GROUP = 0 GROUP_NAME = 1 class ContactInfo(Gtk.ApplicationWindow, EventHelper): - def __init__(self, account, contact, page=None): + def __init__(self, + account: str, + contact: ContactT, + page: Optional[str] = None) -> None: + Gtk.ApplicationWindow.__init__(self) EventHelper.__init__(self) self.set_application(app.app) @@ -69,147 +86,172 @@ def __init__(self, account, contact, page=None): self._ui = get_builder('contact_info.ui') - side_bar_switcher = SideBarSwitcher() - side_bar_switcher.set_stack(self._ui.main_stack) - self._ui.main_grid.attach(side_bar_switcher, 0, 0, 1, 1) - self._ui.main_stack.connect('notify', self._on_stack_child_changed) + self._tasks: list[Task] = [] + self._devices: dict[str, DeviceGrid] = {} - self._ui.name_entry.set_text(contact.name) + self._switcher = SideBarSwitcher() + self._switcher.set_stack(self._ui.main_stack, rows_visible=False) + self._ui.main_grid.attach(self._switcher, 0, 0, 1, 1) + self._ui.main_stack.connect('notify::visible-child-name', + self._on_stack_child_changed) + self._ui.name_entry.set_text(contact.name) if contact.is_in_roster: self._ui.edit_name_button.show() - self._fill_groups_page() - if contact.is_gateway: - side_bar_switcher.hide_row('settings') - side_bar_switcher.hide_row('devices') - else: - self._fill_settings_page() - else: - side_bar_switcher.hide_row('settings') - side_bar_switcher.hide_row('groups') - side_bar_switcher.hide_row('notes') - if contact.is_pm_contact: - if contact.real_jid is None: - side_bar_switcher.hide_row('devices') - else: - side_bar_switcher.hide_row('devices') + + self._load_avatar() + self._fill_information_page() + self._fill_settings_page() + self._fill_device_info() + self._fill_groups_page() + self._fill_note_page() if page is not None: - # Jump to specific page if parameter is supplied - side_bar_switcher.set_row(page) + self._switcher.set_row(page) - self._tasks = [] + self._ui.connect_signals(self) + self.connect('key-press-event', self._on_key_press) + self.connect('destroy', self._on_destroy) # pylint: disable=line-too-long + connect_destroy(self._ui.tree_selection, 'changed', self._on_group_selection_changed) + connect_destroy(self._ui.toggle_renderer, 'toggled', self._on_group_toggled) + connect_destroy(self._ui.text_renderer, 'edited', self._on_group_name_edited) + self.register_events([ ('subscribed-presence-received', ged.GUI1, self._on_subscribed_presence_received), ('unsubscribed-presence-received', ged.GUI1, self._on_unsubscribed_presence_received), ]) # pylint: enable=line-too-long - self._load_avatar() + self.add(self._ui.main_grid) + self.show_all() - self._ui.contact_name_label.set_text(contact.name) - self._ui.contact_jid_label.set_text(str(contact.jid)) - self._ui.contact_jid_label.set_tooltip_text(str(contact.jid)) - - self._update_timeout_id = None - self._time = 0 - self._devices = {} - self._received_devices = set() - self._received_times = set() - - if contact.is_pm_contact: - if contact.real_jid is not None: - self._devices_grid = DevicesGrid(self._ui.devices_grid) - self._query_devices() - - self._ui.contact_jid_label.set_text( - str(contact.real_jid.bare)) - self._ui.contact_jid_label.set_tooltip_text( - str(contact.real_jid.bare)) - self._ui.role_label.set_text(get_uf_role(contact.role)) - self._ui.affiliation_label.set_text( - get_uf_affiliation(contact.affiliation)) - self._ui.group_chat_grid.show() + def _on_key_press(self, _widget: ContactInfo, event: Gdk.EventKey) -> None: + if event.keyval == Gdk.KEY_Escape: + self.destroy() + + def _on_stack_child_changed(self, + _widget: Gtk.Stack, + pspec: GObject.ParamSpec) -> None: - self._vcard_grid = VCardGrid(account) + name = self._ui.main_stack.get_visible_child_name() + self._ui.header_revealer.set_reveal_child(name != 'information') + + def _on_destroy(self, _widget: ContactInfo) -> None: + for task in self._tasks: + task.cancel() + + if self.contact.is_in_roster: + self._save_annotation() + + for device_grid in self._devices.values(): + device_grid.destroy() + self._devices.clear() + + self.unregister_events() + app.check_finalize(self) + + def _fill_information_page(self) -> None: + self._vcard_grid = VCardGrid(self.account) + self._vcard_grid.set_column_homogeneous(True) self._ui.vcard_box.add(self._vcard_grid) self._client.get_module('VCard4').request_vcard( - jid=contact.jid, + jid=self.contact.jid, callback=self._on_vcard_received) - if contact.is_in_roster: - self._devices_grid = DevicesGrid(self._ui.devices_grid) - self._query_devices() + jid = str(self.contact.get_address()) - note = self._client.get_module('Annotations').get_note(contact.jid) - if note is not None: - self._ui.textview_annotation.get_buffer().set_text(note.data) + self._ui.contact_name_label.set_text(self.contact.name) + self._ui.contact_jid_label.set_text(jid) + self._ui.contact_jid_label.set_tooltip_text(jid) - self._ui.connect_signals(self) - self.connect('key-press-event', self._on_key_press) - self.connect('destroy', self._on_destroy) + if isinstance(self.contact, GroupchatParticipant): + self._ui.role_label.set_text(get_uf_role(self.contact.role)) + self._ui.affiliation_label.set_text( + get_uf_affiliation(self.contact.affiliation)) + self._ui.group_chat_grid.show() - connect_destroy(self._ui.tree_selection, - 'changed', - self._on_group_selection_changed) - connect_destroy(self._ui.toggle_renderer, - 'toggled', - self._on_group_toggled) - connect_destroy(self._ui.text_renderer, - 'edited', - self._on_group_name_edited) + self._switcher.set_row_visible('information', True) - self.add(self._ui.main_grid) - self.show_all() + def _fill_note_page(self) -> None: + if not self.contact.is_in_roster: + return - def _on_key_press(self, _widget, event): - if event.keyval == Gdk.KEY_Escape: - self.destroy() + note = self._client.get_module('Annotations').get_note(self.contact.jid) + if note is not None: + self._ui.textview_annotation.get_buffer().set_text(note.data) - def _on_stack_child_changed(self, *args): - if self._ui.main_stack.get_visible_child_name() == 'information': - self._ui.header_revealer.set_reveal_child(False) + self._switcher.set_row_visible('notes', True) + + def _fill_settings_page(self) -> None: + if not isinstance(self.contact, BareContact): + return + + if self.contact.subscription in ('from', 'both'): + self._ui.from_subscription_switch.set_state(True) + + if self.contact.subscription in ('to', 'both'): + self._ui.to_subscription_stack.set_visible_child_name('checkmark') + + elif self.contact.ask == 'subscribe': + self._ui.to_subscription_stack.set_visible_child_name('request') + self._ui.request_stack.set_visible_child_name('requested') else: - self._ui.header_revealer.set_reveal_child(True) + self._ui.to_subscription_stack.set_visible_child_name('request') + self._ui.request_stack.set_visible_child_name('cross') - def _on_destroy(self, _widget): - for task in self._tasks: - task.cancel() - self._tasks.clear() + self._switcher.set_row_visible('settings', True) - if self.contact.is_in_roster: - self._save_annotation() + def _fill_groups_page(self) -> None: + if not isinstance(self.contact, BareContact): + return - if self._update_timeout_id is not None: - GLib.source_remove(self._update_timeout_id) + if not self.contact.is_in_roster: + return - self.unregister_events() - app.check_finalize(self) + model = self._ui.groups_treeview.get_model() + model.set_sort_column_id(Column.GROUP_NAME, Gtk.SortType.ASCENDING) + groups = self._client.get_module('Roster').get_groups() + for group in groups: + is_in_group = group in self.contact.groups + model.append([is_in_group, group]) - def _save_annotation(self): - buffer_ = self._ui.textview_annotation.get_buffer() - new_annotation = buffer_.get_property('text') - note = self._client.get_module('Annotations').get_note( - self.contact.jid) - if note is None or new_annotation != note.data: - new_note = AnnotationNote( - jid=self.contact.jid, data=new_annotation) - self._client.get_module('Annotations').set_note(new_note) + self._switcher.set_row_visible('groups', True) + + def _fill_device_info(self) -> None: + if isinstance(self.contact, GroupchatParticipant): + contact = self.contact.get_real_contact() + if contact is None: + return + else: + contact = self.contact + + contacts = list(contact.iter_resources()) + if not contacts: + return + + for contact in contacts: + device_grid = DeviceGrid(contact) + self._devices[contact.resource] = device_grid + self._ui.devices_box.add(device_grid.widget) + self._query_device(contact) + + self._ui.devices_stack.set_visible_child_name('devices') + self._switcher.set_row_visible('devices', True) + + def _query_device(self, contact: DeviceContactT) -> None: + jid = contact.get_address() + + task = self._client.get_module('SoftwareVersion').request_software_version( + jid, callback=self._set_os_info, user_data=jid.resource) + self._tasks.append(task) - def _update_timer(self): - # Timeout for EntityTime in milliseconds, used to stop the spinner - self._time += 100 - devices_complete = self._received_devices == set(self._devices.keys()) - times_complete = self._received_times == set(self._devices.keys()) - if devices_complete and times_complete or self._time == 10000: - self._ui.devices_spinner.stop() - self._update_timeout_id = None - return False - return True - - def _on_vcard_received(self, task): + task = self._client.get_module('EntityTime').request_entity_time( + jid, callback=self._set_entity_time, user_data=jid.resource) + self._tasks.append(task) + + def _on_vcard_received(self, task: Task) -> None: try: vcard = task.finish() except StanzaError as err: @@ -218,7 +260,7 @@ def _on_vcard_received(self, task): self._vcard_grid.set_vcard(vcard) - def _load_avatar(self): + def _load_avatar(self) -> None: scale = self.get_scale_factor() surface_1 = self.contact.get_avatar(AvatarSize.VCARD, scale, @@ -229,39 +271,7 @@ def _load_avatar(self): self._ui.avatar_image.set_from_surface(surface_1) self._ui.header_image.set_from_surface(surface_2) - def _query_devices(self): - self._update_timeout_id = GLib.timeout_add(100, self._update_timer) - - if self.contact.is_pm_contact: - self._query_device(self.contact) - else: - for contact in self.contact.iter_resources(): - self._query_device(contact) - - def _query_device(self, contact): - self._devices[contact.jid.resource] = { - 'status': contact.show, - 'message': contact.status - } - if not contact.is_pm_contact: - self._devices[contact.jid.resource]['priority'] = str( - contact.priority) - - self._rebuild_devices_grid() - - jid = contact.jid - if contact.is_pm_contact and contact.real_jid is not None: - jid = contact.real_jid - - task = self._client.get_module('SoftwareVersion').request_software_version( - jid, callback=self._set_os_info, user_data=contact) - self._tasks.append(task) - - task = self._client.get_module('EntityTime').request_entity_time( - jid, callback=self._set_entity_time, user_data=contact) - self._tasks.append(task) - - def _set_os_info(self, task): + def _set_os_info(self, task: Task) -> None: self._tasks.remove(task) try: @@ -270,15 +280,11 @@ def _set_os_info(self, task): log.warning('Could not retrieve software version: %s', err) return - contact = task.get_user_data() - self._devices[contact.jid.resource]['client'] = '%s %s' % ( - result.name, result.version) - if result.os is not None: - self._devices[contact.jid.resource]['os'] = result.os - self._received_devices.add(contact.jid.resource) - self._rebuild_devices_grid() + resource = task.get_user_data() + device_grid = self._devices[resource] + device_grid.set_software(result) - def _set_entity_time(self, task): + def _set_entity_time(self, task: Task) -> None: self._tasks.remove(task) try: @@ -287,53 +293,37 @@ def _set_entity_time(self, task): log.warning('Could not retrieve entity time: %s', err) return - contact = task.get_user_data() + resource = task.get_user_data() - self._devices[contact.jid.resource]['time'] = entity_time - self._received_times.add(contact.jid.resource) - self._rebuild_devices_grid() + device_grid = self._devices[resource] + device_grid.set_entity_time(entity_time) - def _rebuild_devices_grid(self): - self._ui.devices_stack.set_visible_child_name('devices') - self._devices_grid.clear() - for key, client in self._devices.items(): - self._devices_grid.add_header(_('Device "%s"') % key) - - if client.get('status'): - self._devices_grid.add_value( - _('Status'), get_uf_show(client['status'].value)) - if client.get('message'): - self._devices_grid.add_value( - _('Status Message'), client['message']) - if client.get('priority'): - self._devices_grid.add_value( - _('Priority'), client['priority']) - if client.get('client'): - self._devices_grid.add_value( - _('Software'), client['client']) - if client.get('os'): - self._devices_grid.add_value( - _('Operating Sytem'), client['os']) - if client.get('time'): - self._devices_grid.add_value( - _('Local Time'), client['time']) - self._ui.devices_grid.show_all() + def _save_annotation(self) -> None: + buffer_ = self._ui.textview_annotation.get_buffer() + new_annotation = buffer_.get_property('text') + note = self._client.get_module('Annotations').get_note( + self.contact.jid) + if note is None or new_annotation != note.data: + new_note = AnnotationNote( + jid=self.contact.jid, data=new_annotation) + self._client.get_module('Annotations').set_note(new_note) - def _on_edit_name_toggled(self, widget): - if widget.get_active(): - self._ui.name_entry.set_sensitive(True) + def _on_edit_name_toggled(self, widget: Gtk.ToggleButton) -> None: + active = widget.get_active() + self._ui.name_entry.set_sensitive(active) + if active: self._ui.name_entry.grab_focus() - else: - self._ui.name_entry.set_sensitive(False) - name = GLib.markup_escape_text(self._ui.name_entry.get_text()) + name = self._ui.name_entry.get_text() self._client.get_module('Roster').set_item(self.contact.jid, name) self._ui.contact_name_label.set_text(name) - def _on_name_entry_activate(self, _widget, *args): + def _on_name_entry_activate(self, _widget: Gtk.Entry) -> None: self._ui.edit_name_button.set_active(False) - def _on_from_subscription_switch_toggled(self, switch, state): + def _on_from_subscription_switch_toggled(self, + switch: Gtk.Switch, + state: bool) -> int: def _stop_sharing(): self._client.get_module('Presence').unsubscribed(self.contact.jid) switch.set_state(state) @@ -355,50 +345,40 @@ def _stop_sharing(): transient_for=self).show() return Gdk.EVENT_STOP - def _on_to_subscription_button_clicked(self, *args): + def _on_to_subscription_button_clicked(self, _widget: Gtk.Button) -> None: # Save auto_auth if switch for disclosing presence is active self._client.get_module('Presence').subscribe( self.contact.jid, auto_auth=self._ui.from_subscription_switch.get_state()) self._ui.request_stack.set_visible_child_name('requested') - def _on_subscribed_presence_received(self, _event): + def _on_subscribed_presence_received(self, + _event: SubscribedPresenceReceived + ) -> None: + self._ui.to_subscription_stack.set_visible_child_name('checkmark') - def _on_unsubscribed_presence_received(self, _event): + def _on_unsubscribed_presence_received(self, + _event: UnsubscribedPresenceReceived + ) -> None: + self._ui.to_subscription_stack.set_visible_child_name('request') self._ui.request_stack.set_visible_child_name('cross') - def _fill_settings_page(self): - if self.contact.subscription in ('from', 'both'): - self._ui.from_subscription_switch.set_state(True) - if self.contact.subscription in ('to', 'both'): - self._ui.to_subscription_stack.set_visible_child_name('checkmark') - elif self.contact.ask == 'subscribe': - self._ui.to_subscription_stack.set_visible_child_name('request') - self._ui.request_stack.set_visible_child_name('requested') - else: - self._ui.to_subscription_stack.set_visible_child_name('request') - self._ui.request_stack.set_visible_child_name('cross') - - def _fill_groups_page(self): - model = self._ui.groups_treeview.get_model() - model.set_sort_column_id(Column.GROUP_NAME, Gtk.SortType.ASCENDING) - groups = self._client.get_module('Roster').get_groups() - for group in groups: - is_in_group = group in self.contact.groups - model.append([is_in_group, group]) - - def _on_group_selection_changed(self, *args): + def _on_group_selection_changed(self, _widget: Gtk.TreeSelection) -> None: selection = self._ui.groups_treeview.get_selection() (_model, iter_) = selection.get_selected() self._ui.group_remove_button.set_sensitive(bool(iter_)) - def _on_group_name_edited(self, _renderer, path, new_name): + def _on_group_name_edited(self, + _renderer: Gtk.CellRendererText, + path: str, + new_name: str) -> None: if new_name == '': return model = self._ui.groups_treeview.get_model() + assert model is not None selected_iter_ = model.get_iter(path) old_name = model[selected_iter_][Column.GROUP_NAME] @@ -412,9 +392,10 @@ def _on_group_name_edited(self, _renderer, path, new_name): model.set_value(selected_iter_, Column.GROUP_NAME, new_name) self._client.get_module('Roster').rename_group(old_name, new_name) - def _on_group_remove_button_clicked(self, *args): + def _on_group_remove_button_clicked(self, _widget: Gtk.Button) -> int: selection = self._ui.groups_treeview.get_selection() - (model, iter_) = selection.get_selected() + model, iter_ = selection.get_selected() + assert iter_ is not None group = model[iter_][Column.GROUP_NAME] def _remove_group(): @@ -431,11 +412,15 @@ def _remove_group(): transient_for=self).show() return Gdk.EVENT_STOP - def _on_group_toggled(self, _renderer, path): + def _on_group_toggled(self, + _renderer: Gtk.CellRendererToggle, + path: str) -> None: + model = self._ui.groups_treeview.get_model() + assert model is not None model[path][Column.IN_GROUP] = not model[path][Column.IN_GROUP] - groups = set() + groups: set[str] = set() iter_ = model.get_iter_first() while iter_: if model.get_value(iter_, Column.IN_GROUP): @@ -444,9 +429,10 @@ def _on_group_toggled(self, _renderer, path): self._client.get_module('Roster').set_groups(self.contact.jid, groups) - def _on_group_add_button_clicked(self, *args): + def _on_group_add_button_clicked(self, _widget: Gtk.Button) -> None: default_name = _('New Group') model = self._ui.groups_treeview.get_model() + assert model is not None # Check if default_name group already exists iter_ = model.get_iter_first() @@ -461,42 +447,60 @@ def _on_group_add_button_clicked(self, *args): self._ui.groups_treeview.set_cursor(path, column, True) -class DevicesGrid: - def __init__(self, grid): - self._grid = grid - self._row_num = 0 - - def clear(self): - row = 0 - while self._grid.get_child_at(0, row): - self._grid.remove_row(row) - self._row_num = 0 - - def add_value(self, name, value): - self._grid.insert_row(self._row_num) - - label = Gtk.Label(label=name) - label.get_style_context().add_class('dim-label') - label.set_valign(Gtk.Align.START) - label.set_halign(Gtk.Align.END) - label.set_margin_start(12) - self._grid.attach(label, 0, self._row_num, 1, 1) - - label = Gtk.Label(label=value) - label.set_valign(Gtk.Align.START) - label.set_halign(Gtk.Align.START) - label.set_line_wrap(True) - label.set_xalign(0) - self._grid.attach(label, 1, self._row_num, 1, 1) - self._row_num += 1 - - def add_header(self, text): - self._grid.insert_row(self._row_num) - - label = Gtk.Label(label=text) - label.get_style_context().add_class('bold16') - if self._row_num > 0: - label.set_margin_top(12) - label.set_halign(Gtk.Align.START) - self._grid.attach(label, 0, self._row_num, 2, 1) - self._row_num += 1 +class DeviceGrid: + def __init__(self, contact: DeviceContactT) -> None: + self._contact = contact + self._ui = get_builder('contact_info.ui', ['devices_grid']) + self._spinner = Gtk.Spinner() + self._spinner.start() + + self._ui.resource_label.set_text(_('Device "%s"') % contact.resource) + self._ui.status_value.set_text(get_uf_show(contact.show.value)) + self._set_priority() + + self._ui.resource_box.add(self._spinner) + self._ui.devices_grid.show_all() + + self._waiting_for_info = 2 + + @property + def widget(self) -> Gtk.Grid: + return self._ui.devices_grid + + def _set_priority(self) -> None: + if not isinstance(self._contact, ResourceContact): + return + + self._ui.priority_value.set_text(str(self._contact.priority)) + self._ui.priority_value.show() + self._ui.priority_label.show() + + def set_entity_time(self, entity_time: str) -> None: + self._ui.time_value.set_text(entity_time) + self._ui.time_value.show() + self._ui.time_label.show() + + self._check_complete() + + def set_software(self, software: SoftwareVersionResult) -> None: + software_string = '%s %s' % (software.name, software.version) + self._ui.software_value.set_text(software_string) + self._ui.software_value.show() + self._ui.software_label.show() + if software.os is not None: + self._ui.system_value.set_text(software.os) + self._ui.system_value.show() + self._ui.system_label.show() + + self._check_complete() + + def _check_complete(self) -> None: + self._waiting_for_info -= 1 + if not self._waiting_for_info: + self._spinner.stop() + + def destroy(self) -> None: + self._spinner.stop() + del self._spinner + del self._ui + del self._contact ===================================== gajim/gtk/sidebar_switcher.py ===================================== @@ -12,9 +12,15 @@ # You should have received a copy of the GNU General Public License # along with Gajim. If not, see <
http://www.gnu.org/licenses/
>. +from __future__ import annotations + +from typing import Optional +from typing import cast from gi.repository import Gtk +from gajim.common import app + class SideBarSwitcher(Gtk.ListBox): def __init__(self): @@ -22,45 +28,69 @@ def __init__(self): self.set_vexpand(True) self.get_style_context().add_class('settings-menu') self.connect('row-activated', self._on_row_activated) - self._stack = None + self._stack = cast(Gtk.Stack, None) + self._rows: dict[str, Row] = {} + + self.connect('destroy', self._destroy) - def set_stack(self, stack): + def set_stack(self, stack: Gtk.Stack, rows_visible: bool = True) -> None: self._stack = stack for page in self._stack.get_children(): - attributes = ['name', 'title', 'icon-name'] - properties = self._stack.child_get(page, *attributes) - self.add(Row(*properties)) + name = self._stack.child_get_property(page, 'name') + if name is None: + raise ValueError('unnamed child') + title = self._stack.child_get_property(page, 'title') + if title is None: + raise ValueError('no title on child') + icon_name = self._stack.child_get_property(page, 'icon-name') + + row = Row(name, title, icon_name, rows_visible) + + self.add(row) + self._rows[name] = row self._select_first_row() - def hide_row(self, name): - for row in self.get_children(): - if row.name == name: - row.set_no_show_all(True) - row.hide() - break - - def set_row(self, name): - for row in self.get_children(): - if row.name == name: - self.select_row(row) - self._stack.set_visible_child_name(name) - break - - def _on_row_activated(self, _listbox, row): + def set_row_visible(self, name: str, state: bool) -> None: + row = self._rows.get(name) + if row is None: + raise ValueError + row.set_visible(state) + + def set_row(self, name: str) -> None: + row = self._rows.get(name) + if row is None: + raise ValueError + self.select_row(row) + self._stack.set_visible_child_name(name) + + def _on_row_activated(self, _listbox: SideBarSwitcher, row: Row): self._stack.set_visible_child_name(row.name) def _select_first_row(self): self.select_row(self.get_row_at_index(0)) + def _destroy(self, _widget: SideBarSwitcher) -> None: + for row in self._rows.values(): + row.destroy() + self._rows.clear() + del self._stack + app.check_finalize(self) + class Row(Gtk.ListBoxRow): - def __init__(self, name, title, icon_name): + def __init__(self, + name: str, + title: str, + icon_name: Optional[str], + visible: bool) -> None: + Gtk.ListBoxRow.__init__(self) self.name = name + box = Gtk.Box() - if icon_name: + if icon_name is not None: image = Gtk.Image.new_from_icon_name(icon_name, Gtk.IconSize.MENU) image.get_style_context().add_class('dim-label') box.add(image) @@ -69,3 +99,7 @@ def __init__(self, name, title, icon_name): label.set_xalign(0) box.add(label) self.add(box) + + self.show_all() + self.set_no_show_all(True) + self.set_visible(visible) ===================================== pyrightconfig.json ===================================== @@ -37,6 +37,7 @@ "gajim/gtk/conversation/rows/widgets.py", "gajim/gtk/conversation/scrolled.py", "gajim/gtk/notification.py", + "gajim/gtk/side_bar_switcher.py", "gajim/gtk/status_message_selector.py", "gajim/gtk/status_selector.py", ], View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/0654533e62d1ac872f27a3000d21718…
-- View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/0654533e62d1ac872f27a3000d21718…
You're receiving this email because of your account on
dev.gajim.org
.
1
0
0
0
[Git][gajim/gajim][master] Add server shutdown notification
by Philipp Hörist (@lovetox)
09 Jan '22
09 Jan '22
Philipp Hörist pushed to branch master at gajim / gajim Commits: 0654533e by lovetox at 2022-01-09T15:18:06+01:00 Add server shutdown notification - - - - - 3 changed files: - gajim/common/client.py - gajim/gtk/application.py - gajim/gtk/notification.py Changes: ===================================== gajim/common/client.py ===================================== @@ -277,6 +277,12 @@ def _on_disconnected(self, app.settings.set_account_setting(self._account, 'resource', 'gajim.$rand') + if error == 'system-shutdown': + app.ged.raise_event( + Notification(account=self._account, + type='server-shutdown', + title=_('Server Shutdown'), + text=text or _('The server was shut down.'))) elif domain == StreamError.SASL: self._reconnect = False ===================================== gajim/gtk/application.py ===================================== @@ -719,7 +719,8 @@ def _on_open_event_action(_action: Gio.SimpleAction, if params.type in ('connection-failed', 'subscription-request', 'unsubscribed', - 'group-chat-invitation'): + 'group-chat-invitation', + 'server-shutdown'): app.window.show_account_page(params.account) ===================================== gajim/gtk/notification.py ===================================== @@ -72,6 +72,7 @@ _notification_backend = None + class NotificationBackend(EventHelper): def __init__(self) -> None: EventHelper.__init__(self) @@ -94,6 +95,7 @@ def _on_our_show(self, event: events.ShowChanged) -> None: if not app.account_is_connected(event.account): return self._withdraw(['connection-failed', event.account]) + self._withdraw(['server-shutdown', event.account]) def _send(self, event: events.Notification) -> None: raise NotImplementedError @@ -232,6 +234,7 @@ class Linux(NotificationBackend): _action_types = [ 'connection-failed', + 'server-shutdown', 'file-transfer', 'group-chat-invitation', 'incoming-call', @@ -322,8 +325,8 @@ def _add_actions(self, def _make_notification_id(self, event: events.Notification) -> Optional[str]: - if event.type == 'connection-failed': - return self._make_id(['connection-failed', event.account]) + if event.type in ('connection-failed', 'server-shutdown'): + return self._make_id([event.type, event.account]) if event.type == 'incoming-message': return self._make_id(['new-message', event.account, str(event.jid)]) View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/0654533e62d1ac872f27a3000d217181…
-- View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/0654533e62d1ac872f27a3000d217181…
You're receiving this email because of your account on
dev.gajim.org
.
1
0
0
0
[Git][gajim/gajim][master] Chats: Add remove history option
by Philipp Hörist (@lovetox)
09 Jan '22
09 Jan '22
Philipp Hörist pushed to branch master at gajim / gajim Commits: e236e904 by lovetox at 2022-01-09T08:11:12+01:00 Chats: Add remove history option - - - - - 5 changed files: - gajim/common/storage/archive.py - gajim/gtk/application.py - gajim/gtk/controls/groupchat.py - gajim/gtk/menus.py - gajim/gtk/structs.py Changes: ===================================== gajim/common/storage/archive.py ===================================== @@ -1349,13 +1349,9 @@ def reset_archive_infos(self, jid: str) -> None: log.info('Reset message archive info: %s', jid) self._delayed_commit() - def remove_chat_history(self, - account: str, - jid: str, - groupchat: bool = False - ) -> None: + def remove_history(self, account: str, jid: JID) -> None: """ - Remove chat history for a specific chat. + Remove history for a specific chat. If it's a group chat, remove last MAM ID as well. """ account_id = self.get_account_id(account) @@ -1363,15 +1359,19 @@ def remove_chat_history(self, sql = 'DELETE FROM logs WHERE account_id = ? AND jid_id = ?' self._con.execute(sql, (account_id, jid_id)) + self._delayed_commit() + log.info('Removed history for: %s', jid) + + def forget_jid_data(self, account: str, jid: JID) -> None: + jid_id = self.get_jid_id(jid) sql = 'DELETE FROM jids WHERE jid_id = ?' self._con.execute(sql, (jid_id,)) - if groupchat: - sql = 'DELETE FROM last_archive_message WHERE jid_id = ?' - self._con.execute(sql, (jid_id,)) + sql = 'DELETE FROM last_archive_message WHERE jid_id = ?' + self._con.execute(sql, (jid_id,)) self._delayed_commit() - log.info('Removed chat history for: %s', jid) + log.info('Forgot data for: %s', jid) def _cleanup_chat_history(self) -> None: """ ===================================== gajim/gtk/application.py ===================================== @@ -75,7 +75,9 @@ from gajim.gui.dialogs import ShortcutsWindow from gajim.gui.about import AboutDialog from gajim.gui.discovery import ServiceDiscoveryWindow +from gajim.gui.structs import ForgetGroupchatActionParams from gajim.gui.structs import OpenEventActionParams +from gajim.gtk.structs import RemoveHistoryActionParams ActionListT = list[tuple[str, @@ -380,8 +382,9 @@ def add_actions(self) -> None: ('copy-text', 's', self._on_copy_text_action), ('open-link', 'as', self._on_open_link_action), ('open-mail', 's', self._on_open_mail_action), + ('remove-history', 'a{sv}', self._on_remove_history_action), ('create-groupchat', 's', self._on_create_groupchat_action), - ('forget-groupchat', 'as', self._on_forget_groupchat_action), + ('forget-groupchat', 'a{sv}', self._on_forget_groupchat_action), ('groupchat-join', 'as', self._on_groupchat_join_action), ] @@ -775,20 +778,35 @@ def _on_open_chat_action(_action: Gio.SimpleAction, account, jid = param.get_strv() app.interface.start_chat_from_jid(account, jid) + @staticmethod + def _on_remove_history_action(_action: Gio.SimpleAction, + param: GLib.Variant) -> None: + + params = RemoveHistoryActionParams.from_variant(param) + + if params.jid is not None: + app.storage.archive.remove_history(params.account, params.jid) + control = app.window.get_control(params.account, params.jid) + if control is not None: + control.reset_view() + else: + for control in app.window.get_controls(params.account): + control.reset_view() + @staticmethod def _on_forget_groupchat_action(_action: Gio.SimpleAction, param: GLib.Variant) -> None: - account, jid = param.unpack() - room_jid = JID.from_string(jid) + + params = ForgetGroupchatActionParams.from_variant(param) window = get_app_window('StartChatDialog') - window.remove_row(account, str(room_jid)) + window.remove_row(params.account, str(params.jid)) - client = app.get_client(account) - client.get_module('MUC').leave(room_jid) - client.get_module('Bookmarks').remove(room_jid) + client = app.get_client(params.account) + client.get_module('MUC').leave(params.jid) + client.get_module('Bookmarks').remove(params.jid) - app.storage.archive.remove_chat_history( - account, str(room_jid), groupchat=True) + app.storage.archive.remove_history(params.account, params.jid) + app.storage.archive.forget_jid_data(params.account, params.jid) @staticmethod def _on_groupchat_join_action(_action: Gio.SimpleAction, ===================================== gajim/gtk/controls/groupchat.py ===================================== @@ -191,7 +191,7 @@ def __init__(self, account: str, jid: JID) -> None: self.control_menu = get_groupchat_menu(self.control_id, self.account, - self.room_jid) + self.contact.jid) self.xml.settings_menu.set_menu_model(self.control_menu) ===================================== gajim/gtk/menus.py ===================================== @@ -41,6 +41,8 @@ from gajim.common.const import URIAction from gajim.common.structs import URI +from gajim.gui.structs import ForgetGroupchatActionParams +from gajim.gui.structs import RemoveHistoryActionParams from gajim.gui.const import ControlType @@ -52,7 +54,7 @@ def get_singlechat_menu(control_id: str, client = app.get_client(account) is_self_contact = jid.bare == client.get_own_jid().bare - singlechat_menu: List[Any] = [ + singlechat_menu: list[tuple[str, Any]] = [ (_('Send File'), [ ('win.send-file-httpupload-', _('Upload File…')), ('win.send-file-jingle-', _('Send File Directly…')) @@ -66,7 +68,8 @@ def get_singlechat_menu(control_id: str, ('win.add-to-roster-', _('Add to Contact List…')), ('win.block-contact-', _('Block Contact…')), ('win.start-call-', _('Start Call…')), - ('win.information-', _('Information')) + ('win.information-', _('Information')), + ('app.remove-history', _('Remove History')) ] if is_self_contact: @@ -90,7 +93,7 @@ def build_chatstate_menu() -> Gio.Menu: menu.append(label, action) return menu - def build_menu(preset): + def build_menu(preset: list[tuple[str, Any]]): menu = Gio.Menu() for item in preset: if isinstance(item[1], str): @@ -116,6 +119,12 @@ def build_menu(preset): menuitem.set_action_and_target_value(action_name, variant_dict) menu.append_item(menuitem) + elif action_name == 'app.remove-history': + params = RemoveHistoryActionParams(account=account, jid=jid) + menuitem = Gio.MenuItem.new(label, action_name) + menuitem.set_action_and_target_value(action_name, + params.to_variant()) + menu.append_item(menuitem) else: menu.append(label, action_name + control_id) else: @@ -130,7 +139,7 @@ def build_menu(preset): return build_menu(singlechat_menu) -def get_groupchat_menu(control_id: str, account: str, jid: str) -> Gio.Menu: +def get_groupchat_menu(control_id: str, account: str, jid: JID) -> Gio.Menu: groupchat_menu = [ ('win.information-', _('Information')), ('win.groupchat-settings-', _('Settings…')), @@ -140,6 +149,7 @@ def get_groupchat_menu(control_id: str, account: str, jid: str) -> Gio.Menu: ('win.request-voice-', _('Request Voice')), ('win.execute-command-', _('Execute Command…')), ('win.search-history', _('Search…')), + ('app.remove-history', _('Remove History')) ] def build_menu(preset: list[tuple[str, str]]) -> Gio.Menu: @@ -154,7 +164,7 @@ def build_menu(preset: list[tuple[str, str]]) -> Gio.Menu: elif action_name == 'app.browse-history': menuitem = Gio.MenuItem.new(label, action_name) dict_ = {'account': GLib.Variant('s', account), - 'jid': GLib.Variant('s', jid)} + 'jid': GLib.Variant('s', str(jid))} variant_dict = GLib.Variant('a{sv}', dict_) menuitem.set_action_and_target_value( action_name, variant_dict) @@ -166,6 +176,13 @@ def build_menu(preset: list[tuple[str, str]]) -> Gio.Menu: menuitem.set_action_and_target_value( action_name, GLib.Variant('s', '')) menu.append_item(menuitem) + + elif action_name == 'app.remove-history': + params = RemoveHistoryActionParams(account=account, jid=jid) + menuitem = Gio.MenuItem.new(label, action_name) + menuitem.set_action_and_target_value(action_name, + params.to_variant()) + menu.append_item(menuitem) else: menu.append(label, action_name + control_id) @@ -485,10 +502,7 @@ def get_subscription_menu(account: str, jid: str) -> Gio.Menu: return menu -def get_start_chat_row_menu(account: str, - jid: Union[JID, str] - ) -> Gio.Menu: - jid = str(jid) +def get_start_chat_row_menu(account: str, jid: JID) -> Gio.Menu: menu_items: List[Tuple[str, str]] = [ ('forget-groupchat', _('Forget this Group Chat')), ] @@ -497,8 +511,8 @@ def get_start_chat_row_menu(account: str, action, label = item action = f'app.{action}' menuitem = Gio.MenuItem.new(label, action) - variant_list = GLib.Variant('as', [account, jid]) - menuitem.set_action_and_target_value(action, variant_list) + params = ForgetGroupchatActionParams(account=account, jid=jid) + menuitem.set_action_and_target_value(action, params.to_variant()) menu.append_item(menuitem) return menu ===================================== gajim/gtk/structs.py ===================================== @@ -29,3 +29,15 @@ class OpenEventActionParams(VariantMixin): sub_type: Optional[str] account: str jid: Optional[JID] + + +@dataclass +class RemoveHistoryActionParams(VariantMixin): + account: str + jid: Optional[JID] = None + + +@dataclass +class ForgetGroupchatActionParams(VariantMixin): + account: str + jid: JID View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/e236e90498c6507ec887433a8958005d…
-- View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/e236e90498c6507ec887433a8958005d…
You're receiving this email because of your account on
dev.gajim.org
.
1
0
0
0
[Git][gajim/gajim][master] Remove dialog_messages module
by Philipp Hörist (@lovetox)
08 Jan '22
08 Jan '22
Philipp Hörist pushed to branch master at gajim / gajim Commits: 810711d3 by lovetox at 2022-01-08T17:42:03+01:00 Remove dialog_messages module - Remove InformationEvent - - - - - 6 changed files: - gajim/common/events.py - gajim/common/jingle_rtp.py - gajim/common/modules/bytestream.py - gajim/common/zeroconf/connection_zeroconf.py - − gajim/dialog_messages.py - gajim/gui_interface.py Changes: ===================================== gajim/common/events.py ===================================== @@ -640,15 +640,6 @@ class UnsubscribedPresenceReceived(ApplicationEvent): jid: str -@dataclass -class InformationEvent(ApplicationEvent): - name: str = field(init=False, default='information-event') - dialog_name: str - args: Optional[Any] = None - kwargs: Optional[dict[str, Any]] = None - popup: bool = False - - @dataclass class FileRequestReceivedEvent(ApplicationEvent): name: str = field(init=False, default='file-request-received') ===================================== gajim/common/jingle_rtp.py ===================================== @@ -39,7 +39,6 @@ from gajim.common.jingle_content import contents from gajim.common.jingle_content import JingleContent from gajim.common.jingle_content import JingleContentSetupException -from gajim.common.events import InformationEvent from gajim.common.jingle_session import FailedApplication @@ -125,17 +124,9 @@ def make_bin_from_config(self, config_key, pipeline, text): gst_bin = Gst.parse_bin_from_description(pipeline, True) return gst_bin except GLib.Error as err: - app.ged.raise_event( - InformationEvent( - conn=self.session.connection, - level='error', - pri_txt=_('%s configuration error') % text, - sec_txt=_('Couldn’t set up %(text)s. Check your ' - 'configuration.\nPipeline:\n%(pipeline)s\n' - 'Error:\n%(error)s') % { - 'text': text, - 'pipeline': pipeline, - 'error': str(err)})) + log.error('Couldn’t set up %s. Check your ' + 'configuration. Pipeline: %s' + 'Error: %s', text, pipeline, err) raise JingleContentSetupException def add_remote_candidates(self, candidates): @@ -235,6 +226,7 @@ def _on_gst_message(self, _bus, message): log.error('Farstream error #%d!\nMessage: %s', message.get_structure().get_value('error-no'), message.get_structure().get_value('error-msg')) + elif message.type == Gst.MessageType.ERROR: # TODO: Fix it to fallback to videotestsrc anytime an error occur, # or raise an error, Jingle way @@ -243,12 +235,6 @@ def _on_gst_message(self, _bus, message): debug_msg = message.get_structure().get_value('debug') log.error(gerror_msg) log.error(debug_msg) - if not self.stream_failed_once: - app.ged.raise_event( - InformationEvent( - dialog_name='gstreamer-error', - kwargs={'error': gerror_msg, 'debug': debug_msg})) - sink_pad = self.p2psession.get_property('sink-pad') # Remove old source ===================================== gajim/common/modules/bytestream.py ===================================== @@ -38,7 +38,6 @@ from gajim.common.events import FileRequestError from gajim.common.file_props import FilesProp from gajim.common.socks5 import Socks5SenderClient -from gajim.common.events import InformationEvent from gajim.common.modules.base import BaseModule @@ -323,7 +322,7 @@ def _add_local_ips_as_streamhosts_to_query(self, query, file_props): port = app.settings.get('file_transfers_port') self._add_streamhosts_to_query(query, sender, port, my_ips) except socket.gaierror: - app.ged.raise_event(InformationEvent(dialog_name='wrong-host')) + log.error('wrong host, invalid local address?') def _add_addiditional_streamhosts_to_query(self, query, file_props): sender = file_props.sender ===================================== gajim/common/zeroconf/connection_zeroconf.py ===================================== @@ -44,7 +44,6 @@ from gajim.common.zeroconf import client_zeroconf from gajim.common.zeroconf import zeroconf from gajim.common.zeroconf.connection_handlers_zeroconf import ConnectionHandlersZeroconf -from gajim.common.events import InformationEvent log = logging.getLogger('gajim.c.connection_zeroconf') @@ -380,8 +379,7 @@ def _on_name_conflictCB(self, alt_name): alt_name=alt_name)) def _on_error(self, message): - app.ged.raise_event(InformationEvent( - dialog_name='avahi-error', args=message)) + log.warning('avahi error: %s', message) def connect(self, show='online', msg=''): self.get_config_values_or_default() ===================================== gajim/dialog_messages.py deleted ===================================== @@ -1,67 +0,0 @@ -# Copyright (C) 2017 Philipp Hörist <philipp AT
hoerist.com
> -# -# This file is part of Gajim. -# -# Gajim is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Gajim is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Gajim. If not, see <
http://www.gnu.org/licenses/
>. - -from collections import namedtuple - -from gi.repository import GLib - -from gajim.common.app import app -from gajim.common.i18n import _ -from gajim.gui.dialogs import ErrorDialog - -Message = namedtuple('Message', ['title', 'text', 'dialog']) - -messages = { - 'gstreamer-error': Message( - _('GStreamer Error'), - _('Error: %(error)s\nDebug: %(debug)s'), - ErrorDialog), - - 'wrong-host': Message( - _('Wrong Host'), - _('Invalid local address? :-O'), - ErrorDialog), - - 'avahi-error': Message( - _('Avahi Error'), - _('%s\nLink-local messaging might not work properly.'), - ErrorDialog), - } - - -def get_dialog(dialog_name, *args, **kwargs): - message = messages.get(dialog_name, None) - if message is None: - raise ValueError('Dialog %s does not exist' % dialog_name) - - # Set transient window - transient_for = kwargs.get('transient_for', None) - if transient_for is None: - transient_for = app.get_active_window() - else: - del kwargs['transient_for'] - - if args: - message_text = message.text % args - elif kwargs: - message_text = message.text % kwargs - else: - message_text = message.text - dialog = message.dialog(message.title, - GLib.markup_escape_text(message_text), - transient_for=transient_for) - return dialog ===================================== gajim/gui_interface.py ===================================== @@ -58,8 +58,6 @@ from nbxmpp import Hashes2 from nbxmpp import JID -from gajim.dialog_messages import get_dialog - from gajim.common import app from gajim.common import ged from gajim.common import exceptions @@ -95,8 +93,6 @@ from gajim.gui.avatar import AvatarStorage from gajim.gui.dialogs import DialogButton from gajim.gui.dialogs import ErrorDialog -from gajim.gui.dialogs import WarningDialog -from gajim.gui.dialogs import InformationDialog from gajim.gui.dialogs import ConfirmationDialog from gajim.gui.dialogs import InputDialog from gajim.gui.filechoosers import FileChooserDialog @@ -201,7 +197,6 @@ def __init__(self): def _create_core_handlers_list(self) -> None: # pylint: disable=line-too-long self.handlers = { - 'information': [self.handle_event_information], 'iq-error-received': [self.handle_event_iq_error], 'plain-connection': [self.handle_event_plain_connection], 'http-auth-received': [self.handle_event_http_auth], @@ -235,30 +230,6 @@ def _register_core_handlers(self) -> None: prio, event_handler) - @staticmethod - def handle_event_information(event): - if not event.popup: - return - - if event.dialog_name is not None: - get_dialog(event.dialog_name, *event.args, **event.kwargs) - return - - if event.level == 'error': - cls = ErrorDialog - elif event.level == 'warn': - cls = WarningDialog - elif event.level == 'info': - cls = InformationDialog - else: - return - - cls(event.pri_txt, GLib.markup_escape_text(event.sec_txt)) - - @staticmethod - def raise_dialog(name, *args, **kwargs): - get_dialog(name, *args, **kwargs) - @staticmethod def handle_event_iq_error(event): ctrl = app.window.get_control(event.account, event.properties.jid.bare) View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/810711d34e1679c4eb220eb29c32d05e…
-- View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/810711d34e1679c4eb220eb29c32d05e…
You're receiving this email because of your account on
dev.gajim.org
.
1
0
0
0
[Git][gajim/gajim][master] 3 commits: Accounts: Add type annotations
by Philipp Hörist (@lovetox)
08 Jan '22
08 Jan '22
Philipp Hörist pushed to branch master at gajim / gajim Commits: 84e80350 by lovetox at 2022-01-08T17:01:17+01:00 Accounts: Add type annotations - - - - - c917c5d1 by lovetox at 2022-01-08T17:02:03+01:00 AccountPage: Add type annotations - - - - - df3d4ac6 by lovetox at 2022-01-08T17:03:02+01:00 Util: Fix return type Use Any for now, real types create an import cycle - - - - - 4 changed files: - gajim/gtk/account_page.py - gajim/gtk/accounts.py - gajim/gtk/util.py - pyrightconfig.json Changes: ===================================== gajim/gtk/account_page.py ===================================== @@ -12,7 +12,7 @@ # You should have received a copy of the GNU General Public License # along with Gajim. If not, see <
http://www.gnu.org/licenses/
>. -from typing import Any +from __future__ import annotations from gi.repository import Gdk from gi.repository import Gio @@ -21,6 +21,7 @@ from gajim.common import app from gajim.common import ged from gajim.common.const import AvatarSize +from gajim.common.events import ApplicationEvent from gajim.common.events import SubscribePresenceReceived from gajim.common.events import UnsubscribedPresenceReceived from gajim.common.events import MucInvitation @@ -35,6 +36,7 @@ from .util import open_window from .util import EventHelper + ROSTER_MENU_DICT = { 'show-offline': _('Show Offline Contacts'), 'sort-by-show': _('Sort by Status'), @@ -91,7 +93,7 @@ def __init__(self, account: str) -> None: self.show_all() self.connect('destroy', self._on_destroy) - def _on_destroy(self, *args: Any) -> None: + def _on_destroy(self, _widget: AccountPage) -> None: app.check_finalize(self) def _on_edit_profile(self, _button: Gtk.Button) -> None: @@ -149,5 +151,5 @@ def _muc_invitation_declined(self, event: MucDecline) -> None: return self._notification_manager.add_invitation_declined(event) - def process_event(self, event): + def process_event(self, event: ApplicationEvent) -> None: self._roster.process_event(event) ===================================== gajim/gtk/accounts.py ===================================== @@ -12,6 +12,10 @@ # You should have received a copy of the GNU General Public License # along with Gajim. If not, see <
http://www.gnu.org/licenses/
>. +from __future__ import annotations + +from typing import Any + import sys import locale import logging @@ -42,7 +46,7 @@ class AccountsWindow(Gtk.ApplicationWindow): - def __init__(self): + def __init__(self) -> None: Gtk.ApplicationWindow.__init__(self) self.set_application(app.app) self.set_position(Gtk.WindowPosition.CENTER) @@ -74,7 +78,10 @@ def __init__(self): self.show_all() - def _on_menu_activated(self, _listbox, account, name): + def _on_menu_activated(self, + _listbox: Gtk.ListBox, + account: str, + name: str) -> None: if name == 'back': self._settings.set_page('add-account') self._check_relogin() @@ -83,21 +90,23 @@ def _on_menu_activated(self, _listbox, account, name): else: self._settings.set_page(name) - def _on_key_press(self, _widget, event): + def _on_key_press(self, + _widget: AccountsWindow, + event: Gdk.EventKey) -> None: if event.keyval == Gdk.KEY_Escape: self.destroy() - def _on_destroy(self, *args): + def _on_destroy(self, _widget: AccountsWindow) -> None: self._check_relogin() - def update_account_label(self, account): + def update_account_label(self, account: str) -> None: self._accounts[account].update_account_label() - def update_proxy_list(self): + def update_proxy_list(self) -> None: for account in self._accounts: self._settings.update_proxy_list(account) - def _check_relogin(self): + def _check_relogin(self) -> None: for account, r_settings in self._need_relogin.items(): settings = self._get_relogin_settings(account) active = app.settings.get_account_setting(account, 'active') @@ -107,7 +116,7 @@ def _check_relogin(self): self._relog(account) break - def _relog(self, account): + def _relog(self, account: str) -> None: if not app.account_is_connected(account): return @@ -132,7 +141,7 @@ def relog(): transient_for=self).show() @staticmethod - def _get_relogin_settings(account): + def _get_relogin_settings(account: str) -> list[Any]: if account == app.ZEROCONF_ACC_NAME: settings = ['zeroconf_first_name', 'zeroconf_last_name', 'zeroconf_jabber_id', 'zeroconf_email'] @@ -140,37 +149,37 @@ def _get_relogin_settings(account): settings = ['client_cert', 'proxy', 'resource', 'use_custom_host', 'custom_host', 'custom_port'] - values = [] + values: list[Any] = [] for setting in settings: values.append(app.settings.get_account_setting(account, setting)) return values @staticmethod - def on_remove_account(account): + def on_remove_account(account: str) -> None: if app.settings.get_account_setting(account, 'is_zeroconf'): # Should never happen as button is insensitive return open_window('RemoveAccount', account=account) - def remove_account(self, account): + def remove_account(self, account: str) -> None: del self._need_relogin[account] self._accounts[account].remove() - def add_account(self, account, initial=False): + def add_account(self, account: str, initial: bool = False) -> None: self._need_relogin[account] = self._get_relogin_settings(account) self._accounts[account] = Account(account, self._menu, self._settings) if not initial: self._accounts[account].show() - def select_account(self, account): + def select_account(self, account: str) -> None: try: self._accounts[account].select() except KeyError: log.warning('select_account() failed, account %s not found', account) - def enable_account(self, account, state): + def enable_account(self, account: str, state: bool) -> None: self._accounts[account].enable_account(state) ===================================== gajim/gtk/util.py ===================================== @@ -774,7 +774,7 @@ def get_app_window(name: str, return None -def open_window(name: str, **kwargs: Any) -> Gtk.Window: +def open_window(name: str, **kwargs: Any) -> Any: window = get_app_window(name, kwargs.get('account'), kwargs.get('jid')) ===================================== pyrightconfig.json ===================================== @@ -16,6 +16,7 @@ "gajim/common/regex.py", "gajim/common/sound.py", "gajim/common/storage/", + "gajim/gtk/account_page.py", "gajim/gtk/app_side_bar.py", "gajim/gtk/chat_filter.py", "gajim/gtk/chat_page.py", View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/2f99b1f64ac73f8b3e05b436c664c41…
-- View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/2f99b1f64ac73f8b3e05b436c664c41…
You're receiving this email because of your account on
dev.gajim.org
.
1
0
0
0
[Git][gajim/gajim][master] 5 commits: Settings: Add notification_timeout as IntSetting
by Philipp Hörist (@lovetox)
08 Jan '22
08 Jan '22
Philipp Hörist pushed to branch master at gajim / gajim Commits: 78d02128 by lovetox at 2022-01-08T14:41:24+01:00 Settings: Add notification_timeout as IntSetting - - - - - f06ba0fc by lovetox at 2022-01-08T14:41:24+01:00 Add VariantMixin This Mixin serializes dataclasses to GLib.Variant - - - - - e95ce79a by lovetox at 2022-01-08T14:41:24+01:00 Add constants - - - - - 995c0e69 by lovetox at 2022-01-08T14:41:24+01:00 Contacts: Always return list for groups attr - - - - - 2f99b1f6 by lovetox at 2022-01-08T14:45:48+01:00 Notifications: Refactor - Split code into various backends - Rename attributes on Notification dataclass - - - - - 15 changed files: - gajim/common/client.py - gajim/common/const.py - gajim/common/events.py - gajim/common/modules/contacts.py - gajim/common/setting_values.py - gajim/common/structs.py - gajim/gtk/application.py - gajim/gtk/call_widget.py - gajim/gtk/controls/base.py - gajim/gtk/filetransfer.py - gajim/gtk/notification.py - gajim/gtk/notification_manager.py - + gajim/gtk/structs.py - gajim/gui_interface.py - pyrightconfig.json Changes: ===================================== gajim/common/client.py ===================================== @@ -293,7 +293,7 @@ def _on_password(password: str) -> None: app.ged.raise_event( Notification(account=self._account, - notif_type='connection-failed', + type='connection-failed', title=_('Authentication failed'), text=text or error)) ===================================== gajim/common/const.py ===================================== @@ -32,6 +32,10 @@ from gajim.common.i18n import Q_ +STOP_EVENT = True +PROPAGATE_EVENT = False + + class EncryptionData(NamedTuple): additional_data: Any = None ===================================== gajim/common/events.py ===================================== @@ -89,11 +89,11 @@ class PasswordRequired(ApplicationEvent): class Notification(ApplicationEvent): name: str = field(init=False, default='notification') account: str - notif_type: str + type: str title: str text: str jid: Optional[Union[JID, str]] = None - notif_detail: Optional[str] = None + sub_type: Optional[str] = None sound: Optional[str] = None icon_name: Optional[str] = None ===================================== gajim/common/modules/contacts.py ===================================== @@ -384,8 +384,11 @@ def subscription(self): return self._get_roster_attr('subscription') @property - def groups(self): - return self._get_roster_attr('groups') + def groups(self) -> list[str]: + groups = self._get_roster_attr('groups') + if groups is None: + return [] + return groups @property def is_subscribed(self) -> bool: ===================================== gajim/common/setting_values.py ===================================== @@ -109,6 +109,7 @@ class _ACCOUNT_DEFAULT: 'mainwin_width', 'mainwin_x_position', 'mainwin_y_position', + 'notification_timeout', 'notification_position_x', 'notification_position_y', 'preview_max_file_size', ===================================== gajim/common/structs.py ===================================== @@ -12,13 +12,20 @@ # You should have received a copy of the GNU General Public License # along with Gajim. If not, see <
http://www.gnu.org/licenses/
>. +from __future__ import annotations + +from typing import Any from typing import Dict +from typing import Type +from typing import TypeVar from typing import NamedTuple from typing import Optional from typing import Union import time from dataclasses import dataclass +from dataclasses import fields +from gi.repository import GLib from nbxmpp.protocol import JID from nbxmpp.const import Role @@ -32,6 +39,9 @@ from gajim.common.const import URIAction +_T = TypeVar('_T') + + class URI(NamedTuple): type: URIType action: Optional[URIAction] = None @@ -234,3 +244,68 @@ def from_presence(cls, properties): affiliation=Affiliation.NONE, role=Role.NONE, real_jid=None) + +class VariantMixin: + + _type_to_variant_funcs = { + JID: str, + } + + _variant_to_type_funcs = { + 'JID': JID.from_string, + } + + def _get_type_and_variant_string(self, + field_type: str) -> tuple[Type[Any], str]: + variant_str = '' + if 'Optional' in field_type: + variant_str = 'm' + + if 'str' in field_type: + return str, f'{variant_str}s' + + if 'int' in field_type: + return str, f'{variant_str}i' + + if 'JID' in field_type: + return JID, f'{variant_str}s' + + raise ValueError('unknown type: %s' % field_type) + + def to_variant(self) -> GLib.Variant: + __types = {} + vdict = {} + for field in fields(self): + value = getattr(self, field.name) + field_t, variant_str = self._get_type_and_variant_string(field.type) + if value is None: + vdict[field.name] = GLib.Variant(variant_str, value) + continue + + if not isinstance(value, field_t): + raise ValueError('invalid type: %s is not a %s' % (value, + field_t)) + + conversion_func = self._type_to_variant_funcs.get(field_t) + if conversion_func is not None: + value = conversion_func(value) + __types[field.name] = field_t.__name__ + + vdict[field.name] = GLib.Variant(variant_str, value) + + if __types: + vdict['__types'] = GLib.Variant('a{ss}', __types) + return GLib.Variant('a{sv}', vdict) + + @classmethod + def from_variant(cls: Type[_T], variant: GLib.Variant) -> _T: + vdict = variant.unpack() + __types = vdict.pop('__types', None) + if __types is not None: + for field_name, value_t_name in __types.items(): + value = vdict[field_name] + conversion_func = cls._variant_to_type_funcs.get(value_t_name) + if conversion_func is None: + raise ValueError('no conversion for: %s' % value_t_name) + vdict[field_name] = conversion_func(value) + return cls(**vdict) ===================================== gajim/gtk/application.py ===================================== @@ -70,11 +70,12 @@ from gajim.gui import menus from gajim.gui.builder import get_builder from gajim.gui.util import load_user_iconsets +from gajim.gui.util import open_window +from gajim.gui.util import get_app_window from gajim.gui.dialogs import ShortcutsWindow from gajim.gui.about import AboutDialog from gajim.gui.discovery import ServiceDiscoveryWindow -from gajim.gui.util import open_window -from gajim.gui.util import get_app_window +from gajim.gui.structs import OpenEventActionParams ActionListT = list[tuple[str, @@ -210,7 +211,11 @@ def _startup(self, _application: GajimApplication) -> None: builder = get_builder('application_menu.ui') self.set_menubar(cast(Gio.Menu, builder.get_object('menubar'))) + from gajim.gui import notification + notification.init() + from gajim.gui_interface import Interface + self.interface = Interface() self.interface.run(self) self.add_actions() @@ -706,9 +711,23 @@ def _on_file_transfer_action(_action: Gio.SimpleAction, @staticmethod def _on_open_event_action(_action: Gio.SimpleAction, param: GLib.Variant) -> None: - dict_ = param.unpack() - app.interface.handle_event( - dict_['account'], dict_['jid'], dict_['notif_detail']) + params = OpenEventActionParams.from_variant(param) + + if params.type in ('connection-failed', + 'subscription-request', + 'unsubscribed', + 'group-chat-invitation'): + + app.window.show_account_page(params.account) + + elif params.type in ('incoming-message', + 'incoming-call', + 'file-transfer'): + + assert params.jid is not None + app.window.select_chat(params.account, params.jid) + + app.window.present_with_time(Gtk.get_current_event_time()) @staticmethod def _on_mark_as_read_action(_action: Gio.SimpleAction, ===================================== gajim/gtk/call_widget.py ===================================== @@ -247,7 +247,7 @@ def _on_jingle_request(self, event): app.ged.raise_event( Notification(account=self._account, jid=self._contact.jid, - notif_type='incoming-call', + type='incoming-call', title=_('Incoming Call'), text=_('%s is calling') % self._contact.name)) ===================================== gajim/gtk/controls/base.py ===================================== @@ -1301,8 +1301,8 @@ def _notify(self, app.ged.raise_event( Notification(account=self.account, jid=self.contact.jid, - notif_type='incoming-message', - notif_detail=msg_type, + type='incoming-message', + sub_type=msg_type, title=title, text=text, sound=sound)) ===================================== gajim/gtk/filetransfer.py ===================================== @@ -188,8 +188,8 @@ def _file_completed(self, event): app.ged.raise_event( Notification(account=event.account, jid=event.jid, - notif_type='file-transfer', - notif_detail='file-completed', + type='file-transfer', + sub_type='file-completed', title=_('File Transfer Completed'), text=_('File: %s') % event.file_props.name)) @@ -210,8 +210,8 @@ def _file_send_error(self, event): app.ged.raise_event( Notification(account=event.account, jid=event.jid, - notif_type='file-transfer', - notif_detail='file-send-error', + type='file-transfer', + sub_type='file-send-error', title=_('File Transfer Failed'), text=_('File: %s') % event.file_props.name)) @@ -226,9 +226,9 @@ def _file_request_error(self, event): return if errno in (-4, -5): - notif_detail = 'file-error' + sub_type = 'file-error' else: - notif_detail = 'file-request-error' + sub_type = 'file-request-error' if app.window.is_chat_active(account, event.jid): return @@ -237,8 +237,8 @@ def _file_request_error(self, event): app.ged.raise_event( Notification(account=account, jid=event.jid, - notif_type='file-transfer', - notif_detail=notif_detail, + type='file-transfer', + sub_type=sub_type, title=_('File Transfer Failed'), text=text)) @@ -264,8 +264,8 @@ def _file_request_received(self, event): app.ged.raise_event( Notification(account=account, jid=event.jid, - notif_type='file-transfer', - notif_detail='file-request-received', + type='file-transfer', + sub_type='file-request-received', title=_('File Offered'), text=text)) ===================================== gajim/gtk/notification.py ===================================== @@ -26,6 +26,7 @@ from __future__ import annotations +from typing import Any from typing import Optional from typing import Union @@ -49,10 +50,11 @@ from gajim.common.helpers import play_sound from gajim.common.ged import EventHelper -from .util import add_css_to_widget from .builder import get_builder +from .util import add_css_to_widget from .util import get_monitor_scale_factor from .util import get_total_screen_geometry +from .structs import OpenEventActionParams log = logging.getLogger('gajim.gui.notification') @@ -68,52 +70,17 @@ } -class Notification(EventHelper): - """ - Handle notifications - """ +_notification_backend = None + +class NotificationBackend(EventHelper): def __init__(self) -> None: EventHelper.__init__(self) - self._dbus_available: bool = False - self._daemon_capabilities = ['actions'] - self._win32_active_popup = None - - self._detect_dbus_caps() self.register_events([ ('notification', ged.GUI2, self._on_notification), ('our-show', ged.GUI2, self._on_our_show) ]) - def _detect_dbus_caps(self) -> None: - if sys.platform in ('win32', 'darwin'): - return - - if app.is_flatpak(): - self._dbus_available = True - return - - def on_proxy_ready(_source: Gio.DBusProxy, - res: Gio.AsyncResult) -> None: - try: - proxy = Gio.DBusProxy.new_finish(res) - self._daemon_capabilities = proxy.GetCapabilities() - except GLib.Error as error: - log.warning('Notifications D-Bus not available: %s', error) - else: - self._dbus_available = True - log.info('Notifications D-Bus connected') - - log.info('Connecting to Notifications D-Bus') - Gio.DBusProxy.new_for_bus(Gio.BusType.SESSION, - Gio.DBusProxyFlags.DO_NOT_CONNECT_SIGNALS, - None, - 'org.freedesktop.Notifications', - '/org/freedesktop/Notifications', - 'org.freedesktop.Notifications', - None, - on_proxy_ready) - def _on_notification(self, event: events.Notification) -> None: if event.sound is not None: play_sound(event.sound, event.account) @@ -121,154 +88,62 @@ def _on_notification(self, event: events.Notification) -> None: if not allow_showing_notification(event.account): return - notif_detail = event.notif_detail or event.notif_type - - if event.icon_name is not None: - icon_name = event.icon_name - else: - icon_name = NOTIFICATION_ICONS.get(notif_detail, 'mail-unread') - - self._issue_notification( - event.notif_type, - event.account, - event.jid, - notif_detail=notif_detail, - title=event.title, - text=event.text, - icon_name=icon_name) + self._send(event) def _on_our_show(self, event: events.ShowChanged) -> None: - if app.account_is_connected(event.account): - self._withdraw('connection-failed', event.account) - - def _issue_notification(self, - notif_type: str, - account: str, - jid: Optional[Union[str, JID]], - notif_detail: str = '', - title: str = '', - text: str = '', - icon_name: Optional[str] = None, - timeout: int = -1 - ) -> None: - """ - Notify a user of an event using GNotification and GApplication under - Linux, Use PopupNotificationWindow under Windows - """ - if jid is not None: - jid = str(jid) - - if icon_name is None: - icon_name = 'mail-message-new' - - if timeout < 0: - timeout = app.settings.get('notification_timeout') - - title = GLib.markup_escape_text(title) - text = GLib.markup_escape_text(text) - - if sys.platform == 'win32': - self._withdraw() - self._win32_active_popup = PopupNotification( - notif_type, - account, - jid, - notif_detail, - title, - text, - icon_name, - timeout) - self._win32_active_popup.connect('destroy', self._on_popup_destroy) + if not app.account_is_connected(event.account): return + self._withdraw(['connection-failed', event.account]) - if not self._dbus_available: - return + def _send(self, event: events.Notification) -> None: + raise NotImplementedError - icon = Gio.ThemedIcon.new(icon_name) + def _withdraw(self, details: list[Any]) -> None: + raise NotImplementedError - notification = Gio.Notification() - if title is not None: - notification.set_title(title) - if text is not None: - notification.set_body(text) - notif_id = None - if notif_type in ( - 'incoming-message', - 'file-transfer', - 'group-chat-invitation', - 'subscription-request', - 'unsubscribed', - 'incoming-call', - 'connection-failed'): - if 'actions' in self._daemon_capabilities: - # Create Variant Dict - dict_ = {'account': GLib.Variant('s', account), - 'jid': GLib.Variant('s', jid), - 'notif_detail': GLib.Variant('s', notif_detail)} - variant_dict = GLib.Variant('a{sv}', dict_) - - # Add 'Open' action button to notification - action = f'app.{account}-open-event' - notification.add_button_with_target( - _('Open'), action, variant_dict) - notification.set_default_action_and_target( - action, variant_dict) - - if notif_type == 'incoming-message': - # Add 'Mark as Read' action button to notification - action = f'app.{account}-mark-as-read' - notification.add_button_with_target( - _('Mark as Read'), action, variant_dict) - - # Only one notification per JID - if notif_type == 'connection-failed': - notif_id = self._make_id('connection-failed', account) - elif notif_type == 'incoming-message': - if app.desktop_env == 'gnome': - icon = self._get_avatar_for_notification(account, jid) - notif_id = self._make_id('new-message', account, jid) - notification.set_icon(icon) - notification.set_priority(Gio.NotificationPriority.NORMAL) +class DummyBackend(NotificationBackend): - app.app.send_notification(notif_id, notification) + def _send(self, event: events.Notification) -> None: + pass - @staticmethod - def _get_avatar_for_notification(account: str, - jid: str - ) -> GdkPixbuf.Pixbuf: - scale = get_monitor_scale_factor() - client = app.get_client(account) - contact = client.get_module('Contacts').get_contact(jid) - return app.interface.get_avatar( - contact, AvatarSize.NOTIFICATION, scale, pixbuf=True) + def _withdraw(self, details: list[Any]) -> None: + pass - def _on_popup_destroy(self, *args): - self._win32_active_popup = None - def _withdraw(self, *args): - if sys.platform == 'win32': - if self._win32_active_popup is not None: - self._win32_active_popup.destroy() - elif self._dbus_available: - app.app.withdraw_notification(self._make_id(*args)) +class Windows(NotificationBackend): + def __init__(self): + NotificationBackend.__init__(self) + self._active_notification = None - @staticmethod - def _make_id(*args): - return ','.join(map(str, args)) + def _send(self, event: events.Notification) -> None: + timeout = app.settings.get('notification_timeout') + self._withdraw() + self._win32_active_popup = PopupNotification(event, timeout) + + def _on_popup_destroy(_widget: Gtk.Window) -> None: + self._win32_active_popup = None + + self._win32_active_popup.connect('destroy', _on_popup_destroy) + + def _withdraw(self, *args: Any) -> None: + if self._win32_active_popup is not None: + self._win32_active_popup.destroy() class PopupNotification(Gtk.Window): - def __init__(self, - notif_type: str, - account: str, - jid: Optional[str], - notif_detail: str, - title: str, - text: str, - icon_name: str, - timeout: int - ) -> None: + + _background_class = { + 'incoming-message': '.gajim-notify-message', + 'file-error': '.gajim-notify-error', + 'file-send-error': '.gajim-notify-error', + 'file-request-error': '.gajim-notify-error', + 'file-completed': '.gajim-notify-success', + 'file-stopped': '.gajim-notify-success', + 'group-chat-invitation': '.gajim-notify-invite', + } + + def __init__(self, event: events.Notification, timeout: int) -> None: Gtk.Window.__init__(self) self.set_type_hint(Gdk.WindowTypeHint.NOTIFICATION) self.set_focus_on_map(False) @@ -277,48 +152,19 @@ def __init__(self, self.set_decorated(False) self._timeout_id: Optional[int] = None - self._account = account - self._jid = jid - self._notif_type = notif_type + self._event = event self._ui = get_builder('popup_notification_window.ui') self.add(self._ui.eventbox) - if notif_detail == 'incoming-message': - bg_color = app.css_config.get_value('.gajim-notify-message', - StyleAttr.COLOR) - elif notif_detail in ('file-error', - 'file-send-error', - 'file-request-error'): - bg_color = app.css_config.get_value('.gajim-notify-error', - StyleAttr.COLOR) - elif notif_detail in ('file-completed', 'file-stopped'): - bg_color = app.css_config.get_value('.gajim-notify-success', - StyleAttr.COLOR) - elif notif_detail == 'group-chat-invitation': - bg_color = app.css_config.get_value('.gajim-notify-invite', - StyleAttr.COLOR) - else: - bg_color = app.css_config.get_value('.gajim-notify-other', - StyleAttr.COLOR) - - bar_class = ''' - .popup-bar { - background-color: %s - }''' % bg_color - add_css_to_widget(self._ui.color_bar, bar_class) - self._ui.color_bar.get_style_context().add_class('popup-bar') - - self._ui.event_type_label.set_markup(title) - - if not text: - client = app.get_client(account) - contact = client.get_module('Contacts').get_contact(jid) - text = contact.name - escaped_text = GLib.markup_escape_text(text) - self._ui.event_description_label.set_markup(escaped_text) - + self._add_background_color(event) + icon_name = self._get_icon_name(event) self._ui.image.set_from_icon_name(icon_name, Gtk.IconSize.DIALOG) + self._ui.event_type_label.set_text(event.title) + self._ui.event_description_label.set_text(event.text) + + if timeout > 0: + self._timeout_id = GLib.timeout_add_seconds(timeout, self.destroy) self.move(*self._get_window_pos()) @@ -326,8 +172,24 @@ def __init__(self, self.connect('button-press-event', self._on_button_press) self.connect('destroy', self._on_destroy) self.show_all() - if timeout > 0: - self._timeout_id = GLib.timeout_add_seconds(timeout, self.destroy) + + def _get_icon_name(self, event: events.Notification) -> str: + if event.icon_name is not None: + return event.icon_name + icon_name = event.sub_type or event.type + return NOTIFICATION_ICONS.get(icon_name, 'mail-unread') + + def _add_background_color(self, event: events.Notification) -> None: + event_type = event.sub_type or event.type + css_class = self._background_class.get(event_type, + '.gajim-notify-other') + bg_color = app.css_config.get_value(css_class, StyleAttr.COLOR) + bar_class = ''' + .popup-bar { + background-color: %s + }''' % bg_color + add_css_to_widget(self._ui.color_bar, bar_class) + self._ui.color_bar.get_style_context().add_class('popup-bar') @staticmethod def _get_window_pos() -> tuple[int, int]: @@ -348,10 +210,169 @@ def _on_button_press(self, event: Gdk.EventButton ) -> None: if event.button == 1: - app.interface.handle_event( - self._account, self._jid, self._notif_type) + jid = self._event.jid + if jid is not None and isinstance(jid, str): + jid = JID.from_string(jid) + + params = OpenEventActionParams(type=self._event.type, + sub_type=self._event.sub_type, + account=self._event.account, + jid=jid) + app.app.activate_action(f'app.{self._event.account}-open-event', + params.to_variant()) + self.destroy() def _on_destroy(self, _widget: Gtk.Window) -> None: if self._timeout_id is not None: GLib.source_remove(self._timeout_id) + + +class Linux(NotificationBackend): + + _action_types = [ + 'connection-failed', + 'file-transfer', + 'group-chat-invitation', + 'incoming-call', + 'incoming-message', + 'subscription-request', + 'unsubscribed', + ] + + def __init__(self): + NotificationBackend.__init__(self) + self._dbus_available: bool = False + self._daemon_capabilities = ['actions'] + self._detect_dbus_caps() + + def _detect_dbus_caps(self) -> None: + if app.is_flatpak(): + self._dbus_available = True + return + + def on_proxy_ready(_source: Gio.DBusProxy, + res: Gio.AsyncResult) -> None: + try: + proxy = Gio.DBusProxy.new_finish(res) + self._daemon_capabilities = proxy.GetCapabilities() # type: ignore + except GLib.Error as error: + log.warning('Notifications D-Bus not available: %s', error) + else: + self._dbus_available = True + log.info('Notifications D-Bus connected') + + log.info('Connecting to Notifications D-Bus') + Gio.DBusProxy.new_for_bus(Gio.BusType.SESSION, + Gio.DBusProxyFlags.DO_NOT_CONNECT_SIGNALS, + None, + 'org.freedesktop.Notifications', + '/org/freedesktop/Notifications', + 'org.freedesktop.Notifications', + None, + on_proxy_ready) + + def _send(self, event: events.Notification) -> None: + if not self._dbus_available: + return + + notification = Gio.Notification() + if event.title is not None: + notification.set_title(GLib.markup_escape_text(event.title)) + notification.set_body(GLib.markup_escape_text(event.text)) + notification.set_priority(Gio.NotificationPriority.NORMAL) + + icon = self._make_icon(event) + notification.set_icon(icon) + + self._add_actions(event, notification) + notification_id = self._make_notification_id(event) + + app.app.send_notification(notification_id, notification) + + def _add_actions(self, + event: events.Notification, + notification: Gio.Notification) -> None: + + if event.type not in self._action_types: + return + + if 'actions' not in self._daemon_capabilities: + return + + jid = event.jid + if jid is not None and isinstance(jid, str): + jid = JID.from_string(jid) + + params = OpenEventActionParams(type=event.type, + sub_type=event.sub_type, + account=event.account, + jid=jid) + + action = f'app.{event.account}-open-event' + notification.add_button_with_target( + _('Open'), action, params.to_variant()) + notification.set_default_action_and_target( + action, params.to_variant()) + + if event.type == 'incoming-message': + action = f'app.{event.account}-mark-as-read' + notification.add_button_with_target( + _('Mark as Read'), action, params.to_variant()) + + def _make_notification_id(self, + event: events.Notification) -> Optional[str]: + if event.type == 'connection-failed': + return self._make_id(['connection-failed', event.account]) + + if event.type == 'incoming-message': + return self._make_id(['new-message', event.account, str(event.jid)]) + + return None + + @staticmethod + def _get_avatar_for_notification(account: str, + jid: Union[JID, str]) -> GdkPixbuf.Pixbuf: + scale = get_monitor_scale_factor() + client = app.get_client(account) + contact = client.get_module('Contacts').get_contact(jid) + return app.interface.get_avatar(contact, + AvatarSize.NOTIFICATION, + scale, + pixbuf=True) + + def _make_icon(self, event: events.Notification) -> Gio.Icon: + if (event.type == 'incoming-message' and app.desktop_env == 'gnome'): + assert event.jid is not None + return self._get_avatar_for_notification(event.account, event.jid) + + if event.icon_name is not None: + return Gio.ThemedIcon.new(event.icon_name) + + icon_name = event.sub_type or event.type + icon_name = NOTIFICATION_ICONS.get(icon_name, 'mail-unread') + return Gio.ThemedIcon.new(icon_name) + + def _withdraw(self, details: list[Any]) -> None: + if not self._dbus_available: + return + notification_id = self._make_id(details) + app.app.withdraw_notification(notification_id) + + @staticmethod + def _make_id(details: list[Any]) -> str: + return ','.join(map(str, details)) + + +def get_notification_backend() -> NotificationBackend: + if sys.platform == 'win32': + return Windows() + + if sys.platform == 'darwin': + return DummyBackend() + return Linux() + + +def init() -> None: + global _notification_backend # pylint: disable=global-statement + _notification_backend = get_notification_backend() ===================================== gajim/gtk/notification_manager.py ===================================== @@ -173,7 +173,7 @@ def add_subscription_request(self, app.ged.raise_event( Notification(account=self._account, jid=event.jid, - notif_type='subscription-request', + type='subscription-request', title=_('Subscription Request'), text=text)) elif row.type == 'unsubscribed': @@ -193,7 +193,7 @@ def add_unsubscribed(self, app.ged.raise_event( Notification(account=self._account, jid=event.jid, - notif_type='unsubscribed', + type='unsubscribed', title=_('Contact Unsubscribed'), text=text)) elif row.type == 'subscribe': @@ -216,7 +216,7 @@ def add_invitation_received(self, event: MucInvitation) -> None: app.ged.raise_event( Notification(account=self._account, jid=jid, - notif_type='group-chat-invitation', + type='group-chat-invitation', title=_('Group Chat Invitation'), text=text)) ===================================== gajim/gtk/structs.py ===================================== @@ -0,0 +1,31 @@ +# This file is part of Gajim. +# +# Gajim is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published +# by the Free Software Foundation; version 3 only. +# +# Gajim is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Gajim. If not, see <
http://www.gnu.org/licenses/
>. + +from __future__ import annotations + +from typing import Optional + +from dataclasses import dataclass + +from nbxmpp.protocol import JID + +from gajim.common.structs import VariantMixin + + +@dataclass +class OpenEventActionParams(VariantMixin): + type: str + sub_type: Optional[str] + account: str + jid: Optional[JID] ===================================== gajim/gui_interface.py ===================================== @@ -33,6 +33,7 @@ from __future__ import annotations +from typing import Any from typing import Dict from typing import Optional from typing import Union @@ -92,7 +93,6 @@ from gajim.common.modules.httpupload import HTTPFileTransfer from gajim.gui.avatar import AvatarStorage -from gajim.gui.notification import Notification from gajim.gui.dialogs import DialogButton from gajim.gui.dialogs import ErrorDialog from gajim.gui.dialogs import WarningDialog @@ -144,8 +144,6 @@ def __init__(self): app.proxy65_manager = proxy65_manager.Proxy65Manager(app.idlequeue) - app.notification = Notification() - self._create_core_handlers_list() self._register_core_handlers() @@ -237,26 +235,6 @@ def _register_core_handlers(self) -> None: prio, event_handler) - def handle_event(self, account: str, jid: str, notif_detail: str) -> None: - jid = JID.from_string(jid) - - if notif_detail in ('connection-lost', 'connection-failed'): - app.window.show_account_page(account) - elif notif_detail == 'private-chat-message': - app.window.select_chat(account, jid) - elif notif_detail in ('chat-message', 'group-chat-message'): - app.window.select_chat(account, jid.bare) - elif notif_detail == 'incoming-call': - app.window.select_chat(account, jid.bare) - elif notif_detail == 'file-request-received': - app.window.select_chat(account, jid.bare) - elif notif_detail in ('subscription-request', - 'unsubscribed', - 'group-chat-invitation'): - app.window.show_account_page(account) - - app.window.present_with_time(Gtk.get_current_event_time()) - @staticmethod def handle_event_information(event): if not event.popup: @@ -983,7 +961,7 @@ def get_avatar(self, scale: int, show: Optional[str] = None, pixbuf: bool = False, - style: str = 'circle'): + style: str = 'circle') -> Any: if pixbuf: return self.avatar_storage.get_pixbuf( contact, size, scale, show, style=style) ===================================== pyrightconfig.json ===================================== @@ -35,6 +35,7 @@ "gajim/gtk/conversation/rows/scroll_hint.py", "gajim/gtk/conversation/rows/widgets.py", "gajim/gtk/conversation/scrolled.py", + "gajim/gtk/notification.py", "gajim/gtk/status_message_selector.py", "gajim/gtk/status_selector.py", ], View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/5477bd0308b5e4574aa38ee67104f00…
-- View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/5477bd0308b5e4574aa38ee67104f00…
You're receiving this email because of your account on
dev.gajim.org
.
1
0
0
0
← Newer
1
...
11
12
13
14
15
16
17
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Results per page:
10
25
50
100
200