Mercurial > pidgin
annotate finch/gntprefs.c @ 15979:2c81ebc7bf0b
Add a way to get a list of bindings for a widget. This can be used by, eg, a window-manager to show helpful messages to the user.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Wed, 04 Apr 2007 03:47:13 +0000 |
parents | 66dff3dfdea6 |
children | 0f0832c13fcb |
rev | line source |
---|---|
15817 | 1 /** |
2 * @file gntprefs.c GNT Preferences API | |
3 * @ingroup gntui | |
4 * | |
15870
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15822
diff
changeset
|
5 * finch |
15817 | 6 * |
15870
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15822
diff
changeset
|
7 * Finch is the legal property of its developers, whose names are too numerous |
15817 | 8 * to list here. Please refer to the COPYRIGHT file distributed with this |
9 * source distribution. | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 */ | |
25 #include <prefs.h> | |
26 #include <savedstatuses.h> | |
27 | |
15822 | 28 #include "finch.h" |
15817 | 29 #include "gntprefs.h" |
30 #include "gntrequest.h" | |
31 | |
32 #include <string.h> | |
33 | |
34 static GList *freestrings; /* strings to be freed when the pref-window is closed */ | |
35 | |
36 void finch_prefs_init() | |
37 { | |
15822 | 38 purple_prefs_add_none("/purple"); |
39 purple_prefs_add_none("/purple/gnt"); | |
15817 | 40 |
15822 | 41 purple_prefs_add_none("/purple/gnt/plugins"); |
42 purple_prefs_add_path_list("/purple/gnt/plugins/loaded", NULL); | |
15817 | 43 |
15822 | 44 purple_prefs_add_none("/purple/gnt/conversations"); |
45 purple_prefs_add_bool("/purple/gnt/conversations/timestamps", TRUE); | |
46 purple_prefs_add_bool("/purple/gnt/conversations/notify_typing", FALSE); /* XXX: Not functional yet */ | |
15817 | 47 } |
48 | |
49 typedef struct | |
50 { | |
15822 | 51 PurplePrefType type; |
15817 | 52 const char *pref; |
53 const char *label; | |
54 GList *(*lv)(); /* If the value is to be selected from a number of choices */ | |
55 } Prefs; | |
56 | |
57 static GList * | |
58 get_log_options() | |
59 { | |
15822 | 60 return purple_log_logger_get_options(); |
15817 | 61 } |
62 | |
63 static GList * | |
64 get_idle_options() | |
65 { | |
66 GList *list = NULL; | |
67 list = g_list_append(list, "Based on keyboard use"); /* XXX: string freeze */ | |
68 list = g_list_append(list, "system"); | |
69 list = g_list_append(list, (char*)_("From last sent message")); | |
15822 | 70 list = g_list_append(list, "purple"); |
15817 | 71 list = g_list_append(list, (char*)_("Never")); |
72 list = g_list_append(list, "never"); | |
73 return list; | |
74 } | |
75 | |
76 static GList * | |
77 get_status_titles() | |
78 { | |
79 GList *list = NULL; | |
80 const GList *iter; | |
15822 | 81 for (iter = purple_savedstatuses_get_all(); iter; iter = iter->next) { |
15817 | 82 char *str; |
15822 | 83 if (purple_savedstatus_is_transient(iter->data)) |
15817 | 84 continue; |
15822 | 85 str = g_strdup_printf("%ld", purple_savedstatus_get_creation_time(iter->data)); |
86 list = g_list_append(list, (char*)purple_savedstatus_get_title(iter->data)); | |
15817 | 87 list = g_list_append(list, str); |
88 freestrings = g_list_prepend(freestrings, str); | |
89 } | |
90 return list; | |
91 } | |
92 | |
15822 | 93 static PurpleRequestField * |
15817 | 94 get_pref_field(Prefs *prefs) |
95 { | |
15822 | 96 PurpleRequestField *field = NULL; |
15817 | 97 |
98 if (prefs->lv == NULL) | |
99 { | |
100 switch (prefs->type) | |
101 { | |
15822 | 102 case PURPLE_PREF_BOOLEAN: |
103 field = purple_request_field_bool_new(prefs->pref, _(prefs->label), | |
104 purple_prefs_get_bool(prefs->pref)); | |
15817 | 105 break; |
15822 | 106 case PURPLE_PREF_INT: |
107 field = purple_request_field_int_new(prefs->pref, _(prefs->label), | |
108 purple_prefs_get_int(prefs->pref)); | |
15817 | 109 break; |
15822 | 110 case PURPLE_PREF_STRING: |
111 field = purple_request_field_string_new(prefs->pref, _(prefs->label), | |
112 purple_prefs_get_string(prefs->pref), FALSE); | |
15817 | 113 break; |
114 default: | |
115 break; | |
116 } | |
117 } | |
118 else | |
119 { | |
120 GList *list = prefs->lv(), *iter; | |
121 if (list) | |
15822 | 122 field = purple_request_field_list_new(prefs->pref, _(prefs->label)); |
15817 | 123 for (iter = list; iter; iter = iter->next) |
124 { | |
125 gboolean select = FALSE; | |
126 const char *data = iter->data; | |
127 int idata; | |
128 iter = iter->next; | |
129 switch (prefs->type) | |
130 { | |
15822 | 131 case PURPLE_PREF_BOOLEAN: |
15817 | 132 sscanf(iter->data, "%d", &idata); |
15822 | 133 if (purple_prefs_get_bool(prefs->pref) == idata) |
15817 | 134 select = TRUE; |
135 break; | |
15822 | 136 case PURPLE_PREF_INT: |
15817 | 137 sscanf(iter->data, "%d", &idata); |
15822 | 138 if (purple_prefs_get_int(prefs->pref) == idata) |
15817 | 139 select = TRUE; |
140 break; | |
15822 | 141 case PURPLE_PREF_STRING: |
142 if (strcmp(purple_prefs_get_string(prefs->pref), iter->data) == 0) | |
15817 | 143 select = TRUE; |
144 break; | |
145 default: | |
146 break; | |
147 } | |
15822 | 148 purple_request_field_list_add(field, data, iter->data); |
15817 | 149 if (select) |
15822 | 150 purple_request_field_list_add_selected(field, data); |
15817 | 151 } |
152 g_list_free(list); | |
153 } | |
154 return field; | |
155 } | |
156 | |
157 static Prefs blist[] = | |
158 { | |
15822 | 159 {PURPLE_PREF_BOOLEAN, "/purple/gnt/blist/idletime", N_("Show Idle Time"), NULL}, |
160 {PURPLE_PREF_BOOLEAN, "/purple/gnt/blist/showoffline", N_("Show Offline Buddies"), NULL}, | |
161 {PURPLE_PREF_NONE, NULL, NULL, NULL} | |
15817 | 162 }; |
163 | |
164 static Prefs convs[] = | |
165 { | |
15822 | 166 {PURPLE_PREF_BOOLEAN, "/purple/gnt/conversations/timestamps", N_("Show Timestamps"), NULL}, |
167 {PURPLE_PREF_BOOLEAN, "/purple/gnt/conversations/notify_typing", N_("Notify buddies when you are typing"), NULL}, | |
168 {PURPLE_PREF_NONE, NULL, NULL, NULL} | |
15817 | 169 }; |
170 | |
171 static Prefs logging[] = | |
172 { | |
15822 | 173 {PURPLE_PREF_STRING, "/core/logging/format", N_("Log format"), get_log_options}, |
174 {PURPLE_PREF_BOOLEAN, "/core/logging/log_ims", N_("Log IMs"), NULL}, | |
175 {PURPLE_PREF_BOOLEAN, "/core/logging/log_chats", N_("Log chats"), NULL}, | |
176 {PURPLE_PREF_BOOLEAN, "/core/logging/log_system", N_("Log status change events"), NULL}, | |
177 {PURPLE_PREF_NONE, NULL, NULL, NULL}, | |
15817 | 178 }; |
179 | |
180 /* XXX: Translate after the freeze */ | |
181 static Prefs idle[] = | |
182 { | |
15822 | 183 {PURPLE_PREF_STRING, "/core/away/idle_reporting", "Report Idle time", get_idle_options}, |
184 {PURPLE_PREF_BOOLEAN, "/core/away/away_when_idle", "Change status when idle", NULL}, | |
185 {PURPLE_PREF_INT, "/core/away/mins_before_away", "Minutes before changing status", NULL}, | |
186 {PURPLE_PREF_INT, "/core/savedstatus/idleaway", "Change status to", get_status_titles}, | |
187 {PURPLE_PREF_NONE, NULL, NULL, NULL}, | |
15817 | 188 }; |
189 | |
190 static void | |
191 free_strings() | |
192 { | |
193 g_list_foreach(freestrings, (GFunc)g_free, NULL); | |
194 g_list_free(freestrings); | |
195 freestrings = NULL; | |
196 } | |
197 | |
198 static void | |
15822 | 199 save_cb(void *data, PurpleRequestFields *allfields) |
15817 | 200 { |
201 GList *list; | |
15822 | 202 for (list = purple_request_fields_get_groups(allfields); list; list = list->next) |
15817 | 203 { |
15822 | 204 PurpleRequestFieldGroup *group = list->data; |
205 GList *fields = purple_request_field_group_get_fields(group); | |
15817 | 206 |
207 for (; fields ; fields = fields->next) | |
208 { | |
15822 | 209 PurpleRequestField *field = fields->data; |
210 PurpleRequestFieldType type = purple_request_field_get_type(field); | |
211 PurplePrefType pt; | |
15817 | 212 gpointer val = NULL; |
15822 | 213 const char *id = purple_request_field_get_id(field); |
15817 | 214 |
215 switch (type) | |
216 { | |
15822 | 217 case PURPLE_REQUEST_FIELD_LIST: |
218 val = purple_request_field_list_get_selected(field)->data; | |
15817 | 219 break; |
15822 | 220 case PURPLE_REQUEST_FIELD_BOOLEAN: |
221 val = GINT_TO_POINTER(purple_request_field_bool_get_value(field)); | |
15817 | 222 break; |
15822 | 223 case PURPLE_REQUEST_FIELD_INTEGER: |
224 val = GINT_TO_POINTER(purple_request_field_int_get_value(field)); | |
15817 | 225 break; |
15822 | 226 case PURPLE_REQUEST_FIELD_STRING: |
227 val = (gpointer)purple_request_field_string_get_value(field); | |
15817 | 228 break; |
229 default: | |
230 break; | |
231 } | |
232 | |
15822 | 233 pt = purple_prefs_get_type(id); |
15817 | 234 switch (pt) |
235 { | |
15822 | 236 case PURPLE_PREF_INT: |
237 if (type == PURPLE_REQUEST_FIELD_LIST) /* Lists always return string */ | |
15817 | 238 sscanf(val, "%ld", (long int *)&val); |
15822 | 239 purple_prefs_set_int(id, GPOINTER_TO_INT(val)); |
15817 | 240 break; |
15822 | 241 case PURPLE_PREF_BOOLEAN: |
242 purple_prefs_set_bool(id, GPOINTER_TO_INT(val)); | |
15817 | 243 break; |
15822 | 244 case PURPLE_PREF_STRING: |
245 purple_prefs_set_string(id, val); | |
15817 | 246 break; |
247 default: | |
248 break; | |
249 } | |
250 } | |
251 } | |
252 free_strings(); | |
253 } | |
254 | |
255 static void | |
15822 | 256 add_pref_group(PurpleRequestFields *fields, const char *title, Prefs *prefs) |
15817 | 257 { |
15822 | 258 PurpleRequestField *field; |
259 PurpleRequestFieldGroup *group; | |
15817 | 260 int i; |
261 | |
15822 | 262 group = purple_request_field_group_new(title); |
263 purple_request_fields_add_group(fields, group); | |
15817 | 264 for (i = 0; prefs[i].pref; i++) |
265 { | |
266 field = get_pref_field(prefs + i); | |
267 if (field) | |
15822 | 268 purple_request_field_group_add_field(group, field); |
15817 | 269 } |
270 } | |
271 | |
272 void finch_prefs_show_all() | |
273 { | |
15822 | 274 PurpleRequestFields *fields; |
15817 | 275 |
15822 | 276 fields = purple_request_fields_new(); |
15817 | 277 |
278 add_pref_group(fields, _("Buddy List"), blist); | |
279 add_pref_group(fields, _("Conversations"), convs); | |
280 add_pref_group(fields, _("Logging"), logging); | |
281 add_pref_group(fields, _("Idle"), idle); | |
282 | |
15822 | 283 purple_request_fields(NULL, _("Preferences"), NULL, NULL, fields, |
15817 | 284 _("Save"), G_CALLBACK(save_cb), _("Cancel"), free_strings, NULL); |
285 } | |
286 |