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
7
+ 123
0
#
# Copyright (C) 2020 Alexander "PapaTutuWawa" <papatutuwawa AT polynom.me>
# This file is part of the Stickers plugin for Gajim.
#
# Gajim is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
# by the Free Software Foundation; version 3 only.
#
# Gajim is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
#
from gi.repository import Gtk
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
from stickers.utils import sticker_data_path
from stickers.gtk.stickers import StickerStorage
class StickersConfigDialog(GajimPluginConfigDialog):
def init(self):
path = self.plugin.local_file_path('gtk/config.ui')
self._ui = get_builder(path)
box = self.get_content_area()
box.pack_start(self._ui.stickers_config_dialog, True, True, 0)
self._ui.connect_signals(self)
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'):
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'):
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.retract_sticker_pack(id_)
ConfirmationDialog(
_('Delete Sticker Pack'),
_('Are you sure you want to delete the sticker pack?'),
_('This will delete the sticker pack and its files from your computer.'),
[DialogButton.make('Cancel'),
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
# 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