[pan2] remember last group/article



commit 8318800be89ff757921784e7094c468f3dc48f2b
Author: Heinrich MÃller <henmull src gnome org>
Date:   Thu May 31 02:31:21 2012 +0200

    remember last group/article

 pan/gui/body-pane.cc   |    3 +++
 pan/gui/body-pane.h    |    4 +++-
 pan/gui/group-pane.cc  |   16 ++++++++++++----
 pan/gui/group-pane.h   |    3 +++
 pan/gui/gui.cc         |   36 ++++++++++++++++++++++++++++++++++++
 pan/gui/gui.h          |    5 +++++
 pan/gui/header-pane.cc |    3 +--
 7 files changed, 63 insertions(+), 7 deletions(-)
---
diff --git a/pan/gui/body-pane.cc b/pan/gui/body-pane.cc
index 3f73e4e..4b8b7a7 100644
--- a/pan/gui/body-pane.cc
+++ b/pan/gui/body-pane.cc
@@ -1792,6 +1792,9 @@ BodyPane :: ~BodyPane ()
 
   foreach (std::set<char*>, _attach_names, it)
     g_free(*it);
+
+  // store last opened message in prefs
+  _prefs.set_string("last-opened-msg", get_message_id ().to_view());
 }
 
 
diff --git a/pan/gui/body-pane.h b/pan/gui/body-pane.h
index ecd9a69..4478218 100644
--- a/pan/gui/body-pane.h
+++ b/pan/gui/body-pane.h
@@ -97,13 +97,15 @@ namespace pan
     public:
       void set_character_encoding (const char * character_encoding);
 
+    public:
+      void set_text_from_message (GMimeMessage*);
+
     private:
       void refresh ();
       void refresh_fonts ();
       void refresh_colors ();
       bool read_more_or_less (bool more);
       char* body_to_utf8 (GMimePart*);
-      void set_text_from_message (GMimeMessage*);
       void append_part (GMimeObject*, GMimeObject*, GtkAllocation*);
       static gboolean expander_activated_idle (gpointer self);
       static void expander_activated_cb (GtkExpander*, gpointer self);
diff --git a/pan/gui/group-pane.cc b/pan/gui/group-pane.cc
index bcf4ffa..6f9f0f5 100644
--- a/pan/gui/group-pane.cc
+++ b/pan/gui/group-pane.cc
@@ -708,10 +708,6 @@ namespace
       g_snprintf (buf, sizeof(buf), " (%lu)", unread);
       group_name += buf;
     }
-    //if (unread || total)
-      //if (unread)
-      //  g_snprintf (buf, sizeof(buf), _(" (%lu of %lu)"), unread, total);
-      //else
     g_object_set (renderer, "text", group_name.c_str(),
                             "weight", (!is_g || unread ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL),
                             "foreground", pane->get_group_prefs().get_group_color_str(name).c_str(),
@@ -786,6 +782,18 @@ GroupPane :: find_next_subscribed_group (bool unread_only)
 }
 
 void
+GroupPane :: read_group (const StringView& groupname)
+{
+    GtkTreeView * view (GTK_TREE_VIEW (_tree_view));
+    PanTreeStore * tree (PAN_TREE_STORE(gtk_tree_view_get_model(view)));
+    GtkTreeIter iter;
+//    gtk_tree_model_iter_nth_child (model, &iter, 0, 0);
+    const MyRow* row = find_row (groupname);
+    iter = tree->get_iter (row);
+    read_group(gtk_tree_model_get_path(gtk_tree_view_get_model(view), &iter));
+}
+
+void
 GroupPane :: read_group (GtkTreePath * path)
 {
   g_assert (path);
diff --git a/pan/gui/group-pane.h b/pan/gui/group-pane.h
index 51906b9..b22b61e 100644
--- a/pan/gui/group-pane.h
+++ b/pan/gui/group-pane.h
@@ -73,6 +73,9 @@ namespace pan
       void read_group (GtkTreePath*);
       void read_next_group_impl (bool unread_only);
 
+    public:
+      void read_group (const StringView&);
+
     private:
       static void do_popup_menu (GtkWidget*, GdkEventButton*, gpointer);
       static gboolean on_button_pressed (GtkWidget*, GdkEventButton*, gpointer);
diff --git a/pan/gui/gui.cc b/pan/gui/gui.cc
index 1f0804f..141f61d 100644
--- a/pan/gui/gui.cc
+++ b/pan/gui/gui.cc
@@ -177,6 +177,38 @@ void GUI :: show_task_window_cb (GtkWidget *, gpointer gui_gpointer)
   static_cast<GUI*>(gui_gpointer)->activate_action ("show-task-window");
 }
 
+void
+GUI :: root_realized_cb (GtkWidget*, gpointer self_gpointer)
+{
+  GUI* gui (static_cast<GUI*>(self_gpointer));
+
+  StringView last_group = gui->_prefs.get_string("last-visited-group", "");
+  if (!last_group.empty())
+  {
+    gui->_group_pane->read_group(last_group.str);
+  }
+
+  // TODO if article is not cached, load with a taskarticle action!
+  StringView last_msg = gui->_prefs.get_string("last-opened-msg", "");
+  if (!last_msg.empty() && !last_group.empty())
+  {
+    GPGDecErr err;
+    mid_sequence_t files;
+    files.push_back(last_msg);
+    GMimeMessage* msg = gui->_cache.get_message(files,err);
+    gui->_body_pane->set_text_from_message(msg);
+
+//    Article article;
+//    PartBatch part_batch;
+//    last_msg = last_msg.substr(last_msg.strchr('<')+1, last_msg.strchr('>'));
+//    std::cerr<<"msg "<<last_msg<<"\n";
+//    part_batch.init (last_msg, 1, 0);
+//    part_batch.add_part (0, last_msg, 0);
+//    article.set_parts(part_batch);
+//    Task * t = new TaskArticle (_data, _data, article, _cache, _data, this);
+//    _queue.add_task (t, Queue::TOP);
+  }
+}
 
 GUI :: GUI (Data& data, Queue& queue, Prefs& prefs, GroupPrefs& group_prefs):
   _data (data),
@@ -352,6 +384,10 @@ GUI :: GUI (Data& data, Queue& queue, Prefs& prefs, GroupPrefs& group_prefs):
 #ifdef HAVE_GMIME_CRYPTO
   init_gpg();
 #endif
+
+  g_signal_connect (_root, "realize", G_CALLBACK(root_realized_cb), this);
+
+
 }
 
 namespace
diff --git a/pan/gui/gui.h b/pan/gui/gui.h
index 5a96e5f..bde4822 100644
--- a/pan/gui/gui.h
+++ b/pan/gui/gui.h
@@ -60,6 +60,9 @@ namespace pan
   {
 
     public:
+
+      typedef std::vector<Quark> mid_sequence_t;
+
       GUI (Data& data, Queue&, Prefs&, GroupPrefs&);
       virtual ~GUI ();
       GtkWidget* root () { return _root; }
@@ -271,6 +274,8 @@ namespace pan
 
       static void notebook_page_switched_cb (GtkNotebook*, GtkNotebookPage*, gint, gpointer);
 
+      static void root_realized_cb (GtkWidget*, gpointer self_gpointer);
+
     private:
       static void add_widget (GtkUIManager*, GtkWidget*, gpointer);
       static void server_list_dialog_destroyed_cb (GtkWidget*, gpointer);
diff --git a/pan/gui/header-pane.cc b/pan/gui/header-pane.cc
index b09ad05..4868863 100644
--- a/pan/gui/header-pane.cc
+++ b/pan/gui/header-pane.cc
@@ -1742,11 +1742,11 @@ HeaderPane :: ~HeaderPane ()
   }
   g_list_free (columns);
 
+  _prefs.set_string("last-visited-group", _group.to_view());
   set_group (Quark());
 
   for (guint i=0; i<ICON_QTY; ++i)
     g_object_unref (G_OBJECT(_icons[i].pixbuf));
-
 }
 
 GtkWidget*
@@ -1883,7 +1883,6 @@ HeaderPane :: HeaderPane (ActionManager       & action_manager,
   g_signal_connect (sel, "changed", G_CALLBACK(on_selection_changed), this);
   on_selection_changed (sel, this);
 
-
   g_signal_connect (w, "button-release-event", G_CALLBACK(on_button_pressed), this);
   g_signal_connect (w, "button-press-event", G_CALLBACK(on_button_pressed), this);
 



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