[ekiga/ds-gsettings] GSettings: Converted GmWindow objects to use GSettings.



commit b7f0f512f4942c0d317e72db13ea87cc12bac95f
Author: Damien Sandras <dsandras beip be>
Date:   Sun Apr 7 17:48:08 2013 +0200

    GSettings: Converted GmWindow objects to use GSettings.

 lib/ekiga-settings.h                         | 44 ++++++++++++++++
 lib/engine/gui/gtk-frontend/call-window.cpp  | 75 ++++++++--------------------
 lib/engine/gui/gtk-frontend/gtk-frontend.cpp |  7 +--
 lib/gui/gmwindow.c                           | 46 +++++++----------
 src/gui/main_window.cpp                      |  4 +-
 5 files changed, 90 insertions(+), 86 deletions(-)
---
diff --git a/lib/ekiga-settings.h b/lib/ekiga-settings.h
new file mode 100644
index 0000000..c465d6e
--- /dev/null
+++ b/lib/ekiga-settings.h
@@ -0,0 +1,44 @@
+
+/* Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2013 Damien Sandras <dsandras seconix 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, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *
+ * Ekiga is licensed under the GPL license and as a special exception,
+ * you have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination,
+ * without applying the requirements of the GNU GPL to the OPAL, OpenH323
+ * and PWLIB programs, as long as you do follow the requirements of the
+ * GNU GPL for all the rest of the software thus combined.
+ */
+
+
+/*
+ *                         ekiga-ettings.h  -  description
+ *                         -------------------------------
+ *   begin                : Sat Dec 23 2000
+ *   copyright            : (C) 2000-2013 by Damien Sandras
+ *   description          : This file defines gsettings keys
+ *
+ */
+
+
+#ifndef EKIGA_SETTINGS_H_
+#define EKIGA_SETTINGS_H_
+
+#define USER_INTERFACE "org.gnome." PACKAGE_NAME ".general.user-interface"
+
+#endif /* EKIGA_SETTINGS_H */
diff --git a/lib/engine/gui/gtk-frontend/call-window.cpp b/lib/engine/gui/gtk-frontend/call-window.cpp
index 340a730..9d336f2 100644
--- a/lib/engine/gui/gtk-frontend/call-window.cpp
+++ b/lib/engine/gui/gtk-frontend/call-window.cpp
@@ -40,6 +40,8 @@
 
 #include "config.h"
 
+#include "ekiga-settings.h"
+
 #include "call-window.h"
 
 #include "dialpad.h"
@@ -216,9 +218,6 @@ static void pick_up_call_cb (GtkWidget * /*widget*/,
 static void hang_up_call_cb (GtkWidget * /*widget*/,
                             gpointer data);
 
-static void show_window_cb (GtkWidget *widget,
-                            gpointer data);
-
 static void hold_current_call_cb (GtkWidget *widget,
                                   gpointer data);
 
@@ -600,13 +599,6 @@ hang_up_call_cb (GtkWidget * /*widget*/,
 
 
 static void
-show_window_cb (G_GNUC_UNUSED GtkWidget *widget,
-               gpointer data)
-{
-  gm_window_show (GTK_WIDGET (data));
-}
-
-static void
 hold_current_call_cb (G_GNUC_UNUSED GtkWidget *widget,
                       gpointer data)
 {
@@ -1737,15 +1729,8 @@ gm_cw_video_settings_window_new (EkigaCallWindow *cw)
   int brightness = 0, colour = 0, contrast = 0, whiteness = 0;
 
   /* Build the window */
-  window = gtk_dialog_new ();
-  g_object_set_data_full (G_OBJECT (window), "window_name",
-                         g_strdup ("video_settings_window"), g_free);
-  gtk_dialog_add_button (GTK_DIALOG (window),
-                         GTK_STOCK_CLOSE,
-                         GTK_RESPONSE_CANCEL);
-
-  gtk_window_set_title (GTK_WINDOW (window),
-                        _("Video Settings"));
+  window = gm_window_new_with_key (USER_INTERFACE ".video-settings-window");
+  gtk_window_set_title (GTK_WINDOW (window), _("Video Settings"));
 
   /* Webcam Control Frame, we need it to disable controls */
   cw->priv->video_settings_frame = gtk_frame_new (NULL);
@@ -1837,18 +1822,12 @@ gm_cw_video_settings_window_new (EkigaCallWindow *cw)
                    G_CALLBACK (video_settings_changed_cb),
                    (gpointer) cw);
 
-  gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (window))),
+  gtk_container_add (GTK_CONTAINER (window),
                      cw->priv->video_settings_frame);
   gtk_widget_show_all (cw->priv->video_settings_frame);
 
   gtk_widget_set_sensitive (GTK_WIDGET (cw->priv->video_settings_frame), false);
 
-  /* That's an usual GtkWindow, connect it to the signals */
-  g_signal_connect_swapped (window,
-                           "response",
-                           G_CALLBACK (gm_window_hide),
-                           (gpointer) window);
-
   gm_window_hide_on_delete (window);
 
   return window;
@@ -1860,27 +1839,21 @@ gm_cw_audio_settings_window_new (EkigaCallWindow *cw)
   GtkWidget *hscale_play = NULL;
   GtkWidget *hscale_rec = NULL;
   GtkWidget *hbox = NULL;
+  GtkWidget *main_vbox = NULL;
   GtkWidget *vbox = NULL;
   GtkWidget *small_vbox = NULL;
   GtkWidget *window = NULL;
 
   /* Build the window */
-  window = gtk_dialog_new ();
-  g_object_set_data_full (G_OBJECT (window), "window_name",
-                         g_strdup ("audio_settings_window"), g_free);
-  gtk_dialog_add_button (GTK_DIALOG (window),
-                         GTK_STOCK_CLOSE,
-                         GTK_RESPONSE_CANCEL);
-
-  gtk_window_set_title (GTK_WINDOW (window),
-                        _("Audio Settings"));
+  window = gm_window_new_with_key (USER_INTERFACE ".audio-settings-window");
+  gtk_window_set_title (GTK_WINDOW (window), _("Audio Settings"));
 
   /* Audio control frame, we need it to disable controls */
   cw->priv->audio_output_volume_frame = gtk_frame_new (NULL);
   gtk_frame_set_shadow_type (GTK_FRAME (cw->priv->audio_output_volume_frame),
                             GTK_SHADOW_NONE);
   gtk_container_set_border_width (GTK_CONTAINER (cw->priv->audio_output_volume_frame), 5);
-
+  main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
 
   /* The vbox */
   vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
@@ -1905,8 +1878,8 @@ gm_cw_audio_settings_window_new (EkigaCallWindow *cw)
   gtk_box_pack_start (GTK_BOX (hbox), small_vbox, true, true, 2);
   gtk_box_pack_start (GTK_BOX (vbox), hbox, false, false, 3);
 
-  gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (window))),
-                     cw->priv->audio_output_volume_frame);
+  gtk_box_pack_start (GTK_BOX (main_vbox), cw->priv->audio_output_volume_frame,
+                      false, false, 0);
   gtk_widget_show_all (cw->priv->audio_output_volume_frame);
   gtk_widget_set_sensitive (GTK_WIDGET (cw->priv->audio_output_volume_frame),  false);
 
@@ -1940,23 +1913,19 @@ gm_cw_audio_settings_window_new (EkigaCallWindow *cw)
   gtk_box_pack_start (GTK_BOX (hbox), small_vbox, true, true, 2);
   gtk_box_pack_start (GTK_BOX (vbox), hbox, false, false, 3);
 
-  gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (window))),
-                     cw->priv->audio_input_volume_frame);
+  gtk_box_pack_start (GTK_BOX (main_vbox), cw->priv->audio_input_volume_frame,
+                      false, false, 0);
   gtk_widget_show_all (cw->priv->audio_input_volume_frame);
   gtk_widget_set_sensitive (GTK_WIDGET (cw->priv->audio_input_volume_frame),  false);
 
+  gtk_container_add (GTK_CONTAINER (window), main_vbox);
+
   g_signal_connect (cw->priv->adj_output_volume, "value-changed",
                    G_CALLBACK (audio_volume_changed_cb), cw);
 
   g_signal_connect (cw->priv->adj_input_volume, "value-changed",
                    G_CALLBACK (audio_volume_changed_cb), cw);
 
-  /* That's an usual GtkWindow, connect it to the signals */
-  g_signal_connect_swapped (window,
-                           "response",
-                           G_CALLBACK (gm_window_hide),
-                           (gpointer) window);
-
   gm_window_hide_on_delete (window);
 
   g_signal_connect (window, "show",
@@ -2432,9 +2401,9 @@ ekiga_call_window_init_gui (EkigaCallWindow *cw)
                         GTK_TOOL_ITEM (item), -1);
     gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (item),
                                     _("Change the volume of your soundcard"));
-    g_signal_connect (cw->priv->audio_settings_button, "clicked",
-                      G_CALLBACK (show_window_cb),
-                      (gpointer) cw->priv->audio_settings_window);
+    g_signal_connect_swapped (cw->priv->audio_settings_button, "clicked",
+                              G_CALLBACK (gtk_widget_show),
+                              (gpointer) cw->priv->audio_settings_window);
   }
 
   /* Video Settings */
@@ -2453,9 +2422,9 @@ ekiga_call_window_init_gui (EkigaCallWindow *cw)
   gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (item),
                                   _("Change the color settings of your video device"));
 
-  g_signal_connect (cw->priv->video_settings_button, "clicked",
-                   G_CALLBACK (show_window_cb),
-                   (gpointer) cw->priv->video_settings_window);
+  g_signal_connect_swapped (cw->priv->video_settings_button, "clicked",
+                            G_CALLBACK (gtk_widget_show),
+                            (gpointer) cw->priv->video_settings_window);
 
   /* Call Pause */
   item = gtk_tool_item_new ();
@@ -2642,7 +2611,7 @@ call_window_new (Ekiga::ServiceCore & core)
   gm_conf_notifier_add (VIDEO_DISPLAY_KEY "stay_on_top",
                        stay_on_top_changed_nt, cw);
 
-  gm_window_set_key (GM_WINDOW (cw), USER_INTERFACE_KEY "call_window");
+  gm_window_set_key (GM_WINDOW (cw), USER_INTERFACE ".call-window");
   gm_window_set_hide_on_delete (GM_WINDOW (cw), false);
   gm_window_set_hide_on_escape (GM_WINDOW (cw), false);
 
diff --git a/lib/engine/gui/gtk-frontend/gtk-frontend.cpp b/lib/engine/gui/gtk-frontend/gtk-frontend.cpp
index f8f86f6..53eb4ab 100644
--- a/lib/engine/gui/gtk-frontend/gtk-frontend.cpp
+++ b/lib/engine/gui/gtk-frontend/gtk-frontend.cpp
@@ -41,6 +41,7 @@
 #include <gtk/gtk.h>
 
 #include "config.h"
+#include "ekiga-settings.h"
 
 #include "gtk-frontend.h"
 
@@ -105,10 +106,10 @@ void GtkFrontend::build ()
   boost::shared_ptr<Ekiga::ChatCore> chat_core = core.get<Ekiga::ChatCore> ("chat-core");
 
   addressbook_window =
-    addressbook_window_new_with_key (*contact_core, "/apps/" PACKAGE_NAME 
"/general/user_interface/addressbook_window");
-  accounts_window = accounts_window_new_with_key (core, "/apps/" PACKAGE_NAME 
"/general/user_interface/accounts_window");
+    addressbook_window_new_with_key (*contact_core, USER_INTERFACE ".addressbook-window");
+  accounts_window = accounts_window_new_with_key (core, USER_INTERFACE ".accounts-window");
   call_window = call_window_new (core);
-  chat_window = chat_window_new (core, "/apps/" PACKAGE_NAME "/general/user_interface/chat_window");
+  chat_window = chat_window_new (core, USER_INTERFACE ".chat-window");
   preferences_window = preferences_window_new (core);
   status_icon = status_icon_new (core);
 }
diff --git a/lib/gui/gmwindow.c b/lib/gui/gmwindow.c
index 28fd6ba..4417fc3 100644
--- a/lib/gui/gmwindow.c
+++ b/lib/gui/gmwindow.c
@@ -39,7 +39,6 @@
 #include "config.h"
 
 #include "gmwindow.h"
-
 #include "gmconf.h"
 
 #include <gdk/gdkkeysyms.h>
@@ -52,6 +51,7 @@
 struct _GmWindowPrivate
 {
   GtkAccelGroup *accel;
+  GSettings *settings;
   gboolean hide_on_esc;
   gboolean hide_on_delete;
   gchar *key;
@@ -93,12 +93,16 @@ gm_window_configure_event (GtkWidget *widget,
 static void
 gm_window_finalize (GObject *obj)
 {
-  GmWindow *window = NULL;
+  GmWindow *self = NULL;
 
-  window = GM_WINDOW (obj);
+  self = GM_WINDOW (obj);
 
-  g_free (window->priv->key);
-  window->priv->key = NULL;
+  g_free (self->priv->key);
+  self->priv->key = NULL;
+
+  if (self->priv->settings)
+    g_clear_object (&self->priv->settings);
+  self->priv->settings = NULL;
 
   G_OBJECT_CLASS (gm_window_parent_class)->finalize (obj);
 }
@@ -155,6 +159,9 @@ gm_window_set_property (GObject *obj,
       g_free (self->priv->key);
     str = g_value_get_string (value);
     self->priv->key = g_strdup (str ? str : "");
+    if (self->priv->settings)
+      g_clear_object (&self->priv->settings);
+    self->priv->settings = g_settings_new (self->priv->key);
     break;
 
   case GM_HIDE_ON_ESC:
@@ -207,6 +214,7 @@ static void
 gm_window_init (GmWindow* self)
 {
   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GM_TYPE_WINDOW, GmWindowPrivate);
+  self->priv->settings = NULL;
   self->priv->key = g_strdup ("");
   self->priv->hide_on_esc = TRUE;
   self->priv->hide_on_delete = TRUE;
@@ -269,8 +277,6 @@ window_show_cb (GtkWidget *w,
 
   GmWindow *self = NULL;
 
-  gchar *conf_key_size = NULL;
-  gchar *conf_key_position = NULL;
   gchar *size = NULL;
   gchar *position = NULL;
   gchar **couple = NULL;
@@ -279,14 +285,9 @@ window_show_cb (GtkWidget *w,
 
   g_return_if_fail (g_strcmp0 (self->priv->key, ""));
 
-  conf_key_position =
-    g_strdup_printf ("%s/position", self->priv->key);
-  conf_key_size =
-    g_strdup_printf ("%s/size", self->priv->key);
-
   if (gtk_window_get_resizable (GTK_WINDOW (w))) {
 
-    size = gm_conf_get_string (conf_key_size);
+    size = g_settings_get_string (self->priv->settings, "size");
     if (size)
       couple = g_strsplit (size, ",", 0);
 
@@ -303,7 +304,7 @@ window_show_cb (GtkWidget *w,
     g_free (size);
   }
 
-  position = gm_conf_get_string (conf_key_position);
+  position = g_settings_get_string (self->priv->settings, "position");
   if (position)
     couple = g_strsplit (position, ",", 0);
 
@@ -320,9 +321,6 @@ window_show_cb (GtkWidget *w,
   g_free (position);
 
   gtk_widget_realize (GTK_WIDGET (w));
-
-  g_free (conf_key_position);
-  g_free (conf_key_size);
 }
 
 
@@ -332,8 +330,6 @@ window_hide_cb (GtkWidget *w,
 {
   GmWindow *self = NULL;
 
-  gchar *conf_key_size = NULL;
-  gchar *conf_key_position = NULL;
   gchar *size = NULL;
   gchar *position = NULL;
 
@@ -343,24 +339,16 @@ window_hide_cb (GtkWidget *w,
 
   g_return_if_fail (g_strcmp0 (self->priv->key, ""));
 
-  conf_key_position =
-    g_strdup_printf ("%s/position", self->priv->key);
-  conf_key_size =
-    g_strdup_printf ("%s/size", self->priv->key);
-
   position = g_strdup_printf ("%d,%d", self->priv->x, self->priv->y);
-  gm_conf_set_string (conf_key_position, position);
+  g_settings_set_string (self->priv->settings, "position", position);
   g_free (position);
 
   if (gtk_window_get_resizable (GTK_WINDOW (w))) {
 
     size = g_strdup_printf ("%d,%d", self->priv->width, self->priv->height);
-    gm_conf_set_string (conf_key_size, size);
+    g_settings_set_string (self->priv->settings, "size", size);
     g_free (size);
   }
-
-  g_free (conf_key_position);
-  g_free (conf_key_size);
 }
 
 
diff --git a/src/gui/main_window.cpp b/src/gui/main_window.cpp
index 14f43da..a75729e 100644
--- a/src/gui/main_window.cpp
+++ b/src/gui/main_window.cpp
@@ -37,6 +37,8 @@
 
 #include "config.h"
 
+#include "ekiga-settings.h"
+
 #include "main_window.h"
 
 #include "ekiga.h"
@@ -1707,7 +1709,7 @@ gm_main_window_new (Ekiga::ServiceCore & core)
 
   /* basic gtk+ setup  */
   mw = EKIGA_MAIN_WINDOW (g_object_new (EKIGA_TYPE_MAIN_WINDOW, NULL));
-  gm_window_set_key (GM_WINDOW (mw), USER_INTERFACE_KEY "main_window");
+  gm_window_set_key (GM_WINDOW (mw), USER_INTERFACE ".main-window");
 
   /* fetching needed engine objects */
 


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