diff options
author | Niels De Graef <nielsdegraef@gmail.com> | 2017-08-22 10:33:30 +0200 |
---|---|---|
committer | Niels De Graef <nielsdegraef@gmail.com> | 2017-08-22 10:33:30 +0200 |
commit | e80fef8824eaa1083eb9250dfe9cf68f6b65c254 (patch) | |
tree | a976a65b6dc082da94266dc2f26657dfcec97a8b | |
parent | 18d6c57d6e825df3f81b6f9165e3501debd5de1d (diff) | |
download | gnome-contacts-e80fef8824eaa1083eb9250dfe9cf68f6b65c254.tar.gz |
Provide a convenience Contacts.Settings class.
Also, make the appropriate field private and just pass it on in the
constructor if necessary.
-rw-r--r-- | po/POTFILES.in | 1 | ||||
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/contacts-app.vala | 7 | ||||
-rw-r--r-- | src/contacts-settings.vala | 32 | ||||
-rw-r--r-- | src/contacts-window.vala | 12 |
5 files changed, 43 insertions, 10 deletions
diff --git a/po/POTFILES.in b/po/POTFILES.in index 304862d..0f80370 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -19,6 +19,7 @@ src/contacts-contact-sheet.vala src/contacts-contact.vala src/contacts-esd-setup.c src/contacts-linked-accounts-dialog.vala +src/contacts-settings.vala src/contacts-types.vala src/contacts-view.vala src/contacts-window.vala diff --git a/src/Makefile.am b/src/Makefile.am index 319e750..e0e1389 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -34,6 +34,7 @@ vala_sources = \ contacts-list-pane.vala \ contacts-linked-accounts-dialog.vala \ contacts-linking.vala \ + contacts-settings.vala \ contacts-store.vala \ contacts-view.vala \ contacts-utils.vala \ diff --git a/src/contacts-app.vala b/src/contacts-app.vala index 6ae1d94..fb72d27 100644 --- a/src/contacts-app.vala +++ b/src/contacts-app.vala @@ -20,7 +20,8 @@ using Folks; public class Contacts.App : Gtk.Application { public static App app; - public GLib.Settings settings; + + private Settings settings; /* moving creation to Window */ public Store contacts_store; @@ -180,7 +181,7 @@ public class Contacts.App : Gtk.Application { } private void create_window () { - window = new Contacts.Window (this, contacts_store); + this.window = new Contacts.Window (this, this.contacts_store, this.settings); } private void schedule_window_creation () { @@ -350,6 +351,6 @@ public class Contacts.App : Gtk.Application { public App () { Object (application_id: "org.gnome.Contacts", flags: ApplicationFlags.HANDLES_COMMAND_LINE); app = this; - settings = new GLib.Settings ("org.gnome.Contacts"); + this.settings = new Settings (this); } } diff --git a/src/contacts-settings.vala b/src/contacts-settings.vala new file mode 100644 index 0000000..bfb11b8 --- /dev/null +++ b/src/contacts-settings.vala @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2011 Alexander Larsson <alexl@redhat.com> + * + * 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 2 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/>. + */ + +/** + * Provides a convenient interface to deal with the settings. + */ +public class Contacts.Settings { + private GLib.Settings settings; + + public bool did_initial_setup { + get { return settings.get_boolean ("did-initial-setup"); } + set { settings.set_boolean ("did-initial-setup", value); } + } + + public Settings (App app) { + this.settings = new GLib.Settings (app.application_id); + } +} diff --git a/src/contacts-window.vala b/src/contacts-window.vala index 37d0db4..e0b2208 100644 --- a/src/contacts-window.vala +++ b/src/contacts-window.vala @@ -1,4 +1,3 @@ -/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 8 -*- */ /* * Copyright (C) 2011 Alexander Larsson <alexl@redhat.com> * @@ -96,7 +95,7 @@ public class Contacts.Window : Gtk.ApplicationWindow { get; set; } - public Window (Gtk.Application app, Store contacts_store) { + public Window (App app, Store contacts_store, Settings settings) { Object ( application: app, show_menubar: false, @@ -143,14 +142,13 @@ public class Contacts.Window : Gtk.ApplicationWindow { BindingFlags.DEFAULT | BindingFlags.INVERT_BOOLEAN); - if ((app as App).settings.get_boolean ("did-initial-setup")) { + if (settings.did_initial_setup) { view_switcher.visible_child_name = "content-view"; set_titlebar (content_header_bar); } else { var change_book_action = app.lookup_action ("change-book") as GLib.SimpleAction; - if (change_book_action != null) { - change_book_action.set_enabled (false); - } + if (change_book_action != null) + change_book_action.set_enabled (false); store.eds_persona_store_changed.connect ( () => { setup_accounts_list.update_contents (false); @@ -172,7 +170,7 @@ public class Contacts.Window : Gtk.ApplicationWindow { var e_store = setup_accounts_list.selected_store as Edsf.PersonaStore; eds_source_registry.set_default_address_book (e_store.source); - (app as App).settings.set_boolean ("did-initial-setup", true); + settings.did_initial_setup = true; if (change_book_action != null) { change_book_action.set_enabled (true); |