paperbox r119 - in trunk: . src



Author: markoa
Date: Sat Mar 15 11:41:05 2008
New Revision: 119
URL: http://svn.gnome.org/viewvc/paperbox?rev=119&view=rev

Log:
Document set switching on category selection changes

Modified:
   trunk/ChangeLog
   trunk/src/browser.cc
   trunk/src/browser.hh
   trunk/src/category.cc
   trunk/src/category.hh
   trunk/src/document.cc
   trunk/src/document.hh
   trunk/src/file-utils.cc
   trunk/src/file-utils.hh
   trunk/src/main-window.cc
   trunk/src/main-window.hh
   trunk/src/tracker-phone.cc

Modified: trunk/src/browser.cc
==============================================================================
--- trunk/src/browser.cc	(original)
+++ trunk/src/browser.cc	Sat Mar 15 11:41:05 2008
@@ -31,9 +31,27 @@
 namespace paperbox {
 
     using std::auto_ptr;
+    using std::list;
     using std::vector;
     using boost::shared_ptr;
 
+    ///
+
+    struct doc_mtime_compare_desc
+        : public std::binary_function<shared_ptr<Document>,
+                                      shared_ptr<Document>,
+                                      bool>
+    {
+        bool
+        operator()(const shared_ptr<Document>& lhs,
+                   const shared_ptr<Document>& rhs) const
+            {
+                return (lhs->get_mtime() > rhs->get_mtime());
+            }
+    };
+
+    ///
+
     auto_ptr<Browser> Browser::instance_;
 
     Browser*
@@ -218,7 +236,17 @@
     }
 
     void
-    Browser::get_all_documents(vector<shared_ptr<Document> >& docs)
+    Browser::get_all_documents(doc_vector& docs)
+    {
+        doc_map::iterator it(docs_.begin());
+        doc_map::iterator end(docs_.end());
+
+        for ( ; it != end; ++it)
+            docs.push_back(it->second);
+    }
+
+    void
+    Browser::get_all_documents(list<shared_ptr<Document> >& docs)
     {
         doc_map::iterator it(docs_.begin());
         doc_map::iterator end(docs_.end());
@@ -228,8 +256,26 @@
     }
 
     void
+    Browser::get_recent_documents(doc_vector& docs, int count)
+    {
+        list<shared_ptr<Document> > ldocs;
+        get_all_documents(ldocs);
+
+        //sort by modtime
+        ldocs.sort(doc_mtime_compare_desc());
+
+        // copy and return
+        list<shared_ptr<Document> >::iterator it(ldocs.begin());
+        list<shared_ptr<Document> >::iterator end(ldocs.end());
+        for ( int i = 0; (it != end) && (i < count*3); ++it) {
+            docs.push_back(*it);
+            ++i;
+        }
+    }
+
+    void
     Browser::get_documents_for_tag(const Glib::ustring& tag,
-                                   vector<shared_ptr<Document> >& docs_ret)
+                                   doc_vector& docs_ret)
     {
         doc_map::iterator it(docs_.begin());
         doc_map::iterator end(docs_.end());
@@ -241,4 +287,25 @@
         }
     }
 
+    void
+    Browser::get_documents_for_tag_bundle(const vector<Glib::ustring>& tags,
+                                          doc_vector& docs_ret)
+    {
+        doc_map::iterator it(docs_.begin());
+        doc_map::iterator end(docs_.end());
+
+        for ( ; it != end; ++it) {
+            shared_ptr<Document> doc = it->second;
+
+            vector<Glib::ustring>::const_iterator tit(tags.begin());
+            vector<Glib::ustring>::const_iterator tend(tags.end());
+            for ( ; tit != tend; ++tit) {
+                if (doc->contains_tag(*tit)) {
+                    docs_ret.push_back(doc);
+                    break;
+                }
+            }
+        }
+    }
+
 } // namespace paperbox

Modified: trunk/src/browser.hh
==============================================================================
--- trunk/src/browser.hh	(original)
+++ trunk/src/browser.hh	Sat Mar 15 11:41:05 2008
@@ -23,6 +23,7 @@
 #ifndef __PAPER_BOX_BROWSER__
 #define __PAPER_BOX_BROWSER__
 
+#include <list>
 #include <map>
 #include <memory>
 #include <queue>
@@ -35,6 +36,8 @@
 
 namespace paperbox {
 
+    typedef std::vector<boost::shared_ptr<Document> > doc_vector;
+
     class Browser : public sigc::trackable, private boost::noncopyable
     {
     public:
@@ -66,10 +69,17 @@
                         const Glib::ustring& from_tag,
                         const Glib::ustring& to_tag);
 
-        void get_all_documents(std::vector<boost::shared_ptr<Document> >& docs);
+        void get_all_documents(doc_vector& docs);
+        void get_all_documents(std::list<boost::shared_ptr<Document> >& docs);
+
+        void get_recent_documents(doc_vector& docs, int count);
 
         void get_documents_for_tag(const Glib::ustring& tag,
-                                   std::vector<boost::shared_ptr<Document> >& docs);
+                                   doc_vector& docs);
+
+        void get_documents_for_tag_bundle(
+            const std::vector<Glib::ustring>& tags,
+            doc_vector& docs);
 
         void dump_document_data();
 

Modified: trunk/src/category.cc
==============================================================================
--- trunk/src/category.cc	(original)
+++ trunk/src/category.cc	Sat Mar 15 11:41:05 2008
@@ -45,7 +45,7 @@
 
     // Loads open text stream's contents into a string list.
     void read_lines(std::ifstream& fs,
-                    std::list<std::string>& lines)
+                    std::vector<std::string>& lines)
     {
         std::string line;
 
@@ -59,7 +59,7 @@
     // TODO: clean up the mess with strings vs ustrings.
     // Loads open text stream's contents into a string list.
     void read_lines(std::ifstream& fs,
-                    std::list<Glib::ustring>& lines)
+                    std::vector<Glib::ustring>& lines)
     {
          std::string std_line;
 
@@ -75,7 +75,6 @@
 
     namespace bfs = boost::filesystem;
 
-    using std::list;
     using std::string;
     using std::vector;
 
@@ -119,7 +118,7 @@
             return false;
         }
 
-        list<string> tags;
+        vector<string> tags;
         read_lines(ifs, tags);
 
         if (find(tags.begin(), tags.end(), tag) != tags.end()) {
@@ -160,7 +159,7 @@
             return false;
         }
 
-        list<string> tags;
+        vector<string> tags;
         read_lines(ifs, tags);
 
         if (find(tags.begin(), tags.end(), tag.raw()) == tags.end()) {
@@ -174,8 +173,8 @@
         // rewrite the file with remaining tags
         bfs::ofstream fs(path_);
 
-        list<string>::iterator it(tags.begin());
-        list<string>::iterator end(tags.end());
+        vector<string>::iterator it(tags.begin());
+        vector<string>::iterator end(tags.end());
         for ( ; it != end; ++it) {
             fs << *it << std::endl;
         }
@@ -184,7 +183,7 @@
         return true;
     }
 
-    std::list<Glib::ustring>
+    std::vector<Glib::ustring>
     Category::get_tags() const
     {
         return tags_;
@@ -194,8 +193,8 @@
     Category::get_tags_as_string() const
     {
         Glib::ustring tag_text;
-        list<Glib::ustring>::const_iterator it(tags_.begin());
-        list<Glib::ustring>::const_iterator end(tags_.end());
+        vector<Glib::ustring>::const_iterator it(tags_.begin());
+        vector<Glib::ustring>::const_iterator end(tags_.end());
 
         if (it != end)
             tag_text = *it++;

Modified: trunk/src/category.hh
==============================================================================
--- trunk/src/category.hh	(original)
+++ trunk/src/category.hh	Sat Mar 15 11:41:05 2008
@@ -23,7 +23,6 @@
 #ifndef __PAPER_BOX_CATEGORY_HH__
 #define __PAPER_BOX_CATEGORY_HH__
 
-#include <list>
 #include <string>
 #include <vector>
 #include <boost/filesystem.hpp>
@@ -45,7 +44,7 @@
         bool remove_tag(const Glib::ustring& tag);
 
         std::string get_name() const;
-        std::list<Glib::ustring> get_tags() const;
+        std::vector<Glib::ustring> get_tags() const;
         Glib::ustring get_tags_as_string() const;
 
         static std::string get_default_path();
@@ -53,7 +52,7 @@
     protected:
         std::string name_;
         boost::filesystem::path path_;
-        std::list<Glib::ustring> tags_;
+        std::vector<Glib::ustring> tags_;
     };
 
     inline std::string

Modified: trunk/src/document.cc
==============================================================================
--- trunk/src/document.cc	(original)
+++ trunk/src/document.cc	Sat Mar 15 11:41:05 2008
@@ -104,6 +104,18 @@
         modtime_ = file_modtime;
     }
 
+    guint64
+    Document::get_mtime() const
+    {
+        return mtime_;
+    }
+
+    void
+    Document::set_mtime(guint64 mtime)
+    {
+        mtime_ = mtime;
+    }
+
     Glib::ustring
     Document::get_subject() const
     {

Modified: trunk/src/document.hh
==============================================================================
--- trunk/src/document.hh	(original)
+++ trunk/src/document.hh	Sat Mar 15 11:41:05 2008
@@ -42,6 +42,9 @@
         Glib::ustring get_modification_time() const;
         void          set_modification_time(const Glib::ustring& modtime);
 
+        guint64       get_mtime() const;
+        void          set_mtime(guint64 mtime);
+
         Glib::ustring get_subject() const;
         void          set_subject(const Glib::ustring& subject);
 
@@ -74,6 +77,7 @@
         Glib::ustring uri_;
 
         Glib::ustring file_name_;
+        guint64       mtime_;
         Glib::ustring modtime_;
         Glib::ustring subject_;
         Glib::ustring author_;

Modified: trunk/src/file-utils.cc
==============================================================================
--- trunk/src/file-utils.cc	(original)
+++ trunk/src/file-utils.cc	Sat Mar 15 11:41:05 2008
@@ -51,11 +51,11 @@
 	return result;
     }
 
-    Glib::ustring
-    get_file_modification_time(const Glib::ustring& uri)
+    void
+    get_file_modification_time(const Glib::ustring& uri,
+                               guint64& modtime,
+                               Glib::ustring& modtime_string)
     {
-        Glib::ustring res;
-
 #ifdef HAVE_GIO
         GFile* file;
         GFileQueryInfoFlags flags;
@@ -73,19 +73,19 @@
         if (info == NULL) {
             g_printerr ("Error getting time info: %s\n", error->message);
             g_error_free (error);
-            return res;
         }
 
         struct timeval tv;
         struct tm* ptm;
         char time_string[256];
 
-        tv.tv_sec = g_file_info_get_attribute_uint64 (info, "time::modified");
+        modtime = g_file_info_get_attribute_uint64 (info, "time::modified");
+        tv.tv_sec = modtime;
 
         ptm = localtime(&tv.tv_sec);
         strftime(time_string, sizeof(time_string), "%c", ptm);
 
-        res = Glib::locale_to_utf8(time_string);
+        modtime_string = Glib::locale_to_utf8(time_string);
 #else
         GnomeVFSFileInfo* info = NULL;
         GnomeVFSResult result;
@@ -95,17 +95,16 @@
                                           info,
                                           GNOME_VFS_FILE_INFO_DEFAULT);
 
-        if (result == GNOME_VFS_OK)
-            Glib::Util::get_modification_date(info->mtime, res);
-        else
+        if (result == GNOME_VFS_OK) {
+            modtime = info->mtime;
+            Glib::Util::get_modification_date(info->mtime, modtime_string);
+        } else
             g_warning("no file info for %s: %s",
                       uri.c_str(),
                       gnome_vfs_result_to_string (result));
 
         gnome_vfs_file_info_unref(info);
 #endif // HAVE_GIO
-
-        return res;
     }
 
 } // namespace paperbox

Modified: trunk/src/file-utils.hh
==============================================================================
--- trunk/src/file-utils.hh	(original)
+++ trunk/src/file-utils.hh	Sat Mar 15 11:41:05 2008
@@ -27,7 +27,9 @@
 
 namespace paperbox {
 
-    Glib::ustring get_file_modification_time(const Glib::ustring& path);
+    void get_file_modification_time(const Glib::ustring& path,
+                                    guint64& modtime,
+                                    Glib::ustring& modtime_string);
 
     bool open_file_with_xdg(const Glib::ustring& path);
 

Modified: trunk/src/main-window.cc
==============================================================================
--- trunk/src/main-window.cc	(original)
+++ trunk/src/main-window.cc	Sat Mar 15 11:41:05 2008
@@ -91,8 +91,9 @@
 
     ///
 
-    const int ITEM_ALL = 1;
-    const int ITEM_RECENT = 2;
+    const int DOCS_ALL = 1;
+    const int DOCS_RECENT = 2;
+    const int MAX_RECENT_DOCS = 7;
 
     MainWindow::MainWindow(GtkWindow* cobject,
                            const Glib::RefPtr<Gnome::Glade::Xml>& glade)
@@ -214,11 +215,41 @@
     }
 
     bool
-    MainWindow::on_category_selected(const Glib::RefPtr<Gtk::TreeModel>& ,
-                                     const Gtk::TreeModel::Path& /*path*/,
-                                     bool /*path_currently_selected*/)
-    {
-        //TODO
+    MainWindow::on_category_selected(const Glib::RefPtr<Gtk::TreeModel>& /*m*/,
+                                     const Gtk::TreeModel::Path& path,
+                                     bool path_selected)
+    {
+        Gtk::TreeModel::Row row = *(category_view_->treemodel->get_iter(path));
+        int id = row[category_view_->columns.col_id];
+        Glib::ustring cat_name = row[category_view_->columns.col_name];
+
+        if (! ((cat_name != selected_cat_name_) && (! path_selected)))
+            return true; // selection hasn't changed
+
+        selected_cat_name_ = cat_name;
+
+        vector<shared_ptr<Document> > docs;
+
+        // decide which set of documents to display
+        if (id == DOCS_ALL)
+            browser_->get_all_documents(docs);
+        else if (id == DOCS_RECENT)
+            browser_->get_recent_documents(docs, MAX_RECENT_DOCS);
+        else {
+            shared_ptr<Category> cat =
+                category_model_->get_category(selected_cat_name_);
+
+            if (! cat.get())
+                g_warning("Invalid selection for category %s",
+                          selected_cat_name_.c_str());
+            else {
+                vector<Glib::ustring> tags = cat->get_tags();
+                browser_->get_documents_for_tag_bundle(tags, docs);
+            }
+        }
+
+        render_documents(docs);
+
         return true;
     }
 
@@ -230,12 +261,12 @@
         Gtk::TreeModel::Row row;
 
         row = *(category_view_->treemodel->append());
-        row[category_view_->columns.col_id] = ITEM_ALL;
+        row[category_view_->columns.col_id] = DOCS_ALL;
         //TRANSLATORS: 'all' means 'all categories'
         row[category_view_->columns.col_name] = _("All");
 
         row = *(category_view_->treemodel->append());
-        row[category_view_->columns.col_id] = ITEM_RECENT;
+        row[category_view_->columns.col_id] = DOCS_RECENT;
         //TODO: verify the string and wrap in _()
         row[category_view_->columns.col_name] = "Recent";
 
@@ -265,9 +296,6 @@
         button_edit_category_.signal_clicked().connect(
             sigc::mem_fun(*this, &MainWindow::on_edit_category));
 
-        button_view_all_.signal_clicked().connect(
-            sigc::mem_fun(*this, &MainWindow::on_view_all));
-
         tile_view_->signal_tag_clicked().connect(
             sigc::mem_fun(*this, &MainWindow::on_tag_clicked));
 
@@ -335,16 +363,6 @@
     }
 
     void
-    MainWindow::on_view_all()
-    {
-        vector<shared_ptr<Document> > docs;
-        browser_->get_all_documents(docs);
-        render_new_tile_set(docs);
-        button_view_all_.set_sensitive(false);
-        tag_cloud_.reset_selection();
-    }
-
-    void
     MainWindow::on_edit_category()
     {
         shared_ptr<CategoryEditor> dialog(CategoryEditor::create());
@@ -355,4 +373,12 @@
         reload_category_view();
     }
 
+    void
+    MainWindow::render_documents(const vector<shared_ptr<Document> > docs)
+    {
+        render_new_tile_set(docs);
+        button_view_all_.set_sensitive(false);
+        tag_cloud_.reset_selection();
+    }
+
 } // namespace paperbox

Modified: trunk/src/main-window.hh
==============================================================================
--- trunk/src/main-window.hh	(original)
+++ trunk/src/main-window.hh	Sat Mar 15 11:41:05 2008
@@ -59,12 +59,14 @@
         void setup_pane_pos();
         void setup_categories();
         void reload_category_view();
-
         void connect_signals();
 
         void render_new_tile_set(
             const std::vector<boost::shared_ptr<Document> >& docs);
 
+        void render_documents(
+            const std::vector<boost::shared_ptr<Document> > docs);
+
         /*** Signal handlers ***/
         void on_new_document(const boost::shared_ptr<Document>& doc);
 
@@ -102,6 +104,7 @@
 
         Gtk::VBox* category_vbox_;
         boost::shared_ptr<CategoryView> category_view_;
+        Glib::ustring selected_cat_name_;
 
         Gtk::HBox*  category_buttons_hbox_;
         Gtk::Button button_edit_category_;

Modified: trunk/src/tracker-phone.cc
==============================================================================
--- trunk/src/tracker-phone.cc	(original)
+++ trunk/src/tracker-phone.cc	Sat Mar 15 11:41:05 2008
@@ -225,7 +225,9 @@
             document->set_file_name(file_name);
         }
 
-        Glib::ustring file_modified = get_file_modification_time (uri);
+        guint64 modtime;
+        Glib::ustring file_modified;
+        get_file_modification_time (uri, modtime, file_modified);
         document->set_modification_time(file_modified);
 
         if (! is_empty_string(keys[SUBJECT])) {



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