pidgin/gtkprefs.c

branch
cpw.qulogic.gtk3-required
changeset 33120
f6f1a27ade72
parent 32745
c0648a124649
parent 32433
f539a2c083b2
child 33128
88ee8f3bfff3
equal deleted inserted replaced
32771:681ca041d42b 33120:f6f1a27ade72
121 GtkWidget * 121 GtkWidget *
122 pidgin_prefs_labeled_spin_button(GtkWidget *box, const gchar *title, 122 pidgin_prefs_labeled_spin_button(GtkWidget *box, const gchar *title,
123 const char *key, int min, int max, GtkSizeGroup *sg) 123 const char *key, int min, int max, GtkSizeGroup *sg)
124 { 124 {
125 GtkWidget *spin; 125 GtkWidget *spin;
126 GtkObject *adjust; 126 GtkAdjustment *adjust;
127 int val; 127 int val;
128 128
129 val = purple_prefs_get_int(key); 129 val = purple_prefs_get_int(key);
130 130
131 adjust = gtk_adjustment_new(val, min, max, 1, 1, 0); 131 adjust = gtk_adjustment_new(val, min, max, 1, 1, 0);
185 gtk_widget_show(entry); 185 gtk_widget_show(entry);
186 186
187 return pidgin_add_widget_to_vbox(GTK_BOX(page), title, sg, entry, TRUE, NULL); 187 return pidgin_add_widget_to_vbox(GTK_BOX(page), title, sg, entry, TRUE, NULL);
188 } 188 }
189 189
190 /* TODO: Maybe move this up somewheres... */
191 enum {
192 PREF_DROPDOWN_TEXT,
193 PREF_DROPDOWN_VALUE,
194 PREF_DROPDOWN_COUNT
195 };
190 196
191 static void 197 static void
192 dropdown_set(GObject *w, const char *key) 198 dropdown_set(GObject *w, const char *key)
193 { 199 {
194 const char *str_value; 200 const char *str_value;
195 int int_value; 201 int int_value;
202 gboolean bool_value;
196 PurplePrefType type; 203 PurplePrefType type;
204 GtkTreeIter iter;
205 GtkTreeModel *tree_model;
206
207 tree_model = gtk_combo_box_get_model(GTK_COMBO_BOX(w));
208 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(w), &iter))
209 return;
197 210
198 type = GPOINTER_TO_INT(g_object_get_data(w, "type")); 211 type = GPOINTER_TO_INT(g_object_get_data(w, "type"));
199 212
200 if (type == PURPLE_PREF_INT) { 213 if (type == PURPLE_PREF_INT) {
201 int_value = GPOINTER_TO_INT(g_object_get_data(w, "value")); 214 gtk_tree_model_get(tree_model, &iter,
215 PREF_DROPDOWN_VALUE, &int_value,
216 -1);
202 217
203 purple_prefs_set_int(key, int_value); 218 purple_prefs_set_int(key, int_value);
204 } 219 }
205 else if (type == PURPLE_PREF_STRING) { 220 else if (type == PURPLE_PREF_STRING) {
206 str_value = (const char *)g_object_get_data(w, "value"); 221 gtk_tree_model_get(tree_model, &iter,
222 PREF_DROPDOWN_VALUE, &str_value,
223 -1);
207 224
208 purple_prefs_set_string(key, str_value); 225 purple_prefs_set_string(key, str_value);
209 } 226 }
210 else if (type == PURPLE_PREF_BOOLEAN) { 227 else if (type == PURPLE_PREF_BOOLEAN) {
211 purple_prefs_set_bool(key, 228 gtk_tree_model_get(tree_model, &iter,
212 GPOINTER_TO_INT(g_object_get_data(w, "value"))); 229 PREF_DROPDOWN_VALUE, &bool_value,
230 -1);
231
232 purple_prefs_set_bool(key, bool_value);
213 } 233 }
214 } 234 }
215 235
216 GtkWidget * 236 GtkWidget *
217 pidgin_prefs_dropdown_from_list(GtkWidget *box, const gchar *title, 237 pidgin_prefs_dropdown_from_list(GtkWidget *box, const gchar *title,
218 PurplePrefType type, const char *key, GList *menuitems) 238 PurplePrefType type, const char *key, GList *menuitems)
219 { 239 {
220 GtkWidget *dropdown, *opt, *menu; 240 GtkWidget *dropdown;
221 GtkWidget *label = NULL; 241 GtkWidget *label = NULL;
222 gchar *text; 242 gchar *text;
223 const char *stored_str = NULL; 243 const char *stored_str = NULL;
224 int stored_int = 0; 244 int stored_int = 0;
245 gboolean stored_bool = FALSE;
225 int int_value = 0; 246 int int_value = 0;
226 const char *str_value = NULL; 247 const char *str_value = NULL;
227 int o = 0; 248 gboolean bool_value = FALSE;
249 GtkListStore *store;
250 GtkTreeIter iter;
251 GtkTreeIter active;
252 GtkCellRenderer *renderer;
228 253
229 g_return_val_if_fail(menuitems != NULL, NULL); 254 g_return_val_if_fail(menuitems != NULL, NULL);
230 255
231 dropdown = gtk_option_menu_new(); 256 if (type == PURPLE_PREF_INT) {
232 menu = gtk_menu_new(); 257 store = gtk_list_store_new(PREF_DROPDOWN_COUNT, G_TYPE_STRING, G_TYPE_INT);
233
234 if (type == PURPLE_PREF_INT)
235 stored_int = purple_prefs_get_int(key); 258 stored_int = purple_prefs_get_int(key);
236 else if (type == PURPLE_PREF_STRING) 259 } else if (type == PURPLE_PREF_STRING) {
260 store = gtk_list_store_new(PREF_DROPDOWN_COUNT, G_TYPE_STRING, G_TYPE_STRING);
237 stored_str = purple_prefs_get_string(key); 261 stored_str = purple_prefs_get_string(key);
238 262 } else if (type == PURPLE_PREF_BOOLEAN) {
239 while (menuitems != NULL && (text = (char *) menuitems->data) != NULL) { 263 store = gtk_list_store_new(PREF_DROPDOWN_COUNT, G_TYPE_STRING, G_TYPE_BOOLEAN);
264 stored_bool = purple_prefs_get_bool(key);
265 }
266
267 dropdown = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
268 g_object_set_data(G_OBJECT(dropdown), "type", GINT_TO_POINTER(type));
269
270 while (menuitems != NULL && (text = (char *)menuitems->data) != NULL) {
240 menuitems = g_list_next(menuitems); 271 menuitems = g_list_next(menuitems);
241 g_return_val_if_fail(menuitems != NULL, NULL); 272 g_return_val_if_fail(menuitems != NULL, NULL);
242 273
243 opt = gtk_menu_item_new_with_label(text); 274 gtk_list_store_append(store, &iter);
244 275 gtk_list_store_set(store, &iter,
245 g_object_set_data(G_OBJECT(opt), "type", GINT_TO_POINTER(type)); 276 PREF_DROPDOWN_TEXT, text,
277 -1);
246 278
247 if (type == PURPLE_PREF_INT) { 279 if (type == PURPLE_PREF_INT) {
248 int_value = GPOINTER_TO_INT(menuitems->data); 280 int_value = GPOINTER_TO_INT(menuitems->data);
249 g_object_set_data(G_OBJECT(opt), "value", 281 gtk_list_store_set(store, &iter,
250 GINT_TO_POINTER(int_value)); 282 PREF_DROPDOWN_VALUE, int_value,
283 -1);
251 } 284 }
252 else if (type == PURPLE_PREF_STRING) { 285 else if (type == PURPLE_PREF_STRING) {
253 str_value = (const char *)menuitems->data; 286 str_value = (const char *)menuitems->data;
254 287 gtk_list_store_set(store, &iter,
255 g_object_set_data(G_OBJECT(opt), "value", (char *)str_value); 288 PREF_DROPDOWN_VALUE, str_value,
289 -1);
256 } 290 }
257 else if (type == PURPLE_PREF_BOOLEAN) { 291 else if (type == PURPLE_PREF_BOOLEAN) {
258 g_object_set_data(G_OBJECT(opt), "value", 292 bool_value = (gboolean)GPOINTER_TO_INT(menuitems->data);
259 menuitems->data); 293 gtk_list_store_set(store, &iter,
294 PREF_DROPDOWN_VALUE, bool_value,
295 -1);
260 } 296 }
261
262 g_signal_connect(G_OBJECT(opt), "activate",
263 G_CALLBACK(dropdown_set), (char *)key);
264
265 gtk_widget_show(opt);
266 gtk_menu_shell_append(GTK_MENU_SHELL(menu), opt);
267 297
268 if ((type == PURPLE_PREF_INT && stored_int == int_value) || 298 if ((type == PURPLE_PREF_INT && stored_int == int_value) ||
269 (type == PURPLE_PREF_STRING && stored_str != NULL && 299 (type == PURPLE_PREF_STRING && stored_str != NULL &&
270 !strcmp(stored_str, str_value)) || 300 !strcmp(stored_str, str_value)) ||
271 (type == PURPLE_PREF_BOOLEAN && 301 (type == PURPLE_PREF_BOOLEAN &&
272 (purple_prefs_get_bool(key) == GPOINTER_TO_INT(menuitems->data)))) { 302 (stored_bool == bool_value))) {
273 303
274 gtk_menu_set_active(GTK_MENU(menu), o); 304 active = iter;
275 } 305 }
276 306
277 menuitems = g_list_next(menuitems); 307 menuitems = g_list_next(menuitems);
278 308 }
279 o++; 309
280 } 310 renderer = gtk_cell_renderer_text_new();
281 311 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(dropdown), renderer, TRUE);
282 gtk_option_menu_set_menu(GTK_OPTION_MENU(dropdown), menu); 312 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(dropdown), renderer,
313 "text", 0,
314 NULL);
315
316 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(dropdown), &active);
317
318 g_signal_connect(G_OBJECT(dropdown), "changed",
319 G_CALLBACK(dropdown_set), (char *)key);
283 320
284 pidgin_add_widget_to_vbox(GTK_BOX(box), title, NULL, dropdown, FALSE, &label); 321 pidgin_add_widget_to_vbox(GTK_BOX(box), title, NULL, dropdown, FALSE, &label);
285 322
286 return label; 323 return label;
287 } 324 }
860 897
861 static void 898 static void
862 theme_dnd_recv(GtkWidget *widget, GdkDragContext *dc, guint x, guint y, 899 theme_dnd_recv(GtkWidget *widget, GdkDragContext *dc, guint x, guint y,
863 GtkSelectionData *sd, guint info, guint t, gpointer user_data) 900 GtkSelectionData *sd, guint info, guint t, gpointer user_data)
864 { 901 {
865 gchar *name = g_strchomp((gchar *)sd->data); 902 gchar *name = g_strchomp((gchar *)gtk_selection_data_get_data(sd));
866 903
867 if ((sd->length >= 0) && (sd->format == 8)) { 904 if ((gtk_selection_data_get_length(sd) >= 0)
905 && (gtk_selection_data_get_format(sd) == 8)) {
868 /* Well, it looks like the drag event was cool. 906 /* Well, it looks like the drag event was cool.
869 * Let's do something with it */ 907 * Let's do something with it */
870 gchar *temp; 908 gchar *temp;
871 struct theme_info *info = g_new0(struct theme_info, 1); 909 struct theme_info *info = g_new0(struct theme_info, 1);
872 info->type = g_strdup((gchar *)user_data); 910 info->type = g_strdup((gchar *)user_data);
2585 2623
2586 static GtkWidget * 2624 static GtkWidget *
2587 sound_page(void) 2625 sound_page(void)
2588 { 2626 {
2589 GtkWidget *ret; 2627 GtkWidget *ret;
2590 GtkWidget *vbox, *vbox2, *sw, *button; 2628 GtkWidget *vbox, *vbox2, *sw, *button, *parent, *parent_parent, *parent_parent_parent;
2591 GtkSizeGroup *sg; 2629 GtkSizeGroup *sg;
2592 GtkTreeIter iter; 2630 GtkTreeIter iter;
2593 GtkWidget *event_view; 2631 GtkWidget *event_view;
2594 GtkListStore *event_store; 2632 GtkListStore *event_store;
2595 GtkCellRenderer *rend; 2633 GtkCellRenderer *rend;
2682 strcmp(purple_prefs_get_string(PIDGIN_PREFS_ROOT "/sound/method"), "none")); 2720 strcmp(purple_prefs_get_string(PIDGIN_PREFS_ROOT "/sound/method"), "none"));
2683 purple_prefs_connect_callback(prefs, PIDGIN_PREFS_ROOT "/sound/method", 2721 purple_prefs_connect_callback(prefs, PIDGIN_PREFS_ROOT "/sound/method",
2684 sound_changed2_cb, vbox); 2722 sound_changed2_cb, vbox);
2685 #endif 2723 #endif
2686 vbox = pidgin_make_frame(ret, _("Sound Events")); 2724 vbox = pidgin_make_frame(ret, _("Sound Events"));
2725 parent = gtk_widget_get_parent(vbox);
2726 parent_parent = gtk_widget_get_parent(parent);
2727 parent_parent_parent = gtk_widget_get_parent(parent_parent);
2687 2728
2688 /* The following is an ugly hack to make the frame expand so the 2729 /* The following is an ugly hack to make the frame expand so the
2689 * sound events list is big enough to be usable */ 2730 * sound events list is big enough to be usable */
2690 gtk_box_set_child_packing(GTK_BOX(vbox->parent), vbox, TRUE, TRUE, 0, 2731 gtk_box_set_child_packing(GTK_BOX(parent), vbox, TRUE, TRUE, 0,
2691 GTK_PACK_START); 2732 GTK_PACK_START);
2692 gtk_box_set_child_packing(GTK_BOX(vbox->parent->parent), vbox->parent, TRUE, 2733 gtk_box_set_child_packing(GTK_BOX(parent_parent),
2693 TRUE, 0, GTK_PACK_START); 2734 parent, TRUE, TRUE, 0, GTK_PACK_START);
2694 gtk_box_set_child_packing(GTK_BOX(vbox->parent->parent->parent), 2735 gtk_box_set_child_packing(GTK_BOX(parent_parent_parent),
2695 vbox->parent->parent, TRUE, TRUE, 0, GTK_PACK_START); 2736 parent_parent, TRUE, TRUE, 0, GTK_PACK_START);
2696 2737
2697 /* SOUND SELECTION */ 2738 /* SOUND SELECTION */
2698 event_store = gtk_list_store_new (4, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT); 2739 event_store = gtk_list_store_new (4, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT);
2699 2740
2700 for (j=0; j < PURPLE_NUM_SOUNDS; j++) { 2741 for (j=0; j < PURPLE_NUM_SOUNDS; j++) {

mercurial