[ekiga/ds-gsettings2: 24/33] Moved most of video devices keys to GSettings.



commit ce8bf9af0c7e33bf45ef4da499c11eef4a5f6f89
Author: Damien Sandras <dsandras beip be>
Date:   Sun May 5 17:50:25 2013 +0200

    Moved most of video devices keys to GSettings.
    
    Also rewrote a part of the VideoInputCore to make it more robust.
    
    This work is unfinished unfortunately.

 lib/ekiga-settings.h                               |    1 +
 lib/engine/engine.cpp                              |    3 +-
 lib/engine/gui/gtk-frontend/call-window.cpp        |    5 +-
 lib/engine/gui/gtk-frontend/main_window.cpp        |   84 +++---
 lib/engine/gui/gtk-frontend/preferences-window.cpp |  297 +++++++++++++-------
 lib/engine/videoinput/videoinput-core.cpp          |  151 +++++++++--
 lib/engine/videoinput/videoinput-core.h            |   19 +-
 lib/engine/videoinput/videoinput-gmconf-bridge.cpp |   62 ----
 8 files changed, 388 insertions(+), 234 deletions(-)
---
diff --git a/lib/ekiga-settings.h b/lib/ekiga-settings.h
index 8dc05fc..a0cf2b7 100644
--- a/lib/ekiga-settings.h
+++ b/lib/ekiga-settings.h
@@ -46,6 +46,7 @@
 
 #define SOUND_EVENTS_SCHEMA "org.gnome." PACKAGE_NAME ".general.sound-events"
 #define AUDIO_DEVICES_SCHEMA "org.gnome." PACKAGE_NAME ".devices.audio"
+#define VIDEO_DEVICES_SCHEMA "org.gnome." PACKAGE_NAME ".devices.video"
 
 namespace Ekiga {
 
diff --git a/lib/engine/engine.cpp b/lib/engine/engine.cpp
index 6536f77..b2be0f7 100644
--- a/lib/engine/engine.cpp
+++ b/lib/engine/engine.cpp
@@ -198,7 +198,8 @@ engine_init (Ekiga::ServiceCorePtr service_core,
    */
 
   videooutput_core->setup_conf_bridge();
-  videoinput_core->setup_conf_bridge();
+  videoinput_core->setup_conf_bridge ();
+  videoinput_core->setup ("any");
   audioinput_core->setup ();
   audiooutput_core->setup ();
 
diff --git a/lib/engine/gui/gtk-frontend/call-window.cpp b/lib/engine/gui/gtk-frontend/call-window.cpp
index 827d144..0c091fe 100644
--- a/lib/engine/gui/gtk-frontend/call-window.cpp
+++ b/lib/engine/gui/gtk-frontend/call-window.cpp
@@ -1350,6 +1350,7 @@ ekiga_call_window_delete_event_cb (GtkWidget *widget,
                                    G_GNUC_UNUSED GdkEventAny *event)
 {
   EkigaCallWindow *cw = NULL;
+  GSettings *settings = NULL;
 
   cw = EKIGA_CALL_WINDOW (widget);
   g_return_val_if_fail (EKIGA_IS_CALL_WINDOW (cw), false);
@@ -1359,7 +1360,9 @@ ekiga_call_window_delete_event_cb (GtkWidget *widget,
     cw->priv->current_call->hang_up ();
   }
   else {
-    gm_conf_set_bool (VIDEO_DEVICES_KEY "enable_preview", false);
+    settings = g_settings_new (VIDEO_DEVICES_SCHEMA);
+    g_settings_set_boolean (settings, "enable-preview", false);
+    g_clear_object (&settings);
   }
 
   return true; // Do not relay the event anymore
diff --git a/lib/engine/gui/gtk-frontend/main_window.cpp b/lib/engine/gui/gtk-frontend/main_window.cpp
index 8888af9..2ecec98 100644
--- a/lib/engine/gui/gtk-frontend/main_window.cpp
+++ b/lib/engine/gui/gtk-frontend/main_window.cpp
@@ -149,6 +149,7 @@ struct _EkigaMainWindowPrivate
   std::list<gpointer> notifiers;
 
   GSettings *sound_events_settings;
+  GSettings *video_devices_settings;
 };
 
 /* channel types */
@@ -216,9 +217,9 @@ static void panel_section_changed_nt (gpointer id,
  * BEHAVIOR     :  Show / hide the call window.
  * PRE          :  /
  */
-static void video_preview_changed_nt (gpointer id,
-                                      GmConfEntry *entry,
-                                      gpointer data);
+static void video_preview_changed (GSettings *settings,
+                                   gchar *key,
+                                   gpointer data);
 
 /** Pull a trigger from a Ekiga::Service
  *
@@ -669,7 +670,8 @@ on_delayed_hide_call_window_cb (gpointer data)
 
       GtkWidget* call_window = GTK_WIDGET (gtk_frontend->get_call_window ());
 
-      if (!mw->priv->current_call && !gm_conf_get_bool (VIDEO_DEVICES_KEY "enable_preview"))
+      if (!mw->priv->current_call
+          && !g_settings_get_boolean (mw->priv->video_devices_settings, "enable-preview"))
        gtk_widget_hide (GTK_WIDGET (call_window));
     }
 
@@ -835,39 +837,35 @@ panel_section_changed_nt (G_GNUC_UNUSED gpointer id,
 
 
 static void
-video_preview_changed_nt (G_GNUC_UNUSED gpointer id,
-                          GmConfEntry *entry,
-                          gpointer data)
+video_preview_changed (GSettings *settings,
+                       gchar *key,
+                       gpointer data)
 {
   g_return_if_fail (EKIGA_IS_MAIN_WINDOW (data));
 
-  if (gm_conf_entry_get_type (entry) == GM_CONF_BOOL) {
+  EkigaMainWindow* mw = EKIGA_MAIN_WINDOW (data);
+  GtkWidget *menu_item = NULL;
 
-    EkigaMainWindow* mw = EKIGA_MAIN_WINDOW (data);
-    GtkWidget *menu_item = NULL;
-
-    if (gm_conf_entry_get_type (entry) == GM_CONF_BOOL) {
-      if (mw->priv->calling_state == Standby) {
-
-       boost::shared_ptr<GtkFrontend> gtk_frontend = mw->priv->gtk_frontend.lock ();
-       if (gtk_frontend) {
-
-         GtkWidget *call_window = GTK_WIDGET (gtk_frontend->get_call_window ());
-         if (!gm_conf_entry_get_bool (entry))
-           gtk_widget_hide (call_window);
-         else
-           gtk_widget_show (call_window);
-       }
-        g_signal_handlers_block_by_func (mw->priv->preview_button,
-                                         (gpointer) video_preview_action_toggled_cb, mw);
-        menu_item = gtk_menu_get_widget (mw->priv->main_menu, "preview");
-        gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item), gm_conf_entry_get_bool (entry));
-        gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (mw->priv->preview_button),
-                                           gm_conf_entry_get_bool (entry));
-        g_signal_handlers_unblock_by_func (mw->priv->preview_button,
-                                           (gpointer) video_preview_action_toggled_cb, mw);
-      }
+  if (mw->priv->calling_state == Standby) {
+
+    bool toggled = g_settings_get_boolean (settings, key);
+    boost::shared_ptr<GtkFrontend> gtk_frontend = mw->priv->gtk_frontend.lock ();
+    if (gtk_frontend) {
+
+      GtkWidget *call_window = GTK_WIDGET (gtk_frontend->get_call_window ());
+      if (!toggled)
+        gtk_widget_hide (call_window);
+      else
+        gtk_widget_show (call_window);
     }
+    g_signal_handlers_block_by_func (mw->priv->preview_button,
+                                     (gpointer) video_preview_action_toggled_cb, mw);
+    menu_item = gtk_menu_get_widget (mw->priv->main_menu, "preview");
+    gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item), toggled);
+    gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (mw->priv->preview_button),
+                                       toggled);
+    g_signal_handlers_unblock_by_func (mw->priv->preview_button,
+                                       (gpointer) video_preview_action_toggled_cb, mw);
   }
 }
 
@@ -904,9 +902,14 @@ panel_section_action_clicked_cb (GtkWidget * /*widget*/,
 
 static void
 video_preview_action_toggled_cb (GtkToggleToolButton *b,
-                                 G_GNUC_UNUSED gpointer data)
+                                 gpointer data)
 {
-  gm_conf_set_bool (VIDEO_DEVICES_KEY "enable_preview", gtk_toggle_tool_button_get_active (b));
+  if (g_settings_get_boolean (EKIGA_MAIN_WINDOW (data)->priv->video_devices_settings,
+                              "enable-preview")
+      != gtk_toggle_tool_button_get_active (b))
+    g_settings_set_boolean (EKIGA_MAIN_WINDOW (data)->priv->video_devices_settings,
+                            "enable-preview",
+                            gtk_toggle_tool_button_get_active (b));
 }
 
 
@@ -1182,7 +1185,8 @@ ekiga_main_window_init_menu (EkigaMainWindow *mw)
   /* Default values */
   cps = (PanelSection) gm_conf_get_int (USER_INTERFACE_KEY "main_window/panel_section");
   show_offline_contacts = gm_conf_get_bool (CONTACTS_KEY "show_offline_contacts");
-  enable_preview = gm_conf_get_bool (VIDEO_DEVICES_KEY "enable_preview");
+  enable_preview = g_settings_get_boolean (mw->priv->video_devices_settings,
+                                           "enable-preview");
 
   static MenuEntry gnomemeeting_menu [] =
     {
@@ -1247,6 +1251,7 @@ ekiga_main_window_init_menu (EkigaMainWindow *mw)
 
       GTK_MENU_NEW(_("_View")),
 
+      //FIXME GSETTINGS MENU
       GTK_MENU_TOGGLE_ENTRY("preview", _("_Video Preview"),
                             _("Display images from your camera device"),
                             NULL, 0,
@@ -1464,6 +1469,7 @@ ekiga_main_window_init (EkigaMainWindow *mw)
   mw->priv->calling_state = Standby;
 
   mw->priv->sound_events_settings = g_settings_new (SOUND_EVENTS_SCHEMA);
+  mw->priv->video_devices_settings = g_settings_new (VIDEO_DEVICES_SCHEMA);
 
   for (int i = 0 ; i < NUM_SECTIONS ; i++)
     mw->priv->toggle_buttons[i] = NULL;
@@ -1474,10 +1480,9 @@ ekiga_main_window_init (EkigaMainWindow *mw)
     gm_conf_notifier_add (USER_INTERFACE_KEY "main_window/panel_section",
                          panel_section_changed_nt, mw);
   mw->priv->notifiers.push_front (notifier);
-  notifier =
-    gm_conf_notifier_add (VIDEO_DEVICES_KEY "enable_preview",
-                         video_preview_changed_nt, mw);
-  mw->priv->notifiers.push_front (notifier);
+
+  g_signal_connect (mw->priv->video_devices_settings, "changed::enable-preview",
+                    G_CALLBACK (video_preview_changed), mw);
 }
 
 static GObject *
@@ -1513,6 +1518,7 @@ ekiga_main_window_dispose (GObject* gobject)
   }
 
   g_clear_object (&mw->priv->sound_events_settings);
+  g_clear_object (&mw->priv->video_devices_settings);
 
   G_OBJECT_CLASS (ekiga_main_window_parent_class)->dispose (gobject);
 }
diff --git a/lib/engine/gui/gtk-frontend/preferences-window.cpp 
b/lib/engine/gui/gtk-frontend/preferences-window.cpp
index 58218f8..0748d09 100644
--- a/lib/engine/gui/gtk-frontend/preferences-window.cpp
+++ b/lib/engine/gui/gtk-frontend/preferences-window.cpp
@@ -80,6 +80,7 @@ typedef struct _GmPreferencesWindow
   boost::shared_ptr<Ekiga::AudioOutputCore> audiooutput_core;
   GSettings *sound_events_settings;
   GSettings *audio_devices_settings;
+  GSettings *video_devices_settings;
   Ekiga::scoped_connections connections;
 } GmPreferencesWindow;
 
@@ -89,12 +90,14 @@ _GmPreferencesWindow::_GmPreferencesWindow(Ekiga::ServiceCore &_core): core(_cor
 {
   sound_events_settings = g_settings_new (SOUND_EVENTS_SCHEMA);
   audio_devices_settings = g_settings_new (AUDIO_DEVICES_SCHEMA);
+  video_devices_settings = g_settings_new (VIDEO_DEVICES_SCHEMA);
 }
 
 _GmPreferencesWindow::~_GmPreferencesWindow()
 {
   g_clear_object (&sound_events_settings);
   g_clear_object (&audio_devices_settings);
+  g_clear_object (&video_devices_settings);
 }
 
 enum {
@@ -232,6 +235,8 @@ static void gm_pw_init_video_codecs_page (GtkWidget *prefs_window,
                                           GtkWidget *container);
 
 
+// FIXME: I'm sure the int and string option menus could be merged together...
+
 /* DESCRIPTION  :  /
  * BEHAVIOR     :  Creates a GtkOptionMenu associated with a string config
  *                 key and returns the result.
@@ -251,6 +256,24 @@ static GtkWidget *gm_pw_string_option_menu_new (GtkWidget *,
 
 
 /* DESCRIPTION  :  /
+ * BEHAVIOR     :  Creates a GtkOptionMenu associated with an int config
+ *                 key and returns the result.
+ *                 The first parameter is the section in which the GtkEntry
+ *                 should be attached. The other parameters are the text label,
+ *                 the possible values for the menu, the config key, the
+ *                 tooltip, the row where to attach it in the section.
+ * PRE          :  The array ends with NULL.
+ */
+static GtkWidget *gm_pw_int_option_menu_new (GtkWidget *table,
+                                             const gchar *label_txt,
+                                             const gchar **options,
+                                             GSettings *settings,
+                                             const gchar *conf_key,
+                                             const gchar *tooltip,
+                                             int row);
+
+
+/* DESCRIPTION  :  /
  * BEHAVIOR     :  Updates the content of a GtkOptionMenu associated with
  *                 a string config key. The first parameter is the menu,
  *                 the second is the array of possible values, and the
@@ -344,7 +367,6 @@ static void string_option_setting_changed (GSettings *settings,
                                            gchar *key,
                                            gpointer data);
 
-<<<<<<< HEAD
 /* DESCRIPTION  :  This callback is called by the preview-play button of the
  *                selected audio file in the audio file selector.
  * BEHAVIOR     :  GMSoundEv's the audio file.
@@ -352,7 +374,13 @@ static void string_option_setting_changed (GSettings *settings,
  */
 static void audioev_filename_browse_play_cb (GtkWidget *playbutton,
                                              gpointer data);
-=======
+static void int_option_menu_changed (GtkWidget *option_menu,
+                                     gpointer data);
+
+static void int_option_setting_changed (GSettings *settings,
+                                        gchar *key,
+                                        gpointer data);
+
 static void
 gm_prefs_window_get_audiooutput_devices_list (Ekiga::ServiceCore& core,
                                         std::vector<std::string> & device_list);
@@ -363,7 +391,6 @@ gm_prefs_window_get_audioinput_devices_list (Ekiga::ServiceCore& core,
 
 gchar**
 gm_prefs_window_convert_string_list (const std::vector<std::string> & list);
->>>>>>> GSettings: Ported the sound events part of the preferences window.
 
 void 
 gm_prefs_window_update_devices_list (GtkWidget *prefs_window);
@@ -896,7 +923,6 @@ gm_prefs_window_convert_string_list (const std::vector<std::string> & list)
 
 
 static void
->>>>>>> GSettings: Migrated sound events, audio output and audio input settins.
 gm_pw_init_video_devices_page (GtkWidget *prefs_window,
                                GtkWidget *container)
 {
@@ -947,15 +973,15 @@ gm_pw_init_video_devices_page (GtkWidget *prefs_window,
   get_videoinput_devices (pw->videoinput_core, device_list);
   array = vector_of_string_to_array (device_list);
   pw->video_device =
-    gnome_prefs_string_option_menu_new (subsection, _("Input device:"), (const gchar **)array, 
VIDEO_DEVICES_KEY "input_device", _("Select the video input device to use. If an error occurs when using this 
device a test picture will be transmitted."), 0, NULL);
+    gm_pw_string_option_menu_new (subsection, _("Input device:"), (const gchar **)array, 
pw->video_devices_settings, "input-device", _("Select the video input device to use. If an error occurs when 
using this device a test picture will be transmitted."), 0);
   g_free (array);
 
   /* Video Channel */
   gnome_prefs_spin_new (subsection, _("Channel:"), VIDEO_DEVICES_KEY "channel", _("The video channel number 
to use (to select camera, tv or other sources)"), 0.0, 10.0, 1.0, 3, 3, NULL, false);
 
-  gnome_prefs_int_option_menu_new (subsection, _("Size:"), (const gchar**)video_size, VIDEO_DEVICES_KEY 
"size", _("Select the transmitted video size"), 1);
+  gm_pw_int_option_menu_new (subsection, _("Size:"), (const gchar**)video_size, pw->video_devices_settings, 
"size", _("Select the transmitted video size"), 1);
 
-  gnome_prefs_int_option_menu_new (subsection, _("Format:"), video_format, VIDEO_DEVICES_KEY "format", 
_("Select the format for video cameras (does not apply to most USB cameras)"), 2);
+  gm_pw_int_option_menu_new (subsection, _("Format:"), video_format, pw->video_devices_settings, "format", 
_("Select the format for video cameras (does not apply to most USB cameras)"), 2);
 
   /* That button will refresh the device list */
   gm_pw_add_update_button (container, _("_Detect devices"), G_CALLBACK (refresh_devices_list_cb), _("Click 
here to refresh the device list"), 1, prefs_window);
@@ -1124,6 +1150,96 @@ gm_pw_string_option_menu_new (GtkWidget *table,
 }
 
 
+GtkWidget *
+gm_pw_int_option_menu_new (GtkWidget *table,
+                           const gchar *label_txt,
+                           const gchar **options,
+                           GSettings *settings,
+                           const gchar *conf_key,
+                           const gchar *tooltip,
+                           int row)
+{
+  GtkWidget *label = NULL;
+  GtkWidget *option_menu = NULL;
+
+  GtkListStore *list_store = NULL;
+  GtkCellRenderer *renderer = NULL;
+  GtkTreeIter iter;
+
+  gchar *signal_name = NULL;
+  gboolean writable = FALSE;
+
+  int history = -1;
+  int cpt = 0;
+
+  writable = g_settings_is_writable (settings, conf_key);
+
+  label = gtk_label_new_with_mnemonic (label_txt);
+  if (!writable)
+    gtk_widget_set_sensitive (GTK_WIDGET (label), FALSE);
+
+  gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row+1,
+                    (GtkAttachOptions) (GTK_FILL),
+                    (GtkAttachOptions) (GTK_FILL),
+                    0, 0);
+
+  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+  gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
+
+  list_store = gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
+  option_menu = gtk_combo_box_new_with_model (GTK_TREE_MODEL (list_store));
+  if (!writable)
+    gtk_widget_set_sensitive (GTK_WIDGET (option_menu), FALSE);
+  renderer = gtk_cell_renderer_text_new ();
+  gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (option_menu), renderer, FALSE);
+  gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (option_menu), renderer,
+                                  "text", COLUMN_STRING_TRANSLATED,
+                                  NULL);
+  g_object_set (G_OBJECT (renderer),
+                "ellipsize-set", TRUE,
+                "ellipsize", PANGO_ELLIPSIZE_END,
+                "width-chars", 30, NULL);
+  gtk_label_set_mnemonic_widget (GTK_LABEL (label), option_menu);
+
+  history = g_settings_get_int (settings, conf_key);
+  while (options [cpt]) {
+
+    gtk_list_store_append (GTK_LIST_STORE (list_store), &iter);
+    gtk_list_store_set (GTK_LIST_STORE (list_store), &iter,
+                        COLUMN_STRING_RAW, options [cpt],
+                        COLUMN_STRING_TRANSLATED, gettext (options [cpt]),
+                        COLUMN_GSETTINGS, settings,
+                        -1);
+    cpt++;
+  }
+
+  gtk_combo_box_set_active (GTK_COMBO_BOX (option_menu), history);
+  gtk_table_attach (GTK_TABLE (table), option_menu, 1, 2, row, row+1,
+                    (GtkAttachOptions) (GTK_FILL),
+                    (GtkAttachOptions) (GTK_FILL),
+                    0, 0);
+
+  if (tooltip)
+    gtk_widget_set_tooltip_text (option_menu, tooltip);
+
+  /* Update configuration when the user changes the selected option */
+  g_signal_connect (option_menu, "changed",
+                   G_CALLBACK (int_option_menu_changed),
+                   (gpointer) conf_key);
+
+  /* Update the widget when the user changes the configuration */
+  signal_name = g_strdup_printf ("changed::%s", conf_key);
+  g_signal_connect (settings, signal_name,
+                    G_CALLBACK (int_option_setting_changed), option_menu);
+  g_free (signal_name);
+
+  gtk_widget_show_all (table);
+
+  return option_menu;
+}
+
+
+
 void
 gm_pw_string_option_menu_update (GtkWidget *option_menu,
                                  const gchar **options,
@@ -1197,7 +1313,7 @@ refresh_devices_list_cb (G_GNUC_UNUSED GtkWidget *widget,
   g_return_if_fail (data != NULL);
   GtkWidget *prefs_window = GTK_WIDGET (data);
 
-  gm_prefs_window_update_devices_list(prefs_window);
+  gm_prefs_window_update_devices_list (prefs_window);
 }
 
 
@@ -1346,22 +1462,12 @@ sound_event_play_cb (G_GNUC_UNUSED GtkWidget *widget,
 
     gtk_tree_model_get (GTK_TREE_MODEL (model), &selected_iter, 2, &key, -1);
 
-<<<<<<< HEAD
-=======
     sound_event = g_settings_get_string (pw->sound_events_settings, key);
-    boost::shared_ptr<Ekiga::AudioOutputCore> audiooutput_core =
-      pw->core.get<Ekiga::AudioOutputCore> ("audiooutput-core");
-
->>>>>>> GSettings: Ported the sound events part of the preferences window.
     if (sound_event) {
-<<<<<<< HEAD
-      pw->audiooutput_core->play_event(sound_event);
-=======
       if (!g_path_is_absolute (sound_event))
-        audiooutput_core->play_event(sound_event);
+       pw->audiooutput_core->play_event(sound_event);
       else
-        audiooutput_core->play_file(sound_event);
->>>>>>> GmPrefs: Fixed sound event playing if full filename is provided.
+        pw->audiooutput_core->play_file(sound_event);
       g_free (sound_event);
     }
 
@@ -1402,7 +1508,6 @@ sound_event_toggled_cb (G_GNUC_UNUSED GtkCellRendererToggle *cell,
 }
 
 
-<<<<<<< HEAD
 static void
 audioev_filename_browse_play_cb (GtkWidget* /* playbutton */,
                                 gpointer data)
@@ -1420,8 +1525,6 @@ audioev_filename_browse_play_cb (GtkWidget* /* playbutton */,
   g_free (file_name);
 }
 
-=======
->>>>>>> GSettings: Ported the sound events part of the preferences window.
 void on_videoinput_device_added_cb (const Ekiga::VideoInputDevice & device, bool isDesired, GtkWidget 
*prefs_window)
 {
   GmPreferencesWindow *pw = NULL;
@@ -1555,8 +1658,74 @@ string_option_setting_changed (GSettings *settings,
                                      NULL);
 }
 
+
+void
+int_option_menu_changed (GtkWidget *option_menu,
+                        gpointer data)
+{
+  gchar *key = NULL;
+  GSettings *settings = NULL;
+
+  GtkTreeModel *model = NULL;
+  GtkTreeIter iter;
+
+  unsigned int i = 0;
+  unsigned int current_value = 0;
+
+  key = (gchar *) data;
+
+  model = gtk_combo_box_get_model (GTK_COMBO_BOX (option_menu));
+  if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (option_menu), &iter)) {
+
+    gtk_tree_model_get (GTK_TREE_MODEL (model), &iter,
+                        COLUMN_GSETTINGS, &settings, -1);
+    i = gtk_combo_box_get_active (GTK_COMBO_BOX (option_menu));
+    current_value = g_settings_get_int (settings, key);
+
+    if (i != current_value)
+      g_settings_set_int (settings, key, i);
+  }
+}
+
+
+void
+int_option_setting_changed (GSettings *settings,
+                           gchar *key,
+                           gpointer data)
+{
+  GtkWidget *e = NULL;
+
+  GtkTreeModel *model = NULL;
+  GtkTreeIter iter;
+
+  gint current_value = 0;
+
+  e = GTK_WIDGET (data);
+
+  model = gtk_combo_box_get_model (GTK_COMBO_BOX (e));
+  gtk_tree_model_get_iter_first (model, &iter);
+
+  gtk_tree_model_get (model, &iter, COLUMN_GSETTINGS, &settings, -1);
+
+  current_value = g_settings_get_int (settings, key);
+
+  g_signal_handlers_block_matched (G_OBJECT (e),
+                                   G_SIGNAL_MATCH_FUNC,
+                                   0, 0, NULL,
+                                   (gpointer) int_option_menu_changed,
+                                   NULL);
+  if (current_value != gtk_combo_box_get_active (GTK_COMBO_BOX (e)))
+    gtk_combo_box_set_active (GTK_COMBO_BOX (e), current_value);
+  g_signal_handlers_unblock_matched (G_OBJECT (e),
+                                     G_SIGNAL_MATCH_FUNC,
+                                     0, 0, NULL,
+                                     (gpointer) int_option_menu_changed,
+                                     NULL);
+}
+
+
 /* Public functions */
-void 
+void
 gm_prefs_window_update_devices_list (GtkWidget *prefs_window)
 {
   GmPreferencesWindow *pw = NULL;
@@ -1568,29 +1737,8 @@ gm_prefs_window_update_devices_list (GtkWidget *prefs_window)
   std::vector <std::string> device_list;
 
   /* The player */
-<<<<<<< HEAD
   get_audiooutput_devices (pw->audiooutput_core, device_list);
   array = vector_of_string_to_array (device_list);
-  gnome_prefs_string_option_menu_update (pw->audio_player,
-                                        (const gchar **)array,
-                                        AUDIO_DEVICES_KEY "output_device",
-                                        DEFAULT_AUDIO_DEVICE_NAME);
-  gnome_prefs_string_option_menu_update (pw->sound_events_output,
-                                         (const gchar **)array,
-                                         SOUND_EVENTS_KEY "output_device",
-                                         DEFAULT_AUDIO_DEVICE_NAME);
-  g_free (array);
-
-  /* The recorder */
-  get_audioinput_devices (pw->audioinput_core, device_list);
-  array = vector_of_string_to_array (device_list);
-  gnome_prefs_string_option_menu_update (pw->audio_recorder,
-                                        (const gchar **)array,
-                                        AUDIO_DEVICES_KEY "input_device",
-                                        DEFAULT_AUDIO_DEVICE_NAME);
-=======
-  gm_prefs_window_get_audiooutput_devices_list (pw->core, device_list);
-  array = gm_prefs_window_convert_string_list(device_list);
   gm_pw_string_option_menu_update (pw->audio_player,
                                    (const gchar **)array,
                                    pw->audio_devices_settings,
@@ -1604,14 +1752,13 @@ gm_prefs_window_update_devices_list (GtkWidget *prefs_window)
   g_free (array);
 
   /* The recorder */
-  gm_prefs_window_get_audioinput_devices_list (pw->core, device_list);
-  array = gm_prefs_window_convert_string_list(device_list);
+  get_audioinput_devices (pw->audioinput_core, device_list);
+  array = vector_of_string_to_array (device_list);
   gm_pw_string_option_menu_update (pw->audio_recorder,
                                    (const gchar **)array,
                                    pw->audio_devices_settings,
                                    "input-device",
                                    DEFAULT_AUDIO_DEVICE_NAME);
->>>>>>> GSettings: Migrated sound events, audio output and audio input settins.
   g_free (array);
 
 
@@ -1738,59 +1885,6 @@ preferences_window_new (Ekiga::ServiceCore& core)
   conn = pw->audiooutput_core->device_removed.connect (boost::bind (&on_audiooutput_device_removed_cb, _1, 
_2, window));
   pw->connections.add (conn);
 
-<<<<<<< HEAD
-  /* Connect notifiers for SOUND_EVENTS_KEY keys */
-  notifier =
-    gm_conf_notifier_add (SOUND_EVENTS_KEY "enable_incoming_call_sound", 
-                         sound_events_list_changed_nt, window);
-   pw->notifiers.push_front (notifier);
-
-  notifier =
-    gm_conf_notifier_add (SOUND_EVENTS_KEY "incoming_call_sound",
-                         sound_events_list_changed_nt, window);
-  pw->notifiers.push_front (notifier);
-
-  notifier =
-    gm_conf_notifier_add (SOUND_EVENTS_KEY "enable_ring_tone_sound", 
-                         sound_events_list_changed_nt, window);
-  pw->notifiers.push_front (notifier);
-  
-  notifier =
-    gm_conf_notifier_add (SOUND_EVENTS_KEY "ring_tone_sound", 
-                         sound_events_list_changed_nt, window);
-  pw->notifiers.push_front (notifier);
-  
-  notifier =
-    gm_conf_notifier_add (SOUND_EVENTS_KEY "enable_busy_tone_sound", 
-                         sound_events_list_changed_nt, window);
-  pw->notifiers.push_front (notifier);
-  
-  notifier =
-    gm_conf_notifier_add (SOUND_EVENTS_KEY "busy_tone_sound",
-                         sound_events_list_changed_nt, window);
-  pw->notifiers.push_front (notifier);
-  
-  notifier =
-    gm_conf_notifier_add (SOUND_EVENTS_KEY "enable_new_voicemail_sound", 
-                         sound_events_list_changed_nt, window);
-  pw->notifiers.push_front (notifier);
-  
-  notifier =
-    gm_conf_notifier_add (SOUND_EVENTS_KEY "new_voicemail_sound",
-                         sound_events_list_changed_nt, window);
-  pw->notifiers.push_front (notifier);
-
-  notifier =
-    gm_conf_notifier_add (SOUND_EVENTS_KEY "enable_new_message_sound",
-                         sound_events_list_changed_nt, window);
-  pw->notifiers.push_front (notifier);
-
-  notifier =
-    gm_conf_notifier_add (SOUND_EVENTS_KEY "new_message_sound",
-                         sound_events_list_changed_nt, window);
-  pw->notifiers.push_front (notifier);
-=======
-
   /* Connect notifiers for SOUND_EVENTS_SCHEMA settings */
   g_signal_connect (pw->sound_events_settings, "changed::enable-incoming-call-sound",
                     G_CALLBACK (sound_event_setting_changed), window);
@@ -1806,7 +1900,6 @@ preferences_window_new (Ekiga::ServiceCore& core)
 
   g_signal_connect (pw->sound_events_settings, "changed::enable-new-message-sound",
                     G_CALLBACK (sound_event_setting_changed), window);
->>>>>>> GSettings: Ported the sound events part of the preferences window.
 
   return window;
 }
diff --git a/lib/engine/videoinput/videoinput-core.cpp b/lib/engine/videoinput/videoinput-core.cpp
index 0aae9ac..734ac7b 100644
--- a/lib/engine/videoinput/videoinput-core.cpp
+++ b/lib/engine/videoinput/videoinput-core.cpp
@@ -43,6 +43,7 @@
 
 using namespace Ekiga;
 
+
 VideoInputCore::VideoPreviewManager::VideoPreviewManager (VideoInputCore& _videoinput_core, 
boost::shared_ptr<VideoOutputCore> _videooutput_core)
 : PThread (1000, AutoDeleteThread, HighestPriority, "VideoPreviewManager"),
     videoinput_core (_videoinput_core),
@@ -56,64 +57,89 @@ VideoInputCore::VideoPreviewManager::VideoPreviewManager (VideoInputCore& _video
   // Since windows does not like to restart a thread that
   // was never started, we do so here
   this->Resume ();
-  thread_paused.Wait();
 }
 
 void VideoInputCore::VideoPreviewManager::quit ()
 {
-  if (!pause_thread)
-    stop();
+  stop ();
+
+  PWaitAndSignal q(exit_mutex);
   end_thread = true;
-  run_thread.Signal();
-  PWaitAndSignal m(thread_ended);
+
+  PWaitAndSignal m(thread_mutex);
+  if (frame)
+    free (frame);
 }
 
 void VideoInputCore::VideoPreviewManager::start (unsigned _width, unsigned _height)
 {
   PTRACE(4, "PreviewManager\tStarting Preview");
-  width = _width;
-  height = _height;
-  end_thread = false;
-  frame = (char*) malloc (unsigned (width * height * 3 / 2));
+
+  {
+    PWaitAndSignal c(capture_mutex);
+    width = _width;
+    height = _height;
+    pause_thread = false;
+  }
 
   videooutput_core->start();
-  pause_thread = false;
-  run_thread.Signal();
 }
 
 void VideoInputCore::VideoPreviewManager::stop ()
 {
   PTRACE(4, "PreviewManager\tStopping Preview");
-  pause_thread = true;
-  thread_paused.Wait();
 
-  if (frame) {
-    free (frame);
-    frame = NULL;
+  {
+    PWaitAndSignal c(capture_mutex);
+    if (pause_thread)
+      return;
+    pause_thread = true;
   }
+
   videooutput_core->stop();
 }
 
 void VideoInputCore::VideoPreviewManager::Main ()
 {
-  PWaitAndSignal m(thread_ended);
+  PWaitAndSignal m(thread_mutex);
+  bool exit = end_thread;
+  bool capture = !pause_thread;
 
-  while (!end_thread) {
+  while (!exit) {
 
-    thread_paused.Signal ();
-    run_thread.Wait ();
+    {
+      PWaitAndSignal c(capture_mutex);
+      capture = !pause_thread;
+      if (capture) {
+        if (frame)
+          free (frame);
+        frame = (char*) malloc (unsigned (width * height * 3 / 2));
+      }
+    }
+    while (capture) {
 
-    while (!pause_thread) {
       if (frame) {
+
         videoinput_core.get_frame_data(frame);
         videooutput_core->set_frame_data(frame, width, height, 0, 1);
       }
+      {
+        PWaitAndSignal c(capture_mutex);
+        capture = !pause_thread;
+      }
+
       // We have to sleep some time outside the mutex lock
       // to give other threads time to get the mutex
       // It will be taken into account by PAdaptiveDelay
       Current()->Sleep (5);
     }
 
+    {
+      PWaitAndSignal q(exit_mutex);
+      exit = end_thread;
+    }
+
+    Current()->Sleep (5);
   }
 }
 
@@ -126,6 +152,7 @@ VideoInputCore::VideoInputCore (Ekiga::ServiceCore & _core,
 
   preview_manager = new VideoPreviewManager (*this, _videooutput_core);
 
+
   preview_config.active = false;
   preview_config.width = 176;
   preview_config.height = 144;
@@ -149,6 +176,9 @@ VideoInputCore::VideoInputCore (Ekiga::ServiceCore & _core,
   current_manager = NULL;
   videoinput_core_conf_bridge = NULL;
   notification_core = core.get<Ekiga::NotificationCore> ("notification-core");
+
+  device_settings = new Settings (VIDEO_DEVICES_SCHEMA);
+  device_settings->changed.connect (boost::bind (&VideoInputCore::setup, this, _1));
 }
 
 VideoInputCore::~VideoInputCore ()
@@ -166,8 +196,11 @@ VideoInputCore::~VideoInputCore ()
     delete (*iter);
 
   managers.clear();
+
+  delete device_settings;
 }
 
+
 void VideoInputCore::setup_conf_bridge ()
 {
   PWaitAndSignal m(core_mutex);
@@ -175,6 +208,40 @@ void VideoInputCore::setup_conf_bridge ()
   videoinput_core_conf_bridge = new VideoInputCoreConfBridge (*this);
 }
 
+
+void VideoInputCore::setup (std::string setting)
+{
+  std::cout << "dans setup " << setting << std::endl << std::flush;
+  GSettings* settings = device_settings->get_g_settings ();
+  VideoInputDevice device;
+
+  /* Get device settings */
+  if (setting == "any" || setting == "input-device" || setting == "format" || setting == "channel") {
+    gchar *device_string = g_settings_get_string (settings, "input-device");
+    unsigned video_format = g_settings_get_int (settings, "format");
+    unsigned channel = g_settings_get_int (settings, "channel");
+    device.SetFromString (device_string);
+
+    std::cout << "dans setup set device " << setting << " " << device_string << std::endl << std::flush;
+    set_device (device, channel, (VideoInputFormat) video_format);
+    g_free (device_string);
+  }
+
+  /* Previenw */
+  if (setting == "any" || setting == "enable-preview") {
+    std::cout << "dans setup " << setting << std::endl << std::flush;
+    if (g_settings_get_boolean (settings, "enable-preview")) {
+      std::cout << "start " << std::endl << std::flush;
+      start_preview ();
+    }
+    else {
+      std::cout << "stop " << std::endl << std::flush;
+      stop_preview ();
+    }
+  }
+}
+
+
 void VideoInputCore::add_manager (VideoInputManager &manager)
 {
   managers.insert (&manager);
@@ -217,10 +284,46 @@ void VideoInputCore::get_devices (std::vector <VideoInputDevice> & devices)
 #endif
 }
 
-void VideoInputCore::set_device(const VideoInputDevice & device, int channel, VideoInputFormat format)
+void VideoInputCore::set_device(const VideoInputDevice & _device, int channel, VideoInputFormat format)
 {
   PWaitAndSignal m(core_mutex);
-  internal_set_device(device, channel, format);
+  std::cout << "dans set_device" << std::endl << std::flush;
+  VideoInputDevice device;
+
+  /* Check if device exists */
+  std::vector <VideoInputDevice> devices;
+  bool found = false;
+  get_devices (devices);
+  for (std::vector<VideoInputDevice>::iterator it = devices.begin ();
+       it < devices.end ();
+       it++) {
+    if ((*it).GetString () == _device.GetString ()) {
+      found = true;
+      break;
+    }
+  }
+  PTRACE(4, "VidInputCoreConfBridge\tUpdating device");
+
+  if (found)
+    device = _device;
+  else
+    device.SetFromString (devices.begin ()->GetString ());
+
+  if ( (device.type == "" )   ||
+       (device.source == "")  ||
+       (device.name == "" ) ) {
+    PTRACE(1, "VidinputCore\tTried to set malformed device");
+    device.type = VIDEO_INPUT_FALLBACK_DEVICE_TYPE;
+    device.source = VIDEO_INPUT_FALLBACK_DEVICE_SOURCE;
+    device.name = VIDEO_INPUT_FALLBACK_DEVICE_NAME;
+  }
+
+  if (format >= VI_FORMAT_MAX) {
+    PTRACE(1, "VidInputCoreConfBridge\t" << VIDEO_DEVICES_KEY "format" << " out of range, ajusting to 3");
+    format = (VideoInputFormat) 3;
+  }
+
+  internal_set_device (device, channel, format);
   desired_device  = device;
 }
 
@@ -397,8 +500,6 @@ void VideoInputCore::get_frame_data (char *data)
 
       internal_close();
 
-      internal_set_fallback();
-
       if (preview_config.active && !stream_config.active)
         internal_open(preview_config.width, preview_config.height, preview_config.fps);
 
diff --git a/lib/engine/videoinput/videoinput-core.h b/lib/engine/videoinput/videoinput-core.h
index 3b7065e..1634a1c 100644
--- a/lib/engine/videoinput/videoinput-core.h
+++ b/lib/engine/videoinput/videoinput-core.h
@@ -50,6 +50,9 @@
 #include <glib.h>
 #include <set>
 #include <ptlib.h>
+#include <gio/gio.h>
+
+#include "ekiga-settings.h"
 
 #define VIDEO_INPUT_FALLBACK_DEVICE_TYPE   "Moving Logo"
 #define VIDEO_INPUT_FALLBACK_DEVICE_SOURCE "Moving Logo"
@@ -115,6 +118,10 @@ namespace Ekiga
        */
       void setup_conf_bridge();
 
+      /** Set up settings
+       */
+      void setup (std::string setting);
+
 
       /*** Service Implementation ***/
 
@@ -352,9 +359,10 @@ private:
 
         bool end_thread;
         bool pause_thread;
-        PMutex     thread_ended;
-        PSyncPoint thread_paused;
-        PSyncPoint run_thread;
+
+        PMutex exit_mutex;
+        PMutex thread_mutex;
+        PMutex capture_mutex;
 
         VideoInputCore  & videoinput_core;
         boost::shared_ptr<VideoOutputCore> videooutput_core;
@@ -417,6 +425,7 @@ private:
       };
 
 private:
+
       std::set<VideoInputManager *> managers;
 
       VideoDeviceConfig       preview_config;
@@ -427,7 +436,7 @@ private:
       VideoInputDevice        current_device;
       VideoInputFormat        current_format;
       int                     current_channel;
-      VideoInputSettings      current_settings; 
+      VideoInputSettings      current_settings;
       VideoInputSettings      desired_settings;
 
       PMutex core_mutex;
@@ -437,6 +446,8 @@ private:
       VideoPreviewManager* preview_manager;
       VideoInputCoreConfBridge* videoinput_core_conf_bridge;
       boost::shared_ptr<Ekiga::NotificationCore> notification_core;
+
+      Settings* device_settings;
     };
 /**
  * @}
diff --git a/lib/engine/videoinput/videoinput-gmconf-bridge.cpp 
b/lib/engine/videoinput/videoinput-gmconf-bridge.cpp
index 1ef576f..36dbfc9 100644
--- a/lib/engine/videoinput/videoinput-gmconf-bridge.cpp
+++ b/lib/engine/videoinput/videoinput-gmconf-bridge.cpp
@@ -78,68 +78,6 @@ VideoInputCoreConfBridge::on_property_changed (std::string key,
                                         VideoSizes[size].height,
                                         max_frame_rate);
   }
-  else if ( (key == VIDEO_DEVICES_KEY "input_device") ||
-            (key == VIDEO_DEVICES_KEY "channel") ||
-            (key == VIDEO_DEVICES_KEY "format") ) {
-
-    std::vector <VideoInputDevice> devices;
-    bool found = false;
-    gchar *value = gm_conf_get_string (VIDEO_DEVICES_KEY "input_device");
-    videoinput_core.get_devices (devices);
-    if (value != NULL) {
-      for (std::vector<VideoInputDevice>::iterator it = devices.begin ();
-           it < devices.end ();
-           it++) {
-        if ((*it).GetString () == value) {
-          found = true;
-          break;
-        }
-      }
-    }
-    PTRACE(4, "VidInputCoreConfBridge\tUpdating device");
-
-    VideoInputDevice device;
-    if (found)
-      device.SetFromString (value);
-    else 
-      device.SetFromString (devices.begin ()->GetString ());
-    g_free (value);
-
-    if ( (device.type == "" )   ||
-         (device.source == "")  ||
-         (device.name == "" ) ) {
-      PTRACE(1, "VidinputCore\tTried to set malformed device");
-      device.type = VIDEO_INPUT_FALLBACK_DEVICE_TYPE;
-      device.source = VIDEO_INPUT_FALLBACK_DEVICE_SOURCE;
-      device.name = VIDEO_INPUT_FALLBACK_DEVICE_NAME;
-    }
-
-    unsigned video_format = gm_conf_get_int (VIDEO_DEVICES_KEY "format");
-    if (video_format >= VI_FORMAT_MAX) {
-      PTRACE(1, "VidInputCoreConfBridge\t" << VIDEO_DEVICES_KEY "format" << " out of range, ajusting to 3");
-      video_format = 3;
-    }
-
-    videoinput_core.set_device (device, gm_conf_get_int (VIDEO_DEVICES_KEY "channel") ,(VideoInputFormat) 
video_format);
-  }
-  else if (key == VIDEO_DEVICES_KEY "enable_preview") {
-
-    static bool startup = true;
-
-    if (!startup) {
-
-      PTRACE(4, "VidInputCoreConfBridge\tUpdating preview");
-      if (gm_conf_get_bool ( VIDEO_DEVICES_KEY "enable_preview"))
-        videoinput_core.start_preview();
-      else
-        videoinput_core.stop_preview();
-    } else {
-
-      startup = false;
-      if (gm_conf_get_bool ( VIDEO_DEVICES_KEY "enable_preview"))
-       Ekiga::Runtime::run_in_main (boost::bind (&VideoInputCore::start_preview, boost::ref 
(videoinput_core)), 5);
-    }
-  }
   else if (key == VIDEO_DEVICES_KEY "image") {
     PTRACE(4, "VidInputCoreConfBridge\tUpdating image");
   }



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