[gnome-clocks] Port to AdwApplication



commit 82d747476e7f2ee68af9cb3781deff76d13c4895
Author: Maximiliano Sandoval R <msandova gnome org>
Date:   Mon Dec 13 23:08:26 2021 +0100

    Port to AdwApplication

 data/css/gnome-clocks.dark.css  | 27 +++++++++++++++++++++++++++
 data/gnome-clocks.gresource.xml |  5 +++--
 src/application.vala            | 33 ++++++---------------------------
 src/utils.vala                  | 16 ----------------
 src/window.vala                 |  5 -----
 5 files changed, 36 insertions(+), 50 deletions(-)
---
diff --git a/data/css/gnome-clocks.dark.css b/data/css/gnome-clocks.dark.css
new file mode 100644
index 00000000..79df2648
--- /dev/null
+++ b/data/css/gnome-clocks.dark.css
@@ -0,0 +1,27 @@
+.clock-time {
+       color: alpha(black, 0.8);
+}
+
+.none .clock-time {
+       background: #f6f5f4;
+}
+
+.night .clock-time {
+       background: #a0a2b7;
+}
+
+.astro .clock-time {
+       background: #c6adaa;
+}
+
+.naut .clock-time {
+       background: #ecb89c;
+}
+
+.civil .clock-time {
+       background: #fae189;
+}
+
+.day .clock-time {
+       background: #fcf7b0;
+}
diff --git a/data/gnome-clocks.gresource.xml b/data/gnome-clocks.gresource.xml
index 39070a36..2f34f278 100644
--- a/data/gnome-clocks.gresource.xml
+++ b/data/gnome-clocks.gresource.xml
@@ -1,8 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gresources>
   <gresource prefix="/org/gnome/clocks">
-    <file>css/gnome-clocks.css</file>
-    <file>css/gnome-clocks.highcontrast.css</file>
+    <file alias="style.css">css/gnome-clocks.css</file>
+    <file alias="style-hc.css">css/gnome-clocks.highcontrast.css</file>
+    <file alias="style-dark.css">css/gnome-clocks.dark.css</file>
     <file preprocess="xml-stripblanks">gtk/help-overlay.ui</file>
     <file preprocess="xml-stripblanks">ui/alarm-day-picker-row.ui</file>
     <file preprocess="xml-stripblanks">ui/alarm-face.ui</file>
diff --git a/src/application.vala b/src/application.vala
index 606e6a7c..4d8f942c 100644
--- a/src/application.vala
+++ b/src/application.vala
@@ -18,7 +18,7 @@
 
 namespace Clocks {
 
-public class Application : Gtk.Application {
+public class Application : Adw.Application {
     const OptionEntry[] OPTION_ENTRIES = {
         { "version", 'v', 0, OptionArg.NONE, null, N_("Print version information and exit"), null },
         { (string) null }
@@ -46,7 +46,8 @@ public class Application : Gtk.Application {
     }
 
     public Application () {
-        Object (application_id: Config.APP_ID);
+        Object (application_id: Config.APP_ID,
+                resource_base_path: "/org/gnome/clocks/");
 
         Gtk.Window.set_default_icon_name (Config.APP_ID);
 
@@ -105,36 +106,14 @@ public class Application : Gtk.Application {
         ((Gtk.Widget) win).add_controller (controller);
     }
 
-    private void update_theme (Gtk.Settings settings) {
-        string theme_name;
-
-        settings.get ("gtk-theme-name", out theme_name);
-        Utils.load_css ("gnome-clocks." + theme_name.down ());
-    }
-
     protected override void startup () {
         base.startup ();
 
-        Adw.init ();
-
-        Utils.load_css ("gnome-clocks");
-
-        set_resource_base_path ("/org/gnome/clocks/");
-
-        var theme = Gtk.IconTheme.get_for_display (Gdk.Display.get_default ());
-        theme.add_resource_path ("/org/gnome/clocks/icons");
-
-        var settings = (Gtk.Settings) Gtk.Settings.get_default ();
-        settings.notify["gtk-theme-name"].connect (() => {
-            update_theme (settings);
-        });
-        update_theme (settings);
-
-        set_accels_for_action ("win.new", { "<Primary>n" });
+        set_accels_for_action ("win.new", { "<Control>n" });
         set_accels_for_action ("win.show-primary-menu", { "F10" });
-        set_accels_for_action ("win.show-help-overlay", { "<Primary>question" });
+        set_accels_for_action ("win.show-help-overlay", { "<Control>question" });
         set_accels_for_action ("win.help", { "F1" });
-        set_accels_for_action ("app.quit", { "<Primary>q" });
+        set_accels_for_action ("app.quit", { "<Control>q" });
     }
 
     protected override int handle_local_options (GLib.VariantDict options) {
diff --git a/src/utils.vala b/src/utils.vala
index 78842082..6f8bdfa8 100644
--- a/src/utils.vala
+++ b/src/utils.vala
@@ -36,22 +36,6 @@ const double RISESET_CORRECTION_ASTRONOMICAL = 18.0;
 namespace Clocks {
 namespace Utils {
 
-public void load_css (string css) {
-    var provider = new Gtk.CssProvider ();
-    try {
-        var data = resources_lookup_data ("/org/gnome/clocks/css/" + css + ".css", NONE);
-        provider.load_from_data (data.get_data ());
-        Gtk.StyleContext.add_provider_for_display (Gdk.Display.get_default (),
-                                                   provider,
-                                                   Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
-
-    } catch (ResourceError.NOT_FOUND e) {
-        /* Ignore */
-    } catch (Error e) {
-        warning ("Didn't load css for %s: %s".printf (css, e.message));
-    }
-}
-
 public void time_to_hms (double t, out int h, out int m, out int s, out double remainder) {
     h = (int) t / 3600;
     t = t % 3600;
diff --git a/src/window.vala b/src/window.vala
index 808b0490..1bc781ec 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -94,11 +94,6 @@ public class Window : Adw.ApplicationWindow {
         settings = new Settings ("org.gnome.clocks.state.window");
         settings.delay ();
 
-        // We need to set this manually, otherwise it fails in the devel version
-        var builder = new Gtk.Builder.from_resource ("/org/gnome/clocks/gtk/help-overlay.ui");
-        var dialog = (Gtk.ShortcutsWindow)builder.get_object ("help_overlay");
-        set_help_overlay (dialog);
-
         // GSettings gives us the nick, which matches the stack page name
         stack.visible_child_name = settings.get_string ("panel-id");
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]