Mercurial > pidgin.yaz
annotate finch/gntprefs.c @ 19679:7e2327d291fb
merge of '7360490707a66389e7834a0251d950ce13a46165'
and '98350d405d58b18ceb5e45eeed882bbf41892259'
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Fri, 07 Sep 2007 06:53:01 +0000 |
parents | 719f73b9a593 |
children | 44b4e8bd759b b8870878531e |
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 */ | |
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 |
15818 | 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 |
15818 | 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; |
15818 | 43 |
44 void finch_prefs_init() | |
45 { | |
16427
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); |
16952
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:
16573
diff
changeset
|
50 purple_prefs_add_path_list("/finch/plugins/seen", NULL); |
15818 | 51 |
16427
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); |
16573
ac0d07c7fd90
Pref migration for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16442
diff
changeset
|
54 purple_prefs_add_bool("/finch/conversations/notify_typing", FALSE); |
18410
719f73b9a593
Remember the open/save file locations.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18345
diff
changeset
|
55 |
719f73b9a593
Remember the open/save file locations.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18345
diff
changeset
|
56 purple_prefs_add_none("/finch/filelocations"); |
719f73b9a593
Remember the open/save file locations.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18345
diff
changeset
|
57 purple_prefs_add_path("/finch/filelocations/last_save_folder", ""); |
719f73b9a593
Remember the open/save file locations.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18345
diff
changeset
|
58 purple_prefs_add_path("/finch/filelocations/last_save_folder", ""); |
16573
ac0d07c7fd90
Pref migration for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16442
diff
changeset
|
59 } |
ac0d07c7fd90
Pref migration for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16442
diff
changeset
|
60 |
ac0d07c7fd90
Pref migration for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16442
diff
changeset
|
61 void finch_prefs_update_old() |
ac0d07c7fd90
Pref migration for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16442
diff
changeset
|
62 { |
ac0d07c7fd90
Pref migration for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16442
diff
changeset
|
63 const char *str = NULL; |
ac0d07c7fd90
Pref migration for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16442
diff
changeset
|
64 |
16427
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
|
65 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
|
66 purple_prefs_rename("/purple/gnt", "/finch"); |
16573
ac0d07c7fd90
Pref migration for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16442
diff
changeset
|
67 |
ac0d07c7fd90
Pref migration for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16442
diff
changeset
|
68 if ((str = purple_prefs_get_string("/purple/away/idle_reporting")) && |
ac0d07c7fd90
Pref migration for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16442
diff
changeset
|
69 strcmp(str, "gaim") == 0) |
ac0d07c7fd90
Pref migration for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16442
diff
changeset
|
70 purple_prefs_set_string("/purple/away/idle_reporting", "purple"); |
15818 | 71 } |
72 | |
73 typedef struct | |
74 { | |
15823 | 75 PurplePrefType type; |
15818 | 76 const char *pref; |
77 const char *label; | |
78 GList *(*lv)(); /* If the value is to be selected from a number of choices */ | |
79 } Prefs; | |
80 | |
81 static GList * | |
82 get_log_options() | |
83 { | |
15823 | 84 return purple_log_logger_get_options(); |
15818 | 85 } |
86 | |
87 static GList * | |
88 get_idle_options() | |
89 { | |
90 GList *list = NULL; | |
17171
c61187e0c752
Fix a compiler warning.
Richard Laager <rlaager@wiktel.com>
parents:
17160
diff
changeset
|
91 list = g_list_append(list, (char *)_("Based on keyboard use")); |
15818 | 92 list = g_list_append(list, "system"); |
93 list = g_list_append(list, (char*)_("From last sent message")); | |
15823 | 94 list = g_list_append(list, "purple"); |
15818 | 95 list = g_list_append(list, (char*)_("Never")); |
96 list = g_list_append(list, "never"); | |
97 return list; | |
98 } | |
99 | |
100 static GList * | |
101 get_status_titles() | |
102 { | |
103 GList *list = NULL; | |
18118
ab6d2763b8d8
Re-fix the DBus list handling code by killing const GList* / const GSList*
Richard Laager <rlaager@wiktel.com>
parents:
17171
diff
changeset
|
104 GList *iter; |
15823 | 105 for (iter = purple_savedstatuses_get_all(); iter; iter = iter->next) { |
15818 | 106 char *str; |
15823 | 107 if (purple_savedstatus_is_transient(iter->data)) |
15818 | 108 continue; |
15823 | 109 str = g_strdup_printf("%ld", purple_savedstatus_get_creation_time(iter->data)); |
110 list = g_list_append(list, (char*)purple_savedstatus_get_title(iter->data)); | |
15818 | 111 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
|
112 pref_request.freestrings = g_list_prepend(pref_request.freestrings, str); |
15818 | 113 } |
114 return list; | |
115 } | |
116 | |
15823 | 117 static PurpleRequestField * |
15818 | 118 get_pref_field(Prefs *prefs) |
119 { | |
15823 | 120 PurpleRequestField *field = NULL; |
15818 | 121 |
122 if (prefs->lv == NULL) | |
123 { | |
124 switch (prefs->type) | |
125 { | |
15823 | 126 case PURPLE_PREF_BOOLEAN: |
127 field = purple_request_field_bool_new(prefs->pref, _(prefs->label), | |
128 purple_prefs_get_bool(prefs->pref)); | |
15818 | 129 break; |
15823 | 130 case PURPLE_PREF_INT: |
131 field = purple_request_field_int_new(prefs->pref, _(prefs->label), | |
132 purple_prefs_get_int(prefs->pref)); | |
15818 | 133 break; |
15823 | 134 case PURPLE_PREF_STRING: |
135 field = purple_request_field_string_new(prefs->pref, _(prefs->label), | |
136 purple_prefs_get_string(prefs->pref), FALSE); | |
15818 | 137 break; |
138 default: | |
139 break; | |
140 } | |
141 } | |
142 else | |
143 { | |
144 GList *list = prefs->lv(), *iter; | |
145 if (list) | |
15823 | 146 field = purple_request_field_list_new(prefs->pref, _(prefs->label)); |
15818 | 147 for (iter = list; iter; iter = iter->next) |
148 { | |
149 gboolean select = FALSE; | |
150 const char *data = iter->data; | |
151 int idata; | |
152 iter = iter->next; | |
153 switch (prefs->type) | |
154 { | |
15823 | 155 case PURPLE_PREF_BOOLEAN: |
15818 | 156 sscanf(iter->data, "%d", &idata); |
15823 | 157 if (purple_prefs_get_bool(prefs->pref) == idata) |
15818 | 158 select = TRUE; |
159 break; | |
15823 | 160 case PURPLE_PREF_INT: |
15818 | 161 sscanf(iter->data, "%d", &idata); |
15823 | 162 if (purple_prefs_get_int(prefs->pref) == idata) |
15818 | 163 select = TRUE; |
164 break; | |
15823 | 165 case PURPLE_PREF_STRING: |
166 if (strcmp(purple_prefs_get_string(prefs->pref), iter->data) == 0) | |
15818 | 167 select = TRUE; |
168 break; | |
169 default: | |
170 break; | |
171 } | |
15823 | 172 purple_request_field_list_add(field, data, iter->data); |
15818 | 173 if (select) |
15823 | 174 purple_request_field_list_add_selected(field, data); |
15818 | 175 } |
176 g_list_free(list); | |
177 } | |
178 return field; | |
179 } | |
180 | |
181 static Prefs blist[] = | |
182 { | |
16427
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
|
183 {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
|
184 {PURPLE_PREF_BOOLEAN, "/finch/blist/showoffline", N_("Show Offline Buddies"), NULL}, |
15823 | 185 {PURPLE_PREF_NONE, NULL, NULL, NULL} |
15818 | 186 }; |
187 | |
188 static Prefs convs[] = | |
189 { | |
16427
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
|
190 {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
|
191 {PURPLE_PREF_BOOLEAN, "/finch/conversations/notify_typing", N_("Notify buddies when you are typing"), NULL}, |
15823 | 192 {PURPLE_PREF_NONE, NULL, NULL, NULL} |
15818 | 193 }; |
194 | |
195 static Prefs logging[] = | |
196 { | |
16427
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
|
197 {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
|
198 {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
|
199 {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
|
200 {PURPLE_PREF_BOOLEAN, "/purple/logging/log_system", N_("Log status change events"), NULL}, |
15823 | 201 {PURPLE_PREF_NONE, NULL, NULL, NULL}, |
15818 | 202 }; |
203 | |
204 static Prefs idle[] = | |
205 { | |
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
|
206 {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
|
207 {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
|
208 {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
|
209 {PURPLE_PREF_INT, "/purple/savedstatus/idleaway", N_("Change status to"), get_status_titles}, |
15823 | 210 {PURPLE_PREF_NONE, NULL, NULL, NULL}, |
15818 | 211 }; |
212 | |
213 static void | |
214 free_strings() | |
215 { | |
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
|
216 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
|
217 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
|
218 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
|
219 pref_request.showing = FALSE; |
15818 | 220 } |
221 | |
222 static void | |
15823 | 223 save_cb(void *data, PurpleRequestFields *allfields) |
15818 | 224 { |
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
|
225 finch_request_save_in_prefs(data, allfields); |
15818 | 226 free_strings(); |
227 } | |
228 | |
229 static void | |
15823 | 230 add_pref_group(PurpleRequestFields *fields, const char *title, Prefs *prefs) |
15818 | 231 { |
15823 | 232 PurpleRequestField *field; |
233 PurpleRequestFieldGroup *group; | |
15818 | 234 int i; |
235 | |
15823 | 236 group = purple_request_field_group_new(title); |
237 purple_request_fields_add_group(fields, group); | |
15818 | 238 for (i = 0; prefs[i].pref; i++) |
239 { | |
240 field = get_pref_field(prefs + i); | |
241 if (field) | |
15823 | 242 purple_request_field_group_add_field(group, field); |
15818 | 243 } |
244 } | |
245 | |
246 void finch_prefs_show_all() | |
247 { | |
15823 | 248 PurpleRequestFields *fields; |
15818 | 249 |
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
|
250 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
|
251 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
|
252 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
|
253 } |
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
|
254 |
15823 | 255 fields = purple_request_fields_new(); |
15818 | 256 |
257 add_pref_group(fields, _("Buddy List"), blist); | |
258 add_pref_group(fields, _("Conversations"), convs); | |
259 add_pref_group(fields, _("Logging"), logging); | |
260 add_pref_group(fields, _("Idle"), idle); | |
261 | |
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
|
262 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
|
263 pref_request.window = purple_request_fields(NULL, _("Preferences"), NULL, NULL, fields, |
16442
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:
16427
diff
changeset
|
264 _("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:
16427
diff
changeset
|
265 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:
16427
diff
changeset
|
266 NULL); |
15818 | 267 } |
268 |