[balsa/77-notification] simplify playing new mail sound
- From: Albrecht Dreß <albrecht src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [balsa/77-notification] simplify playing new mail sound
- Date: Mon, 23 May 2022 16:36:15 +0000 (UTC)
commit 9b52d5c98947ebd32b4ce5aa62486ac216d5c4ec
Author: Albrecht Dreß <albrecht dress netcologne de>
Date: Mon May 23 18:36:10 2022 +0200
simplify playing new mail sound
Instead of selecting a user-defined new message sound file use the
standard one.
- libbalsa.[ch]: replace canberra helper by two ones for playing an
event or a file
- libbalsa/filter.c: use new play sound file helper
- src/balsa-app.[ch], src/save-restore.c: drop new mail sound file
variable
- src/main-window.c: play standard "message-new-email" event sound if
enabled
- src/pref-manager.c: drop gui element for selecting and playing a new
message sound file
Signed-off-by: Albrecht Dreß <albrecht dress netcologne de>
libbalsa/filter.c | 2 +-
libbalsa/libbalsa.c | 24 +++++++++++++++++----
libbalsa/libbalsa.h | 5 ++++-
src/balsa-app.c | 1 -
src/balsa-app.h | 1 -
src/main-window.c | 7 +++---
src/pref-manager.c | 61 +----------------------------------------------------
src/save-restore.c | 3 ---
8 files changed, 29 insertions(+), 75 deletions(-)
---
diff --git a/libbalsa/filter.c b/libbalsa/filter.c
index 565f88365..017fd2e1d 100644
--- a/libbalsa/filter.c
+++ b/libbalsa/filter.c
@@ -245,7 +245,7 @@ libbalsa_filter_mailbox_messages(LibBalsaFilter * filt,
#if HAVE_CANBERRA
if (filt->sound) {
- if (!libbalsa_play_sound(filt->sound, &err)) {
+ if (!libbalsa_play_sound_file(filt->sound, &err)) {
g_warning("%s: %s", __func__, (err != NULL) ? err->message : "unknown");
g_clear_error(&err);
}
diff --git a/libbalsa/libbalsa.c b/libbalsa/libbalsa.c
index ec5fb116a..d7be8e10a 100644
--- a/libbalsa/libbalsa.c
+++ b/libbalsa/libbalsa.c
@@ -701,17 +701,33 @@ libbalsa_source_view_new(gboolean highlight_phrases)
#if HAVE_CANBERRA
gboolean
-libbalsa_play_sound(const gchar *soundfile, GError **error)
+libbalsa_play_sound_event(const gchar *event_id, GError **error)
{
GdkScreen *screen;
gint rc;
- g_return_val_if_fail(soundfile != NULL, FALSE);
+ g_return_val_if_fail(event_id != NULL, FALSE);
screen = gdk_screen_get_default();
- rc = ca_context_play(ca_gtk_context_get_for_screen(screen), 0, CA_PROP_MEDIA_FILENAME, soundfile,
NULL);
+ rc = ca_context_play(ca_gtk_context_get_for_screen(screen), 0, CA_PROP_EVENT_ID, event_id, NULL);
if (rc != 0) {
- g_set_error(error, LIBBALSA_ERROR_QUARK, rc, _("Cannot play sound file “%s”: %s"), soundfile,
ca_strerror(rc));
+ g_set_error(error, LIBBALSA_ERROR_QUARK, rc, _("Cannot play sound event “%s”: %s"), event_id,
ca_strerror(rc));
+ }
+ return rc == 0;
+}
+
+gboolean
+libbalsa_play_sound_file(const gchar *filename, GError **error)
+{
+ GdkScreen *screen;
+ gint rc;
+
+ g_return_val_if_fail(filename != NULL, FALSE);
+
+ screen = gdk_screen_get_default();
+ rc = ca_context_play(ca_gtk_context_get_for_screen(screen), 0, CA_PROP_MEDIA_FILENAME, filename,
NULL);
+ if (rc != 0) {
+ g_set_error(error, LIBBALSA_ERROR_QUARK, rc, _("Cannot play sound file “%s”: %s"), filename,
ca_strerror(rc));
}
return rc == 0;
}
diff --git a/libbalsa/libbalsa.h b/libbalsa/libbalsa.h
index 0d048e047..f9cc0b903 100644
--- a/libbalsa/libbalsa.h
+++ b/libbalsa/libbalsa.h
@@ -191,7 +191,10 @@ GtkWidget *libbalsa_source_view_new(gboolean highlight_phrases);
#endif /* HAVE_GTKSOURCEVIEW */
#ifdef HAVE_CANBERRA
-gboolean libbalsa_play_sound(const gchar *soundfile, GError **error);
+gboolean libbalsa_play_sound_event(const gchar *event_id,
+ GError **error);
+gboolean libbalsa_play_sound_file(const gchar *filename,
+ GError **error);
#endif /* HAVE_CANBERRA*/
#endif /* __LIBBALSA_H__ */
diff --git a/src/balsa-app.c b/src/balsa-app.c
index 88c07e589..0b5bcb31e 100644
--- a/src/balsa-app.c
+++ b/src/balsa-app.c
@@ -414,7 +414,6 @@ balsa_app_init(void)
#ifdef HAVE_CANBERRA
balsa_app.notify_new_mail_sound = 0;
- balsa_app.new_mail_sound_file = NULL;
#endif
balsa_app.notify_new_mail_dialog = 0;
diff --git a/src/balsa-app.h b/src/balsa-app.h
index c9e2c4c37..51c006aec 100644
--- a/src/balsa-app.h
+++ b/src/balsa-app.h
@@ -169,7 +169,6 @@ extern struct BalsaApplication {
#ifdef HAVE_CANBERRA
gint notify_new_mail_sound;
- gchar *new_mail_sound_file;
#endif
gint notify_new_mail_dialog;
diff --git a/src/main-window.c b/src/main-window.c
index a5c32749e..fd7cc8e25 100644
--- a/src/main-window.c
+++ b/src/main-window.c
@@ -3717,12 +3717,11 @@ bw_display_new_mail_notification(int num_new, int has_new)
#ifdef HAVE_CANBERRA
/* play sound if configured, but not too frequently (min. 30 seconds in between)*/
now = g_get_monotonic_time();
- if ((balsa_app.notify_new_mail_sound != 0) && (balsa_app.new_mail_sound_file != NULL) &&
- (now > (last_new_mail_sound + 30 * 1000000))) {
+ if ((balsa_app.notify_new_mail_sound != 0) && (now > (last_new_mail_sound + 30 * 1000000))) {
GError *error = NULL;
- if (!libbalsa_play_sound(balsa_app.new_mail_sound_file, &error)) {
- g_warning("%s: %s", __func__, (error != NULL) ? error->message : "unknown");
+ if (!libbalsa_play_sound_event("message-new-email", &error)) {
+ g_warning("%s: %s", __func__, error->message);
g_clear_error(&error);
} else {
last_new_mail_sound = now;
diff --git a/src/pref-manager.c b/src/pref-manager.c
index e8521cc51..501e74634 100644
--- a/src/pref-manager.c
+++ b/src/pref-manager.c
@@ -93,8 +93,6 @@ typedef struct _PropertyUI {
GtkWidget *notify_new_mail_dialog;
#ifdef HAVE_CANBERRA
GtkWidget *notify_new_mail_sound;
- GtkWidget *new_mail_sound_file;
- GtkWidget *new_mail_sound_play;
#endif
GtkWidget *mdn_reply_clean_menu, *mdn_reply_notclean_menu;
@@ -479,9 +477,6 @@ apply_prefs(GtkDialog * pbox)
balsa_app.notify_new_mail_sound =
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
(pui->notify_new_mail_sound));
- g_free(balsa_app.new_mail_sound_file);
- balsa_app.new_mail_sound_file =
- gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(pui->new_mail_sound_file));
#endif
balsa_app.mdn_reply_clean =
@@ -740,8 +735,6 @@ set_prefs(void)
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON
(pui->notify_new_mail_sound),
balsa_app.notify_new_mail_sound);
- gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(pui->new_mail_sound_file),
- balsa_app.new_mail_sound_file);
#endif
if (!balsa_app.check_imap)
@@ -1756,47 +1749,6 @@ timer_modified_cb(GtkWidget * widget, GtkWidget * pbox)
properties_modified_cb(widget, pbox);
}
-#ifdef HAVE_CANBERRA
-static void
-sound_modified_cb(GtkWidget *widget, GtkWidget *pbox)
-{
- gboolean newstate;
-
- newstate = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pui->notify_new_mail_sound));
-
- gtk_widget_set_sensitive(pui->new_mail_sound_file, newstate);
- if (newstate) {
- gchar *soundfile;
-
- soundfile = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(pui->new_mail_sound_file));
- gtk_widget_set_sensitive(pui->new_mail_sound_play, soundfile != NULL);
- g_free(soundfile);
- } else {
- gtk_widget_set_sensitive(pui->new_mail_sound_play, FALSE);
- }
- properties_modified_cb(widget, pbox);
-}
-
-static void
-sound_play(GtkWidget G_GNUC_UNUSED *widget, gpointer G_GNUC_UNUSED data)
-{
- if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pui->notify_new_mail_sound))) {
- gchar *soundfile;
-
- soundfile = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(pui->new_mail_sound_file));
- if (soundfile != NULL) {
- GError *error = NULL;
-
- if (!libbalsa_play_sound(soundfile, &error)) {
- libbalsa_information(LIBBALSA_INFORMATION_ERROR, "%s", (error != NULL) ?
error->message : _("unknown"));
- g_clear_error(&error);
- }
- g_free(soundfile);
- }
- }
-}
-#endif /* HAVE_CANBERRA */
-
static void
send_timer_modified_cb(GtkWidget * widget, GtkWidget * pbox)
{
@@ -2235,13 +2187,6 @@ pm_grid_add_new_mail_notify_group(GtkWidget * grid_widget)
#ifdef HAVE_CANBERRA
pui->notify_new_mail_sound = gtk_check_button_new_with_label(_("Play sound"));
pm_grid_attach(grid, pui->notify_new_mail_sound, 1, ++row, 1, 1);
-
- pui->new_mail_sound_file = gtk_file_chooser_button_new(_("New message sound"),
GTK_FILE_CHOOSER_ACTION_OPEN);
- pm_grid_attach(grid, pui->new_mail_sound_file, 2, row, 1, 1);
-
- pui->new_mail_sound_play = gtk_button_new_from_icon_name("media-playback-start",
GTK_ICON_SIZE_SMALL_TOOLBAR);
- pm_grid_attach(grid, pui->new_mail_sound_play, 3, row, 1, 1);
- gtk_widget_set_halign(pui->new_mail_sound_play, GTK_ALIGN_START);
#endif
pm_grid_set_next_row(grid, ++row);
@@ -3512,11 +3457,7 @@ open_preferences_manager(GtkWidget * widget, gpointer data)
#ifdef HAVE_CANBERRA
g_signal_connect(pui->notify_new_mail_sound, "toggled",
- G_CALLBACK(sound_modified_cb), property_box);
- g_signal_connect(pui->new_mail_sound_file, "selection-changed",
- G_CALLBACK(sound_modified_cb), property_box);
- g_signal_connect(pui->new_mail_sound_play, "clicked",
- G_CALLBACK(sound_play), property_box);
+ G_CALLBACK(properties_modified_cb), property_box);
#endif
g_signal_connect(pui->close_mailbox_auto, "toggled",
diff --git a/src/save-restore.c b/src/save-restore.c
index a020c61c2..5e8e630f4 100644
--- a/src/save-restore.c
+++ b/src/save-restore.c
@@ -983,8 +983,6 @@ config_global_load(void)
#ifdef HAVE_CANBERRA
balsa_app.notify_new_mail_sound =
d_get_gint("NewMailNotificationSound", 0);
- balsa_app.new_mail_sound_file =
- libbalsa_conf_get_string("NewMailNotificationSoundFile");
#endif
balsa_app.check_mail_upon_startup =
libbalsa_conf_get_bool("OnStartup=false");
@@ -1444,7 +1442,6 @@ config_save(void)
#ifdef HAVE_CANBERRA
libbalsa_conf_set_int("NewMailNotificationSound",
balsa_app.notify_new_mail_sound);
- libbalsa_conf_set_string("NewMailNotificationSoundFile", balsa_app.new_mail_sound_file);
#endif
libbalsa_conf_set_bool("OnStartup", balsa_app.check_mail_upon_startup);
libbalsa_conf_set_bool("Auto", balsa_app.check_mail_auto);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]