2022-08-23 17:57:53 +00:00
|
|
|
# plugin_row.py
|
|
|
|
#
|
|
|
|
# Change the look of Adwaita, with ease
|
|
|
|
# Copyright (C) 2022 Gradience Team
|
|
|
|
#
|
|
|
|
# This program 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, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
2022-08-19 12:23:25 +00:00
|
|
|
|
2022-09-07 16:00:33 +00:00
|
|
|
from gi.repository import Gtk, Adw
|
2022-08-19 12:23:25 +00:00
|
|
|
|
2022-08-23 17:38:09 +00:00
|
|
|
from .modules.utils import buglog
|
2022-08-19 12:23:25 +00:00
|
|
|
from .constants import rootdir
|
2022-09-10 13:39:54 +00:00
|
|
|
from pathlib import Path
|
|
|
|
import os
|
|
|
|
|
|
|
|
USER_PLUGIN_DIR = Path(
|
|
|
|
os.path.join(
|
|
|
|
os.environ.get("XDG_DATA_HOME", os.environ["HOME"] + "/.local/share"),
|
|
|
|
"gradience",
|
|
|
|
"plugins",
|
|
|
|
)
|
|
|
|
)
|
2022-08-19 12:23:25 +00:00
|
|
|
|
2022-09-04 09:44:19 +00:00
|
|
|
|
2022-08-19 12:23:25 +00:00
|
|
|
@Gtk.Template(resource_path=f"{rootdir}/ui/plugin_row.ui")
|
2022-08-19 12:44:02 +00:00
|
|
|
class GradiencePluginRow(Adw.ActionRow):
|
|
|
|
__gtype_name__ = "GradiencePluginRow"
|
2022-08-19 12:23:25 +00:00
|
|
|
|
2022-09-10 13:19:16 +00:00
|
|
|
switch = Gtk.Template.Child("switch")
|
|
|
|
settings_button = Gtk.Template.Child("settings-button")
|
|
|
|
remove_button = Gtk.Template.Child("remove-button")
|
2022-09-10 13:19:47 +00:00
|
|
|
|
2022-09-10 13:19:16 +00:00
|
|
|
def __init__(self, plugin_object, preset, plugins_list, **kwargs):
|
2022-08-19 12:23:25 +00:00
|
|
|
super().__init__(**kwargs)
|
2022-09-10 13:19:47 +00:00
|
|
|
|
2022-09-10 13:19:16 +00:00
|
|
|
self.plugins_list = plugins_list
|
2022-08-19 12:23:25 +00:00
|
|
|
|
2022-09-04 09:08:32 +00:00
|
|
|
self.plugin_object = plugin_object
|
2022-09-23 11:14:21 +00:00
|
|
|
if not os.path.exists(
|
|
|
|
USER_PLUGIN_DIR / f"{self.plugin_object.plugin_id}.yapsy-plugin"
|
|
|
|
):
|
2022-09-22 12:48:29 +00:00
|
|
|
self.remove_button.set_visible(False)
|
|
|
|
|
2022-09-04 09:08:32 +00:00
|
|
|
self.set_name(plugin_object.plugin_id)
|
|
|
|
self.set_title(plugin_object.title)
|
|
|
|
self.set_subtitle("@" + plugin_object.plugin_id)
|
2022-08-19 18:49:02 +00:00
|
|
|
|
2022-09-10 13:19:16 +00:00
|
|
|
self.enabled_plugins = self.plugins_list.enabled_plugins
|
|
|
|
if self.plugin_object.plugin_id in self.enabled_plugins:
|
|
|
|
self.switch.set_active(True)
|
2022-09-10 10:38:58 +00:00
|
|
|
|
2022-09-10 10:37:08 +00:00
|
|
|
self.give_preset_settings(preset)
|
2022-09-04 09:44:19 +00:00
|
|
|
|
2022-08-19 18:49:02 +00:00
|
|
|
@Gtk.Template.Callback()
|
|
|
|
def on_settings_plugin_clicked(self, *_args):
|
2022-09-04 09:08:32 +00:00
|
|
|
self.plugin_object.open_settings()
|
2022-08-19 18:49:02 +00:00
|
|
|
|
|
|
|
@Gtk.Template.Callback()
|
|
|
|
def on_remove_plugin_clicked(self, *_args):
|
2022-09-10 13:43:03 +00:00
|
|
|
plugin_yapsy_file = (
|
|
|
|
USER_PLUGIN_DIR / f"{self.plugin_object.plugin_id}.yapsy-plugin"
|
|
|
|
)
|
2022-09-10 13:39:54 +00:00
|
|
|
buglog("remove", plugin_yapsy_file)
|
2022-09-22 12:33:02 +00:00
|
|
|
try:
|
|
|
|
os.remove(plugin_yapsy_file)
|
|
|
|
except FileNotFoundError:
|
|
|
|
error_dialog = Adw.MessageDialog(
|
|
|
|
heading=_("Unable to remove"),
|
2022-09-23 11:14:21 +00:00
|
|
|
body=_("This is a system plugin, and cannot be removed. "),
|
2022-09-22 12:33:02 +00:00
|
|
|
)
|
|
|
|
error_dialog.add_response("close", _("Close"))
|
|
|
|
error_dialog.present()
|
|
|
|
buglog("remove", plugin_yapsy_file)
|
2022-09-10 08:19:54 +00:00
|
|
|
Gtk.Application.get_default().reload_plugins()
|
2022-08-19 18:49:02 +00:00
|
|
|
|
|
|
|
@Gtk.Template.Callback()
|
|
|
|
def on_switch_toggled(self, *_args):
|
2022-09-10 13:19:16 +00:00
|
|
|
if self.switch.get_active():
|
|
|
|
self.plugins_list.enable_plugin(self.plugin_object.plugin_id)
|
|
|
|
else:
|
|
|
|
self.plugins_list.disable_plugin(self.plugin_object.plugin_id)
|
2022-09-10 10:38:58 +00:00
|
|
|
|
2022-09-10 10:37:08 +00:00
|
|
|
def give_preset_settings(self, preset_settings):
|
|
|
|
self.preset_settings = preset_settings
|
|
|
|
self.plugin_object.give_preset_settings(preset_settings)
|