diff --git a/data/com.github.dbhowell.peeq.gschema.xml b/data/com.github.dbhowell.peeq.gschema.xml index a694363..a0269d8 100644 --- a/data/com.github.dbhowell.peeq.gschema.xml +++ b/data/com.github.dbhowell.peeq.gschema.xml @@ -57,6 +57,11 @@ '12pt' Preferred font size Set the preferred font size for SQL queries and results. + + + false + Request dark Gtk stylesheet variant + Switches between dark and light style diff --git a/src/Dialogs/PreferencesDialog.vala b/src/Dialogs/PreferencesDialog.vala index 2e90a2b..b1f2bc5 100644 --- a/src/Dialogs/PreferencesDialog.vala +++ b/src/Dialogs/PreferencesDialog.vala @@ -66,8 +66,6 @@ namespace Peeq.Dialogs { style_combo.append ("tango", _("Tango")); Peeq.settings.schema.bind ("style-scheme", style_combo, "active-id", SettingsBindFlags.DEFAULT); - var font_header = new Granite.HeaderLabel (_("Font")); - var use_custom_font_label = new SettingsLabel (_("Custom font:")); use_custom_font = new Gtk.Switch (); use_custom_font.halign = Gtk.Align.START; @@ -78,10 +76,24 @@ namespace Peeq.Dialogs { Peeq.settings.schema.bind ("font", select_font, "font-name", SettingsBindFlags.DEFAULT); Peeq.settings.schema.bind ("use-system-font", select_font, "sensitive", SettingsBindFlags.INVERT_BOOLEAN); - content.attach (editor_header, 0, 0, 3, 1); + + var general_header = new Granite.HeaderLabel (_("General")); + var dark_mode_label = new SettingsLabel (_("Dark mode:")); + var dark_mode_switch = new Granite.ModeSwitch.from_icon_name ( + "display-brightness-symbolic", "weather-clear-night-symbolic" + ); + dark_mode_switch.notify["active"].connect (() => { + var gtk_settings = Gtk.Settings.get_default (); + gtk_settings.gtk_application_prefer_dark_theme = dark_mode_switch.active; + }); + Peeq.settings.schema.bind ("prefer-dark-style", dark_mode_switch, "active", GLib.SettingsBindFlags.DEFAULT); + + content.attach (general_header, 0, 1, 3, 1); + content.attach (dark_mode_label, 0, 2, 1, 1); + content.attach (dark_mode_switch, 1, 2, 3, 1); + content.attach (editor_header, 0, 3, 3, 1); content.attach (style_label, 0, 4, 1, 1); content.attach (style_combo, 1, 4, 2, 1); - content.attach (font_header, 0, 7, 3, 1); content.attach (use_custom_font_label , 0, 9, 1, 1); content.attach (use_custom_font, 1, 9, 1, 1); content.attach (select_font, 2, 9, 1, 1); diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 30bcf04..6e4a843 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -23,7 +23,6 @@ namespace Peeq { private Widgets.MainHeaderBar headerbar; private Widgets.Welcome welcome; - private Services.Settings settings; private Widgets.ServerList server_list; private Gtk.Stack content; private Gtk.ScrolledWindow scrolled_window; @@ -41,12 +40,14 @@ namespace Peeq { } construct { - settings = new Services.Settings (); query_windows = new Gee.ArrayList (); init_layout (); } private void init_layout () { + var gtk_settings = Gtk.Settings.get_default (); + gtk_settings.gtk_application_prefer_dark_theme = Peeq.settings.prefer_dark_style; + headerbar = new Widgets.MainHeaderBar (); set_titlebar (headerbar); @@ -243,7 +244,7 @@ namespace Peeq { } private void restore_settings () { - foreach (var s in settings.servers) { + foreach (var s in Peeq.settings.servers) { Utils.ConnectionString cs = Utils.ConnectionString.parse (s); if (cs.get("server_name") != null) { @@ -251,10 +252,10 @@ namespace Peeq { } } - default_width = settings.window_width; - default_height = settings.window_height; + default_width = Peeq.settings.window_width; + default_height = Peeq.settings.window_height; - switch (settings.window_state) { + switch (Peeq.settings.window_state) { case PeeqWindowState.MAXIMIZED: maximize (); break; @@ -262,7 +263,7 @@ namespace Peeq { fullscreen (); break; default: - move (settings.window_x, settings.window_y); + move (Peeq.settings.window_x, Peeq.settings.window_y); break; } } @@ -276,27 +277,27 @@ namespace Peeq { servers += @"$(server_item.page.server.connection_string)"; } - settings.servers = servers; + Peeq.settings.servers = servers; var state = get_window ().get_state (); if (Gdk.WindowState.MAXIMIZED in state) { - settings.window_state = PeeqWindowState.MAXIMIZED; + Peeq.settings.window_state = PeeqWindowState.MAXIMIZED; } else if (Gdk.WindowState.FULLSCREEN in state) { - settings.window_state = PeeqWindowState.FULLSCREEN; + Peeq.settings.window_state = PeeqWindowState.FULLSCREEN; } else { - settings.window_state = PeeqWindowState.NORMAL; + Peeq.settings.window_state = PeeqWindowState.NORMAL; // Save window size int width, height; get_size (out width, out height); - settings.window_width = width; - settings.window_height = height; + Peeq.settings.window_width = width; + Peeq.settings.window_height = height; } int x, y; get_position (out x, out y); - settings.window_x = x; - settings.window_y = y; + Peeq.settings.window_x = x; + Peeq.settings.window_y = y; } diff --git a/src/Services/Settings.vala b/src/Services/Settings.vala index 2892b9e..7e86791 100644 --- a/src/Services/Settings.vala +++ b/src/Services/Settings.vala @@ -36,6 +36,7 @@ namespace Peeq { public string font { get; set; } public string font_size { get; set; } public bool use_system_font { get; set; } + public bool prefer_dark_style { get; set; } public Settings () { base (Constants.PROJECT_NAME + ".settings"); diff --git a/src/Utils/DataFormat.vala b/src/Utils/DataFormat.vala index 54fecf4..6124d43 100644 --- a/src/Utils/DataFormat.vala +++ b/src/Utils/DataFormat.vala @@ -7,6 +7,7 @@ namespace Peeq.Utils { public const string QUOTE = "'"; public const string NEW_LINE = "\n"; + public const uint PG_TYPE_JSON = 114; public const uint PG_TYPE_BOOL = 16; public const uint PG_TYPE_TIMESTAMP = 1184; @@ -21,6 +22,20 @@ namespace Peeq.Utils { return "null"; } + if (format == PG_TYPE_BOOL && value == "") { + return "null"; + } + + if (format == PG_TYPE_JSON) { + Json.Node? json_value = Json.from_string (value); + + if (json_value == null) { + return "null"; + } + + return Json.to_string(json_value, true); + } + return @"\"$(value)\""; } diff --git a/src/meson.build b/src/meson.build index 0a788e9..0b32cb4 100644 --- a/src/meson.build +++ b/src/meson.build @@ -54,6 +54,7 @@ executable( dependency('gee-0.8'), dependency('libpq'), dependency('granite'), + dependency('json-glib-1.0'), meson.get_compiler('vala').find_library('posix') ], install: true