[pan2: 226/268] further improve on flags : mark all flagged



commit 34f0715557ec7a668732ec405d2093615589b292
Author: Heinrich MÃller <henmull src gnome org>
Date:   Mon Dec 5 00:54:14 2011 +0100

    further improve on flags : mark all flagged

 pan/data-impl/headers.cc         |    6 ----
 pan/general/sorted-vector.h      |   52 +++++++++++++++++++-------------------
 pan/general/time-elapsed.h       |    7 +++++
 pan/gui/actions.cc               |    6 ++++
 pan/gui/gui.cc                   |    6 ++++
 pan/gui/gui.h                    |    1 +
 pan/gui/header-pane.cc           |   52 ++++++++++++++++++++++++++++---------
 pan/gui/header-pane.h            |    4 +++
 pan/gui/pan-ui.h                 |    1 +
 pan/gui/pan.ui.h                 |    2 +
 pan/gui/post-ui.cc               |    1 -
 pan/tasks/socket-impl-gio.cc     |    2 +-
 pan/tasks/socket-impl-openssl.cc |    2 +-
 pan/tasks/task-article.h         |   13 +++++++++
 14 files changed, 107 insertions(+), 48 deletions(-)
---
diff --git a/pan/data-impl/headers.cc b/pan/data-impl/headers.cc
index adf1420..8645d25 100644
--- a/pan/data-impl/headers.cc
+++ b/pan/data-impl/headers.cc
@@ -1156,9 +1156,6 @@ DataImpl :: on_articles_removed (const quarks_t& mids) const
 void
 DataImpl :: on_articles_changed (const Quark& group, const quarks_t& mids, bool do_refilter)
 {
-//  for (listeners_t::iterator it(_header_listeners.begin()), end(_header_listeners.end()); it!=end; ++it)
-//    (*it)->on_articles_plus (group, mids);
-
   rescore_articles (group, mids);
 
   // notify the trees that the articles have changed...
@@ -1170,9 +1167,6 @@ void
 DataImpl :: on_articles_added (const Quark& group, const quarks_t& mids)
 {
 
-//  for (listeners_t::iterator it(_header_listeners.begin()), end(_header_listeners.end()); it!=end; ++it)
-//    (*it)->on_articles_plus (group, mids);
-
   if (!mids.empty())
   {
     Log::add_info_va (_("Added %lu articles to %s."),
diff --git a/pan/general/sorted-vector.h b/pan/general/sorted-vector.h
index 5a334b5..f4f8903 100644
--- a/pan/general/sorted-vector.h
+++ b/pan/general/sorted-vector.h
@@ -4,7 +4,7 @@
  *
  * Permission is granted to use, distribute and modify this code provided that:
  *   · this copyright notice appears,
- *   · 
+ *   ·
  * The author welcomes any suggestions on the code or reportings of actual
  * use of the code. Please send your comments to holzherr infobrain com 
  *
@@ -14,10 +14,10 @@
  * you, its user, assume the entire risk as to its quality and accuracy.
  *
  * Created:			November 19th, 2002
- * Last modified:	November 27th, 2002 
+ * Last modified:	November 27th, 2002
 						(changed namespace from std to codeproject;
 						uses template member functions for MSCVER>=1300)
-								
+
  */
 
 #ifndef SORTED_VECTOR_
@@ -30,16 +30,16 @@
 
 namespace pan
 {
-        /**
-         * std::set implemented as a sorted vector.
-         *
-         * This can give a significant memory improvement over std::set,
-         * which is implemented as a tree.  The tradeoff is that insertion
-         * and removal is slow, so this is best used on sets whose contents
-         * rarely change.
-         * 
-         * This class was written by Martin Holzherr and is in the public domain.
-         */
+/**
+ * std::set implemented as a sorted vector.
+ *
+ * This can give a significant memory improvement over std::set,
+ * which is implemented as a tree.  The tradeoff is that insertion
+ * and removal is slow, so this is best used on sets whose contents
+ * rarely change.
+ *
+ * This class was written by Martin Holzherr and is in the public domain.
+ */
 	template<class K, bool bNoDuplicates= false,class Pr = std::less<K>, class A = std::allocator<K> >
 	class sorted_vector {
 public:
@@ -67,7 +67,7 @@ public:
 	explicit sorted_vector(const Pr& pred = Pr(),const A& al = A())
 		:key_compare_(pred),vec_(al){}
 	template<class It>
-	sorted_vector(It first, It beyond, 
+	sorted_vector(It first, It beyond,
 					const Pr& pred = Pr(),const A& al = A())
 		:key_compare_(pred),vec_(first,beyond,al)
         {stable_sort();}
@@ -80,18 +80,18 @@ public:
                                      return *this;}
     Myt_& operator=(const Cont& x){vec_.operator=(x);
                                     sort();return *this;}
-		
+
 	void				reserve(size_type n)	{vec_.reserve(n);}
 	iterator			begin()					{return vec_.begin(); }
 	const_iterator		begin() const			{return vec_.begin(); }
     iterator			end()					{return vec_.end();}
     const_iterator		end() const				{return vec_.end();}
     reverse_iterator	rbegin()				{return vec_.rbegin();}
-    const_reverse_iterator rbegin() const   
+    const_reverse_iterator rbegin() const
 												{return vec_.rbegin();}
 
     reverse_iterator rend()						{return vec_.rend();}
-    const_reverse_iterator rend() const     
+    const_reverse_iterator rend() const
 												{return vec_.rend();}
 
 
@@ -103,7 +103,7 @@ public:
     reference at(size_type p)					{return vec_.at(p);}
 	const_reference operator[](size_type p) const
 												{return vec_.operator[](p);}
-		
+
 	reference operator[](size_type p)			{return vec_.operator[](p);}
     reference front()							{return vec_.front();}
 	const_reference front() const				{return vec_.front();}
@@ -111,7 +111,7 @@ public:
     const_reference back() const				{return vec_.back();}
     void pop_back()								{vec_.pop_back();}
 
-    void assign(const_iterator first, const_iterator beyond)					
+    void assign(const_iterator first, const_iterator beyond)
 												{vec_.assign(first,beyond);}
 	void assign(size_type n, const K& x = K())
 												{vec_.assign(n,x);}
@@ -162,7 +162,7 @@ public:
     iterator erase(iterator p)          {return vec_.erase(p);}
 	iterator erase(iterator first, iterator beyond)
                                         {return vec_.erase(first,beyond);}
-    size_type erase(const K& key)     
+    size_type erase(const K& key)
         {
             Pairii_ begEnd= equal_range(key);
             size_type n= std::distance(begEnd.first,begEnd.second);
@@ -170,8 +170,8 @@ public:
             return n;
         }
     void clear()                        {return vec_.clear();}
-		
-    bool Eq_(const Myt_& x) const      
+
+    bool Eq_(const Myt_& x) const
 		{return (size() == x.size()
 		&& std::equal(begin(), end(), x.begin())); }
 	bool Lt_(const Myt_& x) const
@@ -179,7 +179,7 @@ public:
 										x.begin(), x.end()));}
 	void swap(Myt_& x)
         {vec_.swap(x.vec_);std::swap(key_compare_,x.key_compare_);}
-        
+
 	friend void swap(Myt_& x, Myt_& Y_)
 		{x.swap(Y_); }
 
@@ -212,18 +212,18 @@ public:
 /*functions for use with direct std::vector-access*/
     Cont& get_container()
         {return vec_;}
-    void sort()//restore sorted order after low level access 
+    void sort()//restore sorted order after low level access
         {   std::sort(vec_.begin(),vec_.end(),key_compare_);
             if( bNoDuplicates ){
                 vec_.erase(Unique_(),vec_.end());
             }
         }
-    void stable_sort()//restore sorted order after low level access 
+    void stable_sort()//restore sorted order after low level access
         {   std::stable_sort(vec_.begin(),vec_.end(),key_compare_);
             if( bNoDuplicates ){
                 erase(Unique_(),end());
             }
-        }   
+        }
 protected:
     iterator Unique_()
         {   iterator front_= vec_.begin(),out_= vec_.end(),end_=vec_.end();
diff --git a/pan/general/time-elapsed.h b/pan/general/time-elapsed.h
index 7dd5594..ec4e76d 100644
--- a/pan/general/time-elapsed.h
+++ b/pan/general/time-elapsed.h
@@ -24,6 +24,13 @@ namespace pan
       diff += (finish.tv_usec - start.tv_usec)/(double)G_USEC_PER_SEC;
       return diff;
     }
+
+    double get_usecs_elapsed () const {
+      GTimeVal finish;
+      g_get_current_time (&finish);
+      double diff = finish.tv_usec - start.tv_usec;
+      return diff;
+    }
   };
 }
 
diff --git a/pan/gui/actions.cc b/pan/gui/actions.cc
index ca78b8e..cf886c9 100644
--- a/pan/gui/actions.cc
+++ b/pan/gui/actions.cc
@@ -149,6 +149,7 @@ namespace
   void do_flag_off                     (GtkAction*) { pan_ui->do_flag_off(); }
   void do_next_flag                    (GtkAction*) { pan_ui->do_next_flag(); }
   void do_last_flag                    (GtkAction*) { pan_ui->do_last_flag(); }
+  void do_mark_all_flagged             (GtkAction*) { pan_ui->do_mark_all_flagged(); }
   void do_show_score_dialog            (GtkAction*) { pan_ui->do_show_score_dialog(); }
   void do_show_new_score_dialog        (GtkAction*) { pan_ui->do_show_new_score_dialog(); }
   void do_cancel_article               (GtkAction*) { pan_ui->do_cancel_article(); }
@@ -553,6 +554,11 @@ namespace
       N_("_Toggle Flag off for Thread"),
       G_CALLBACK(do_flag_off) },
 
+    { "mark-all-flagged", NULL,
+      N_("_Mark all flagged Threads"), "<control>X",
+      N_("_Mark all flagged Threads"),
+      G_CALLBACK(do_mark_all_flagged) },
+
     { "next-flagged", NULL,
       N_("_Goto next flagged Thread"), "plus",
       N_("_Goto next flagged Thread"),
diff --git a/pan/gui/gui.cc b/pan/gui/gui.cc
index fb3dbbb..feb329f 100644
--- a/pan/gui/gui.cc
+++ b/pan/gui/gui.cc
@@ -1167,6 +1167,12 @@ GUI :: do_flag (bool on)
 }
 
 void
+GUI :: do_mark_all_flagged()
+{
+  _header_pane->mark_all_flagged();
+}
+
+void
 GUI :: step_bookmarks(int step)
 {
   _header_pane->move_to_next_bookmark(step);
diff --git a/pan/gui/gui.h b/pan/gui/gui.h
index a8b0bb4..b38a447 100644
--- a/pan/gui/gui.h
+++ b/pan/gui/gui.h
@@ -139,6 +139,7 @@ namespace pan
       virtual void do_flag_off ();
       virtual void do_next_flag ();
       virtual void do_last_flag ();
+      virtual void do_mark_all_flagged ();
       virtual void do_show_score_dialog ();
       virtual void do_show_new_score_dialog ();
       virtual void do_cancel_article ();
diff --git a/pan/gui/header-pane.cc b/pan/gui/header-pane.cc
index c4b0728..db5e472 100644
--- a/pan/gui/header-pane.cc
+++ b/pan/gui/header-pane.cc
@@ -274,6 +274,7 @@ struct HeaderPane::CountUnread: public PanTreeStore::WalkFunctor
   }
 };
 
+
 void
 HeaderPane :: render_subject (GtkTreeViewColumn * ,
                               GtkCellRenderer   * renderer,
@@ -829,6 +830,36 @@ HeaderPane :: get_full_selection () const
 }
 
 void
+HeaderPane :: mark_all_flagged ()
+{
+
+  GtkTreeIter iter;
+  GtkTreeModel * model(gtk_tree_view_get_model(GTK_TREE_VIEW(_tree_view)));
+  GtkTreeSelection * sel (gtk_tree_view_get_selection (GTK_TREE_VIEW(_tree_view)));
+  gtk_tree_selection_unselect_all(sel);
+  gtk_tree_model_get_iter_first (model, &iter);
+  walk_and_collect_flagged(model, &iter, sel);
+
+}
+
+void
+HeaderPane :: walk_and_collect_flagged (GtkTreeModel  * model,
+                                GtkTreeIter           * cur,
+                                GtkTreeSelection      * setme) const
+{
+   for (;;) {
+    const Article * a(get_article (model, cur));
+    if (a->get_flag()) gtk_tree_selection_select_iter(setme,cur);
+    GtkTreeIter child;
+    if (gtk_tree_model_iter_children (model, &child, cur))
+      walk_and_collect_flagged (model, &child, setme);
+    if (!gtk_tree_model_iter_next (model, cur))
+      break;
+  }
+
+}
+
+void
 HeaderPane :: walk_and_collect (GtkTreeModel          * model,
                                 GtkTreeIter           * cur,
                                 articles_set          & setme) const
@@ -2014,18 +2045,14 @@ namespace
 
   struct SelectFunctor: public pan::RowActionFunctor {
     virtual ~SelectFunctor () {}
-    SelectFunctor (GtkTreeView * view, bool exp): _view(view), _expand(exp) {}
+    SelectFunctor (GtkTreeView * view): _view(view) {}
     GtkTreeView * _view;
-    bool _expand;
     virtual void operator() (GtkTreeModel* model, GtkTreeIter* iter, const Article&) {
       GtkTreeSelection * sel (gtk_tree_view_get_selection (_view));
       gtk_tree_selection_unselect_all (sel);
       GtkTreePath * path = gtk_tree_model_get_path (model, iter);
-//      if (_expand)
-//      {
-        gtk_tree_view_expand_row (_view, path, true);
-        gtk_tree_view_expand_to_path (_view, path);
-//      }
+      gtk_tree_view_expand_row (_view, path, true);
+      gtk_tree_view_expand_to_path (_view, path);
       gtk_tree_view_set_cursor (_view, path, NULL, FALSE);
       gtk_tree_view_scroll_to_cell (_view, path, NULL, true, 0.5f, 0.0f);
       gtk_tree_path_free (path);
@@ -2034,7 +2061,7 @@ namespace
 
   struct ReadFunctor: public SelectFunctor {
     virtual ~ReadFunctor() {}
-    ReadFunctor (GtkTreeView * view, bool exp, ActionManager& am): SelectFunctor(view,exp), _am(am) {}
+    ReadFunctor (GtkTreeView * view, ActionManager& am): SelectFunctor(view), _am(am) {}
     ActionManager& _am;
     virtual void operator() (GtkTreeModel* model, GtkTreeIter* iter, const Article& a) {
       SelectFunctor::operator() (model, iter, a);
@@ -2119,7 +2146,7 @@ HeaderPane :: read_next_if (const ArticleTester& test)
 {
 
   GtkTreeView * v (GTK_TREE_VIEW(_tree_view));
-  ReadFunctor read (v, _prefs.get_flag("expand-selected-articles", false), _action_manager);
+  ReadFunctor read (v, _action_manager);
   action_next_if (test, read);
 }
 
@@ -2129,7 +2156,7 @@ HeaderPane :: read_prev_if (const ArticleTester & test)
 
   GtkTreeView * v (GTK_TREE_VIEW(_tree_view));
   GtkTreeModel * m (GTK_TREE_MODEL(_tree_store));
-  ReadFunctor read (v, _prefs.get_flag("expand-selected-articles", false), _action_manager);
+  ReadFunctor read (v, _action_manager);
   next_iterator (v, m, TreeIteratorPrev(), test, read);
 }
 
@@ -2138,7 +2165,7 @@ HeaderPane :: select_next_if (const ArticleTester& test)
 {
 
   GtkTreeView * v (GTK_TREE_VIEW(_tree_view));
-  SelectFunctor sel (v, _prefs.get_flag("expand-selected-articles", false));
+  SelectFunctor sel (v);
   action_next_if (test, sel);
 }
 
@@ -2148,7 +2175,7 @@ HeaderPane :: select_prev_if (const ArticleTester& test)
 
   GtkTreeView * v (GTK_TREE_VIEW(_tree_view));
   GtkTreeModel * m (GTK_TREE_MODEL(_tree_store));
-  SelectFunctor sel (v, _prefs.get_flag("expand-selected-articles", false));
+  SelectFunctor sel (v);
   next_iterator (v, m, TreeIteratorPrev(), test, sel);
 }
 
@@ -2293,7 +2320,6 @@ HeaderPane :: on_queue_task_removed (Queue&, Task& task, int)
 void
 HeaderPane :: on_cache_added (const Quark& message_id)
 {
-  /// SLOOOOW!
   quarks_t q;
   q.insert(message_id);
   _data.rescore_articles ( _group, q );
diff --git a/pan/gui/header-pane.h b/pan/gui/header-pane.h
index 7908cfe..8552c53 100644
--- a/pan/gui/header-pane.h
+++ b/pan/gui/header-pane.h
@@ -122,6 +122,7 @@ namespace pan
       Article* get_first_selected_article ();
       std::set<const Article*> get_full_selection () const;
       std::vector<const Article*> get_full_selection_v () const;
+      void mark_all_flagged ();
       const guint get_full_selection_rows_num () const;
       std::set<const Article*> get_nested_selection (bool do_mark_all) const;
       bool set_group (const Quark& group);
@@ -165,6 +166,7 @@ namespace pan
       virtual void on_cache_added (const Quark& mid);
       virtual void on_cache_removed (const quarks_t& mids);
 
+
     public: // pretend it's private
       ActionManager& _action_manager;
 
@@ -345,6 +347,8 @@ namespace pan
       class RowInserter;
       class SimilarWalk;
       void walk_and_collect (GtkTreeModel*, GtkTreeIter*, articles_set&) const;
+      void walk_and_collect_flagged (GtkTreeModel*, GtkTreeIter*, GtkTreeSelection*) const;
+
     private:
       typedef void RenderFunc (GtkTreeViewColumn*, GtkCellRenderer*, GtkTreeModel*, GtkTreeIter*, gpointer);
       static RenderFunc render_action;
diff --git a/pan/gui/pan-ui.h b/pan/gui/pan-ui.h
index a2ed903..96932f7 100644
--- a/pan/gui/pan-ui.h
+++ b/pan/gui/pan-ui.h
@@ -70,6 +70,7 @@ namespace pan
     virtual void do_flag_off () = 0;
     virtual void do_next_flag () = 0;
     virtual void do_last_flag () = 0;
+    virtual void do_mark_all_flagged () = 0;
     virtual void do_cancel_article () = 0;
     virtual void do_supersede_article () = 0;
     virtual void do_delete_article () = 0;
diff --git a/pan/gui/pan.ui.h b/pan/gui/pan.ui.h
index c6b8c3b..bbfa8f9 100644
--- a/pan/gui/pan.ui.h
+++ b/pan/gui/pan.ui.h
@@ -134,6 +134,7 @@ const char * fallback_ui_file =
 "        <menuitem action='unflag-thread' />\n"
 "        <menuitem action='next-flagged' />\n"
 "        <menuitem action='last-flagged' />\n"
+"        <menuitem action='mark-all-flagged' />\n"
 "        <separator />\n"
 "        <menuitem action='plonk' />\n"
 "        <menuitem action='view-article-score' />\n"
@@ -207,6 +208,7 @@ const char * fallback_ui_file =
 "    <menuitem action='unflag-thread' />\n"
 "    <menuitem action='next-flagged' />\n"
 "    <menuitem action='last-flagged' />\n"
+"    <menuitem action='mark-all-flagged' />\n"
 "    <separator />\n"
 "    <menuitem action='plonk' />\n"
 "    <menuitem action='view-article-score' />\n"
diff --git a/pan/gui/post-ui.cc b/pan/gui/post-ui.cc
index d1b4f6a..7947e72 100644
--- a/pan/gui/post-ui.cc
+++ b/pan/gui/post-ui.cc
@@ -2436,7 +2436,6 @@ PostUI :: create_filequeue_tab ()
 {
   GtkWidget *w ;
   GtkListStore *list_store;
-  GtkTreeIter   iter;
   GtkCellRenderer *renderer;
   GtkWidget * vbox = gtk_vbox_new (false, 0);
   GtkWidget * buttons = gtk_hbox_new (false, PAD_SMALL);
diff --git a/pan/tasks/socket-impl-gio.cc b/pan/tasks/socket-impl-gio.cc
index b2a2aa2..fb2eb36 100644
--- a/pan/tasks/socket-impl-gio.cc
+++ b/pan/tasks/socket-impl-gio.cc
@@ -262,7 +262,7 @@ namespace
 
 GIOChannelSocket :: ~GIOChannelSocket ()
 {
-//std::cerr << LINE_ID << " destroying socket " << this << std::endl;
+  debug(" destroying GIO socket "<<this);
 
   remove_source (_tag_watch);
   remove_source (_tag_timeout);
diff --git a/pan/tasks/socket-impl-openssl.cc b/pan/tasks/socket-impl-openssl.cc
index e1202ab..fec8cfd 100644
--- a/pan/tasks/socket-impl-openssl.cc
+++ b/pan/tasks/socket-impl-openssl.cc
@@ -313,7 +313,7 @@ GIOChannelSocketSSL :: ~GIOChannelSocketSSL ()
 
   _certstore.remove_listener(this);
 
-  std::cerr << LINE_ID << " destroying socket " << this <<std::endl;
+  debug(" destroying SSL socket "<<this);
 
   remove_source (_tag_watch);
   remove_source (_tag_timeout);
diff --git a/pan/tasks/task-article.h b/pan/tasks/task-article.h
index 778b614..01afcf6 100644
--- a/pan/tasks/task-article.h
+++ b/pan/tasks/task-article.h
@@ -104,6 +104,19 @@ namespace pan
       std::string _groups;
 
     private:
+
+//      typedef std::pair<std::string,StringView> lines_p;
+//      typedef std::vector<lines_p> lines_v;
+//
+//      struct CacheAdder
+//      {
+//        lines_v lines;
+//        void add(std::string& q, const StringView& v)
+//          { lines.push_back(lines_p(q,v)); }
+//      };
+//
+//      CacheAdder adder;
+
       struct Needed {
         std::string message_id;
         unsigned long bytes;



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