Skip to content
Snippets Groups Projects

New plugin: Stickers

Open Alexander requested to merge PapaTutuWawa/gajim-plugins:feat/stickers-plugin into master
7 unresolved threads
Files
12
+ 59
66
@@ -16,39 +16,17 @@
#
from gi.repository import Gtk
from gi.repository import Gio
from gi.repository import GObject
from gajim.common import app
from gajim.common.i18n import _
from gajim.common.helpers import open_file
from gajim.plugins.gui import GajimPluginConfigDialog
from gajim.plugins.helpers import get_builder
from gajim.gui.dialogs import ConfirmationDialog
from gajim.gui.dialogs import DialogButton
class StickerPackObject(GObject.GObject):
def __init__(self, name, summary, amount, id_):
self._name = name
self._summary = summary
self._amount = amount
self._id = id_
GObject.GObject.__init__(self)
@property
def name(self):
return self._name
@property
def summary(self):
return self._summary
@property
def amount(self):
return self._amount
@property
def id_(self):
return self._id
from stickers.utils import sticker_data_path
from stickers.gtk.stickers import StickerStorage
class StickersConfigDialog(GajimPluginConfigDialog):
def init(self):
@@ -59,58 +37,63 @@ class StickersConfigDialog(GajimPluginConfigDialog):
box.pack_start(self._ui.stickers_config_dialog, True, True, 0)
self._ui.connect_signals(self)
self._list_model = Gio.ListStore()
self._ui.get_object('STICKER_WIDTH').set_range(0, 400)
self._ui.get_object('STICKER_WIDTH').set_increments(1, -1)
self._ui.get_object('sticker_packs_list').bind_model(self._list_model, self._create_sticker_pack_row)
self._list_model = StickerStorage().get_model()
self._ui.sticker_width.set_range(0, 400)
self._ui.sticker_width.set_increments(1, -1)
self._ui.sticker_packs_list.bind_model(self._list_model, self._create_sticker_pack_row)
self._ui.reload_sticker_packs.connect('clicked', self.on_sticker_packs_reload_clicked)
self._ui.sticker_packs_location_button.connect('clicked', lambda x: open_file(sticker_data_path()))
def set_wrapper(setting):
return lambda widget: self._on_setting_changed(widget, setting)
for setting in ('DOWNLOAD_NEW', 'DOWNLOAD_NEW_SIGNIN', 'UPLOAD_NEW_SIGNIN', 'SHOW_ANIMATED_STICKERS'):
self._ui.get_object(setting).connect('toggled', set_wrapper(setting))
self._ui.get_object('STICKER_WIDTH').connect('value-changed', set_wrapper('STICKER_WIDTH'))
def on_sticker_pack_added(self, pack):
'''
Called when a new sticker pack has been added.
'''
self._list_model.append(StickerPackObject(pack.name,
pack.summary,
len(pack.stickers),
pack.id_))
def on_sticker_pack_removed(self, pack):
'''
Called when a sticker pack has been removed.
'''
# Find the correct index in the ListStore
index = -1
for index_ in range(self._list_model.get_n_items()):
if self._list_model.get_item(index_).id_ == pack.id_:
index = index_
break
if index != -1:
self._list_model.remove(index)
for setting in ('download_new', 'download_new_signin', 'upload_new_signin', 'show_animated_stickers'):
getattr(self._ui, setting).set_active(self.plugin.config[setting.upper()])
getattr(self._ui, setting).connect('toggled', set_wrapper(setting.upper()))
self._ui.sticker_width.connect('value-changed', set_wrapper('STICKER_WIDTH'))
self._ui.sticker_privacy.set_active_id(self.plugin.config['STICKER_ACCESS_MODEL'])
self._ui.sticker_privacy.connect('changed', self.on_sticker_privacy_changed)
def on_sticker_privacy_changed(self, combobox):
self._on_setting_changed(combobox, 'STICKER_ACCESS_MODEL')
access_model = combobox.get_active_id()
for account in app.connections:
app.connections[account].get_module('Stickers').set_sticker_access_model(access_model)
def on_sticker_packs_reload_clicked(self, button):
# pylint: disable=unused-argument
def reload_sticker_packs():
self.plugin.reload_sticker_packs()
ConfirmationDialog(
_('Reload Sticker Packs'),
_('Are you sure you want to reload all sticker packs?'),
_('Depending on the amount of installed sticker packs this might take some time.'),
[DialogButton.make('Cancel'),
DialogButton.make('Accept',
callback=reload_sticker_packs)]).show()
def on_run(self):
# Update all config settings
for setting in ('DOWNLOAD_NEW', 'DOWNLOAD_NEW_SIGNIN', 'UPLOAD_NEW_SIGNIN', 'SHOW_ANIMATED_STICKERS'):
self._ui.get_object(setting).set_active(self.plugin.config[setting])
self._ui.get_object('STICKER_WIDTH').set_value(self.plugin.config['STICKER_WIDTH'])
for setting in ('download_new', 'download_new_signin', 'upload_new_signin', 'show_animated_stickers'):
getattr(self._ui, setting).set_active(self.plugin.config[setting.upper()])
self._ui.sticker_width.set_value(self.plugin.config['STICKER_WIDTH'])
def _on_setting_changed(self, widget, data):
if isinstance(widget, Gtk.CheckButton):
value = widget.get_active()
elif isinstance(widget, Gtk.SpinButton):
value = int(widget.get_value())
elif isinstance(widget, Gtk.ComboBoxText):
value = widget.get_active_id()
self.plugin.config[data] = value
def _on_delete_button_clicked(self, id_):
def delete_sticker_pack():
self.plugin.delete_sticker_pack(id_)
self.plugin.retract_sticker_pack(id_)
ConfirmationDialog(
_('Delete Sticker Pack'),
@@ -120,11 +103,21 @@ class StickersConfigDialog(GajimPluginConfigDialog):
DialogButton.make('Remove',
callback=delete_sticker_pack)]).show()
def _on_upload_button_clicked(self, id_):
self.plugin.upload_sticker_pack(id_)
def _create_sticker_pack_row(self, pack):
item = get_builder(self.plugin.local_file_path('gtk/config_stickers_listitem.ui'))
item.get_object('header').set_markup(_('<b>%s</b>') % pack.name)
item.get_object('summary').set_text(pack.summary)
item.get_object('amount').set_text(_('%s stickers') % pack.amount)
item.get_object('delete_button').connect('clicked', lambda x: self._on_delete_button_clicked(pack.id_))
return item.get_object('sticker_pack_list_item')
# TODO: If available, display the localized version of the sticker pack's
# name and summary
item.header.set_markup(f'<b>{pack.name}</b>')
item.summary.set_text(pack.summary)
item.amount.set_text(_('%s stickers') % pack.amount)
item.delete_button.connect('clicked', lambda x: self._on_delete_button_clicked(pack.id_))
if pack.uploaded:
item.upload_button.destroy()
else:
item.upload_button.connect('clicked', lambda x: self._on_upload_button_clicked(pack.id_))
return item.sticker_pack_list_item
Loading