Commit 40dd052d authored by Daniel Brötzmann's avatar Daniel Brötzmann Committed by Philipp Hörist

GroupChatControl: Add avatar selector page

parent eb3140bd
Pipeline #6547 passed with stages
in 4 minutes and 52 seconds
......@@ -2216,7 +2216,7 @@
<property name="no_show_all">True</property>
<property name="halign">end</property>
<property name="valign">end</property>
<signal name="clicked" handler="_on_upload_avatar" swapped="no"/>
<signal name="clicked" handler="_on_change_avatar" swapped="no"/>
<child>
<object class="GtkImage">
<property name="visible">True</property>
......@@ -2379,6 +2379,114 @@
<property name="position">15</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkGrid" id="avatar_selector_grid">
<property name="name">settings_grid</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="border_width">18</property>
<property name="row_spacing">6</property>
<property name="column_spacing">12</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="margin_top">6</property>
<property name="spacing">12</property>
<child type="center">
<object class="GtkButton" id="avatar_update_button">
<property name="label" translatable="yes">Update</property>
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="_on_avatar_update_clicked" swapped="no"/>
<style>
<class name="suggested-action"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">_Close</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
<signal name="clicked" handler="_on_page_cancel_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Select File…</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<signal name="clicked" handler="_on_avatar_select_file_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Update Avatar</property>
<style>
<class name="bold16"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="name">avatar-selector</property>
<property name="position">16</property>
</packing>
</child>
</object>
<packing>
<property name="index">-1</property>
......
......@@ -69,6 +69,7 @@
from gajim.gtk.filechoosers import AvatarChooserDialog
from gajim.gtk.groupchat_config import GroupchatConfig
from gajim.gtk.adhoc import AdHocCommand
from gajim.gtk.avatar_selector import AvatarSelector
from gajim.gtk.dataform import DataFormWidget
from gajim.gtk.groupchat_info import GroupChatInfoScrolled
from gajim.gtk.groupchat_invite import GroupChatInvite
......@@ -189,6 +190,11 @@ def __init__(self, parent_win, contact, muc_data, acct):
self.xml.invite_grid.attach(self._invite_box, 0, 0, 1, 1)
self._invite_box.connect('listbox-changed', self._on_invite_ready)
# Avatar selector
self._avatar_selector = AvatarSelector()
self._avatar_selector.set_size_request(400, 400)
self.xml.avatar_selector_grid.attach(self._avatar_selector, 0, 1, 1, 1)
self.control_menu = gui_menu_builder.get_groupchat_menu(self.control_id,
self.account,
self.room_jid)
......@@ -578,22 +584,23 @@ def _on_execute_command(self, _action, param):
jid += '/' + nick
AdHocCommand(self.account, jid)
def _on_upload_avatar(self, _button):
def _on_accept(filename):
data, sha = app.interface.avatar_storage.prepare_for_publish(
filename)
if sha is None:
self.add_info_message(_('Loading avatar failed'))
return
def _on_change_avatar(self, _button):
def _on_accept(path):
self._avatar_selector.prepare_crop_area(path)
self.xml.avatar_update_button.set_sensitive(
self._avatar_selector.get_prepared())
self._show_page('avatar-selector')
self.xml.avatar_update_button.grab_default()
vcard = VCard()
vcard.set_avatar(data, 'image/png')
AvatarChooserDialog(_on_accept,
transient_for=self.parent_win.window,
modal=True)
con = app.connections[self.account]
con.get_module('VCardTemp').set_vcard(
vcard,
jid=self.room_jid,
callback=self._on_upload_avatar_result)
def _on_avatar_select_file_clicked(self, _button):
def _on_accept(path):
self._avatar_selector.prepare_crop_area(path)
self.xml.avatar_update_button.set_sensitive(
self._avatar_selector.get_prepared())
AvatarChooserDialog(_on_accept,
transient_for=self.parent_win.window,
......@@ -608,6 +615,27 @@ def _on_upload_avatar_result(self, task):
else:
self.add_info_message(_('Avatar upload successful'))
def _on_avatar_update_clicked(self, _button):
success, data = self._avatar_selector.get_avatar_bytes()
if not success:
self.add_info_message(_('Loading avatar failed'))
return
sha = app.interface.avatar_storage.save_avatar(data)
if sha is None:
self.add_info_message(_('Loading avatar failed'))
return
vcard = VCard()
vcard.set_avatar(data, 'image/png')
con = app.connections[self.account]
con.get_module('VCardTemp').set_vcard(
vcard,
jid=self.room_jid,
callback=self._on_upload_avatar_result)
self._show_page('groupchat')
def _on_contact_information(self, _action, param):
nick = param.get_string()
gc_contact = app.contacts.get_gc_contact(self.account,
......@@ -739,13 +767,19 @@ def get_tab_image(self):
self.scale_factor)
def _update_avatar(self):
surface = app.interface.avatar_storage.get_muc_surface(
surface_banner = app.interface.avatar_storage.get_muc_surface(
self.account,
self.contact.jid,
AvatarSize.CHAT,
self.scale_factor)
self.xml.avatar_image.set_from_surface(surface_banner)
self.xml.avatar_image.set_from_surface(surface)
surface_manage = app.interface.avatar_storage.get_muc_surface(
self.account,
self.contact.jid,
AvatarSize.GROUP_INFO,
self.scale_factor)
self.xml.avatar_button_image.set_from_surface(surface_manage)
def draw_banner_text(self):
"""
......@@ -755,7 +789,7 @@ def draw_banner_text(self):
self.xml.banner_name_label.set_text(self.room_name)
@event_filter(['jid=room_jid'])
def _on_update_room_avatar(self, event):
def _on_update_room_avatar(self, _event):
self._update_avatar()
@event_filter(['account'])
......
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