changeset 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 09bcb6ee5eb5
files Makefile.in configure.in pidgin-twitter.c
diffstat 3 files changed, 285 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile.in	Sat Jul 19 11:33:17 2008 +0900
+++ b/Makefile.in	Mon Jul 21 10:40:55 2008 +0900
@@ -2,17 +2,17 @@
 SRC = pidgin-twitter.c
 HDR = ${SRC:.c=.h}
 
+PIDGIN_PLUGIN_DIR = @PIDGIN_PREFIX@/lib/pidgin
+PIDGIN_DATA_DIR = @PIDGIN_DATA_DIR@
+
 PIDGIN_CFLAGS = @PIDGIN_CFLAGS@
 GLIB_CFLAGS = @GLIB_CFLAGS@
 XML_CFLAGS = @XML_CFLAGS@
-CFLAGS = -fPIC -shared -Wall $(PIDGIN_CFLAGS) $(GLIB_CFLAGS) $(XML_CFLAGS)
+CFLAGS = -fPIC -shared -Wall $(PIDGIN_CFLAGS) $(GLIB_CFLAGS) $(XML_CFLAGS) -DDATADIR=\"$(PIDGIN_DATA_DIR)\"
 
 GLIB_LIBS = @GLIB_LIBS@
 LDFLAGS = $(GLIB_LIBS) $(XML_LIBS)
 
-PIDGIN_PLUGIN_DIR = @PIDGIN_PREFIX@/lib/pidgin
-
-
 all: $(OBJECTIVE)
 
 
@@ -22,7 +22,7 @@
 
 install: $(OBJECTIVE)
 	install -m 755 $(OBJECTIVE) $(PIDGIN_PLUGIN_DIR)
-
+	install -D -m 644 prefs.ui $(PIDGIN_DATA_DIR)/pidgin-twitter/prefs.ui
 
 clean:
 	rm -f $(OBJECTIVE)
--- a/configure.in	Sat Jul 19 11:33:17 2008 +0900
+++ b/configure.in	Mon Jul 21 10:40:55 2008 +0900
@@ -9,6 +9,13 @@
 AC_PROG_CC
 
 # Checks for libraries.
+PKG_CHECK_MODULES(GTK, [gtk+-2.0 >= 2.12.0], , [
+        AC_MSG_RESULT(no)
+        AC_MSG_ERROR([
+
+You must have gtk+-2.0 >= 2.12.0 development headers installed to build.
+])])
+
 PKG_CHECK_MODULES(GLIB, [glib-2.0 >= 2.14.0], , [
         AC_MSG_RESULT(no)
         AC_MSG_ERROR([
@@ -23,14 +30,15 @@
 AC_SUBST(GLIB_LIBS)
 AC_SUBST(GLIB_LIB_DIR)
 
-PKG_CHECK_MODULES(PIDGIN, [pidgin >= 2.0.0], , [
+PKG_CHECK_MODULES(PIDGIN, [pidgin >= 2.4.0], , [
         AC_MSG_RESULT(no)
         AC_MSG_ERROR([
 
-You must have pidgin >= 2.0.0 development headers installed to build.
+You must have pidgin >= 2.4.0 development headers installed to build.
 ])])
 PIDGIN_CFLAGS=`pkg-config --cflags pidgin 2> /dev/null`
 PIDGIN_LIBS=`pkg-config --libs pidgin 2> /dev/null`
+PIDGIN_DATA_DIR=`pkg-config --variable=datadir pidgin 2> /dev/null`
 if test x"$prefix" = x"NONE" ; then
 	PIDGIN_PREFIX=`pkg-config --variable=prefix pidgin 2> /dev/null`
 else
@@ -39,6 +47,7 @@
 AC_SUBST(PIDGIN_CFLAGS)
 AC_SUBST(PIDGIN_LIBS)
 AC_SUBST(PIDGIN_PREFIX)
+AC_SUBST(PIDGIN_DATA_DIR)
 
 PKG_CHECK_MODULES(GLIB, [libxml-2.0 >= 2.6.27], , [
         AC_MSG_RESULT(no)
--- a/pidgin-twitter.c	Sat Jul 19 11:33:17 2008 +0900
+++ b/pidgin-twitter.c	Mon Jul 21 10:40:55 2008 +0900
@@ -2390,6 +2390,254 @@
                          (GHFunc)invalidate_icon_data_func, NULL);
 }
 
+static void
+text_changed_cb(gpointer *data)
+{
+    const gchar *text;
+    gchar *pref = (gchar *)g_object_get_data(G_OBJECT(data), "pref");
+    text = gtk_entry_get_text(GTK_ENTRY(data));
+    purple_prefs_set_string(pref, text);
+}
+
+static void
+bool_toggled_cb(gpointer *data)
+{
+    gchar *pref = (gchar *)g_object_get_data(G_OBJECT(data), "pref");
+    gboolean value = purple_prefs_get_bool(pref);
+    purple_prefs_set_bool(pref, !value);
+}
+
+static void
+spin_changed_cb(gpointer *data)
+{
+    gchar *pref = (gchar *)g_object_get_data(G_OBJECT(data), "pref");
+
+    twitter_debug("called\n");
+
+    purple_prefs_set_int(
+        pref,
+        gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(data)));
+}
+
+static void
+combo_changed_cb(gpointer *data)
+{
+    gint position;
+    gchar *pref = (gchar *)g_object_get_data(G_OBJECT(data), "pref");
+    position = gtk_combo_box_get_active(GTK_COMBO_BOX(data));
+    purple_prefs_set_int(pref, position);
+}
+
+static GtkWidget *
+prefs_get_frame(PurplePlugin *plugin)
+{
+    GtkBuilder *builder;
+    GError *err = NULL;
+    gchar *filename;
+    GtkWidget *window, *notebook, *e;
+    const gchar *text;
+    int i;
+
+    builder = gtk_builder_new();
+
+    filename = g_build_filename(DATADIR, "pidgin-twitter", "prefs.ui", NULL);
+    gtk_builder_add_from_file(builder, filename, &err);
+    if(err) {
+        twitter_debug("%s\n", err->message);
+        return NULL;
+    }
+
+    g_free(filename);
+
+    gtk_builder_connect_signals(builder, NULL);
+
+    window = GTK_WIDGET(gtk_builder_get_object(builder, "prefswindow"));
+    notebook = GTK_WIDGET(gtk_builder_get_object(builder, "prefsnotebook"));
+
+    gtk_container_remove(GTK_CONTAINER(window), notebook);
+
+    g_signal_connect(notebook, "destroy",
+                     G_CALLBACK(gtk_widget_destroyed), &notebook);
+
+    /* connect to signals */
+
+    /* account page */
+    e = GTK_WIDGET(gtk_builder_get_object (builder, "account_twitter"));
+    g_object_set_data(G_OBJECT(e), "pref", OPT_SCREEN_NAME_TWITTER);
+    text = purple_prefs_get_string(OPT_SCREEN_NAME_TWITTER);
+    gtk_entry_set_text(GTK_ENTRY(e), text);
+    g_signal_connect(e, "changed",
+                     G_CALLBACK(text_changed_cb), &e);
+
+    e = GTK_WIDGET(gtk_builder_get_object (builder, "account_wassr"));
+    g_object_set_data(G_OBJECT(e), "pref", OPT_SCREEN_NAME_WASSR);
+    text = purple_prefs_get_string(OPT_SCREEN_NAME_WASSR);
+    gtk_entry_set_text(GTK_ENTRY(e), text);
+    g_signal_connect(e, "changed",
+                     G_CALLBACK(text_changed_cb), &e);
+
+    e = GTK_WIDGET(gtk_builder_get_object (builder, "account_identica"));
+    g_object_set_data(G_OBJECT(e), "pref", OPT_SCREEN_NAME_IDENTICA);
+    text = purple_prefs_get_string(OPT_SCREEN_NAME_IDENTICA);
+    gtk_entry_set_text(GTK_ENTRY(e), text);
+    g_signal_connect(e, "changed",
+                     G_CALLBACK(text_changed_cb), &e);
+
+    e = GTK_WIDGET(gtk_builder_get_object (builder, "account_api"));
+    g_object_set_data(G_OBJECT(e), "pref", OPT_API_BASE_POST);
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(e),
+                                 purple_prefs_get_bool(OPT_API_BASE_POST));
+    g_signal_connect(e, "toggled",
+                     G_CALLBACK(bool_toggled_cb), &e);
+
+    purple_prefs_connect_callback(plugin, OPT_API_BASE_POST, // xxx devide?
+                                  api_base_post_cb, NULL);
+
+    e = GTK_WIDGET(gtk_builder_get_object (builder, "account_api_password"));
+    g_object_set_data(G_OBJECT(e), "pref", OPT_PASSWORD_TWITTER);
+    text = purple_prefs_get_string(OPT_PASSWORD_TWITTER); //xxx should be masked
+    gtk_entry_set_text(GTK_ENTRY(e), text);
+    g_signal_connect(e, "changed",
+                     G_CALLBACK(text_changed_cb), &e);
+
+    /* translation page */
+    e = GTK_WIDGET(gtk_builder_get_object (builder, "translation_recipient"));
+    g_object_set_data(G_OBJECT(e), "pref", OPT_TRANSLATE_RECIPIENT);
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(e),
+                                 purple_prefs_get_bool(OPT_TRANSLATE_RECIPIENT));
+    g_signal_connect(e, "toggled",
+                     G_CALLBACK(bool_toggled_cb), &e);
+
+    e = GTK_WIDGET(gtk_builder_get_object (builder, "translation_sender"));
+    g_object_set_data(G_OBJECT(e), "pref", OPT_TRANSLATE_SENDER);
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(e),
+                                 purple_prefs_get_bool(OPT_TRANSLATE_SENDER));
+    g_signal_connect(e, "toggled",
+                     G_CALLBACK(bool_toggled_cb), &e);
+
+    e = GTK_WIDGET(gtk_builder_get_object (builder, "translation_channel"));
+    g_object_set_data(G_OBJECT(e), "pref", OPT_TRANSLATE_CHANNEL);
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(e),
+                                 purple_prefs_get_bool(OPT_TRANSLATE_CHANNEL));
+    g_signal_connect(e, "toggled",
+                     G_CALLBACK(bool_toggled_cb), &e);
+
+    /* utility page */
+    e = GTK_WIDGET(gtk_builder_get_object (builder, "utility_show_icon"));
+    g_object_set_data(G_OBJECT(e), "pref", OPT_SHOW_ICON);
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(e),
+                                 purple_prefs_get_bool(OPT_SHOW_ICON));
+    g_signal_connect(e, "toggled",
+                     G_CALLBACK(bool_toggled_cb), &e);
+    purple_prefs_connect_callback(plugin, OPT_ICON_SIZE, //xxx 
+                                  icon_size_prefs_cb, NULL);
+
+    /* setup spin */
+    e = GTK_WIDGET(gtk_builder_get_object (builder, "utility_icon_size_spin"));
+    g_object_set_data(G_OBJECT(e), "pref", OPT_ICON_SIZE);
+
+    GtkSpinButton *spin = GTK_SPIN_BUTTON(e);
+
+    int value = purple_prefs_get_int(OPT_ICON_SIZE);
+    twitter_debug("spin value = %d\n", value);
+
+	GtkAdjustment *adjust = gtk_adjustment_new(value, 16, 128, 4, 1, 1);
+    gtk_spin_button_set_adjustment(spin, adjust);
+    gtk_widget_set_size_request(spin, 50, -1);
+
+    if(value == 0) {
+        value = DEFAULT_ICON_SIZE;
+        purple_prefs_set_int(OPT_ICON_SIZE, value);
+    }
+    gtk_spin_button_set_value(GTK_SPIN_BUTTON(e), (gdouble)value);
+    g_signal_connect(e, "value-changed",
+                     G_CALLBACK(spin_changed_cb), &e);
+
+
+
+    e = GTK_WIDGET(gtk_builder_get_object (builder, "utility_counter"));
+    g_object_set_data(G_OBJECT(e), "pref", OPT_COUNTER);
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(e),
+                                 purple_prefs_get_bool(OPT_COUNTER));
+    g_signal_connect(e, "toggled",
+                     G_CALLBACK(bool_toggled_cb), &e);
+    purple_prefs_connect_callback(plugin, OPT_COUNTER, //xxx
+                                  counter_prefs_cb, NULL);
+
+    e = GTK_WIDGET(gtk_builder_get_object (builder, "utility_pseudo"));
+    g_object_set_data(G_OBJECT(e), "pref", OPT_ESCAPE_PSEUDO);
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(e),
+                                 purple_prefs_get_bool(OPT_ESCAPE_PSEUDO));
+    g_signal_connect(e, "toggled",
+                     G_CALLBACK(bool_toggled_cb), &e);
+
+    e = GTK_WIDGET(gtk_builder_get_object (builder, "utility_oops"));
+    g_object_set_data(G_OBJECT(e), "pref", OPT_SUPPRESS_OOPS);
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(e),
+                                 purple_prefs_get_bool(OPT_SUPPRESS_OOPS));
+    g_signal_connect(e, "toggled",
+                     G_CALLBACK(bool_toggled_cb), &e);
+
+    e = GTK_WIDGET(gtk_builder_get_object (builder, "utility_notify"));
+    g_object_set_data(G_OBJECT(e), "pref", OPT_PREVENT_NOTIFICATION);
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(e),
+                                 purple_prefs_get_bool(OPT_PREVENT_NOTIFICATION));
+    g_signal_connect(e, "toggled",
+                     G_CALLBACK(bool_toggled_cb), &e);
+
+
+    /* sound page */
+    e = GTK_WIDGET(gtk_builder_get_object (builder, "sound_recip_check"));
+    g_object_set_data(G_OBJECT(e), "pref", OPT_PLAYSOUND_RECIPIENT);
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(e),
+                                 purple_prefs_get_bool(OPT_PLAYSOUND_RECIPIENT));
+    g_signal_connect(e, "toggled",
+                     G_CALLBACK(bool_toggled_cb), &e);
+
+    e = GTK_WIDGET(gtk_builder_get_object (builder, "sound_recip_list"));
+    g_object_set_data(G_OBJECT(e), "pref", OPT_USERLIST_RECIPIENT);
+    text = purple_prefs_get_string(OPT_USERLIST_RECIPIENT);
+    gtk_entry_set_text(GTK_ENTRY(e), text);
+    g_signal_connect(e, "changed",
+                     G_CALLBACK(text_changed_cb), &e);
+
+    /* setup combobox */
+    e = GTK_WIDGET(gtk_builder_get_object (builder, "sound_recip_combo"));
+    gtk_combo_box_set_active(GTK_COMBO_BOX(e),
+                             purple_prefs_get_int(OPT_SOUNDID_RECIPIENT));
+    g_object_set_data(G_OBJECT(e), "pref", OPT_SOUNDID_RECIPIENT);
+    g_signal_connect(e, "changed",
+                     G_CALLBACK(combo_changed_cb), &e);
+
+
+
+    e = GTK_WIDGET(gtk_builder_get_object (builder, "sound_send_check"));
+    g_object_set_data(G_OBJECT(e), "pref", OPT_PLAYSOUND_SENDER);
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(e),
+                                 purple_prefs_get_bool(OPT_PLAYSOUND_SENDER));
+    g_signal_connect(e, "toggled",
+                     G_CALLBACK(bool_toggled_cb), &e);
+
+    e = GTK_WIDGET(gtk_builder_get_object (builder, "sound_send_list"));
+    g_object_set_data(G_OBJECT(e), "pref", OPT_USERLIST_SENDER);
+    text = purple_prefs_get_string(OPT_USERLIST_SENDER);
+    gtk_entry_set_text(GTK_ENTRY(e), text);
+    g_signal_connect(e, "changed",
+                     G_CALLBACK(text_changed_cb), &e);
+
+    /* setup combobox */
+    e = GTK_WIDGET(gtk_builder_get_object (builder, "sound_send_combo"));
+    gtk_combo_box_set_active(GTK_COMBO_BOX(e),
+                             purple_prefs_get_int(OPT_SOUNDID_RECIPIENT));
+    g_object_set_data(G_OBJECT(e), "pref", OPT_SOUNDID_SENDER);
+    g_signal_connect(e, "changed",
+                     G_CALLBACK(combo_changed_cb), &e);
+
+
+    gtk_widget_show_all(notebook);
+    return notebook;
+}
+
 static PurplePluginPrefFrame *
 get_plugin_pref_frame(PurplePlugin *plugin)
 {
@@ -2510,7 +2758,7 @@
     purple_plugin_pref_add_choice(pref, "Arrive", GINT_TO_POINTER(0));
     purple_plugin_pref_add_choice(pref, "Leave", GINT_TO_POINTER(1));
     purple_plugin_pref_add_choice(pref, "Receive", GINT_TO_POINTER(2));
-    purple_plugin_pref_add_choice(pref, "Fist Receive", GINT_TO_POINTER(3));
+    purple_plugin_pref_add_choice(pref, "First Receive", GINT_TO_POINTER(3));
     purple_plugin_pref_add_choice(pref, "Send", GINT_TO_POINTER(4));
     purple_plugin_pref_add_choice(pref, "Chat Join", GINT_TO_POINTER(5));
     purple_plugin_pref_add_choice(pref, "Chat Leave", GINT_TO_POINTER(6));
@@ -2540,7 +2788,7 @@
     purple_plugin_pref_add_choice(pref, "Arrive", GINT_TO_POINTER(0));
     purple_plugin_pref_add_choice(pref, "Leave", GINT_TO_POINTER(1));
     purple_plugin_pref_add_choice(pref, "Receive", GINT_TO_POINTER(2));
-    purple_plugin_pref_add_choice(pref, "Fist Receive", GINT_TO_POINTER(3));
+    purple_plugin_pref_add_choice(pref, "First Receive", GINT_TO_POINTER(3));
     purple_plugin_pref_add_choice(pref, "Send", GINT_TO_POINTER(4));
     purple_plugin_pref_add_choice(pref, "Chat Join", GINT_TO_POINTER(5));
     purple_plugin_pref_add_choice(pref, "Chat Leave", GINT_TO_POINTER(6));
@@ -2573,16 +2821,28 @@
     return frame;
 }
 
+#if 0
 static PurplePluginUiInfo pref_info = {
     get_plugin_pref_frame
 };
+#endif
+
+static PidginPluginUiInfo ui_info = {
+    prefs_get_frame,
+	0,									/* page number - reserved	*/
+	NULL,								/* reserved 1	*/
+	NULL,								/* reserved 2	*/
+	NULL,								/* reserved 3	*/
+	NULL								/* reserved 4	*/
+};
 
 static PurplePluginInfo info = {
     PURPLE_PLUGIN_MAGIC,
     PURPLE_MAJOR_VERSION,
     PURPLE_MINOR_VERSION,
     PURPLE_PLUGIN_STANDARD,     /**< type	*/
-    NULL,                       /**< ui_req	*/
+//    NULL,                       /**< ui_req	*/
+	PIDGIN_PLUGIN_TYPE,                       /**< ui_req	*/
     0,                          /**< flags	*/
     NULL,                       /**< deps	*/
     PURPLE_PRIORITY_DEFAULT,    /**< priority	*/
@@ -2596,9 +2856,15 @@
     load_plugin,                /**< load	*/
     unload_plugin,              /**< unload	*/
     NULL,                       /**< destroy	*/
+#if 0
     NULL,                       /**< ui_info	*/
     NULL,                       /**< extra_info	*/
     &pref_info,                 /**< pref info	*/
+#else
+    &ui_info,                    /**< ui_info	*/
+    NULL,                       /**< extra_info	*/
+    NULL,                       /**< pref info	*/
+#endif
     NULL
 };