Mercurial > pidgin
annotate finch/gntprefs.c @ 19135:3ec3d55a1e37
FIX: Setting combo_box doesn't cause memory corruption.
author | Eric Polino <aluink@pidgin.im> |
---|---|
date | Thu, 05 Jul 2007 18:15:32 +0000 |
parents | 2d4df5ef0090 |
children | 719f73b9a593 |
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 */ | |
18210
b8572b937c09
#include reorganizations to allow compiling with glib < 2.8 using the
Stu Tomlinson <stu@nosnilmot.com>
parents:
18118
diff
changeset
|
25 #include "finch.h" |
b8572b937c09
#include reorganizations to allow compiling with glib < 2.8 using the
Stu Tomlinson <stu@nosnilmot.com>
parents:
18118
diff
changeset
|
26 |
15817 | 27 #include <prefs.h> |
28 #include <savedstatuses.h> | |
29 | |
30 #include "gntprefs.h" | |
31 #include "gntrequest.h" | |
32 | |
18345
2d4df5ef0090
If the action-windows are already there, then bring them to front when
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18334
diff
changeset
|
33 #include "gnt.h" |
2d4df5ef0090
If the action-windows are already there, then bring them to front when
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18334
diff
changeset
|
34 #include "gntwidget.h" |
2d4df5ef0090
If the action-windows are already there, then bring them to front when
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18334
diff
changeset
|
35 |
15817 | 36 #include <string.h> |
37 | |
18334
65fedb03ac05
Mark some string for translation, and show only one preference window at a
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18210
diff
changeset
|
38 static struct { |
65fedb03ac05
Mark some string for translation, and show only one preference window at a
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18210
diff
changeset
|
39 GList *freestrings; /* strings to be freed when the pref-window is closed */ |
65fedb03ac05
Mark some string for translation, and show only one preference window at a
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18210
diff
changeset
|
40 gboolean showing; |
18345
2d4df5ef0090
If the action-windows are already there, then bring them to front when
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18334
diff
changeset
|
41 GntWidget *window; |
18334
65fedb03ac05
Mark some string for translation, and show only one preference window at a
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18210
diff
changeset
|
42 } pref_request; |
15817 | 43 |
44 void finch_prefs_init() | |
45 { | |
16424
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16310
diff
changeset
|
46 purple_prefs_add_none("/finch"); |
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16310
diff
changeset
|
47 |
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16310
diff
changeset
|
48 purple_prefs_add_none("/finch/plugins"); |
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16310
diff
changeset
|
49 purple_prefs_add_path_list("/finch/plugins/loaded", NULL); |
16941
beb960114f7d
I liked Etan's suggestion in devel. Now, Finch will bold unseen plugins in the plugin dialog. A plugin is considered 'seen' only after the details of the plugin is viewed by the user.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16565
diff
changeset
|
50 purple_prefs_add_path_list("/finch/plugins/seen", NULL); |
15817 | 51 |
16424
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16310
diff
changeset
|
52 purple_prefs_add_none("/finch/conversations"); |
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16310
diff
changeset
|
53 purple_prefs_add_bool("/finch/conversations/timestamps", TRUE); |
16565
ac0d07c7fd90
Pref migration for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16439
diff
changeset
|
54 purple_prefs_add_bool("/finch/conversations/notify_typing", FALSE); |
ac0d07c7fd90
Pref migration for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16439
diff
changeset
|
55 } |
ac0d07c7fd90
Pref migration for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16439
diff
changeset
|
56 |
ac0d07c7fd90
Pref migration for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16439
diff
changeset
|
57 void finch_prefs_update_old() |
ac0d07c7fd90
Pref migration for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16439
diff
changeset
|
58 { |
ac0d07c7fd90
Pref migration for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16439
diff
changeset
|
59 const char *str = NULL; |
ac0d07c7fd90
Pref migration for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16439
diff
changeset
|
60 |
16424
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16310
diff
changeset
|
61 purple_prefs_rename("/gaim/gnt", "/finch"); |
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16310
diff
changeset
|
62 purple_prefs_rename("/purple/gnt", "/finch"); |
16565
ac0d07c7fd90
Pref migration for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16439
diff
changeset
|
63 |
ac0d07c7fd90
Pref migration for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16439
diff
changeset
|
64 if ((str = purple_prefs_get_string("/purple/away/idle_reporting")) && |
ac0d07c7fd90
Pref migration for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16439
diff
changeset
|
65 strcmp(str, "gaim") == 0) |
ac0d07c7fd90
Pref migration for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16439
diff
changeset
|
66 purple_prefs_set_string("/purple/away/idle_reporting", "purple"); |
15817 | 67 } |
68 | |
69 typedef struct | |
70 { | |
15822 | 71 PurplePrefType type; |
15817 | 72 const char *pref; |
73 const char *label; | |
74 GList *(*lv)(); /* If the value is to be selected from a number of choices */ | |
75 } Prefs; | |
76 | |
77 static GList * | |
78 get_log_options() | |
79 { | |
15822 | 80 return purple_log_logger_get_options(); |
15817 | 81 } |
82 | |
83 static GList * | |
84 get_idle_options() | |
85 { | |
86 GList *list = NULL; | |
17144
c61187e0c752
Fix a compiler warning.
Richard Laager <rlaager@wiktel.com>
parents:
17137
diff
changeset
|
87 list = g_list_append(list, (char *)_("Based on keyboard use")); |
15817 | 88 list = g_list_append(list, "system"); |
89 list = g_list_append(list, (char*)_("From last sent message")); | |
15822 | 90 list = g_list_append(list, "purple"); |
15817 | 91 list = g_list_append(list, (char*)_("Never")); |
92 list = g_list_append(list, "never"); | |
93 return list; | |
94 } | |
95 | |
96 static GList * | |
97 get_status_titles() | |
98 { | |
99 GList *list = NULL; | |
18118
ab6d2763b8d8
Re-fix the DBus list handling code by killing const GList* / const GSList*
Richard Laager <rlaager@wiktel.com>
parents:
17144
diff
changeset
|
100 GList *iter; |
15822 | 101 for (iter = purple_savedstatuses_get_all(); iter; iter = iter->next) { |
15817 | 102 char *str; |
15822 | 103 if (purple_savedstatus_is_transient(iter->data)) |
15817 | 104 continue; |
15822 | 105 str = g_strdup_printf("%ld", purple_savedstatus_get_creation_time(iter->data)); |
106 list = g_list_append(list, (char*)purple_savedstatus_get_title(iter->data)); | |
15817 | 107 list = g_list_append(list, str); |
18334
65fedb03ac05
Mark some string for translation, and show only one preference window at a
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18210
diff
changeset
|
108 pref_request.freestrings = g_list_prepend(pref_request.freestrings, str); |
15817 | 109 } |
110 return list; | |
111 } | |
112 | |
15822 | 113 static PurpleRequestField * |
15817 | 114 get_pref_field(Prefs *prefs) |
115 { | |
15822 | 116 PurpleRequestField *field = NULL; |
15817 | 117 |
118 if (prefs->lv == NULL) | |
119 { | |
120 switch (prefs->type) | |
121 { | |
15822 | 122 case PURPLE_PREF_BOOLEAN: |
123 field = purple_request_field_bool_new(prefs->pref, _(prefs->label), | |
124 purple_prefs_get_bool(prefs->pref)); | |
15817 | 125 break; |
15822 | 126 case PURPLE_PREF_INT: |
127 field = purple_request_field_int_new(prefs->pref, _(prefs->label), | |
128 purple_prefs_get_int(prefs->pref)); | |
15817 | 129 break; |
15822 | 130 case PURPLE_PREF_STRING: |
131 field = purple_request_field_string_new(prefs->pref, _(prefs->label), | |
132 purple_prefs_get_string(prefs->pref), FALSE); | |
15817 | 133 break; |
134 default: | |
135 break; | |
136 } | |
137 } | |
138 else | |
139 { | |
140 GList *list = prefs->lv(), *iter; | |
141 if (list) | |
15822 | 142 field = purple_request_field_list_new(prefs->pref, _(prefs->label)); |
15817 | 143 for (iter = list; iter; iter = iter->next) |
144 { | |
145 gboolean select = FALSE; | |
146 const char *data = iter->data; | |
147 int idata; | |
148 iter = iter->next; | |
149 switch (prefs->type) | |
150 { | |
15822 | 151 case PURPLE_PREF_BOOLEAN: |
15817 | 152 sscanf(iter->data, "%d", &idata); |
15822 | 153 if (purple_prefs_get_bool(prefs->pref) == idata) |
15817 | 154 select = TRUE; |
155 break; | |
15822 | 156 case PURPLE_PREF_INT: |
15817 | 157 sscanf(iter->data, "%d", &idata); |
15822 | 158 if (purple_prefs_get_int(prefs->pref) == idata) |
15817 | 159 select = TRUE; |
160 break; | |
15822 | 161 case PURPLE_PREF_STRING: |
162 if (strcmp(purple_prefs_get_string(prefs->pref), iter->data) == 0) | |
15817 | 163 select = TRUE; |
164 break; | |
165 default: | |
166 break; | |
167 } | |
15822 | 168 purple_request_field_list_add(field, data, iter->data); |
15817 | 169 if (select) |
15822 | 170 purple_request_field_list_add_selected(field, data); |
15817 | 171 } |
172 g_list_free(list); | |
173 } | |
174 return field; | |
175 } | |
176 | |
177 static Prefs blist[] = | |
178 { | |
16424
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16310
diff
changeset
|
179 {PURPLE_PREF_BOOLEAN, "/finch/blist/idletime", N_("Show Idle Time"), NULL}, |
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16310
diff
changeset
|
180 {PURPLE_PREF_BOOLEAN, "/finch/blist/showoffline", N_("Show Offline Buddies"), NULL}, |
15822 | 181 {PURPLE_PREF_NONE, NULL, NULL, NULL} |
15817 | 182 }; |
183 | |
184 static Prefs convs[] = | |
185 { | |
16424
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16310
diff
changeset
|
186 {PURPLE_PREF_BOOLEAN, "/finch/conversations/timestamps", N_("Show Timestamps"), NULL}, |
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16310
diff
changeset
|
187 {PURPLE_PREF_BOOLEAN, "/finch/conversations/notify_typing", N_("Notify buddies when you are typing"), NULL}, |
15822 | 188 {PURPLE_PREF_NONE, NULL, NULL, NULL} |
15817 | 189 }; |
190 | |
191 static Prefs logging[] = | |
192 { | |
16424
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16310
diff
changeset
|
193 {PURPLE_PREF_STRING, "/purple/logging/format", N_("Log format"), get_log_options}, |
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16310
diff
changeset
|
194 {PURPLE_PREF_BOOLEAN, "/purple/logging/log_ims", N_("Log IMs"), NULL}, |
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16310
diff
changeset
|
195 {PURPLE_PREF_BOOLEAN, "/purple/logging/log_chats", N_("Log chats"), NULL}, |
4999bbc52881
Works for me! Renames prefs: /core to /purple, /gaim/gtk to /pidgin, /gaim/gnt to /finch
Sean Egan <seanegan@gmail.com>
parents:
16310
diff
changeset
|
196 {PURPLE_PREF_BOOLEAN, "/purple/logging/log_system", N_("Log status change events"), NULL}, |
15822 | 197 {PURPLE_PREF_NONE, NULL, NULL, NULL}, |
15817 | 198 }; |
199 | |
200 static Prefs idle[] = | |
201 { | |
18334
65fedb03ac05
Mark some string for translation, and show only one preference window at a
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18210
diff
changeset
|
202 {PURPLE_PREF_STRING, "/purple/away/idle_reporting", N_("Report Idle time"), get_idle_options}, |
65fedb03ac05
Mark some string for translation, and show only one preference window at a
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18210
diff
changeset
|
203 {PURPLE_PREF_BOOLEAN, "/purple/away/away_when_idle", N_("Change status when idle"), NULL}, |
65fedb03ac05
Mark some string for translation, and show only one preference window at a
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18210
diff
changeset
|
204 {PURPLE_PREF_INT, "/purple/away/mins_before_away", N_("Minutes before changing status"), NULL}, |
65fedb03ac05
Mark some string for translation, and show only one preference window at a
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18210
diff
changeset
|
205 {PURPLE_PREF_INT, "/purple/savedstatus/idleaway", N_("Change status to"), get_status_titles}, |
15822 | 206 {PURPLE_PREF_NONE, NULL, NULL, NULL}, |
15817 | 207 }; |
208 | |
209 static void | |
210 free_strings() | |
211 { | |
18334
65fedb03ac05
Mark some string for translation, and show only one preference window at a
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18210
diff
changeset
|
212 g_list_foreach(pref_request.freestrings, (GFunc)g_free, NULL); |
65fedb03ac05
Mark some string for translation, and show only one preference window at a
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18210
diff
changeset
|
213 g_list_free(pref_request.freestrings); |
65fedb03ac05
Mark some string for translation, and show only one preference window at a
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18210
diff
changeset
|
214 pref_request.freestrings = NULL; |
65fedb03ac05
Mark some string for translation, and show only one preference window at a
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18210
diff
changeset
|
215 pref_request.showing = FALSE; |
15817 | 216 } |
217 | |
218 static void | |
15822 | 219 save_cb(void *data, PurpleRequestFields *allfields) |
15817 | 220 { |
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
|
221 finch_request_save_in_prefs(data, allfields); |
15817 | 222 free_strings(); |
223 } | |
224 | |
225 static void | |
15822 | 226 add_pref_group(PurpleRequestFields *fields, const char *title, Prefs *prefs) |
15817 | 227 { |
15822 | 228 PurpleRequestField *field; |
229 PurpleRequestFieldGroup *group; | |
15817 | 230 int i; |
231 | |
15822 | 232 group = purple_request_field_group_new(title); |
233 purple_request_fields_add_group(fields, group); | |
15817 | 234 for (i = 0; prefs[i].pref; i++) |
235 { | |
236 field = get_pref_field(prefs + i); | |
237 if (field) | |
15822 | 238 purple_request_field_group_add_field(group, field); |
15817 | 239 } |
240 } | |
241 | |
242 void finch_prefs_show_all() | |
243 { | |
15822 | 244 PurpleRequestFields *fields; |
15817 | 245 |
18345
2d4df5ef0090
If the action-windows are already there, then bring them to front when
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18334
diff
changeset
|
246 if (pref_request.showing) { |
2d4df5ef0090
If the action-windows are already there, then bring them to front when
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18334
diff
changeset
|
247 gnt_window_present(pref_request.window); |
18334
65fedb03ac05
Mark some string for translation, and show only one preference window at a
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18210
diff
changeset
|
248 return; |
18345
2d4df5ef0090
If the action-windows are already there, then bring them to front when
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18334
diff
changeset
|
249 } |
18334
65fedb03ac05
Mark some string for translation, and show only one preference window at a
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18210
diff
changeset
|
250 |
15822 | 251 fields = purple_request_fields_new(); |
15817 | 252 |
253 add_pref_group(fields, _("Buddy List"), blist); | |
254 add_pref_group(fields, _("Conversations"), convs); | |
255 add_pref_group(fields, _("Logging"), logging); | |
256 add_pref_group(fields, _("Idle"), idle); | |
257 | |
18334
65fedb03ac05
Mark some string for translation, and show only one preference window at a
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18210
diff
changeset
|
258 pref_request.showing = TRUE; |
18345
2d4df5ef0090
If the action-windows are already there, then bring them to front when
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18334
diff
changeset
|
259 pref_request.window = purple_request_fields(NULL, _("Preferences"), NULL, NULL, fields, |
16439
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16424
diff
changeset
|
260 _("Save"), G_CALLBACK(save_cb), _("Cancel"), free_strings, |
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16424
diff
changeset
|
261 NULL, NULL, NULL, |
08db93bbd798
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evan.s@dreskin.net>
parents:
16424
diff
changeset
|
262 NULL); |
15817 | 263 } |
264 |