[ekiga/gnome-2-26] Set the default audio and video devices



commit f1d73cbbe10c517e85fb492b1b1215a567eb761d
Author: Eugen Dedu <Eugen Dedu pu-pm univ-fcomte fr>
Date:   Wed May 12 17:50:11 2010 +0200

    Set the default audio and video devices
    
    They are used when ekiga is installed for the first time.  Tested on
    GNU/Linux and Windows.

 ekiga.schemas.in.in     |    6 +++---
 src/gui/assistant.cpp   |   16 ++++++++++------
 src/gui/misc.cpp        |   34 +++++++++++++++++++++++++++++++++-
 src/gui/misc.h          |   14 ++++++++++++++
 src/gui/preferences.cpp |   14 +++++++-------
 5 files changed, 67 insertions(+), 17 deletions(-)
---
diff --git a/ekiga.schemas.in.in b/ekiga.schemas.in.in
index dffba7d..bfc13f1 100644
--- a/ekiga.schemas.in.in
+++ b/ekiga.schemas.in.in
@@ -5,7 +5,7 @@
       <applyto>/apps/@PACKAGE_NAME@/devices/audio/output_device</applyto>
       <owner>Ekiga</owner>
       <type>string</type>
-      <default>Default (PTLIB/ALSA)</default>
+      <default></default>
       <locale name="C">
 	<short>Audio output device</short>
 	<long>Select the audio output device to use</long>
@@ -16,7 +16,7 @@
       <applyto>/apps/@PACKAGE_NAME@/devices/audio/input_device</applyto>
       <owner>Ekiga</owner>
       <type>string</type>
-      <default>Default (PTLIB/ALSA)</default>
+      <default></default>
       <locale name="C">
 	<short>Audio input device</short>
 	<long>Select the audio input device to use</long>
@@ -193,7 +193,7 @@
       <applyto>/apps/@PACKAGE_NAME@/general/sound_events/output_device</applyto>
       <owner>Ekiga</owner>
       <type>string</type>
-      <default>Default (PTLIB/ALSA)</default>
+      <default></default>
       <locale name="C">
 	<short>Alternative audio output device</short>
 	<long>Select an alternative audio output device to use for sound events.</long>
diff --git a/src/gui/assistant.cpp b/src/gui/assistant.cpp
index a450e01..f0197ff 100644
--- a/src/gui/assistant.cpp
+++ b/src/gui/assistant.cpp
@@ -1067,16 +1067,16 @@ prepare_audio_devices_page (EkigaAssistant *assistant)
   char **array;
 
   ringer = gm_conf_get_string (SOUND_EVENTS_KEY "output_device");
-  if (ringer == NULL)
-    ringer = g_strdup ("Default (PTLIB/ALSA)");
+  if (ringer == NULL || !ringer[0])
+    ringer = g_strdup (get_default_audio_device_name ());
 
   player = gm_conf_get_string (AUDIO_DEVICES_KEY "output_device");
-  if (player == NULL)
-    player = g_strdup ("Default (PTLIB/ALSA)");
+  if (player == NULL || !player[0])
+    player = g_strdup (get_default_audio_device_name ());
 
   recorder = gm_conf_get_string (AUDIO_DEVICES_KEY "input_device");
-  if (recorder == NULL)
-    recorder = g_strdup ("Default (PTLIB/ALSA)");
+  if (recorder == NULL || !recorder[0])
+    recorder = g_strdup (get_default_audio_device_name ());
 
   /* FIXME: We should use DetectDevices, however DetectDevices
    * works only for the currently selected audio and video plugins,
@@ -1185,6 +1185,10 @@ prepare_video_devices_page (EkigaAssistant *assistant)
   get_videoinput_devices_list (assistant->priv->core, device_list);
   array = convert_string_list (device_list);
   current_plugin = gm_conf_get_string (VIDEO_DEVICES_KEY "input_device");
+  if (current_plugin == NULL || !current_plugin[0]) {
+    g_free (current_plugin);
+    current_plugin = g_strdup (get_default_video_device_name (array));
+  }
   update_combo_box (GTK_COMBO_BOX (assistant->priv->video_device),
                     array, current_plugin);
   g_free (array);
diff --git a/src/gui/misc.cpp b/src/gui/misc.cpp
index 0cea935..42f3a74 100644
--- a/src/gui/misc.cpp
+++ b/src/gui/misc.cpp
@@ -32,7 +32,7 @@
  *   begin                : Thu Nov 22 2001
  *   copyright            : (C) 2000-2006 by Damien Sandras
  *   description          : This file contains miscellaneous functions.
- *   Additional Code      : De Michele Cristiano, Miguel Rodríguez 
+ *   Additional Code      : De Michele Cristiano, Miguel Rodríguez
  *
  */
 
@@ -54,6 +54,38 @@
 #include <glib/gi18n.h>
 
 
+/* return the default audio device name */
+const gchar *get_default_audio_device_name (void)
+{
+#ifdef WIN32
+  return "Default (PTLIB/WindowsMultimedia)";
+#else
+  return "Default (PTLIB/ALSA)";
+#endif
+}
+
+/* return the default video name from the list of existing devices */
+const gchar *get_default_video_device_name (const gchar * const *options)
+{
+#ifdef WIN32
+  /* look for the entry containing "PTLIB/DirectShow" or "PTLIB/VideoForWindows" */
+  for (int i = 0; options[i]; i++)
+    if (g_strrstr (options[i], "PTLIB/DirectShow")
+        || g_strrstr (options[i], "PTLIB/VideoForWindows"))
+      return options[i];
+#else
+  /* look for the entry containing "PTLIB/V4L2", otherwise "PTLIB/V4L" */
+  for (int i = 0; options[i]; i++)
+    if (g_strrstr (options[i], "PTLIB/V4L2"))
+      return options[i];
+  for (int i = 0; options[i]; i++)
+    if (g_strrstr (options[i], "PTLIB/V4L"))
+      return options[i];
+#endif
+  return NULL;  // not found
+}
+
+
 /* The functions */
 GtkWidget *
 gnomemeeting_button_new (const char *lbl, 
diff --git a/src/gui/misc.h b/src/gui/misc.h
index d25cba1..30dd10e 100644
--- a/src/gui/misc.h
+++ b/src/gui/misc.h
@@ -43,6 +43,20 @@
 #include <gtk/gtk.h>
 
 
+/* DESCRIPTION  :  /
+ * BEHAVIOR     :  /
+ * PRE          :  /
+ */
+const gchar *get_default_audio_device_name (void);
+
+
+/* DESCRIPTION  :  /
+ * BEHAVIOR     :  /
+ * PRE          :  /
+ */
+const gchar *get_default_video_device_name (const gchar * const *options);
+
+
 /* DESCRIPTION  :  / 
  * BEHAVIOR     :  Creates a button with the GtkWidget * as pixmap 
  *                 and the label as label.
diff --git a/src/gui/preferences.cpp b/src/gui/preferences.cpp
index 6801e6b..595359c 100644
--- a/src/gui/preferences.cpp
+++ b/src/gui/preferences.cpp
@@ -765,16 +765,16 @@ gm_pw_init_audio_devices_page (GtkWidget *prefs_window,
   gm_prefs_window_get_audiooutput_devices_list (pw->core, device_list);
   array = gm_prefs_window_convert_string_list(device_list);
   pw->sound_events_output = 
-    gnome_prefs_string_option_menu_new (subsection, _("Ringing Device"), (const gchar **)array, SOUND_EVENTS_KEY "output_device", _("Select the ringing audio device to use"), 0, "Default (PTLIB/ALSA)");
+    gnome_prefs_string_option_menu_new (subsection, _("Ringing Device"), (const gchar **)array, SOUND_EVENTS_KEY "output_device", _("Select the ringing audio device to use"), 0, get_default_audio_device_name ());
   pw->audio_player =
-    gnome_prefs_string_option_menu_new (subsection, _("Output device:"), (const gchar **)array, AUDIO_DEVICES_KEY "output_device", _("Select the audio output device to use"), 1, "Default (PTLIB/ALSA)");
+    gnome_prefs_string_option_menu_new (subsection, _("Output device:"), (const gchar **)array, AUDIO_DEVICES_KEY "output_device", _("Select the audio output device to use"), 1, get_default_audio_device_name ());
   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);
   pw->audio_recorder =
-    gnome_prefs_string_option_menu_new (subsection, _("Input device:"), (const gchar **)array, AUDIO_DEVICES_KEY "input_device", _("Select the audio input device to use"), 2, "Default (PTLIB/ALSA)");
+    gnome_prefs_string_option_menu_new (subsection, _("Input device:"), (const gchar **)array, AUDIO_DEVICES_KEY "input_device", _("Select the audio input device to use"), 2, get_default_audio_device_name ());
   g_free (array);
 
 
@@ -1287,11 +1287,11 @@ gm_prefs_window_update_devices_list (GtkWidget *prefs_window)
   gnome_prefs_string_option_menu_update (pw->audio_player,
  					 (const gchar **)array,
  					 AUDIO_DEVICES_KEY "output_device",
-                                         "Default (PTLIB/ALSA)");
+ 					 get_default_audio_device_name ());
   gnome_prefs_string_option_menu_update (pw->sound_events_output,
                                          (const gchar **)array,
                                          SOUND_EVENTS_KEY "output_device",
-                                         "Default (PTLIB/ALSA)");
+                                         get_default_audio_device_name ());
   g_free (array);
 
   /* The recorder */
@@ -1300,7 +1300,7 @@ gm_prefs_window_update_devices_list (GtkWidget *prefs_window)
   gnome_prefs_string_option_menu_update (pw->audio_recorder,
  					 (const gchar **)array,
  					 AUDIO_DEVICES_KEY "input_device",
-                                         "Default (PTLIB/ALSA)");
+ 					 get_default_audio_device_name ());
   g_free (array);
 
 
@@ -1310,7 +1310,7 @@ gm_prefs_window_update_devices_list (GtkWidget *prefs_window)
   gnome_prefs_string_option_menu_update (pw->video_device,
 					 (const gchar **)array,
 					 VIDEO_DEVICES_KEY "input_device",
-                                         NULL);
+					 get_default_video_device_name (array));
   g_free (array);
 }
 



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