diff --git a/meson.build b/meson.build index 4ad41b5..6224315 100644 --- a/meson.build +++ b/meson.build @@ -35,7 +35,6 @@ executable( meson.project_name(), config_file, 'src/Application.vala', - 'src/AppSettings.vala', 'src/Constants.vala', 'src/DetailedView.vala', 'src/FolderLoader.vala', @@ -54,4 +53,4 @@ executable( subdir('data') subdir('po') -meson.add_install_script('meson/post_install.py') \ No newline at end of file +meson.add_install_script('meson/post_install.py') diff --git a/src/AppSettings.vala b/src/AppSettings.vala deleted file mode 100755 index fc4e030..0000000 --- a/src/AppSettings.vala +++ /dev/null @@ -1,40 +0,0 @@ -/*- - * Copyright 2021 Adam Bieńkowski - * - * This program is free software: you can redistribute it - * and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see http://www.gnu.org/licenses/. - */ - -public class Eddy.AppSettings : Granite.Services.Settings { - public string[] mime_types { get; set; } - public bool always_on_top { get; set; } - - public int window_width { get; set; } - public int window_height { get; set; } - public int window_x { get; set; } - public int window_y { get; set; } - public bool window_maximized { get; set; } - - private static AppSettings? instance; - public static unowned AppSettings get_default () { - if (instance == null) { - instance = new AppSettings (); - } - - return instance; - } - - private AppSettings () { - base (Constants.SCHEMA_NAME); - } -} \ No newline at end of file diff --git a/src/Application.vala b/src/Application.vala index 8dbde08..17ef4ee 100755 --- a/src/Application.vala +++ b/src/Application.vala @@ -21,6 +21,12 @@ public class Eddy.Application : Gtk.Application { private Pk.Control control; private MainWindow? window = null; + public static Settings settings; + + static construct { + settings = new Settings (Constants.SCHEMA_NAME); + } + construct { flags |= ApplicationFlags.HANDLES_OPEN; @@ -33,8 +39,7 @@ public class Eddy.Application : Gtk.Application { control = new Pk.Control (); - var settings = AppSettings.get_default (); - string[] available_mimetypes = settings.mime_types; + string[] available_mimetypes = settings.get_strv ("mime-types"); if (available_mimetypes.length > 0) { debug ("Using cached mime types from %s schema: %s", Constants.SCHEMA_NAME, string.joinv ("; ", available_mimetypes)); @@ -59,7 +64,7 @@ public class Eddy.Application : Gtk.Application { supported_mimetypes = Constants.DEFAULT_SUPPORTED_MIMETYPES; } - settings.mime_types = supported_mimetypes; + settings.set_strv ("mime-types", supported_mimetypes); // Register Eddy as the default app if there's no handler for a supported mimetype register_default_handler (); diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 1b776a5..1e8c529 100755 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -158,21 +158,21 @@ public class Eddy.MainWindow : Gtk.Window { Gtk.drag_dest_set (this, Gtk.DestDefaults.MOTION | Gtk.DestDefaults.DROP, Constants.DRAG_TARGETS, Gdk.DragAction.COPY); - var settings = AppSettings.get_default (); - - int x = settings.window_x; - int y = settings.window_y; + int x = Application.settings.get_int ("window-x"); + int y = Application.settings.get_int ("window-y"); if (x != -1 && y != -1) { move (x, y); } - resize (settings.window_width, settings.window_height); - if (settings.window_maximized) { + int w = Application.settings.get_int ("window-width"); + int h = Application.settings.get_int ("window-height"); + resize (w, h); + if (Application.settings.get_boolean ("window-maximized")) { maximize (); } - set_keep_above (settings.always_on_top); + set_keep_above (Application.settings.get_boolean ("always-on-top")); drag_data_received.connect (on_drag_data_received); @@ -240,16 +240,15 @@ public class Eddy.MainWindow : Gtk.Window { get_position (out x, out y); get_size (out width, out height); - var settings = AppSettings.get_default (); - settings.window_x = x; - settings.window_y = y; - settings.window_width = width; - settings.window_height = height; - settings.window_maximized = is_maximized; + Application.settings.set_int ("window-x", x); + Application.settings.set_int ("window-y", y); + Application.settings.set_int ("window-width", width); + Application.settings.set_int ("window-height", height); + Application.settings.set_boolean ("window-maximized", is_maximized); var window = get_window (); if (window != null) { - settings.always_on_top = Gdk.WindowState.ABOVE in window.get_state (); + Application.settings.set_boolean ("always-on-top", Gdk.WindowState.ABOVE in window.get_state ()); } return false;