pidgin/gtkconv-theme-loader.c

Mon, 19 Sep 2011 18:48:00 +0000

author
Elliott Sales de Andrade <qulogic@pidgin.im>
date
Mon, 19 Sep 2011 18:48:00 +0000
changeset 32562
9c094ffe9333
parent 32545
1b21192ab58a
child 32565
9278cf3bf2c5
permissions
-rw-r--r--

Load the list of variants when building the theme.

32536
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
1 /*
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
2 * PidginConvThemeLoader for Pidgin
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
3 *
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
4 * Pidgin is the legal property of its developers, whose names are too numerous
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
6 * source distribution.
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
7 *
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
11 * (at your option) any later version.
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
12 *
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
16 * GNU General Public License for more details.
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
17 *
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
21 */
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
22
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
23 #include "gtkconv-theme-loader.h"
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
24 #include "gtkconv-theme.h"
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
25
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
26 #include "xmlnode.h"
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
27 #include "debug.h"
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
28
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
29 /*****************************************************************************
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
30 * Conversation Theme Builder
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
31 *****************************************************************************/
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
32
32545
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
33 static GHashTable *
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
34 read_info_plist(xmlnode *plist)
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
35 {
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
36 GHashTable *info;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
37 xmlnode *key, *value;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
38 gboolean fail = FALSE;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
39
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
40 info = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
41
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
42 for (key = xmlnode_get_child(plist, "dict/key");
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
43 key;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
44 key = xmlnode_get_next_twin(key)) {
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
45 char *keyname;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
46 GValue *val;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
47
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
48 ;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
49 for (value = key->next; value && value->type != XMLNODE_TYPE_TAG; value = value->next)
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
50 ;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
51 if (!value) {
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
52 fail = TRUE;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
53 break;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
54 }
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
55
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
56 val = g_new0(GValue, 1);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
57 if (g_str_equal(value->name, "string")) {
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
58 g_value_init(val, G_TYPE_STRING);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
59 g_value_take_string(val, xmlnode_get_data_unescaped(value));
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
60
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
61 } else if (g_str_equal(value->name, "true")) {
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
62 g_value_init(val, G_TYPE_BOOLEAN);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
63 g_value_set_boolean(val, TRUE);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
64
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
65 } else if (g_str_equal(value->name, "false")) {
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
66 g_value_init(val, G_TYPE_BOOLEAN);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
67 g_value_set_boolean(val, FALSE);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
68
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
69 } else if (g_str_equal(value->name, "real")) {
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
70 char *temp = xmlnode_get_data_unescaped(value);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
71 g_value_init(val, G_TYPE_FLOAT);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
72 g_value_set_float(val, atof(temp));
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
73 g_free(temp);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
74
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
75 } else if (g_str_equal(value->name, "integer")) {
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
76 char *temp = xmlnode_get_data_unescaped(value);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
77 g_value_init(val, G_TYPE_INT);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
78 g_value_set_int(val, atoi(temp));
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
79 g_free(temp);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
80
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
81 } else {
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
82 /* NOTE: We don't support array, data, date, or dict as values,
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
83 since they don't seem to be needed for styles. */
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
84 g_free(val);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
85 fail = TRUE;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
86 break;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
87 }
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
88
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
89 keyname = xmlnode_get_data_unescaped(key);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
90 g_hash_table_insert(info, keyname, val);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
91 }
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
92
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
93 if (fail) {
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
94 g_hash_table_destroy(info);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
95 info = NULL;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
96 }
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
97
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
98 return info;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
99 }
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
100
32536
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
101 static PurpleTheme *
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
102 pidgin_conv_loader_build(const gchar *dir)
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
103 {
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
104 PidginConvTheme *theme = NULL;
32545
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
105 char *contents;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
106 xmlnode *plist;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
107 GHashTable *info;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
108 GValue *val;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
109 int MessageViewVersion;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
110 const char *CFBundleName;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
111 const char *CFBundleIdentifier;
32562
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
112 GDir *variants;
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
113 char *variant_dir;
32536
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
114
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
115 g_return_val_if_fail(dir != NULL, NULL);
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
116
32545
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
117 /* Load Info.plist for theme information */
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
118 contents = g_build_filename(dir, "Contents", NULL);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
119 plist = xmlnode_from_file(contents, "Info.plist", "Info.plist", "gtkconv-theme-loader");
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
120 g_free(contents);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
121 if (plist == NULL) {
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
122 purple_debug_error("gtkconv-theme", "Failed to load Contents/Info.plist in %s\n", dir);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
123 return NULL;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
124 }
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
125
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
126 info = read_info_plist(plist);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
127 xmlnode_free(plist);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
128 if (info == NULL) {
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
129 purple_debug_error("gtkconv-theme", "Failed to load Contents/Info.plist in %s\n", dir);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
130 return NULL;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
131 }
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
132
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
133 /* Check for required keys: CFBundleName */
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
134 val = g_hash_table_lookup(info, "CFBundleName");
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
135 if (!val) {
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
136 purple_debug_error("gtkconv-theme", "%s/Contents/Info.plist missing required key CFBundleName.\n", dir);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
137 g_hash_table_destroy(info);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
138 return NULL;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
139 }
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
140 CFBundleName = g_value_get_string(val);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
141
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
142 /* Check for required keys: CFBundleIdentifier */
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
143 val = g_hash_table_lookup(info, "CFBundleIdentifier");
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
144 if (!val) {
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
145 purple_debug_error("gtkconv-theme", "%s/Contents/Info.plist missing required key CFBundleIdentifier.\n", dir);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
146 g_hash_table_destroy(info);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
147 return NULL;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
148 }
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
149 CFBundleIdentifier = g_value_get_string(val);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
150
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
151 /* Check for required keys: MessageViewVersion */
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
152 val = g_hash_table_lookup(info, "MessageViewVersion");
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
153 if (!val) {
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
154 purple_debug_error("gtkconv-theme", "%s/Contents/Info.plist missing required key MessageViewVersion.\n", dir);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
155 g_hash_table_destroy(info);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
156 return NULL;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
157 }
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
158
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
159 MessageViewVersion = g_value_get_int(val);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
160 if (MessageViewVersion < 3) {
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
161 purple_debug_error("gtkconv-theme", "%s is a legacy style (version %d) and will not be loaded.\n",
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
162 CFBundleName, MessageViewVersion);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
163 g_hash_table_destroy(info);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
164 return NULL;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
165 }
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
166
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
167 theme = g_object_new(PIDGIN_TYPE_CONV_THEME,
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
168 "type", "conversation",
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
169 "name", CFBundleName,
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
170 "directory", dir,
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
171 "info", info, NULL);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
172
32562
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
173 /* Read list of variants */
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
174 variant_dir = g_build_filename(dir, "Contents", "Resources", "Variants", NULL);
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
175 variants = g_dir_open(variant_dir, 0, NULL);
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
176 g_free(variant_dir);
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
177
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
178 if (variants) {
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
179 const char *file;
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
180 char *name;
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
181
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
182 while ((file = g_dir_read_name(variants)) != NULL) {
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
183 const char *end = g_strrstr(file, ".css");
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
184 char *name;
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
185
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
186 if ((end == NULL) || (*(end + 4) != '\0'))
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
187 continue;
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
188
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
189 name = g_strndup(file, end - file);
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
190 pidgin_conversation_theme_add_variant(theme, name);
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
191 }
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
192
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
193 g_dir_close(variants);
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
194 }
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
195
32536
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
196 return PURPLE_THEME(theme);
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
197 }
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
198
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
199 /******************************************************************************
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
200 * GObject Stuff
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
201 *****************************************************************************/
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
202
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
203 static void
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
204 pidgin_conv_theme_loader_class_init(PidginConvThemeLoaderClass *klass)
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
205 {
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
206 PurpleThemeLoaderClass *loader_klass = PURPLE_THEME_LOADER_CLASS(klass);
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
207
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
208 loader_klass->purple_theme_loader_build = pidgin_conv_loader_build;
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
209 }
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
210
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
211
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
212 GType
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
213 pidgin_conversation_theme_loader_get_type(void)
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
214 {
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
215 static GType type = 0;
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
216 if (type == 0) {
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
217 static const GTypeInfo info = {
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
218 sizeof(PidginConvThemeLoaderClass),
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
219 NULL, /* base_init */
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
220 NULL, /* base_finalize */
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
221 (GClassInitFunc)pidgin_conv_theme_loader_class_init, /* class_init */
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
222 NULL, /* class_finalize */
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
223 NULL, /* class_data */
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
224 sizeof (PidginConvThemeLoader),
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
225 0, /* n_preallocs */
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
226 NULL, /* instance_init */
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
227 NULL, /* value table */
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
228 };
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
229 type = g_type_register_static(PURPLE_TYPE_THEME_LOADER,
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
230 "PidginConvThemeLoader", &info, 0);
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
231 }
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
232 return type;
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
233 }
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
234

mercurial