From ff7084ffe4a935a4cfafc9cd44a9b9daf43cb976 Mon Sep 17 00:00:00 2001 From: "H.Habighorst" Date: Sun, 23 Aug 2009 08:31:14 -0400 Subject: Bug 571488 - Migrate from deprecated gnome_sound to libcanberra --- calendar/gui/alarm-notify/Makefile.am | 6 +- calendar/gui/alarm-notify/alarm-queue.c | 16 ++- calendar/gui/alarm-notify/notify-main.c | 6 -- configure.ac | 6 ++ mail/Makefile.am | 2 + mail/mail-folder-cache.c | 1 - mail/mail-session.c | 6 +- plugins/mail-notification/Makefile.am | 4 +- .../apps-evolution-mail-notification.schemas.in | 11 +++ plugins/mail-notification/mail-notification.c | 108 +++++++++++++-------- shell/main.c | 3 - 11 files changed, 113 insertions(+), 56 deletions(-) diff --git a/calendar/gui/alarm-notify/Makefile.am b/calendar/gui/alarm-notify/Makefile.am index 680c5e95e5..ea1c36e0d9 100644 --- a/calendar/gui/alarm-notify/Makefile.am +++ b/calendar/gui/alarm-notify/Makefile.am @@ -25,7 +25,8 @@ AM_CPPFLAGS = \ -DEVOLUTION_GLADEDIR=\""$(gladedir)"\" \ -DEVOLUTION_LOCALEDIR=\""$(localedir)"\" \ -DEVOLUTION_LIBEXECDIR=\""$(privlibexecdir)"\" \ - $(EVOLUTION_CALENDAR_CFLAGS) + $(EVOLUTION_CALENDAR_CFLAGS) \ + $(CANBERRA_CFLAGS) glade_DATA = \ alarm-notify.glade @@ -51,7 +52,8 @@ evolution_alarm_notify_LDADD = \ $(top_builddir)/widgets/misc/libemiscwidgets.la \ $(top_builddir)/calendar/common/libevolution-calendarprivate.la \ $(CAMEL_LIBS) \ - $(EVOLUTION_CALENDAR_LIBS) + $(EVOLUTION_CALENDAR_LIBS) \ + $(CANBERRA_LIBS) if OS_WIN32 evolution_alarm_notify_LDFLAGS = -mwindows diff --git a/calendar/gui/alarm-notify/alarm-queue.c b/calendar/gui/alarm-notify/alarm-queue.c index 1aaca186ca..8d272764bd 100644 --- a/calendar/gui/alarm-notify/alarm-queue.c +++ b/calendar/gui/alarm-notify/alarm-queue.c @@ -34,7 +34,7 @@ #include #include #include -#include +#include #include #include @@ -1641,13 +1641,23 @@ audio_notification (time_t trigger, CompQueuedAlarms *cqa, if (attach && icalattach_get_is_url (attach)) { const gchar *url; + gchar *filename; + GError *error = NULL; url = icalattach_get_url (attach); + filename = g_filename_from_uri (url, NULL, &error); - if (url && *url && g_file_test (url, G_FILE_TEST_EXISTS)) { + if (error != NULL) { + g_warning ("%s", error->message); + g_error_free (error); + } else if (g_file_test (filename, G_FILE_TEST_EXISTS)) { flag = 1; - gnome_sound_play (url); /* this sucks */ + ca_context_play ( + ca_gtk_context_get(), 0, + CA_PROP_MEDIA_FILENAME, filename, NULL); } + + g_free (filename); } if (!flag) diff --git a/calendar/gui/alarm-notify/notify-main.c b/calendar/gui/alarm-notify/notify-main.c index 887adaa1d5..b3ff0db6a5 100644 --- a/calendar/gui/alarm-notify/notify-main.c +++ b/calendar/gui/alarm-notify/notify-main.c @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -48,8 +47,6 @@ #include "config-data.h" #include - - static BonoboGenericFactory *factory; static AlarmNotify *alarm_notify_service = NULL; @@ -142,8 +139,6 @@ main (gint argc, gchar **argv) glade_init (); - gnome_sound_init ("localhost"); - e_icon_factory_init (); init_alarm_service (NULL); @@ -173,7 +168,6 @@ main (gint argc, gchar **argv) alarm_done (); e_passwords_shutdown (); - gnome_sound_shutdown (); return 0; } diff --git a/configure.ac b/configure.ac index 41ea74d6a9..ad5521c885 100644 --- a/configure.ac +++ b/configure.ac @@ -259,6 +259,12 @@ PKG_CHECK_MODULES([EVOLUTION_DATA_SERVER], libgdata-$EDS_PACKAGE >= eds_minimum_version libgdata-google-$EDS_PACKAGE >= eds_minimum_version]) +dnl ****************************** +dnl Canberra / Canberra-GTK Sound +dnl ****************************** +PKG_CHECK_MODULES([CANBERRA],[libcanberra-gtk]) +AC_SUBST(CANBERRA_CFLAGS) +AC_SUBST(CANBERRA_LIBS) dnl ****************** dnl User Documentation diff --git a/mail/Makefile.am b/mail/Makefile.am index 53b5bca508..63cceb43f3 100644 --- a/mail/Makefile.am +++ b/mail/Makefile.am @@ -17,6 +17,7 @@ AM_CPPFLAGS = \ $(EVOLUTION_MAIL_CFLAGS) \ $(CERT_UI_CFLAGS) \ $(THREADS_CFLAGS) \ + $(CANBERRA_CFLAGS) \ -DEVOLUTION_DATADIR=\""$(datadir)"\" \ -DEVOLUTION_PRIVDATADIR=\""$(privdatadir)"\" \ -DEVOLUTION_GLADEDIR=\""$(gladedir)"\" \ @@ -164,6 +165,7 @@ libevolution_mail_la_LIBADD = \ $(top_builddir)/widgets/misc/libemiscwidgets.la \ $(top_builddir)/addressbook/gui/contact-editor/libecontacteditor.la \ $(top_builddir)/addressbook/gui/contact-list-editor/libecontactlisteditor.la \ + $(CANBERRA_LIBS) \ $(GTKHTML_LIBS) \ $(SMIME_LIBS) diff --git a/mail/mail-folder-cache.c b/mail/mail-folder-cache.c index bf728aa963..d19e163001 100644 --- a/mail/mail-folder-cache.c +++ b/mail/mail-folder-cache.c @@ -37,7 +37,6 @@ #include #include -#include #include #include #include diff --git a/mail/mail-session.c b/mail/mail-session.c index 4bd0a5f78d..27fdaf9942 100644 --- a/mail/mail-session.c +++ b/mail/mail-session.c @@ -33,7 +33,7 @@ #include -#include +#include #include #include @@ -462,7 +462,9 @@ static void main_play_sound (CamelFilterDriver *driver, gchar *filename, gpointer user_data) { if (filename && *filename) - gnome_sound_play (filename); + ca_context_play(ca_gtk_context_get(), 0, + CA_PROP_MEDIA_FILENAME, filename, + NULL); else gdk_beep (); diff --git a/plugins/mail-notification/Makefile.am b/plugins/mail-notification/Makefile.am index f409f8831a..b53e6a55a6 100644 --- a/plugins/mail-notification/Makefile.am +++ b/plugins/mail-notification/Makefile.am @@ -9,7 +9,8 @@ AM_CPPFLAGS = \ -I$(top_srcdir) \ -I$(top_srcdir)/widgets \ $(EVOLUTION_MAIL_CFLAGS) \ - $(LIBNOTIFY_CFLAGS) + $(LIBNOTIFY_CFLAGS) \ + $(CANBERRA_CFLAGS) if DBUS_SUPPORT AM_CPPFLAGS += -DDBUS_API_SUBJECT_TO_CHANGE=1 \ @@ -25,6 +26,7 @@ liborg_gnome_mail_notification_la_SOURCES = mail-notification.c liborg_gnome_mail_notification_la_LDFLAGS = \ -module -avoid-version $(NO_UNDEFINED) liborg_gnome_mail_notification_la_LIBADD = \ + $(CANBERRA_LIBS) \ $(LIBNOTIFY_LIBS) \ $(top_builddir)/e-util/libeutil.la \ $(top_builddir)/mail/libevolution-mail.la \ diff --git a/plugins/mail-notification/apps-evolution-mail-notification.schemas.in b/plugins/mail-notification/apps-evolution-mail-notification.schemas.in index c0a038068d..ad7dd91615 100644 --- a/plugins/mail-notification/apps-evolution-mail-notification.schemas.in +++ b/plugins/mail-notification/apps-evolution-mail-notification.schemas.in @@ -91,6 +91,17 @@ Sound file to be played when new messages arrive, if not in beep mode. + + /schemas/apps/evolution/eplugin/mail-notification/sound-use-theme + /apps/evolution/eplugin/mail-notification/sound-use-theme + evolution-mail + bool + false + + Use sound theme + Play themed sound when new messages arrive, if not in beep mode. + + diff --git a/plugins/mail-notification/mail-notification.c b/plugins/mail-notification/mail-notification.c index 9bc8458eb4..f48eaf3fa8 100644 --- a/plugins/mail-notification/mail-notification.c +++ b/plugins/mail-notification/mail-notification.c @@ -29,7 +29,7 @@ #include #include #include -#include +#include #ifdef HAVE_DBUS #include @@ -84,7 +84,7 @@ static GStaticMutex mlock = G_STATIC_MUTEX_INIT; static gboolean is_part_enabled (const gchar *gconf_key) { - /* the part is enabled by defaul */ + /* the part is enabled by default */ gboolean res = TRUE; GConfClient *client; GConfValue *is_key; @@ -276,12 +276,12 @@ icon_activated (GtkStatusIcon *icon, NotifyNotification *pnotify) icon_activated (GtkStatusIcon *icon, gpointer pnotify) #endif { - #ifdef HAVE_LIBNOTIFY +#ifdef HAVE_LIBNOTIFY if (notify) notify_notification_close (notify, NULL); notify = NULL; - #endif +#endif gtk_status_icon_set_visible (status_icon, FALSE); g_object_unref (status_icon); @@ -318,9 +318,9 @@ struct _StatusConfigureWidgets { GtkWidget *enable; GtkWidget *blink; - #ifdef HAVE_LIBNOTIFY +#ifdef HAVE_LIBNOTIFY GtkWidget *message; - #endif +#endif }; static void @@ -332,9 +332,9 @@ toggled_status_cb (GtkWidget *widget, gpointer data) g_return_if_fail (scw != NULL); g_return_if_fail (scw->enable != NULL); g_return_if_fail (scw->blink != NULL); - #ifdef HAVE_LIBNOTIFY +#ifdef HAVE_LIBNOTIFY g_return_if_fail (scw->message != NULL); - #endif +#endif enabl = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scw->enable)); if (widget == scw->enable) @@ -346,9 +346,9 @@ toggled_status_cb (GtkWidget *widget, gpointer data) set_part_enabled (key, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w))); work_widget (scw->blink, GCONF_KEY_STATUS_BLINK); - #ifdef HAVE_LIBNOTIFY +#ifdef HAVE_LIBNOTIFY work_widget (scw->message, GCONF_KEY_STATUS_NOTIFICATION); - #endif +#endif #undef work_widget } @@ -409,11 +409,11 @@ popup_menu_status (GtkStatusIcon *status_icon, guint button, guint activate_time menu = GTK_MENU (gtk_menu_new ()); item = gtk_image_menu_item_new_from_stock (GTK_STOCK_CLOSE, NULL); - #ifdef HAVE_LIBNOTIFY +#ifdef HAVE_LIBNOTIFY g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (icon_activated), notify); - #else +#else g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (icon_activated), NULL); - #endif +#endif gtk_widget_show (item); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); @@ -513,7 +513,7 @@ new_notify_status (EMEventTargetFolder *t) gtk_status_icon_set_visible (status_icon, TRUE); - #ifdef HAVE_LIBNOTIFY +#ifdef HAVE_LIBNOTIFY /* Now check whether we're supposed to send notifications */ if (is_part_enabled (GCONF_KEY_STATUS_NOTIFICATION)) { if (notify) { @@ -534,16 +534,16 @@ new_notify_status (EMEventTargetFolder *t) } } } - #endif +#endif g_free (msg); if (new_icon) { - #ifdef HAVE_LIBNOTIFY +#ifdef HAVE_LIBNOTIFY g_signal_connect (G_OBJECT (status_icon), "activate", G_CALLBACK (icon_activated), notify); - #else +#else g_signal_connect (G_OBJECT (status_icon), "activate", G_CALLBACK (icon_activated), NULL); - #endif +#endif g_signal_connect (G_OBJECT (status_icon), "popup-menu", G_CALLBACK (popup_menu_status), NULL); } @@ -555,11 +555,11 @@ read_notify_status (EMEventTargetMessage *t) if (!status_icon) return; - #ifdef HAVE_LIBNOTIFY +#ifdef HAVE_LIBNOTIFY icon_activated (status_icon, notify); - #else +#else icon_activated (status_icon, NULL); - #endif +#endif } static void @@ -589,9 +589,9 @@ get_config_widget_status (void) parent = gtk_vbox_new (FALSE, 0); create_check (scw->blink, GCONF_KEY_STATUS_BLINK, _("B_link icon in notification area")); - #ifdef HAVE_LIBNOTIFY +#ifdef HAVE_LIBNOTIFY create_check (scw->message, GCONF_KEY_STATUS_NOTIFICATION, _("Popup _message together with the icon")); - #endif +#endif alignment = gtk_alignment_new (0.0, 0.0, 1.0, 1.0); gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 20, 0); @@ -618,22 +618,32 @@ get_config_widget_status (void) #define GCONF_KEY_SOUND_BEEP GCONF_KEY_ROOT "sound-beep" #define GCONF_KEY_SOUND_FILE GCONF_KEY_ROOT "sound-file" +#define GCONF_KEY_SOUND_USE_THEME GCONF_KEY_ROOT "sound-use-theme" + +static ca_context *mailnotification = NULL; static void -do_play_sound (gboolean beep, const gchar *file) -{ - if (beep) - gdk_beep (); - else if (!file || !*file) - g_warning ("No file to play!"); +do_play_sound (gboolean beep, gboolean use_theme, const gchar *file) +{ + if (!beep) { + if ( (file || *file) && !use_theme ) + ca_context_play(mailnotification, 0, + CA_PROP_MEDIA_FILENAME, file, + NULL); + else + ca_context_play(mailnotification, 0, + CA_PROP_EVENT_ID,"message-new-email", + NULL); + } else - gnome_sound_play (file); + gdk_beep(); } struct _SoundConfigureWidgets { GtkWidget *enable; GtkWidget *beep; + GtkWidget *use_theme; GtkWidget *file; GtkWidget *label; GtkWidget *filechooser; @@ -649,6 +659,7 @@ toggled_sound_cb (GtkWidget *widget, gpointer data) g_return_if_fail (data != NULL); g_return_if_fail (scw->enable != NULL); g_return_if_fail (scw->beep != NULL); + g_return_if_fail (scw->use_theme != NULL); g_return_if_fail (scw->file != NULL); g_return_if_fail (scw->label != NULL); g_return_if_fail (scw->filechooser != NULL); @@ -659,13 +670,21 @@ toggled_sound_cb (GtkWidget *widget, gpointer data) set_part_enabled (GCONF_KEY_ENABLED_SOUND, enabl); gtk_widget_set_sensitive (scw->beep, enabl); + gtk_widget_set_sensitive (scw->use_theme, enabl); gtk_widget_set_sensitive (scw->file, enabl); gtk_widget_set_sensitive (scw->label, enabl); - gtk_widget_set_sensitive (scw->filechooser, enabl && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scw->file))); + gtk_widget_set_sensitive (scw->filechooser, enabl + && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scw->file)) + && !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scw->use_theme))); gtk_widget_set_sensitive (scw->play, enabl); - if (widget == scw->beep || widget == scw->file) + if (widget == scw->beep || widget == scw->file || widget == scw->use_theme) set_part_enabled (GCONF_KEY_SOUND_BEEP, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scw->beep))); + + if (widget == scw->use_theme) { + set_part_enabled (GCONF_KEY_SOUND_USE_THEME, gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON (scw->use_theme))); + set_part_enabled (GCONF_KEY_SOUND_BEEP, FALSE); + } } static void @@ -697,7 +716,9 @@ sound_play_cb (GtkWidget *widget, gpointer data) return; file = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (scw->filechooser)); - do_play_sound (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scw->beep)), file); + do_play_sound (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (scw->beep)), + gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (scw->use_theme)), + file); g_free (file); } @@ -717,8 +738,10 @@ sound_notify_idle_cb (gpointer user_data) client = gconf_client_get_default (); file = gconf_client_get_string (client, GCONF_KEY_SOUND_FILE, NULL); - - do_play_sound (is_part_enabled (GCONF_KEY_SOUND_BEEP), file); + + do_play_sound (is_part_enabled (GCONF_KEY_SOUND_BEEP), + is_part_enabled (GCONF_KEY_SOUND_USE_THEME), + file); g_object_unref (client); g_free (file); @@ -754,10 +777,14 @@ read_notify_sound (EMEventTargetMessage *t) static void enable_sound (gint enable) { - if (enable) - gnome_sound_init ("localhost"); + if (enable){ + ca_context_create(&mailnotification); + ca_context_change_props(mailnotification, + CA_PROP_APPLICATION_NAME, "mailnotification Plugin", + NULL); + } else - gnome_sound_shutdown (); + ca_context_destroy(mailnotification); } static GtkWidget * @@ -778,14 +805,18 @@ get_config_widget_sound (void) parent = gtk_vbox_new (FALSE, 0); scw->beep = gtk_radio_button_new_with_mnemonic (NULL, _("_Beep")); + scw->use_theme = gtk_radio_button_new_with_mnemonic_from_widget (GTK_RADIO_BUTTON (scw->beep), _("Use sound _theme")); scw->file = gtk_radio_button_new_with_mnemonic_from_widget (GTK_RADIO_BUTTON (scw->beep), _("Play _sound file")); if (is_part_enabled (GCONF_KEY_SOUND_BEEP)) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (scw->beep), TRUE); + else if (is_part_enabled (GCONF_KEY_SOUND_USE_THEME)) + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (scw->use_theme), TRUE); else gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (scw->file), TRUE); g_signal_connect (G_OBJECT (scw->beep), "toggled", G_CALLBACK (toggled_sound_cb), scw); + g_signal_connect (G_OBJECT (scw->use_theme), "toggled", G_CALLBACK (toggled_sound_cb), scw); g_signal_connect (G_OBJECT (scw->file), "toggled", G_CALLBACK (toggled_sound_cb), scw); hbox = gtk_hbox_new (FALSE, 0); @@ -813,6 +844,7 @@ get_config_widget_sound (void) gtk_box_pack_start (GTK_BOX (hbox), scw->play, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (parent), scw->beep, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (parent), scw->use_theme, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (parent), scw->file, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (parent), hbox, FALSE, FALSE, 0); diff --git a/shell/main.c b/shell/main.c index a8a385025a..f27961dbd2 100644 --- a/shell/main.c +++ b/shell/main.c @@ -56,7 +56,6 @@ #include #include -#include #include @@ -635,7 +634,6 @@ main (gint argc, gchar **argv) exit (0); categories_icon_theme_hack (); - gnome_sound_init ("localhost"); gtk_accel_map_load (e_get_accels_filename ()); if (!disable_eplugin) { @@ -675,7 +673,6 @@ main (gint argc, gchar **argv) gtk_accel_map_save (e_get_accels_filename ()); e_icon_factory_shutdown (); - gnome_sound_shutdown (); e_cursors_shutdown (); #ifdef G_OS_WIN32 link_shutdown (); -- cgit v1.2.3