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
11
+ 24
52
@@ -16,39 +16,16 @@
#
from gi.repository import Gtk
from gi.repository import Gio
from gi.repository import GObject
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,12 +36,13 @@ 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._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)
@@ -75,30 +53,16 @@ class StickersConfigDialog(GajimPluginConfigDialog):
self._ui.sticker_width.connect('value-changed', set_wrapper('STICKER_WIDTH'))
def on_sticker_packs_reload_clicked(self, button):
self.plugin.reload_sticker_packs()
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)
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
@@ -116,7 +80,7 @@ class StickersConfigDialog(GajimPluginConfigDialog):
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'),
@@ -126,6 +90,9 @@ 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'))
# TODO: If available, display the localized version of the sticker pack's
@@ -135,4 +102,9 @@ class StickersConfigDialog(GajimPluginConfigDialog):
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