[easytag/wip/gsettings: 13/31] Store CDDB window location in GSettings



commit 6b3c55608136f1e4f657d3e816965dff7bae7ff3
Author: David King <amigadave amigadave com>
Date:   Sun Mar 3 10:21:10 2013 +0000

    Store CDDB window location in GSettings

 src/cddb.c    |   53 ++++++++++++++++++++++++++++++++++-------------------
 src/setting.c |   11 -----------
 src/setting.h |    6 ------
 3 files changed, 34 insertions(+), 36 deletions(-)
---
diff --git a/src/cddb.c b/src/cddb.c
index d294d5a..a79b158 100644
--- a/src/cddb.c
+++ b/src/cddb.c
@@ -240,8 +240,14 @@ void Open_Cddb_Window (void)
     gtk_window_set_title(GTK_WINDOW(CddbWindow),_("CD Database Search"));
     gtk_window_set_position(GTK_WINDOW(CddbWindow),GTK_WIN_POS_CENTER);
 
-    // This part is needed to set correctly the position of handle panes
-    gtk_window_set_default_size(GTK_WINDOW(CddbWindow),CDDB_WINDOW_WIDTH,CDDB_WINDOW_HEIGHT);
+    /* This part is needed to correctly set the position of handle panes. */
+    {
+        gint width, height;
+
+        g_settings_get (ETSettings, "cddb-location", "(iiii)", NULL, NULL,
+                        &width, &height);
+        gtk_window_set_default_size (GTK_WINDOW (CddbWindow), width, height);
+    }
 
     g_signal_connect(G_OBJECT(CddbWindow),"delete_event", G_CALLBACK(Cddb_Destroy_Window),NULL);
     g_signal_connect(G_OBJECT(CddbWindow),"key_press_event", G_CALLBACK(Cddb_Window_Key_Press),NULL);
@@ -637,7 +643,9 @@ void Open_Cddb_Window (void)
      */
     CddbWindowHPaned = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
     gtk_box_pack_start(GTK_BOX(VBox),CddbWindowHPaned,TRUE,TRUE,0);
-    gtk_paned_set_position(GTK_PANED(CddbWindowHPaned),CDDB_PANE_HANDLE_POSITION);
+    gtk_paned_set_position (GTK_PANED (CddbWindowHPaned),
+                            g_settings_get_uint (ETSettings,
+                                                 "cddb-pane-position"));
 
     // List of albums
     ScrollWindow = gtk_scrolled_window_new(NULL, NULL);
@@ -844,12 +852,19 @@ void Open_Cddb_Window (void)
     CddbStopSearch = FALSE;
 
     gtk_widget_show_all(CddbWindow);
-    if (g_settings_get_boolean (ETSettings, "cddb-remember-location")
-    && CDDB_WINDOW_X > 0 && CDDB_WINDOW_Y > 0)
+    if (g_settings_get_boolean (ETSettings, "cddb-remember-location"))
     {
-        gtk_window_move(GTK_WINDOW(CddbWindow),CDDB_WINDOW_X,CDDB_WINDOW_Y);
+        gint x, y;
+
+        g_settings_get (ETSettings, "cddb-location", "(iiii)", &x, &y, NULL,
+                        NULL);
+        if (x > 0 && y > 0)
+        {
+            gtk_window_move (GTK_WINDOW (CddbWindow), x, y);
+        }
     }
-    // Force resize window
+
+    /* Force resize window. */
     gtk_widget_get_allocation(GTK_WIDGET(CddbSearchInAllCategories), &allocation);
     gtk_widget_set_size_request(GTK_WIDGET(CddbSearchInAllFields), allocation.width, -1);
     g_signal_emit_by_name(G_OBJECT(CddbShowCategoriesButton),"toggled");
@@ -897,24 +912,24 @@ void Cddb_Window_Apply_Changes (void)
 {
     if (CddbWindow)
     {
-        gint x, y, width, height;
         GdkWindow *window;
 
         window = gtk_widget_get_window(CddbWindow);
 
         if ( window && gdk_window_is_visible(window) && 
gdk_window_get_state(window)!=GDK_WINDOW_STATE_MAXIMIZED )
         {
-            // Position and Origin of the window
-            gdk_window_get_root_origin(window,&x,&y);
-            CDDB_WINDOW_X = x;
-            CDDB_WINDOW_Y = y;
-            width = gdk_window_get_width(window);
-            height = gdk_window_get_height(window);
-            CDDB_WINDOW_WIDTH  = width;
-            CDDB_WINDOW_HEIGHT = height;
-
-            // Handle panes position
-            CDDB_PANE_HANDLE_POSITION = gtk_paned_get_position(GTK_PANED(CddbWindowHPaned));
+            gint x, y, width, height;
+
+            /* Position and Origin of the window. */
+            gdk_window_get_root_origin (window, &x, &y);
+            width = gdk_window_get_width (window);
+            height = gdk_window_get_height (window);
+            g_settings_set (ETSettings, "cddb-location", "(iiii)", x, y, width,
+                            height);
+
+            /* Handle pane position. */
+            g_settings_set_uint (ETSettings, "cddb-pane-position",
+                                 gtk_paned_get_position (GTK_PANED (CddbWindowHPaned)));
         }
 
         CDDB_SEARCH_IN_ARTIST_FIELD     = 
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(CddbSearchInArtistField));
diff --git a/src/setting.c b/src/setting.c
index b8c1467..c06760e 100644
--- a/src/setting.c
+++ b/src/setting.c
@@ -173,11 +173,6 @@ tConfigVariable Config_Variables[] =
     {"load_file_window_height",                 CV_TYPE_INT,     &LOAD_FILE_WINDOW_HEIGHT                },
 
     {"cddb_local_path",                         CV_TYPE_STRING,  &CDDB_LOCAL_PATH                        },
-    {"cddb_window_x",                           CV_TYPE_INT,     &CDDB_WINDOW_X                          },
-    {"cddb_window_y",                           CV_TYPE_INT,     &CDDB_WINDOW_Y                          },
-    {"cddb_window_height",                      CV_TYPE_INT,     &CDDB_WINDOW_HEIGHT                     },
-    {"cddb_window_width",                       CV_TYPE_INT,     &CDDB_WINDOW_WIDTH                      },
-    {"cddb_pane_handle_position",               CV_TYPE_INT,     &CDDB_PANE_HANDLE_POSITION              },
 
     {"cddb_search_in_artist_field",             CV_TYPE_BOOL,    &CDDB_SEARCH_IN_ARTIST_FIELD            },
     {"cddb_search_in_title_field",              CV_TYPE_BOOL,    &CDDB_SEARCH_IN_TITLE_FIELD             },
@@ -347,12 +342,6 @@ void Init_Config_Variables (void)
      */
     CDDB_LOCAL_PATH                         = NULL;
 
-    CDDB_WINDOW_X                 = -1;
-    CDDB_WINDOW_Y                 = -1;
-    CDDB_WINDOW_WIDTH             = 660;
-    CDDB_WINDOW_HEIGHT            = 470;
-    CDDB_PANE_HANDLE_POSITION     = 350;
-
     CDDB_SEARCH_IN_ARTIST_FIELD         = 1;
     CDDB_SEARCH_IN_TITLE_FIELD          = 1;
     CDDB_SEARCH_IN_TRACK_NAME_FIELD     = 0;
diff --git a/src/setting.h b/src/setting.h
index ad6492b..d4b3cf6 100644
--- a/src/setting.h
+++ b/src/setting.h
@@ -129,12 +129,6 @@ gint    LOAD_FILE_WINDOW_HEIGHT;
 /* CDDB in preferences window */
 gchar  *CDDB_LOCAL_PATH;
 
-gint    CDDB_WINDOW_X;
-gint    CDDB_WINDOW_Y;
-gint    CDDB_WINDOW_HEIGHT;
-gint    CDDB_WINDOW_WIDTH;
-gint    CDDB_PANE_HANDLE_POSITION;
-
 /* CDDB window */
 gint    CDDB_SEARCH_IN_ARTIST_FIELD;
 gint    CDDB_SEARCH_IN_TITLE_FIELD;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]