changeset 40:e60e6cbdc4c4

- added is_twitter_account(). - added function prototypes. - cleanups.
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Mon, 12 May 2008 23:13:29 +0900
parents 2ac81c0afb53
children 0a81ccfa1941
files pidgin-twitter.c
diffstat 1 files changed, 46 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin-twitter.c	Mon May 12 22:22:19 2008 +0900
+++ b/pidgin-twitter.c	Mon May 12 23:13:29 2008 +0900
@@ -66,11 +66,30 @@
 static gboolean suppress_oops = FALSE;
 
 /* prototypes */
-static gboolean is_twitter_conv(PurpleConversation *conv);
-static void attach_to_gtkconv(PidginConversation *gtkconv, gpointer null);
+static void delete_sender_with_link(gchar **str);
+static void escape(gchar **str);
+static gboolean sending_im_cb(PurpleAccount *account, char *recipient, char **buffer, void *data);
+static gboolean eval(const GMatchInfo *match_info, GString *result, gpointer user_data);
+static void translate(gchar **str, int which);
+static void playsound(gchar **str, int which);
+static gboolean writing_im_cb(PurpleAccount *account, char *sender, char **buffer, PurpleConversation *conv, int *flags, void *data);
+static void insert_text_cb(GtkTextBuffer *textbuffer, GtkTextIter *position, gchar *new_text, gint new_text_length, gpointer user_data);
+static void delete_text_cb(GtkTextBuffer *textbuffer, GtkTextIter *start_pos, GtkTextIter *end_pos, gpointer user_data);
+static void detach_from_window(void);
 static void detach_from_gtkconv(PidginConversation *gtkconv, gpointer null);
-static void escape(gchar **str);
+static void attach_to_window(void);
+static void attach_to_gtkconv(PidginConversation *gtkconv, gpointer null);
+static gboolean is_twitter_account(PurpleAccount *account, const char *name);
+static gboolean is_twitter_conv(PurpleConversation *conv);
+static void conv_created_cb(PurpleConversation *conv, gpointer null);
+static gboolean receiving_im_cb(PurpleAccount *account, char **sender, char **buffer, PurpleConversation *conv, PurpleMessageFlags *flags, void *data);
+static gboolean load_plugin(PurplePlugin *plugin);
+static gboolean unload_plugin(PurplePlugin *plugin);
+static void counter_prefs_cb(const char *name, PurplePrefType type, gconstpointer val, gpointer data);
+static PurplePluginPrefFrame *get_plugin_pref_frame(PurplePlugin *plugin);
+static void init_plugin(PurplePlugin *plugin);
 
+/* implementation */
 static void
 delete_sender_with_link(gchar **str)
 {
@@ -135,29 +154,24 @@
 sending_im_cb(PurpleAccount *account, char *recipient, char **buffer,
               void *data)
 {
-    const gchar *proto;
-
     /* check if the message is from twitter */
-    proto = purple_account_get_protocol_id(account);
-    twitter_debug("proto = %s recipient = %s\n",
-                  proto, recipient);
-
-    if(!strcmp(proto, "prpl-jabber") &&
-       !strcmp(recipient, "twitter@twitter.com")) {
+    if(is_twitter_account(account, recipient)) {
         /* escape */
         if(purple_prefs_get_bool(OPT_ESCAPE_PSEUDO)) {
             escape(buffer);
         }
+
         /* strip excessive link from @username */
         delete_sender_with_link(buffer);
 
-        /* try to suppress Oops message */
+        /* try to suppress oops message */
         gint utflen = g_utf8_strlen(*buffer, -1);
         gint bytes = strlen(*buffer);
         twitter_debug("utflen = %d bytes = %d\n", utflen, bytes);
         if(bytes > 140 && utflen <= 140)
             suppress_oops = TRUE;
     }
+
     return FALSE;
 }
 
@@ -242,14 +256,8 @@
 writing_im_cb(PurpleAccount *account, char *sender, char **buffer,
               PurpleConversation *conv, int *flags, void *data)
 {
-    const gchar *proto;
-
     /* check if the message is from twitter */
-    proto = purple_account_get_protocol_id(account);
-    twitter_debug("proto = %s sender = %s\n", proto, sender);
-
-    if(!strcmp(sender, "twitter@twitter.com") &&
-       !strcmp(proto, "prpl-jabber")) {
+    if(is_twitter_account(account, sender)) {
         /* playsound */
         if(purple_prefs_get_bool(OPT_PLAYSOUND_SENDER)) {
             playsound(buffer, SENDER);
@@ -326,12 +334,12 @@
     g_free(markup);
 }
 
-
 static void
 detach_from_window(void)
 {
     GList *list;
 
+    /* find twitter conv window out and detach from that */
     for(list = pidgin_conv_windows_get_list(); list; list = list->next) {
         PidginWindow *win = list->data;
         PurpleConversation *conv =
@@ -377,6 +385,7 @@
 {
     GList *list;
 
+    /* find twitter conv window out and attach to that */
     for(list = pidgin_conv_windows_get_list(); list; list = list->next) {
         PidginWindow *win = list->data;
         PurpleConversation *conv =
@@ -420,19 +429,27 @@
 }
 
 static gboolean
+is_twitter_account(PurpleAccount *account, const char *name)
+{
+    const gchar *proto = purple_account_get_protocol_id(account);
+
+    twitter_debug("name  = %s proto = %s\n", name, proto);
+
+    if(!strcmp(name, "twitter@twitter.com") &&
+       !strcmp(proto, "prpl-jabber")) {
+        return TRUE;
+    }
+
+    return FALSE;
+}
+
+static gboolean
 is_twitter_conv(PurpleConversation *conv)
 {
     const char *name = purple_conversation_get_name(conv);
     PurpleAccount *account = purple_conversation_get_account(conv);
-    const gchar *proto = purple_account_get_protocol_id(account);
 
-    twitter_debug("name  = %s proto = %s\n", name, proto);
-
-    if(!strcmp(name, "twitter@twitter.com") && !strcmp(proto, "prpl-jabber")) {
-        return TRUE;
-    }
-
-    return FALSE;
+    return is_twitter_account(account, name);
 }
 
 static void
@@ -546,7 +563,7 @@
 {
     gboolean enabled = purple_prefs_get_bool(OPT_COUNTER);
     if(enabled) {
-        attach_to_window();     //xxx should check whether already attached or not?
+        attach_to_window();
     }
     else {
         detach_from_window();