Mercurial > pidgin
annotate finch/gntprefs.c @ 16362:7d0d3a746299
merge of '0ad153fbef57439d42601681df47200b190f5306'
and '7bc42f0640ea8a9dce96dfc69f883523273e253d'
author | Ethan Blanton <elb@pidgin.im> |
---|---|
date | Wed, 25 Apr 2007 02:23:29 +0000 |
parents | 8c89913276b3 |
children | 4999bbc52881 |
rev | line source |
---|---|
15817 | 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:
15870
diff
changeset
|
3 * @ingroup finch |
15817 | 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 { |
16310
8c89913276b3
Implement the plugin-pref ui using the request api. The preferences for the core plugins can now be modified from Finch. And no new strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16194
diff
changeset
|
201 finch_request_save_in_prefs(data, allfields); |
15817 | 202 free_strings(); |
203 } | |
204 | |
205 static void | |
15822 | 206 add_pref_group(PurpleRequestFields *fields, const char *title, Prefs *prefs) |
15817 | 207 { |
15822 | 208 PurpleRequestField *field; |
209 PurpleRequestFieldGroup *group; | |
15817 | 210 int i; |
211 | |
15822 | 212 group = purple_request_field_group_new(title); |
213 purple_request_fields_add_group(fields, group); | |
15817 | 214 for (i = 0; prefs[i].pref; i++) |
215 { | |
216 field = get_pref_field(prefs + i); | |
217 if (field) | |
15822 | 218 purple_request_field_group_add_field(group, field); |
15817 | 219 } |
220 } | |
221 | |
222 void finch_prefs_show_all() | |
223 { | |
15822 | 224 PurpleRequestFields *fields; |
15817 | 225 |
15822 | 226 fields = purple_request_fields_new(); |
15817 | 227 |
228 add_pref_group(fields, _("Buddy List"), blist); | |
229 add_pref_group(fields, _("Conversations"), convs); | |
230 add_pref_group(fields, _("Logging"), logging); | |
231 add_pref_group(fields, _("Idle"), idle); | |
232 | |
15822 | 233 purple_request_fields(NULL, _("Preferences"), NULL, NULL, fields, |
15817 | 234 _("Save"), G_CALLBACK(save_cb), _("Cancel"), free_strings, NULL); |
235 } | |
236 |