From 78e4e20d496a050207ce03b43faf33a9b38e299d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Sun, 22 Jul 2018 16:53:02 +0200 Subject: [PATCH] Move ProfileWindow into gtk module --- gajim/gtk/__init__.py | 1 + gajim/{profile_window.py => gtk/profile.py} | 124 ++++++++++---------- gajim/gui_interface.py | 6 +- 3 files changed, 68 insertions(+), 63 deletions(-) rename gajim/{profile_window.py => gtk/profile.py} (79%) diff --git a/gajim/gtk/__init__.py b/gajim/gtk/__init__.py index c55c7c756..e7644bf1c 100644 --- a/gajim/gtk/__init__.py +++ b/gajim/gtk/__init__.py @@ -56,3 +56,4 @@ from gajim.gtk.single_message import SingleMessageWindow from gajim.gtk.server_info import ServerInfoDialog from gajim.gtk.pep_config import ManagePEPServicesWindow from gajim.gtk.bookmarks import ManageBookmarksWindow +from gajim.gtk.profile import ProfileWindow diff --git a/gajim/profile_window.py b/gajim/gtk/profile.py similarity index 79% rename from gajim/profile_window.py rename to gajim/gtk/profile.py index 088914d3c..8b8e6bb7d 100644 --- a/gajim/profile_window.py +++ b/gajim/gtk/profile.py @@ -1,24 +1,20 @@ -# -*- coding:utf-8 -*- -## src/profile_window.py -## -## Copyright (C) 2003-2014 Yann Leboulanger -## Copyright (C) 2005-2006 Nikos Kouremenos -## Copyright (C) 2006-2008 Jean-Marie Traissard -## -## 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 . -## +# Copyright (C) 2003-2014 Yann Leboulanger +# Copyright (C) 2005-2006 Nikos Kouremenos +# Copyright (C) 2006-2008 Jean-Marie Traissard +# +# 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 . import base64 import time @@ -32,6 +28,7 @@ from gi.repository import GLib from gajim import gtkgui_helpers from gajim.gtk import ErrorDialog from gajim.gtk import InformationDialog +from gajim.gtk.util import get_builder from gajim.filechoosers import AvatarChooserDialog from gajim.common.const import AvatarSize from gajim.common import app @@ -51,7 +48,7 @@ class ProfileWindow(Gtk.ApplicationWindow): 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.xml = get_builder('profile_window.ui') self.add(self.xml.get_object('profile_box')) self.progressbar = self.xml.get_object('progressbar') self.statusbar = self.xml.get_object('statusbar') @@ -89,7 +86,7 @@ class ProfileWindow(Gtk.ApplicationWindow): def update_progressbar(self): self.progressbar.pulse() - return True # loop forever + return True def remove_statusbar(self, message_id): self.statusbar.remove(self.context_id, message_id) @@ -100,12 +97,12 @@ class ProfileWindow(Gtk.ApplicationWindow): GLib.source_remove(self.update_progressbar_timeout_id) if self.remove_statusbar_timeout_id is not None: GLib.source_remove(self.remove_statusbar_timeout_id) - app.ged.remove_event_handler('vcard-published', ged.GUI1, - self._nec_vcard_published) - app.ged.remove_event_handler('vcard-not-published', ged.GUI1, - self._nec_vcard_not_published) + app.ged.remove_event_handler( + 'vcard-published', ged.GUI1, self._nec_vcard_published) + app.ged.remove_event_handler( + 'vcard-not-published', ged.GUI1, self._nec_vcard_not_published) - if self.dialog: # Image chooser dialog + if self.dialog: # Image chooser dialog self.dialog.destroy() def on_profile_window_key_press_event(self, widget, event): @@ -161,16 +158,17 @@ class ProfileWindow(Gtk.ApplicationWindow): nick = app.config.get_per('accounts', self.account, 'name') sha = app.contacts.get_avatar_sha(self.account, self.jid) menuitem = Gtk.MenuItem.new_with_mnemonic(_('Save _As')) - menuitem.connect('activate', + menuitem.connect( + 'activate', gtkgui_helpers.on_avatar_save_as_menuitem_activate, sha, nick) menu.append(menuitem) - menu.connect('selection-done', lambda w:w.destroy()) + menu.connect('selection-done', lambda w: w.destroy()) # show the menu menu.show_all() menu.attach_to_widget(widget, None) menu.popup(None, None, None, None, event.button, event.time) - elif event.button == 1: # left click + elif event.button == 1: # left click self.on_set_avatar_button_clicked(widget) def on_BDAY_entry_focus_out_event(self, widget, event): @@ -182,8 +180,10 @@ class ProfileWindow(Gtk.ApplicationWindow): except ValueError: if not widget.is_focus(): pritext = _('Wrong date format') - ErrorDialog(pritext, _('Format of the date must be ' - 'YYYY-MM-DD'), transient_for=self) + ErrorDialog( + pritext, + _('Format of the date must be YYYY-MM-DD'), + transient_for=self) GLib.idle_add(lambda: widget.grab_focus()) return True @@ -201,7 +201,7 @@ class ProfileWindow(Gtk.ApplicationWindow): button = self.xml.get_object('PHOTO_button') image = self.xml.get_object('PHOTO_image') text_button = self.xml.get_object('NOPHOTO_button') - if not 'PHOTO' in vcard_: + if 'PHOTO' not in vcard_: # set default image image.set_from_pixbuf(None) button.hide() @@ -248,10 +248,10 @@ class ProfileWindow(Gtk.ApplicationWindow): if self.update_progressbar_timeout_id is not None: if self.message_id: self.statusbar.remove(self.context_id, self.message_id) - self.message_id = self.statusbar.push(self.context_id, - _('Information received')) - self.remove_statusbar_timeout_id = GLib.timeout_add_seconds(3, - self.remove_statusbar, self.message_id) + self.message_id = self.statusbar.push( + self.context_id, _('Information received')) + self.remove_statusbar_timeout_id = GLib.timeout_add_seconds( + 3, self.remove_statusbar, self.message_id) GLib.source_remove(self.update_progressbar_timeout_id) self.progressbar.hide() self.progressbar.set_fraction(0) @@ -266,10 +266,10 @@ class ProfileWindow(Gtk.ApplicationWindow): """ entries = entry.split('_') loc = vcard_ - if len(entries) == 3: # We need to use lists + if len(entries) == 3: # We need to use lists if entries[0] not in loc: loc[entries[0]] = [] - found = False + for e in loc[entries[0]]: if entries[1] in e: e[entries[2]] = txt @@ -289,13 +289,14 @@ class ProfileWindow(Gtk.ApplicationWindow): """ Make the vCard dictionary """ - entries = ['FN', 'NICKNAME', 'BDAY', 'EMAIL_HOME_USERID', 'JABBERID', 'URL', - 'TEL_HOME_NUMBER', 'N_FAMILY', 'N_GIVEN', 'N_MIDDLE', 'N_PREFIX', - 'N_SUFFIX', 'ADR_HOME_STREET', 'ADR_HOME_EXTADR', 'ADR_HOME_LOCALITY', - 'ADR_HOME_REGION', 'ADR_HOME_PCODE', 'ADR_HOME_CTRY', 'ORG_ORGNAME', - 'ORG_ORGUNIT', 'TITLE', 'ROLE', 'TEL_WORK_NUMBER', 'EMAIL_WORK_USERID', - 'ADR_WORK_STREET', 'ADR_WORK_EXTADR', 'ADR_WORK_LOCALITY', - 'ADR_WORK_REGION', 'ADR_WORK_PCODE', 'ADR_WORK_CTRY'] + entries = [ + 'FN', 'NICKNAME', 'BDAY', 'EMAIL_HOME_USERID', 'JABBERID', 'URL', + 'TEL_HOME_NUMBER', 'N_FAMILY', 'N_GIVEN', 'N_MIDDLE', 'N_PREFIX', + 'N_SUFFIX', 'ADR_HOME_STREET', 'ADR_HOME_EXTADR', 'ADR_HOME_LOCALITY', + 'ADR_HOME_REGION', 'ADR_HOME_PCODE', 'ADR_HOME_CTRY', 'ORG_ORGNAME', + 'ORG_ORGUNIT', 'TITLE', 'ROLE', 'TEL_WORK_NUMBER', 'EMAIL_WORK_USERID', + 'ADR_WORK_STREET', 'ADR_WORK_EXTADR', 'ADR_WORK_LOCALITY', + 'ADR_WORK_REGION', 'ADR_WORK_PCODE', 'ADR_WORK_CTRY'] vcard_ = {} for e in entries: txt = self.xml.get_object(e + '_entry').get_text() @@ -322,9 +323,11 @@ class ProfileWindow(Gtk.ApplicationWindow): # Operation in progress return if app.connections[self.account].connected < 2: - ErrorDialog(_('You are not connected to the server'), - _('Without a connection, you can not publish your contact ' - 'information.'), transient_for=self) + ErrorDialog( + _('You are not connected to the server'), + _('Without a connection, you can not publish your contact ' + 'information.'), + transient_for=self) return vcard_, sha = self.make_vcard() nick = '' @@ -337,11 +340,11 @@ class ProfileWindow(Gtk.ApplicationWindow): app.nicks[self.account] = nick app.connections[self.account].get_module('VCardTemp').send_vcard( vcard_, sha) - self.message_id = self.statusbar.push(self.context_id, - _('Sending profileā€¦')) + self.message_id = self.statusbar.push( + self.context_id, _('Sending profileā€¦')) self.progressbar.show() - self.update_progressbar_timeout_id = GLib.timeout_add(100, - self.update_progressbar) + self.update_progressbar_timeout_id = GLib.timeout_add( + 100, self.update_progressbar) def _nec_vcard_published(self, obj): if obj.conn.name != self.account: @@ -356,17 +359,18 @@ class ProfileWindow(Gtk.ApplicationWindow): return if self.message_id: self.statusbar.remove(self.context_id, self.message_id) - self.message_id = self.statusbar.push(self.context_id, - _('Information NOT published')) - self.remove_statusbar_timeout_id = GLib.timeout_add_seconds(3, - self.remove_statusbar, self.message_id) + self.message_id = self.statusbar.push( + self.context_id, _('Information NOT published')) + self.remove_statusbar_timeout_id = GLib.timeout_add_seconds( + 3, self.remove_statusbar, self.message_id) if self.update_progressbar_timeout_id is not None: GLib.source_remove(self.update_progressbar_timeout_id) self.progressbar.set_fraction(0) self.update_progressbar_timeout_id = None - InformationDialog(_('vCard publication failed'), + InformationDialog( + _('vCard publication failed'), _('There was an error while publishing your personal information, ' - 'try again later.'), transient_for=self) + 'try again later.'), transient_for=self) def on_cancel_button_clicked(self, widget): self.destroy() diff --git a/gajim/gui_interface.py b/gajim/gui_interface.py index a99f2f076..c68ba874f 100644 --- a/gajim/gui_interface.py +++ b/gajim/gui_interface.py @@ -106,7 +106,6 @@ from gajim.common.const import AvatarSize, SSLError, PEPEventType from gajim.common.const import ACTIVITIES, MOODS from gajim import roster_window -from gajim import profile_window from gajim import config from threading import Thread from gajim.common import ged @@ -123,6 +122,7 @@ from gajim.gtk import PlainConnectionDialog from gajim.gtk import SSLErrorDialog from gajim.gtk import ConfirmationDialogDoubleCheck from gajim.gtk import ChangeNickDialog +from gajim.gtk import ProfileWindow from gajim.common import configpaths @@ -284,9 +284,9 @@ class Interface: self.show_vcard_when_connect.remove(account) def edit_own_details(self, account): - window = app.get_app_window(profile_window.ProfileWindow) + window = app.get_app_window(ProfileWindow) if window is None: - profile_window.ProfileWindow(account) + ProfileWindow(account) else: window.present()