2 * @file gntprefs.c GNT Preferences API
8 * Finch is the legal property of its developers, whose names are too numerous
9 * to list here. Please refer to the COPYRIGHT file distributed with this
10 * source distribution.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
30 #include <savedstatuses.h>
33 #include "gntrequest.h"
36 #include "gntwidget.h"
41 GList
*freestrings
; /* strings to be freed when the pref-window is closed */
46 void finch_prefs_init()
48 purple_prefs_add_none("/finch");
50 purple_prefs_add_none("/finch/plugins");
51 purple_prefs_add_path_list("/finch/plugins/loaded", NULL
);
52 purple_prefs_add_path_list("/finch/plugins/seen", NULL
);
54 purple_prefs_add_none("/finch/conversations");
55 purple_prefs_add_bool("/finch/conversations/timestamps", TRUE
);
56 purple_prefs_add_bool("/finch/conversations/notify_typing", FALSE
);
58 purple_prefs_add_none("/finch/filelocations");
59 purple_prefs_add_path("/finch/filelocations/last_save_folder", "");
60 purple_prefs_add_path("/finch/filelocations/last_save_folder", "");
63 void finch_prefs_update_old()
65 const char *str
= NULL
;
67 purple_prefs_rename("/gaim/gnt", "/finch");
68 purple_prefs_rename("/purple/gnt", "/finch");
70 if ((str
= purple_prefs_get_string("/purple/away/idle_reporting")) &&
71 strcmp(str
, "gaim") == 0)
72 purple_prefs_set_string("/purple/away/idle_reporting", "purple");
80 GList
*(*lv
)(void); /* If the value is to be selected from a number of choices */
86 return purple_log_logger_get_options();
90 get_idle_options(void)
93 list
= g_list_append(list
, (char *)_("Based on keyboard use"));
94 list
= g_list_append(list
, "system");
95 list
= g_list_append(list
, (char*)_("From last sent message"));
96 list
= g_list_append(list
, "purple");
97 list
= g_list_append(list
, (char*)_("Never"));
98 list
= g_list_append(list
, "never");
103 get_status_titles(void)
107 for (iter
= purple_savedstatuses_get_all(); iter
; iter
= iter
->next
) {
109 if (purple_savedstatus_is_transient(iter
->data
))
111 str
= g_strdup_printf("%ld", purple_savedstatus_get_creation_time(iter
->data
));
112 list
= g_list_append(list
, (char*)purple_savedstatus_get_title(iter
->data
));
113 list
= g_list_append(list
, str
);
114 pref_request
.freestrings
= g_list_prepend(pref_request
.freestrings
, str
);
119 static PurpleRequestField
*
120 get_pref_field(Prefs
*prefs
)
122 PurpleRequestField
*field
= NULL
;
124 if (prefs
->lv
== NULL
)
128 case PURPLE_PREF_BOOLEAN
:
129 field
= purple_request_field_bool_new(prefs
->pref
, _(prefs
->label
),
130 purple_prefs_get_bool(prefs
->pref
));
132 case PURPLE_PREF_INT
:
133 field
= purple_request_field_int_new(prefs
->pref
, _(prefs
->label
),
134 purple_prefs_get_int(prefs
->pref
));
136 case PURPLE_PREF_STRING
:
137 field
= purple_request_field_string_new(prefs
->pref
, _(prefs
->label
),
138 purple_prefs_get_string(prefs
->pref
), FALSE
);
146 GList
*list
= prefs
->lv(), *iter
;
148 field
= purple_request_field_list_new(prefs
->pref
, _(prefs
->label
));
149 for (iter
= list
; iter
; iter
= iter
->next
)
151 gboolean select
= FALSE
;
152 const char *data
= iter
->data
;
157 case PURPLE_PREF_BOOLEAN
:
158 sscanf(iter
->data
, "%d", &idata
);
159 if (purple_prefs_get_bool(prefs
->pref
) == idata
)
162 case PURPLE_PREF_INT
:
163 sscanf(iter
->data
, "%d", &idata
);
164 if (purple_prefs_get_int(prefs
->pref
) == idata
)
167 case PURPLE_PREF_STRING
:
168 if (strcmp(purple_prefs_get_string(prefs
->pref
), iter
->data
) == 0)
174 purple_request_field_list_add_icon(field
, data
, NULL
, iter
->data
);
176 purple_request_field_list_add_selected(field
, data
);
183 static Prefs blist
[] =
185 {PURPLE_PREF_BOOLEAN
, "/finch/blist/idletime", N_("Show Idle Time"), NULL
},
186 {PURPLE_PREF_BOOLEAN
, "/finch/blist/showoffline", N_("Show Offline Buddies"), NULL
},
187 {PURPLE_PREF_NONE
, NULL
, NULL
, NULL
}
190 static Prefs convs
[] =
192 {PURPLE_PREF_BOOLEAN
, "/finch/conversations/timestamps", N_("Show Timestamps"), NULL
},
193 {PURPLE_PREF_BOOLEAN
, "/finch/conversations/notify_typing", N_("Notify buddies when you are typing"), NULL
},
194 {PURPLE_PREF_NONE
, NULL
, NULL
, NULL
}
197 static Prefs logging
[] =
199 {PURPLE_PREF_STRING
, "/purple/logging/format", N_("Log format"), get_log_options
},
200 {PURPLE_PREF_BOOLEAN
, "/purple/logging/log_ims", N_("Log IMs"), NULL
},
201 {PURPLE_PREF_BOOLEAN
, "/purple/logging/log_chats", N_("Log chats"), NULL
},
202 {PURPLE_PREF_BOOLEAN
, "/purple/logging/log_system", N_("Log status change events"), NULL
},
203 {PURPLE_PREF_NONE
, NULL
, NULL
, NULL
},
206 static Prefs idle
[] =
208 {PURPLE_PREF_STRING
, "/purple/away/idle_reporting", N_("Report Idle time"), get_idle_options
},
209 {PURPLE_PREF_BOOLEAN
, "/purple/away/away_when_idle", N_("Change status when idle"), NULL
},
210 {PURPLE_PREF_INT
, "/purple/away/mins_before_away", N_("Minutes before changing status"), NULL
},
211 {PURPLE_PREF_INT
, "/purple/savedstatus/idleaway", N_("Change status to"), get_status_titles
},
212 {PURPLE_PREF_NONE
, NULL
, NULL
, NULL
},
218 g_list_foreach(pref_request
.freestrings
, (GFunc
)g_free
, NULL
);
219 g_list_free(pref_request
.freestrings
);
220 pref_request
.freestrings
= NULL
;
221 pref_request
.showing
= FALSE
;
225 save_cb(void *data
, PurpleRequestFields
*allfields
)
227 finch_request_save_in_prefs(data
, allfields
);
232 add_pref_group(PurpleRequestFields
*fields
, const char *title
, Prefs
*prefs
)
234 PurpleRequestField
*field
;
235 PurpleRequestFieldGroup
*group
;
238 group
= purple_request_field_group_new(title
);
239 purple_request_fields_add_group(fields
, group
);
240 for (i
= 0; prefs
[i
].pref
; i
++)
242 field
= get_pref_field(prefs
+ i
);
244 purple_request_field_group_add_field(group
, field
);
248 void finch_prefs_show_all()
250 PurpleRequestFields
*fields
;
252 if (pref_request
.showing
) {
253 gnt_window_present(pref_request
.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
, _("Logging"), logging
);
262 add_pref_group(fields
, _("Idle"), idle
);
264 pref_request
.showing
= TRUE
;
265 pref_request
.window
= purple_request_fields(NULL
, _("Preferences"), NULL
, NULL
, fields
,
266 _("Save"), G_CALLBACK(save_cb
), _("Cancel"), free_strings
,