From 4c60b19e986fb188352a7cbf55381ec310ffa8e6 Mon Sep 17 00:00:00 2001 From: 0xMRTT <0xMRTT@tuta.io> Date: Sun, 2 Oct 2022 12:33:32 +0200 Subject: [PATCH] feat: add preferences --- accumulate/main.py | 21 ++++++++++++++++++++- accumulate/window.py | 1 + data/ui/window.blp | 6 +++--- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/accumulate/main.py b/accumulate/main.py index 9f50683..d5c70cf 100644 --- a/accumulate/main.py +++ b/accumulate/main.py @@ -82,7 +82,7 @@ class AccumulateApplication(Adw.Application): except requests.HTTPError: self.win.error.set_title(f"{r.status_code}: An HTTP error occured") self.win.error.set_description(f"Server message: {str(r.text)}") - self.win.error_content.set_label(str(r.content)) + self.win.error_label.set_label(str(r.content)) self.win.error_content.set_visible(True) self.win.view_stack.set_visible_child(self.win.error_stack) except requests.ConnectionError: @@ -213,6 +213,25 @@ class AccumulateApplication(Adw.Application): def on_preferences_action(self, widget, _): """Callback for the app.preferences action.""" print('app.preferences action activated') + + pref = Adw.PreferencesWindow() + pref.set_transient_for(self.props.active_window) + pref.set_title("Preferences") + page = Adw.PreferencesPage() + group = Adw.PreferencesGroup(title="Server") + self.server_row = Adw.EntryRow() + self.server_row.set_title("URL") + self.server_row.set_input_purpose(Gtk.InputPurpose.URL) + self.server_row.set_text(self.server) + self.server_row.connect("changed", self.on_server_entry_changed) + group.add(self.server_row) + page.add(group) + pref.add(page) + pref.present() + + def on_server_entry_changed(self, widget): + self.server = widget.get_text() + self.settings.set_string("server-url", self.server) def create_action(self, name, callback, shortcuts=None): """Add an application action. diff --git a/accumulate/window.py b/accumulate/window.py index 58bd5b1..2b700a4 100644 --- a/accumulate/window.py +++ b/accumulate/window.py @@ -35,6 +35,7 @@ class AccumulateWindow(Adw.ApplicationWindow): error = Gtk.Template.Child() error_stack = Gtk.Template.Child() error_content = Gtk.Template.Child() + error_label = Gtk.Template.Child() content = Gtk.Template.Child() already_submitted = Gtk.Template.Child() diff --git a/data/ui/window.blp b/data/ui/window.blp index 3c5c0e1..ba65251 100644 --- a/data/ui/window.blp +++ b/data/ui/window.blp @@ -232,7 +232,8 @@ template AccumulateWindow : Adw.ApplicationWindow { description: _("Please report an issue to the GNOME Team."); icon-name: "error-symbolic"; - Gtk.Box { + Gtk.Box error_content { + visible: false; margin-end: 50; margin-start: 50; styles ["card"] @@ -242,10 +243,9 @@ template AccumulateWindow : Adw.ApplicationWindow { margin-end: 12; min-content-height: 200; overflow: hidden; - Gtk.Label error_content { + Gtk.Label error_label { hexpand: true; vexpand: true; - visible: false; selectable: true; wrap: true; xalign: 0;