paperbox r199 - in trunk: . src



Author: markoa
Date: Mon Oct 13 23:21:19 2008
New Revision: 199
URL: http://svn.gnome.org/viewvc/paperbox?rev=199&view=rev

Log:
Started work towards sorting box

Modified:
   trunk/ChangeLog
   trunk/src/browser.cc
   trunk/src/browser.hh
   trunk/src/main-window.cc
   trunk/src/main-window.hh

Modified: trunk/src/browser.cc
==============================================================================
--- trunk/src/browser.cc	(original)
+++ trunk/src/browser.cc	Mon Oct 13 23:21:19 2008
@@ -95,6 +95,7 @@
         uri_queue_ = uris;
 
         // begin retrieving information
+        signal_retrieval_started_.emit();
         Glib::signal_idle().connect(
             sigc::mem_fun(*this, &Browser::on_idle_initial_document_retrieval));
     }
@@ -119,6 +120,7 @@
             LOG_DD("Cancelling document retrieval from tracker - "
                    << "is it (re)indexing? "
                    << "Try running Paperbox again after a minute.");
+            signal_retrieval_finished_.emit();
             return false; // idle function done
         }
 
@@ -144,7 +146,24 @@
 
         uri_queue_.pop();
 
-        return (uri_queue_.empty()) ? false /* done with all */ : true;
+        if (uri_queue_.empty()) {
+            signal_retrieval_finished_.emit();
+            return false; // done with all
+        } else {
+            return true; // continue working in idle time
+        }
+    }
+
+    sigc::signal<void>&
+    Browser::signal_retrieval_started()
+    {
+        return signal_retrieval_started_;
+    }
+
+    sigc::signal<void>&
+    Browser::signal_retrieval_finished()
+    {
+        return signal_retrieval_finished_;
     }
 
     Browser::SignalNewDocument&
@@ -287,37 +306,31 @@
     }
 
     void
-    Browser::get_all_documents(doc_vector& docs)
+    Browser::get_all_documents(doc_vector& docs, DocumentSorting sorting)
     {
         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());
 
-        for ( ; it != end; ++it)
-            docs.push_back(it->second);
+        if (sorting == DOCUMENT_SORTING_ALPHABETICAL) {
+            //
+        } else if (sorting == DOCUMENT_SORTING_BY_DATE) {
+            sort(docs.begin(), docs.end(), doc_mtime_compare_desc());
+        }
     }
 
     void
     Browser::get_recent_documents(doc_vector& docs, int count)
     {
-        list<shared_ptr<Document> > ldocs;
-        get_all_documents(ldocs);
-
-        // sort by modtime, descending
-        ldocs.sort(doc_mtime_compare_desc());
-
+        doc_vector all_docs;
+        get_all_documents(all_docs);
+        sort(docs.begin(), docs.end(), doc_mtime_compare_desc());
+        
         // copy and return
-        list<shared_ptr<Document> >::iterator it(ldocs.begin());
-        list<shared_ptr<Document> >::iterator end(ldocs.end());
+        doc_vector::iterator it(all_docs.begin());
+        doc_vector::iterator end(all_docs.end());
         for ( int i = 0; (it != end) && (i < count); ++it) {
             docs.push_back(*it);
             ++i;
@@ -327,11 +340,11 @@
     void
     Browser::get_untagged_documents(doc_vector& docs)
     {
-        list<shared_ptr<Document> > all_docs;
+        doc_vector all_docs;
         get_all_documents(all_docs);
 
-        list<shared_ptr<Document> >::iterator it(all_docs.begin());
-        list<shared_ptr<Document> >::iterator end(all_docs.end());
+        doc_vector::iterator it(all_docs.begin());
+        doc_vector::iterator end(all_docs.end());
 
         for ( ; it != end; ++it)
             if (! (*it)->get_tags().size())

Modified: trunk/src/browser.hh
==============================================================================
--- trunk/src/browser.hh	(original)
+++ trunk/src/browser.hh	Mon Oct 13 23:21:19 2008
@@ -23,7 +23,6 @@
 #ifndef __PAPER_BOX_BROWSER__
 #define __PAPER_BOX_BROWSER__
 
-#include <list>
 #include <map>
 #include <memory>
 #include <queue>
@@ -38,6 +37,12 @@
 
     typedef std::vector<boost::shared_ptr<Document> > doc_vector;
 
+    enum DocumentSorting {
+        DOCUMENT_SORTING_NONE,
+        DOCUMENT_SORTING_ALPHABETICAL,
+        DOCUMENT_SORTING_BY_DATE,
+    };
+
     class Browser : public sigc::trackable, private boost::noncopyable
     {
     public:
@@ -71,8 +76,8 @@
 
         void get_all_tags(std::list<Glib::ustring>& tags);
 
-        void get_all_documents(doc_vector& docs);
-        void get_all_documents(std::list<boost::shared_ptr<Document> >& docs);
+        void get_all_documents(doc_vector& docs,
+                               DocumentSorting sorting = DOCUMENT_SORTING_NONE);
 
         void get_recent_documents(doc_vector& docs, int count);
 
@@ -87,6 +92,9 @@
 
         void dump_document_data();
 
+        sigc::signal<void>& signal_retrieval_started();
+        sigc::signal<void>& signal_retrieval_finished();
+
         SignalNewDocument& signal_new_document();
         SignalTagsChanged& signal_tags_changed();
 
@@ -111,6 +119,8 @@
         std::queue<Glib::ustring> uri_queue_;
         doc_map docs_;
 
+        sigc::signal<void> signal_retrieval_started_;
+        sigc::signal<void> signal_retrieval_finished_;
         SignalNewDocument signal_new_document_;
         SignalTagsChanged signal_tags_changed_;
 

Modified: trunk/src/main-window.cc
==============================================================================
--- trunk/src/main-window.cc	(original)
+++ trunk/src/main-window.cc	Mon Oct 13 23:21:19 2008
@@ -95,6 +95,12 @@
     }
 
     ///
+    
+    enum BROWSING_MODE {
+        BROWSING_ALPHABETICAL,
+        BROWSING_BY_DATE,
+        BROWSING_DAY_BY_DAY
+    };
 
     const int DOCS_ALL = 1;
     const int DOCS_RECENT = 2;
@@ -107,6 +113,7 @@
         :
         Gtk::Window(cobject),
         glade_(glade),
+        in_retrieval_(false),
         hpane_(0),
         left_top_vbox_(0),
         tile_view_(0),
@@ -173,6 +180,7 @@
     {
         get_widgets_from_ui_file();
         init_toolbar();
+        init_sorting_area();
         setup_tiles();
 
         label_tags_.set_markup(boldify(_("Tags")));
@@ -258,6 +266,24 @@
     }
 
     void
+    MainWindow::init_sorting_area()
+    {
+        sorting_label_.set_text("Browsing mode");
+
+        sorting_combo_.append_text("Alphabetical");
+        sorting_combo_.append_text("By date");
+        sorting_combo_.append_text("Day by day");
+        sorting_combo_.signal_changed().connect(
+                sigc::mem_fun(*this, &MainWindow::on_sorting_changed));
+
+        sorting_hbox_.set_spacing(5);
+        sorting_hbox_.pack_start(sorting_label_, false, false);
+        sorting_hbox_.pack_start(sorting_combo_, false, false);
+
+        left_top_vbox_->pack_start(sorting_hbox_, false, false);
+    }
+
+    void
     MainWindow::setup_tiles()
     {
         tile_view_ = Gtk::manage(new DocumentTileView());
@@ -406,6 +432,12 @@
     void
     MainWindow::connect_signals()
     {
+        browser_->signal_retrieval_started().connect(
+            sigc::mem_fun(*this, &MainWindow::on_retrieval_started));
+
+        browser_->signal_retrieval_finished().connect(
+            sigc::mem_fun(*this, &MainWindow::on_retrieval_finished));
+
         browser_->signal_new_document().connect(
             sigc::mem_fun(*this, &MainWindow::on_new_document));
 
@@ -422,6 +454,20 @@
             sigc::mem_fun(*this, &MainWindow::on_tag_clicked));
     }
 
+    void
+    MainWindow::on_retrieval_started()
+    {
+        in_retrieval_ = true;
+        hide_widgets_in_retrieval();
+    }
+
+    void
+    MainWindow::on_retrieval_finished()
+    {
+        in_retrieval_ = false;
+        show_widgets_after_retrieval();
+    }
+
     // Invoked from Browser during idle time.
     // All this should be re-thought when we get xesam dbus api in tracker.
     void
@@ -442,6 +488,8 @@
             model_->add_tag(*it);
 
         show_all_children();
+        if (in_retrieval_)
+            hide_widgets_in_retrieval();
     }
 
     void
@@ -500,4 +548,28 @@
         tag_cloud_.reset_selection();
     }
 
+    void
+    MainWindow::on_sorting_changed()
+    {
+        int sorting = sorting_combo_.get_active_row_number();
+        
+        if (sorting == BROWSING_BY_DATE) {
+            doc_vector docs;
+            browser_->get_all_documents(docs, DOCUMENT_SORTING_BY_DATE);
+            render_documents(docs);
+        }
+    }
+
+    void
+    MainWindow::hide_widgets_in_retrieval()
+    {
+        sorting_hbox_.hide_all();
+    }
+
+    void
+    MainWindow::show_widgets_after_retrieval()
+    {
+        sorting_hbox_.show_all();
+    }
+
 } // namespace paperbox

Modified: trunk/src/main-window.hh
==============================================================================
--- trunk/src/main-window.hh	(original)
+++ trunk/src/main-window.hh	Mon Oct 13 23:21:19 2008
@@ -60,12 +60,16 @@
 
     protected:
         void init_gui(const boost::shared_ptr<Config>& cfg);
+
         void get_widgets_from_ui_file();
         void init_toolbar();
+        void init_sorting_area();
         void setup_tiles();
+        
+        void connect_signals();
+
         void setup_categories();
         void reload_category_view();
-        void connect_signals();
 
         void render_new_tile_set(
             const std::vector<boost::shared_ptr<Document> >& docs);
@@ -75,6 +79,10 @@
 
         /*** Signal handlers ***/
         void on_menu_about();
+        
+        void on_retrieval_started();
+
+        void on_retrieval_finished();
 
         void on_new_document(const boost::shared_ptr<Document>& doc);
 
@@ -89,6 +97,13 @@
                                   const Gtk::TreeModel::Path& path,
                                   bool path_currently_selected);
 
+        void on_sorting_changed();
+
+        // some widgets should not be available while retrieval gives
+        // stochastic ordering of documents
+        void hide_widgets_in_retrieval();
+        void show_widgets_after_retrieval();
+
         /*** Members ***/
         Browser* browser_;
 
@@ -96,6 +111,8 @@
         Glib::RefPtr<Gtk::UIManager> ui_manager_;
         Glib::RefPtr<Gtk::ActionGroup> action_group_;
 
+        bool in_retrieval_; // flags retrieval from tracker being in progress
+
         /* * Child widgets * */
 
         Gtk::VBox* menu_vbox_;
@@ -103,6 +120,9 @@
         // ~left side~
         Gtk::HPaned*      hpane_;
         Gtk::VBox*        left_top_vbox_;
+        Gtk::HBox         sorting_hbox_;
+        Gtk::Label        sorting_label_;
+        Gtk::ComboBoxText sorting_combo_;
         DocumentTileView* tile_view_;
 
         boost::shared_ptr<TileSet> tiles_;



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