soc.2008.themes: 26cb0ec0: Working sound themes (option 1) theme is...
ffdragon at soc.pidgin.im
ffdragon at soc.pidgin.im
Thu Jun 26 21:35:42 EDT 2008
-----------------------------------------------------------------
Revision: 26cb0ec05cc5301a1d7050a267d2e7abac2229b8
Ancestor: f3b38e0cf2855a8c22a1949257165b7ffa9f4358
Author: ffdragon at soc.pidgin.im
Date: 2008-06-27T01:29:59
Branch: im.pidgin.soc.2008.themes
URL: http://d.pidgin.im/viewmtn/revision/info/26cb0ec05cc5301a1d7050a267d2e7abac2229b8
Modified files:
libpurple/sound-theme.c libpurple/sound-theme.h
pidgin/gtkprefs.c pidgin/gtksound.c pidgin/gtksound.h
ChangeLog:
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
-------------- next part --------------
============================================================
--- libpurple/sound-theme.c 0d7ce076ad8f8973ed1180bbd2e1a5d122ef4c7b
+++ libpurple/sound-theme.c 5342aaa1c69757db8af503f12fe6c5688bcf091d
@@ -133,16 +133,19 @@ purple_sound_theme_get_file_full(PurpleS
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 @@ purple_sound_theme_set_file(PurpleSoundT
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);
}
============================================================
--- libpurple/sound-theme.h 855355263c84f20baa9fe02dc76e74b279dccbce
+++ libpurple/sound-theme.h 47373d0d77cbdc18479d037488214c1777fdf87f
@@ -92,11 +92,11 @@ gchar *purple_sound_theme_get_file_full(
* 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_ */
============================================================
--- pidgin/gtkprefs.c 6caf8a9c8df904cef72904bea02ef887080da7d7
+++ pidgin/gtkprefs.c fecdaee6dbdc30659f04dd9c601d41994fe1bac5
@@ -73,6 +73,7 @@ static GtkListStore *prefs_sound_themes;
static gboolean prefs_themes_unsorted = TRUE;
static GtkListStore *prefs_sound_themes;
+static GtkTreeIter prefs_sound_iter;
/*
* PROTOTYPES
@@ -551,40 +552,92 @@ theme_dnd_recv(GtkWidget *widget, GdkDra
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 @@ reset_sound(GtkWidget *button, gpointer
g_free(pref);
gtk_entry_set_text(GTK_ENTRY(sound_entry), _("(default)"));
+
+ pref_set_sound_customized();
}
static void
@@ -1865,6 +1920,8 @@ static void prefs_sound_sel(GtkTreeSelec
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 @@ sound_page(void)
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 @@ sound_page(void)
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);
============================================================
--- pidgin/gtksound.c 0cc7acc221605e6665426880ed18147a98d32dec
+++ pidgin/gtksound.c d9ce4c4a32f2e3cd64aafb0b49f87d2ebbb4311b
@@ -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 @@ pidgin_sound_init(void)
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 @@ pidgin_sound_play_event(PurpleSoundEvent
{
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 @@ pidgin_sound_play_event(PurpleSoundEvent
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,
============================================================
--- pidgin/gtksound.h 4006ee765aeee147347b96d135888375a3ec4aad
+++ pidgin/gtksound.h 064f1e4731b6e1a5f71952a67710ed0892d93915
@@ -63,6 +63,13 @@ void *pidgin_sound_get_handle(void);
*/
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_ */
More information about the Commits
mailing list