pidgin/gtkconv-theme-loader.c

Fri, 29 Mar 2019 04:48:49 -0400

author
Elliott Sales de Andrade <qulogic@pidgin.im>
date
Fri, 29 Mar 2019 04:48:49 -0400
changeset 39548
dfd989c8236e
parent 36692
324db2a53c4c
permissions
-rw-r--r--

Use G_DECLARE* for Pidgin theme objects.

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
32568
22cb8a095118 Set the default variant when loading the theme. The priorities
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32566
diff changeset
23 #include "pidgin.h"
32536
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-loader.h"
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
25 #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
26
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
27 #include "xmlnode.h"
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
28 #include "debug.h"
36512
35b1e42281e5 Removed loadable field from plugin info dialog, and added license
Ankit Vani <a@nevitus.org>
parents: 32958
diff changeset
29 #include "prefs.h"
32536
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
30
39548
dfd989c8236e Use G_DECLARE* for Pidgin theme objects.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 36692
diff changeset
31 /**
dfd989c8236e Use G_DECLARE* for Pidgin theme objects.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 36692
diff changeset
32 * PidginConvThemeLoader:
dfd989c8236e Use G_DECLARE* for Pidgin theme objects.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 36692
diff changeset
33 *
dfd989c8236e Use G_DECLARE* for Pidgin theme objects.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 36692
diff changeset
34 * A pidgin conversation theme loader. Extends PurpleThemeLoader (theme-loader.h)
dfd989c8236e Use G_DECLARE* for Pidgin theme objects.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 36692
diff changeset
35 * This is a class designed to build conversation themes
dfd989c8236e Use G_DECLARE* for Pidgin theme objects.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 36692
diff changeset
36 */
dfd989c8236e Use G_DECLARE* for Pidgin theme objects.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 36692
diff changeset
37 struct _PidginConvThemeLoader
dfd989c8236e Use G_DECLARE* for Pidgin theme objects.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 36692
diff changeset
38 {
dfd989c8236e Use G_DECLARE* for Pidgin theme objects.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 36692
diff changeset
39 PurpleThemeLoader parent;
dfd989c8236e Use G_DECLARE* for Pidgin theme objects.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 36692
diff changeset
40 };
dfd989c8236e Use G_DECLARE* for Pidgin theme objects.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 36692
diff changeset
41
32536
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
42 /*****************************************************************************
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
43 * Conversation Theme Builder
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
44 *****************************************************************************/
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
45
32545
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
46 static GHashTable *
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 32958
diff changeset
47 read_info_plist(PurpleXmlNode *plist)
32545
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 GHashTable *info;
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 32958
diff changeset
50 PurpleXmlNode *key, *value;
32545
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
51 gboolean fail = FALSE;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
52
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
53 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
54
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 32958
diff changeset
55 for (key = purple_xmlnode_get_child(plist, "dict/key");
32545
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
56 key;
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 32958
diff changeset
57 key = purple_xmlnode_get_next_twin(key)) {
32545
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
58 char *keyname;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
59 GValue *val;
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 ;
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 32958
diff changeset
62 for (value = key->next; value && value->type != PURPLE_XMLNODE_TYPE_TAG; value = value->next)
32545
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
63 ;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
64 if (!value) {
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
65 fail = TRUE;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
66 break;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
67 }
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 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
70 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
71 g_value_init(val, G_TYPE_STRING);
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 32958
diff changeset
72 g_value_take_string(val, purple_xmlnode_get_data_unescaped(value));
32545
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
73
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
74 } 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
75 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
76 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
77
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
78 } 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
79 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
80 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
81
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
82 } else if (g_str_equal(value->name, "real")) {
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 32958
diff changeset
83 char *temp = purple_xmlnode_get_data_unescaped(value);
32545
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
84 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
85 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
86 g_free(temp);
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 } else if (g_str_equal(value->name, "integer")) {
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 32958
diff changeset
89 char *temp = purple_xmlnode_get_data_unescaped(value);
32545
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
90 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
91 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
92 g_free(temp);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
93
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
94 } else {
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
95 /* 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
96 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
97 g_free(val);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
98 fail = TRUE;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
99 break;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
100 }
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
101
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 32958
diff changeset
102 keyname = purple_xmlnode_get_data_unescaped(key);
32545
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
103 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
104 }
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
105
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
106 if (fail) {
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
107 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
108 info = NULL;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
109 }
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
110
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
111 return info;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
112 }
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
113
32958
98a8270ec6aa Override the probe function in the conversation theme loader.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32588
diff changeset
114 static gboolean
98a8270ec6aa Override the probe function in the conversation theme loader.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32588
diff changeset
115 pidgin_conv_loader_probe(const gchar *dir)
98a8270ec6aa Override the probe function in the conversation theme loader.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32588
diff changeset
116 {
98a8270ec6aa Override the probe function in the conversation theme loader.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32588
diff changeset
117 gboolean result;
98a8270ec6aa Override the probe function in the conversation theme loader.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32588
diff changeset
118 gchar *plist_file;
98a8270ec6aa Override the probe function in the conversation theme loader.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32588
diff changeset
119
98a8270ec6aa Override the probe function in the conversation theme loader.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32588
diff changeset
120 plist_file = g_build_filename(dir, "Contents", "Info.plist", NULL);
98a8270ec6aa Override the probe function in the conversation theme loader.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32588
diff changeset
121 result = g_file_test(plist_file, G_FILE_TEST_IS_REGULAR);
98a8270ec6aa Override the probe function in the conversation theme loader.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32588
diff changeset
122 g_free(plist_file);
98a8270ec6aa Override the probe function in the conversation theme loader.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32588
diff changeset
123
98a8270ec6aa Override the probe function in the conversation theme loader.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32588
diff changeset
124 return result;
98a8270ec6aa Override the probe function in the conversation theme loader.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32588
diff changeset
125 }
98a8270ec6aa Override the probe function in the conversation theme loader.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32588
diff changeset
126
32536
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
127 static PurpleTheme *
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
128 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
129 {
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
130 PidginConvTheme *theme = NULL;
32545
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
131 char *contents;
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 32958
diff changeset
132 PurpleXmlNode *plist;
32545
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
133 GHashTable *info;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
134 GValue *val;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
135 int MessageViewVersion;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
136 const char *CFBundleName;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
137 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
138 GDir *variants;
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
139 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
140
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
141 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
142
32545
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
143 /* 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
144 contents = g_build_filename(dir, "Contents", NULL);
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 32958
diff changeset
145 plist = purple_xmlnode_from_file(contents, "Info.plist", "Info.plist", "gtkconv-theme-loader");
32545
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
146 g_free(contents);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
147 if (plist == NULL) {
32565
9278cf3bf2c5 Use a consistent debugging domain.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32562
diff changeset
148 purple_debug_error("gtkconv-theme-loader",
9278cf3bf2c5 Use a consistent debugging domain.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32562
diff changeset
149 "Failed to load Contents/Info.plist in %s\n", dir);
32545
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
150 return NULL;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
151 }
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
152
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
153 info = read_info_plist(plist);
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 32958
diff changeset
154 purple_xmlnode_free(plist);
32545
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
155 if (info == NULL) {
32565
9278cf3bf2c5 Use a consistent debugging domain.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32562
diff changeset
156 purple_debug_error("gtkconv-theme-loader",
9278cf3bf2c5 Use a consistent debugging domain.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32562
diff changeset
157 "Failed to load Contents/Info.plist in %s\n", dir);
32545
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
158 return NULL;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
159 }
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
160
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
161 /* 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
162 val = g_hash_table_lookup(info, "CFBundleName");
32566
05644bb1aec2 Be a bit stricter about types in Info.plist.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32565
diff changeset
163 if (!val || !G_VALUE_HOLDS_STRING(val)) {
32565
9278cf3bf2c5 Use a consistent debugging domain.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32562
diff changeset
164 purple_debug_error("gtkconv-theme-loader",
32566
05644bb1aec2 Be a bit stricter about types in Info.plist.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32565
diff changeset
165 "%s/Contents/Info.plist missing required string key CFBundleName.\n",
32565
9278cf3bf2c5 Use a consistent debugging domain.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32562
diff changeset
166 dir);
32545
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
167 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
168 return NULL;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
169 }
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
170 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
171
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
172 /* 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
173 val = g_hash_table_lookup(info, "CFBundleIdentifier");
32566
05644bb1aec2 Be a bit stricter about types in Info.plist.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32565
diff changeset
174 if (!val || !G_VALUE_HOLDS_STRING(val)) {
32565
9278cf3bf2c5 Use a consistent debugging domain.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32562
diff changeset
175 purple_debug_error("gtkconv-theme-loader",
32566
05644bb1aec2 Be a bit stricter about types in Info.plist.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32565
diff changeset
176 "%s/Contents/Info.plist missing required string key CFBundleIdentifier.\n",
32565
9278cf3bf2c5 Use a consistent debugging domain.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32562
diff changeset
177 dir);
32545
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
178 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
179 return NULL;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
180 }
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
181 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
182
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
183 /* 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
184 val = g_hash_table_lookup(info, "MessageViewVersion");
32566
05644bb1aec2 Be a bit stricter about types in Info.plist.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32565
diff changeset
185 if (!val || !G_VALUE_HOLDS_INT(val)) {
32565
9278cf3bf2c5 Use a consistent debugging domain.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32562
diff changeset
186 purple_debug_error("gtkconv-theme-loader",
32566
05644bb1aec2 Be a bit stricter about types in Info.plist.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32565
diff changeset
187 "%s/Contents/Info.plist missing required integer key MessageViewVersion.\n",
32565
9278cf3bf2c5 Use a consistent debugging domain.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32562
diff changeset
188 dir);
32545
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
189 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
190 return NULL;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
191 }
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
192
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
193 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
194 if (MessageViewVersion < 3) {
32565
9278cf3bf2c5 Use a consistent debugging domain.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32562
diff changeset
195 purple_debug_error("gtkconv-theme-loader",
9278cf3bf2c5 Use a consistent debugging domain.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32562
diff changeset
196 "%s is a legacy style (version %d) and will not be loaded.\n",
9278cf3bf2c5 Use a consistent debugging domain.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32562
diff changeset
197 CFBundleName, MessageViewVersion);
32545
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
198 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
199 return NULL;
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
200 }
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
201
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
202 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
203 "type", "conversation",
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
204 "name", CFBundleName,
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
205 "directory", dir,
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
206 "info", info, NULL);
1b21192ab58a Move conversation theme loading into the PidginConvThemeLoader GObject
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32536
diff changeset
207
32562
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
208 /* 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
209 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
210 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
211 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
212
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
213 if (variants) {
32568
22cb8a095118 Set the default variant when loading the theme. The priorities
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32566
diff changeset
214 char *prefname;
22cb8a095118 Set the default variant when loading the theme. The priorities
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32566
diff changeset
215 const char *default_variant = NULL;
32562
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
216 const char *file;
32568
22cb8a095118 Set the default variant when loading the theme. The priorities
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32566
diff changeset
217
32588
b0ce9232396b Make sure our pref parents exist, or else saved variants will
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32570
diff changeset
218 /* Make sure prefs exist */
b0ce9232396b Make sure our pref parents exist, or else saved variants will
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32570
diff changeset
219 prefname = g_strdup_printf(PIDGIN_PREFS_ROOT "/conversations/themes/%s",
b0ce9232396b Make sure our pref parents exist, or else saved variants will
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32570
diff changeset
220 CFBundleIdentifier);
b0ce9232396b Make sure our pref parents exist, or else saved variants will
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32570
diff changeset
221 purple_prefs_add_none(prefname);
b0ce9232396b Make sure our pref parents exist, or else saved variants will
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32570
diff changeset
222 g_free(prefname);
b0ce9232396b Make sure our pref parents exist, or else saved variants will
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32570
diff changeset
223
32568
22cb8a095118 Set the default variant when loading the theme. The priorities
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32566
diff changeset
224 /* Try user-set variant */
22cb8a095118 Set the default variant when loading the theme. The priorities
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32566
diff changeset
225 prefname = g_strdup_printf(PIDGIN_PREFS_ROOT "/conversations/themes/%s/variant",
22cb8a095118 Set the default variant when loading the theme. The priorities
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32566
diff changeset
226 CFBundleIdentifier);
32570
52af6871a599 Avoid an error log for non-existent prefs.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32568
diff changeset
227 if (purple_prefs_exists(prefname))
52af6871a599 Avoid an error log for non-existent prefs.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32568
diff changeset
228 default_variant = purple_prefs_get_string(prefname);
32568
22cb8a095118 Set the default variant when loading the theme. The priorities
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32566
diff changeset
229 g_free(prefname);
22cb8a095118 Set the default variant when loading the theme. The priorities
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32566
diff changeset
230
22cb8a095118 Set the default variant when loading the theme. The priorities
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32566
diff changeset
231 if (default_variant && *default_variant) {
22cb8a095118 Set the default variant when loading the theme. The priorities
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32566
diff changeset
232 pidgin_conversation_theme_set_variant(theme, default_variant);
22cb8a095118 Set the default variant when loading the theme. The priorities
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32566
diff changeset
233
22cb8a095118 Set the default variant when loading the theme. The priorities
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32566
diff changeset
234 } else {
22cb8a095118 Set the default variant when loading the theme. The priorities
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32566
diff changeset
235 /* Try theme default */
22cb8a095118 Set the default variant when loading the theme. The priorities
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32566
diff changeset
236 val = g_hash_table_lookup(info, "DefaultVariant");
22cb8a095118 Set the default variant when loading the theme. The priorities
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32566
diff changeset
237 if (val && G_VALUE_HOLDS_STRING(val)) {
22cb8a095118 Set the default variant when loading the theme. The priorities
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32566
diff changeset
238 default_variant = g_value_get_string(val);
22cb8a095118 Set the default variant when loading the theme. The priorities
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32566
diff changeset
239 if (default_variant && *default_variant)
22cb8a095118 Set the default variant when loading the theme. The priorities
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32566
diff changeset
240 pidgin_conversation_theme_set_variant(theme, default_variant);
22cb8a095118 Set the default variant when loading the theme. The priorities
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32566
diff changeset
241 else
22cb8a095118 Set the default variant when loading the theme. The priorities
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32566
diff changeset
242 default_variant = NULL;
22cb8a095118 Set the default variant when loading the theme. The priorities
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32566
diff changeset
243 } else
22cb8a095118 Set the default variant when loading the theme. The priorities
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32566
diff changeset
244 default_variant = NULL;
22cb8a095118 Set the default variant when loading the theme. The priorities
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32566
diff changeset
245 }
32562
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
246
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
247 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
248 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
249 char *name;
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
250
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
251 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
252 continue;
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
253
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
254 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
255 pidgin_conversation_theme_add_variant(theme, name);
32568
22cb8a095118 Set the default variant when loading the theme. The priorities
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32566
diff changeset
256
22cb8a095118 Set the default variant when loading the theme. The priorities
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32566
diff changeset
257 /* Set variant with first found */
22cb8a095118 Set the default variant when loading the theme. The priorities
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32566
diff changeset
258 if (!default_variant) {
22cb8a095118 Set the default variant when loading the theme. The priorities
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32566
diff changeset
259 pidgin_conversation_theme_set_variant(theme, name);
22cb8a095118 Set the default variant when loading the theme. The priorities
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32566
diff changeset
260 default_variant = name;
22cb8a095118 Set the default variant when loading the theme. The priorities
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32566
diff changeset
261 }
32562
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
262 }
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
263
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
264 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
265 }
9c094ffe9333 Load the list of variants when building the theme.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32545
diff changeset
266
32536
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
267 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
268 }
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
269
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
270 /******************************************************************************
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
271 * GObject Stuff
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
272 *****************************************************************************/
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
273
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
274 static void
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
275 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
276 {
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
277 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
278
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
279 loader_klass->purple_theme_loader_build = pidgin_conv_loader_build;
32958
98a8270ec6aa Override the probe function in the conversation theme loader.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32588
diff changeset
280 loader_klass->probe_directory = pidgin_conv_loader_probe;
32536
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
281 }
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
282
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
283
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
284 GType
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
285 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
286 {
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
287 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
288 if (type == 0) {
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
289 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
290 sizeof(PidginConvThemeLoaderClass),
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
291 NULL, /* base_init */
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
292 NULL, /* base_finalize */
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
293 (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
294 NULL, /* class_finalize */
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
295 NULL, /* class_data */
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
296 sizeof (PidginConvThemeLoader),
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
297 0, /* n_preallocs */
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
298 NULL, /* instance_init */
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
299 NULL, /* value table */
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
300 };
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
301 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
302 "PidginConvThemeLoader", &info, 0);
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
303 }
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
304 return type;
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
305 }
91b09760ab0c Add some boilerplate Conversation theme GObjects. These don't do
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
306

mercurial