Commit 9187c720 authored by Daniel Brötzmann's avatar Daniel Brötzmann

Profile: Add avatar and nickname

parent 822c2034
Pipeline #6744 failed with stages
in 3 minutes and 20 seconds
This diff is collapsed.
......@@ -35,6 +35,15 @@
/* VCardWindow */
.VCard-GtkLinkButton { padding-left: 5px; border-left: none; }
#NicknameEntry:disabled {
font-size: 28px;
font-weight: bold;
border: none;
padding: 0px 0px 0px 0px;
background-color: @theme_unfocused_bg_color;
color: @theme_fg_color;
}
#ProfileWindow grid { padding: 18px; }
#ProfileWindow grid > button {
padding-left: 4px;
......
......@@ -3,14 +3,21 @@
from gi.repository import Gio
from gi.repository import Gdk
from gi.repository import Gtk
from gi.repository import GLib
from nbxmpp.errors import StanzaError
# from nbxmpp.modules.vcard_temp import VCard
from nbxmpp.modules.vcard4 import VCard
from gajim.common import app
from gajim.common.const import AvatarSize
from gajim.common.i18n import _
from gajim.common.i18n import Q_
from gajim.gtk.avatar import clip_circle
from gajim.gtk.avatar_selector import AvatarSelector
from gajim.gtk.filechoosers import AvatarChooserDialog
from gajim.gtk.util import get_builder
from gajim.gtk.vcard_grid import VCardGrid
log = logging.getLogger('gajim.gtk.profile')
......@@ -38,21 +45,14 @@ def __init__(self, account, *args):
self.set_show_menubar(False)
self.set_resizable(True)
self.set_default_size(600, 600)
self.set_default_size(700, 600)
self.set_name('ProfileWindow')
self.set_title(_('Profile'))
self.account = account
self._jid = app.get_jid_from_account(account)
self._stack = Gtk.Stack()
self._stack.get_style_context().add_class('padding-18')
self._spinner = Gtk.Spinner()
self._spinner.start()
self._stack.add_named(self._spinner, 'spinner')
self._edit_button = Gtk.Button.new_with_mnemonic(label=_('_Edit'))
self._edit_button.get_style_context().add_class('suggested-action')
self._edit_button.connect('clicked', self._on_edit_clicked)
self._ui = get_builder('profile_new.ui')
# 'Add entry' menu for edit mode
menu = Gio.Menu()
......@@ -61,72 +61,62 @@ def __init__(self, account, *args):
continue
menu.append(label, 'win.add-' + action.lower())
self._add_entry_button = Gtk.MenuButton()
menubox = Gtk.Box(spacing=6)
menubox.add(Gtk.Label(label=_('Add Entry')))
menubox.add(Gtk.Image.new_from_icon_name(
'list-add-symbolic', Gtk.IconSize.MENU))
self._add_entry_button.add(menubox)
self._add_entry_button.set_menu_model(menu)
self._add_entry_button.set_no_show_all(True)
self._ui.add_entry_button.set_menu_model(menu)
self._add_actions()
self._cancel_button = Gtk.Button.new_with_mnemonic(label=_('_Cancel'))
self._cancel_button.connect('clicked', self._on_cancel_clicked)
self._cancel_button.set_no_show_all(True)
self._save_button = Gtk.Button.new_with_mnemonic(label=_('_Save'))
self._save_button.get_style_context().add_class('suggested-action')
self._save_button.connect('clicked', self._on_save_clicked)
self._save_button.set_no_show_all(True)
self._avatar_selector = None
self._current_avatar = None
# Actionbar for edit mode
actionbar = Gtk.ActionBar()
actionbar.pack_end(self._edit_button)
actionbar.set_center_widget(self._add_entry_button)
actionbar.pack_end(self._save_button)
actionbar.pack_end(self._cancel_button)
self._ui.nickname_entry.set_text(app.nicks[account])
profile_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
scrolled = Gtk.ScrolledWindow()
self._profile = VCardGrid(self.account)
scrolled.add(self._profile)
profile_box.pack_start(scrolled, True, True, 0)
profile_box.pack_end(actionbar, False, False, 0)
self._stack.add_named(profile_box, 'profile')
self._ui.profile_box.add(self._profile)
self.add(self._stack)
self.add(self._ui.profile_stack)
self.show_all()
client = app.get_client(account)
client._client.get_module('VCard4').request_vcard(
callback=self._on_vcard_received)
self._load_avatar()
# TODO: get access data
avatar_nick_access = True
vcard_access = True
self._ui.avatar_nick_access.set_active(avatar_nick_access)
self._ui.vcard_access.set_active(vcard_access)
self._ui.connect_signals(self)
self.connect('key-press-event', self._on_key_press_event)
def _on_vcard_received(self, task):
try:
vcard = task.finish()
except StanzaError as error:
# TODO Handle error
return
log.info('Error loading VCard: %s', error)
vcard = VCard()
self._load_avatar()
self._profile.set_vcard(vcard)
self._stack.set_visible_child_name('profile')
self._spinner.stop()
self._ui.profile_stack.set_visible_child_name('profile')
self._ui.spinner.stop()
def _load_avatar(self):
scale = self.get_scale_factor()
self._current_avatar = app.contacts.get_avatar(
self.account,
self._jid,
AvatarSize.VCARD,
scale)
self._ui.avatar_image.set_from_surface(self._current_avatar)
self._ui.avatar_image.show()
def _on_key_press_event(self, _widget, event):
if event.keyval == Gdk.KEY_Escape:
self.destroy()
def _on_edit_clicked(self, *args):
self._profile.set_editable(True)
self._edit_button.hide()
self._add_entry_button.set_no_show_all(False)
self._add_entry_button.show_all()
self._cancel_button.show()
self._save_button.show()
def _add_actions(self):
for action in MENU_DICT:
if action in ('PHOTO', 'NICKNAME'):
......@@ -141,40 +131,122 @@ def _on_action(self, action, _param):
key = name.split('-')[1]
self._profile.add_new_property(key)
def _on_edit_clicked(self, *args):
self._profile.set_editable(True)
self._ui.edit_button.hide()
self._ui.add_entry_button.set_no_show_all(False)
self._ui.add_entry_button.show_all()
self._ui.cancel_button.show()
self._ui.save_button.show()
self._ui.remove_avatar_button.show()
self._ui.edit_avatar_button.show()
self._ui.nickname_entry.set_sensitive(True)
self._ui.privacy_button.show()
def _on_cancel_clicked(self, _widget):
self._profile.set_editable(False)
self._edit_button.show()
self._add_entry_button.hide()
self._cancel_button.hide()
self._save_button.hide()
self._ui.edit_button.show()
self._ui.add_entry_button.hide()
self._ui.cancel_button.hide()
self._ui.save_button.hide()
self._ui.remove_avatar_button.hide()
self._ui.edit_avatar_button.hide()
self._ui.privacy_button.hide()
self._ui.nickname_entry.set_sensitive(False)
self._ui.avatar_image.set_from_surface(self._current_avatar)
self._ui.nickname_entry.set_text(app.nicks[self.account])
def _on_save_clicked(self, _widget):
self._spinner.start()
self._stack.set_visible_child_name('spinner')
self._add_entry_button.hide()
self._cancel_button.hide()
self._save_button.hide()
self._edit_button.show()
self._ui.spinner.start()
self._ui.profile_stack.set_visible_child_name('spinner')
self._ui.add_entry_button.hide()
self._ui.cancel_button.hide()
self._ui.save_button.hide()
self._ui.edit_button.show()
self._ui.remove_avatar_button.hide()
self._ui.edit_avatar_button.hide()
self._ui.privacy_button.hide()
self._ui.nickname_entry.set_sensitive(False)
# iq = self._profile.get_vcard_data()
# public = self._ui.vcard_access.get_active()
con = app.connections[self.account]
con._client.get_module('VCard4').set_vcard(self._profile.get_vcard(),
callback=self._on_save_finished)
con._client.get_module('VCard4').set_vcard(
self._profile.get_vcard(),
callback=self._on_save_finished)
# TODO: update avatar
# public = self._ui.avatar_nick_access.get_active()
nick = GLib.markup_escape_text(self._ui.nickname_entry.get_text())
con.get_module('UserNickname').set_nickname(nick)
if not nick:
nick = app.settings.get_account_setting(
self.account, 'name')
app.nicks[self.account] = nick
def _on_remove_avatar(self, _button):
app.contacts.set_avatar(self.account, self._jid, None)
pixbuf = Gtk.IconTheme.load_icon_for_scale(
Gtk.IconTheme.get_default(),
'avatar-default-symbolic',
AvatarSize.VCARD,
self.get_scale_factor(),
0)
self._ui.avatar_image.set_from_pixbuf(pixbuf)
self._ui.remove_avatar_button.hide()
def _on_edit_avatar(self, button):
def _on_file_selected(path):
if self._avatar_selector is None:
self._avatar_selector = AvatarSelector()
self._ui.avatar_selector_box.add(self._avatar_selector)
self._avatar_selector.prepare_crop_area(path)
self._ui.avatar_update_button.set_sensitive(
self._avatar_selector.get_prepared())
self._ui.profile_stack.set_visible_child_name('avatar_selector')
AvatarChooserDialog(_on_file_selected,
transient_for=button.get_toplevel())
def _on_cancel_update_avatar(self, _button):
self._ui.profile_stack.set_visible_child_name('profile')
def _on_update_avatar(self, _button):
success, data = self._avatar_selector.get_avatar_bytes()
if not success:
# TODO: Error handling
return
sha = app.interface.avatar_storage.save_avatar(data)
if sha is None:
# TODO: Error handling
return
scale = self.get_scale_factor()
surface = app.interface.avatar_storage.surface_from_filename(
sha, AvatarSize.VCARD, scale)
# nick = self._profile.get_nickname()
# con.get_module('UserNickname').set_nickname(nick)
# if not nick:
# nick = app.settings.get_account_setting(
# self.account, 'name')
# app.nicks[self.account] = nick
self._ui.avatar_image.set_from_surface(clip_circle(surface))
self._ui.remove_avatar_button.show()
self._ui.profile_stack.set_visible_child_name('profile')
def _access_switch_toggled(self, *args):
avatar_nick_access = self._ui.avatar_nick_access.get_active()
vcard_access = self._ui.vcard_access.get_active()
self._ui.avatar_nick_access_label.set_text(
_('Everyone') if avatar_nick_access else _('Contacts'))
self._ui.vcard_access_label.set_text(
_('Everyone') if vcard_access else _('Contacts'))
def _on_save_finished(self, task):
try:
task.finish()
except StanzaError as error:
except StanzaError as err:
log.error('Could not publish VCard: %s', err)
# TODO Handle error
return
self._profile.set_editable(False)
self._stack.set_visible_child_name('profile')
self._spinner.stop()
self._ui.profile_stack.set_visible_child_name('profile')
self._ui.spinner.stop()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment