Skip to content

Commit

Permalink
Merge pull request #24 from dbhowell/format-json-type
Browse files Browse the repository at this point in the history
Format json type
  • Loading branch information
dbhowell authored Jul 7, 2019
2 parents a2d86c5 + 39e9982 commit 41451a1
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 19 deletions.
5 changes: 5 additions & 0 deletions data/com.github.dbhowell.peeq.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
<default>'12pt'</default>
<summary>Preferred font size</summary>
<description>Set the preferred font size for SQL queries and results.</description>
</key>
<key name="prefer-dark-style" type="b">
<default>false</default>
<summary>Request dark Gtk stylesheet variant</summary>
<description>Switches between dark and light style</description>
</key>
</schema>
</schemalist>
20 changes: 16 additions & 4 deletions src/Dialogs/PreferencesDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
31 changes: 16 additions & 15 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,12 +40,14 @@ namespace Peeq {
}

construct {
settings = new Services.Settings ();
query_windows = new Gee.ArrayList<QueryWindow> ();
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);

Expand Down Expand Up @@ -243,26 +244,26 @@ 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) {
create_server_item (cs);
}
}

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;
case PeeqWindowState.FULLSCREEN:
fullscreen ();
break;
default:
move (settings.window_x, settings.window_y);
move (Peeq.settings.window_x, Peeq.settings.window_y);
break;
}
}
Expand All @@ -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;

}

Expand Down
1 change: 1 addition & 0 deletions src/Services/Settings.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
15 changes: 15 additions & 0 deletions src/Utils/DataFormat.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)\"";
}

Expand Down
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 41451a1

Please sign in to comment.