| ... |
... |
@@ -20,43 +20,46 @@ |
|
20
|
20
|
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
|
21
|
21
|
##
|
|
22
|
22
|
|
|
23
|
|
-# THIS FILE IS FOR **OUR** PROFILE (when we edit our INFO)
|
|
24
|
|
-
|
|
25
|
|
-from gi.repository import Gtk
|
|
26
|
|
-from gi.repository import Gdk
|
|
27
|
|
-from gi.repository import GLib
|
|
28
|
|
-from gi.repository import GdkPixbuf
|
|
29
|
23
|
import base64
|
|
30
|
24
|
import time
|
|
31
|
25
|
import logging
|
|
32
|
26
|
import hashlib
|
|
33
|
27
|
|
|
|
28
|
+from gi.repository import Gtk
|
|
|
29
|
+from gi.repository import Gdk
|
|
|
30
|
+from gi.repository import GLib
|
|
|
31
|
+
|
|
34
|
32
|
from gajim import gtkgui_helpers
|
|
35
|
33
|
from gajim import dialogs
|
|
36
|
34
|
from gajim.filechoosers import AvatarChooserDialog
|
|
37
|
35
|
from gajim.common.const import AvatarSize
|
|
38
|
|
-
|
|
39
|
36
|
from gajim.common import app
|
|
40
|
37
|
from gajim.common import ged
|
|
41
|
38
|
|
|
42
|
39
|
log = logging.getLogger('gajim.profile')
|
|
43
|
40
|
|
|
44
|
|
-class ProfileWindow:
|
|
45
|
|
- """
|
|
46
|
|
- Class for our information window
|
|
47
|
|
- """
|
|
48
|
41
|
|
|
49
|
|
- def __init__(self, account, transient_for=None):
|
|
|
42
|
+class ProfileWindow(Gtk.ApplicationWindow):
|
|
|
43
|
+ def __init__(self, account):
|
|
|
44
|
+ Gtk.ApplicationWindow.__init__(self)
|
|
|
45
|
+ self.set_application(app.app)
|
|
|
46
|
+ self.set_position(Gtk.WindowPosition.CENTER)
|
|
|
47
|
+ self.set_show_menubar(False)
|
|
|
48
|
+ self.set_title(_('Profile'))
|
|
|
49
|
+
|
|
|
50
|
+ self.connect('destroy', self.on_profile_window_destroy)
|
|
|
51
|
+ self.connect('key-press-event', self.on_profile_window_key_press_event)
|
|
|
52
|
+
|
|
50
|
53
|
self.xml = gtkgui_helpers.get_gtk_builder('profile_window.ui')
|
|
51
|
|
- self.window = self.xml.get_object('profile_window')
|
|
52
|
|
- self.window.set_transient_for(transient_for)
|
|
|
54
|
+ self.add(self.xml.get_object('profile_box'))
|
|
53
|
55
|
self.progressbar = self.xml.get_object('progressbar')
|
|
54
|
56
|
self.statusbar = self.xml.get_object('statusbar')
|
|
55
|
57
|
self.context_id = self.statusbar.get_context_id('profile')
|
|
56
|
58
|
|
|
57
|
59
|
self.account = account
|
|
58
|
60
|
self.jid = app.get_jid_from_account(account)
|
|
59
|
|
- account_label = app.config.get_per('accounts', account, 'account_label')
|
|
|
61
|
+ account_label = app.config.get_per(
|
|
|
62
|
+ 'accounts', account, 'account_label')
|
|
60
|
63
|
self.set_value('account_label', account_label)
|
|
61
|
64
|
|
|
62
|
65
|
self.dialog = None
|
| ... |
... |
@@ -64,17 +67,18 @@ class ProfileWindow: |
|
64
|
67
|
self.avatar_encoded = None
|
|
65
|
68
|
self.avatar_sha = None
|
|
66
|
69
|
self.message_id = self.statusbar.push(self.context_id,
|
|
67
|
|
- _('Retrieving profile…'))
|
|
68
|
|
- self.update_progressbar_timeout_id = GLib.timeout_add(100,
|
|
69
|
|
- self.update_progressbar)
|
|
|
70
|
+ _('Retrieving profile…'))
|
|
|
71
|
+ self.update_progressbar_timeout_id = GLib.timeout_add(
|
|
|
72
|
+ 100, self.update_progressbar)
|
|
70
|
73
|
self.remove_statusbar_timeout_id = None
|
|
71
|
74
|
|
|
72
|
75
|
self.xml.connect_signals(self)
|
|
73
|
76
|
app.ged.register_event_handler('vcard-published', ged.GUI1,
|
|
74
|
|
- self._nec_vcard_published)
|
|
|
77
|
+ self._nec_vcard_published)
|
|
75
|
78
|
app.ged.register_event_handler('vcard-not-published', ged.GUI1,
|
|
76
|
|
- self._nec_vcard_not_published)
|
|
77
|
|
- self.window.show_all()
|
|
|
79
|
+ self._nec_vcard_not_published)
|
|
|
80
|
+
|
|
|
81
|
+ self.show_all()
|
|
78
|
82
|
self.xml.get_object('ok_button').grab_focus()
|
|
79
|
83
|
app.connections[account].get_module('VCardTemp').request_vcard(
|
|
80
|
84
|
self._nec_vcard_received, self.jid)
|
| ... |
... |
@@ -99,13 +103,13 @@ class ProfileWindow: |
|
99
|
103
|
self._nec_vcard_published)
|
|
100
|
104
|
app.ged.remove_event_handler('vcard-not-published', ged.GUI1,
|
|
101
|
105
|
self._nec_vcard_not_published)
|
|
102
|
|
- del app.interface.instances[self.account]['profile']
|
|
|
106
|
+
|
|
103
|
107
|
if self.dialog: # Image chooser dialog
|
|
104
|
108
|
self.dialog.destroy()
|
|
105
|
109
|
|
|
106
|
110
|
def on_profile_window_key_press_event(self, widget, event):
|
|
107
|
111
|
if event.keyval == Gdk.KEY_Escape:
|
|
108
|
|
- self.window.destroy()
|
|
|
112
|
+ self.destroy()
|
|
109
|
113
|
|
|
110
|
114
|
def _clear_photo(self, widget):
|
|
111
|
115
|
# empty the image
|
| ... |
... |
@@ -124,10 +128,10 @@ class ProfileWindow: |
|
124
|
128
|
sha = app.interface.save_avatar(path_to_file, publish=True)
|
|
125
|
129
|
if sha is None:
|
|
126
|
130
|
dialogs.ErrorDialog(
|
|
127
|
|
- _('Could not load image'), transient_for=self.window)
|
|
|
131
|
+ _('Could not load image'), transient_for=self)
|
|
128
|
132
|
return
|
|
129
|
133
|
|
|
130
|
|
- scale = self.window.get_scale_factor()
|
|
|
134
|
+ scale = self.get_scale_factor()
|
|
131
|
135
|
surface = app.interface.get_avatar(sha, AvatarSize.VCARD, scale)
|
|
132
|
136
|
|
|
133
|
137
|
button = self.xml.get_object('PHOTO_button')
|
| ... |
... |
@@ -142,7 +146,7 @@ class ProfileWindow: |
|
142
|
146
|
self.avatar_encoded = base64.b64encode(publish).decode('utf-8')
|
|
143
|
147
|
self.avatar_mime_type = 'image/png'
|
|
144
|
148
|
|
|
145
|
|
- AvatarChooserDialog(on_ok, transient_for=self.window)
|
|
|
149
|
+ AvatarChooserDialog(on_ok, transient_for=self)
|
|
146
|
150
|
|
|
147
|
151
|
def on_PHOTO_button_press_event(self, widget, event):
|
|
148
|
152
|
"""
|
| ... |
... |
@@ -178,7 +182,7 @@ class ProfileWindow: |
|
178
|
182
|
if not widget.is_focus():
|
|
179
|
183
|
pritext = _('Wrong date format')
|
|
180
|
184
|
dialogs.ErrorDialog(pritext, _('Format of the date must be '
|
|
181
|
|
- 'YYYY-MM-DD'), transient_for=self.window)
|
|
|
185
|
+ 'YYYY-MM-DD'), transient_for=self)
|
|
182
|
186
|
GLib.idle_add(lambda: widget.grab_focus())
|
|
183
|
187
|
return True
|
|
184
|
188
|
|
| ... |
... |
@@ -212,7 +216,7 @@ class ProfileWindow: |
|
212
|
216
|
if 'TYPE' in vcard_[i]:
|
|
213
|
217
|
self.avatar_mime_type = vcard_[i]['TYPE']
|
|
214
|
218
|
|
|
215
|
|
- scale = self.window.get_scale_factor()
|
|
|
219
|
+ scale = self.get_scale_factor()
|
|
216
|
220
|
surface = app.interface.get_avatar(
|
|
217
|
221
|
self.avatar_sha, AvatarSize.VCARD, scale)
|
|
218
|
222
|
if surface is None:
|
| ... |
... |
@@ -319,7 +323,7 @@ class ProfileWindow: |
|
319
|
323
|
if app.connections[self.account].connected < 2:
|
|
320
|
324
|
dialogs.ErrorDialog(_('You are not connected to the server'),
|
|
321
|
325
|
_('Without a connection, you can not publish your contact '
|
|
322
|
|
- 'information.'), transient_for=self.window)
|
|
|
326
|
+ 'information.'), transient_for=self)
|
|
323
|
327
|
return
|
|
324
|
328
|
vcard_, sha = self.make_vcard()
|
|
325
|
329
|
nick = ''
|
| ... |
... |
@@ -344,7 +348,7 @@ class ProfileWindow: |
|
344
|
348
|
if self.update_progressbar_timeout_id is not None:
|
|
345
|
349
|
GLib.source_remove(self.update_progressbar_timeout_id)
|
|
346
|
350
|
self.update_progressbar_timeout_id = None
|
|
347
|
|
- self.window.destroy()
|
|
|
351
|
+ self.destroy()
|
|
348
|
352
|
|
|
349
|
353
|
def _nec_vcard_not_published(self, obj):
|
|
350
|
354
|
if obj.conn.name != self.account:
|
| ... |
... |
@@ -361,7 +365,7 @@ class ProfileWindow: |
|
361
|
365
|
self.update_progressbar_timeout_id = None
|
|
362
|
366
|
dialogs.InformationDialog(_('vCard publication failed'),
|
|
363
|
367
|
_('There was an error while publishing your personal information, '
|
|
364
|
|
- 'try again later.'), transient_for=self.window)
|
|
|
368
|
+ 'try again later.'), transient_for=self)
|
|
365
|
369
|
|
|
366
|
370
|
def on_cancel_button_clicked(self, widget):
|
|
367
|
|
- self.window.destroy()
|
|
|
371
|
+ self.destroy()
|