annotate console/libgnt/gntstyle.c @ 14139:44ec6c7cbc76

[gaim-migrate @ 16781] Allow setting the preferences for gnt-plugins. Add a guifications-like plugin for gntgaim. You can set its preferences. The preferences for core plugins are still not accessible. The makefile-foo will require changes once the split is complete. I am now just committing whatever works for me. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Wed, 16 Aug 2006 05:12:48 +0000
parents 7573bd40a190
children bb38f32ab6aa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14004
06f75fb84a78 [gaim-migrate @ 16589]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
1 #include "gntstyle.h"
06f75fb84a78 [gaim-migrate @ 16589]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
2 #include "gntcolors.h"
06f75fb84a78 [gaim-migrate @ 16589]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
3
14010
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
4 #include <string.h>
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
5
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
6 static char * str_styles[GNT_STYLES];
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
7 static int int_styles[GNT_STYLES];
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
8 static int bool_styles[GNT_STYLES];
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
9
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
10 const char *gnt_style_get(GntStyle style)
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
11 {
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
12 return str_styles[style];
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
13 }
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
14
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
15 gboolean gnt_style_get_bool(GntStyle style, gboolean def)
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
16 {
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
17 int i;
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
18 const char * str;
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
19
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
20 if (bool_styles[style] != -1)
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
21 return bool_styles[style];
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
22
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
23 str = gnt_style_get(style);
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
24
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
25 if (str)
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
26 {
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
27 if (strcmp(str, "false") == 0)
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
28 def = FALSE;
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
29 else if (strcmp(str, "true") == 0)
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
30 def = TRUE;
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
31 else if (sscanf(str, "%d", &i) == 1)
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
32 {
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
33 if (i)
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
34 def = TRUE;
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
35 else
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
36 def = FALSE;
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
37 }
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
38 }
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
39
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
40 bool_styles[style] = def;
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
41 return bool_styles[style];
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
42 }
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
43
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
44 static void
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
45 read_general_style(GKeyFile *kfile)
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
46 {
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
47 GError *error = NULL;
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
48 gsize nkeys;
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
49 char **keys = g_key_file_get_keys(kfile, "general", &nkeys, &error);
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
50 int i;
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
51 struct
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
52 {
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
53 const char *style;
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
54 GntStyle en;
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
55 } styles[] = {{"shadow", GNT_STYLE_SHADOW},
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
56 {NULL, 0}};
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
57
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
58 if (error)
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
59 {
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
60 /* XXX: some error happened. */
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
61 g_error_free(error);
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
62 }
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
63 else
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
64 {
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
65 for (i = 0; styles[i].style; i++)
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
66 {
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
67 error = NULL;
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
68 str_styles[styles[i].en] =
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
69 g_key_file_get_string(kfile, "general", styles[i].style, &error);
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
70 }
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
71 }
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
72 }
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
73
14004
06f75fb84a78 [gaim-migrate @ 16589]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
74 void gnt_style_read_configure_file(const char *filename)
06f75fb84a78 [gaim-migrate @ 16589]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
75 {
06f75fb84a78 [gaim-migrate @ 16589]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
76 #if GLIB_CHECK_VERSION(2,6,0)
06f75fb84a78 [gaim-migrate @ 16589]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
77 GKeyFile *kfile = g_key_file_new();
06f75fb84a78 [gaim-migrate @ 16589]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
78 GError *error = NULL;
06f75fb84a78 [gaim-migrate @ 16589]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
79
06f75fb84a78 [gaim-migrate @ 16589]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
80 if (!g_key_file_load_from_file(kfile, filename, G_KEY_FILE_NONE, &error))
06f75fb84a78 [gaim-migrate @ 16589]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
81 {
06f75fb84a78 [gaim-migrate @ 16589]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
82 /* XXX: Print the error or something */
06f75fb84a78 [gaim-migrate @ 16589]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
83 g_error_free(error);
06f75fb84a78 [gaim-migrate @ 16589]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
84 return;
06f75fb84a78 [gaim-migrate @ 16589]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
85 }
06f75fb84a78 [gaim-migrate @ 16589]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
86 gnt_colors_parse(kfile);
14010
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
87 read_general_style(kfile);
14004
06f75fb84a78 [gaim-migrate @ 16589]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
88
06f75fb84a78 [gaim-migrate @ 16589]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
89 g_key_file_free(kfile);
06f75fb84a78 [gaim-migrate @ 16589]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
90 #endif
06f75fb84a78 [gaim-migrate @ 16589]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
91 }
06f75fb84a78 [gaim-migrate @ 16589]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
92
14010
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
93 void gnt_init_styles()
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
94 {
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
95 int i;
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
96 for (i = 0; i < GNT_STYLES; i++)
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
97 {
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
98 str_styles[i] = NULL;
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
99 int_styles[i] = -1;
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
100 bool_styles[i] = -1;
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
101 }
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
102 }
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
103
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
104 void gnt_uninit_styles()
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
105 {
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
106 int i;
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
107 for (i = 0; i < GNT_STYLES; i++)
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
108 g_free(str_styles[i]);
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
109 }
7573bd40a190 [gaim-migrate @ 16602]
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 14004
diff changeset
110