[pan2] a few fixes



commit 6873d36ba98b70b492cc84fc1f197042a480d844
Author: Heinrich MÃller <henmull src gnome org>
Date:   Mon Feb 13 19:20:11 2012 +0100

    a few fixes

 pan/data-impl/data-impl.cc     |    7 +-
 pan/gui/pan.cc                 |  117 ++++++++++++----------------
 pan/gui/prefs-ui.cc            |   23 +++++-
 pan/gui/prefs-ui.h             |    2 +-
 pan/usenet-utils/mime-utils.cc |  167 ++++++++++------------------------------
 pan/usenet-utils/mime-utils.h  |    5 +
 6 files changed, 117 insertions(+), 204 deletions(-)
---
diff --git a/pan/data-impl/data-impl.cc b/pan/data-impl/data-impl.cc
index 14424e8..cb94038 100644
--- a/pan/data-impl/data-impl.cc
+++ b/pan/data-impl/data-impl.cc
@@ -131,7 +131,7 @@ DataImpl :: save_state ()
 GnomeKeyringResult
 DataImpl :: password_encrypt (const PasswordData* pw)
 {
-//  g_return_val_if_fail (gnome_keyring_is_available(), GNOME_KEYRING_RESULT_NO_KEYRING_DAEMON);
+  g_return_val_if_fail (pw, GNOME_KEYRING_RESULT_NO_KEYRING_DAEMON);
 
   return (
     gnome_keyring_store_password_sync (
@@ -146,12 +146,13 @@ DataImpl :: password_encrypt (const PasswordData* pw)
 
 }
 
+// TODO use gnome_keyring_memory_new etc
 GnomeKeyringResult
 DataImpl :: password_decrypt (PasswordData* pw) const
 {
 
-  gchar* pwd(0);
-//  g_return_val_if_fail (gnome_keyring_is_available(), GNOME_KEYRING_RESULT_NO_KEYRING_DAEMON);
+  gchar* pwd = NULL;
+  g_return_val_if_fail (pw, GNOME_KEYRING_RESULT_NO_KEYRING_DAEMON);
 
   GnomeKeyringResult ret =
     gnome_keyring_find_password_sync (
diff --git a/pan/gui/pan.cc b/pan/gui/pan.cc
index 48c9674..339ed69 100644
--- a/pan/gui/pan.cc
+++ b/pan/gui/pan.cc
@@ -21,10 +21,6 @@
 #include <config.h>
 #include <signal.h>
 
-#ifdef HAVE_LIBNOTIFY
-  #include <libnotify/notify.h>
-#endif
-
 extern "C" {
   #include <glib/gi18n.h>
   #include "gtk-compat.h"
@@ -41,16 +37,19 @@ extern "C" {
   #include <windows.h>
 #endif
 
-#include <config.h>
-#include <pan/general/debug.h>
-#include <pan/general/log.h>
-#include <pan/general/file-util.h>
-#include <pan/general/worker-pool.h>
+#ifdef HAVE_LIBNOTIFY
+  #include <libnotify/notify.h>
+#endif
 
 #ifdef HAVE_GNUTLS
   #include <pan/tasks/socket-impl-openssl.h>
 #endif
 
+#include <config.h>
+#include <pan/general/debug.h>
+#include <pan/general/log.h>
+#include <pan/general/file-util.h>
+#include <pan/general/worker-pool.h>
 #include <pan/usenet-utils/gpg.h>
 #include <pan/data/cert-store.h>
 #include <pan/tasks/socket-impl-gio.h>
@@ -68,11 +67,6 @@ extern "C" {
 #include "server-ui.h"
 #include "pad.h"
 
-#ifdef HAVE_GKR
-  #include <gnome-keyring-1/gnome-keyring.h>
-  #include <gnome-keyring-1/gnome-keyring-memory.h>
-#endif
-
 //#define DEBUG_LOCALE 1
 //#define DEBUG_PARALLEL 1
 
@@ -201,7 +195,6 @@ namespace
     }
     else
     {
-//      gtk_widget_hide(GTK_WIDGET(window));
       gtk_widget_show (GTK_WIDGET(window));
       gtk_window_deiconify(window);
     }
@@ -243,7 +236,8 @@ namespace
 
     bool n() { return notif_shown; }
 
-    StatusIconListener(GtkStatusIcon * i, GtkWidget* r, Prefs& p, Queue& q, Data& d, bool v) : icon(i), root(r), prefs(p), queue(q), data(d),
+    StatusIconListener(GtkStatusIcon * i, GtkWidget* r, Prefs& p, Queue& q, Data& d, bool v) :
+      icon(i), root(r), prefs(p), queue(q), data(d),
       tasks_active(0), tasks_total(0), minimized(v), notif_shown(false)
     {
       prefs.add_listener(this);
@@ -291,8 +285,11 @@ namespace
                                   "<b>Tasks running:</b> %d\n"
                                   "<b>Total queued:</b> %d\n"
                                   "<b>Speed:</b> %.1f KiBps\n",
-                                  PACKAGE_VERSION, is_online ? "online" : "offline",
-                                  tasks_active, tasks_total, queue.get_speed_KiBps());
+                                  PACKAGE_VERSION,
+                                  is_online ? "online" : "offline",
+                                  tasks_active,
+                                  tasks_total,
+                                  queue.get_speed_KiBps());
 
       gtk_status_icon_set_tooltip_markup(icon, buf);
 
@@ -418,29 +415,6 @@ namespace
 
   static StatusIconListener* _status_icon;
 
-/* ****** End Status Icon and Notification ****************************************/
-
-//  static gboolean window_state_event (GtkWidget *widget, GdkEventWindowState *event, gpointer trayIcon)
-//  {
-//
-//    StatusIconListener* l(static_cast<StatusIconListener*>(trayIcon));
-//
-//    if(event->changed_mask == GDK_WINDOW_STATE_ICONIFIED
-//       && (event->new_window_state == GDK_WINDOW_STATE_ICONIFIED
-//       || event->new_window_state == (GDK_WINDOW_STATE_ICONIFIED | GDK_WINDOW_STATE_MAXIMIZED)))
-//    {
-//        gtk_status_icon_set_visible(GTK_STATUS_ICON(l->icon), TRUE);
-//        gtk_widget_hide (GTK_WIDGET(widget));
-//    }
-////    else if(event->changed_mask == GDK_WINDOW_STATE_WITHDRAWN
-////            && (event->new_window_state == GDK_WINDOW_STATE_ICONIFIED
-////            || event->new_window_state == (GDK_WINDOW_STATE_ICONIFIED | GDK_WINDOW_STATE_MAXIMIZED)))
-////    {
-////        gtk_status_icon_set_visible(GTK_STATUS_ICON(l->icon), FALSE);
-////    }
-//    return TRUE;
-//  }
-
   struct QueueAndGui
   {
     Queue& queue;
@@ -471,7 +445,7 @@ namespace
     GUI& gui (*_gui);
 
     for (guint i=0; i<NUM_STATUS_ICONS; ++i)
-        status_icons[i].pixbuf = gdk_pixbuf_new_from_inline (-1, status_icons[i].pixbuf_txt, FALSE, 0);
+      status_icons[i].pixbuf = gdk_pixbuf_new_from_inline (-1, status_icons[i].pixbuf_txt, FALSE, 0);
 
     GtkStatusIcon * icon = gtk_status_icon_new_from_pixbuf (status_icons[ICON_STATUS_IDLE].pixbuf);
     GtkWidget * menu = gtk_menu_new ();
@@ -498,7 +472,7 @@ namespace
     gtk_widget_show_all(menu);
     g_signal_connect(icon, "activate", G_CALLBACK(status_icon_activate), window);
     g_signal_connect(icon, "popup-menu", G_CALLBACK(status_icon_popup_menu), menu);
-//    g_signal_connect (G_OBJECT (window), "window-state-event", G_CALLBACK (window_state_event), pl);
+
   }
 
 
@@ -516,7 +490,10 @@ namespace
 
     gtk_container_add (GTK_CONTAINER(window), gui.root());
     const bool minimized(prefs.get_flag("start-minimized", false));
+    const bool status_icon(prefs.get_flag("start-minimized", false));
+
     if (minimized) gtk_window_iconify (window);
+
     gtk_widget_show (GTK_WIDGET(window));
 
     const quarks_t servers (data.get_servers ());
@@ -921,36 +898,38 @@ main (int argc, char *argv[])
 #ifdef HAVE_DBUS
     Pan pan(data, queue, cache, encode_cache, prefs, group_prefs);
   #ifndef DEBUG_PARALLEL
-    pan_dbus_init(&pan);
+    if (!prefs.get_flag("allow-multiple-instances", false))
+    {
 
-    GError* error(NULL);
-    GVariant* var;
+      pan_dbus_init(&pan);
 
-    if (!dbus_connection) goto _fail;
+      GError* error(NULL);
+      GVariant* var;
 
-//    if (pan.dbus_id == -1 || pan.lost_name)
-    {
-      g_dbus_connection_call_sync (dbus_connection,
-                             PAN_DBUS_SERVICE_NAME,
-                             PAN_DBUS_SERVICE_PATH,
-                             "news.pan.NZB",
-                             "NZBEnqueue",
-                             g_variant_new ("(sssbb)",
-                                groups.c_str(), nzb_output_path.c_str(), nzb_str.c_str(),  gui, nzb),
-                             NULL,
-                             G_DBUS_CALL_FLAGS_NONE,
-                             -1,
-                             NULL,
-                             &error);
-
-      if (!error)
-      {
-        std::cout<<"Added "<<nzb_files.size()<<" files to the queue. Exiting.\n";
-        exit(EXIT_SUCCESS);
-      } else
+      if (!dbus_connection) goto _fail;
       {
-        std::cerr<<error->message<<"\n";
-        g_error_free(error);
+        g_dbus_connection_call_sync (dbus_connection,
+                               PAN_DBUS_SERVICE_NAME,
+                               PAN_DBUS_SERVICE_PATH,
+                               "news.pan.NZB",
+                               "NZBEnqueue",
+                               g_variant_new ("(sssbb)",
+                                  groups.c_str(), nzb_output_path.c_str(), nzb_str.c_str(),  gui, nzb),
+                               NULL,
+                               G_DBUS_CALL_FLAGS_NONE,
+                               -1,
+                               NULL,
+                               &error);
+
+        if (!error)
+        {
+          std::cout<<"Added "<<nzb_files.size()<<" files to the queue. Exiting.\n";
+          exit(EXIT_SUCCESS);
+        } else
+        {
+          std::cerr<<error->message<<"\n";
+          g_error_free(error);
+        }
       }
     }
   #endif
diff --git a/pan/gui/prefs-ui.cc b/pan/gui/prefs-ui.cc
index 8c41d1b..5f21e52 100644
--- a/pan/gui/prefs-ui.cc
+++ b/pan/gui/prefs-ui.cc
@@ -466,8 +466,6 @@ namespace pan
     const int n_rows (gtk_tree_model_iter_n_children (model, NULL));
     const bool do_show (gtk_combo_box_get_active(c) == (n_rows-1));
 
-    std::cerr<<"dbg  "<<do_show<<" "<<w_parent<<" "<<n_rows<<"\n";
-
     if (do_show && !w_parent && c_parent) // add it
     {
       gtk_box_pack_start (GTK_BOX(c_parent), w, true, true, 0);
@@ -529,7 +527,6 @@ namespace pan
     }
   }
 
-  /* TODO ! static array for now */
   GtkWidget* new_tabs_combo_box (Prefs& prefs,
                                  const char * mode_key)
   {
@@ -623,7 +620,8 @@ namespace pan
     "Scores of 9999 or more:"
     "Scores from 5000 to 9998:"
     "Scores from 1 to 4999:"
-    "Scores from -9998 to -1:" */
+    "Scores from -9998 to -1:"
+*/
   GtkWidget* score_handler_new (Prefs& prefs,
                               const char * mode_key,
                               const char * mode_fallback,
@@ -720,6 +718,17 @@ PrefsDialog :: on_prefs_string_changed (const StringView& key, const StringView&
 
 }
 
+void
+PrefsDialog :: on_prefs_flag_changed (const StringView& key, bool value)
+{
+
+  if (key == "allow-multiple-instances")
+  {
+    _prefs.save();
+  }
+
+}
+
 namespace
 {
   void select_prefs_charset_cb (GtkButton *, gpointer user_data)
@@ -1003,6 +1012,12 @@ PrefsDialog :: PrefsDialog (Prefs& prefs, GtkWindow* parent):
     HIG :: workarea_add_wide_control (t, &row, w);
 #endif
 
+    // allow multiple instances (seperate, not communicating with dbus)
+    HIG :: workarea_add_section_title (t, &row, _("Startup Behavior"));
+    HIG :: workarea_add_section_spacer (t, row, 1);
+    w = new_check_button (_("Allow multiple instances of Pan"), "allow-multiple-instances", false, prefs);
+    HIG :: workarea_add_wide_control (t, &row, w);
+
     // Autosave Features
     HIG :: workarea_add_section_spacer (t, row, 2);
     HIG :: workarea_add_section_title (t, &row, _("Autosave Article Draft"));
diff --git a/pan/gui/prefs-ui.h b/pan/gui/prefs-ui.h
index 6ec0b6a..6648a86 100644
--- a/pan/gui/prefs-ui.h
+++ b/pan/gui/prefs-ui.h
@@ -59,7 +59,7 @@ namespace pan
       GtkWidget* charset_label;
       void update_default_charset_label(const StringView&);
 
-      void on_prefs_flag_changed (const StringView& key, bool value) {}
+      void on_prefs_flag_changed (const StringView& key, bool value) ;
       void on_prefs_int_changed (const StringView& key, int color) {}
       void on_prefs_string_changed (const StringView& key, const StringView& value) ;
       void on_prefs_color_changed (const StringView& key, const GdkColor& color) {}
diff --git a/pan/usenet-utils/mime-utils.cc b/pan/usenet-utils/mime-utils.cc
index 4af732f..5909256 100644
--- a/pan/usenet-utils/mime-utils.cc
+++ b/pan/usenet-utils/mime-utils.cc
@@ -323,6 +323,19 @@ namespace
       return !strncmp (line, YENC_MARKER_END, YENC_MARKER_END_LEN) &&
              !yenc_parse_end_line (line, NULL, NULL, NULL, NULL);
    }
+
+   bool
+   html_is_beginning_line(const char *line)
+   {
+     return !strncmp (line, HTML_MARKER_BEGIN, HTML_MARKER_BEGIN_LEN) ;
+   }
+
+   bool
+   html_is_ending_line(const char *line)
+   {
+     return !strncmp (line, HTML_MARKER_END, HTML_MARKER_END_LEN) ;
+   }
+
 };
 
 
@@ -469,136 +482,12 @@ enum EncType
 	ENC_YENC,
 	ENC_UU,
 	ENC_BASE64,
-	ENC_QP
+	ENC_QP,
+	ENC_HTML
 };
 
 namespace pan
 {
-
-  /*
-   base64.cpp and base64.h
-
-   Copyright (C) 2004-2008 Renï Nyffenegger
-
-   This source code is provided 'as-is', without any express or implied
-   warranty. In no event will the author be held liable for any damages
-   arising from the use of this software.
-
-   Permission is granted to anyone to use this software for any purpose,
-   including commercial applications, and to alter it and redistribute it
-   freely, subject to the following restrictions:
-
-   1. The origin of this source code must not be misrepresented; you must not
-      claim that you wrote the original source code. If you use this source code
-      in a product, an acknowledgment in the product documentation would be
-      appreciated but is not required.
-
-   2. Altered source versions must be plainly marked as such, and must not be
-      misrepresented as being the original source code.
-
-   3. This notice may not be removed or altered from any source distribution.
-
-   Renï Nyffenegger rene nyffenegger adp-gmbh ch
-
-*/
-
-  static const std::string base64_chars =
-             "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
-             "abcdefghijklmnopqrstuvwxyz"
-             "0123456789+/";
-
-
-  static inline bool is_base64(unsigned char c) {
-    return (isalnum(c) || (c == '+') || (c == '/'));
-  }
-
-  std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len) {
-    std::string ret;
-    int i = 0;
-    int j = 0;
-    unsigned char char_array_3[3];
-    unsigned char char_array_4[4];
-
-    while (in_len--) {
-      char_array_3[i++] = *(bytes_to_encode++);
-      if (i == 3) {
-        char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
-        char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
-        char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
-        char_array_4[3] = char_array_3[2] & 0x3f;
-
-        for(i = 0; (i <4) ; i++)
-          ret += base64_chars[char_array_4[i]];
-        i = 0;
-      }
-    }
-
-    if (i)
-    {
-      for(j = i; j < 3; j++)
-        char_array_3[j] = '\0';
-
-      char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
-      char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
-      char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
-      char_array_4[3] = char_array_3[2] & 0x3f;
-
-      for (j = 0; (j < i + 1); j++)
-        ret += base64_chars[char_array_4[j]];
-
-      while((i++ < 3))
-        ret += '=';
-
-    }
-
-    return ret;
-
-  }
-
-  std::string base64_decode(std::string const& encoded_string) {
-    int in_len = encoded_string.size();
-    int i = 0;
-    int j = 0;
-    int in_ = 0;
-    unsigned char char_array_4[4], char_array_3[3];
-    std::string ret;
-
-    while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) {
-      char_array_4[i++] = encoded_string[in_]; in_++;
-      if (i ==4) {
-        for (i = 0; i <4; i++)
-          char_array_4[i] = base64_chars.find(char_array_4[i]);
-
-        char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
-        char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
-        char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
-
-        for (i = 0; (i < 3); i++)
-          ret += char_array_3[i];
-        i = 0;
-      }
-    }
-
-    if (i) {
-      for (j = i; j <4; j++)
-        char_array_4[j] = 0;
-
-      for (j = 0; j <4; j++)
-        char_array_4[j] = base64_chars.find(char_array_4[j]);
-
-      char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
-      char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
-      char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
-
-      for (j = 0; (j < i - 1); j++) ret += char_array_3[j];
-    }
-
-    return ret;
-  }
-}
-
-namespace pan
-{
   struct TempPart
   {
     GMimeStream * stream;
@@ -811,6 +700,12 @@ namespace pan
               yenc_looking_for_part_line = cur->y_part!=0;
             }
           }
+          else if (html_is_beginning_line (line_str))
+          {
+            found = true;
+            sub_begin = linestart_pos;
+
+          }
           else if (state.uu_temp != NULL && is_uu_line(line_str, line_len) )
           {
             // continue an incomplete uu decode
@@ -832,7 +727,7 @@ namespace pan
           else if (cur == NULL)
           {
             sub_begin = linestart_pos;
-            cur = new TempPart(type = type);
+            cur = new TempPart(type = ENC_HTML);
 
           }
           break;
@@ -901,6 +796,24 @@ namespace pan
           }
           break;
         }
+        case ENC_HTML:
+        {
+          if (html_is_ending_line (line_str))
+          {
+            GMimeStream * stream = g_mime_stream_substream (istream, sub_begin, linestart_pos+line_len);
+            apply_source_and_maybe_filter (cur, stream);
+            if( append_if_not_present (master, cur) )
+              append_if_not_present (appendme, cur);
+
+            cur = NULL;
+            type = ENC_PLAIN;
+          }
+          else
+          {
+            ++cur->valid_lines;
+          }
+          break;
+        }
       }
     }
 
diff --git a/pan/usenet-utils/mime-utils.h b/pan/usenet-utils/mime-utils.h
index 7ac8e15..c2cfa47 100644
--- a/pan/usenet-utils/mime-utils.h
+++ b/pan/usenet-utils/mime-utils.h
@@ -56,6 +56,11 @@
 #define YENC_SHIFT             42
 #define YENC_QUOTE_SHIFT       64
 
+#define HTML_MARKER_BEGIN         "<html>"
+#define HTML_MARKER_BEGIN_LEN     6
+#define HTML_MARKER_END           "</html>"
+#define HTML_MARKER_END_LEN       7
+
 #define NEEDS_DECODING(encoding) ((encoding == GMIME_CONTENT_ENCODING_BASE64) ||   \
                                  (encoding == GMIME_CONTENT_ENCODING_QUOTEDPRINTABLE))
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]