Mercurial > pidgin-twitter
changeset 193:0b0b4cab7c0e multiaccounts
move some UI definition of preferences per conversation from pidgin-twitter.c to prefs.ui
author | mikanbako <maoutwo@gmail.com> |
---|---|
date | Tue, 05 Aug 2008 23:19:09 +0900 |
parents | 1265988dc2bf |
children | be4ef598d120 |
files | pidgin-twitter.c pidgin-twitter.h prefs.ui |
diffstat | 3 files changed, 420 insertions(+), 137 deletions(-) [+] |
line wrap: on
line diff
--- a/pidgin-twitter.c Tue Aug 05 01:26:08 2008 +0900 +++ b/pidgin-twitter.c Tue Aug 05 23:19:09 2008 +0900 @@ -2956,8 +2956,7 @@ { PidginConversation *gtkconv = (PidginConversation *) gtkconv_ptr; PurpleConversation *conv = gtkconv->active_conv; - GtkWidget *dialog; - GtkWidget *notebook = gtk_notebook_new(); + GtkWidget *dialog, *vbox; gchar *title; title = g_strdup_printf("\"%s\" Account Preference", conv->title); @@ -2986,42 +2985,50 @@ G_CALLBACK(closed_account_preference_window_cb), pref_button); - /* Screen Name */ - build_screen_name_preference_form(conv, notebook); /* API Base Post */ if(is_twitter_conv(conv)) - build_twitter_api_preference_form(conv, notebook); + vbox = build_twitter_preference_form(conv); + else + vbox = build_default_preference_form(conv); gtk_button_set_label(GTK_BUTTON(pref_button), ACCOUNT_PREF_BUTTON_NORMAL); gtk_widget_set_sensitive(pref_button, FALSE); - gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), notebook); + gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), vbox); gtk_widget_show_all(GTK_WIDGET(dialog)); } -static void -build_screen_name_preference_form(PurpleConversation *conv, - GtkWidget *notebook) +static GtkWidget* +build_default_preference_form(PurpleConversation *conv) { PurpleAccount *account = purple_conversation_get_account(conv); const char *conv_name = purple_conversation_get_name(conv); - GtkWidget *tab_label, *child, *line, *container, *widget; - - child = gtk_vbox_new(FALSE, 0); - - /********************/ - /* screen name form */ - /********************/ - line = gtk_hbox_new(TRUE, 0); - - /* label */ - widget = gtk_label_new("screen name"); - container = gtk_alignment_new(0.0, 0.5, 0.0, 0.0); - gtk_container_add(GTK_CONTAINER(container), widget); - gtk_alignment_set_padding(GTK_ALIGNMENT(container), 0, 0, 20, 0); - gtk_box_pack_start_defaults(GTK_BOX(line), container); - - /* entry */ - widget = gtk_entry_new(); + GtkWidget *widget; + gchar *filename; + GError *err = NULL; + GtkBuilder *builder = gtk_builder_new(); + +#ifdef _WIN32 + filename = g_build_filename(purple_user_dir(), + "pidgin-twitter", "prefs.ui", NULL); +#else + filename = g_build_filename(DATADIR, + "pidgin-twitter", "prefs.ui", NULL); +#endif + + gtk_builder_add_from_file(builder, filename, &err); + if(err) { + twitter_debug("%s\n", err->message); + g_free(filename); + return NULL; + } + gtk_builder_connect_signals(builder, NULL); + + /**********************/ + /* connect to signals */ + /**********************/ + + /* screen name */ + widget = GTK_WIDGET(gtk_builder_get_object(builder, "screen_name")); gtk_entry_set_text(GTK_ENTRY(widget), service_account_get_string(account, conv_name, @@ -3035,58 +3042,61 @@ "changed", G_CALLBACK(account_preference_text_changed_cb), conv); - container = gtk_alignment_new(1.0, 0.5, 1.0, 0.0); - gtk_container_add(GTK_CONTAINER(container), widget); - gtk_alignment_set_padding(GTK_ALIGNMENT(container), 0, 0, 0, 20); - gtk_box_pack_start_defaults(GTK_BOX(line), container); - - gtk_box_pack_start_defaults(GTK_BOX(child), line); - - /**************************************************/ - /* the explanation why a screen name is necessary */ - /**************************************************/ - line = gtk_hbox_new(FALSE, 0); - widget = gtk_label_new("If you do not input your screen name,"); - container = gtk_alignment_new(0.0, 0.5, 0.0, 0.0); - gtk_container_add(GTK_CONTAINER(container), widget); - gtk_alignment_set_padding(GTK_ALIGNMENT(container), 20, 0, 20, 0); - gtk_box_pack_start(GTK_BOX(line), container, FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(child), line, FALSE, FALSE, 0); - - line = gtk_hbox_new(FALSE, 0); - widget = gtk_label_new("you cannot see your icon."); - container = gtk_alignment_new(0.0, 0.5, 0.0, 0.0); - gtk_container_add(GTK_CONTAINER(container), widget); - gtk_alignment_set_padding(GTK_ALIGNMENT(container), 0, 0, 20, 0); - gtk_box_pack_start(GTK_BOX(line), line, FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(child), container, FALSE, FALSE, 0); - - /***************/ - /* create page */ - /***************/ - tab_label = gtk_label_new("Screen Name"); - gtk_notebook_append_page(GTK_NOTEBOOK(notebook), child, tab_label); + + return GTK_WIDGET(gtk_builder_get_object( + builder, "account_preference_default")); } -static void -build_twitter_api_preference_form(PurpleConversation *conv, - GtkWidget *notebook) +static GtkWidget* +build_twitter_preference_form(PurpleConversation *conv) { PurpleAccount *account = purple_conversation_get_account(conv); const char *conv_name = purple_conversation_get_name(conv); - - GtkWidget *tab_label, *child, *line, *container, *widget; + GtkWidget *widget; GtkObject *adjust; int value; - - child = gtk_vbox_new(FALSE, 0); - - /*****************************/ + gchar *filename; + GError *err = NULL; + GtkBuilder *builder = gtk_builder_new(); + +#ifdef _WIN32 + filename = g_build_filename(purple_user_dir(), + "pidgin-twitter", "prefs.ui", NULL); +#else + filename = g_build_filename(DATADIR, + "pidgin-twitter", "prefs.ui", NULL); +#endif + + gtk_builder_add_from_file(builder, filename, &err); + if(err) { + twitter_debug("%s\n", err->message); + g_free(filename); + return NULL; + } + gtk_builder_connect_signals(builder, NULL); + + /**********************/ + /* connect to signals */ + /**********************/ + + /* screen name */ + widget = GTK_WIDGET(gtk_builder_get_object(builder, "twitter_screen_name")); + gtk_entry_set_text(GTK_ENTRY(widget), + service_account_get_string(account, + conv_name, + OPT_SCREEN_NAME, + EMPTY)); + gtk_entry_set_activates_default(GTK_ENTRY(widget), TRUE); + g_object_set_data(G_OBJECT(widget), + PLUGIN_ID "-account_pref-key", + OPT_SCREEN_NAME); + g_signal_connect(G_OBJECT(widget), + "changed", + G_CALLBACK(account_preference_text_changed_cb), + conv); + /* Checkbox about to use API */ - /*****************************/ - - line = gtk_hbox_new(TRUE, 0); - widget = gtk_check_button_new_with_label("Get/post statuses via API"); + widget = GTK_WIDGET(gtk_builder_get_object(builder, "twitter_api")); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), service_account_get_bool(account, conv_name, @@ -3099,27 +3109,10 @@ "toggled", G_CALLBACK(account_preference_bool_toggled_cb), conv); - container = gtk_alignment_new(0.0, 0.5, 0.0, 0.0); - gtk_container_add(GTK_CONTAINER(container), widget); - gtk_alignment_set_padding(GTK_ALIGNMENT(container), 0, 0, 20, 0); - gtk_box_pack_start_defaults(GTK_BOX(line), container); - - gtk_box_pack_start_defaults(GTK_BOX(child), line); - - /*****************/ - /* Password Form */ - /*****************/ - - /* label */ - line = gtk_hbox_new(TRUE, 0); - widget = gtk_label_new("Password"); - container = gtk_alignment_new(0.0, 0.5, 0.0, 0.0); - gtk_container_add(GTK_CONTAINER(container), widget); - gtk_alignment_set_padding(GTK_ALIGNMENT(container), 0, 0, 20, 0); - gtk_box_pack_start_defaults(GTK_BOX(line), container); - - /* entry */ - widget = gtk_entry_new(); + + /* Password */ + widget = GTK_WIDGET(gtk_builder_get_object(builder, + "twitter_api_password")); gtk_entry_set_visibility(GTK_ENTRY(widget), FALSE); gtk_entry_set_activates_default(GTK_ENTRY(widget), TRUE); if (gtk_entry_get_invisible_char(GTK_ENTRY(widget)) == '*') @@ -3136,26 +3129,8 @@ "changed", G_CALLBACK(account_preference_text_changed_cb), conv); - container = gtk_alignment_new(1.0, 0.5, 1.0, 0.0); - gtk_container_add(GTK_CONTAINER(container), widget); - gtk_alignment_set_padding(GTK_ALIGNMENT(container), 0, 0, 0, 20); - gtk_box_pack_start_defaults(GTK_BOX(line), container); - - gtk_box_pack_start_defaults(GTK_BOX(child), line); - - /**************************/ - /* Retrieve interval Form */ - /**************************/ - - /* label */ - line = gtk_hbox_new(FALSE, 0); - widget = gtk_label_new("Retrieve interval"); - container = gtk_alignment_new(0.0, 0.5, 0.0, 0.0); - gtk_container_add(GTK_CONTAINER(container), widget); - gtk_alignment_set_padding(GTK_ALIGNMENT(container), 0, 0, 20, 0); - gtk_box_pack_start_defaults(GTK_BOX(line), container); - - /* spin button */ + + /* Retrieve interval */ value = service_account_get_int(account, conv_name, OPT_API_BASE_GET_INTERVAL, 0); @@ -3167,7 +3142,10 @@ value); } adjust = gtk_adjustment_new(value, 40, 3600, 10, 100, 100); - widget = gtk_spin_button_new(GTK_ADJUSTMENT(adjust), 1.0, 0); + widget = GTK_WIDGET(gtk_builder_get_object(builder, + "twitter_api_interval")); + gtk_spin_button_set_adjustment(GTK_SPIN_BUTTON(widget), + GTK_ADJUSTMENT(adjust)); gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(widget), TRUE); gtk_spin_button_set_snap_to_ticks(GTK_SPIN_BUTTON(widget), TRUE); g_object_set_data(G_OBJECT(widget), @@ -3177,26 +3155,9 @@ "value-changed", G_CALLBACK(account_preference_spin_changed_cb), conv); - container = gtk_alignment_new(1.0, 0.5, 0.0, 0.0); - gtk_container_add(GTK_CONTAINER(container), widget); - gtk_alignment_set_padding(GTK_ALIGNMENT(container), 0, 0, 0, 0); - gtk_box_pack_start(GTK_BOX(line), container, FALSE, FALSE, 0); - - /* label */ - widget = gtk_label_new("sec"); - container = gtk_alignment_new(1.0, 0.5, 0.0, 0.0); - gtk_container_add(GTK_CONTAINER(container), widget); - gtk_alignment_set_padding(GTK_ALIGNMENT(container), 0, 0, 0, 20); - gtk_box_pack_start(GTK_BOX(line), container, FALSE, FALSE, 0); - - gtk_box_pack_start_defaults(GTK_BOX(child), line); - - /***************/ - /* create page */ - /***************/ - - tab_label = gtk_label_new("API Based Access"); - gtk_notebook_append_page(GTK_NOTEBOOK(notebook), child, tab_label); + + return GTK_WIDGET(gtk_builder_get_object(builder, + "account_preference_twitter")); } static void @@ -3300,8 +3261,6 @@ if(purple_prefs_exists(key)) return; - twitter_debug("eeeee : %s\n", key); - names = g_strsplit(key, "/", 0); names_length = g_strv_length(names);
--- a/pidgin-twitter.h Tue Aug 05 01:26:08 2008 +0900 +++ b/pidgin-twitter.h Tue Aug 05 23:19:09 2008 +0900 @@ -220,8 +220,8 @@ static gint get_service_type(PurpleConversation *conv); static GdkPixbuf *make_scaled_pixbuf(const gchar *url_text, gsize len); static void open_account_preference_window(GtkWidget *called_widged, gpointer gtkconv_ptr); -static void build_screen_name_preference_form(PurpleConversation *conv, GtkWidget *notebook); -static void build_twitter_api_preference_form(PurpleConversation *conv, GtkWidget *notebook); +static GtkWidget* build_default_preference_form(PurpleConversation *conv); +static GtkWidget* build_twitter_preference_form(PurpleConversation *conv); static void destroyed_pref_button_cb(GtkWidget *pref_button, gpointer dialog); static void closed_account_preference_window_cb(GtkDialog *dialog, gint response_id, gpointer pref_button); static void account_preference_text_changed_cb(GtkEditable *editable, gpointer conv_ptr); @@ -229,6 +229,7 @@ static void account_preference_bool_toggled_cb(GtkToggleButton *togglebutton, gpointer conv_ptr); static void account_preference_interval_changed(PurpleAccount *account, const char *conv_name); static void account_preference_spin_changed_cb(GtkSpinButton *spinbutton, gpointer conv_ptr); +static void add_pref(const char *key); static gchar* create_key_with_service_account(PurpleAccount *account, const char *conv_name, const char *key, gboolean create_node); static void service_account_set_string(PurpleAccount *account, const char *conv_name, const char *key, const char *value); static const char* service_account_get_string(PurpleAccount *account, const char *conv_name, const char *key, const char *default_value);
--- a/prefs.ui Tue Aug 05 01:26:08 2008 +0900 +++ b/prefs.ui Tue Aug 05 23:19:09 2008 +0900 @@ -881,4 +881,327 @@ </object> </child> </object> + + <object class="GtkVBox" id="account_preference_default"> + <property name="visible">True</property> + <child> + <object class="GtkHBox" id="hbox10"> + <property name="visible">True</property> + <child> + <object class="GtkAlignment" id="alignment50"> + <property name="visible">True</property> + <property name="left_padding">20</property> + <property name="right_padding">20</property> + <child> + <object class="GtkLabel" id="label20"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">screen name</property> + <property name="max_width_chars">10</property> + </object> + </child> + </object> + </child> + <child> + <object class="GtkAlignment" id="alignment51"> + <property name="visible">True</property> + <property name="xalign">1</property> + <property name="right_padding">4</property> + <child> + <object class="GtkEntry" id="screen_name"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="width_chars">20</property> + </object> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> + </child> + </object> + <packing> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkHBox" id="hbox11"> + <property name="visible">True</property> + <property name="expand">True</property> + <property name="fill">True</property> + <child> + <object class="GtkAlignment" id="alignment52"> + <property name="visible">True</property> + <property name="top_padding">20</property> + <property name="left_padding">20</property> + <child> + <object class="GtkLabel" id="label21"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">If you do not set your screen name,</property> + <property name="max_width_chars">10</property> + </object> + </child> + </object> + </child> + </object> + <packing> + <property name="position">2</property> + </packing> + </child> + <child> + <object class="GtkHBox" id="hbox12"> + <property name="visible">True</property> + <property name="expand">True</property> + <property name="fill">True</property> + <child> + <object class="GtkAlignment" id="alignment53"> + <property name="visible">True</property> + <property name="left_padding">20</property> + <child> + <object class="GtkLabel" id="label22"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">you cannot see your icon.</property> + <property name="max_width_chars">10</property> + </object> + </child> + </object> + </child> + </object> + <packing> + <property name="position">3</property> + </packing> + </child> + </object> + + <object class="GtkVBox" id="account_preference_twitter"> + <property name="visible">True</property> + <child> + <object class="GtkHBox" id="hbox13"> + <property name="visible">True</property> + <child> + <object class="GtkAlignment" id="alignment54"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="left_padding">20</property> + <property name="right_padding">20</property> + <child> + <object class="GtkLabel" id="label23"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">screen name</property> + <property name="max_width_chars">10</property> + </object> + </child> + </object> + </child> + <child> + <object class="GtkAlignment" id="alignment55"> + <property name="visible">True</property> + <property name="xalign">1</property> + <property name="right_padding">4</property> + <child> + <object class="GtkEntry" id="twitter_screen_name"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="width_chars">20</property> + </object> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> + </child> + </object> + <packing> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkHBox" id="hbox14"> + <property name="visible">True</property> + <child> + <object class="GtkAlignment" id="alignment56"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="top_padding">20</property> + <property name="left_padding">20</property> + <child> + <object class="GtkLabel" id="label24"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">If you do not set your screen name,</property> + <property name="max_width_chars">10</property> + </object> + </child> + </object> + </child> + </object> + <packing> + <property name="position">2</property> + </packing> + </child> + <child> + <object class="GtkHBox" id="hbox15"> + <property name="visible">True</property> + <child> + <object class="GtkAlignment" id="alignment57"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="left_padding">20</property> + <child> + <object class="GtkLabel" id="label25"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">you cannot see your icon.</property> + <property name="max_width_chars">10</property> + </object> + </child> + </object> + </child> + </object> + <packing> + <property name="position">3</property> + </packing> + </child> + <child> + <object class="GtkAlignment" id="alignment58"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="top_padding">20</property> + <property name="left_padding">20</property> + <child> + <object class="GtkCheckButton" id="twitter_api"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="label" translatable="yes">Get/post statuses via API</property> + <property name="response_id">0</property> + <property name="draw_indicator">True</property> + </object> + </child> + </object> + <packing> + <property name="position">4</property> + </packing> + </child> + <child> + <object class="GtkHBox" id="hbox16"> + <property name="visible">True</property> + <child> + <object class="GtkAlignment" id="alignment59"> + <property name="visible">True</property> + <property name="left_padding">40</property> + <child> + <object class="GtkLabel" id="label26"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">Password</property> + <property name="max_width_chars">10</property> + </object> + </child> + </object> + <packing> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkAlignment" id="alignment60"> + <property name="visible">True</property> + <property name="xalign">1</property> + <property name="right_padding">4</property> + <child> + <object class="GtkEntry" id="twitter_api_password"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="width_chars">20</property> + </object> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="pack_type">GTK_PACK_END</property> + <property name="position">1</property> + </packing> + </child> + </object> + <packing> + <property name="position">5</property> + </packing> + </child> + <child> + <object class="GtkHBox" id="hbox17"> + <property name="visible">True</property> + <child> + <object class="GtkAlignment" id="alignment61"> + <property name="visible">True</property> + <property name="top_padding">2</property> + <property name="bottom_padding">10</property> + <property name="left_padding">40</property> + <child> + <object class="GtkLabel" id="label27"> + <property name="visible">True</property> + <property name="label" translatable="yes">Retrieve interval</property> + </object> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + </packing> + </child> + <child> + <object class="GtkAlignment" id="alignment62"> + <property name="visible">True</property> + <property name="top_padding">2</property> + <property name="bottom_padding">10</property> + <property name="right_padding">4</property> + <child> + <object class="GtkSpinButton" id="twitter_api_interval"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="climb_rate">1</property> + <property name="snap_to_ticks">True</property> + <property name="numeric">True</property> + </object> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="pack_type">GTK_PACK_END</property> + <property name="position">2</property> + </packing> + </child> + <child> + <object class="GtkAlignment" id="alignment63"> + <property name="visible">True</property> + <property name="bottom_padding">10</property> + <property name="right_padding">8</property> + <child> + <object class="GtkLabel" id="label28"> + <property name="visible">True</property> + <property name="label" translatable="yes">sec</property> + </object> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="pack_type">GTK_PACK_END</property> + <property name="position">1</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="position">6</property> + </packing> + </child> + </object> + </interface>