* Thanks guys!
*/
-#include <config.h>
+#include "config.h"
+#include "empathy-mic-menu.h"
-#include <gtk/gtk.h>
+#include "empathy-mic-monitor.h"
-#include "empathy-mic-menu.h"
+#define DEBUG_FLAG EMPATHY_DEBUG_VOIP
+#include "empathy-debug.h"
struct _EmpathyMicMenuPrivate
{
/* Queue of GtkRadioActions. */
GQueue *microphones;
+
+ EmpathyMicMonitor *mic_monitor;
};
G_DEFINE_TYPE (EmpathyMicMenu, empathy_mic_menu, G_TYPE_OBJECT);
+#define MONITOR_KEY "empathy-mic-menu-is-monitor"
+
enum
{
PROP_WINDOW = 1,
if (!empathy_audio_src_change_microphone_finish (audio, result, &error))
{
- g_debug ("Failed to change microphone: %s", error->message);
+ DEBUG ("Failed to change microphone: %s", error->message);
g_clear_error (&error);
/* We call update here because if this change operation failed
GtkRadioAction *action = l->data;
const gchar *name = gtk_action_get_name (GTK_ACTION (action));
gint value;
+ gboolean active;
g_object_get (action, "value", &value, NULL);
- if (value == (gint) current_mic)
+ active = (value == (gint) current_mic);
+
+ if (active)
{
priv->in_update = TRUE;
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
priv->in_update = FALSE;
}
+ /* If action is a monitor then don't show it in the UI, BUT do
+ * display it regardless if it is the current device. This is so
+ * we don't have a rubbish UI by showing monitor devices in
+ * Empathy, but still show the correct device when someone plays
+ * with pavucontrol. */
+ if (g_object_get_data (G_OBJECT (action), MONITOR_KEY) != NULL
+ && !active)
+ continue;
+
gtk_ui_manager_add_ui (ui_manager, priv->ui_id,
/* TODO: this should probably be passed from the call
* window, seeing that it's a reference to
empathy_mic_menu_add_microphone (EmpathyMicMenu *self,
const gchar *name,
const gchar *description,
- guint source_idx)
+ guint source_idx,
+ gboolean is_monitor)
{
EmpathyMicMenuPrivate *priv = self->priv;
GtkRadioAction *action;
gtk_action_group_add_action_with_accel (priv->action_group,
GTK_ACTION (action), NULL);
+ /* Set MONITOR_KEY on the action to non-NULL if it's a monitor
+ * because we don't want to show monitors if we can help it. */
+ if (is_monitor)
+ {
+ g_object_set_data (G_OBJECT (action), MONITOR_KEY,
+ GUINT_TO_POINTER (TRUE));
+ }
+
group = gtk_radio_action_get_group (GTK_RADIO_ACTION (priv->anchor_action));
gtk_radio_action_set_group (GTK_RADIO_ACTION (action), group);
}
static void
-empathy_mic_menu_microphone_added_cb (EmpathyGstAudioSrc *audio,
+empathy_mic_menu_microphone_added_cb (EmpathyMicMonitor *monitor,
guint source_idx,
const gchar *name,
const gchar *description,
gboolean is_monitor,
EmpathyMicMenu *self)
{
- empathy_mic_menu_add_microphone (self, name, description, source_idx);
+ empathy_mic_menu_add_microphone (self, name, description,
+ source_idx, is_monitor);
empathy_mic_menu_update (self);
}
static void
-empathy_mic_menu_microphone_removed_cb (EmpathyGstAudioSrc *audio,
+empathy_mic_menu_microphone_removed_cb (EmpathyMicMonitor *monitor,
guint source_idx,
EmpathyMicMenu *self)
{
}
static void
-empathy_mic_menu_get_microphones_cb (GObject *source_object,
+empathy_mic_menu_list_microphones_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
- EmpathyGstAudioSrc *audio = EMPATHY_GST_AUDIO_SRC (source_object);
+ EmpathyMicMonitor *monitor = EMPATHY_MIC_MONITOR (source_object);
EmpathyMicMenu *self = user_data;
GError *error = NULL;
const GList *mics = NULL;
- mics = empathy_audio_src_get_microphones_finish (audio, result, &error);
+ mics = empathy_mic_monitor_list_microphones_finish (monitor, result, &error);
if (error != NULL)
{
- g_debug ("Failed to get microphone list: %s", error->message);
+ DEBUG ("Failed to get microphone list: %s", error->message);
g_clear_error (&error);
return;
}
for (; mics != NULL; mics = mics->next)
{
- EmpathyAudioSrcMicrophone *mic = mics->data;
+ EmpathyMicrophone *mic = mics->data;
empathy_mic_menu_add_microphone (self, mic->name,
- mic->description, mic->index);
+ mic->description, mic->index, mic->is_monitor);
}
empathy_mic_menu_update (self);
/* Okay let's go go go. */
+ priv->mic_monitor = empathy_mic_monitor_new ();
+
priv->action_group = gtk_action_group_new ("EmpathyMicMenu");
gtk_ui_manager_insert_action_group (ui_manager, priv->action_group, -1);
/* the UI manager now owns this */
gtk_action_group_add_action (priv->action_group, priv->anchor_action);
g_object_unref (priv->anchor_action);
+ priv->microphones = g_queue_new ();
+
+ /* Don't bother with any of this if we don't support changing
+ * microphone, so don't listen for microphone changes or enumerate
+ * the available microphones. */
+ if (!empathy_audio_src_supports_changing_mic (audio))
+ return;
+
tp_g_signal_connect_object (audio, "notify::microphone",
G_CALLBACK (empathy_mic_menu_notify_microphone_cb), self, 0);
- tp_g_signal_connect_object (audio, "microphone-added",
+ tp_g_signal_connect_object (priv->mic_monitor, "microphone-added",
G_CALLBACK (empathy_mic_menu_microphone_added_cb), self, 0);
- tp_g_signal_connect_object (audio, "microphone-removed",
+ tp_g_signal_connect_object (priv->mic_monitor, "microphone-removed",
G_CALLBACK (empathy_mic_menu_microphone_removed_cb), self, 0);
- priv->microphones = g_queue_new ();
-
- empathy_audio_src_get_microphones_async (audio,
- empathy_mic_menu_get_microphones_cb, self);
+ empathy_mic_monitor_list_microphones_async (priv->mic_monitor,
+ empathy_mic_menu_list_microphones_cb, self);
}
static void
g_queue_free (priv->microphones);
priv->microphones = NULL;
+ tp_clear_object (&priv->mic_monitor);
+
G_OBJECT_CLASS (empathy_mic_menu_parent_class)->dispose (obj);
}