Commit e6377889 authored by Daniel Brötzmann's avatar Daniel Brötzmann Committed by Daniel Brötzmann
Browse files

GroupChatControl: Add avatar selector page

parent 6729a122
Pipeline #7759 passed with stages
in 7 minutes and 25 seconds
...@@ -2216,7 +2216,7 @@ ...@@ -2216,7 +2216,7 @@
<property name="no_show_all">True</property> <property name="no_show_all">True</property>
<property name="halign">end</property> <property name="halign">end</property>
<property name="valign">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> <child>
<object class="GtkImage"> <object class="GtkImage">
<property name="visible">True</property> <property name="visible">True</property>
...@@ -2379,6 +2379,114 @@ ...@@ -2379,6 +2379,114 @@
<property name="position">15</property> <property name="position">15</property>
</packing> </packing>
</child> </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> </object>
<packing> <packing>
<property name="index">-1</property> <property name="index">-1</property>
......
...@@ -69,6 +69,7 @@ ...@@ -69,6 +69,7 @@
from gajim.gui.filechoosers import AvatarChooserDialog from gajim.gui.filechoosers import AvatarChooserDialog
from gajim.gui.groupchat_config import GroupchatConfig from gajim.gui.groupchat_config import GroupchatConfig
from gajim.gui.adhoc import AdHocCommand from gajim.gui.adhoc import AdHocCommand
from gajim.gui.avatar_selector import AvatarSelector
from gajim.gui.dataform import DataFormWidget from gajim.gui.dataform import DataFormWidget
from gajim.gui.groupchat_info import GroupChatInfoScrolled from gajim.gui.groupchat_info import GroupChatInfoScrolled
from gajim.gui.groupchat_invite import GroupChatInvite from gajim.gui.groupchat_invite import GroupChatInvite
...@@ -187,6 +188,11 @@ def __init__(self, parent_win, contact, muc_data, acct): ...@@ -187,6 +188,11 @@ def __init__(self, parent_win, contact, muc_data, acct):
self.xml.invite_grid.attach(self._invite_box, 0, 0, 1, 1) self.xml.invite_grid.attach(self._invite_box, 0, 0, 1, 1)
self._invite_box.connect('listbox-changed', self._on_invite_ready) 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.control_menu = gui_menu_builder.get_groupchat_menu(self.control_id,
self.account, self.account,
self.room_jid) self.room_jid)
...@@ -579,22 +585,23 @@ def _on_execute_command(self, _action, param): ...@@ -579,22 +585,23 @@ def _on_execute_command(self, _action, param):
jid += '/' + nick jid += '/' + nick
AdHocCommand(self.account, jid) AdHocCommand(self.account, jid)
def _on_upload_avatar(self, _button): def _on_change_avatar(self, _button):
def _on_accept(filename): def _on_accept(path):
data, sha = app.interface.avatar_storage.prepare_for_publish( self._avatar_selector.prepare_crop_area(path)
filename) self.xml.avatar_update_button.set_sensitive(
if sha is None: self._avatar_selector.get_prepared())
self.add_info_message(_('Loading avatar failed')) self._show_page('avatar-selector')
return self.xml.avatar_update_button.grab_default()
vcard = VCard() AvatarChooserDialog(_on_accept,
vcard.set_avatar(data, 'image/png') transient_for=self.parent_win.window,
modal=True)
con = app.connections[self.account] def _on_avatar_select_file_clicked(self, _button):
con.get_module('VCardTemp').set_vcard( def _on_accept(path):
vcard, self._avatar_selector.prepare_crop_area(path)
jid=self.room_jid, self.xml.avatar_update_button.set_sensitive(
callback=self._on_upload_avatar_result) self._avatar_selector.get_prepared())
AvatarChooserDialog(_on_accept, AvatarChooserDialog(_on_accept,
transient_for=self.parent_win.window, transient_for=self.parent_win.window,
...@@ -609,6 +616,27 @@ def _on_upload_avatar_result(self, task): ...@@ -609,6 +616,27 @@ def _on_upload_avatar_result(self, task):
else: else:
self.add_info_message(_('Avatar upload successful')) 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')
client = app.get_client(self.account)
client.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): def _on_contact_information(self, _action, param):
nick = param.get_string() nick = param.get_string()
gc_contact = app.contacts.get_gc_contact(self.account, gc_contact = app.contacts.get_gc_contact(self.account,
...@@ -751,13 +779,19 @@ def get_tab_image(self): ...@@ -751,13 +779,19 @@ def get_tab_image(self):
self.scale_factor) self.scale_factor)
def _update_avatar(self): def _update_avatar(self):
surface = app.interface.avatar_storage.get_muc_surface( surface_banner = app.interface.avatar_storage.get_muc_surface(
self.account, self.account,
self.contact.jid, self.contact.jid,
AvatarSize.CHAT, AvatarSize.CHAT,
self.scale_factor) 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): def draw_banner_text(self):
""" """
...@@ -767,7 +801,7 @@ def draw_banner_text(self): ...@@ -767,7 +801,7 @@ def draw_banner_text(self):
self.xml.banner_name_label.set_text(self.room_name) self.xml.banner_name_label.set_text(self.room_name)
@event_filter(['jid=room_jid']) @event_filter(['jid=room_jid'])
def _on_update_room_avatar(self, event): def _on_update_room_avatar(self, _event):
self._update_avatar() self._update_avatar()
@event_filter(['account']) @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