Skip to content

Commit

Permalink
First two pages done
Browse files Browse the repository at this point in the history
  • Loading branch information
rdbende committed Dec 2, 2024
1 parent 6cda5f3 commit 4b5f2b8
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 210 deletions.
3 changes: 3 additions & 0 deletions cozy/ui/main_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -92,6 +93,8 @@ def __init_window(self):

self.navigation_view.add(BookDetailView())

WelcomeDialog().present(self.window)

self.window.present()

def __init_actions(self):
Expand Down
1 change: 0 additions & 1 deletion cozy/ui/preferences_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
78 changes: 27 additions & 51 deletions cozy/ui/widgets/error_reporting.py
Original file line number Diff line number Diff line change
@@ -1,92 +1,68 @@
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

LEVELS = [
_("Disabled"),
_("Basic error reporting"),
_("Detailed error reporting"),
_("Detailed error reporting with import errors")
_("Detailed, with media types")
]

LEVEL_DESCRIPTION = [
_("No error or crash reporting."),
_("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":
Expand Down
33 changes: 33 additions & 0 deletions cozy/ui/widgets/welcome_dialog.py
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions data/gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<file preprocess="xml-stripblanks">ui/storage_locations.ui</file>
<file preprocess="xml-stripblanks">ui/storage_row.ui</file>
<file preprocess="xml-stripblanks">ui/timer_popover.ui</file>
<file preprocess="xml-stripblanks">ui/welcome_dialog.ui</file>
</gresource>
<gresource prefix="/com/github/geigi/cozy/appdata">
<file alias="authors.list">../AUTHORS.md</file>
Expand Down
191 changes: 33 additions & 158 deletions data/ui/error_reporting.blp
Original file line number Diff line number Diff line change
@@ -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: _("<a href=\"https://github.com/geigi/cozy/tree/master/cozy/report\">Sourcecode on GitHub</a>");
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 {}
}
}
}
Loading

0 comments on commit 4b5f2b8

Please sign in to comment.