Change Finch to use Pidgin's clientkey/devid when connecting to ICQ.
[pidgin-git.git] / finch / gntprefs.c
blob02ebf6a98e786e8be728d995165369e09a684938
1 /**
2 * @file gntprefs.c GNT Preferences API
3 * @ingroup finch
4 */
6 /* finch
8 * Finch is the legal property of its developers, whose names are too numerous
9 * to list here. Please refer to the COPYRIGHT file distributed with this
10 * source distribution.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
26 #include "finch.h"
27 #include <internal.h>
29 #include <prefs.h>
30 #include <savedstatuses.h>
32 #include "gntprefs.h"
33 #include "gntrequest.h"
35 #include "gnt.h"
36 #include "gntwidget.h"
38 #include <string.h>
40 static struct {
41 GList *freestrings; /* strings to be freed when the pref-window is closed */
42 gboolean showing;
43 GntWidget *window;
44 } pref_request;
46 void finch_prefs_init()
48 purple_prefs_add_none("/finch");
50 purple_prefs_add_none("/finch/plugins");
51 purple_prefs_add_path_list("/finch/plugins/loaded", NULL);
52 purple_prefs_add_path_list("/finch/plugins/seen", NULL);
54 purple_prefs_add_none("/finch/conversations");
55 purple_prefs_add_bool("/finch/conversations/timestamps", TRUE);
56 purple_prefs_add_bool("/finch/conversations/notify_typing", FALSE);
58 purple_prefs_add_none("/finch/filelocations");
59 purple_prefs_add_path("/finch/filelocations/last_save_folder", "");
60 purple_prefs_add_path("/finch/filelocations/last_save_folder", "");
63 void finch_prefs_update_old()
65 const char *str = NULL;
67 purple_prefs_rename("/gaim/gnt", "/finch");
68 purple_prefs_rename("/purple/gnt", "/finch");
70 if ((str = purple_prefs_get_string("/purple/away/idle_reporting")) &&
71 strcmp(str, "gaim") == 0)
72 purple_prefs_set_string("/purple/away/idle_reporting", "purple");
75 typedef struct
77 PurplePrefType type;
78 const char *pref;
79 const char *label;
80 GList *(*lv)(void); /* If the value is to be selected from a number of choices */
81 } Prefs;
83 static GList *
84 get_log_options(void)
86 return purple_log_logger_get_options();
89 static GList *
90 get_idle_options(void)
92 GList *list = NULL;
93 list = g_list_append(list, (char *)_("Based on keyboard use"));
94 list = g_list_append(list, "system");
95 list = g_list_append(list, (char*)_("From last sent message"));
96 list = g_list_append(list, "purple");
97 list = g_list_append(list, (char*)_("Never"));
98 list = g_list_append(list, "never");
99 return list;
102 static GList *
103 get_status_titles(void)
105 GList *list = NULL;
106 GList *iter;
107 for (iter = purple_savedstatuses_get_all(); iter; iter = iter->next) {
108 char *str;
109 if (purple_savedstatus_is_transient(iter->data))
110 continue;
111 str = g_strdup_printf("%ld", purple_savedstatus_get_creation_time(iter->data));
112 list = g_list_append(list, (char*)purple_savedstatus_get_title(iter->data));
113 list = g_list_append(list, str);
114 pref_request.freestrings = g_list_prepend(pref_request.freestrings, str);
116 return list;
119 static PurpleRequestField *
120 get_pref_field(Prefs *prefs)
122 PurpleRequestField *field = NULL;
124 if (prefs->lv == NULL)
126 switch (prefs->type)
128 case PURPLE_PREF_BOOLEAN:
129 field = purple_request_field_bool_new(prefs->pref, _(prefs->label),
130 purple_prefs_get_bool(prefs->pref));
131 break;
132 case PURPLE_PREF_INT:
133 field = purple_request_field_int_new(prefs->pref, _(prefs->label),
134 purple_prefs_get_int(prefs->pref));
135 break;
136 case PURPLE_PREF_STRING:
137 field = purple_request_field_string_new(prefs->pref, _(prefs->label),
138 purple_prefs_get_string(prefs->pref), FALSE);
139 break;
140 default:
141 break;
144 else
146 GList *list = prefs->lv(), *iter;
147 if (list)
148 field = purple_request_field_list_new(prefs->pref, _(prefs->label));
149 for (iter = list; iter; iter = iter->next)
151 gboolean select = FALSE;
152 const char *data = iter->data;
153 int idata;
154 iter = iter->next;
155 switch (prefs->type)
157 case PURPLE_PREF_BOOLEAN:
158 sscanf(iter->data, "%d", &idata);
159 if (purple_prefs_get_bool(prefs->pref) == idata)
160 select = TRUE;
161 break;
162 case PURPLE_PREF_INT:
163 sscanf(iter->data, "%d", &idata);
164 if (purple_prefs_get_int(prefs->pref) == idata)
165 select = TRUE;
166 break;
167 case PURPLE_PREF_STRING:
168 if (strcmp(purple_prefs_get_string(prefs->pref), iter->data) == 0)
169 select = TRUE;
170 break;
171 default:
172 break;
174 purple_request_field_list_add_icon(field, data, NULL, iter->data);
175 if (select)
176 purple_request_field_list_add_selected(field, data);
178 g_list_free(list);
180 return field;
183 static Prefs blist[] =
185 {PURPLE_PREF_BOOLEAN, "/finch/blist/idletime", N_("Show Idle Time"), NULL},
186 {PURPLE_PREF_BOOLEAN, "/finch/blist/showoffline", N_("Show Offline Buddies"), NULL},
187 {PURPLE_PREF_NONE, NULL, NULL, NULL}
190 static Prefs convs[] =
192 {PURPLE_PREF_BOOLEAN, "/finch/conversations/timestamps", N_("Show Timestamps"), NULL},
193 {PURPLE_PREF_BOOLEAN, "/finch/conversations/notify_typing", N_("Notify buddies when you are typing"), NULL},
194 {PURPLE_PREF_NONE, NULL, NULL, NULL}
197 static Prefs logging[] =
199 {PURPLE_PREF_STRING, "/purple/logging/format", N_("Log format"), get_log_options},
200 {PURPLE_PREF_BOOLEAN, "/purple/logging/log_ims", N_("Log IMs"), NULL},
201 {PURPLE_PREF_BOOLEAN, "/purple/logging/log_chats", N_("Log chats"), NULL},
202 {PURPLE_PREF_BOOLEAN, "/purple/logging/log_system", N_("Log status change events"), NULL},
203 {PURPLE_PREF_NONE, NULL, NULL, NULL},
206 static Prefs idle[] =
208 {PURPLE_PREF_STRING, "/purple/away/idle_reporting", N_("Report Idle time"), get_idle_options},
209 {PURPLE_PREF_BOOLEAN, "/purple/away/away_when_idle", N_("Change status when idle"), NULL},
210 {PURPLE_PREF_INT, "/purple/away/mins_before_away", N_("Minutes before changing status"), NULL},
211 {PURPLE_PREF_INT, "/purple/savedstatus/idleaway", N_("Change status to"), get_status_titles},
212 {PURPLE_PREF_NONE, NULL, NULL, NULL},
215 static void
216 free_strings(void)
218 g_list_foreach(pref_request.freestrings, (GFunc)g_free, NULL);
219 g_list_free(pref_request.freestrings);
220 pref_request.freestrings = NULL;
221 pref_request.showing = FALSE;
224 static void
225 save_cb(void *data, PurpleRequestFields *allfields)
227 finch_request_save_in_prefs(data, allfields);
228 free_strings();
231 static void
232 add_pref_group(PurpleRequestFields *fields, const char *title, Prefs *prefs)
234 PurpleRequestField *field;
235 PurpleRequestFieldGroup *group;
236 int i;
238 group = purple_request_field_group_new(title);
239 purple_request_fields_add_group(fields, group);
240 for (i = 0; prefs[i].pref; i++)
242 field = get_pref_field(prefs + i);
243 if (field)
244 purple_request_field_group_add_field(group, field);
248 void finch_prefs_show_all()
250 PurpleRequestFields *fields;
252 if (pref_request.showing) {
253 gnt_window_present(pref_request.window);
254 return;
257 fields = purple_request_fields_new();
259 add_pref_group(fields, _("Buddy List"), blist);
260 add_pref_group(fields, _("Conversations"), convs);
261 add_pref_group(fields, _("Logging"), logging);
262 add_pref_group(fields, _("Idle"), idle);
264 pref_request.showing = TRUE;
265 pref_request.window = purple_request_fields(NULL, _("Preferences"), NULL, NULL, fields,
266 _("Save"), G_CALLBACK(save_cb), _("Cancel"), free_strings,
267 NULL, NULL, NULL,
268 NULL);