comparison pidgin-twitter.c @ 126:bac987852e66

switched to native gtk preferences dialog.
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Mon, 21 Jul 2008 10:40:55 +0900
parents f0305c387d32
children 249174fdd63d
comparison
equal deleted inserted replaced
125:f0305c387d32 126:bac987852e66
2388 (GHFunc)invalidate_icon_data_func, NULL); 2388 (GHFunc)invalidate_icon_data_func, NULL);
2389 g_hash_table_foreach(icon_data_by_user3, 2389 g_hash_table_foreach(icon_data_by_user3,
2390 (GHFunc)invalidate_icon_data_func, NULL); 2390 (GHFunc)invalidate_icon_data_func, NULL);
2391 } 2391 }
2392 2392
2393 static void
2394 text_changed_cb(gpointer *data)
2395 {
2396 const gchar *text;
2397 gchar *pref = (gchar *)g_object_get_data(G_OBJECT(data), "pref");
2398 text = gtk_entry_get_text(GTK_ENTRY(data));
2399 purple_prefs_set_string(pref, text);
2400 }
2401
2402 static void
2403 bool_toggled_cb(gpointer *data)
2404 {
2405 gchar *pref = (gchar *)g_object_get_data(G_OBJECT(data), "pref");
2406 gboolean value = purple_prefs_get_bool(pref);
2407 purple_prefs_set_bool(pref, !value);
2408 }
2409
2410 static void
2411 spin_changed_cb(gpointer *data)
2412 {
2413 gchar *pref = (gchar *)g_object_get_data(G_OBJECT(data), "pref");
2414
2415 twitter_debug("called\n");
2416
2417 purple_prefs_set_int(
2418 pref,
2419 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(data)));
2420 }
2421
2422 static void
2423 combo_changed_cb(gpointer *data)
2424 {
2425 gint position;
2426 gchar *pref = (gchar *)g_object_get_data(G_OBJECT(data), "pref");
2427 position = gtk_combo_box_get_active(GTK_COMBO_BOX(data));
2428 purple_prefs_set_int(pref, position);
2429 }
2430
2431 static GtkWidget *
2432 prefs_get_frame(PurplePlugin *plugin)
2433 {
2434 GtkBuilder *builder;
2435 GError *err = NULL;
2436 gchar *filename;
2437 GtkWidget *window, *notebook, *e;
2438 const gchar *text;
2439 int i;
2440
2441 builder = gtk_builder_new();
2442
2443 filename = g_build_filename(DATADIR, "pidgin-twitter", "prefs.ui", NULL);
2444 gtk_builder_add_from_file(builder, filename, &err);
2445 if(err) {
2446 twitter_debug("%s\n", err->message);
2447 return NULL;
2448 }
2449
2450 g_free(filename);
2451
2452 gtk_builder_connect_signals(builder, NULL);
2453
2454 window = GTK_WIDGET(gtk_builder_get_object(builder, "prefswindow"));
2455 notebook = GTK_WIDGET(gtk_builder_get_object(builder, "prefsnotebook"));
2456
2457 gtk_container_remove(GTK_CONTAINER(window), notebook);
2458
2459 g_signal_connect(notebook, "destroy",
2460 G_CALLBACK(gtk_widget_destroyed), &notebook);
2461
2462 /* connect to signals */
2463
2464 /* account page */
2465 e = GTK_WIDGET(gtk_builder_get_object (builder, "account_twitter"));
2466 g_object_set_data(G_OBJECT(e), "pref", OPT_SCREEN_NAME_TWITTER);
2467 text = purple_prefs_get_string(OPT_SCREEN_NAME_TWITTER);
2468 gtk_entry_set_text(GTK_ENTRY(e), text);
2469 g_signal_connect(e, "changed",
2470 G_CALLBACK(text_changed_cb), &e);
2471
2472 e = GTK_WIDGET(gtk_builder_get_object (builder, "account_wassr"));
2473 g_object_set_data(G_OBJECT(e), "pref", OPT_SCREEN_NAME_WASSR);
2474 text = purple_prefs_get_string(OPT_SCREEN_NAME_WASSR);
2475 gtk_entry_set_text(GTK_ENTRY(e), text);
2476 g_signal_connect(e, "changed",
2477 G_CALLBACK(text_changed_cb), &e);
2478
2479 e = GTK_WIDGET(gtk_builder_get_object (builder, "account_identica"));
2480 g_object_set_data(G_OBJECT(e), "pref", OPT_SCREEN_NAME_IDENTICA);
2481 text = purple_prefs_get_string(OPT_SCREEN_NAME_IDENTICA);
2482 gtk_entry_set_text(GTK_ENTRY(e), text);
2483 g_signal_connect(e, "changed",
2484 G_CALLBACK(text_changed_cb), &e);
2485
2486 e = GTK_WIDGET(gtk_builder_get_object (builder, "account_api"));
2487 g_object_set_data(G_OBJECT(e), "pref", OPT_API_BASE_POST);
2488 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(e),
2489 purple_prefs_get_bool(OPT_API_BASE_POST));
2490 g_signal_connect(e, "toggled",
2491 G_CALLBACK(bool_toggled_cb), &e);
2492
2493 purple_prefs_connect_callback(plugin, OPT_API_BASE_POST, // xxx devide?
2494 api_base_post_cb, NULL);
2495
2496 e = GTK_WIDGET(gtk_builder_get_object (builder, "account_api_password"));
2497 g_object_set_data(G_OBJECT(e), "pref", OPT_PASSWORD_TWITTER);
2498 text = purple_prefs_get_string(OPT_PASSWORD_TWITTER); //xxx should be masked
2499 gtk_entry_set_text(GTK_ENTRY(e), text);
2500 g_signal_connect(e, "changed",
2501 G_CALLBACK(text_changed_cb), &e);
2502
2503 /* translation page */
2504 e = GTK_WIDGET(gtk_builder_get_object (builder, "translation_recipient"));
2505 g_object_set_data(G_OBJECT(e), "pref", OPT_TRANSLATE_RECIPIENT);
2506 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(e),
2507 purple_prefs_get_bool(OPT_TRANSLATE_RECIPIENT));
2508 g_signal_connect(e, "toggled",
2509 G_CALLBACK(bool_toggled_cb), &e);
2510
2511 e = GTK_WIDGET(gtk_builder_get_object (builder, "translation_sender"));
2512 g_object_set_data(G_OBJECT(e), "pref", OPT_TRANSLATE_SENDER);
2513 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(e),
2514 purple_prefs_get_bool(OPT_TRANSLATE_SENDER));
2515 g_signal_connect(e, "toggled",
2516 G_CALLBACK(bool_toggled_cb), &e);
2517
2518 e = GTK_WIDGET(gtk_builder_get_object (builder, "translation_channel"));
2519 g_object_set_data(G_OBJECT(e), "pref", OPT_TRANSLATE_CHANNEL);
2520 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(e),
2521 purple_prefs_get_bool(OPT_TRANSLATE_CHANNEL));
2522 g_signal_connect(e, "toggled",
2523 G_CALLBACK(bool_toggled_cb), &e);
2524
2525 /* utility page */
2526 e = GTK_WIDGET(gtk_builder_get_object (builder, "utility_show_icon"));
2527 g_object_set_data(G_OBJECT(e), "pref", OPT_SHOW_ICON);
2528 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(e),
2529 purple_prefs_get_bool(OPT_SHOW_ICON));
2530 g_signal_connect(e, "toggled",
2531 G_CALLBACK(bool_toggled_cb), &e);
2532 purple_prefs_connect_callback(plugin, OPT_ICON_SIZE, //xxx
2533 icon_size_prefs_cb, NULL);
2534
2535 /* setup spin */
2536 e = GTK_WIDGET(gtk_builder_get_object (builder, "utility_icon_size_spin"));
2537 g_object_set_data(G_OBJECT(e), "pref", OPT_ICON_SIZE);
2538
2539 GtkSpinButton *spin = GTK_SPIN_BUTTON(e);
2540
2541 int value = purple_prefs_get_int(OPT_ICON_SIZE);
2542 twitter_debug("spin value = %d\n", value);
2543
2544 GtkAdjustment *adjust = gtk_adjustment_new(value, 16, 128, 4, 1, 1);
2545 gtk_spin_button_set_adjustment(spin, adjust);
2546 gtk_widget_set_size_request(spin, 50, -1);
2547
2548 if(value == 0) {
2549 value = DEFAULT_ICON_SIZE;
2550 purple_prefs_set_int(OPT_ICON_SIZE, value);
2551 }
2552 gtk_spin_button_set_value(GTK_SPIN_BUTTON(e), (gdouble)value);
2553 g_signal_connect(e, "value-changed",
2554 G_CALLBACK(spin_changed_cb), &e);
2555
2556
2557
2558 e = GTK_WIDGET(gtk_builder_get_object (builder, "utility_counter"));
2559 g_object_set_data(G_OBJECT(e), "pref", OPT_COUNTER);
2560 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(e),
2561 purple_prefs_get_bool(OPT_COUNTER));
2562 g_signal_connect(e, "toggled",
2563 G_CALLBACK(bool_toggled_cb), &e);
2564 purple_prefs_connect_callback(plugin, OPT_COUNTER, //xxx
2565 counter_prefs_cb, NULL);
2566
2567 e = GTK_WIDGET(gtk_builder_get_object (builder, "utility_pseudo"));
2568 g_object_set_data(G_OBJECT(e), "pref", OPT_ESCAPE_PSEUDO);
2569 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(e),
2570 purple_prefs_get_bool(OPT_ESCAPE_PSEUDO));
2571 g_signal_connect(e, "toggled",
2572 G_CALLBACK(bool_toggled_cb), &e);
2573
2574 e = GTK_WIDGET(gtk_builder_get_object (builder, "utility_oops"));
2575 g_object_set_data(G_OBJECT(e), "pref", OPT_SUPPRESS_OOPS);
2576 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(e),
2577 purple_prefs_get_bool(OPT_SUPPRESS_OOPS));
2578 g_signal_connect(e, "toggled",
2579 G_CALLBACK(bool_toggled_cb), &e);
2580
2581 e = GTK_WIDGET(gtk_builder_get_object (builder, "utility_notify"));
2582 g_object_set_data(G_OBJECT(e), "pref", OPT_PREVENT_NOTIFICATION);
2583 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(e),
2584 purple_prefs_get_bool(OPT_PREVENT_NOTIFICATION));
2585 g_signal_connect(e, "toggled",
2586 G_CALLBACK(bool_toggled_cb), &e);
2587
2588
2589 /* sound page */
2590 e = GTK_WIDGET(gtk_builder_get_object (builder, "sound_recip_check"));
2591 g_object_set_data(G_OBJECT(e), "pref", OPT_PLAYSOUND_RECIPIENT);
2592 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(e),
2593 purple_prefs_get_bool(OPT_PLAYSOUND_RECIPIENT));
2594 g_signal_connect(e, "toggled",
2595 G_CALLBACK(bool_toggled_cb), &e);
2596
2597 e = GTK_WIDGET(gtk_builder_get_object (builder, "sound_recip_list"));
2598 g_object_set_data(G_OBJECT(e), "pref", OPT_USERLIST_RECIPIENT);
2599 text = purple_prefs_get_string(OPT_USERLIST_RECIPIENT);
2600 gtk_entry_set_text(GTK_ENTRY(e), text);
2601 g_signal_connect(e, "changed",
2602 G_CALLBACK(text_changed_cb), &e);
2603
2604 /* setup combobox */
2605 e = GTK_WIDGET(gtk_builder_get_object (builder, "sound_recip_combo"));
2606 gtk_combo_box_set_active(GTK_COMBO_BOX(e),
2607 purple_prefs_get_int(OPT_SOUNDID_RECIPIENT));
2608 g_object_set_data(G_OBJECT(e), "pref", OPT_SOUNDID_RECIPIENT);
2609 g_signal_connect(e, "changed",
2610 G_CALLBACK(combo_changed_cb), &e);
2611
2612
2613
2614 e = GTK_WIDGET(gtk_builder_get_object (builder, "sound_send_check"));
2615 g_object_set_data(G_OBJECT(e), "pref", OPT_PLAYSOUND_SENDER);
2616 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(e),
2617 purple_prefs_get_bool(OPT_PLAYSOUND_SENDER));
2618 g_signal_connect(e, "toggled",
2619 G_CALLBACK(bool_toggled_cb), &e);
2620
2621 e = GTK_WIDGET(gtk_builder_get_object (builder, "sound_send_list"));
2622 g_object_set_data(G_OBJECT(e), "pref", OPT_USERLIST_SENDER);
2623 text = purple_prefs_get_string(OPT_USERLIST_SENDER);
2624 gtk_entry_set_text(GTK_ENTRY(e), text);
2625 g_signal_connect(e, "changed",
2626 G_CALLBACK(text_changed_cb), &e);
2627
2628 /* setup combobox */
2629 e = GTK_WIDGET(gtk_builder_get_object (builder, "sound_send_combo"));
2630 gtk_combo_box_set_active(GTK_COMBO_BOX(e),
2631 purple_prefs_get_int(OPT_SOUNDID_RECIPIENT));
2632 g_object_set_data(G_OBJECT(e), "pref", OPT_SOUNDID_SENDER);
2633 g_signal_connect(e, "changed",
2634 G_CALLBACK(combo_changed_cb), &e);
2635
2636
2637 gtk_widget_show_all(notebook);
2638 return notebook;
2639 }
2640
2393 static PurplePluginPrefFrame * 2641 static PurplePluginPrefFrame *
2394 get_plugin_pref_frame(PurplePlugin *plugin) 2642 get_plugin_pref_frame(PurplePlugin *plugin)
2395 { 2643 {
2396 /* create gtk elements for the plugin preferences */ 2644 /* create gtk elements for the plugin preferences */
2397 PurplePluginPref *pref; 2645 PurplePluginPref *pref;
2508 2756
2509 purple_plugin_pref_set_type(pref, PURPLE_PLUGIN_PREF_CHOICE); 2757 purple_plugin_pref_set_type(pref, PURPLE_PLUGIN_PREF_CHOICE);
2510 purple_plugin_pref_add_choice(pref, "Arrive", GINT_TO_POINTER(0)); 2758 purple_plugin_pref_add_choice(pref, "Arrive", GINT_TO_POINTER(0));
2511 purple_plugin_pref_add_choice(pref, "Leave", GINT_TO_POINTER(1)); 2759 purple_plugin_pref_add_choice(pref, "Leave", GINT_TO_POINTER(1));
2512 purple_plugin_pref_add_choice(pref, "Receive", GINT_TO_POINTER(2)); 2760 purple_plugin_pref_add_choice(pref, "Receive", GINT_TO_POINTER(2));
2513 purple_plugin_pref_add_choice(pref, "Fist Receive", GINT_TO_POINTER(3)); 2761 purple_plugin_pref_add_choice(pref, "First Receive", GINT_TO_POINTER(3));
2514 purple_plugin_pref_add_choice(pref, "Send", GINT_TO_POINTER(4)); 2762 purple_plugin_pref_add_choice(pref, "Send", GINT_TO_POINTER(4));
2515 purple_plugin_pref_add_choice(pref, "Chat Join", GINT_TO_POINTER(5)); 2763 purple_plugin_pref_add_choice(pref, "Chat Join", GINT_TO_POINTER(5));
2516 purple_plugin_pref_add_choice(pref, "Chat Leave", GINT_TO_POINTER(6)); 2764 purple_plugin_pref_add_choice(pref, "Chat Leave", GINT_TO_POINTER(6));
2517 purple_plugin_pref_add_choice(pref, "Chat You Say", GINT_TO_POINTER(7)); 2765 purple_plugin_pref_add_choice(pref, "Chat You Say", GINT_TO_POINTER(7));
2518 purple_plugin_pref_add_choice(pref, "Chat Someone Say", GINT_TO_POINTER(8)); 2766 purple_plugin_pref_add_choice(pref, "Chat Someone Say", GINT_TO_POINTER(8));
2538 2786
2539 purple_plugin_pref_set_type(pref, PURPLE_PLUGIN_PREF_CHOICE); 2787 purple_plugin_pref_set_type(pref, PURPLE_PLUGIN_PREF_CHOICE);
2540 purple_plugin_pref_add_choice(pref, "Arrive", GINT_TO_POINTER(0)); 2788 purple_plugin_pref_add_choice(pref, "Arrive", GINT_TO_POINTER(0));
2541 purple_plugin_pref_add_choice(pref, "Leave", GINT_TO_POINTER(1)); 2789 purple_plugin_pref_add_choice(pref, "Leave", GINT_TO_POINTER(1));
2542 purple_plugin_pref_add_choice(pref, "Receive", GINT_TO_POINTER(2)); 2790 purple_plugin_pref_add_choice(pref, "Receive", GINT_TO_POINTER(2));
2543 purple_plugin_pref_add_choice(pref, "Fist Receive", GINT_TO_POINTER(3)); 2791 purple_plugin_pref_add_choice(pref, "First Receive", GINT_TO_POINTER(3));
2544 purple_plugin_pref_add_choice(pref, "Send", GINT_TO_POINTER(4)); 2792 purple_plugin_pref_add_choice(pref, "Send", GINT_TO_POINTER(4));
2545 purple_plugin_pref_add_choice(pref, "Chat Join", GINT_TO_POINTER(5)); 2793 purple_plugin_pref_add_choice(pref, "Chat Join", GINT_TO_POINTER(5));
2546 purple_plugin_pref_add_choice(pref, "Chat Leave", GINT_TO_POINTER(6)); 2794 purple_plugin_pref_add_choice(pref, "Chat Leave", GINT_TO_POINTER(6));
2547 purple_plugin_pref_add_choice(pref, "Chat You Say", GINT_TO_POINTER(7)); 2795 purple_plugin_pref_add_choice(pref, "Chat You Say", GINT_TO_POINTER(7));
2548 purple_plugin_pref_add_choice(pref, "Chat Someone Say", GINT_TO_POINTER(8)); 2796 purple_plugin_pref_add_choice(pref, "Chat Someone Say", GINT_TO_POINTER(8));
2571 purple_plugin_pref_frame_add(frame, pref); 2819 purple_plugin_pref_frame_add(frame, pref);
2572 2820
2573 return frame; 2821 return frame;
2574 } 2822 }
2575 2823
2824 #if 0
2576 static PurplePluginUiInfo pref_info = { 2825 static PurplePluginUiInfo pref_info = {
2577 get_plugin_pref_frame 2826 get_plugin_pref_frame
2827 };
2828 #endif
2829
2830 static PidginPluginUiInfo ui_info = {
2831 prefs_get_frame,
2832 0, /* page number - reserved */
2833 NULL, /* reserved 1 */
2834 NULL, /* reserved 2 */
2835 NULL, /* reserved 3 */
2836 NULL /* reserved 4 */
2578 }; 2837 };
2579 2838
2580 static PurplePluginInfo info = { 2839 static PurplePluginInfo info = {
2581 PURPLE_PLUGIN_MAGIC, 2840 PURPLE_PLUGIN_MAGIC,
2582 PURPLE_MAJOR_VERSION, 2841 PURPLE_MAJOR_VERSION,
2583 PURPLE_MINOR_VERSION, 2842 PURPLE_MINOR_VERSION,
2584 PURPLE_PLUGIN_STANDARD, /**< type */ 2843 PURPLE_PLUGIN_STANDARD, /**< type */
2585 NULL, /**< ui_req */ 2844 // NULL, /**< ui_req */
2845 PIDGIN_PLUGIN_TYPE, /**< ui_req */
2586 0, /**< flags */ 2846 0, /**< flags */
2587 NULL, /**< deps */ 2847 NULL, /**< deps */
2588 PURPLE_PRIORITY_DEFAULT, /**< priority */ 2848 PURPLE_PRIORITY_DEFAULT, /**< priority */
2589 PLUGIN_ID, /**< id */ 2849 PLUGIN_ID, /**< id */
2590 "Pidgin-Twitter", /**< name */ 2850 "Pidgin-Twitter", /**< name */
2594 "Yoshiki Yazawa, mikanbako, \nKonosuke Watanabe, IWATA Ray, mojin, \nthe pidging-twitter team", /**< author */ 2854 "Yoshiki Yazawa, mikanbako, \nKonosuke Watanabe, IWATA Ray, mojin, \nthe pidging-twitter team", /**< author */
2595 "http://www.honeyplanet.jp/", /**< homepage */ 2855 "http://www.honeyplanet.jp/", /**< homepage */
2596 load_plugin, /**< load */ 2856 load_plugin, /**< load */
2597 unload_plugin, /**< unload */ 2857 unload_plugin, /**< unload */
2598 NULL, /**< destroy */ 2858 NULL, /**< destroy */
2859 #if 0
2599 NULL, /**< ui_info */ 2860 NULL, /**< ui_info */
2600 NULL, /**< extra_info */ 2861 NULL, /**< extra_info */
2601 &pref_info, /**< pref info */ 2862 &pref_info, /**< pref info */
2863 #else
2864 &ui_info, /**< ui_info */
2865 NULL, /**< extra_info */
2866 NULL, /**< pref info */
2867 #endif
2602 NULL 2868 NULL
2603 }; 2869 };
2604 2870
2605 static void 2871 static void
2606 init_plugin(PurplePlugin *plugin) 2872 init_plugin(PurplePlugin *plugin)