Mercurial > pidgin
changeset 25092:cf7625d4d7e0
Working sound themes (option 1) theme is saved in prefs and there is no seperate custom theme, everything
else is backwards compatiable, sound plays but the theme is not always found
author | Justin Rodriguez <ffdragon@soc.pidgin.im> |
---|---|
date | Fri, 27 Jun 2008 01:29:59 +0000 |
parents | 655a37bc0eb0 |
children | e8be608b6bab |
files | libpurple/sound-theme.c libpurple/sound-theme.h pidgin/gtkprefs.c pidgin/gtksound.c pidgin/gtksound.h |
diffstat | 5 files changed, 141 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/sound-theme.c Tue Jun 24 02:06:42 2008 +0000 +++ b/libpurple/sound-theme.c Fri Jun 27 01:29:59 2008 +0000 @@ -133,16 +133,19 @@ purple_sound_theme_get_file_full(PurpleSoundTheme *theme, const gchar *event) { - gchar *dir, *fname, *full; + gchar *dir, *filename, *full; g_return_val_if_fail(PURPLE_IS_SOUND_THEME(theme), NULL); dir = purple_theme_get_dir(PURPLE_THEME(theme)); - fname = purple_sound_theme_get_file(theme, event); - full = g_build_filename(dir, fname, NULL); + filename = purple_sound_theme_get_file(theme, event); + + g_return_val_if_fail(filename, NULL); + + full = g_build_filename(dir, filename, NULL); g_free(dir); - g_free(fname); + g_free(filename); return full; } @@ -150,16 +153,16 @@ void purple_sound_theme_set_file(PurpleSoundTheme *theme, const gchar *event, - const gchar *fname) + const gchar *filename) { PurpleSoundThemePrivate *priv; g_return_if_fail(PURPLE_IS_SOUND_THEME(theme)); priv = PURPLE_SOUND_THEME_GET_PRIVATE(theme); - if (fname)g_hash_table_replace(priv->sound_files, + if (filename)g_hash_table_replace(priv->sound_files, g_strdup(event), - g_strdup(fname)); + g_strdup(filename)); else g_hash_table_remove(priv->sound_files, event); }
--- a/libpurple/sound-theme.h Tue Jun 24 02:06:42 2008 +0000 +++ b/libpurple/sound-theme.h Fri Jun 27 01:29:59 2008 +0000 @@ -92,11 +92,11 @@ * Sets the filename for a given sound event * * @param event the purple sound event to look up - * @param fname the name of the file to be used for the event + * @param filename the name of the file to be used for the event */ void purple_sound_theme_set_file(PurpleSoundTheme *theme, const gchar *event, - const gchar *fname); + const gchar *filename); G_END_DECLS #endif /* _PURPLE_SOUND_THEME_H_ */
--- a/pidgin/gtkprefs.c Tue Jun 24 02:06:42 2008 +0000 +++ b/pidgin/gtkprefs.c Fri Jun 27 01:29:59 2008 +0000 @@ -73,6 +73,7 @@ static gboolean prefs_themes_unsorted = TRUE; static GtkListStore *prefs_sound_themes; +static GtkTreeIter prefs_sound_iter; /* * PROTOTYPES @@ -551,40 +552,92 @@ gtk_drag_finish(dc, FALSE, FALSE, t); } +/* sets the current sound theme to customized or NULL */ +static void +pref_set_sound_customized() +{ + if (pidgin_sound_is_customized()) + gtk_list_store_set(prefs_sound_themes, &prefs_sound_iter, 2, "(Custom)", -1); + else gtk_list_store_set(prefs_sound_themes, &prefs_sound_iter, 2, NULL, -1); +} + +/* adds the themes to the theme list from the manager so they can be sisplayed in prefs */ static void prefs_themes_sort(PurpleTheme *theme) { - GdkPixbuf *pixbuf; + GdkPixbuf *pixbuf = NULL; GtkTreeIter iter; + if (PURPLE_IS_SOUND_THEME(theme)){ - /* TODO: string leak? */ + /* TODO: string leaks? */ + gchar *pref = purple_prefs_get_string(PIDGIN_PREFS_ROOT "/sound/theme"); + pixbuf = pidgin_pixbuf_from_imgstore(purple_theme_get_image(theme)); gtk_list_store_append (prefs_sound_themes, &iter); - gtk_list_store_set (prefs_sound_themes, &iter, 0, pixbuf, 1, purple_theme_get_name(theme), -1); - gdk_pixbuf_unref (pixbuf); + gtk_list_store_set (prefs_sound_themes, &iter, 0, pixbuf, 1, purple_theme_get_name(theme), 2, NULL, -1); + gdk_pixbuf_unref(pixbuf); + + if (pref && strlen(pref) && !strcmp(purple_theme_get_name(theme), pref)) + prefs_sound_iter = iter; + } } +/* init all the theme variables so that the themes can be sorted later and used by pref pages */ static void prefs_themes_init(void) { GdkPixbuf *pixbuf = NULL; - GtkTreeIter iter; gchar *filename; /* sound themes */ - prefs_sound_themes = gtk_list_store_new (2, GDK_TYPE_PIXBUF, G_TYPE_STRING); + prefs_sound_themes = gtk_list_store_new (3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING); filename = g_build_filename(DATADIR, "icons", "hicolor", "16x16", "apps", "pidgin.png", NULL); pixbuf= gdk_pixbuf_new_from_file (filename, NULL); g_free(filename); - gtk_list_store_append (prefs_sound_themes, &iter); - gtk_list_store_set (prefs_sound_themes, &iter, 0, pixbuf, 1, _("(Default)"), -1); + gtk_list_store_append (prefs_sound_themes, &prefs_sound_iter); + + gtk_list_store_set (prefs_sound_themes, &prefs_sound_iter, 0, pixbuf, 1, _("(Default)"), 2, NULL, -1); gdk_pixbuf_unref (pixbuf); } +/* sets the current sound theme */ +static void +prefs_set_sound_theme(GtkComboBox *combo_box, gpointer user_data) +{ + gint i; + gchar *pref; + gchar *theme_name; + + /* remove "(custom)" */ + gtk_list_store_set(prefs_sound_themes, &prefs_sound_iter, 2, NULL, -1); + + g_return_if_fail(gtk_combo_box_get_active_iter(combo_box, &prefs_sound_iter)); + + gtk_tree_model_get(GTK_TREE_MODEL(prefs_sound_themes), &prefs_sound_iter, 1, &theme_name, -1); + + if (strcmp(theme_name, "(Default)") == 0){ + g_free(theme_name); + theme_name = g_strdup(""); + } + + purple_prefs_set_string(PIDGIN_PREFS_ROOT "/sound/theme", theme_name); + + for(i=0; i < PURPLE_NUM_SOUNDS; i++){ + pref = g_strdup_printf(PIDGIN_PREFS_ROOT "/sound/file/%s", + pidgin_sound_get_event_option(i)); + purple_prefs_set_path(pref, ""); + g_free(pref); + } + + gtk_entry_set_text(GTK_ENTRY(sound_entry), _("(default)")); + + g_free(theme_name); +} + /* Does same as normal sort, except "none" is sorted first */ static gint pidgin_sort_smileys (GtkTreeModel *model, GtkTreeIter *a, @@ -1775,6 +1828,8 @@ g_free(pref); gtk_entry_set_text(GTK_ENTRY(sound_entry), _("(default)")); + + pref_set_sound_customized(); } static void @@ -1865,6 +1920,8 @@ if (sound_entry) gtk_entry_set_text(GTK_ENTRY(sound_entry), (file && *file != '\0') ? file : _("(default)")); g_value_unset (&val); + + pref_set_sound_customized(); } static GtkWidget * @@ -1974,7 +2031,7 @@ vbox->parent->parent, TRUE, TRUE, 0, GTK_PACK_START); /* SOUND THEMES */ - combo_box = gtk_combo_box_new_with_model (GTK_TREE_MODEL (prefs_sound_themes)); + combo_box = gtk_combo_box_new_with_model(GTK_TREE_MODEL (prefs_sound_themes)); gtk_box_pack_start (GTK_BOX (vbox), combo_box, FALSE, FALSE, 0); cell_rend = gtk_cell_renderer_pixbuf_new (); @@ -1984,7 +2041,12 @@ cell_rend = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell_rend, FALSE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell_rend, "text", 1, NULL); - + + gtk_combo_box_set_active_iter(GTK_COMBO_BOX(combo_box), &prefs_sound_iter); + g_signal_connect(G_OBJECT(combo_box), "changed", (GCallback)prefs_set_sound_theme, NULL); + + pref_set_sound_customized(); + /* SOUND SELECTION */ sw = gtk_scrolled_window_new(NULL,NULL); gtk_widget_set_size_request(sw, -1, 100);
--- a/pidgin/gtksound.c Tue Jun 24 02:06:42 2008 +0000 +++ b/pidgin/gtksound.c Fri Jun 27 01:29:59 2008 +0000 @@ -40,6 +40,8 @@ #include "notify.h" #include "prefs.h" #include "sound.h" +#include "sound-theme.h" +#include "theme-manager.h" #include "util.h" #include "gtkconv.h" @@ -294,6 +296,7 @@ purple_prefs_add_path(PIDGIN_PREFS_ROOT "/sound/file/nick_said", ""); purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/sound/enabled/pounce_default", TRUE); purple_prefs_add_path(PIDGIN_PREFS_ROOT "/sound/file/pounce_default", ""); + purple_prefs_add_string(PIDGIN_PREFS_ROOT "/sound/theme", ""); purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/sound/conv_focus", TRUE); purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/sound/mute", FALSE); purple_prefs_add_path(PIDGIN_PREFS_ROOT "/sound/command", ""); @@ -557,6 +560,8 @@ { char *enable_pref; char *file_pref; + char *theme_pref, *theme_name; + PurpleSoundTheme *theme; if ((event == PURPLE_SOUND_BUDDY_ARRIVE) && mute_login_sounds) return; @@ -570,23 +575,67 @@ sounds[event].pref); file_pref = g_strdup_printf(PIDGIN_PREFS_ROOT "/sound/file/%s", sounds[event].pref); + + /* check NULL for sounds that don't have an option, ie buddy pounce */ if (purple_prefs_get_bool(enable_pref)) { char *filename = g_strdup(purple_prefs_get_path(file_pref)); - if(!filename || !strlen(filename)) { + theme_name = g_strdup(purple_prefs_get_string(PIDGIN_PREFS_ROOT "/sound/theme")); + + if (theme_name && strlen(theme_name) && (!filename || !strlen(filename))){ /* Use theme */ g_free(filename); + + theme = PURPLE_SOUND_THEME(purple_theme_manager_find_theme(theme_name, "sound")); + filename = purple_sound_theme_get_file_full(theme, sounds[event].pref); + + if(!g_file_test(filename, G_FILE_TEST_IS_REGULAR)){ /* Use Default sound in this case */ + purple_debug_error("sound", "The file: (%s) %s\n from theme: %s, was not found or wasn't readable\n", + sounds[event].pref, filename, theme_name); + g_free(filename); + } + } + + if (!filename || !strlen(filename)) { /* Use Default sounds */ + g_free(filename); + /* XXX Consider creating a constant for "sounds/purple" to be shared with Finch */ filename = g_build_filename(DATADIR, "sounds", "purple", sounds[event].def, NULL); } purple_sound_play_file(filename, NULL); + + g_free(theme_name); g_free(filename); } + g_free(enable_pref); g_free(file_pref); } +gboolean +pidgin_sound_is_customized(void) +{ + gint i; + gchar *path, *file; + + for (i=0; i < PURPLE_NUM_SOUNDS; i++){ + path = g_strdup_printf(PIDGIN_PREFS_ROOT "/sound/file/%s", sounds[i].pref); + file = g_strdup(purple_prefs_get_path(path)); + g_free(path); + + if (file && strlen(file)){ + g_free(file); + return TRUE; + } + + g_free(file); + } + + return FALSE; + +} + static PurpleSoundUiOps sound_ui_ops = { pidgin_sound_init,
--- a/pidgin/gtksound.h Tue Jun 24 02:06:42 2008 +0000 +++ b/pidgin/gtksound.h Fri Jun 27 01:29:59 2008 +0000 @@ -63,6 +63,13 @@ */ void *pidgin_sound_get_handle(void); +/** + * Returns true Pidgin is using customized sounds + * + * @return TRUE if non default sounds are used + */ +gboolean pidgin_sound_is_customized(void); + /*@}*/ #endif /* _PIDGINSOUND_H_ */