changeset 239:e3a24c98772d

added a new feature that strips excessive consecutive new line characters.
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Tue, 07 Oct 2008 14:51:22 +0900
parents 2e431c7062f2
children 405f8b880142
files pidgin-twitter.c pidgin-twitter.h prefs.ui
diffstat 3 files changed, 144 insertions(+), 109 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin-twitter.c	Mon Sep 29 22:51:25 2008 +0900
+++ b/pidgin-twitter.c	Tue Oct 07 14:51:22 2008 +0900
@@ -24,7 +24,7 @@
 /***********/
 /* globals */
 /***********/
-#define NUM_REGPS 11
+#define NUM_REGPS 12
 #define NUM_SERVICES 3          /* twitter, wassr, identica. */
 static GRegex *regp[NUM_REGPS];
 static gboolean suppress_oops = FALSE;
@@ -962,6 +962,9 @@
         g_free(match);
         g_free(link);
     }
+    else if(which == EXCESS_LF) {
+        g_snprintf(sub, SUBST_BUF_SIZE, "%s", "\n\n");
+    }
 
     g_string_append(result, sub);
     twitter_debug("sub = %s\n", sub);
@@ -970,16 +973,14 @@
 }
 
 static void
-translate(gchar **str, gint which, gint service)
+translate(gchar **str, gint regp_id, gint service)
 {
     gchar *newstr;
     eval_data *data = g_new0(eval_data, 1);
-    gint regp_id;
-
-    data->which = which;
+
+    data->which = regp_id;
     data->service = service;
 
-    regp_id = which; /* for future use --yaz */
     newstr = g_regex_replace_eval(regp[regp_id],  /* compiled regex */
                                   *str,  /* subject string */
                                   -1,    /* length of the subject string */
@@ -991,7 +992,7 @@
 
     g_free(data); data = NULL;
 
-    twitter_debug("which = %d *str = %s newstr = %s\n", which, *str, newstr);
+    twitter_debug("which = %d *str = %s newstr = %s\n", regp_id, *str, newstr);
 
     g_free(*str);
     *str = newstr;
@@ -1110,6 +1111,10 @@
         escape(buffer);
     }
 
+    if(purple_prefs_get_bool(OPT_STRIP_EXCESS_LF)) {
+        translate(buffer, EXCESS_LF, service);
+    }
+
     return FALSE;
 }
 
@@ -2611,6 +2616,7 @@
     regp[IMAGE_IDENTICA] = g_regex_new(P_IMAGE_IDENTICA, 0, 0, NULL);
     regp[TAG_IDENTICA]   = g_regex_new(P_TAG_IDENTICA, 0, 0, NULL);
     regp[SIZE_128_WASSR] = g_regex_new(P_SIZE_128_WASSR, 0, 0, NULL);
+    regp[EXCESS_LF] = g_regex_new(P_EXCESS_LF, 0, 0, NULL);
 
     for(i = twitter_service; i < NUM_SERVICES; i++) {
         icon_hash[i] = g_hash_table_new_full(g_str_hash, g_str_equal,
@@ -3185,6 +3191,13 @@
     g_signal_connect(e, "toggled",
                      G_CALLBACK(bool_toggled_cb), &e);
 
+    e = GTK_WIDGET(gtk_builder_get_object (builder, "utility_strip_excess_lf"));
+    g_object_set_data(G_OBJECT(e), "pref", OPT_STRIP_EXCESS_LF);
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(e),
+                                 purple_prefs_get_bool(OPT_STRIP_EXCESS_LF));
+    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),
@@ -3256,6 +3269,7 @@
     purple_prefs_add_bool(OPT_TRANSLATE_SENDER, TRUE);
     purple_prefs_add_bool(OPT_TRANSLATE_CHANNEL, TRUE);
     purple_prefs_add_bool(OPT_ESCAPE_PSEUDO, TRUE);
+    purple_prefs_add_bool(OPT_STRIP_EXCESS_LF, TRUE);
 
     purple_prefs_add_bool(OPT_PLAYSOUND_RECIPIENT, TRUE);
     purple_prefs_add_bool(OPT_PLAYSOUND_SENDER, TRUE);
--- a/pidgin-twitter.h	Mon Sep 29 22:51:25 2008 +0900
+++ b/pidgin-twitter.h	Tue Oct 07 14:51:22 2008 +0900
@@ -36,7 +36,8 @@
     IMAGE_WASSR,
     IMAGE_IDENTICA,
     TAG_IDENTICA,
-    SIZE_128_WASSR
+    SIZE_128_WASSR,
+    EXCESS_LF
 };
 
 /* service id */
@@ -124,6 +125,7 @@
 #define OPT_FILTER_TWITTER      OPT_PIDGINTWITTER "/filter_twitter"
 #define OPT_FILTER_WASSR        OPT_PIDGINTWITTER "/filter_wassr"
 #define OPT_FILTER_IDENTICA     OPT_PIDGINTWITTER "/filter_identica"
+#define OPT_STRIP_EXCESS_LF     OPT_PIDGINTWITTER "/strip_excess_lf"
 
 #ifdef _WIN32
 #define OPT_PIDGIN_BLINK_IM     PIDGIN_PREFS_ROOT "/win32/blink_im"
@@ -153,9 +155,10 @@
 #define P_CHANNEL           "^(.*?(?:<a .+?>)?[-A-Za-z0-9_]+(?:</a>)?: \\r?\\n?#)([A-Za-z0-9_]+) "
 #define P_IMAGE_TWITTER     "<a href=\"/account/profile_image/.+?\"><img .+? id=\"profile-image\".*src=\"(http://.+)\" .+?/>"
 #define P_IMAGE_WASSR       "<div class=\"image\"><a href=\".+\"><img src=\"(.+)\" width=\".+?\" /></a></div>"
+#define P_SIZE_128_WASSR    "\\.128\\."
 #define P_IMAGE_IDENTICA    "<img src=\"(http://.+.identi.ca/.+)\" class=\"avatar profile\" width=\"96\" height=\"96\" alt=\"[A-Za-z0-0_]+\"/>"
 #define P_TAG_IDENTICA      "#([-A-Za-z0-9_]+)"
-#define P_SIZE_128_WASSR    "\\.128\\."
+#define P_EXCESS_LF         "([\\r|\\n]{3,})"
 
 /* twitter API specific macros */
 #define TWITTER_BASE_URL "http://twitter.com"
--- a/prefs.ui	Mon Sep 29 22:51:25 2008 +0900
+++ b/prefs.ui	Tue Oct 07 14:51:22 2008 +0900
@@ -760,17 +760,46 @@
                   <placeholder/>
                 </child>
                 <child>
-                  <object class="GtkAlignment" id="alignment40">
+                  <object class="GtkAlignment" id="alignment18">
                     <property name="visible">True</property>
-                    <property name="left_padding">40</property>
+                    <child>
+                      <placeholder/>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="left_attach">2</property>
+                    <property name="right_attach">3</property>
+                    <property name="x_options"></property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkAlignment" id="alignment16">
+                    <property name="visible">True</property>
                     <child>
-                      <object class="GtkLabel" id="label24">
+                      <placeholder/>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkAlignment" id="alignment45">
+                    <property name="visible">True</property>
+                    <property name="right_padding">20</property>
+                    <child>
+                      <object class="GtkLabel" id="label27">
                         <property name="visible">True</property>
-                        <property name="label" translatable="yes">Icon size</property>
+                        <property name="label" translatable="yes">pixel</property>
                       </object>
                     </child>
                   </object>
                   <packing>
+                    <property name="left_attach">3</property>
+                    <property name="right_attach">4</property>
                     <property name="x_options"></property>
                     <property name="y_options"></property>
                   </packing>
@@ -797,46 +826,17 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkAlignment" id="alignment45">
+                  <object class="GtkAlignment" id="alignment40">
                     <property name="visible">True</property>
-                    <property name="right_padding">20</property>
+                    <property name="left_padding">40</property>
                     <child>
-                      <object class="GtkLabel" id="label27">
+                      <object class="GtkLabel" id="label24">
                         <property name="visible">True</property>
-                        <property name="label" translatable="yes">pixel</property>
+                        <property name="label" translatable="yes">Icon size</property>
                       </object>
                     </child>
                   </object>
                   <packing>
-                    <property name="left_attach">3</property>
-                    <property name="right_attach">4</property>
-                    <property name="x_options"></property>
-                    <property name="y_options"></property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkAlignment" id="alignment16">
-                    <property name="visible">True</property>
-                    <child>
-                      <placeholder/>
-                    </child>
-                  </object>
-                  <packing>
-                    <property name="left_attach">1</property>
-                    <property name="right_attach">2</property>
-                    <property name="y_options"></property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkAlignment" id="alignment18">
-                    <property name="visible">True</property>
-                    <child>
-                      <placeholder/>
-                    </child>
-                  </object>
-                  <packing>
-                    <property name="left_attach">2</property>
-                    <property name="right_attach">3</property>
                     <property name="x_options"></property>
                     <property name="y_options"></property>
                   </packing>
@@ -927,24 +927,72 @@
                   <placeholder/>
                 </child>
                 <child>
-                  <object class="GtkAlignment" id="alignment52">
+                  <object class="GtkAlignment" id="alignment19">
                     <property name="visible">True</property>
-                    <property name="right_padding">20</property>
                     <child>
-                      <object class="GtkLabel" id="label18">
+                      <placeholder/>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkAlignment" id="alignment50">
+                    <property name="visible">True</property>
+                    <property name="left_padding">40</property>
+                    <child>
+                      <object class="GtkLabel" id="label25">
                         <property name="visible">True</property>
-                        <property name="label" translatable="yes">days</property>
+                        <property name="label" translatable="yes">Update every</property>
                       </object>
                     </child>
                   </object>
                   <packing>
-                    <property name="left_attach">5</property>
-                    <property name="right_attach">6</property>
                     <property name="x_options"></property>
                     <property name="y_options"></property>
                   </packing>
                 </child>
                 <child>
+                  <object class="GtkAlignment" id="alignment51">
+                    <property name="visible">True</property>
+                    <property name="left_padding">4</property>
+                    <child>
+                      <object class="GtkSpinButton" id="icon_max_count_spin">
+                        <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="left_attach">2</property>
+                    <property name="right_attach">3</property>
+                    <property name="x_options"></property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkAlignment" id="alignment53">
+                    <property name="visible">True</property>
+                    <child>
+                      <object class="GtkLabel" id="label3">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">times  or</property>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="left_attach">3</property>
+                    <property name="right_attach">4</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
                   <object class="GtkAlignment" id="alignment54">
                     <property name="visible">True</property>
                     <property name="left_padding">4</property>
@@ -967,71 +1015,23 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkAlignment" id="alignment53">
+                  <object class="GtkAlignment" id="alignment52">
                     <property name="visible">True</property>
+                    <property name="right_padding">20</property>
                     <child>
-                      <object class="GtkLabel" id="label3">
+                      <object class="GtkLabel" id="label18">
                         <property name="visible">True</property>
-                        <property name="label" translatable="yes">times  or</property>
-                      </object>
-                    </child>
-                  </object>
-                  <packing>
-                    <property name="left_attach">3</property>
-                    <property name="right_attach">4</property>
-                    <property name="y_options"></property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkAlignment" id="alignment51">
-                    <property name="visible">True</property>
-                    <property name="left_padding">4</property>
-                    <child>
-                      <object class="GtkSpinButton" id="icon_max_count_spin">
-                        <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>
+                        <property name="label" translatable="yes">days</property>
                       </object>
                     </child>
                   </object>
                   <packing>
-                    <property name="left_attach">2</property>
-                    <property name="right_attach">3</property>
+                    <property name="left_attach">5</property>
+                    <property name="right_attach">6</property>
                     <property name="x_options"></property>
                     <property name="y_options"></property>
                   </packing>
                 </child>
-                <child>
-                  <object class="GtkAlignment" id="alignment50">
-                    <property name="visible">True</property>
-                    <property name="left_padding">40</property>
-                    <child>
-                      <object class="GtkLabel" id="label25">
-                        <property name="visible">True</property>
-                        <property name="label" translatable="yes">Update every</property>
-                      </object>
-                    </child>
-                  </object>
-                  <packing>
-                    <property name="x_options"></property>
-                    <property name="y_options"></property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkAlignment" id="alignment19">
-                    <property name="visible">True</property>
-                    <child>
-                      <placeholder/>
-                    </child>
-                  </object>
-                  <packing>
-                    <property name="left_attach">1</property>
-                    <property name="right_attach">2</property>
-                    <property name="y_options"></property>
-                  </packing>
-                </child>
               </object>
               <packing>
                 <property name="expand">False</property>
@@ -1430,6 +1430,24 @@
               </packing>
             </child>
             <child>
+              <object class="GtkAlignment" id="alignment64">
+                <property name="visible">True</property>
+                <property name="left_padding">20</property>
+                <child>
+                  <object class="GtkCheckButton" id="utility_strip_excess_lf">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="label" translatable="yes">Strip excessive LF characters in a message</property>
+                    <property name="response_id">0</property>
+                    <property name="draw_indicator">True</property>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="position">5</property>
+              </packing>
+            </child>
+            <child>
               <object class="GtkAlignment" id="alignment25">
                 <property name="visible">True</property>
                 <property name="left_padding">20</property>
@@ -1444,7 +1462,7 @@
                 </child>
               </object>
               <packing>
-                <property name="position">5</property>
+                <property name="position">6</property>
               </packing>
             </child>
             <child>
@@ -1463,7 +1481,7 @@
                 </child>
               </object>
               <packing>
-                <property name="position">6</property>
+                <property name="position">7</property>
               </packing>
             </child>
             <child>
@@ -1482,7 +1500,7 @@
                 </child>
               </object>
               <packing>
-                <property name="position">7</property>
+                <property name="position">8</property>
               </packing>
             </child>
           </object>