Mercurial > pidgin
view libpurple/theme-manager.c @ 32533:e091c8ea292e
Pluck all MSNP18 changes. This is pretty much to fix sending OIMs.
*** Plucked rev b8b574c4d6f6c05105b372191ca5259b4ae0ad41 (qulogic@pidgin.im):
Add a function for parsing a network:username for MSNP18.
*** Plucked rev 86bb401efa33f02ca5d28fea216a39a3cf29b5b4 (qulogic@pidgin.im):
Fix UBX on MSNP18.
*** Plucked rev ba2513694e6abcbdfddc66820f1df20540a36847 (qulogic@pidgin.im):
Fix NLN on MSNP18.
*** Plucked rev 83a617670da618f4dbdeeebbdb5e2813a4ad2c0c (qulogic@pidgin.im):
Switch to ABFindContactsPaged instead of ABFindAll.
*** Plucked rev b6bd214d29db885c6d28628c163fa144bdf4a76d (qulogic@pidgin.im):
Send circle authentication on the notification server on MSNP18.
*** Plucked rev 2ca50146aa67469313579cea414e4a2b660939aa (qulogic@pidgin.im):
Make a small name change.
*** Plucked rev 2c13bf358104060d6713317e18e03b434862cb38 (qulogic@pidgin.im):
Add a missing function.
*** Plucked rev a8deb3f73726f4148e8f36f317a88fedcb051c34 (qulogic@pidgin.im):
Update UUM to allow sending to users on any network.
*** Plucked rev dddff988e830a7a2fa0e40aad200f0e908b9231e (qulogic@pidgin.im):
Switch to MSNP18.
*** Plucked rev 9fe45819000c530c509c07b7feb29ce9d4ea13b0 (qulogic@pidgin.im):
Send offline messages using UUM.
*** Plucked rev c1584182b85f99fa3507ea3f76b07865ee7e43f7 (qulogic@pidgin.im):
Drop support for protocols below 18.
*** Plucked rev f0388e54998489dbe4b6133796f77459f20fe884 (qulogic@pidgin.im):
Fix indices for client capabilities and display pics.
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Wed, 22 Feb 2012 05:52:30 +0000 |
parents | a8cc50c2279f |
children | b276701931d9 |
line wrap: on
line source
/* * Themes for libpurple * * Pidgin is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ #include "internal.h" #include "theme-manager.h" #include "util.h" /****************************************************************************** * Globals *****************************************************************************/ static GHashTable *theme_table = NULL; /***************************************************************************** * GObject Stuff ****************************************************************************/ GType purple_theme_manager_get_type(void) { static GType type = 0; if (type == 0) { static const GTypeInfo info = { sizeof(PurpleThemeManagerClass), NULL, /* base_init */ NULL, /* base_finalize */ NULL, /* class_init */ NULL, /* class_finalize */ NULL, /* class_data */ sizeof(PurpleThemeManager), 0, /* n_preallocs */ NULL, /* instance_init */ NULL, /* Value Table */ }; type = g_type_register_static(G_TYPE_OBJECT, "PurpleThemeManager", &info, 0); } return type; } /****************************************************************************** * Helpers *****************************************************************************/ /* makes a key of <type> + '/' + <name> */ static gchar * purple_theme_manager_make_key(const gchar *name, const gchar *type) { g_return_val_if_fail(name && *name, NULL); g_return_val_if_fail(type && *type, NULL); return g_strconcat(type, "/", name, NULL); } /* returns TRUE if theme is of type "user_data" */ static gboolean purple_theme_manager_is_theme_type(gchar *key, gpointer value, gchar *user_data) { return g_str_has_prefix(key, g_strconcat(user_data, "/", NULL)); } static gboolean purple_theme_manager_is_theme(gchar *key, gpointer value, gchar *user_data) { return PURPLE_IS_THEME(value); } static void purple_theme_manager_function_wrapper(gchar *key, gpointer value, PTFunc user_data) { if (PURPLE_IS_THEME(value)) (* user_data)(value); } static void purple_theme_manager_build_dir(const gchar *root) { gchar *purple_dir, *theme_dir; const gchar *name = NULL, *type = NULL; GDir *rdir, *tdir; PurpleThemeLoader *loader; rdir = g_dir_open(root, 0, NULL); if (!rdir) return; /* Parses directory by root/name/purple/type */ while ((name = g_dir_read_name(rdir))) { purple_dir = g_build_filename(root, name, "purple", NULL); tdir = g_dir_open(purple_dir, 0, NULL); if (!tdir) { g_free(purple_dir); continue; } while ((type = g_dir_read_name(tdir))) { if ((loader = g_hash_table_lookup(theme_table, type))) { PurpleTheme *theme = NULL; theme_dir = g_build_filename(purple_dir, type, NULL); theme = purple_theme_loader_build(loader, theme_dir); g_free(theme_dir); if (PURPLE_IS_THEME(theme)) purple_theme_manager_add_theme(theme); } } g_dir_close(tdir); g_free(purple_dir); } g_dir_close(rdir); } /***************************************************************************** * Public API functions *****************************************************************************/ void purple_theme_manager_init(void) { theme_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_object_unref); } void purple_theme_manager_refresh(void) { gchar *path = NULL; const gchar *xdg = NULL; gint i = 0; g_hash_table_foreach_remove(theme_table, (GHRFunc) purple_theme_manager_is_theme, NULL); /* Add themes from ~/.purple */ path = g_build_filename(purple_user_dir(), "themes", NULL); purple_theme_manager_build_dir(path); g_free(path); /* look for XDG_DATA_HOME. If we don't have it use ~/.local, and add it */ if ((xdg = g_getenv("XDG_DATA_HOME")) != NULL) path = g_build_filename(xdg, "themes", NULL); else path = g_build_filename(purple_home_dir(), ".local", "themes", NULL); purple_theme_manager_build_dir(path); g_free(path); /* now dig through XDG_DATA_DIRS and add those too */ xdg = g_getenv("XDG_DATA_DIRS"); if (xdg) { gchar **xdg_dirs = g_strsplit(xdg, G_SEARCHPATH_SEPARATOR_S, 0); for (i = 0; xdg_dirs[i]; i++) { path = g_build_filename(xdg_dirs[i], "themes", NULL); purple_theme_manager_build_dir(path); g_free(path); } g_strfreev(xdg_dirs); } } void purple_theme_manager_uninit(void) { g_hash_table_destroy(theme_table); } void purple_theme_manager_register_type(PurpleThemeLoader *loader) { gchar *type; g_return_if_fail(PURPLE_IS_THEME_LOADER(loader)); type = g_strdup(purple_theme_loader_get_type_string(loader)); g_return_if_fail(type); /* if something is already there do nothing */ if (!g_hash_table_lookup(theme_table, type)) g_hash_table_insert(theme_table, type, loader); } void purple_theme_manager_unregister_type(PurpleThemeLoader *loader) { const gchar *type; g_return_if_fail(PURPLE_IS_THEME_LOADER(loader)); type = purple_theme_loader_get_type_string(loader); g_return_if_fail(type); if (g_hash_table_lookup(theme_table, type) == loader) { g_hash_table_remove(theme_table, type); g_hash_table_foreach_remove(theme_table, (GHRFunc)purple_theme_manager_is_theme_type, (gpointer)type); } /* only free if given registered loader */ } PurpleTheme * purple_theme_manager_find_theme(const gchar *name, const gchar *type) { gchar *key; PurpleTheme *theme; key = purple_theme_manager_make_key(name, type); g_return_val_if_fail(key, NULL); theme = g_hash_table_lookup(theme_table, key); g_free(key); return theme; } void purple_theme_manager_add_theme(PurpleTheme *theme) { gchar *key; g_return_if_fail(PURPLE_IS_THEME(theme)); key = purple_theme_manager_make_key(purple_theme_get_name(theme), purple_theme_get_type_string(theme)); g_return_if_fail(key); /* if something is already there do nothing */ if (g_hash_table_lookup(theme_table, key) == NULL) g_hash_table_insert(theme_table, key, theme); } void purple_theme_manager_remove_theme(PurpleTheme *theme) { gchar *key; g_return_if_fail(PURPLE_IS_THEME(theme)); key = purple_theme_manager_make_key(purple_theme_get_name(theme), purple_theme_get_type_string(theme)); g_return_if_fail(key); g_hash_table_remove(theme_table, key); g_free(key); } void purple_theme_manager_for_each_theme(PTFunc func) { g_return_if_fail(func); g_hash_table_foreach(theme_table, (GHFunc) purple_theme_manager_function_wrapper, func); } PurpleTheme * purple_theme_manager_load_theme(const gchar *theme_dir, const gchar *type) { PurpleThemeLoader *loader; g_return_val_if_fail(theme_dir != NULL && type != NULL, NULL); loader = g_hash_table_lookup(theme_table, type); g_return_val_if_fail(PURPLE_IS_THEME_LOADER(loader), NULL); return purple_theme_loader_build(loader, theme_dir); }