[pan2] fixed behaviour of mark_read in taskarticle according to action-implied post-action or simple gui in



commit f21f939139508d3ae83580e6fdeffc3824b185ce
Author: Heinrich MÃller <henmull src gnome org>
Date:   Fri Jul 13 07:41:44 2012 +0200

    fixed behaviour of mark_read in taskarticle according to action-implied post-action or simple gui interaction
    (marks read if either the flag in prefs is set to do this after an filter-based action occurred or by default)

 pan/data-impl/data-impl.cc |    4 ++--
 pan/data-impl/data-impl.h  |   11 ++++++++++-
 pan/data-impl/my-tree.cc   |   23 +++++++++++++++--------
 pan/data/data.h            |   10 +---------
 pan/gui/gui.cc             |   15 +++++++++++----
 pan/gui/pan.cc             |    1 +
 pan/gui/prefs-ui.cc        |   17 +++++++++--------
 pan/gui/save-attach-ui.cc  |    4 ++++
 pan/gui/save-ui.cc         |    4 ++++
 pan/tasks/decoder.cc       |    1 +
 pan/tasks/nzb.cc           |    4 +++-
 pan/tasks/task-article.cc  |   15 +++++++++++++--
 pan/tasks/task-article.h   |   11 +++++++++++
 13 files changed, 85 insertions(+), 35 deletions(-)
---
diff --git a/pan/data-impl/data-impl.cc b/pan/data-impl/data-impl.cc
index b68e2b2..30cadfc 100644
--- a/pan/data-impl/data-impl.cc
+++ b/pan/data-impl/data-impl.cc
@@ -78,8 +78,8 @@ DataImpl :: DataImpl (const StringView& cache_ext, Prefs& prefs, bool unit_test,
   _descriptions_loaded (false),
   newsrc_autosave_id (0),
   newsrc_autosave_timeout (0),
-  _rules_filter (prefs.get_flag("autocache-mark-read", false), prefs.get_flag("auto-dl-mark-read", false),
-                 prefs.get_flag("auto-delete-mark-read", false))
+  _rules_filter (prefs.get_flag("rules-autocache-mark-read", false), prefs.get_flag("rules-auto-dl-mark-read", false),
+                 prefs.get_flag("rules-autocache-mark-read", false))
 
 {
   rebuild_backend ();
diff --git a/pan/data-impl/data-impl.h b/pan/data-impl/data-impl.h
index 9f8faa6..14ff1d1 100644
--- a/pan/data-impl/data-impl.h
+++ b/pan/data-impl/data-impl.h
@@ -90,10 +90,20 @@ namespace pan
       virtual CertStore& get_certstore () { return _certstore; }
       virtual const CertStore& get_certstore () const { return _certstore; }
 
+      virtual Prefs& get_prefs () { return _prefs; }
+      virtual const Prefs& get_prefs () const { return _prefs; }
+
+      virtual Queue* get_queue () { return _queue; }
+      virtual const Queue* get_queue () const { return _queue; }
+
+      virtual void set_queue (Queue* q) { _queue = q; }
+
     private:
       ArticleCache _cache;
       EncodeCache _encode_cache;
       CertStore _certstore;
+      Prefs _prefs;
+      Queue* _queue;
 
     public:
 #ifdef HAVE_GKR
@@ -105,7 +115,6 @@ namespace pan
       void rebuild_backend ();
       const bool _unit_test;
       DataIO * _data_io;
-      Prefs& _prefs;
 
     /**
     *** SERVERS
diff --git a/pan/data-impl/my-tree.cc b/pan/data-impl/my-tree.cc
index 89f707a..c4d49a1 100644
--- a/pan/data-impl/my-tree.cc
+++ b/pan/data-impl/my-tree.cc
@@ -251,32 +251,39 @@ DataImpl :: MyTree :: apply_rules (const_nodes_v& candidates)
 void
 DataImpl :: MyTree :: cache_articles (std::set<const Article*> s)
 {
-  Queue * q (_data.get_queue());
-  if (!q) return;
+  Queue* queue (_data.get_queue());
+  Prefs& prefs (_data.get_prefs());
+  const bool action (prefs.get_flag("rules-autocache-mark-read", false));
+  const bool always (prefs.get_flag("mark-downloaded-articles-read", false));
 
   Queue::tasks_t tasks;
   ArticleCache& cache(_data.get_cache());
   foreach_const (std::set<const Article*>, s, it)
     if (!_data.is_read(*it))
-      tasks.push_back (new TaskArticle (_data, _data, **it, cache, _data));
+      tasks.push_back (new TaskArticle (_data, _data, **it, cache, _data,
+                                        always ? TaskArticle::ALWAYS_MARK : action ? TaskArticle::ACTION_TRUE : TaskArticle::ACTION_FALSE));
   if (!tasks.empty())
-    q->add_tasks (tasks, Queue::BOTTOM);
+    queue->add_tasks (tasks, Queue::BOTTOM);
 }
 
 void
 DataImpl :: MyTree :: download_articles (std::set<const Article*> s)
 {
-  Queue * q (_data.get_queue());
-  if (!q) return;
+  Queue* queue (_data.get_queue());
 
   Queue::tasks_t tasks;
   ArticleCache& cache(_data.get_cache());
+  Prefs& prefs (_data.get_prefs());
+  const bool action (prefs.get_flag("rules-auto-dl-mark-read", false));
+  const bool always (prefs.get_flag("mark-downloaded-articles-read", false));
 
   foreach_const (std::set<const Article*>, s, it)
     if (!_data.is_read(*it))
-      tasks.push_back (new TaskArticle (_data, _data, **it, cache, _data, 0, TaskArticle::DECODE, _save_path));
+      tasks.push_back (new TaskArticle (_data, _data, **it, cache, _data,
+                                        always ? TaskArticle::ALWAYS_MARK : action ? TaskArticle::ACTION_TRUE : TaskArticle::ACTION_FALSE,
+                                        0, TaskArticle::DECODE, _save_path));
   if (!tasks.empty())
-    q->add_tasks (tasks, Queue::BOTTOM);
+    queue->add_tasks (tasks, Queue::BOTTOM);
 }
 
 
diff --git a/pan/data/data.h b/pan/data/data.h
index e76a26a..7d4f4a8 100644
--- a/pan/data/data.h
+++ b/pan/data/data.h
@@ -34,7 +34,7 @@
 #include <pan/data/encode-cache.h>
 #include <pan/data/cert-store.h>
 #include <pan/data/server-info.h>
-
+#include <pan/gui/prefs.h>
 
 #ifdef HAVE_GKR
   #include <gnome-keyring-1/gnome-keyring.h>
@@ -592,14 +592,6 @@ namespace pan
 
        virtual void rescore () = 0;
 
-    public:
-      void set_queue (Queue* q) { _queue = q; }
-      Queue* get_queue () { return _queue; }
-
-    private:
-      Queue * _queue;
-
-
     /*****************************************************************
     ***
     ***  HEADERS - XOVER
diff --git a/pan/gui/gui.cc b/pan/gui/gui.cc
index 2b1658b..ffc508a 100644
--- a/pan/gui/gui.cc
+++ b/pan/gui/gui.cc
@@ -40,6 +40,7 @@ extern "C" {
 #include <pan/tasks/task-xover.h>
 #include <pan/tasks/nzb.h>
 #include <pan/icons/pan-pixbufs.h>
+#include <pan/data-impl/rules-filter.h>
 #include "actions.h"
 #include "body-pane.h"
 #include "dl-headers-ui.h"
@@ -685,12 +686,14 @@ void GUI :: do_save_articles_to_nzb ()
   foreach_const (std::vector<const Article*>, articles, it)
     copies.push_back (**it);
 
+  const bool always (_prefs.get_flag("mark-downloaded-articles-read", false));
+
   const std::string file (GUI :: prompt_user_for_filename (get_window(_root), _prefs));
     if (!file.empty()) {
       Queue::tasks_t tasks;
       std::string emptystring;
       foreach_const (std::vector<Article>, copies, it)
-        tasks.push_back (new TaskArticle (_data, _data, *it, _cache, _data, 0, TaskArticle::RAW,emptystring));
+        tasks.push_back (new TaskArticle (_data, _data, *it, _cache, _data, always ? TaskArticle::ALWAYS_MARK : TaskArticle::NEVER_MARK, 0, TaskArticle::RAW,emptystring));
 
       // write them to a file
       std::ofstream tmp(file.c_str());
@@ -765,6 +768,7 @@ namespace
 
 void GUI :: do_save_articles_from_nzb ()
 {
+  const bool always (_prefs.get_flag("mark-downloaded-articles-read", false));
   const Article* article (_header_pane->get_first_selected_article ());
   if (article)
   {
@@ -773,7 +777,7 @@ void GUI :: do_save_articles_from_nzb ()
     {
       SaveArticlesFromNZB * listener = new SaveArticlesFromNZB (_data, _queue, _root,
                                                                 _prefs, _cache, _encode_cache, *article, path);
-      Task * t = new TaskArticle (_data, _data, *article, _cache, _data, listener);
+      Task * t = new TaskArticle (_data, _data, *article, _cache, _data, always ? TaskArticle::ALWAYS_MARK : TaskArticle::NEVER_MARK, listener);
       _queue.add_task (t, Queue::TOP);
     }
   }
@@ -989,9 +993,11 @@ void GUI :: do_read_selected_article ()
   if (article)
   {
     const bool expand (_prefs.get_flag("expand-selected-articles",false));
+    const bool always (_prefs.get_flag("mark-downloaded-articles-read", false));
+
     if (expand) _header_pane->expand_selected ();
 
-    Task * t = new TaskArticle (_data, _data, *article, _cache, _data, this);
+    Task * t = new TaskArticle (_data, _data, *article, _cache, _data, always ? TaskArticle::ALWAYS_MARK : TaskArticle::NEVER_MARK, this);
     _queue.add_task (t, Queue::TOP);
   }
 }
@@ -999,9 +1005,10 @@ void GUI :: do_download_selected_article ()
 {
   typedef std::vector<const Article*> article_vector_t;
   const article_vector_t articles (_header_pane->get_full_selection_v ());
+  const bool always (_prefs.get_flag("mark-downloaded-articles-read", false));
   Queue::tasks_t tasks;
   foreach_const (article_vector_t, articles, it)
-    tasks.push_back (new TaskArticle (_data, _data, **it, _cache, _data));
+    tasks.push_back (new TaskArticle (_data, _data, **it, _cache, _data, always ? TaskArticle::ALWAYS_MARK : TaskArticle::NEVER_MARK));
   if (!tasks.empty())
     _queue.add_tasks (tasks, Queue::TOP);
 }
diff --git a/pan/gui/pan.cc b/pan/gui/pan.cc
index 0c39e64..2991745 100644
--- a/pan/gui/pan.cc
+++ b/pan/gui/pan.cc
@@ -913,6 +913,7 @@ main (int argc, char *argv[])
     WorkerPool worker_pool (4, true);
     SocketCreator socket_creator(data, certstore);
     Queue queue (data, data, &socket_creator, certstore, prefs, worker_pool, false, 32768);
+
     data.set_queue (&queue);
 
 #ifdef HAVE_DBUS
diff --git a/pan/gui/prefs-ui.cc b/pan/gui/prefs-ui.cc
index b9c1af8..323bf3b 100644
--- a/pan/gui/prefs-ui.cc
+++ b/pan/gui/prefs-ui.cc
@@ -724,7 +724,6 @@ PrefsDialog :: on_prefs_string_changed (const StringView& key, const StringView&
     _prefs.save();
     update_default_charset_label(value);
   }
-
 }
 
 void
@@ -953,7 +952,9 @@ PrefsDialog :: PrefsDialog (Prefs& prefs, GtkWindow* parent):
     HIG::workarea_add_section_divider (t, &row);
 
     HIG :: workarea_add_section_title (t, &row, _("Articles"));
-    HIG :: workarea_add_section_spacer (t, row, 5);
+    HIG :: workarea_add_section_spacer (t, row, 6);
+    w = new_check_button (_("Mark downloaded articles read"), "mark-downloaded-articles-read", false, prefs);
+    HIG :: workarea_add_wide_control (t, &row, w);
     w = new_check_button (_("Space selects next article rather than next unread"), "space-selects-next-article", true, prefs);
     HIG :: workarea_add_wide_control (t, &row, w);
     w = new_check_button (_("Expand threads upon selection"), "expand-selected-articles", false, prefs);
@@ -1098,16 +1099,16 @@ PrefsDialog :: PrefsDialog (Prefs& prefs, GtkWindow* parent):
     int i(0);
     GtkWidget** action_combo = new GtkWidget*[2];
     char* tmp = _("Mark affected articles read");
-    action_combo[i++] = new_check_button (tmp, "auto-delete-mark-read", false, prefs);
-    action_combo[i++] = new_check_button (tmp, "autocache-mark-read", false, prefs);
-    action_combo[i++] = new_check_button (tmp, "auto-dl-mark-read", false, prefs);
+    action_combo[i++] = new_check_button (tmp, "rules-autocache-mark-read", false, prefs);
+    action_combo[i++] = new_check_button (tmp, "rules-autocache-mark-read", false, prefs);
+    action_combo[i++] = new_check_button (tmp, "rules-auto-dl-mark-read", false, prefs);
     i=0;
 
     w = score_handler_new (prefs, "rules-delete-value", "never", b);
     h = gtk_hbox_new (false, PAD);
     gtk_box_pack_start (GTK_BOX(h), w, false, false, 0);
     gtk_box_pack_start (GTK_BOX(h), action_combo[i++], false, false, 0);
-    HIG :: workarea_add_row (t, &row, _("_Delete articles scoring at: "), w);
+    HIG :: workarea_add_row (t, &row, _("_Delete articles scoring at: "), h);
 
     w = score_handler_new (prefs, "rules-mark-read-value", "never", b);
     HIG :: workarea_add_row (t, &row, _("Mark articles as _read scoring at: "), w);
@@ -1272,11 +1273,11 @@ PrefsDialog :: PrefsDialog (Prefs& prefs, GtkWindow* parent):
   gtk_widget_show_all (scroll);
 
   gtk_notebook_append_page (GTK_NOTEBOOK(notebook), scroll, new_label_with_icon(_("_Shortcuts"), _("Shortcuts"), icon_prefs_hotkeys, prefs));
+  gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 0);
 
   gtk_widget_show_all (notebook);
   gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area( GTK_DIALOG(dialog))), notebook, true, true, 0);
 
-  gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 0);
-
   _root = dialog;
+
 }
diff --git a/pan/gui/save-attach-ui.cc b/pan/gui/save-attach-ui.cc
index 6777448..1483e79 100644
--- a/pan/gui/save-attach-ui.cc
+++ b/pan/gui/save-attach-ui.cc
@@ -28,6 +28,7 @@ extern "C" {
 #include <pan/tasks/task-article.h>
 #include <pan/tasks/queue.h>
 #include <pan/usenet-utils/text-massager.h>
+#include <pan/data-impl/rules-filter.h>
 #include "hig.h"
 #include "pad.h"
 #include "pan-file-entry.h"
@@ -106,6 +107,8 @@ SaveAttachmentsDialog :: response_cb (GtkDialog * dialog,
 
     std::string sep( self->_prefs.get_string("save-subj-seperator", "-") );
 
+    const bool always (self->_prefs.get_flag("mark-downloaded-articles-read", false));
+
     // make the tasks...
     Queue::tasks_t tasks;
     foreach_const (std::vector<Article>, self->_articles, it)
@@ -117,6 +120,7 @@ SaveAttachmentsDialog :: response_cb (GtkDialog * dialog,
                                         *it,
                                         self->_cache,
                                         self->_read,
+                                        always ? TaskArticle::ALWAYS_MARK : TaskArticle::NEVER_MARK,
                                         0,
                                         TaskArticle::DECODE,
                                         path,
diff --git a/pan/gui/save-ui.cc b/pan/gui/save-ui.cc
index 6d65ab1..7352153 100644
--- a/pan/gui/save-ui.cc
+++ b/pan/gui/save-ui.cc
@@ -28,6 +28,7 @@ extern "C" {
 #include <pan/tasks/task-article.h>
 #include <pan/tasks/queue.h>
 #include <pan/usenet-utils/text-massager.h>
+#include <pan/data-impl/rules-filter.h>
 #include "hig.h"
 #include "pad.h"
 #include "pan-file-entry.h"
@@ -114,6 +115,8 @@ SaveDialog :: response_cb (GtkDialog * dialog,
 
     std::string sep( self->_prefs.get_string("save-subj-seperator", "-") );
 
+    const bool always (self->_prefs.get_flag("mark-downloaded-articles-read", false));
+
     // make the tasks...
     Queue::tasks_t tasks;
     foreach_const (std::vector<Article>, self->_articles, it)
@@ -125,6 +128,7 @@ SaveDialog :: response_cb (GtkDialog * dialog,
                                         *it,
                                         self->_cache,
                                         self->_read,
+                                        always ? TaskArticle::ALWAYS_MARK : TaskArticle::NEVER_MARK,
                                         0,
                                         TaskArticle::SaveMode(save_mode),
                                         path));
diff --git a/pan/tasks/decoder.cc b/pan/tasks/decoder.cc
index 6b35f8a..18f8107 100644
--- a/pan/tasks/decoder.cc
+++ b/pan/tasks/decoder.cc
@@ -73,6 +73,7 @@ Decoder :: enqueue (TaskArticle                     * task,
   this->attachment_filename = filename;
 
   mark_read = false;
+
   percent = 0;
   num_scanned_files = 0;
   current_file.clear ();
diff --git a/pan/tasks/nzb.cc b/pan/tasks/nzb.cc
index efb791c..82fdab8 100644
--- a/pan/tasks/nzb.cc
+++ b/pan/tasks/nzb.cc
@@ -35,6 +35,7 @@ extern "C" {
 #include <pan/general/string-view.h>
 #include <pan/usenet-utils/mime-utils.h>
 #include <pan/general/utf8-utils.h>
+#include <pan/data-impl/rules-filter.h>
 #include "nzb.h"
 #include "task-article.h"
 #include "task-upload.h"
@@ -169,7 +170,8 @@ namespace
           mc.a.xref.insert (*sit, *git, 0);
       }
       const StringView p (mc.path.empty() ? mc.fallback_path : StringView(mc.path));
-      TaskArticle* a = new TaskArticle (mc.ranks, mc.gs, mc.a, mc.cache, mc.read, 0, TaskArticle::DECODE, p);
+      /// TODO get action mark read from prefs (?)
+      TaskArticle* a = new TaskArticle (mc.ranks, mc.gs, mc.a, mc.cache, mc.read, TaskArticle::NO_ACTION, 0, TaskArticle::DECODE, p);
       if (mc.paused == "1")
         a->set_start_paused(true);
       mc.tasks.push_back (a);
diff --git a/pan/tasks/task-article.cc b/pan/tasks/task-article.cc
index f5de9e8..7989861 100644
--- a/pan/tasks/task-article.cc
+++ b/pan/tasks/task-article.cc
@@ -88,6 +88,7 @@ TaskArticle :: TaskArticle (const ServerRank          & server_rank,
                             const Article             & article,
                             ArticleCache              & cache,
                             ArticleRead               & read,
+                            const ArticleActionType& mark_read_action,
                             Progress::Listener        * listener,
                             SaveMode                    save_mode,
                             const Quark               & save_path,
@@ -98,6 +99,7 @@ TaskArticle :: TaskArticle (const ServerRank          & server_rank,
   _server_rank (server_rank),
   _cache (cache),
   _read (read),
+  _mark_read_action (mark_read_action),
   _article (article),
   _time_posted (article.time_posted),
   _save_mode (save_mode),
@@ -392,8 +394,17 @@ TaskArticle :: on_worker_done (bool cancelled)
       verbose (it->c_str());
     }
 
-    if (_decoder->mark_read)
-      _read.mark_read(_article);
+    // marks read if either there was no filter action involved or
+    // the user chose to mark read after the action
+    const bool act_on_action (_mark_read_action == ACTION_TRUE);
+    const bool no_action (_mark_read_action == NO_ACTION);
+    const bool always (_mark_read_action == ALWAYS_MARK);
+    const bool never (_mark_read_action == NEVER_MARK);
+    if (!never)
+    {
+      if (_decoder->mark_read && (no_action || act_on_action || always))
+        _read.mark_read(_article);
+    }
 
     if (!_decoder->log_errors.empty())
       set_error (_decoder->log_errors.front());
diff --git a/pan/tasks/task-article.h b/pan/tasks/task-article.h
index b706d6f..105e679 100644
--- a/pan/tasks/task-article.h
+++ b/pan/tasks/task-article.h
@@ -54,6 +54,15 @@ namespace pan
         SAVE_AS
       };
 
+      enum ArticleActionType
+      {
+        ACTION_TRUE,
+        ACTION_FALSE,
+        NO_ACTION,
+        NEVER_MARK,
+        ALWAYS_MARK // TODO implement this in prefs (mark articles read after download ....)
+      };
+
       enum SaveMode { NONE=0, DECODE=(1<<0), RAW=(1<<1) };
 
       TaskArticle (const ServerRank   & server_rank,
@@ -61,6 +70,7 @@ namespace pan
                    const Article      & article,
                    ArticleCache       & cache,
                    ArticleRead        & read,
+                   const ArticleActionType&  mark_read_action,
                    Progress::Listener* l=0,
                    SaveMode             save_mode = NONE,
                    const Quark        & save_path = Quark(),
@@ -106,6 +116,7 @@ namespace pan
       const Article _article;
       const time_t _time_posted;
       StringView _attachment;
+      ArticleActionType _mark_read_action;
 
     private: // implementation
       const SaveMode _save_mode;



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