2022-08-24 18:51:14 +00:00
|
|
|
# explore_preset_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/>.
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
2022-09-07 16:00:33 +00:00
|
|
|
from gi.repository import Gtk, Adw
|
2022-08-24 18:51:14 +00:00
|
|
|
|
|
|
|
from .constants import rootdir
|
|
|
|
from .modules.custom_presets import download_preset
|
|
|
|
from .modules.utils import to_slug_case, buglog
|
|
|
|
|
2022-08-24 22:29:14 +00:00
|
|
|
|
2022-08-24 18:51:14 +00:00
|
|
|
@Gtk.Template(resource_path=f"{rootdir}/ui/explore_preset_row.ui")
|
|
|
|
class GradienceExplorePresetRow(Adw.ActionRow):
|
|
|
|
__gtype_name__ = "GradienceExplorePresetRow"
|
|
|
|
|
|
|
|
apply_button = Gtk.Template.Child("apply_button")
|
|
|
|
download_button = Gtk.Template.Child("download_button")
|
2022-09-16 06:09:46 +00:00
|
|
|
badge = Gtk.Template.Child("badge")
|
2022-08-24 18:51:14 +00:00
|
|
|
|
2022-09-16 06:09:46 +00:00
|
|
|
def __init__(self, name, url, win, repo_name, badge, author="", **kwargs):
|
2022-08-24 18:51:14 +00:00
|
|
|
super().__init__(**kwargs)
|
|
|
|
|
|
|
|
self.name = name
|
2022-09-03 17:04:33 +00:00
|
|
|
|
2022-09-03 16:54:18 +00:00
|
|
|
self.prefix = to_slug_case(repo_name)
|
2022-08-24 18:51:14 +00:00
|
|
|
|
|
|
|
self.set_name(name)
|
|
|
|
self.set_title(name)
|
2022-09-16 06:09:46 +00:00
|
|
|
self.set_subtitle(author)
|
|
|
|
|
|
|
|
self.badge.set_label(repo_name)
|
|
|
|
self.badge.get_style_context().add_class(f"badge-{badge}")
|
2022-08-24 18:51:14 +00:00
|
|
|
|
|
|
|
self.app = Gtk.Application.get_default()
|
|
|
|
self.win = win
|
|
|
|
self.toast_overlay = self.win.toast_overlay
|
|
|
|
|
|
|
|
self.url = url
|
|
|
|
|
|
|
|
@Gtk.Template.Callback()
|
|
|
|
def on_apply_button_clicked(self, *_args):
|
2022-08-24 19:27:18 +00:00
|
|
|
try:
|
2022-09-03 17:04:12 +00:00
|
|
|
download_preset(to_slug_case(self.name), self.prefix, self.url)
|
2022-08-28 01:41:18 +00:00
|
|
|
except Exception as exception:
|
2022-08-24 19:27:18 +00:00
|
|
|
self.toast_overlay.add_toast(
|
2022-08-25 13:28:38 +00:00
|
|
|
Adw.Toast(title=_("Preset could not be downloaded"))
|
2022-08-24 19:27:18 +00:00
|
|
|
)
|
2022-08-28 01:41:18 +00:00
|
|
|
buglog(exception)
|
2022-08-24 19:27:18 +00:00
|
|
|
else:
|
2022-09-07 15:51:36 +00:00
|
|
|
self.app.load_preset_from_file(
|
|
|
|
os.path.join(
|
|
|
|
os.environ.get("XDG_CONFIG_HOME",
|
|
|
|
os.environ["HOME"] + "/.config"),
|
|
|
|
"presets",
|
|
|
|
self.prefix,
|
|
|
|
to_slug_case(self.name) + ".json",
|
|
|
|
)
|
|
|
|
)
|
2022-08-24 19:27:18 +00:00
|
|
|
|
|
|
|
self.toast_overlay.add_toast(
|
2022-09-07 15:51:36 +00:00
|
|
|
Adw.Toast(title=_("Preset downloaded")))
|
2022-08-28 01:41:18 +00:00
|
|
|
self.win.reload_pref_group()
|
2022-08-28 19:05:51 +00:00
|
|
|
|
2022-08-28 01:41:18 +00:00
|
|
|
buglog("Apply and download compeleted")
|
2022-08-24 18:51:14 +00:00
|
|
|
|
|
|
|
@Gtk.Template.Callback()
|
|
|
|
def on_download_button_clicked(self, *_args):
|
|
|
|
try:
|
2022-09-03 16:54:18 +00:00
|
|
|
download_preset(to_slug_case(self.name), self.prefix, self.url)
|
2022-08-28 01:41:18 +00:00
|
|
|
except Exception as exception:
|
2022-08-24 18:51:14 +00:00
|
|
|
self.toast_overlay.add_toast(
|
2022-08-25 13:28:38 +00:00
|
|
|
Adw.Toast(title=_("Preset could not be downloaded"))
|
2022-08-24 18:51:14 +00:00
|
|
|
)
|
2022-08-28 01:41:18 +00:00
|
|
|
buglog(exception)
|
2022-08-24 18:51:14 +00:00
|
|
|
else:
|
|
|
|
self.toast_overlay.add_toast(
|
2022-09-07 15:51:36 +00:00
|
|
|
Adw.Toast(title=_("Preset downloaded")))
|
2022-08-25 09:42:21 +00:00
|
|
|
self.win.reload_pref_group()
|
2022-08-28 01:41:18 +00:00
|
|
|
buglog("Download compeleted")
|