summaryrefslogtreecommitdiff
path: root/mate-volume-control/src/dialog-main.c
diff options
context:
space:
mode:
authorMichal Ratajsky <[email protected]>2014-07-05 01:41:22 +0200
committerinfirit <[email protected]>2014-10-09 16:53:00 +0200
commitcf427cb4ccfc269252c1f7744b4c730ef0bb7a4e (patch)
tree2b623fa9cabd575907a1cf40378eeecb8f21efaa /mate-volume-control/src/dialog-main.c
parenta4cb2a2c9ab27e32449b5696bb989cc761ec73c7 (diff)
downloadmate-media-cf427cb4ccfc269252c1f7744b4c730ef0bb7a4e.tar.bz2
mate-media-cf427cb4ccfc269252c1f7744b4c730ef0bb7a4e.tar.xz
Initial port of the dialog
Diffstat (limited to 'mate-volume-control/src/dialog-main.c')
-rw-r--r--mate-volume-control/src/dialog-main.c175
1 files changed, 112 insertions, 63 deletions
diff --git a/mate-volume-control/src/dialog-main.c b/mate-volume-control/src/dialog-main.c
index 8b85924..f1d5bf4 100644
--- a/mate-volume-control/src/dialog-main.c
+++ b/mate-volume-control/src/dialog-main.c
@@ -20,43 +20,53 @@
#include "config.h"
+#include <libintl.h>
#include <glib/gi18n.h>
#include <glib.h>
#include <gtk/gtk.h>
-#include <libintl.h>
#include <unique/uniqueapp.h>
#include <libmatemixer/matemixer.h>
#include "gvc-mixer-dialog.h"
-#define DIALOG_POPUP_TIMEOUT 3
+#define DIALOG_POPUP_TIMEOUT 1
-static gboolean show_version = FALSE;
-static gchar* page = NULL;
+static guint popup_id = 0;
+static gboolean show_version = FALSE;
-static guint popup_id = 0;
-static GtkWidget *dialog = NULL;
-static GtkWidget *warning_dialog = NULL;
+static gchar *page = NULL;
+static GtkWidget *app_dialog = NULL;
+static GtkWidget *warning_dialog = NULL;
static void
on_dialog_response (GtkDialog *dialog, guint response_id, gpointer data)
{
+ gboolean destroy = GPOINTER_TO_INT (data);
+
+ if (destroy)
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+
gtk_main_quit ();
}
static void
on_dialog_close (GtkDialog *dialog, gpointer data)
{
+ gboolean destroy = GPOINTER_TO_INT (data);
+
+ if (destroy)
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+
gtk_main_quit ();
}
static UniqueResponse
-message_received_cb (UniqueApp *app,
- int command,
- UniqueMessageData *message_data,
- guint time_,
- gpointer user_data)
+on_app_message_received (UniqueApp *app,
+ int command,
+ UniqueMessageData *message_data,
+ guint time_,
+ gpointer user_data)
{
gtk_window_present (GTK_WINDOW (user_data));
@@ -64,84 +74,113 @@ message_received_cb (UniqueApp *app,
}
static void
-on_control_ready (GvcMixerControl *control, UniqueApp *app)
+remove_warning_dialog (void)
{
if (popup_id != 0) {
g_source_remove (popup_id);
popup_id = 0;
}
- if (warning_dialog != NULL) {
- gtk_widget_destroy (warning_dialog);
- warning_dialog = NULL;
- }
- if (dialog)
+ g_clear_pointer (&warning_dialog, gtk_widget_destroy);
+}
+
+static void
+control_ready (MateMixerControl *control, UniqueApp *app)
+{
+ /* The dialog might be already created, e.g. when reconnected
+ * to a sound server */
+ if (app_dialog != NULL)
return;
- dialog = GTK_WIDGET (gvc_mixer_dialog_new (control));
- g_signal_connect (dialog,
+ app_dialog = GTK_WIDGET (gvc_mixer_dialog_new (control));
+ g_signal_connect (app_dialog,
"response",
G_CALLBACK (on_dialog_response),
- NULL);
- g_signal_connect (dialog,
+ GINT_TO_POINTER (FALSE));
+ g_signal_connect (app_dialog,
"close",
G_CALLBACK (on_dialog_close),
- NULL);
+ GINT_TO_POINTER (FALSE));
- gvc_mixer_dialog_set_page (GVC_MIXER_DIALOG (dialog), page);
+ gvc_mixer_dialog_set_page (GVC_MIXER_DIALOG (app_dialog), page);
g_signal_connect (app, "message-received",
- G_CALLBACK (message_received_cb), dialog);
+ G_CALLBACK (on_app_message_received), app_dialog);
- gtk_widget_show (dialog);
+ gtk_widget_show (app_dialog);
}
static void
-warning_dialog_answered (GtkDialog *d,
- gpointer data)
+on_control_state_notify (MateMixerControl *control, UniqueApp *app)
{
- gtk_widget_destroy (warning_dialog);
- gtk_main_quit ();
+ MateMixerState state = mate_mixer_control_get_state (control);
+ gboolean failed = FALSE;
+
+ if (state == MATE_MIXER_STATE_READY) {
+ remove_warning_dialog ();
+
+ if (mate_mixer_control_get_backend_type (control) != MATE_MIXER_BACKEND_NULL)
+ control_ready (control, app);
+ else
+ failed = TRUE;
+ }
+ else if (state == MATE_MIXER_STATE_FAILED) {
+ remove_warning_dialog ();
+ failed = TRUE;
+ }
+
+ if (failed) {
+ GtkWidget *dialog;
+
+ dialog = gtk_message_dialog_new (GTK_WINDOW (app_dialog),
+ 0,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ _("Sound system is not available"));
+
+ g_signal_connect (dialog,
+ "response",
+ G_CALLBACK (on_dialog_response),
+ GINT_TO_POINTER (TRUE));
+ g_signal_connect (dialog,
+ "close",
+ G_CALLBACK (on_dialog_close),
+ GINT_TO_POINTER (TRUE));
+
+ gtk_widget_show (dialog);
+ }
}
static gboolean
dialog_popup_timeout (gpointer data)
{
- warning_dialog = gtk_message_dialog_new (GTK_WINDOW(dialog),
+ warning_dialog = gtk_message_dialog_new (GTK_WINDOW (app_dialog),
0,
GTK_MESSAGE_INFO,
GTK_BUTTONS_CANCEL,
_("Waiting for sound system to respond"));
- g_signal_connect (warning_dialog, "response",
- G_CALLBACK (warning_dialog_answered), NULL);
- g_signal_connect (warning_dialog, "close",
- G_CALLBACK (warning_dialog_answered), NULL);
+ g_signal_connect (warning_dialog,
+ "response",
+ G_CALLBACK (on_dialog_response),
+ GINT_TO_POINTER (TRUE));
+ g_signal_connect (warning_dialog,
+ "close",
+ G_CALLBACK (on_dialog_close),
+ GINT_TO_POINTER (TRUE));
gtk_widget_show (warning_dialog);
return FALSE;
}
-static void
-on_control_connecting (GvcMixerControl *control,
- UniqueApp *app)
-{
- if (popup_id != 0)
- return;
-
- popup_id = g_timeout_add_seconds (DIALOG_POPUP_TIMEOUT,
- dialog_popup_timeout,
- NULL);
-}
-
int
main (int argc, char **argv)
{
- GError *error = NULL;
- GvcMixerControl *control;
- UniqueApp *app;
- GOptionEntry entries[] = {
+ GError *error = NULL;
+ MateMixerControl *control;
+ UniqueApp *app;
+ GOptionEntry entries[] = {
{ "page", 'p', 0, G_OPTION_ARG_STRING, &page, N_("Startup page"), "effects|hardware|input|output|applications" },
{ "version", 'v', 0, G_OPTION_ARG_NONE, &show_version, N_("Version of this application"), NULL },
{ NULL }
@@ -175,27 +214,37 @@ main (int argc, char **argv)
return 1;
}
- gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
- ICON_DATA_DIR);
-
- gtk_window_set_default_icon_name ("multimedia-volume-control");
+ control = mate_mixer_control_new ();
- control = gvc_mixer_control_new ("MATE Volume Control Dialog");
+ mate_mixer_control_set_app_name (control, _("Volume Control"));
+ mate_mixer_control_set_app_id (control, GVC_DIALOG_DBUS_NAME);
+ mate_mixer_control_set_app_version (control, VERSION);
+ mate_mixer_control_set_app_icon (control, "multimedia-volume-control");
g_signal_connect (control,
- "connecting",
- G_CALLBACK (on_control_connecting),
- app);
- g_signal_connect (control,
- "ready",
- G_CALLBACK (on_control_ready),
+ "notify::state",
+ G_CALLBACK (on_control_state_notify),
app);
- gvc_mixer_control_open (control);
+ mate_mixer_control_open (control);
+
+ /* */
+ if (mate_mixer_control_get_state (control) == MATE_MIXER_STATE_CONNECTING)
+ popup_id = g_timeout_add_seconds (DIALOG_POPUP_TIMEOUT,
+ dialog_popup_timeout,
+ NULL);
+
+ gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
+ ICON_DATA_DIR);
+
+ gtk_window_set_default_icon_name ("multimedia-volume-control");
gtk_main ();
g_object_unref (control);
+ g_object_unref (app);
+
+ mate_mixer_deinit ();
return 0;
}