comparison console/gntprefs.c @ 15757:0e9bcdeaf2fa

Preference for idleness. Someone was looking for this thing.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Fri, 02 Mar 2007 03:35:44 +0000
parents ac460d00e235
children
comparison
equal deleted inserted replaced
15756:0d91252f02fb 15757:0e9bcdeaf2fa
21 * You should have received a copy of the GNU General Public License 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 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 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */ 24 */
25 #include <prefs.h> 25 #include <prefs.h>
26 #include <savedstatuses.h>
26 27
27 #include "gntgaim.h" 28 #include "gntgaim.h"
28 #include "gntprefs.h" 29 #include "gntprefs.h"
29 #include "gntrequest.h" 30 #include "gntrequest.h"
30 31
31 #include <string.h> 32 #include <string.h>
33
34 static GList *freestrings; /* strings to be freed when the pref-window is closed */
32 35
33 void gg_prefs_init() 36 void gg_prefs_init()
34 { 37 {
35 gaim_prefs_add_none("/gaim"); 38 gaim_prefs_add_none("/gaim");
36 gaim_prefs_add_none("/gaim/gnt"); 39 gaim_prefs_add_none("/gaim/gnt");
55 get_log_options() 58 get_log_options()
56 { 59 {
57 return gaim_log_logger_get_options(); 60 return gaim_log_logger_get_options();
58 } 61 }
59 62
63 static GList *
64 get_idle_options()
65 {
66 GList *list = NULL;
67 list = g_list_append(list, "Based on keyboard use"); /* XXX: string freeze */
68 list = g_list_append(list, "system");
69 list = g_list_append(list, (char*)_("From last sent message"));
70 list = g_list_append(list, "gaim");
71 list = g_list_append(list, (char*)_("Never"));
72 list = g_list_append(list, "never");
73 return list;
74 }
75
76 static GList *
77 get_status_titles()
78 {
79 GList *list = NULL;
80 const GList *iter;
81 for (iter = gaim_savedstatuses_get_all(); iter; iter = iter->next) {
82 char *str;
83 if (gaim_savedstatus_is_transient(iter->data))
84 continue;
85 str = g_strdup_printf("%ld", gaim_savedstatus_get_creation_time(iter->data));
86 list = g_list_append(list, (char*)gaim_savedstatus_get_title(iter->data));
87 list = g_list_append(list, str);
88 freestrings = g_list_prepend(freestrings, str);
89 }
90 return list;
91 }
92
60 static GaimRequestField * 93 static GaimRequestField *
61 get_pref_field(Prefs *prefs) 94 get_pref_field(Prefs *prefs)
62 { 95 {
63 GaimRequestField *field = NULL; 96 GaimRequestField *field = NULL;
64 97
83 } 116 }
84 } 117 }
85 else 118 else
86 { 119 {
87 GList *list = prefs->lv(), *iter; 120 GList *list = prefs->lv(), *iter;
88 field = gaim_request_field_list_new(prefs->pref, _(prefs->label)); 121 if (list)
122 field = gaim_request_field_list_new(prefs->pref, _(prefs->label));
89 for (iter = list; iter; iter = iter->next) 123 for (iter = list; iter; iter = iter->next)
90 { 124 {
91 gboolean select = FALSE; 125 gboolean select = FALSE;
92 const char *data = iter->data; 126 const char *data = iter->data;
127 int idata;
93 iter = iter->next; 128 iter = iter->next;
94 switch (prefs->type) 129 switch (prefs->type)
95 { 130 {
96 case GAIM_PREF_BOOLEAN: 131 case GAIM_PREF_BOOLEAN:
97 if (gaim_prefs_get_bool(prefs->pref) == GPOINTER_TO_INT(iter->data)) 132 sscanf(iter->data, "%d", &idata);
133 if (gaim_prefs_get_bool(prefs->pref) == idata)
98 select = TRUE; 134 select = TRUE;
99 break; 135 break;
100 case GAIM_PREF_INT: 136 case GAIM_PREF_INT:
101 if (gaim_prefs_get_int(prefs->pref) == GPOINTER_TO_INT(iter->data)) 137 sscanf(iter->data, "%d", &idata);
138 if (gaim_prefs_get_int(prefs->pref) == idata)
102 select = TRUE; 139 select = TRUE;
103 break; 140 break;
104 case GAIM_PREF_STRING: 141 case GAIM_PREF_STRING:
105 if (strcmp(gaim_prefs_get_string(prefs->pref), iter->data) == 0) 142 if (strcmp(gaim_prefs_get_string(prefs->pref), iter->data) == 0)
106 select = TRUE; 143 select = TRUE;
137 {GAIM_PREF_BOOLEAN, "/core/logging/log_ims", N_("Log IMs"), NULL}, 174 {GAIM_PREF_BOOLEAN, "/core/logging/log_ims", N_("Log IMs"), NULL},
138 {GAIM_PREF_BOOLEAN, "/core/logging/log_chats", N_("Log chats"), NULL}, 175 {GAIM_PREF_BOOLEAN, "/core/logging/log_chats", N_("Log chats"), NULL},
139 {GAIM_PREF_BOOLEAN, "/core/logging/log_system", N_("Log status change events"), NULL}, 176 {GAIM_PREF_BOOLEAN, "/core/logging/log_system", N_("Log status change events"), NULL},
140 {GAIM_PREF_NONE, NULL, NULL, NULL}, 177 {GAIM_PREF_NONE, NULL, NULL, NULL},
141 }; 178 };
179
180 /* XXX: Translate after the freeze */
181 static Prefs idle[] =
182 {
183 {GAIM_PREF_STRING, "/core/away/idle_reporting", "Report Idle time", get_idle_options},
184 {GAIM_PREF_BOOLEAN, "/core/away/away_when_idle", "Change status when idle", NULL},
185 {GAIM_PREF_INT, "/core/away/mins_before_away", "Minutes before changing status", NULL},
186 {GAIM_PREF_INT, "/core/savedstatus/idleaway", "Change status to", get_status_titles},
187 {GAIM_PREF_NONE, NULL, NULL, NULL},
188 };
189
190 static void
191 free_strings()
192 {
193 g_list_foreach(freestrings, (GFunc)g_free, NULL);
194 g_list_free(freestrings);
195 freestrings = NULL;
196 }
142 197
143 static void 198 static void
144 save_cb(void *data, GaimRequestFields *allfields) 199 save_cb(void *data, GaimRequestFields *allfields)
145 { 200 {
146 GList *list; 201 GList *list;
177 232
178 pt = gaim_prefs_get_type(id); 233 pt = gaim_prefs_get_type(id);
179 switch (pt) 234 switch (pt)
180 { 235 {
181 case GAIM_PREF_INT: 236 case GAIM_PREF_INT:
237 if (type == GAIM_REQUEST_FIELD_LIST) /* Lists always return string */
238 sscanf(val, "%ld", (long int *)&val);
182 gaim_prefs_set_int(id, GPOINTER_TO_INT(val)); 239 gaim_prefs_set_int(id, GPOINTER_TO_INT(val));
183 break; 240 break;
184 case GAIM_PREF_BOOLEAN: 241 case GAIM_PREF_BOOLEAN:
185 gaim_prefs_set_bool(id, GPOINTER_TO_INT(val)); 242 gaim_prefs_set_bool(id, GPOINTER_TO_INT(val));
186 break; 243 break;
190 default: 247 default:
191 break; 248 break;
192 } 249 }
193 } 250 }
194 } 251 }
252 free_strings();
195 } 253 }
196 254
197 static void 255 static void
198 add_pref_group(GaimRequestFields *fields, const char *title, Prefs *prefs) 256 add_pref_group(GaimRequestFields *fields, const char *title, Prefs *prefs)
199 { 257 {
204 group = gaim_request_field_group_new(title); 262 group = gaim_request_field_group_new(title);
205 gaim_request_fields_add_group(fields, group); 263 gaim_request_fields_add_group(fields, group);
206 for (i = 0; prefs[i].pref; i++) 264 for (i = 0; prefs[i].pref; i++)
207 { 265 {
208 field = get_pref_field(prefs + i); 266 field = get_pref_field(prefs + i);
209 gaim_request_field_group_add_field(group, field); 267 if (field)
268 gaim_request_field_group_add_field(group, field);
210 } 269 }
211 } 270 }
212 271
213 void gg_prefs_show_all() 272 void gg_prefs_show_all()
214 { 273 {
217 fields = gaim_request_fields_new(); 276 fields = gaim_request_fields_new();
218 277
219 add_pref_group(fields, _("Buddy List"), blist); 278 add_pref_group(fields, _("Buddy List"), blist);
220 add_pref_group(fields, _("Conversations"), convs); 279 add_pref_group(fields, _("Conversations"), convs);
221 add_pref_group(fields, _("Logging"), logging); 280 add_pref_group(fields, _("Logging"), logging);
281 add_pref_group(fields, _("Idle"), idle);
222 282
223 gaim_request_fields(NULL, _("Preferences"), NULL, NULL, fields, 283 gaim_request_fields(NULL, _("Preferences"), NULL, NULL, fields,
224 _("Save"), G_CALLBACK(save_cb), _("Cancel"), NULL, NULL); 284 _("Save"), G_CALLBACK(save_cb), _("Cancel"), free_strings, NULL);
225 } 285 }
226 286