Move ProfileWindow into gtk module

This commit is contained in:
Philipp Hörist 2018-07-22 16:53:02 +02:00
parent 8c299c0b77
commit 78e4e20d49
3 changed files with 68 additions and 63 deletions

View File

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

View File

@ -1,24 +1,20 @@
# -*- coding:utf-8 -*-
## src/profile_window.py
##
## Copyright (C) 2003-2014 Yann Leboulanger <asterix AT lagaule.org>
## Copyright (C) 2005-2006 Nikos Kouremenos <kourem AT gmail.com>
## Copyright (C) 2006-2008 Jean-Marie Traissard <jim AT lapin.org>
##
## 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/>.
##
# Copyright (C) 2003-2014 Yann Leboulanger <asterix AT lagaule.org>
# Copyright (C) 2005-2006 Nikos Kouremenos <kourem AT gmail.com>
# Copyright (C) 2006-2008 Jean-Marie Traissard <jim AT lapin.org>
#
# 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/>.
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,10 +97,10 @@ 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
self.dialog.destroy()
@ -161,7 +158,8 @@ 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)
@ -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)
@ -269,7 +269,7 @@ class ProfileWindow(Gtk.ApplicationWindow):
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,7 +289,8 @@ class ProfileWindow(Gtk.ApplicationWindow):
"""
Make the vCard dictionary
"""
entries = ['FN', 'NICKNAME', 'BDAY', 'EMAIL_HOME_USERID', 'JABBERID', 'URL',
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',
@ -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'),
ErrorDialog(
_('You are not connected to the server'),
_('Without a connection, you can not publish your contact '
'information.'), transient_for=self)
'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,15 +359,16 @@ 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)

View File

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