From 3eb84c8a0312fd0d1be89b091d8d6a4dd315d3d9 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Fri, 30 Jan 2009 17:07:26 +0000 Subject: Implement a logic for disabling notifications when away. svn path=/trunk/; revision=2282 --- libempathy-gtk/empathy-ui-utils.c | 55 +++++++++++++++++++++++++++++++++------ libempathy-gtk/empathy-ui-utils.h | 3 +++ 2 files changed, 50 insertions(+), 8 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c index effeb7a01..7b55587ea 100644 --- a/libempathy-gtk/empathy-ui-utils.c +++ b/libempathy-gtk/empathy-ui-utils.c @@ -1572,13 +1572,29 @@ static EmpathySoundEntry sound_entries[LAST_EMPATHY_SOUND] = { N_("Voice call ended"), NULL }, }; +static gboolean +check_available (void) +{ + McPresence presence; + EmpathyIdle *idle; + + idle = empathy_idle_dup_singleton (); + presence = empathy_idle_get_state (idle); + g_object_unref (idle); + + if (presence != MC_PRESENCE_AVAILABLE && + presence != MC_PRESENCE_UNSET) { + return FALSE; + } + + return TRUE; +} + static gboolean empathy_sound_pref_is_enabled (const char *key) { EmpathyConf *conf; - McPresence presence; gboolean res; - EmpathyIdle *idle; conf = empathy_conf_get (); res = FALSE; @@ -1589,12 +1605,7 @@ empathy_sound_pref_is_enabled (const char *key) return FALSE; } - idle = empathy_idle_dup_singleton (); - presence = empathy_idle_get_state (idle); - g_object_unref (idle); - - if (presence != MC_PRESENCE_AVAILABLE && - presence != MC_PRESENCE_UNSET) { + if (!check_available ()) { empathy_conf_get_bool (conf, EMPATHY_PREFS_SOUNDS_DISABLED_AWAY, &res); if (res) { @@ -1634,3 +1645,31 @@ empathy_sound_play (GtkWidget *widget, NULL); } } + +gboolean +empathy_notification_should_show (void) +{ + EmpathyConf *conf; + gboolean res; + + conf = empathy_conf_get (); + res = FALSE; + + empathy_conf_get_bool (conf, EMPATHY_PREFS_NOTIFICATIONS_ENABLED, &res); + + if (!res) { + return FALSE; + } + + if (!check_available ()) { + empathy_conf_get_bool (conf, + EMPATHY_PREFS_NOTIFICATIONS_DISABLED_AWAY, + &res); + if (res) { + return FALSE; + } + } + + return TRUE; +} + diff --git a/libempathy-gtk/empathy-ui-utils.h b/libempathy-gtk/empathy-ui-utils.h index 108b7bb89..b3b26f0bb 100644 --- a/libempathy-gtk/empathy-ui-utils.h +++ b/libempathy-gtk/empathy-ui-utils.h @@ -131,6 +131,9 @@ void empathy_send_file_with_file_chooser (EmpathyContact *conta void empathy_sound_play (GtkWidget *widget, EmpathySound sound_id); +/* Notifications */ +gboolean empathy_notification_should_show (void); + G_END_DECLS #endif /* __EMPATHY_UI_UTILS_H__ */ -- cgit v1.2.3