summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank Zschage <frank@reissan.de>2018-02-18 15:07:38 +0100
committerFrank Zschage <frank@reissan.de>2018-02-18 15:07:38 +0100
commitb689eb8b96fe987d2539b83fe7b18a85682c24bc (patch)
tree66524563bd52aa3fbc4a1aa5117031795c57a89b
parent766368d106a5301801ce6183da59a95bdfedb9ad (diff)
downloadgnome-contacts-b689eb8b96fe987d2539b83fe7b18a85682c24bc.tar.gz
Contacts.Window: remember width and height of window
According to the change request in issue #9 the contacts application will now store any size changes to the window or if the window has got maximized to the underlaying settings store and will restore the changed dimensions after restarting the app. https://gitlab.gnome.org/GNOME/gnome-contacts/issues/9
-rw-r--r--src/contacts-settings.vala18
-rw-r--r--src/contacts-window.vala67
-rw-r--r--src/org.gnome.Contacts.gschema.xml20
3 files changed, 101 insertions, 4 deletions
diff --git a/src/contacts-settings.vala b/src/contacts-settings.vala
index 1327f2d..b2517f8 100644
--- a/src/contacts-settings.vala
+++ b/src/contacts-settings.vala
@@ -20,17 +20,27 @@
*/
public class Contacts.Settings : GLib.Settings {
+ public const string DID_INITIAL_SETUP_KEY = "did-initial-setup";
+ public const string SORT_ON_SURNAME_KEY = "sort-on-surname";
+ public const string WINDOW_WIDTH_KEY = "window-width";
+ public const string WINDOW_HEIGHT_KEY = "window-height";
+ public const string WINDOW_MAXIMIZED_KEY = "window-maximized";
+
public bool did_initial_setup {
- get { return get_boolean ("did-initial-setup"); }
- set { set_boolean ("did-initial-setup", value); }
+ get { return get_boolean (DID_INITIAL_SETUP_KEY); }
+ set { set_boolean (DID_INITIAL_SETUP_KEY, value); }
}
public bool sort_on_surname {
- get { return get_boolean ("sort-on-surname"); }
- set { set_boolean ("sort-on-surname", value); }
+ get { return get_boolean (SORT_ON_SURNAME_KEY); }
+ set { set_boolean (SORT_ON_SURNAME_KEY, value); }
}
public Settings (App app) {
Object (schema_id: app.application_id);
}
+
+ public void bind_default (string key, Object object, string property) {
+ bind (key, object, property, GLib.SettingsBindFlags.DEFAULT);
+ }
}
diff --git a/src/contacts-window.vala b/src/contacts-window.vala
index b548b46..1f493df 100644
--- a/src/contacts-window.vala
+++ b/src/contacts-window.vala
@@ -59,6 +59,18 @@ public class Contacts.Window : Gtk.ApplicationWindow {
public UiState state { get; set; default = UiState.NORMAL; }
+ /** Holds the current width. */
+ public int window_width { get; set; }
+ private const string WINDOW_WIDTH_PROP = "window-width";
+
+ /** Holds the current height. */
+ public int window_height { get; set; }
+ private const string WINDOW_HEIGHT_PROP = "window-height";
+
+ /** Holds true if the window is currently maximized. */
+ public bool window_maximized { get; set; }
+ private const string WINDOW_MAXIMIZED_PROP = "window-maximized";
+
private Settings settings;
public Store store {
@@ -80,9 +92,58 @@ public class Contacts.Window : Gtk.ApplicationWindow {
this.notify["state"].connect (on_ui_state_changed);
+ bind_dimension_properties_to_settings ();
create_contact_pane ();
set_headerbar_layout ();
connect_button_signals ();
+ restore_window_size_and_position_from_settings ();
+ }
+
+ private void restore_window_size_and_position_from_settings () {
+ var screen = get_screen();
+ if (screen != null && this.window_width <= screen.get_width () && this.window_height <= screen.get_height ()) {
+ set_default_size (this.window_width, this.window_height);
+ }
+ if (this.window_maximized) {
+ maximize();
+ }
+ // always put the window into the center position to avoid losing it somewhere at the screen boundaries.
+ this.window_position = Gtk.WindowPosition.CENTER;
+ }
+
+ public override bool window_state_event (Gdk.EventWindowState event) {
+ if ((event.new_window_state & Gdk.WindowState.WITHDRAWN) == 0) {
+ bool maximized = (
+ (event.new_window_state & Gdk.WindowState.MAXIMIZED) != 0
+ );
+ if (this.window_maximized != maximized) {
+ this.window_maximized = maximized;
+ }
+ }
+ return base.window_state_event (event);
+ }
+
+ // Called on window resize. Save window size for the next start.
+ public override void size_allocate (Gtk.Allocation allocation) {
+ base.size_allocate (allocation);
+
+ var screen = get_screen ();
+ if (screen != null && !this.window_maximized) {
+ // Get the size via ::get_size instead of the allocation
+ // so that the window isn't ever-expanding.
+ int width = 0;
+ int height = 0;
+ get_size(out width, out height);
+
+ // Only store if the values have changed and are
+ // reasonable-looking.
+ if (this.window_width != width && width > 0 && width <= screen.get_width ()) {
+ this.window_width = width;
+ }
+ if (this.window_height != height && height > 0 && height <= screen.get_height ()) {
+ this.window_height = height;
+ }
+ }
}
private void create_contact_pane () {
@@ -385,4 +446,10 @@ public class Contacts.Window : Gtk.ApplicationWindow {
add_notification (notification);
}
+
+ private void bind_dimension_properties_to_settings () {
+ this.settings.bind_default (Settings.WINDOW_WIDTH_KEY, this, WINDOW_WIDTH_PROP);
+ this.settings.bind_default (Settings.WINDOW_HEIGHT_KEY, this, WINDOW_HEIGHT_PROP);
+ this.settings.bind_default (Settings.WINDOW_MAXIMIZED_KEY, this, WINDOW_MAXIMIZED_PROP);
+ }
}
diff --git a/src/org.gnome.Contacts.gschema.xml b/src/org.gnome.Contacts.gschema.xml
index 98d2f4e..d069ee6 100644
--- a/src/org.gnome.Contacts.gschema.xml
+++ b/src/org.gnome.Contacts.gschema.xml
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
<schemalist>
<schema id="org.gnome.Contacts" path="/org/gnome/Contacts/" gettext-domain="gnome-contacts">
<key name="did-initial-setup" type="b">
@@ -13,5 +14,24 @@
Otherwise, it will be sorted on the first names of the contacts.
</description>
</key>
+ <key name="window-height" type="i">
+ <default>600</default>
+ <summary>The default height of the contacts window.</summary>
+ <description>
+ If the window size has not been changed by the user yet this will be used as the initial value for the height of the window.
+ </description>
+ </key>
+ <key name="window-width" type="i">
+ <default>800</default>
+ <summary>The default width of the contacts window.</summary>
+ <description>
+ If the window size has not been changed by the user yet this will be used as the initial value for the width of the window.
+ </description>
+ </key>
+ <key name="window-maximized" type="b">
+ <summary>Is the window maximized?</summary>
+ <description>Stores if the window is currently maximized.</description>
+ <default>false</default>
+ </key>
</schema>
</schemalist>