/pidgin/main: a9aa2aa0b1b6: Replace magic numbers on the sound API

Jorge Villase?or salinasv at pidgin.im
Wed Nov 25 02:20:01 EST 2015


Changeset: a9aa2aa0b1b647e461f4d03d2579d9b0a1c015dd
Author:	 Jorge Villase?or <salinasv at pidgin.im>
Date:	 2015-11-24 23:16 -0800
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/a9aa2aa0b1b6

Description:

Replace magic numbers on the sound API

Added an enum for the enable sound preference.
Added sound.c on the list to convert them to GEnums

diffstat:

 libpurple/Makefile.am |   1 +
 libpurple/sound.c     |  12 ++++--------
 libpurple/sound.h     |  10 +++++++++-
 pidgin/gtkprefs.c     |   6 +++---
 4 files changed, 17 insertions(+), 12 deletions(-)

diffs (97 lines):

diff --git a/libpurple/Makefile.am b/libpurple/Makefile.am
--- a/libpurple/Makefile.am
+++ b/libpurple/Makefile.am
@@ -262,6 +262,7 @@ purple_enumheaders = \
 	$(srcdir)/protocols.h \
 	$(srcdir)/roomlist.h \
 	$(srcdir)/status.h \
+	${srcdir}/sound.h \
 	$(srcdir)/xfer.h
 
 marshallers.h: marshallers.list
diff --git a/libpurple/sound.c b/libpurple/sound.c
--- a/libpurple/sound.c
+++ b/libpurple/sound.c
@@ -29,10 +29,6 @@
 #include "theme-manager.h"
 
 static PurpleSoundUiOps *sound_ui_ops = NULL;
-
-#define STATUS_AVAILABLE 1
-#define STATUS_AWAY 2
-
 static time_t last_played[PURPLE_NUM_SOUNDS];
 
 static gboolean
@@ -40,7 +36,7 @@ purple_sound_play_required(const PurpleA
 {
 	gint pref_status = purple_prefs_get_int("/purple/sound/while_status");
 
-	if (pref_status == 3)
+	if (pref_status == PURPLE_SOUND_STATUS_ALWAYS)
 	{
 		/* Play sounds: Always */
 		return TRUE;
@@ -53,8 +49,8 @@ purple_sound_play_required(const PurpleA
 		if (purple_status_is_online(status))
 		{
 			gboolean available = purple_status_is_available(status);
-			return (( available && pref_status == STATUS_AVAILABLE) ||
-			        (!available && pref_status == STATUS_AWAY));
+			return (( available && pref_status == PURPLE_SOUND_STATUS_AVAILABLE) ||
+			        (!available && pref_status == PURPLE_SOUND_STATUS_AWAY));
 		}
 	}
 
@@ -160,7 +156,7 @@ purple_sound_init()
 	                     G_TYPE_BOOLEAN, 2, G_TYPE_INT, PURPLE_TYPE_ACCOUNT);
 
 	purple_prefs_add_none("/purple/sound");
-	purple_prefs_add_int("/purple/sound/while_status", STATUS_AVAILABLE);
+	purple_prefs_add_int("/purple/sound/while_status", PURPLE_SOUND_STATUS_AVAILABLE);
 	memset(last_played, 0, sizeof(last_played));
 
 	purple_theme_manager_register_type(g_object_new(PURPLE_TYPE_SOUND_THEME_LOADER, "type", "sound", NULL));
diff --git a/libpurple/sound.h b/libpurple/sound.h
--- a/libpurple/sound.h
+++ b/libpurple/sound.h
@@ -24,7 +24,7 @@
 /**
  * SECTION:sound
  * @section_id: libpurple-sound
- * @short_description: <filename>sound.h</filename>
+ * @short_description: Sound subsystem definition.
  * @title: Sound API
  * @see_also: <link linkend="chapter-signals-sound">Sound signals</link>
  */
@@ -39,6 +39,14 @@
 typedef struct _PurpleSoundUiOps PurpleSoundUiOps;
 
 /**
+ */
+typedef enum {
+	PURPLE_SOUND_STATUS_AVAILABLE = 1,
+	PURPLE_SOUND_STATUS_AWAY,
+	PURPLE_SOUND_STATUS_ALWAYS,
+} PurpleSoundStatus;
+
+/**
  * PurpleSoundEventID:
  * @PURPLE_SOUND_BUDDY_ARRIVE:   Buddy signs on.
  * @PURPLE_SOUND_BUDDY_LEAVE:    Buddy signs off.
diff --git a/pidgin/gtkprefs.c b/pidgin/gtkprefs.c
--- a/pidgin/gtkprefs.c
+++ b/pidgin/gtkprefs.c
@@ -3246,9 +3246,9 @@ sound_page(void)
 				   PIDGIN_PREFS_ROOT "/sound/conv_focus", vbox);
 	pidgin_prefs_dropdown(vbox, _("_Enable sounds:"),
 				 PURPLE_PREF_INT, "/purple/sound/while_status",
-				_("Only when available"), 1,
-				_("Only when not available"), 2,
-				_("Always"), 3,
+				_("Only when available"), PURPLE_SOUND_STATUS_AVAILABLE,
+				_("Only when not available"), PURPLE_SOUND_STATUS_AWAY,
+				_("Always"), PURPLE_SOUND_STATUS_ALWAYS,
 				NULL);
 
 #ifdef USE_GSTREAMER



More information about the Commits mailing list