]> git.0d.be Git - empathy.git/commitdiff
Update empathy_sound_play () to be nicer to use and centralize the list
authorXavier Claessens <xclaesse@src.gnome.org>
Tue, 6 Jan 2009 16:49:01 +0000 (16:49 +0000)
committerXavier Claessens <xclaesse@src.gnome.org>
Tue, 6 Jan 2009 16:49:01 +0000 (16:49 +0000)
of sounds we support.

svn path=/trunk/; revision=2082

libempathy-gtk/empathy-ui-utils.c
libempathy-gtk/empathy-ui-utils.h
python/pyempathygtk/pyempathygtk.defs
src/empathy-call-window.c
src/empathy-chat-window.c
src/empathy-main-window.c

index f937ce110e2c0f6cdb19553773d86d4d91b864df..7c125a57b6e8c3ae96d3b32a523d7c336f14b69c 100644 (file)
@@ -1493,6 +1493,36 @@ empathy_send_file_with_file_chooser (EmpathyContact *contact)
        gtk_widget_show (widget);
 }
 
+typedef struct {
+       EmpathySound sound_id;
+       const char * event_ca_id;
+       const char * event_ca_description;
+       const char * gconf_key;
+} EmpathySoundEntry;
+
+static EmpathySoundEntry sound_entries[LAST_EMPATHY_SOUND] = {
+       { EMPATHY_SOUND_MESSAGE_INCOMING, "message-new-instant",
+         N_("Received an instant message"), EMPATHY_PREFS_SOUNDS_INCOMING_MESSAGE } ,
+       { EMPATHY_SOUND_MESSAGE_OUTGOING, "message-sent-instant",
+         N_("Sent an instant message"), EMPATHY_PREFS_SOUNDS_OUTGOING_MESSAGE } ,
+       { EMPATHY_SOUND_CONVERSATION_NEW, "message-new-instant",
+         N_("Incoming chat request"), EMPATHY_PREFS_SOUNDS_NEW_CONVERSATION },
+       { EMPATHY_SOUND_CONTACT_CONNECTED, "service-login",
+         N_("Contact connected"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGIN },
+       { EMPATHY_SOUND_CONTACT_DISCONNECTED, "service-logout",
+         N_("Contact disconnected"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGOUT },
+       { EMPATHY_SOUND_ACCOUNT_CONNECTED, "service-login",
+         N_("Connected to server"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGIN },
+       { EMPATHY_SOUND_ACCOUNT_DISCONNECTED, "service-logout",
+         N_("Disconnected from server"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGOUT },
+       { EMPATHY_SOUND_PHONE_INCOMING, "phone-incoming-call",
+         N_("Incoming voice call"), NULL },
+       { EMPATHY_SOUND_PHONE_OUTGOING, "phone-outgoing-calling",
+         N_("Outgoing voice call"), NULL },
+       { EMPATHY_SOUND_PHONE_HANGUP, "phone-hangup",
+         N_("Voice call ended"), NULL },
+};
+
 static gboolean
 empathy_sound_pref_is_enabled (const char *key)
 {
@@ -1530,14 +1560,19 @@ empathy_sound_pref_is_enabled (const char *key)
 
 void
 empathy_sound_play (GtkWidget *widget,
-                   const char *key,
-                   const char *event_id,
-                   const char *description)
+                   EmpathySound sound_id)
 {
-       if (empathy_sound_pref_is_enabled (key)) {
+       EmpathySoundEntry *entry = &(sound_entries[sound_id]);
+       gboolean should_play = TRUE;
+
+       if (entry->gconf_key != NULL) {
+               should_play = empathy_sound_pref_is_enabled (entry->gconf_key);
+       }
+
+       if (should_play) {
                ca_gtk_play_for_widget (widget, 0,
-                                       CA_PROP_EVENT_ID, event_id,
-                                       CA_PROP_EVENT_DESCRIPTION, description,
+                                       CA_PROP_EVENT_ID, entry->event_ca_id,
+                                       CA_PROP_EVENT_DESCRIPTION, entry->event_ca_description,
                                        NULL);
        }
 }
\ No newline at end of file
index 285b66452c42c31b14c65ccdee08cb1f2e4568f5..0ed291af7cf27d5e4d3197916c16899abd68309c 100644 (file)
 
 G_BEGIN_DECLS
 
+typedef enum {
+       EMPATHY_SOUND_MESSAGE_INCOMING,
+       EMPATHY_SOUND_MESSAGE_OUTGOING,
+       EMPATHY_SOUND_CONVERSATION_NEW,
+       EMPATHY_SOUND_CONTACT_CONNECTED,
+       EMPATHY_SOUND_CONTACT_DISCONNECTED,
+       EMPATHY_SOUND_ACCOUNT_CONNECTED,
+       EMPATHY_SOUND_ACCOUNT_DISCONNECTED,
+       EMPATHY_SOUND_PHONE_INCOMING,
+       EMPATHY_SOUND_PHONE_OUTGOING,
+       EMPATHY_SOUND_PHONE_HANGUP,
+       LAST_EMPATHY_SOUND
+} EmpathySound;
+
 #define G_STR_EMPTY(x) ((x) == NULL || (x)[0] == '\0')
 
 void            empathy_gtk_init                        (void);
@@ -116,9 +130,7 @@ void        empathy_send_file_with_file_chooser         (EmpathyContact   *conta
 
 /* Sounds */
 void        empathy_sound_play                          (GtkWidget        *widget,
-                                                        const char       *key,
-                                                        const char       *event_id,
-                                                        const char       *description);
+                                                        EmpathySound      sound_id);
 
 G_END_DECLS
 
index 3c83a28ec52a501d29b237e954ea17375c0970aa..574bbcd1fa53753eecca45114a55d721bbe080bf 100644 (file)
   )
 )
 
+(define-enum Sound
+  (in-module "Empathy")
+  (c-name "EmpathySound")
+  (gtype-id "EMPATHY_TYPE_SOUND")
+  (values
+    '("empathy-sound-message-incoming" "EMPATHY_SOUND_MESSAGE_INCOMING")
+    '("empathy-sound-message-outgoing" "EMPATHY_SOUND_MESSAGE_OUTGOING")
+    '("empathy-sound-conversation-new" "EMPATHY_SOUND_CONVERSATION_NEW")
+    '("empathy-sound-contact-connected" "EMPATHY_SOUND_CONTACT_CONNECTED")
+    '("empathy-sound-contact-disconnected" "EMPATHY_SOUND_CONTACT_DISCONNECTED")
+    '("empathy-sound-account-connected" "EMPATHY_SOUND_ACCOUNT_CONNECTED")
+    '("empathy-sound-account-disconnected" "EMPATHY_SOUND_ACCOUNT_DISCONNECTED")
+    '("empathy-sound-phone-incoming" "EMPATHY_SOUND_PHONE_INCOMING")
+    '("empathy-sound-phone-outgoing" "EMPATHY_SOUND_PHONE_OUTGOING")
+    '("empathy-sound-phone-hangup" "EMPATHY_SOUND_PHONE_HANGUP")
+    '("last-empathy-sound" "LAST_EMPATHY_SOUND")
+  )
+)
+
 
 ;; From empathy-account-chooser.h
 
   (return-type "none")
   (parameters
     '("GtkWidget*" "widget")
-    '("const-char*" "key")
-    '("const-char*" "event_id")
-    '("const-char*" "description")
+    '("EmpathySound" "sound_id")
   )
 )
 
index 4c6777d623c3deaaaa9a1fa8988e411aa524adda..324f37c1e74f6877e6ab0ca1e6e9edef7987ae88 100644 (file)
@@ -25,7 +25,6 @@
 
 #include <glade/glade.h>
 #include <glib/gi18n.h>
-#include <canberra-gtk.h>
 
 #include <telepathy-glib/enums.h>
 
@@ -195,10 +194,9 @@ static void
 call_window_hang_up_button_clicked_cb (GtkWidget *widget,
                                        EmpathyCallWindow *window)
 {
-  ca_gtk_play_for_widget (GTK_WIDGET (window->window), 0,
-                          CA_PROP_EVENT_ID, "phone-hangup",
-                          CA_PROP_EVENT_DESCRIPTION, _("Voice call ended"),
-                          NULL);
+  empathy_sound_play (GTK_WIDGET (window->window),
+                     EMPATHY_SOUND_PHONE_HANGUP);
+
   DEBUG ("Call clicked, end call");
   call_window_finalize (window);
 }
@@ -403,19 +401,14 @@ call_window_update (EmpathyCallWindow *window)
       if (is_incoming)
         {
           call_window_show_confirmation_dialog (window);
-          ca_gtk_play_for_widget (GTK_WIDGET (window->window), 0,
-                                  CA_PROP_EVENT_ID, "phone-incoming-call",
-                                  CA_PROP_EVENT_DESCRIPTION, _("Incoming voice call"),
-                                  NULL);
+          empathy_sound_play (GTK_WIDGET (window->window),
+                             EMPATHY_SOUND_PHONE_INCOMING);
         }
       else
         {
-          ca_gtk_play_for_widget (GTK_WIDGET (window->window), 0,
-                                  CA_PROP_EVENT_ID, "phone-outgoing-calling",
-                                  CA_PROP_EVENT_DESCRIPTION, _("Outgoing voice call"),
-                                  NULL);
-        }
-
+          empathy_sound_play (GTK_WIDGET (window->window),
+                             EMPATHY_SOUND_PHONE_OUTGOING);
+       }
     }
   else if (window->status == EMPATHY_TP_CALL_STATUS_ACCEPTED)
     {
index 2c97301a52e7bce9eb2a40504081aa7b39dda1e3..c6b23b68dbff6af974b95ad19e7e78250451b3af 100644 (file)
@@ -858,13 +858,11 @@ chat_window_new_message_cb (EmpathyChat       *chat,
 
        if (empathy_contact_is_user (sender) != FALSE) {
                empathy_sound_play (GTK_WIDGET (priv->dialog),
-                                   EMPATHY_PREFS_SOUNDS_OUTGOING_MESSAGE,
-                                   "message-sent-instant", _("Sent an instant message"));
+                                   EMPATHY_SOUND_MESSAGE_OUTGOING);
        } else {
                if ((!has_focus || priv->current_chat != chat)) {
                        empathy_sound_play (GTK_WIDGET (priv->dialog),
-                                           EMPATHY_PREFS_SOUNDS_INCOMING_MESSAGE,
-                                           "message-new-instant", _("Received an instant message"));
+                                           EMPATHY_SOUND_MESSAGE_INCOMING);
                }
        }
 
index 07f4b9f7d828e334a574336fec42937952c49f1b..f034638e3abac698a6c86a6170d342704f0b36b1 100644 (file)
@@ -284,8 +284,7 @@ static void
 main_window_flash_start (EmpathyMainWindow *window)
 {
        empathy_sound_play (GTK_WIDGET (window->window),
-                           EMPATHY_PREFS_SOUNDS_NEW_CONVERSATION,
-                           "message-new-instant", _("Incoming chat request"));
+                           EMPATHY_SOUND_CONVERSATION_NEW);
 
        if (window->flash_timeout_id != 0) {
                return;
@@ -431,16 +430,14 @@ main_window_connection_changed_cb (EmpathyAccountManager *manager,
 
        if (current == TP_CONNECTION_STATUS_DISCONNECTED) {
                empathy_sound_play (GTK_WIDGET (window->window),
-                                   EMPATHY_PREFS_SOUNDS_SERVICE_LOGOUT,
-                                   "service-logout", _("Disconnected from server"));
+                                   EMPATHY_SOUND_ACCOUNT_DISCONNECTED);
        }
 
        if (current == TP_CONNECTION_STATUS_CONNECTED) {
                GtkWidget *error_widget;
 
                empathy_sound_play (GTK_WIDGET (window->window),
-                                   EMPATHY_PREFS_SOUNDS_SERVICE_LOGIN,
-                                   "service-login", _("Connected to server"));
+                                   EMPATHY_SOUND_ACCOUNT_CONNECTED);
 
                /* Account connected without error, remove error message if any */
                error_widget = g_hash_table_lookup (window->errors, account);
@@ -471,16 +468,14 @@ main_window_contact_presence_changed_cb (EmpathyContactMonitor *monitor,
        if (previous < MC_PRESENCE_AVAILABLE && current > MC_PRESENCE_OFFLINE) {
                /* someone is logging in */
                empathy_sound_play (GTK_WIDGET (window->window),
-                                   EMPATHY_PREFS_SOUNDS_CONTACT_LOGIN,
-                                   "service-login", _("Contact connected"));
+                                   EMPATHY_SOUND_CONTACT_CONNECTED);
                return;
        }
 
        if (previous > MC_PRESENCE_OFFLINE && current < MC_PRESENCE_AVAILABLE) {
                /* someone is logging off */
                empathy_sound_play (GTK_WIDGET (window->window),
-                                   EMPATHY_PREFS_SOUNDS_CONTACT_LOGOUT,
-                                   "service-logout", _("Contact disconnected"));
+                                   EMPATHY_SOUND_CONTACT_DISCONNECTED);
        }
 }