Mercurial > pidgin
annotate finch/gntprefs.c @ 16464:b2044e10915a
merge of 'ca40214f7a10f0e15d7bd32bed84b177889ca02d'
and 'dfafb91b749752416047f800169f9c839c909733'
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Fri, 27 Apr 2007 00:28:21 +0000 |
parents | 08db93bbd798 |
children | ac0d07c7fd90 |
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 { | |
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
|
38 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
|
39 |
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
|
40 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
|
41 purple_prefs_add_path_list("/finch/plugins/loaded", NULL); |
15817 | 42 |
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
|
43 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
|
44 purple_prefs_add_bool("/finch/conversations/timestamps", TRUE); |
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
|
45 purple_prefs_add_bool("/finch/conversations/notify_typing", FALSE); /* XXX: Not functional yet */ |
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_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
|
47 purple_prefs_rename("/purple/gnt", "/finch"); |
15817 | 48 } |
49 | |
50 typedef struct | |
51 { | |
15822 | 52 PurplePrefType type; |
15817 | 53 const char *pref; |
54 const char *label; | |
55 GList *(*lv)(); /* If the value is to be selected from a number of choices */ | |
56 } Prefs; | |
57 | |
58 static GList * | |
59 get_log_options() | |
60 { | |
15822 | 61 return purple_log_logger_get_options(); |
15817 | 62 } |
63 | |
64 static GList * | |
65 get_idle_options() | |
66 { | |
67 GList *list = NULL; | |
68 list = g_list_append(list, "Based on keyboard use"); /* XXX: string freeze */ | |
69 list = g_list_append(list, "system"); | |
70 list = g_list_append(list, (char*)_("From last sent message")); | |
15822 | 71 list = g_list_append(list, "purple"); |
15817 | 72 list = g_list_append(list, (char*)_("Never")); |
73 list = g_list_append(list, "never"); | |
74 return list; | |
75 } | |
76 | |
77 static GList * | |
78 get_status_titles() | |
79 { | |
80 GList *list = NULL; | |
81 const GList *iter; | |
15822 | 82 for (iter = purple_savedstatuses_get_all(); iter; iter = iter->next) { |
15817 | 83 char *str; |
15822 | 84 if (purple_savedstatus_is_transient(iter->data)) |
15817 | 85 continue; |
15822 | 86 str = g_strdup_printf("%ld", purple_savedstatus_get_creation_time(iter->data)); |
87 list = g_list_append(list, (char*)purple_savedstatus_get_title(iter->data)); | |
15817 | 88 list = g_list_append(list, str); |
89 freestrings = g_list_prepend(freestrings, str); | |
90 } | |
91 return list; | |
92 } | |
93 | |
15822 | 94 static PurpleRequestField * |
15817 | 95 get_pref_field(Prefs *prefs) |
96 { | |
15822 | 97 PurpleRequestField *field = NULL; |
15817 | 98 |
99 if (prefs->lv == NULL) | |
100 { | |
101 switch (prefs->type) | |
102 { | |
15822 | 103 case PURPLE_PREF_BOOLEAN: |
104 field = purple_request_field_bool_new(prefs->pref, _(prefs->label), | |
105 purple_prefs_get_bool(prefs->pref)); | |
15817 | 106 break; |
15822 | 107 case PURPLE_PREF_INT: |
108 field = purple_request_field_int_new(prefs->pref, _(prefs->label), | |
109 purple_prefs_get_int(prefs->pref)); | |
15817 | 110 break; |
15822 | 111 case PURPLE_PREF_STRING: |
112 field = purple_request_field_string_new(prefs->pref, _(prefs->label), | |
113 purple_prefs_get_string(prefs->pref), FALSE); | |
15817 | 114 break; |
115 default: | |
116 break; | |
117 } | |
118 } | |
119 else | |
120 { | |
121 GList *list = prefs->lv(), *iter; | |
122 if (list) | |
15822 | 123 field = purple_request_field_list_new(prefs->pref, _(prefs->label)); |
15817 | 124 for (iter = list; iter; iter = iter->next) |
125 { | |
126 gboolean select = FALSE; | |
127 const char *data = iter->data; | |
128 int idata; | |
129 iter = iter->next; | |
130 switch (prefs->type) | |
131 { | |
15822 | 132 case PURPLE_PREF_BOOLEAN: |
15817 | 133 sscanf(iter->data, "%d", &idata); |
15822 | 134 if (purple_prefs_get_bool(prefs->pref) == idata) |
15817 | 135 select = TRUE; |
136 break; | |
15822 | 137 case PURPLE_PREF_INT: |
15817 | 138 sscanf(iter->data, "%d", &idata); |
15822 | 139 if (purple_prefs_get_int(prefs->pref) == idata) |
15817 | 140 select = TRUE; |
141 break; | |
15822 | 142 case PURPLE_PREF_STRING: |
143 if (strcmp(purple_prefs_get_string(prefs->pref), iter->data) == 0) | |
15817 | 144 select = TRUE; |
145 break; | |
146 default: | |
147 break; | |
148 } | |
15822 | 149 purple_request_field_list_add(field, data, iter->data); |
15817 | 150 if (select) |
15822 | 151 purple_request_field_list_add_selected(field, data); |
15817 | 152 } |
153 g_list_free(list); | |
154 } | |
155 return field; | |
156 } | |
157 | |
158 static Prefs blist[] = | |
159 { | |
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
|
160 {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
|
161 {PURPLE_PREF_BOOLEAN, "/finch/blist/showoffline", N_("Show Offline Buddies"), NULL}, |
15822 | 162 {PURPLE_PREF_NONE, NULL, NULL, NULL} |
15817 | 163 }; |
164 | |
165 static Prefs convs[] = | |
166 { | |
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
|
167 {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
|
168 {PURPLE_PREF_BOOLEAN, "/finch/conversations/notify_typing", N_("Notify buddies when you are typing"), NULL}, |
15822 | 169 {PURPLE_PREF_NONE, NULL, NULL, NULL} |
15817 | 170 }; |
171 | |
172 static Prefs logging[] = | |
173 { | |
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
|
174 {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
|
175 {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
|
176 {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
|
177 {PURPLE_PREF_BOOLEAN, "/purple/logging/log_system", N_("Log status change events"), NULL}, |
15822 | 178 {PURPLE_PREF_NONE, NULL, NULL, NULL}, |
15817 | 179 }; |
180 | |
181 /* XXX: Translate after the freeze */ | |
182 static Prefs idle[] = | |
183 { | |
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
|
184 {PURPLE_PREF_STRING, "/purple/away/idle_reporting", "Report Idle time", get_idle_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
|
185 {PURPLE_PREF_BOOLEAN, "/purple/away/away_when_idle", "Change status when idle", 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
|
186 {PURPLE_PREF_INT, "/purple/away/mins_before_away", "Minutes before changing status", 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_INT, "/purple/savedstatus/idleaway", "Change status to", get_status_titles}, |
15822 | 188 {PURPLE_PREF_NONE, NULL, NULL, NULL}, |
15817 | 189 }; |
190 | |
191 static void | |
192 free_strings() | |
193 { | |
194 g_list_foreach(freestrings, (GFunc)g_free, NULL); | |
195 g_list_free(freestrings); | |
196 freestrings = NULL; | |
197 } | |
198 | |
199 static void | |
15822 | 200 save_cb(void *data, PurpleRequestFields *allfields) |
15817 | 201 { |
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
|
202 finch_request_save_in_prefs(data, allfields); |
15817 | 203 free_strings(); |
204 } | |
205 | |
206 static void | |
15822 | 207 add_pref_group(PurpleRequestFields *fields, const char *title, Prefs *prefs) |
15817 | 208 { |
15822 | 209 PurpleRequestField *field; |
210 PurpleRequestFieldGroup *group; | |
15817 | 211 int i; |
212 | |
15822 | 213 group = purple_request_field_group_new(title); |
214 purple_request_fields_add_group(fields, group); | |
15817 | 215 for (i = 0; prefs[i].pref; i++) |
216 { | |
217 field = get_pref_field(prefs + i); | |
218 if (field) | |
15822 | 219 purple_request_field_group_add_field(group, field); |
15817 | 220 } |
221 } | |
222 | |
223 void finch_prefs_show_all() | |
224 { | |
15822 | 225 PurpleRequestFields *fields; |
15817 | 226 |
15822 | 227 fields = purple_request_fields_new(); |
15817 | 228 |
229 add_pref_group(fields, _("Buddy List"), blist); | |
230 add_pref_group(fields, _("Conversations"), convs); | |
231 add_pref_group(fields, _("Logging"), logging); | |
232 add_pref_group(fields, _("Idle"), idle); | |
233 | |
15822 | 234 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
|
235 _("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
|
236 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
|
237 NULL); |
15817 | 238 } |
239 |