From 4b5f2b8b3abc26c974ddb0024b9a2502c4fa3824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A9v=C3=A9nyi=20Benedek?= Date: Mon, 2 Dec 2024 19:40:03 +0100 Subject: [PATCH] First two pages done --- cozy/ui/main_view.py | 3 + cozy/ui/preferences_window.py | 1 - cozy/ui/widgets/error_reporting.py | 78 ++++-------- cozy/ui/widgets/welcome_dialog.py | 33 +++++ data/gresource.xml | 1 + data/ui/error_reporting.blp | 191 +++++------------------------ data/ui/meson.build | 1 + data/ui/welcome_dialog.blp | 51 ++++++++ 8 files changed, 149 insertions(+), 210 deletions(-) create mode 100644 cozy/ui/widgets/welcome_dialog.py create mode 100644 data/ui/welcome_dialog.blp diff --git a/cozy/ui/main_view.py b/cozy/ui/main_view.py index d5ca71c4..b73d9bad 100644 --- a/cozy/ui/main_view.py +++ b/cozy/ui/main_view.py @@ -20,6 +20,7 @@ from cozy.ui.library_view import LibraryView from cozy.ui.preferences_window import PreferencesWindow from cozy.ui.widgets.first_import_button import FirstImportButton +from cozy.ui.widgets.welcome_dialog import WelcomeDialog from cozy.view_model.playback_control_view_model import PlaybackControlViewModel from cozy.view_model.playback_speed_view_model import PlaybackSpeedViewModel from cozy.view_model.storages_view_model import StoragesViewModel @@ -92,6 +93,8 @@ def __init_window(self): self.navigation_view.add(BookDetailView()) + WelcomeDialog().present(self.window) + self.window.present() def __init_actions(self): diff --git a/cozy/ui/preferences_window.py b/cozy/ui/preferences_window.py index 6c9bc157..8ce105b0 100644 --- a/cozy/ui/preferences_window.py +++ b/cozy/ui/preferences_window.py @@ -29,7 +29,6 @@ def __init__(self) -> None: super().__init__() error_reporting = ErrorReporting() - error_reporting.show_header(False) self.user_feedback_preference_group.add(error_reporting) self.storage_locations_view = StorageLocations() diff --git a/cozy/ui/widgets/error_reporting.py b/cozy/ui/widgets/error_reporting.py index 44177562..880c75ec 100644 --- a/cozy/ui/widgets/error_reporting.py +++ b/cozy/ui/widgets/error_reporting.py @@ -1,7 +1,7 @@ -from gettext import gettext as _ +from itertools import chain import inject -from gi.repository import Gtk +from gi.repository import Adw, Gtk from cozy.settings import ApplicationSettings @@ -9,7 +9,7 @@ _("Disabled"), _("Basic error reporting"), _("Detailed error reporting"), - _("Detailed error reporting with import errors") + _("Detailed, with media types") ] LEVEL_DESCRIPTION = [ @@ -17,76 +17,52 @@ _("The following information will be sent in case of an error or crash:") ] -LEVEL_DETAILS = { - 0: [], - 1: [_("Which type of error occurred"), +LEVEL_DETAILS = [ + [], + [_("Which type of error occurred"), _("Line of code where an error occurred"), _("Cozy's version"), ], - 2: [_("Linux distribution"), + [_("Linux distribution"), _("Desktop environment")], - 3: [_("Media type of files that Cozy couldn't import")] -} + [_("Media type of files that Cozy couldn't import")] +] @Gtk.Template.from_resource('/com/github/geigi/cozy/ui/error_reporting.ui') class ErrorReporting(Gtk.Box): __gtype_name__ = 'ErrorReporting' - level_label: Gtk.Label = Gtk.Template.Child() - description_label: Gtk.Label = Gtk.Template.Child() - details_label: Gtk.Label = Gtk.Template.Child() - header_box: Gtk.Box = Gtk.Template.Child() - - verbose_adjustment: Gtk.Adjustment = Gtk.Template.Child() - verbose_scale: Gtk.Scale = Gtk.Template.Child() + description: Adw.ActionRow = Gtk.Template.Child() + detail_combo: Adw.ComboRow = Gtk.Template.Child() app_settings: ApplicationSettings = inject.attr(ApplicationSettings) def __init__(self, **kwargs): super().__init__(**kwargs) - self.__init_scale() + levels_list = Gtk.StringList(strings=LEVELS) + self.detail_combo.props.model = levels_list + self.detail_combo.connect("notify::selected-item", self._level_selected) + self._load_report_level() - self.__connect() self.app_settings.add_listener(self._on_app_setting_changed) - def show_header(self, show: bool): - self.header_box.set_visible(show) - def _load_report_level(self): level = self.app_settings.report_level - self.verbose_adjustment.set_value(level + 1) - self._update_ui_texts(level) - - def __init_scale(self): - for i in range(1, 5): - self.verbose_scale.add_mark(i, Gtk.PositionType.RIGHT, None) - self.verbose_scale.set_round_digits(0) - - def __connect(self): - self.verbose_adjustment.connect("value-changed", self._adjustment_changed) - - def _adjustment_changed(self, adjustment: Gtk.Adjustment): - level = int(adjustment.get_value()) - 1 - self.app_settings.report_level = level - self._update_ui_texts(level) - - def _update_ui_texts(self, level: int): - self.level_label.set_text(LEVELS[level]) self._update_description(level) - self._update_details(level) - - def _update_description(self, value): - detail_index = min(value, 1) - self.description_label.set_text(LEVEL_DESCRIPTION[detail_index]) - - def _update_details(self, value): - details = "" - for i in range(value + 1): - for line in LEVEL_DETAILS[i]: - details += f"• {line}\n" - self.details_label.set_text(details) + self.detail_combo.set_selected(level) + + def _level_selected(self, obj, param) -> None: + selected = obj.get_property(param.name).get_string() + index = LEVELS.index(selected) + self.app_settings.report_level = index + self._update_description(index) + + def _update_description(self, level: int): + self.description.set_title(LEVEL_DESCRIPTION[min(level, 1)]) + details = "\n".join(["• " + i for i in chain(*LEVEL_DETAILS[:level+1])]) + self.description.set_subtitle(details) def _on_app_setting_changed(self, event, _): if event == "report-level": diff --git a/cozy/ui/widgets/welcome_dialog.py b/cozy/ui/widgets/welcome_dialog.py new file mode 100644 index 00000000..95885259 --- /dev/null +++ b/cozy/ui/widgets/welcome_dialog.py @@ -0,0 +1,33 @@ +import inject +from gi.repository import Adw, Gtk + +from cozy.view_model.playback_speed_view_model import PlaybackSpeedViewModel +from cozy.ui.widgets.error_reporting import ErrorReporting +from cozy.settings import ApplicationSettings + + +@Gtk.Template.from_resource('/com/github/geigi/cozy/ui/welcome_dialog.ui') +class WelcomeDialog(Adw.Dialog): + __gtype_name__ = "WelcomeDialog" + + app_settings: ApplicationSettings = inject.attr(ApplicationSettings) + + carousel: Adw.Carousel = Gtk.Template.Child() + welcome_page: Adw.StatusPage = Gtk.Template.Child() + reporting_page: Gtk.Box = Gtk.Template.Child() + + def __init__(self): + super().__init__() + self.order = [self.welcome_page, self.reporting_page, self.welcome_page] + + @Gtk.Template.Callback() + def deny_reporting(self, _): + self.app_settings.report_level = 0 + self.advance() + + @Gtk.Template.Callback() + def accept_reporting(self, _): + self.advance() + + def advance(self): + self.carousel.scroll_to(self.order[int(self.carousel.get_position()) + 1], True) diff --git a/data/gresource.xml b/data/gresource.xml index 79f0f758..131384ab 100644 --- a/data/gresource.xml +++ b/data/gresource.xml @@ -18,6 +18,7 @@ ui/storage_locations.ui ui/storage_row.ui ui/timer_popover.ui + ui/welcome_dialog.ui ../AUTHORS.md diff --git a/data/ui/error_reporting.blp b/data/ui/error_reporting.blp index 6f59a85d..3494e89d 100644 --- a/data/ui/error_reporting.blp +++ b/data/ui/error_reporting.blp @@ -1,174 +1,49 @@ using Gtk 4.0; +using Adw 1; -Adjustment verbose_adjustment { - lower: 1; - upper: 5; - value: 3; - step-increment: 1; - page-increment: 1; - page-size: 1; -} template $ErrorReporting: Box { orientation: vertical; - spacing: 10; - - styles [ - "card", - ] - - Box header_box { - halign: center; - spacing: 15; + spacing: 12; + + Label { + halign: fill; + hexpand: true; + label: C_("Error and crash reporting dialog", "You can help us improve Cozy by contributing information in case of errors and crashes."); + wrap: true; + xalign: 0; + } - Label { - label: _("User feedback"); - wrap: true; + Label { + halign: fill; + hexpand: true; + label: C_("Error and crash reporting dialog", "Contributing this information is optional and completely anonymous. We will never collect personal data, files you import or any information that could identify you."); + wrap: true; + xalign: 0; + } - styles [ - "title-3", - ] - } + Label { + halign: fill; + hexpand: true; + label: C_("Error and crash reporting dialog", "Cozy is developed in the open, and the error reporting code can be inspected here:"); + wrap: true; + xalign: 0; + } - Image { - pixel-size: 32; - icon-name: 'book-alert-symbolic'; - } + LinkButton { + label: _("Sourcecode on GitHub"); + uri: "https://github.com/geigi/cozy/tree/master/cozy/report"; + margin-bottom: 6; } ListBox { + styles ["boxed-list"] selection-mode: none; - activate-on-single-click: false; - - styles [ - "transparent_bg", - ] - ListBoxRow { - activatable: false; - selectable: false; - - child: Box { - margin-start: 10; - margin-end: 10; - margin-top: 10; - margin-bottom: 10; - orientation: vertical; - spacing: 10; - - Box { - valign: center; - orientation: vertical; - spacing: 10; - - Label { - halign: start; - valign: center; - label: C_("Error and crash reporting dialog", "You can help improve Cozy by contributing information in case of errors and crashes. "); - wrap: true; - xalign: 0; - } - - Label { - valign: center; - label: C_("Error and crash reporting dialog", "Contributing this information is optional and completely anonymous. We will never collect personal data, files you import or any information that could identify you."); - wrap: true; - xalign: 0; - } - - Label { - valign: center; - halign: start; - label: C_("Error and crash reporting dialog", "Cozy is opensource and the user feedback source code can be inspected here: "); - wrap: true; - xalign: 0; - } - } - - Label { - label: _("Sourcecode on GitHub"); - use-markup: true; - } - }; + Adw.ComboRow detail_combo { + title: "Detail Level"; } - ListBoxRow { - activatable: false; - selectable: false; - - child: Separator { - margin-start: 5; - margin-end: 5; - }; - } - - ListBoxRow { - activatable: false; - selectable: false; - - child: Scale verbose_scale { - focusable: true; - margin-start: 20; - margin-end: 20; - margin-top: 10; - margin-bottom: 10; - adjustment: verbose_adjustment; - restrict-to-fill-level: false; - fill-level: 0; - round-digits: 0; - }; - } - - ListBoxRow { - activatable: false; - selectable: false; - - child: Separator { - margin-start: 5; - margin-end: 5; - }; - } - - ListBoxRow { - activatable: false; - selectable: false; - - child: Box { - halign: start; - valign: center; - margin-start: 10; - margin-end: 10; - margin-top: 10; - margin-bottom: 10; - orientation: vertical; - spacing: 10; - - Label level_label { - halign: start; - label: _("Detailed error reporting with import errors"); - wrap: true; - xalign: 0; - - styles [ - "heading", - ] - } - - Label description_label { - halign: start; - valign: start; - label: _("The following information will be sent in case of an error or crash:"); - wrap: true; - xalign: 0; - } - - Label details_label { - vexpand: true; - halign: start; - valign: start; - wrap: true; - } - }; - } + Adw.ActionRow description {} } -} +} \ No newline at end of file diff --git a/data/ui/meson.build b/data/ui/meson.build index 12bfd3b0..37763e49 100644 --- a/data/ui/meson.build +++ b/data/ui/meson.build @@ -19,6 +19,7 @@ blueprints = custom_target('blueprints', 'storage_locations.blp', 'storage_row.blp', 'timer_popover.blp', + 'welcome_dialog.blp', ), output: '.', command: [find_program('blueprint-compiler'), 'batch-compile', '@OUTPUT@', '@CURRENT_SOURCE_DIR@', '@INPUT@'], diff --git a/data/ui/welcome_dialog.blp b/data/ui/welcome_dialog.blp new file mode 100644 index 00000000..981329b7 --- /dev/null +++ b/data/ui/welcome_dialog.blp @@ -0,0 +1,51 @@ +using Gtk 4.0; +using Adw 1; + +template $WelcomeDialog: Adw.Dialog { + width-request: 360; + content-width: 450; + content-height: 600; + + Adw.Carousel carousel { + Adw.StatusPage welcome_page { + icon-name: 'com.github.geigi.cozy'; + title: "Let's Get Cozy!"; + hexpand: true; + } + + Box reporting_page{ + orientation: vertical; + spacing: 18; + + Adw.StatusPage { + valign: start; + margin-start: 12; + margin-end: 12; + title: "Error Reporting"; + + styles ["compact"] + + child: $ErrorReporting {}; + } + + CenterBox { + valign: end; + vexpand: true; + + [center] + Box { + spacing: 12; + margin-bottom: 18; + Button { + label: "I Don't Want This"; + clicked => $deny_reporting(); + } + Button { + label: "It's Fine With Me"; + clicked => $accept_reporting(); + } + } + } + } + } +} \ No newline at end of file