Mercurial > pidgin.yaz
annotate finch/gntprefs.c @ 16278:70a368273778
Fix that pesky ICQ "Unable to add buddy 1" error. Basically we were
trying to add something to our server-stored buddy list, but there
was no "master container" to add the item to. For normal buddies the
oscar code added the master container if needed, but that wasn't
happening for things like the buddy icon item, or the permit/deny item.
So if you had an empty buddylist and you attempted to set an icon
for your icq account, or you changed your privacy setting, or you
went invisible or not invisible then you'd see the error.
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Fri, 20 Apr 2007 06:51:33 +0000 |
parents | 0f0832c13fcb |
children | 8c89913276b3 |
rev | line source |
---|---|
15818 | 1 /** |
2 * @file gntprefs.c GNT Preferences API | |
16194
0f0832c13fcb
Rename the Doxygen group from gntui to finch and define the finch group
Richard Laager <rlaager@wiktel.com>
parents:
15871
diff
changeset
|
3 * @ingroup finch |
15818 | 4 * |
15871
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15823
diff
changeset
|
5 * finch |
15818 | 6 * |
15871
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15823
diff
changeset
|
7 * Finch is the legal property of its developers, whose names are too numerous |
15818 | 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 | |
15823 | 28 #include "finch.h" |
15818 | 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 { | |
15823 | 38 purple_prefs_add_none("/purple"); |
39 purple_prefs_add_none("/purple/gnt"); | |
15818 | 40 |
15823 | 41 purple_prefs_add_none("/purple/gnt/plugins"); |
42 purple_prefs_add_path_list("/purple/gnt/plugins/loaded", NULL); | |
15818 | 43 |
15823 | 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 */ | |
15818 | 47 } |
48 | |
49 typedef struct | |
50 { | |
15823 | 51 PurplePrefType type; |
15818 | 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 { | |
15823 | 60 return purple_log_logger_get_options(); |
15818 | 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")); | |
15823 | 70 list = g_list_append(list, "purple"); |
15818 | 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; | |
15823 | 81 for (iter = purple_savedstatuses_get_all(); iter; iter = iter->next) { |
15818 | 82 char *str; |
15823 | 83 if (purple_savedstatus_is_transient(iter->data)) |
15818 | 84 continue; |
15823 | 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)); | |
15818 | 87 list = g_list_append(list, str); |
88 freestrings = g_list_prepend(freestrings, str); | |
89 } | |
90 return list; | |
91 } | |
92 | |
15823 | 93 static PurpleRequestField * |
15818 | 94 get_pref_field(Prefs *prefs) |
95 { | |
15823 | 96 PurpleRequestField *field = NULL; |
15818 | 97 |
98 if (prefs->lv == NULL) | |
99 { | |
100 switch (prefs->type) | |
101 { | |
15823 | 102 case PURPLE_PREF_BOOLEAN: |
103 field = purple_request_field_bool_new(prefs->pref, _(prefs->label), | |
104 purple_prefs_get_bool(prefs->pref)); | |
15818 | 105 break; |
15823 | 106 case PURPLE_PREF_INT: |
107 field = purple_request_field_int_new(prefs->pref, _(prefs->label), | |
108 purple_prefs_get_int(prefs->pref)); | |
15818 | 109 break; |
15823 | 110 case PURPLE_PREF_STRING: |
111 field = purple_request_field_string_new(prefs->pref, _(prefs->label), | |
112 purple_prefs_get_string(prefs->pref), FALSE); | |
15818 | 113 break; |
114 default: | |
115 break; | |
116 } | |
117 } | |
118 else | |
119 { | |
120 GList *list = prefs->lv(), *iter; | |
121 if (list) | |
15823 | 122 field = purple_request_field_list_new(prefs->pref, _(prefs->label)); |
15818 | 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 { | |
15823 | 131 case PURPLE_PREF_BOOLEAN: |
15818 | 132 sscanf(iter->data, "%d", &idata); |
15823 | 133 if (purple_prefs_get_bool(prefs->pref) == idata) |
15818 | 134 select = TRUE; |
135 break; | |
15823 | 136 case PURPLE_PREF_INT: |
15818 | 137 sscanf(iter->data, "%d", &idata); |
15823 | 138 if (purple_prefs_get_int(prefs->pref) == idata) |
15818 | 139 select = TRUE; |
140 break; | |
15823 | 141 case PURPLE_PREF_STRING: |
142 if (strcmp(purple_prefs_get_string(prefs->pref), iter->data) == 0) | |
15818 | 143 select = TRUE; |
144 break; | |
145 default: | |
146 break; | |
147 } | |
15823 | 148 purple_request_field_list_add(field, data, iter->data); |
15818 | 149 if (select) |
15823 | 150 purple_request_field_list_add_selected(field, data); |
15818 | 151 } |
152 g_list_free(list); | |
153 } | |
154 return field; | |
155 } | |
156 | |
157 static Prefs blist[] = | |
158 { | |
15823 | 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} | |
15818 | 162 }; |
163 | |
164 static Prefs convs[] = | |
165 { | |
15823 | 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} | |
15818 | 169 }; |
170 | |
171 static Prefs logging[] = | |
172 { | |
15823 | 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}, | |
15818 | 178 }; |
179 | |
180 /* XXX: Translate after the freeze */ | |
181 static Prefs idle[] = | |
182 { | |
15823 | 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}, | |
15818 | 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 | |
15823 | 199 save_cb(void *data, PurpleRequestFields *allfields) |
15818 | 200 { |
201 GList *list; | |
15823 | 202 for (list = purple_request_fields_get_groups(allfields); list; list = list->next) |
15818 | 203 { |
15823 | 204 PurpleRequestFieldGroup *group = list->data; |
205 GList *fields = purple_request_field_group_get_fields(group); | |
15818 | 206 |
207 for (; fields ; fields = fields->next) | |
208 { | |
15823 | 209 PurpleRequestField *field = fields->data; |
210 PurpleRequestFieldType type = purple_request_field_get_type(field); | |
211 PurplePrefType pt; | |
15818 | 212 gpointer val = NULL; |
15823 | 213 const char *id = purple_request_field_get_id(field); |
15818 | 214 |
215 switch (type) | |
216 { | |
15823 | 217 case PURPLE_REQUEST_FIELD_LIST: |
218 val = purple_request_field_list_get_selected(field)->data; | |
15818 | 219 break; |
15823 | 220 case PURPLE_REQUEST_FIELD_BOOLEAN: |
221 val = GINT_TO_POINTER(purple_request_field_bool_get_value(field)); | |
15818 | 222 break; |
15823 | 223 case PURPLE_REQUEST_FIELD_INTEGER: |
224 val = GINT_TO_POINTER(purple_request_field_int_get_value(field)); | |
15818 | 225 break; |
15823 | 226 case PURPLE_REQUEST_FIELD_STRING: |
227 val = (gpointer)purple_request_field_string_get_value(field); | |
15818 | 228 break; |
229 default: | |
230 break; | |
231 } | |
232 | |
15823 | 233 pt = purple_prefs_get_type(id); |
15818 | 234 switch (pt) |
235 { | |
15823 | 236 case PURPLE_PREF_INT: |
237 if (type == PURPLE_REQUEST_FIELD_LIST) /* Lists always return string */ | |
15818 | 238 sscanf(val, "%ld", (long int *)&val); |
15823 | 239 purple_prefs_set_int(id, GPOINTER_TO_INT(val)); |
15818 | 240 break; |
15823 | 241 case PURPLE_PREF_BOOLEAN: |
242 purple_prefs_set_bool(id, GPOINTER_TO_INT(val)); | |
15818 | 243 break; |
15823 | 244 case PURPLE_PREF_STRING: |
245 purple_prefs_set_string(id, val); | |
15818 | 246 break; |
247 default: | |
248 break; | |
249 } | |
250 } | |
251 } | |
252 free_strings(); | |
253 } | |
254 | |
255 static void | |
15823 | 256 add_pref_group(PurpleRequestFields *fields, const char *title, Prefs *prefs) |
15818 | 257 { |
15823 | 258 PurpleRequestField *field; |
259 PurpleRequestFieldGroup *group; | |
15818 | 260 int i; |
261 | |
15823 | 262 group = purple_request_field_group_new(title); |
263 purple_request_fields_add_group(fields, group); | |
15818 | 264 for (i = 0; prefs[i].pref; i++) |
265 { | |
266 field = get_pref_field(prefs + i); | |
267 if (field) | |
15823 | 268 purple_request_field_group_add_field(group, field); |
15818 | 269 } |
270 } | |
271 | |
272 void finch_prefs_show_all() | |
273 { | |
15823 | 274 PurpleRequestFields *fields; |
15818 | 275 |
15823 | 276 fields = purple_request_fields_new(); |
15818 | 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 | |
15823 | 283 purple_request_fields(NULL, _("Preferences"), NULL, NULL, fields, |
15818 | 284 _("Save"), G_CALLBACK(save_cb), _("Cancel"), free_strings, NULL); |
285 } | |
286 |