From 0dde1759e89d39ccf57bc3795800da652305d2ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Sun, 1 Jul 2018 13:30:13 +0200 Subject: [PATCH] Make Profile a GtkApplicationWindow Fixes #9180 --- gajim/data/gui/profile_window.ui | 2072 +++++++++++++++--------------- gajim/gui_interface.py | 8 +- gajim/profile_window.py | 68 +- 3 files changed, 1071 insertions(+), 1077 deletions(-) diff --git a/gajim/data/gui/profile_window.ui b/gajim/data/gui/profile_window.ui index 8691f57ae..837d1cded 100644 --- a/gajim/data/gui/profile_window.ui +++ b/gajim/data/gui/profile_window.ui @@ -1,272 +1,156 @@ - + - + + True False - Profile - dialog - - + vertical - + True False - vertical + 6 + 6 + 6 + 6 + True + - + True False - 6 - 6 - 6 - 6 - True - + 18 + 18 + 18 + 18 + vertical + 18 True False - 18 - 18 - 18 - 18 - vertical 18 + 150 True False - 18 + vertical + 6 - - 150 + True - False - vertical - 6 + True + False + - + True - True - False - + False - + True False - - - True - False - gtk-missing-image - - - -1 - - - - - True - True - True - True - Clear Avatar - end - start - 6 - 6 - 6 - 6 - True - - - - True - False - window-close - - - - - + gtk-missing-image + + -1 + - - - - False - False - 0 - - - - - 140 - 140 - True - True - False - True - start - start - True - - - + + True - False - center - vertical - 18 + True + True + True + Clear Avatar + end + start + 6 + 6 + 6 + 6 + True + True False - 10 - avatar-default - 6 + window-close - - False - True - 0 - - - - - True - False - Set Avatar… - - - False - True - 1 - + - - - False - False - 1 - + False - True + False 0 - + + 140 + 140 True - False - 6 - 12 + True + False + True + start + start + True + - + True False - end - Full Name - True - right - + center + vertical + 18 + + + True + False + 10 + avatar-default + 6 + + + False + True + 0 + + + + + True + False + Set Avatar… + + + False + True + 1 + + - - 0 - 2 - - - - - True - True - True - - - 1 - 1 - - - - - True - True - True - - - 1 - 2 - - - - - True - False - end - Nickname - True - right - - - - 0 - 1 - - - - - True - False - end - 6 - 12 - Account - True - right - - - - 0 - 0 - - - - - True - False - start - 2 - 6 - 12 - - - 1 - 0 - + - True - True + False + False 1 @@ -278,120 +162,56 @@ - + True False 6 12 - + + True + False + end + Full Name + True + right + + + + 0 + 2 + + + + True True True - - 1 - 0 - 3 - - - - - True - True - 1 1 - 3 - - True - False - end - Phone No. - True - right - - - - 0 - 3 - - - - + True True + True 1 - 3 + 2 - - True - True - - - - 3 - 3 - - - - - True - False - Format: YYYY-MM-DD - False - - - True - False - end - Birthday - True - right - - - - - - 2 - 3 - - - - + True False end - Homepage - True - right - - - - 0 - 0 - - - - - True - False - end - E-Mail + Nickname True right + True + True 1 - 1 + 0 + 3 - + True True - 2 + 1 1 + 3 - + True False end - Given + Phone No. True right - 3 - 1 + 0 + 3 - + True True - - 4 - 1 - - - - - True - False - end - Middle - True - - - - 1 - 2 - - - - - True - False - end - Prefix - True - right - - 1 3 - + True True - - - 2 - 2 - - - - - True - True - - - 2 - 3 - - - - - True - False - end - Suffix - True - right - + 3 @@ -586,17 +338,693 @@ - + True - True + False + Format: YYYY-MM-DD + False + + + True + False + end + Birthday + True + right + + + - 4 + 2 3 - + + True + False + end + Homepage + True + right + + + + 0 + 0 + + + + + True + False + end + E-Mail + True + right + + + + 0 + 1 + + + + + True + False + end + Jabber ID + True + right + + + + 0 + 2 + + + + + True + True + + + 1 + 2 + 3 + + + + + False + True + 3 + + + + + + + True + False + Main + + + False + + + + + True + False + start + 18 + 18 + 18 + 18 + 6 + 12 + + + True + False + end + Family + True + right + + + + 1 + 1 + + + + + True + True + + + 2 + 1 + + + + + True + False + end + Given + True + right + + + + 3 + 1 + + + + + True + True + + + 4 + 1 + + + + + True + False + end + Middle + True + + + + 1 + 2 + + + + + True + False + end + Prefix + True + right + + + + 1 + 3 + + + + + True + True + + + 2 + 2 + + + + + True + True + + + 2 + 3 + + + + + True + False + end + Suffix + True + right + + + + 3 + 3 + + + + + True + True + + + 4 + 3 + + + + + True + False + end + Street + True + right + + + + 1 + 5 + + + + + True + True + True + + + 2 + 5 + + + + + True + False + end + Extra Address + True + right + + + + 3 + 5 + + + + + True + True + True + + + 4 + 5 + + + + + True + False + end + City + True + right + + + + 1 + 6 + + + + + True + False + end + State + True + right + + + + 1 + 7 + + + + + True + True + + + 2 + 7 + + + + + True + True + + + 2 + 6 + + + + + True + True + + + 4 + 6 + + + + + True + False + end + Postal Code + True + right + + + + 3 + 6 + + + + + True + True + + + 4 + 7 + + + + + True + False + end + Country + True + right + + + + 3 + 7 + + + + + True + False + start + 12 + <b>Address</b> + True + + + 0 + 4 + 5 + + + + + 12 + True + False + + + 0 + 1 + + + + + True + False + start + <b>Name Details</b> + True + + + 0 + 0 + 5 + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + + + + + True + False + Personal + + + 1 + False + + + + + True + False + 18 + 18 + 18 + 18 + vertical + 18 + + + True + False + 6 + 12 + + + True + False + end + Company + True + right + + + + 0 + 0 + + + + + True + True + True + + + 1 + 0 + + + + + True + False + end + Department + True + + + + 2 + 0 + + + + + True + True + True + + + 3 + 0 + + + + + True + False + end + Position + True + right + + + + 0 + 1 + + + + + True + True + + + 1 + 1 + + + + + True + True + + + 3 + 1 + + + + + True + False + end + Role + True + right + + + + 2 + 1 + + + + + False + True + 0 + + + + + True + False + start + 6 + 12 + + + True + False + end + E-Mail + True + right + + + + 1 + 5 + + + + + True + True + + + 2 + 5 + 3 + + + + + True + False + end + Phone No. + True + right + + + + 1 + 6 + + + + + True + True + + + 2 + 6 + + + + True False end @@ -609,22 +1037,21 @@ 1 - 5 + 1 - + True True - True 2 - 5 + 1 - + True False end @@ -637,22 +1064,21 @@ 3 - 5 + 1 - + True True - True 4 - 5 + 1 - + True False end @@ -665,11 +1091,57 @@ 1 - 6 + 2 - + + True + True + + + 2 + 2 + + + + + True + False + end + Postal Code + right + + + + 3 + 2 + + + + + True + True + + + 4 + 2 + + + + + True + True + + + 2 + 3 + + + + True False end @@ -682,68 +1154,21 @@ 1 - 7 + 3 - - True - True - - - 2 - 7 - - - - - True - True - - - 2 - 6 - - - - + True True 4 - 6 + 3 - - True - False - end - Postal Code - True - right - - - - 3 - 6 - - - - - True - True - - - 4 - 7 - - - - + True False end @@ -756,7 +1181,21 @@ 3 - 7 + 3 + + + + + True + False + start + <b>Address</b> + True + + + 0 + 0 + 5 @@ -765,7 +1204,7 @@ False start 12 - <b>Address</b> + <b>Contact</b> True @@ -785,23 +1224,6 @@ 1 - - - True - False - start - <b>Name Details</b> - True - - - 0 - 0 - 5 - - - - - @@ -822,515 +1244,123 @@ + False + True 1 - - - True - False - Personal - - - 1 - False - - - - - True - False - 18 - 18 - 18 - 18 - vertical - 18 - - - True - False - 6 - 12 - - - True - False - end - Company - True - right - - - - 0 - 0 - - - - - True - True - True - - - 1 - 0 - - - - - True - False - end - Department - True - - - - 2 - 0 - - - - - True - True - True - - - 3 - 0 - - - - - True - False - end - Position - True - right - - - - 0 - 1 - - - - - True - True - - - 1 - 1 - - - - - True - True - - - 3 - 1 - - - - - True - False - end - Role - True - right - - - - 2 - 1 - - - - - False - True - 0 - - - - - True - False - start - 6 - 12 - - - True - False - end - E-Mail - True - right - - - - 1 - 5 - - - - - True - True - - - 2 - 5 - 3 - - - - - True - False - end - Phone No. - True - right - - - - 1 - 6 - - - - - True - True - - - 2 - 6 - - - - - True - False - end - Street - True - right - - - - 1 - 1 - - - - - True - True - - - 2 - 1 - - - - - True - False - end - Extra Address - True - right - - - - 3 - 1 - - - - - True - True - - - 4 - 1 - - - - - True - False - end - City - True - right - - - - 1 - 2 - - - - - True - True - - - 2 - 2 - - - - - True - False - end - Postal Code - right - - - - 3 - 2 - - - - - True - True - - - 4 - 2 - - - - - True - True - - - 2 - 3 - - - - - True - False - end - State - True - right - - - - 1 - 3 - - - - - True - True - - - 4 - 3 - - - - - True - False - end - Country - True - right - - - - 3 - 3 - - - - - True - False - start - <b>Address</b> - True - - - 0 - 0 - 5 - - - - - True - False - start - 12 - <b>Contact</b> - True - - - 0 - 4 - 5 - - - - - 12 - True - False - - - 0 - 1 - - - - - - - - - - - - - - - - - - - - - - - False - True - 1 - - - - - 2 - - - - - True - False - Work - - - 2 - False - - - - - True - True - 6 - 6 - 6 - 6 - in - - - 70 - True - True - word - 6 - 6 - 6 - - - - - 3 - - - - - True - False - About - - - 3 - False - - - False - True - 0 + 2 + + + + + True + False + Work + + + 2 + False - + True - False + True 6 6 6 6 - 12 + in - + + 70 True - False - + True + word + 6 + 6 + 6 + + + + + 3 + + + + + True + False + About + + + 3 + False + + + + + False + True + 0 + + + + + True + False + 6 + 6 + 6 + 6 + 12 + + + True + False + + + + False + False + 0 + + + + + True + False + center + 0.10000000149 + + + False + False + 1 + + + + + True + False + end + True + 12 + end + + + gtk-cancel + True + True + True + False + True + False @@ -1339,11 +1369,17 @@ - + + gtk-ok True - False - center - 0.10000000149 + True + True + False + True + + False @@ -1351,67 +1387,19 @@ 1 - - - True - False - end - True - 12 - end - - - gtk-cancel - True - True - True - False - True - - - - False - False - 0 - - - - - gtk-ok - True - True - True - False - True - - - - - False - False - 1 - - - - - False - True - 2 - - False True - 1 + 2 - - - + + False + True + 1 + diff --git a/gajim/gui_interface.py b/gajim/gui_interface.py index a02039cf7..69254ec92 100644 --- a/gajim/gui_interface.py +++ b/gajim/gui_interface.py @@ -268,9 +268,11 @@ class Interface: self.show_vcard_when_connect.remove(account) def edit_own_details(self, account): - if 'profile' not in self.instances[account]: - self.instances[account]['profile'] = \ - profile_window.ProfileWindow(account, app.interface.roster.window) + window = app.get_app_window(profile_window.ProfileWindow) + if window is None: + profile_window.ProfileWindow(account) + else: + window.present() @staticmethod def handle_gc_error(gc_control, pritext, sectext): diff --git a/gajim/profile_window.py b/gajim/profile_window.py index 34e1a26e5..08b2a7b3f 100644 --- a/gajim/profile_window.py +++ b/gajim/profile_window.py @@ -20,43 +20,46 @@ ## along with Gajim. If not, see . ## -# THIS FILE IS FOR **OUR** PROFILE (when we edit our INFO) - -from gi.repository import Gtk -from gi.repository import Gdk -from gi.repository import GLib -from gi.repository import GdkPixbuf import base64 import time import logging import hashlib +from gi.repository import Gtk +from gi.repository import Gdk +from gi.repository import GLib + from gajim import gtkgui_helpers from gajim import dialogs from gajim.filechoosers import AvatarChooserDialog from gajim.common.const import AvatarSize - from gajim.common import app from gajim.common import ged log = logging.getLogger('gajim.profile') -class ProfileWindow: - """ - Class for our information window - """ - def __init__(self, account, transient_for=None): +class ProfileWindow(Gtk.ApplicationWindow): + def __init__(self, account): + Gtk.ApplicationWindow.__init__(self) + self.set_application(app.app) + self.set_position(Gtk.WindowPosition.CENTER) + self.set_show_menubar(False) + self.set_title(_('Profile')) + + self.connect('destroy', self.on_profile_window_destroy) + self.connect('key-press-event', self.on_profile_window_key_press_event) + self.xml = gtkgui_helpers.get_gtk_builder('profile_window.ui') - self.window = self.xml.get_object('profile_window') - self.window.set_transient_for(transient_for) + self.add(self.xml.get_object('profile_box')) self.progressbar = self.xml.get_object('progressbar') self.statusbar = self.xml.get_object('statusbar') self.context_id = self.statusbar.get_context_id('profile') self.account = account self.jid = app.get_jid_from_account(account) - account_label = app.config.get_per('accounts', account, 'account_label') + account_label = app.config.get_per( + 'accounts', account, 'account_label') self.set_value('account_label', account_label) self.dialog = None @@ -64,17 +67,18 @@ class ProfileWindow: self.avatar_encoded = None self.avatar_sha = None self.message_id = self.statusbar.push(self.context_id, - _('Retrieving profile…')) - self.update_progressbar_timeout_id = GLib.timeout_add(100, - self.update_progressbar) + _('Retrieving profile…')) + self.update_progressbar_timeout_id = GLib.timeout_add( + 100, self.update_progressbar) self.remove_statusbar_timeout_id = None self.xml.connect_signals(self) app.ged.register_event_handler('vcard-published', ged.GUI1, - self._nec_vcard_published) + self._nec_vcard_published) app.ged.register_event_handler('vcard-not-published', ged.GUI1, - self._nec_vcard_not_published) - self.window.show_all() + self._nec_vcard_not_published) + + self.show_all() self.xml.get_object('ok_button').grab_focus() app.connections[account].get_module('VCardTemp').request_vcard( self._nec_vcard_received, self.jid) @@ -99,13 +103,13 @@ class ProfileWindow: self._nec_vcard_published) app.ged.remove_event_handler('vcard-not-published', ged.GUI1, self._nec_vcard_not_published) - del app.interface.instances[self.account]['profile'] + if self.dialog: # Image chooser dialog self.dialog.destroy() def on_profile_window_key_press_event(self, widget, event): if event.keyval == Gdk.KEY_Escape: - self.window.destroy() + self.destroy() def _clear_photo(self, widget): # empty the image @@ -124,10 +128,10 @@ class ProfileWindow: sha = app.interface.save_avatar(path_to_file, publish=True) if sha is None: dialogs.ErrorDialog( - _('Could not load image'), transient_for=self.window) + _('Could not load image'), transient_for=self) return - scale = self.window.get_scale_factor() + scale = self.get_scale_factor() surface = app.interface.get_avatar(sha, AvatarSize.VCARD, scale) button = self.xml.get_object('PHOTO_button') @@ -142,7 +146,7 @@ class ProfileWindow: self.avatar_encoded = base64.b64encode(publish).decode('utf-8') self.avatar_mime_type = 'image/png' - AvatarChooserDialog(on_ok, transient_for=self.window) + AvatarChooserDialog(on_ok, transient_for=self) def on_PHOTO_button_press_event(self, widget, event): """ @@ -178,7 +182,7 @@ class ProfileWindow: if not widget.is_focus(): pritext = _('Wrong date format') dialogs.ErrorDialog(pritext, _('Format of the date must be ' - 'YYYY-MM-DD'), transient_for=self.window) + 'YYYY-MM-DD'), transient_for=self) GLib.idle_add(lambda: widget.grab_focus()) return True @@ -212,7 +216,7 @@ class ProfileWindow: if 'TYPE' in vcard_[i]: self.avatar_mime_type = vcard_[i]['TYPE'] - scale = self.window.get_scale_factor() + scale = self.get_scale_factor() surface = app.interface.get_avatar( self.avatar_sha, AvatarSize.VCARD, scale) if surface is None: @@ -319,7 +323,7 @@ class ProfileWindow: if app.connections[self.account].connected < 2: dialogs.ErrorDialog(_('You are not connected to the server'), _('Without a connection, you can not publish your contact ' - 'information.'), transient_for=self.window) + 'information.'), transient_for=self) return vcard_, sha = self.make_vcard() nick = '' @@ -344,7 +348,7 @@ class ProfileWindow: if self.update_progressbar_timeout_id is not None: GLib.source_remove(self.update_progressbar_timeout_id) self.update_progressbar_timeout_id = None - self.window.destroy() + self.destroy() def _nec_vcard_not_published(self, obj): if obj.conn.name != self.account: @@ -361,7 +365,7 @@ class ProfileWindow: self.update_progressbar_timeout_id = None dialogs.InformationDialog(_('vCard publication failed'), _('There was an error while publishing your personal information, ' - 'try again later.'), transient_for=self.window) + 'try again later.'), transient_for=self) def on_cancel_button_clicked(self, widget): - self.window.destroy() + self.destroy()