comparison finch/gntprefs.c @ 15818:0e3a8505ebbe

renamed gaim-text to finch
author Sean Egan <seanegan@gmail.com>
date Sun, 18 Mar 2007 19:38:15 +0000
parents
children 32c366eeeb99
comparison
equal deleted inserted replaced
15817:317e7613e581 15818:0e3a8505ebbe
1 /**
2 * @file gntprefs.c GNT Preferences API
3 * @ingroup gntui
4 *
5 * gaim
6 *
7 * Gaim is the legal property of its developers, whose names are too numerous
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
28 #include "gntgaim.h"
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 {
38 gaim_prefs_add_none("/gaim");
39 gaim_prefs_add_none("/gaim/gnt");
40
41 gaim_prefs_add_none("/gaim/gnt/plugins");
42 gaim_prefs_add_path_list("/gaim/gnt/plugins/loaded", NULL);
43
44 gaim_prefs_add_none("/gaim/gnt/conversations");
45 gaim_prefs_add_bool("/gaim/gnt/conversations/timestamps", TRUE);
46 gaim_prefs_add_bool("/gaim/gnt/conversations/notify_typing", FALSE); /* XXX: Not functional yet */
47 }
48
49 typedef struct
50 {
51 GaimPrefType type;
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 {
60 return gaim_log_logger_get_options();
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"));
70 list = g_list_append(list, "gaim");
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;
81 for (iter = gaim_savedstatuses_get_all(); iter; iter = iter->next) {
82 char *str;
83 if (gaim_savedstatus_is_transient(iter->data))
84 continue;
85 str = g_strdup_printf("%ld", gaim_savedstatus_get_creation_time(iter->data));
86 list = g_list_append(list, (char*)gaim_savedstatus_get_title(iter->data));
87 list = g_list_append(list, str);
88 freestrings = g_list_prepend(freestrings, str);
89 }
90 return list;
91 }
92
93 static GaimRequestField *
94 get_pref_field(Prefs *prefs)
95 {
96 GaimRequestField *field = NULL;
97
98 if (prefs->lv == NULL)
99 {
100 switch (prefs->type)
101 {
102 case GAIM_PREF_BOOLEAN:
103 field = gaim_request_field_bool_new(prefs->pref, _(prefs->label),
104 gaim_prefs_get_bool(prefs->pref));
105 break;
106 case GAIM_PREF_INT:
107 field = gaim_request_field_int_new(prefs->pref, _(prefs->label),
108 gaim_prefs_get_int(prefs->pref));
109 break;
110 case GAIM_PREF_STRING:
111 field = gaim_request_field_string_new(prefs->pref, _(prefs->label),
112 gaim_prefs_get_string(prefs->pref), FALSE);
113 break;
114 default:
115 break;
116 }
117 }
118 else
119 {
120 GList *list = prefs->lv(), *iter;
121 if (list)
122 field = gaim_request_field_list_new(prefs->pref, _(prefs->label));
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 {
131 case GAIM_PREF_BOOLEAN:
132 sscanf(iter->data, "%d", &idata);
133 if (gaim_prefs_get_bool(prefs->pref) == idata)
134 select = TRUE;
135 break;
136 case GAIM_PREF_INT:
137 sscanf(iter->data, "%d", &idata);
138 if (gaim_prefs_get_int(prefs->pref) == idata)
139 select = TRUE;
140 break;
141 case GAIM_PREF_STRING:
142 if (strcmp(gaim_prefs_get_string(prefs->pref), iter->data) == 0)
143 select = TRUE;
144 break;
145 default:
146 break;
147 }
148 gaim_request_field_list_add(field, data, iter->data);
149 if (select)
150 gaim_request_field_list_add_selected(field, data);
151 }
152 g_list_free(list);
153 }
154 return field;
155 }
156
157 static Prefs blist[] =
158 {
159 {GAIM_PREF_BOOLEAN, "/gaim/gnt/blist/idletime", N_("Show Idle Time"), NULL},
160 {GAIM_PREF_BOOLEAN, "/gaim/gnt/blist/showoffline", N_("Show Offline Buddies"), NULL},
161 {GAIM_PREF_NONE, NULL, NULL, NULL}
162 };
163
164 static Prefs convs[] =
165 {
166 {GAIM_PREF_BOOLEAN, "/gaim/gnt/conversations/timestamps", N_("Show Timestamps"), NULL},
167 {GAIM_PREF_BOOLEAN, "/gaim/gnt/conversations/notify_typing", N_("Notify buddies when you are typing"), NULL},
168 {GAIM_PREF_NONE, NULL, NULL, NULL}
169 };
170
171 static Prefs logging[] =
172 {
173 {GAIM_PREF_STRING, "/core/logging/format", N_("Log format"), get_log_options},
174 {GAIM_PREF_BOOLEAN, "/core/logging/log_ims", N_("Log IMs"), NULL},
175 {GAIM_PREF_BOOLEAN, "/core/logging/log_chats", N_("Log chats"), NULL},
176 {GAIM_PREF_BOOLEAN, "/core/logging/log_system", N_("Log status change events"), NULL},
177 {GAIM_PREF_NONE, NULL, NULL, NULL},
178 };
179
180 /* XXX: Translate after the freeze */
181 static Prefs idle[] =
182 {
183 {GAIM_PREF_STRING, "/core/away/idle_reporting", "Report Idle time", get_idle_options},
184 {GAIM_PREF_BOOLEAN, "/core/away/away_when_idle", "Change status when idle", NULL},
185 {GAIM_PREF_INT, "/core/away/mins_before_away", "Minutes before changing status", NULL},
186 {GAIM_PREF_INT, "/core/savedstatus/idleaway", "Change status to", get_status_titles},
187 {GAIM_PREF_NONE, NULL, NULL, NULL},
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
199 save_cb(void *data, GaimRequestFields *allfields)
200 {
201 GList *list;
202 for (list = gaim_request_fields_get_groups(allfields); list; list = list->next)
203 {
204 GaimRequestFieldGroup *group = list->data;
205 GList *fields = gaim_request_field_group_get_fields(group);
206
207 for (; fields ; fields = fields->next)
208 {
209 GaimRequestField *field = fields->data;
210 GaimRequestFieldType type = gaim_request_field_get_type(field);
211 GaimPrefType pt;
212 gpointer val = NULL;
213 const char *id = gaim_request_field_get_id(field);
214
215 switch (type)
216 {
217 case GAIM_REQUEST_FIELD_LIST:
218 val = gaim_request_field_list_get_selected(field)->data;
219 break;
220 case GAIM_REQUEST_FIELD_BOOLEAN:
221 val = GINT_TO_POINTER(gaim_request_field_bool_get_value(field));
222 break;
223 case GAIM_REQUEST_FIELD_INTEGER:
224 val = GINT_TO_POINTER(gaim_request_field_int_get_value(field));
225 break;
226 case GAIM_REQUEST_FIELD_STRING:
227 val = (gpointer)gaim_request_field_string_get_value(field);
228 break;
229 default:
230 break;
231 }
232
233 pt = gaim_prefs_get_type(id);
234 switch (pt)
235 {
236 case GAIM_PREF_INT:
237 if (type == GAIM_REQUEST_FIELD_LIST) /* Lists always return string */
238 sscanf(val, "%ld", (long int *)&val);
239 gaim_prefs_set_int(id, GPOINTER_TO_INT(val));
240 break;
241 case GAIM_PREF_BOOLEAN:
242 gaim_prefs_set_bool(id, GPOINTER_TO_INT(val));
243 break;
244 case GAIM_PREF_STRING:
245 gaim_prefs_set_string(id, val);
246 break;
247 default:
248 break;
249 }
250 }
251 }
252 free_strings();
253 }
254
255 static void
256 add_pref_group(GaimRequestFields *fields, const char *title, Prefs *prefs)
257 {
258 GaimRequestField *field;
259 GaimRequestFieldGroup *group;
260 int i;
261
262 group = gaim_request_field_group_new(title);
263 gaim_request_fields_add_group(fields, group);
264 for (i = 0; prefs[i].pref; i++)
265 {
266 field = get_pref_field(prefs + i);
267 if (field)
268 gaim_request_field_group_add_field(group, field);
269 }
270 }
271
272 void finch_prefs_show_all()
273 {
274 GaimRequestFields *fields;
275
276 fields = gaim_request_fields_new();
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
283 gaim_request_fields(NULL, _("Preferences"), NULL, NULL, fields,
284 _("Save"), G_CALLBACK(save_cb), _("Cancel"), free_strings, NULL);
285 }
286