3 * Finch is the legal property of its developers, whose names are too numerous
4 * to list here. Please refer to the COPYRIGHT file distributed with this
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
25 #include <savedstatuses.h>
28 #include "gntrequest.h"
31 #include "gntwidget.h"
36 GList
*freestrings
; /* strings to be freed when the pref-window is closed */
39 GntWidget
*keyring_window
;
42 void finch_prefs_init()
44 purple_prefs_add_none("/finch");
46 purple_prefs_add_none("/finch/plugins");
47 purple_prefs_add_path_list("/finch/plugins/loaded", NULL
);
48 purple_prefs_add_path_list("/finch/plugins/seen", NULL
);
50 purple_prefs_add_none("/finch/conversations");
51 purple_prefs_add_bool("/finch/conversations/timestamps", TRUE
);
52 purple_prefs_add_bool("/finch/conversations/notify_typing", FALSE
);
54 purple_prefs_add_none("/finch/filelocations");
55 purple_prefs_add_path("/finch/filelocations/last_save_folder", "");
56 purple_prefs_add_path("/finch/filelocations/last_save_folder", "");
59 void finch_prefs_update_old()
68 GList
*(*lv
)(void); /* If the value is to be selected from a number of choices */
74 return purple_log_logger_get_options();
78 get_idle_options(void)
81 list
= g_list_append(list
, (char *)_("Based on keyboard use"));
82 list
= g_list_append(list
, "system");
83 list
= g_list_append(list
, (char*)_("From last sent message"));
84 list
= g_list_append(list
, "purple");
85 list
= g_list_append(list
, (char*)_("Never"));
86 list
= g_list_append(list
, "never");
91 get_status_titles(void)
95 for (iter
= purple_savedstatuses_get_all(); iter
; iter
= iter
->next
) {
97 if (purple_savedstatus_is_transient(iter
->data
))
99 str
= g_strdup_printf("%ld", purple_savedstatus_get_creation_time(iter
->data
));
100 list
= g_list_append(list
, (char*)purple_savedstatus_get_title(iter
->data
));
101 list
= g_list_append(list
, str
);
102 pref_request
.freestrings
= g_list_prepend(pref_request
.freestrings
, str
);
107 static PurpleRequestField
*
108 get_pref_field(Prefs
*prefs
)
110 PurpleRequestField
*field
= NULL
;
112 if (prefs
->lv
== NULL
)
116 case PURPLE_PREF_BOOLEAN
:
117 field
= purple_request_field_bool_new(prefs
->pref
, _(prefs
->label
),
118 purple_prefs_get_bool(prefs
->pref
));
120 case PURPLE_PREF_INT
:
121 field
= purple_request_field_int_new(prefs
->pref
, _(prefs
->label
),
122 purple_prefs_get_int(prefs
->pref
), INT_MIN
, INT_MAX
);
124 case PURPLE_PREF_STRING
:
125 field
= purple_request_field_string_new(prefs
->pref
, _(prefs
->label
),
126 purple_prefs_get_string(prefs
->pref
), FALSE
);
134 GList
*list
= prefs
->lv(), *iter
;
136 field
= purple_request_field_list_new(prefs
->pref
, _(prefs
->label
));
137 for (iter
= list
; iter
; iter
= iter
->next
)
139 gboolean select
= FALSE
;
140 const char *data
= iter
->data
;
145 case PURPLE_PREF_BOOLEAN
:
146 if (sscanf(iter
->data
, "%d", &idata
) != 1)
148 if (purple_prefs_get_bool(prefs
->pref
) == idata
)
151 case PURPLE_PREF_INT
:
152 if (sscanf(iter
->data
, "%d", &idata
) != 1)
154 if (purple_prefs_get_int(prefs
->pref
) == idata
)
157 case PURPLE_PREF_STRING
:
158 if (purple_strequal(purple_prefs_get_string(prefs
->pref
), iter
->data
))
164 purple_request_field_list_add_icon(field
, data
, NULL
, iter
->data
);
166 purple_request_field_list_add_selected(field
, data
);
173 static Prefs blist
[] =
175 {PURPLE_PREF_BOOLEAN
, "/finch/blist/idletime", N_("Show Idle Time"), NULL
},
176 {PURPLE_PREF_BOOLEAN
, "/finch/blist/showoffline", N_("Show Offline Buddies"), NULL
},
177 {PURPLE_PREF_NONE
, NULL
, NULL
, NULL
}
180 static Prefs convs
[] =
182 {PURPLE_PREF_BOOLEAN
, "/finch/conversations/timestamps", N_("Show Timestamps"), NULL
},
183 {PURPLE_PREF_BOOLEAN
, "/finch/conversations/notify_typing", N_("Notify buddies when you are typing"), NULL
},
184 {PURPLE_PREF_NONE
, NULL
, NULL
, NULL
}
187 static Prefs logging
[] =
189 {PURPLE_PREF_STRING
, "/purple/logging/format", N_("Log format"), get_log_options
},
190 {PURPLE_PREF_BOOLEAN
, "/purple/logging/log_ims", N_("Log IMs"), NULL
},
191 {PURPLE_PREF_BOOLEAN
, "/purple/logging/log_chats", N_("Log chats"), NULL
},
192 {PURPLE_PREF_BOOLEAN
, "/purple/logging/log_system", N_("Log status change events"), NULL
},
193 {PURPLE_PREF_NONE
, NULL
, NULL
, NULL
},
196 static Prefs keyring
[] =
198 {PURPLE_PREF_STRING
, "/purple/keyring/active", N_("Active keyring"), purple_keyring_get_options
},
199 {PURPLE_PREF_NONE
, NULL
, NULL
, NULL
}
202 static Prefs idle
[] =
204 {PURPLE_PREF_STRING
, "/purple/away/idle_reporting", N_("Report Idle time"), get_idle_options
},
205 {PURPLE_PREF_BOOLEAN
, "/purple/away/away_when_idle", N_("Change status when idle"), NULL
},
206 {PURPLE_PREF_INT
, "/purple/away/mins_before_away", N_("Minutes before changing status"), NULL
},
207 {PURPLE_PREF_INT
, "/purple/savedstatus/idleaway", N_("Change status to"), get_status_titles
},
208 {PURPLE_PREF_NONE
, NULL
, NULL
, NULL
},
214 g_list_foreach(pref_request
.freestrings
, (GFunc
)g_free
, NULL
);
215 g_list_free(pref_request
.freestrings
);
216 pref_request
.freestrings
= NULL
;
217 pref_request
.showing
= FALSE
;
221 save_cb(void *data
, PurpleRequestFields
*allfields
)
223 finch_request_save_in_prefs(data
, allfields
);
228 add_pref_group(PurpleRequestFields
*fields
, const char *title
, Prefs
*prefs
)
230 PurpleRequestField
*field
;
231 PurpleRequestFieldGroup
*group
;
234 group
= purple_request_field_group_new(title
);
235 purple_request_fields_add_group(fields
, group
);
236 for (i
= 0; prefs
[i
].pref
; i
++)
238 field
= get_pref_field(prefs
+ i
);
240 purple_request_field_group_add_field(group
, field
);
244 void finch_prefs_show_all()
246 PurpleRequestFields
*fields
;
248 if (pref_request
.showing
) {
249 gnt_window_present(pref_request
.window
);
253 if (pref_request
.keyring_window
!= NULL
)
254 purple_request_close(PURPLE_REQUEST_FIELDS
,
255 pref_request
.keyring_window
);
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
, _("Keyring"), keyring
);
262 add_pref_group(fields
, _("Logging"), logging
);
263 add_pref_group(fields
, _("Idle"), idle
);
265 pref_request
.showing
= TRUE
;
266 pref_request
.window
= purple_request_fields(NULL
, _("Preferences"), NULL
, NULL
, fields
,
267 _("Save"), G_CALLBACK(save_cb
), _("Cancel"), free_strings
,
272 finch_prefs_keyring_save(void *data
, PurpleRequestFields
*fields
)
274 pref_request
.keyring_window
= NULL
;
276 purple_keyring_apply_settings(NULL
, fields
);
280 finch_prefs_keyring_cancel(void)
282 pref_request
.keyring_window
= NULL
;
285 void finch_prefs_show_keyring(void)
287 PurpleRequestFields
*fields
;
289 if (pref_request
.keyring_window
!= NULL
) {
290 gnt_window_present(pref_request
.keyring_window
);
294 fields
= purple_keyring_read_settings();
295 if (fields
== NULL
) {
296 purple_notify_info(NULL
, _("Keyring settings"),
297 _("Selected keyring doesn't allow any configuration"),
302 pref_request
.keyring_window
= purple_request_fields(NULL
,
303 _("Keyring settings"), NULL
, NULL
, fields
,
304 _("Save"), G_CALLBACK(finch_prefs_keyring_save
),
305 _("Cancel"), G_CALLBACK(finch_prefs_keyring_cancel
),