[pan2: 152/268] fixed auto-download (from actions menu) to accept group-specific settings.



commit 2e67cfe5d38594dc05ad8964aeb1abd182e72867
Author: Heinrich MÃller <sphemuel stud informatik uni-erlangen de>
Date:   Thu Sep 1 08:10:30 2011 +0200

    fixed auto-download (from actions menu) to accept
    group-specific settings.

 pan/data-impl/data-impl.h              |    3 +++
 pan/data-impl/headers-test.cc          |    6 +++---
 pan/data-impl/headers.cc               |    3 ++-
 pan/data-impl/my-tree.cc               |   14 +++++++-------
 pan/data-impl/rules-filter.cc          |    8 +++++---
 pan/data-impl/speed-test-load-group.cc |    2 +-
 pan/data/data.h                        |    1 +
 pan/gui/gui.cc                         |    2 +-
 pan/gui/header-pane.cc                 |    9 ++++++++-
 pan/gui/header-pane.h                  |    4 +++-
 pan/gui/save-ui.cc                     |    2 +-
 11 files changed, 35 insertions(+), 19 deletions(-)
---
diff --git a/pan/data-impl/data-impl.h b/pan/data-impl/data-impl.h
index c0d92c7..35cebee 100644
--- a/pan/data-impl/data-impl.h
+++ b/pan/data-impl/data-impl.h
@@ -431,6 +431,7 @@ namespace pan
         public: // life cycle
           MyTree (DataImpl              & data_impl,
                   const Quark           & group,
+                  const Quark           & save_path,
                   const Data::ShowType    show_type,
                   const FilterInfo      * filter_info=0,
                   const RulesInfo       * rules=0,
@@ -454,6 +455,7 @@ namespace pan
 
         private: // implementation fields
           const Quark _group;
+          const Quark _save_path;
           DataImpl & _data;
           nodes_t _nodes;
           MemChunk<ArticleNode> _node_chunk;
@@ -489,6 +491,7 @@ namespace pan
       virtual void delete_articles             (const unique_articles_t&);
 
       virtual ArticleTree* group_get_articles  (const Quark        & group,
+                                                const Quark        & save_path,
                                                 const ShowType      show_type = SHOW_ARTICLES,
                                                 const FilterInfo   * criteria=0,
                                                 const RulesInfo    * rules=0,
diff --git a/pan/data-impl/headers-test.cc b/pan/data-impl/headers-test.cc
index cc1abcb..51338c1 100644
--- a/pan/data-impl/headers-test.cc
+++ b/pan/data-impl/headers-test.cc
@@ -26,7 +26,7 @@ int main ()
 
   // TEST: can we add an article?
   data.xover_add (server, group, "Subject", "Author", 0, "<article1 foo com>", "", 40, 100, "");
-  tree = data.group_get_articles (group);
+  tree = data.group_get_articles (group,Quark(""));
   check (tree->size() == 1ul)
   a = tree->get_article ("<article1 foo com>");
   check (a != 0);
@@ -37,7 +37,7 @@ int main ()
 
   // TEST: can we add a child?
   data.xover_add (server, group, "Re: Subject", "Author", 0, "<article2 blah com>", "<article1 foo com>", 40, 100, "");
-  tree = data.group_get_articles (group);
+  tree = data.group_get_articles (group,Quark(""));
   check (tree->size() == 2ul)
   a = tree->get_article ("<article2 blah com>");
   check (a != 0)
@@ -76,7 +76,7 @@ int main ()
   filter_info.set_type_text ("Subject", description);
 
   // show articles whose subject has the letter 'a'
-  tree = data.group_get_articles (group);
+  tree = data.group_get_articles (group,Quark(""));
   tree->set_filter (Data::SHOW_ARTICLES, &filter_info);
   check (tree->size() == 0ul);
 
diff --git a/pan/data-impl/headers.cc b/pan/data-impl/headers.cc
index a81dc3d..2198599 100644
--- a/pan/data-impl/headers.cc
+++ b/pan/data-impl/headers.cc
@@ -1194,11 +1194,12 @@ DataImpl :: find_closest_ancestor (const ArticleNode             * node,
 
 Data::ArticleTree*
 DataImpl :: group_get_articles (const Quark       & group,
+                                const Quark       & save_path,
                                 const ShowType      show_type,
                                 const FilterInfo  * filter,
                                 const RulesInfo   * rules,
                                       Queue       * queue) const
 {
   // cast const away for group_ref()... consider _groups mutable
-  return new MyTree (*const_cast<DataImpl*>(this), group, show_type, filter, rules,queue);
+  return new MyTree (*const_cast<DataImpl*>(this), group, save_path, show_type, filter, rules,queue);
 }
diff --git a/pan/data-impl/my-tree.cc b/pan/data-impl/my-tree.cc
index 85b6f28..03d6b1f 100644
--- a/pan/data-impl/my-tree.cc
+++ b/pan/data-impl/my-tree.cc
@@ -145,12 +145,14 @@ DataImpl :: MyTree :: set_filter (const Data::ShowType    show_type,
 
 DataImpl :: MyTree :: MyTree (DataImpl              & data_impl,
                               const Quark           & group,
+                              const Quark           & save_path,
                               const Data::ShowType    show_type,
                               const FilterInfo      * filter,
                               const RulesInfo       * rules,
                                     Queue           * queue):
   _group (group),
-  _data (data_impl)
+  _data (data_impl),
+  _save_path(save_path)
 {
 
   _data.set_queue(queue);
@@ -257,7 +259,8 @@ DataImpl :: MyTree :: cache_articles (std::set<const Article*> s)
   Queue::tasks_t tasks;
   ArticleCache& cache(_data.get_cache());
   foreach_const (std::set<const Article*>, s, it)
-    tasks.push_back (new TaskArticle (_data, _data, **it, cache, _data));
+    if (!_data.is_read(*it))
+      tasks.push_back (new TaskArticle (_data, _data, **it, cache, _data));
   if (!tasks.empty())
     q->add_tasks (tasks, Queue::BOTTOM);
 }
@@ -268,15 +271,12 @@ DataImpl :: MyTree :: download_articles (std::set<const Article*> s)
   Queue * q (_data.get_queue());
   if (!q) return;
 
-  std::string path; /// TODO default path from prefs !!
   Queue::tasks_t tasks;
   ArticleCache& cache(_data.get_cache());
 
-  if (path.empty())
-    path = file :: get_temp_attach_path();
-
   foreach_const (std::set<const Article*>, s, it)
-    tasks.push_back (new TaskArticle (_data, _data, **it, cache, _data, 0, TaskArticle::DECODE, path));
+    if (!_data.is_read(*it))
+      tasks.push_back (new TaskArticle (_data, _data, **it, cache, _data, 0, TaskArticle::DECODE, _save_path));
   if (!tasks.empty())
     q->add_tasks (tasks, Queue::BOTTOM);
 }
diff --git a/pan/data-impl/rules-filter.cc b/pan/data-impl/rules-filter.cc
index dfd8e1a..3d9db1d 100644
--- a/pan/data-impl/rules-filter.cc
+++ b/pan/data-impl/rules-filter.cc
@@ -31,9 +31,6 @@ using namespace pan;
 void
 RulesFilter :: finalize (Data& data)
 {
-
-//  std::cerr<<"finalize "<<_delete.size()<<std::endl;
-
   data.delete_articles (_delete);
   _delete.clear();
 
@@ -41,7 +38,12 @@ RulesFilter :: finalize (Data& data)
   data.mark_read ((const Article**)&tmp.front(), tmp.size());
   _mark_read.clear();
 
+  const std::vector<const Article*> tmp2 ( _cached.begin(),  _cached.end());
+  data.mark_read ((const Article**)&tmp2.front(), tmp2.size());
   _cached.clear();
+
+  const std::vector<const Article*> tmp3 (_downloaded.begin(), _downloaded.end());
+  data.mark_read ((const Article**)&tmp3.front(), tmp3.size());
   _downloaded.clear();
 }
 
diff --git a/pan/data-impl/speed-test-load-group.cc b/pan/data-impl/speed-test-load-group.cc
index 89cff4e..3880285 100644
--- a/pan/data-impl/speed-test-load-group.cc
+++ b/pan/data-impl/speed-test-load-group.cc
@@ -12,7 +12,7 @@ int main (int argc, char *argv[])
     const Quark group (argv[1]);
     for (int i=0; i<8; ++i) {
       DataImpl data;
-      Data::ArticleTree * tree (data.group_get_articles (group));
+      Data::ArticleTree * tree (data.group_get_articles (group,Quark("")));
       delete tree;
     }
   }
diff --git a/pan/data/data.h b/pan/data/data.h
index 5aad9f1..f38a37c 100644
--- a/pan/data/data.h
+++ b/pan/data/data.h
@@ -480,6 +480,7 @@ namespace pan
         * Get a collection of headers that match the specified filter.
         */
        virtual ArticleTree* group_get_articles (const Quark       & group,
+                                                const Quark       & save_path,
                                                 const ShowType      show_type = SHOW_ARTICLES,
                                                 const FilterInfo  * criteria = 0,
                                                 const RulesInfo   * rules    = 0,
diff --git a/pan/gui/gui.cc b/pan/gui/gui.cc
index 40f2099..164ac69 100644
--- a/pan/gui/gui.cc
+++ b/pan/gui/gui.cc
@@ -212,7 +212,7 @@ GUI :: GUI (Data& data, Queue& queue, ArticleCache& cache, EncodeCache& encode_c
 
   //_group_pane = new GroupPane (*this, data, _prefs);
   _group_pane = new GroupPane (*this, data, _prefs);
-  _header_pane = new HeaderPane (*this, data, _queue, _cache, _prefs, *this);
+  _header_pane = new HeaderPane (*this, data, _queue, _cache, _prefs, _group_prefs, *this);
   _body_pane = new BodyPane (data, _cache, _prefs);
 
   std::string path = "/ui/main-window-toolbar";
diff --git a/pan/gui/header-pane.cc b/pan/gui/header-pane.cc
index b3fe766..cbef674 100644
--- a/pan/gui/header-pane.cc
+++ b/pan/gui/header-pane.cc
@@ -539,9 +539,14 @@ HeaderPane :: set_group (const Quark& new_group)
     delete _atree;
     _atree = 0;
 
+    char * pch = g_build_filename (g_get_home_dir(), "News", NULL);
+    Quark path(_group_prefs.get_string (_group, "default-group-save-path", pch));
+    g_free(pch);
+    std::cerr<<path<<std::endl;
+
     if (!_group.empty())
     {
-      _atree = _data.group_get_articles (new_group, _show_type, &_filter,&_rules,&_queue);
+      _atree = _data.group_get_articles (new_group, path, _show_type, &_filter,&_rules,&_queue);
       _atree->add_listener (this);
 
       rebuild ();
@@ -1663,11 +1668,13 @@ HeaderPane :: HeaderPane (ActionManager       & action_manager,
                           Queue               & queue,
                           ArticleCache        & cache,
                           Prefs               & prefs,
+                          GroupPrefs          & group_prefs,
                           WaitUI              & wait):
   _action_manager (action_manager),
   _data (data),
   _queue (queue),
   _prefs (prefs),
+  _group_prefs (group_prefs),
   _wait (wait),
   _atree (0),
   _root (0),
diff --git a/pan/gui/header-pane.h b/pan/gui/header-pane.h
index 425e85d..d0e0348 100644
--- a/pan/gui/header-pane.h
+++ b/pan/gui/header-pane.h
@@ -32,6 +32,7 @@
 #include <pan/gui/action-manager.h>
 #include <pan/gui/pan-tree.h>
 #include <pan/gui/prefs.h>
+#include <pan/gui/group-prefs.h>
 #include <pan/gui/wait.h>
 
 namespace pan
@@ -75,7 +76,7 @@ namespace pan
     private ArticleCache::Listener
   {
     public:
-      HeaderPane (ActionManager&, Data& data, Queue&, ArticleCache&, Prefs&, WaitUI&);
+      HeaderPane (ActionManager&, Data& data, Queue&, ArticleCache&, Prefs&, GroupPrefs&, WaitUI&);
       ~HeaderPane ();
 
     public:
@@ -291,6 +292,7 @@ namespace pan
       Data& _data;
       Queue& _queue;
       Prefs& _prefs;
+      GroupPrefs& _group_prefs;
       WaitUI& _wait;
       Quark _group;
       Data::ArticleTree * _atree;
diff --git a/pan/gui/save-ui.cc b/pan/gui/save-ui.cc
index 21a4cf3..7b75101 100644
--- a/pan/gui/save-ui.cc
+++ b/pan/gui/save-ui.cc
@@ -284,7 +284,7 @@ SaveDialog :: SaveDialog (Prefs                       & prefs,
   GtkWidget *t, *w, *h;
   t = HIG :: workarea_create ();
 
-  HIG :: workarea_add_section_spacer (t, row, have_group_default?4:3);
+  HIG :: workarea_add_section_spacer (t, row, have_group_default ? 4 : 3);
 
   if (path_mode==PATH_GROUP && !have_group_default)
       path_mode = PATH_ENTRY;



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