[pan2] * sanity checks for gtk_text_buffers * taskarticle paused status beyond restarts



commit f33bf628f1e8c4b503d9e1d53b9cb2b4182304fc
Author: Heinrich MÃlller <henmull src gnome org>
Date:   Sat May 26 07:23:52 2012 +0200

    * sanity checks for gtk_text_buffers
    * taskarticle paused status beyond restarts

 pan/gui/group-prefs-dialog.cc |   25 ++++++++++++++-----------
 pan/gui/group-prefs-dialog.h  |    2 --
 pan/gui/post-ui.cc            |   15 ++++++++++-----
 pan/tasks/nzb.cc              |   11 ++++++++++-
 pan/tasks/queue.cc            |   26 +++++++++++++++++++++-----
 pan/tasks/task-article.cc     |    3 ++-
 pan/tasks/task-article.h      |   16 +++-------------
 pan/tasks/task.h              |    2 ++
 8 files changed, 62 insertions(+), 38 deletions(-)
---
diff --git a/pan/gui/group-prefs-dialog.cc b/pan/gui/group-prefs-dialog.cc
index 9af45ca..2c9fa85 100644
--- a/pan/gui/group-prefs-dialog.cc
+++ b/pan/gui/group-prefs-dialog.cc
@@ -131,9 +131,11 @@ GroupPrefsDialog :: save_from_gui ()
   }
 #endif
 
+  GdkColor col;
+  gtk_color_button_get_color (GTK_COLOR_BUTTON(_group_color), &col);
   foreach_const (quarks_v, _groups, it)
   {
-    _group_prefs.set_group_color(*it, _color);
+    _group_prefs.set_group_color(*it, col);
   }
 
   _group_prefs.save () ;
@@ -228,23 +230,24 @@ namespace
     return w;
   }
 
-  void color_set_cb (GtkColorButton* b, gpointer p)
-  {
-    GroupPrefsDialog* dialog = static_cast<GroupPrefsDialog*>(p);
-	  GdkColor col;
-	  gtk_color_button_get_color (b, &(dialog->get_color()));
-  }
+//  void color_set_cb (GtkColorButton* b, gpointer p)
+//  {
+//    GroupPrefsDialog* dialog = static_cast<GroupPrefsDialog*>(p);
+//	  GdkColor col;
+//	  gtk_color_button_get_color (b, &col);
+//	  dialog->_color = col;
+//  }
 
-  GtkWidget* new_color_button (const Quark& group, GroupPrefs& prefs, GroupPrefsDialog* dialog)
+  GtkWidget* new_color_button (const Quark& group, GroupPrefs& prefs, GroupPrefsDialog* dialog, GtkWidget* w)
   {
     GdkColor color;
-    GtkStyle *style = gtk_rc_get_style(dialog->root());
+    GtkStyle *style = gtk_rc_get_style(w);
     if(!gtk_style_lookup_color(style, "text_color", &color))
       gdk_color_parse("black", &color);
 
     const GdkColor& val (prefs.get_group_color (group, GroupPrefs::color_to_string(color)));
     GtkWidget * b = gtk_color_button_new_with_color (&val);
-    g_signal_connect (b, "color-set", G_CALLBACK(color_set_cb), dialog);
+//    g_signal_connect (b, "color-set", G_CALLBACK(color_set_cb), dialog);
     return b;
   }
 
@@ -305,7 +308,7 @@ GroupPrefsDialog :: GroupPrefsDialog (Data            & data,
     w = _spellchecker_language = create_spellcheck_combo_box ( groups[0], group_prefs);
     HIG :: workarea_add_row (t, &row, _("Spellchecker _language:"), w);
 #endif
-    w = _group_color = new_color_button (groups[0], _group_prefs, this);
+    w = _group_color = new_color_button (groups[0], _group_prefs, this, dialog);
     HIG :: workarea_add_row(t, &row, _("Group color:"), w);
 
   gtk_box_pack_start ( GTK_BOX( gtk_dialog_get_content_area( GTK_DIALOG( dialog))), t, true, true, 0);
diff --git a/pan/gui/group-prefs-dialog.h b/pan/gui/group-prefs-dialog.h
index 89b9b34..86e06ac 100644
--- a/pan/gui/group-prefs-dialog.h
+++ b/pan/gui/group-prefs-dialog.h
@@ -49,7 +49,6 @@ namespace pan
       GtkWidget    * _profile;
       GtkWidget    * _spellchecker_language;
       GtkWidget    * _group_color;
-      GdkColor       _color;
       GtkWidget    * _save_path;
 
     private:
@@ -57,7 +56,6 @@ namespace pan
       void save_from_gui ();
 
     public:
-      	 GdkColor& get_color() { return _color; }
       	 GtkWidget* get_color_button() { return _group_color; }
       	 const quarks_v& get_groups() { return _groups; }
       	 GroupPrefs& get_prefs() { return _group_prefs; }
diff --git a/pan/gui/post-ui.cc b/pan/gui/post-ui.cc
index 46601d6..e7e71d1 100644
--- a/pan/gui/post-ui.cc
+++ b/pan/gui/post-ui.cc
@@ -378,7 +378,8 @@ PostUI :: set_wrap_mode (bool wrap)
     const std::string s (get_body());
     gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW(_body_view),
                                  wrap ? GTK_WRAP_WORD : GTK_WRAP_NONE);
-    gtk_text_buffer_set_text (_body_buf, s.c_str(), s.size());
+    if (!s.empty())
+      gtk_text_buffer_set_text (_body_buf, s.c_str(), s.size());
   }
 }
 
@@ -1970,7 +1971,8 @@ PostUI :: apply_profile_to_body ()
   }
 
   GtkTextBuffer * buf (_body_buf);
-  gtk_text_buffer_set_text (buf, body.c_str(), body.size());
+  if (!body.empty())
+    gtk_text_buffer_set_text (buf, body.c_str(), body.size());
 
   // set & scroll-to the insert point
   GtkTextIter iter;
@@ -2027,7 +2029,8 @@ PostUI :: apply_profile_to_headers ()
   std::string s;
   foreach_const (Profile::headers_t, headers, it)
     s += it->first + ": " + it->second + "\n";
-  gtk_text_buffer_set_text (buf, s.c_str(), s.size());
+  if (!s.empty())
+    gtk_text_buffer_set_text (buf, s.c_str(), s.size());
 }
 
 namespace
@@ -2146,7 +2149,8 @@ PostUI :: set_message (GMimeMessage * message)
   }
 
   s = utf8ize (data.visible_headers);
-  gtk_text_buffer_set_text (_headers_buf, s.c_str(), -1);
+  if (!s.empty())
+    gtk_text_buffer_set_text (_headers_buf, s.c_str(), -1);
   _hidden_headers = data.hidden_headers;
 
   // update body
@@ -2159,7 +2163,8 @@ PostUI :: set_message (GMimeMessage * message)
       s = TextMassager().fill (s);
       s += "\n\n";
     }
-    gtk_text_buffer_set_text (_body_buf, s.c_str(), s.size());
+    if (!s.empty())
+      gtk_text_buffer_set_text (_body_buf, s.c_str(), s.size());
   }
 
   // apply the profiles
diff --git a/pan/tasks/nzb.cc b/pan/tasks/nzb.cc
index 176aaf9..5975bb7 100644
--- a/pan/tasks/nzb.cc
+++ b/pan/tasks/nzb.cc
@@ -71,6 +71,7 @@ namespace
     quarks_t groups;
     std::string text;
     std::string path;
+    std::string paused;
     PartBatch parts;
     tasks_t tasks;
     Article a;
@@ -92,6 +93,7 @@ namespace
       groups.clear ();
       text.clear ();
       path.clear ();
+      paused.clear ();
       a.clear ();
       bytes = 0;
       number = 0;
@@ -152,6 +154,9 @@ namespace
     else if (!strcmp(element_name,"path"))
       mc.path = mc.text;
 
+    else if (!strcmp(element_name,"paused"))
+      mc.paused = mc.text;
+
     else if (!strcmp (element_name, "file"))
     {
       mc.parts.sort ();
@@ -164,7 +169,9 @@ namespace
           mc.a.xref.insert (*sit, *git, 0);
       }
       const StringView p (mc.path.empty() ? mc.fallback_path : StringView(mc.path));
-      mc.tasks.push_back (new TaskArticle (mc.ranks, mc.gs, mc.a, mc.cache, mc.read, 0, TaskArticle::DECODE, p));
+      TaskArticle* a = new TaskArticle (mc.ranks, mc.gs, mc.a, mc.cache, mc.read, 0, TaskArticle::DECODE, p);
+      a->set_paused(mc.paused == "1");
+      mc.tasks.push_back (a);
     }
 
   }
@@ -283,6 +290,8 @@ NZB :: nzb_to_xml (std::ostream             & out,
         escaped (out, path.to_view());
         out << "</path>\n";
       }
+      out << indent(depth) <<"<paused>";
+      out << task->get_paused() << "</paused>\n";
 
       // what groups was this crossposted in?
       quarks_t groups;
diff --git a/pan/tasks/queue.cc b/pan/tasks/queue.cc
index 133470a..30d2fd6 100644
--- a/pan/tasks/queue.cc
+++ b/pan/tasks/queue.cc
@@ -166,10 +166,6 @@ Queue :: upkeep ()
   foreach (std::set<Task*>, active, it)
     process_task (*it);
 
-  //upkeep on paused upload slots
-//  foreach (std::set<TaskUpload*>, _uploads, it)
-//    process_task (*it);
-
   // idle socket upkeep
   foreach (pools_t, _pools, it)
     it->second->idle_upkeep ();
@@ -548,6 +544,12 @@ Queue :: stop_tasks (const tasks_t& tasks)
     if (_tasks.index_of (task) != -1) {
       _stopped.insert (task);
       process_task (task);
+      TaskArticle* ta = dynamic_cast<TaskArticle*>(*it);
+      if (ta)
+      {
+        Task* t = (Task*)*it;
+        t->get_state().set_paused();
+      }
     }
   }
 }
@@ -560,6 +562,12 @@ Queue :: restart_tasks (const tasks_t& tasks)
     if (_tasks.index_of(task) != -1) {
       _stopped.erase (task);
       process_task (task);
+      TaskArticle* ta = dynamic_cast<TaskArticle*>(*it);
+      if (ta)
+      {
+        Task* t = (Task*)*it;
+        t->get_state().set_working();
+      }
     }
   }
 }
@@ -575,10 +583,18 @@ Queue :: add_task (Task * task, AddMode mode)
 void
 Queue :: add_tasks (const tasks_t& tasks, AddMode mode)
 {
+  tasks_t paused_tasks;
   foreach_const (tasks_t, tasks, it) {
     TaskArticle * ta (dynamic_cast<TaskArticle*>(*it));
     if (ta)
+    {
       _mids.insert (ta->get_article().message_id);
+      const bool paused (ta->get_paused());
+      if (paused)
+      {
+        _stopped.insert(*it);
+      }
+    }
   }
 
   if (mode == TOP)
@@ -588,7 +604,7 @@ Queue :: add_tasks (const tasks_t& tasks, AddMode mode)
   else
     _tasks.add (tasks);
 
-  // asdf
+  // process all new tasks
   tasks_t tmp (tasks);
   foreach (tasks_t, tmp, it)
     process_task (*it);
diff --git a/pan/tasks/task-article.cc b/pan/tasks/task-article.cc
index 3f718bd..f5de9e8 100644
--- a/pan/tasks/task-article.cc
+++ b/pan/tasks/task-article.cc
@@ -105,7 +105,8 @@ TaskArticle :: TaskArticle (const ServerRank          & server_rank,
   _decoder_has_run (false),
   _groups(get_groups_str(article)),
   _attachment(filename),
-  _options(options)
+  _options(options),
+  _paused(false)
 {
 
   cache.reserve (article.get_part_mids());
diff --git a/pan/tasks/task-article.h b/pan/tasks/task-article.h
index c8c87f5..7365f8c 100644
--- a/pan/tasks/task-article.h
+++ b/pan/tasks/task-article.h
@@ -72,6 +72,8 @@ namespace pan
       void  set_save_path (const Quark& q) { _save_path = q;}
       const Article& get_article () const { return _article; }
       const std::string& get_groups () const { return _groups; }
+      const bool get_paused () const { return _paused; }
+      void set_paused (bool val) { _paused = val; }
 
     public: // Task subclass
       unsigned long get_bytes_remaining () const;
@@ -112,19 +114,7 @@ namespace pan
       bool _decoder_has_run;
       std::string _groups;
       const SaveOptions _options;
-
-
-//      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;
+      bool _paused;
 
       struct Needed {
         std::string message_id;
diff --git a/pan/tasks/task.h b/pan/tasks/task.h
index b1a9455..9fa2968 100644
--- a/pan/tasks/task.h
+++ b/pan/tasks/task.h
@@ -136,6 +136,8 @@ namespace pan
 
          const State& get_state () const { return _state; }
 
+         State& get_state () { return _state; }
+
          const Quark& get_type () const { return _type; }
 
          virtual unsigned long get_bytes_remaining () const = 0;



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