[pan2] * fixed bug in flags not saving to headers * fixed glib version requirement string



commit 3d32275fd65e612763956de6b682000878900686
Author: Heinrich MÃller <henmull src gnome org>
Date:   Sun Dec 4 15:22:21 2011 +0100

    * fixed bug in flags not saving to headers
    * fixed glib version requirement string

 configure.in               |    2 +-
 pan/data-impl/data-impl.cc |    2 +
 pan/data-impl/data-impl.h  |    8 ++++++
 pan/data-impl/headers.cc   |   16 ++++++++++--
 pan/data/data.cc           |    7 +++++
 pan/data/data.h            |    7 +++++
 pan/gui/gui.cc             |   14 ++++++++---
 pan/gui/gui.h              |    5 ++-
 pan/gui/header-pane.cc     |   55 +++++++++++++++++++++----------------------
 pan/gui/header-pane.h      |    2 +-
 10 files changed, 79 insertions(+), 39 deletions(-)
---
diff --git a/configure.in b/configure.in
index 9756d28..6a29f68 100644
--- a/configure.in
+++ b/configure.in
@@ -44,7 +44,7 @@ dnl
 dnl GtkSpell is optional: GTKSPELL_REQUIRED refers to the minimum version
 dnl needed if you want to build Pan with spellchecking in the Post window.
 
-GLIB_REQUIRED=2.28.6
+GLIB_REQUIRED=2.14.0
 GMIME_REQUIRED=2.4.0
 GTK_REQUIRED=2.16.0
 GTK3_REQUIRED=3.0.0
diff --git a/pan/data-impl/data-impl.cc b/pan/data-impl/data-impl.cc
index c8f3fd4..9d97a23 100644
--- a/pan/data-impl/data-impl.cc
+++ b/pan/data-impl/data-impl.cc
@@ -94,6 +94,7 @@ DataImpl :: rebuild_backend ()
 DataImpl :: ~DataImpl ()
 {
   save_state ();
+
 }
 
 void
@@ -106,3 +107,4 @@ DataImpl :: save_state ()
     save_newsrc_files (*_data_io);
   }
 }
+
diff --git a/pan/data-impl/data-impl.h b/pan/data-impl/data-impl.h
index 6e577b2..3669305 100644
--- a/pan/data-impl/data-impl.h
+++ b/pan/data-impl/data-impl.h
@@ -71,6 +71,7 @@ namespace pan
     public:
       virtual ArticleCache& get_cache () { return _cache; }
       virtual const ArticleCache& get_cache () const { return _cache; }
+
     private:
       ArticleCache _cache;
 
@@ -353,6 +354,11 @@ namespace pan
         }
       };
 
+      /***
+       **
+      ***/
+      virtual void fire_article_flag_changed (const Article* a, const Quark& group);
+
       struct GroupHeaders
       {
         int _ref;
@@ -378,6 +384,7 @@ namespace pan
         const Article* find_article (const Quark& mid) const;
         void remove_articles (const quarks_t& mids);
         void build_references_header (const Article* article, std::string& setme) const;
+
       };
 
       static void find_nodes (const quarks_t           & mids,
@@ -454,6 +461,7 @@ namespace pan
           void accumulate_descendants (unique_nodes_t&, const ArticleNode*) const;
           void add_articles (const const_nodes_v&);
           void apply_filter (const const_nodes_v&);
+
       };
 
       std::set<MyTree*> _trees;
diff --git a/pan/data-impl/headers.cc b/pan/data-impl/headers.cc
index f00797f..297bdd3 100644
--- a/pan/data-impl/headers.cc
+++ b/pan/data-impl/headers.cc
@@ -47,10 +47,12 @@ DataImpl :: GroupHeaders :: GroupHeaders ():
   _ref (0),
   _dirty (false)
 {
+
 }
 
 DataImpl :: GroupHeaders :: ~GroupHeaders ()
 {
+
 }
 
 DataImpl :: ArticleNode*
@@ -177,7 +179,7 @@ DataImpl :: ref_group (const Quark& group)
     load_headers (*_data_io, group);
   }
   ++h->_ref;
-  //std::cerr << LINE_ID << " group " << group << " refcount up to " << h->_ref << std::endl;
+//  std::cerr << LINE_ID << " group " << group << " refcount up to " << h->_ref << std::endl;
 }
 
 void
@@ -187,10 +189,10 @@ DataImpl :: unref_group   (const Quark& group)
   pan_return_if_fail (h != 0);
 
   --h->_ref;
-  //std::cerr << LINE_ID << " group " << group << " refcount down to " << h->_ref << std::endl;
+//  std::cerr << LINE_ID << " group " << group << " refcount down to " << h->_ref << std::endl;
   if (h->_ref == 0)
   {
-    if (h->_dirty)
+    if (h->_dirty )
       save_headers (*_data_io, group);
     h->_dirty = false;
     free_group_headers_memory (group);
@@ -198,6 +200,14 @@ DataImpl :: unref_group   (const Quark& group)
 }
 
 void
+DataImpl :: fire_article_flag_changed (const Article* a, const Quark& group)
+{
+  GroupHeaders * h (get_group_headers (group));
+  h->_dirty = true;
+  Data::fire_article_flag_changed(a,group);
+}
+
+void
 DataImpl :: find_nodes (const quarks_t           & mids,
                         nodes_t                  & nodes,
                         nodes_v                  & setme)
diff --git a/pan/data/data.cc b/pan/data/data.cc
index d29b6f4..0182032 100644
--- a/pan/data/data.cc
+++ b/pan/data/data.cc
@@ -69,3 +69,10 @@ Data :: fire_group_subscribe (const Quark& group, bool sub)
   for (listeners_t::iterator it(_listeners.begin()), end(_listeners.end()); it!=end; )
     (*it++)->on_group_subscribe (group, sub);
 }
+
+void
+Data :: fire_article_flag_changed (const Article* a, const Quark& group)
+{
+  for (listeners_t::iterator it(_listeners.begin()), end(_listeners.end()); it!=end; )
+    (*it++)->on_article_flag_changed (a, group);
+}
diff --git a/pan/data/data.h b/pan/data/data.h
index 23e9823..94354d1 100644
--- a/pan/data/data.h
+++ b/pan/data/data.h
@@ -224,6 +224,9 @@ namespace pan
         virtual void on_group_counts (const Quark& group   UNUSED,
                                       unsigned long unread UNUSED,
                                       unsigned long total  UNUSED) {}
+
+        /* listener for article flag, don't call too often */
+        virtual void on_article_flag_changed (const Article* a UNUSED, const Quark& group UNUSED) {}
       };
 
       void add_listener (Listener * l);
@@ -247,6 +250,10 @@ namespace pan
       typedef std::set<Listener*> listeners_t;
       listeners_t _listeners;
 
+    public:
+
+      virtual void fire_article_flag_changed (const Article* a, const Quark& group);
+
     /*****************************************************************
     ***
     ***  GROUPS
diff --git a/pan/gui/gui.cc b/pan/gui/gui.cc
index c93112f..4dc4cbb 100644
--- a/pan/gui/gui.cc
+++ b/pan/gui/gui.cc
@@ -308,6 +308,7 @@ GUI :: GUI (Data& data, Queue& queue, ArticleCache& cache, Prefs& prefs, GroupPr
     activate_action ("get-new-headers-in-subscribed-groups");
 
   _prefs.add_listener (this);
+  _data.add_listener (this);
 
   gtk_accel_map_load (get_accel_filename().c_str());
 
@@ -331,6 +332,10 @@ namespace
 
 GUI :: ~GUI ()
 {
+  _data.remove_listener(this);
+  _prefs.remove_listener (this);
+  _queue.remove_listener (this);
+  Log::get().remove_listener (this);
   const std::string accel_filename (get_accel_filename());
   gtk_accel_map_save (accel_filename.c_str());
   chmod (accel_filename.c_str(), 0600);
@@ -344,9 +349,7 @@ GUI :: ~GUI ()
                       && (gdk_window_get_state( gtk_widget_get_window(_root)) & GDK_WINDOW_STATE_MAXIMIZED);
   _prefs.set_flag ("main-window-is-maximized", maximized);
 
-  _prefs.remove_listener (this);
-  _queue.remove_listener (this);
-  Log::get().remove_listener (this);
+
   g_source_remove (upkeep_tag);
 
   std::set<GtkWidget*> unref;
@@ -1050,9 +1053,12 @@ void GUI :: do_ignore ()
 void
 GUI :: do_flag ()
 {
+  /// TODO flag selection
   Article* a = _header_pane->get_first_selected_article();
+  g_return_if_fail(a);
   a->toggle_flag();
-  _header_pane->on_article_flag_toggled(a);
+  const Quark& g(_header_pane->get_group());
+  _data.fire_article_flag_changed(a, g);
 }
 
 void
diff --git a/pan/gui/gui.h b/pan/gui/gui.h
index 3ba6246..2235db1 100644
--- a/pan/gui/gui.h
+++ b/pan/gui/gui.h
@@ -23,7 +23,7 @@
 #include <pan/general/progress.h>
 #include <pan/data/article-cache.h>
 #include <pan/tasks/queue.h>
-
+#include <pan/data/article.h>
 #include <pan/gui/action-manager.h>
 #include <pan/gui/pan-ui.h>
 #include <pan/gui/prefs.h>
@@ -50,7 +50,8 @@ namespace pan
     private Log::Listener,
     private Progress::Listener,
     private Queue::Listener,
-    private Prefs::Listener
+    private Prefs::Listener,
+    private Data::Listener
   {
     public:
       GUI (Data& data, Queue&, ArticleCache&, Prefs&, GroupPrefs&);
diff --git a/pan/gui/header-pane.cc b/pan/gui/header-pane.cc
index e014462..2f2b57d 100644
--- a/pan/gui/header-pane.cc
+++ b/pan/gui/header-pane.cc
@@ -1551,7 +1551,7 @@ HeaderPane :: ~HeaderPane ()
   _cache.remove_listener (this);
   _queue.remove_listener (this);
   _prefs.remove_listener (this);
-  _data.remove_listener (this);
+  _data.remove_listener  (this);
 
   // save the column widths
   GList * columns = gtk_tree_view_get_columns (GTK_TREE_VIEW(_tree_view));
@@ -2169,7 +2169,7 @@ HeaderPane :: rebuild_article_action (const Quark& message_id)
 }
 
 void
-HeaderPane :: on_article_flag_toggled (Article* a)
+HeaderPane :: on_article_flag_changed (const Article* a, const Quark& group)
 {
   g_return_if_fail(a);
   rebuild_article_action (a->message_id);
@@ -2250,10 +2250,10 @@ struct HeaderPane::SimilarWalk: public PanTreeStore::WalkFunctor
       // strip out frequent substrings that tend to skew string_likeness too high
       static const char * const frequent_substrings [] = { "mp3", "gif", "jpg", "jpeg", "yEnc" };
       for (size_t i=0; i!=G_N_ELEMENTS(frequent_substrings); ++i) {
-	std::string::size_type pos;
-	const char * needle (frequent_substrings[i]);
-	while (((pos = sa.find (needle))) != std::string::npos) sa.erase (pos, strlen(needle));
-	while (((pos = sb.find (needle))) != std::string::npos) sb.erase (pos, strlen(needle));
+        std::string::size_type pos;
+        const char * needle (frequent_substrings[i]);
+        while (((pos = sa.find (needle))) != std::string::npos) sa.erase (pos, strlen(needle));
+        while (((pos = sb.find (needle))) != std::string::npos) sb.erase (pos, strlen(needle));
       }
 
       // strip out non-alpha characters
@@ -2268,11 +2268,11 @@ struct HeaderPane::SimilarWalk: public PanTreeStore::WalkFunctor
       const bool is_long_string (min_len >= 30);
       double min_closeness;
       if (is_short_string)
-	min_closeness = 0.6;
+        min_closeness = 0.6;
       else if (is_long_string)
-	min_closeness = 0.5;
+        min_closeness = 0.5;
       else
-	min_closeness = 0.55;
+        min_closeness = 0.55;
 
       return string_likeness (sa, sb) >= min_closeness;
     }
@@ -2284,30 +2284,29 @@ struct HeaderPane::SimilarWalk: public PanTreeStore::WalkFunctor
 
       if (!a.strchr(' ')) // only one word, so count common characters
       {
-	int common_chars = 0;
+        int common_chars = 0;
 
-	foreach_const (StringView, a, it) {
-	  const char * pos = b.strchr (*it);
-	  if (pos) {
-	    ++common_chars;
-	    b.eat_chars (pos - b.str);
-	  }
-	}
+        foreach_const (StringView, a, it) {
+          const char * pos = b.strchr (*it);
+          if (pos) {
+            ++common_chars;
+            b.eat_chars (pos - b.str);
+          }
+        }
 
-	retval = (double)common_chars / a.len;
+        retval = (double)common_chars / a.len;
       }
-      else // more than one word, so count common words
+        else // more than one word, so count common words
       {
-	StringView tok;
-	int str1_words(0), common_words(0);
-	while (a.pop_token (tok)) {
-	  ++str1_words;
-	  const char *pch = b.strstr (tok);
-	  if (pch) ++common_words;
-	}
-	retval = (double)common_words / str1_words;
+        StringView tok;
+        int str1_words(0), common_words(0);
+        while (a.pop_token (tok)) {
+          ++str1_words;
+          const char *pch = b.strstr (tok);
+          if (pch) ++common_words;
+        }
+        retval = (double)common_words / str1_words;
       }
-
       return retval;
     }
 };
diff --git a/pan/gui/header-pane.h b/pan/gui/header-pane.h
index 1a1ad87..3c7b5f9 100644
--- a/pan/gui/header-pane.h
+++ b/pan/gui/header-pane.h
@@ -144,7 +144,7 @@ namespace pan
       virtual void on_prefs_color_changed  (const StringView&, const GdkColor&) {}
 
     public:
-      void on_article_flag_toggled(Article*) ;
+      virtual void on_article_flag_changed (const Article* a, const Quark& group);
 
     private:
       virtual void on_queue_task_active_changed (Queue&, Task&, bool active UNUSED) { }



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