[gnome-media] Port to new control-center



commit 87fb57b6f0270103612efb1f3e8503981f68e8ed
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Jun 23 18:27:11 2010 +0100

    Port to new control-center
    
    Port to CcPanels for the new control-center in GNOME 3.0

 configure.ac                                       |   15 ++
 .../data/gnome-volume-control.desktop.in.in        |    4 +-
 gnome-volume-control/src/Makefile.am               |   18 +-
 gnome-volume-control/src/cc-sound-panel.c          |  135 +++++++++++++
 gnome-volume-control/src/cc-sound-panel.h          |   60 ++++++
 gnome-volume-control/src/dialog-main.c             |  211 --------------------
 gnome-volume-control/src/gvc-level-bar.c           |    6 +-
 gnome-volume-control/src/gvc-mixer-dialog.c        |   59 +-----
 gnome-volume-control/src/gvc-mixer-dialog.h        |    4 +-
 po/POTFILES.in                                     |    2 +-
 10 files changed, 239 insertions(+), 275 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 03a7391..6205efe 100644
--- a/configure.ac
+++ b/configure.ac
@@ -120,6 +120,17 @@ if test "x$enable_pulseaudio" != "xno"; then
     )
     AC_SUBST(VOLUME_CONTROL_CFLAGS)
     AC_SUBST(VOLUME_CONTROL_LIBS)
+    PKG_CHECK_MODULES(VOLUME_PANEL,
+            gobject-2.0 >= $GLIB_REQUIRED_VERSION
+            gtk+-2.0 >= $GTK_REQUIRED_VERSION
+            gio-2.0
+            gconf-2.0 >= $GCONF_REQUIRED_VERSION
+            libcanberra-gtk >= $CANBERRA_REQUIRED_VERSION
+            libgnome-control-center
+            libxml-2.0
+    )
+    AC_SUBST(VOLUME_PANEL_CFLAGS)
+    AC_SUBST(VOLUME_PANEL_LIBS)
     AC_DEFINE(HAVE_PULSEAUDIO, [], [Define if we have pulseaudio])
   fi
 else
@@ -130,6 +141,10 @@ AC_SUBST(HAVE_PULSEAUDIO)
 AC_SUBST(PULSEAUDIO_CFLAGS)
 AC_SUBST(PULSEAUDIO_LIBS)
 
+dnl Requires for the gnome-volume-control panel
+PANELS_DIR="${libdir}/control-center-1/panels"
+AC_SUBST(PANELS_DIR)
+
 dnl=======================================================================
 dnl profiles
 dnl=======================================================================
diff --git a/gnome-volume-control/data/gnome-volume-control.desktop.in.in b/gnome-volume-control/data/gnome-volume-control.desktop.in.in
index 8f231aa..2e0466f 100644
--- a/gnome-volume-control/data/gnome-volume-control.desktop.in.in
+++ b/gnome-volume-control/data/gnome-volume-control.desktop.in.in
@@ -1,7 +1,7 @@
 [Desktop Entry]
 _Name=Sound
 _Comment=Change sound volume and sound events
-Exec=gnome-volume-control
+Exec=gnome-control-center sound
 Icon=multimedia-volume-control
 Terminal=false
 Type=Application
@@ -12,3 +12,5 @@ X-GNOME-Bugzilla-Bugzilla=GNOME
 X-GNOME-Bugzilla-Product=gnome-media
 X-GNOME-Bugzilla-Component=gnome-volume-control
 X-GNOME-Bugzilla-Version= VERSION@
+X-GNOME-Bugzilla-OtherBinaries=gnome-control-control-applet
+X-GNOME-Settings-Panel=sound
diff --git a/gnome-volume-control/src/Makefile.am b/gnome-volume-control/src/Makefile.am
index 3b40c1e..3ea3475 100644
--- a/gnome-volume-control/src/Makefile.am
+++ b/gnome-volume-control/src/Makefile.am
@@ -1,14 +1,17 @@
 NULL =
 
-bin_PROGRAMS = 					\
+ccpanelsdir = $(PANELS_DIR)
+ccpanels_LTLIBRARIES = libsound.la
+
+bin_PROGRAMS =					\
 	gnome-volume-control-applet		\
-	gnome-volume-control			\
 	$(NULL)
 
 AM_CPPFLAGS =					\
 	$(WARN_CFLAGS)				\
 	-I$(top_srcdir)/sound-theme		\
 	$(VOLUME_CONTROL_CFLAGS)		\
+	$(VOLUME_PANEL_CFLAGS)			\
 	$(DISABLE_DEPRECATED)			\
 	$(PULSEAUDIO_CFLAGS)			\
 	-DLOCALE_DIR=\""$(datadir)/locale"\"	\
@@ -58,15 +61,17 @@ gnome_volume_control_applet_SOURCES =		\
 	applet-main.c				\
 	$(NULL)
 
-gnome_volume_control_LDADD =				\
+libsound_la_LIBADD =					\
 	-lm						\
 	libgnomevolumecontrol.la			\
 	$(top_builddir)/sound-theme/libsoundtheme.la	\
-	$(VOLUME_CONTROL_LIBS)				\
+	$(VOLUME_PANEL_LIBS)				\
 	$(PULSEAUDIO_LIBS)				\
 	$(NULL)
 
-gnome_volume_control_SOURCES =			\
+libsound_la_LDFLAGS = -avoid-version -module -no-undefined
+
+libsound_la_SOURCES =				\
 	gvc-balance-bar.h			\
 	gvc-balance-bar.c			\
 	gvc-mixer-dialog.h			\
@@ -77,7 +82,8 @@ gnome_volume_control_SOURCES =			\
 	gvc-combo-box.c				\
 	gvc-speaker-test.h			\
 	gvc-speaker-test.c			\
-	dialog-main.c				\
+	cc-sound-panel.c			\
+	cc-sound-panel.h			\
 	$(NULL)
 
 BUILT_SOURCES =				\
diff --git a/gnome-volume-control/src/cc-sound-panel.c b/gnome-volume-control/src/cc-sound-panel.c
new file mode 100644
index 0000000..bbb5e80
--- /dev/null
+++ b/gnome-volume-control/src/cc-sound-panel.c
@@ -0,0 +1,135 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2008 Red Hat, Inc.
+ *
+ * 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
+ * Lesser 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., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include <libintl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <glib/gi18n.h>
+#include <glib.h>
+#include <gtk/gtk.h>
+
+#include "cc-sound-panel.h"
+#include "gvc-mixer-dialog.h"
+#include "gvc-log.h"
+
+G_DEFINE_DYNAMIC_TYPE (CcSoundPanel, cc_sound_panel, CC_TYPE_PANEL)
+
+static void cc_sound_panel_finalize (GObject *object);
+
+static void
+cc_sound_panel_class_init (CcSoundPanelClass *klass)
+{
+        GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+        object_class->finalize = cc_sound_panel_finalize;
+}
+
+static void
+cc_sound_panel_class_finalize (CcSoundPanelClass *klass)
+{
+}
+
+static void
+cc_sound_panel_finalize (GObject *object)
+{
+        CcSoundPanel *panel = CC_SOUND_PANEL (object);
+
+        if (panel->dialog != NULL)
+                panel->dialog = NULL;
+        if (panel->connecting_label != NULL)
+                panel->connecting_label = NULL;
+        if (panel->control != NULL) {
+                g_object_unref (panel->control);
+                panel->control = NULL;
+        }
+
+        G_OBJECT_CLASS (cc_sound_panel_parent_class)->finalize (object);
+}
+
+static void
+on_control_ready (GvcMixerControl *control,
+                  CcSoundPanel    *panel)
+{
+        if (panel->dialog != NULL)
+                return;
+
+        if (panel->connecting_label) {
+                gtk_widget_destroy (panel->connecting_label);
+                panel->connecting_label = NULL;
+        }
+
+        panel->dialog = gvc_mixer_dialog_new (control);
+        gtk_container_add (GTK_CONTAINER (panel),
+                           GTK_WIDGET (panel->dialog));
+        gtk_widget_show (GTK_WIDGET (panel->dialog));
+}
+
+static void
+cc_sound_panel_init (CcSoundPanel *self)
+{
+        gvc_log_init ();
+        gvc_log_set_debug (TRUE);
+
+        gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
+                                           ICON_DATA_DIR);
+        gtk_window_set_default_icon_name ("multimedia-volume-control");
+
+        self->control = gvc_mixer_control_new ("GNOME Volume Control Dialog");
+        g_signal_connect (self->control,
+                          "ready",
+                          G_CALLBACK (on_control_ready),
+                          self);
+        gvc_mixer_control_open (self->control);
+
+        self->connecting_label = gtk_label_new (_("Waiting for sound system to respond"));
+        gtk_container_add (GTK_CONTAINER (self), self->connecting_label);
+        gtk_widget_show (self->connecting_label);
+}
+
+void
+cc_sound_panel_register (GIOModule *module)
+{
+        cc_sound_panel_register_type (G_TYPE_MODULE (module));
+        g_io_extension_point_implement (CC_SHELL_PANEL_EXTENSION_POINT,
+                                        CC_TYPE_SOUND_PANEL,
+                                        "sound", 0);
+}
+
+/* GIO extension stuff */
+void
+g_io_module_load (GIOModule *module)
+{
+        bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR);
+        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+
+        /* register the panel */
+        cc_sound_panel_register (module);
+}
+
+void
+g_io_module_unload (GIOModule *module)
+{
+}
+
diff --git a/gnome-volume-control/src/cc-sound-panel.h b/gnome-volume-control/src/cc-sound-panel.h
new file mode 100644
index 0000000..fda5fb7
--- /dev/null
+++ b/gnome-volume-control/src/cc-sound-panel.h
@@ -0,0 +1,60 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2010 Red Hat, Inc.
+ *
+ * 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
+ * Lesser 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., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#ifndef _CC_SOUND_PANEL_H
+#define _CC_SOUND_PANEL_H
+
+#include <libgnome-control-center/cc-panel.h>
+#include "gvc-mixer-control.h"
+#include "gvc-mixer-dialog.h"
+
+G_BEGIN_DECLS
+
+#define CC_TYPE_SOUND_PANEL cc_sound_panel_get_type()
+#define CC_SOUND_PANEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CC_TYPE_SOUND_PANEL, CcSoundPanel))
+#define CC_SOUND_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CC_TYPE_SOUND_PANEL, CcSoundPanelClass))
+#define CC_IS_SOUND_PANEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CC_TYPE_SOUND_PANEL))
+#define CC_IS_SOUND_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CC_TYPE_SOUND_PANEL))
+#define CC_SOUND_PANEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CC_TYPE_SOUND_PANEL, CcSoundPanelClass))
+
+typedef struct _CcSoundPanel CcSoundPanel;
+typedef struct _CcSoundPanelClass CcSoundPanelClass;
+typedef struct _CcSoundPanelPrivate CcSoundPanelPrivate;
+
+struct _CcSoundPanel {
+	CcPanel parent;
+
+	GvcMixerControl *control;
+	GvcMixerDialog  *dialog;
+	GtkWidget       *connecting_label;
+};
+
+struct _CcSoundPanelClass {
+	CcPanelClass parent_class;
+};
+
+GType cc_sound_panel_get_type (void) G_GNUC_CONST;
+
+void  cc_sound_panel_register (GIOModule *module);
+
+G_END_DECLS
+
+#endif /* _CC_SOUND_PANEL_H */
+
diff --git a/gnome-volume-control/src/gvc-level-bar.c b/gnome-volume-control/src/gvc-level-bar.c
index 12e2f1f..b2e7327 100644
--- a/gnome-volume-control/src/gvc-level-bar.c
+++ b/gnome-volume-control/src/gvc-level-bar.c
@@ -31,7 +31,7 @@
 
 #include "gvc-level-bar.h"
 
-#define NUM_BOXES 15
+#define NUM_BOXES 30
 
 #define GVC_LEVEL_BAR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GVC_TYPE_LEVEL_BAR, GvcLevelBarPrivate))
 
@@ -210,6 +210,10 @@ bar_calc_layout (GvcLevelBar *bar)
                 bar->priv->layout.box_radius = bar->priv->layout.box_height / 2;
         }
 
+        /* This can happen if the level bar isn't realized */
+        if (bar->priv->layout.delta == 0)
+                return;
+
         bar->priv->layout.peak_num = peak_level / bar->priv->layout.delta;
         bar->priv->layout.max_peak_num = max_peak_level / bar->priv->layout.delta;
 }
diff --git a/gnome-volume-control/src/gvc-mixer-dialog.c b/gnome-volume-control/src/gvc-mixer-dialog.c
index 2e1244d..b3b0eed 100644
--- a/gnome-volume-control/src/gvc-mixer-dialog.c
+++ b/gnome-volume-control/src/gvc-mixer-dialog.c
@@ -123,7 +123,7 @@ static void     bar_set_stream              (GvcMixerDialog      *dialog,
 static void     on_adjustment_value_changed (GtkAdjustment  *adjustment,
                                              GvcMixerDialog *dialog);
 
-G_DEFINE_TYPE (GvcMixerDialog, gvc_mixer_dialog, GTK_TYPE_DIALOG)
+G_DEFINE_TYPE (GvcMixerDialog, gvc_mixer_dialog, GTK_TYPE_VBOX)
 
 static void
 update_default_input (GvcMixerDialog *dialog)
@@ -1522,8 +1522,11 @@ on_test_speakers_clicked (GvcComboBox *widget,
                  profile->profile, gvc_mixer_card_get_name (card));
 
 	title = g_strdup_printf (_("Speaker Testing for %s"), gvc_mixer_card_get_name (card));
+	// FIXME
+	// set parent dialogue
+	// https://bugzilla.gnome.org/show_bug.cgi?id=621940
         d = gtk_dialog_new_with_buttons (title,
-                                         GTK_WINDOW (dialog),
+                                         NULL,
                                          GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
                                          NULL);
         g_free (title);
@@ -1669,32 +1672,6 @@ create_cards_treeview (GvcMixerDialog *dialog,
         return treeview;
 }
 
-static const guint tab_accel_keys[] = {
-        GDK_1, GDK_2, GDK_3, GDK_4, GDK_5
-};
-
-static void
-dialog_accel_cb (GtkAccelGroup    *accelgroup,
-                 GObject          *object,
-                 guint             key,
-                 GdkModifierType   mod,
-                 GvcMixerDialog   *self)
-{
-        gint num = -1;
-        gint i;
-
-        for (i = 0; i < G_N_ELEMENTS (tab_accel_keys); i++) {
-                if (tab_accel_keys[i] == key) {
-                        num = i;
-                        break;
-                }
-        }
-
-        if (num != -1) {
-                gtk_notebook_set_current_page (GTK_NOTEBOOK (self->priv->notebook), num);
-        }
-}
-
 static GObject *
 gvc_mixer_dialog_constructor (GType                  type,
                               guint                  n_construct_properties,
@@ -1714,16 +1691,12 @@ gvc_mixer_dialog_constructor (GType                  type,
         GvcMixerStream   *stream;
         GvcMixerCard     *card;
         GtkTreeSelection *selection;
-        GtkAccelGroup    *accel_group;
-        GClosure         *closure;
-        gint             i;
 
         object = G_OBJECT_CLASS (gvc_mixer_dialog_parent_class)->constructor (type, n_construct_properties, construct_params);
 
         self = GVC_MIXER_DIALOG (object);
-        gtk_dialog_add_button (GTK_DIALOG (self), "gtk-close", GTK_RESPONSE_OK);
 
-        main_vbox = gtk_dialog_get_content_area (GTK_DIALOG (self));
+        main_vbox = GTK_WIDGET (self);
         gtk_box_set_spacing (GTK_BOX (main_vbox), 2);
 
         gtk_container_set_border_width (GTK_CONTAINER (self), 6);
@@ -1748,23 +1721,6 @@ gvc_mixer_dialog_constructor (GType                  type,
                             TRUE, TRUE, 0);
         gtk_container_set_border_width (GTK_CONTAINER (self->priv->notebook), 5);
 
-        /* Set up accels (borrowed from Empathy) */
-        accel_group = gtk_accel_group_new ();
-        gtk_window_add_accel_group (GTK_WINDOW (self), accel_group);
-
-        for (i = 0; i < G_N_ELEMENTS (tab_accel_keys); i++) {
-                closure =  g_cclosure_new (G_CALLBACK (dialog_accel_cb),
-                                           self,
-                                           NULL);
-                gtk_accel_group_connect (accel_group,
-                                         tab_accel_keys[i],
-                                         GDK_MOD1_MASK,
-                                         0,
-                                         closure);
-        }
-
-        g_object_unref (accel_group);
-
         /* Effects page */
         self->priv->sound_effects_box = gtk_vbox_new (FALSE, 6);
         gtk_container_set_border_width (GTK_CONTAINER (self->priv->sound_effects_box), 12);
@@ -2087,9 +2043,6 @@ gvc_mixer_dialog_new (GvcMixerControl *control)
 {
         GObject *dialog;
         dialog = g_object_new (GVC_TYPE_MIXER_DIALOG,
-                               "icon-name", "multimedia-volume-control",
-                               "title", _("Sound Preferences"),
-                               "has-separator", FALSE,
                                "mixer-control", control,
                                NULL);
         return GVC_MIXER_DIALOG (dialog);
diff --git a/gnome-volume-control/src/gvc-mixer-dialog.h b/gnome-volume-control/src/gvc-mixer-dialog.h
index 64857b3..e95a7c7 100644
--- a/gnome-volume-control/src/gvc-mixer-dialog.h
+++ b/gnome-volume-control/src/gvc-mixer-dialog.h
@@ -37,13 +37,13 @@ typedef struct GvcMixerDialogPrivate GvcMixerDialogPrivate;
 
 typedef struct
 {
-        GtkDialog              parent;
+        GtkVBox                parent;
         GvcMixerDialogPrivate *priv;
 } GvcMixerDialog;
 
 typedef struct
 {
-        GtkDialogClass         parent_class;
+        GtkVBoxClass           parent_class;
 } GvcMixerDialogClass;
 
 GType               gvc_mixer_dialog_get_type            (void);
diff --git a/po/POTFILES.in b/po/POTFILES.in
index c71cda1..c8651be 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -4,7 +4,7 @@
 gnome-volume-control/data/gnome-volume-control-applet.desktop.in
 gnome-volume-control/data/gnome-volume-control.desktop.in.in
 gnome-volume-control/src/applet-main.c
-gnome-volume-control/src/dialog-main.c
+gnome-volume-control/src/cc-sound-panel.c
 gnome-volume-control/src/gvc-applet.c
 gnome-volume-control/src/gvc-balance-bar.c
 gnome-volume-control/src/gvc-channel-bar.c



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