paperbox r118 - in trunk: . src



Author: markoa
Date: Thu Mar 13 20:02:48 2008
New Revision: 118
URL: http://svn.gnome.org/viewvc/paperbox?rev=118&view=rev

Log:
Display current categories in main window

Modified:
   trunk/ChangeLog
   trunk/src/category-editor.cc
   trunk/src/category-view.cc
   trunk/src/category-view.hh
   trunk/src/main-window.cc
   trunk/src/main-window.hh

Modified: trunk/src/category-editor.cc
==============================================================================
--- trunk/src/category-editor.cc	(original)
+++ trunk/src/category-editor.cc	Thu Mar 13 20:02:48 2008
@@ -180,10 +180,7 @@
         for ( ; it != end; ++it)
             add_new_row(*it);
 
-        // select the first list item, if any
-        if (! category_view_->treemodel->children().empty())
-            category_view_->selection->select(
-                category_view_->treemodel->children().begin());
+        category_view_->select_first();
     }
 
     void

Modified: trunk/src/category-view.cc
==============================================================================
--- trunk/src/category-view.cc	(original)
+++ trunk/src/category-view.cc	Thu Mar 13 20:02:48 2008
@@ -47,4 +47,12 @@
         treeview.append_column(_("Name"), columns.col_name);
     }
 
+    /// selects the first list item, if any
+    void
+    CategoryView::select_first()
+    {
+        if (! treemodel->children().empty())
+            selection->select(treemodel->children().begin());
+    }
+
 } // namespace paperbox

Modified: trunk/src/category-view.hh
==============================================================================
--- trunk/src/category-view.hh	(original)
+++ trunk/src/category-view.hh	Thu Mar 13 20:02:48 2008
@@ -48,6 +48,8 @@
         explicit CategoryView(Gtk::Box* parent);
         virtual ~CategoryView() {}
 
+        virtual void select_first();
+
         Gtk::Box*                        parent;
         Gtk::Label                       label_title;
         Gtk::TreeView                    treeview;

Modified: trunk/src/main-window.cc
==============================================================================
--- trunk/src/main-window.cc	(original)
+++ trunk/src/main-window.cc	Thu Mar 13 20:02:48 2008
@@ -21,12 +21,15 @@
  */
 
 #include <iostream>
+#include <list>
+#include <map>
 #include <vector>
 #include <glib/gi18n.h>
 #include <glibmm/markup.h>
 #include <gtkmm-utils/tile.h>
 #include "browser.hh"
 #include "category-editor.hh"
+#include "category-factory.hh"
 #include "file-utils.hh"
 #include "document-tag-cloud-model.hh"
 #include "document-tile.hh"
@@ -35,9 +38,62 @@
 
 namespace paperbox {
 
+    using std::list;
+    using std::map;
     using std::vector;
     using boost::shared_ptr;
 
+    ///
+
+    class CategoryModel
+    {
+    public:
+        explicit CategoryModel() {}
+        ~CategoryModel() {}
+
+        std::list<shared_ptr<Category> > load_data();
+
+        shared_ptr<Category> get_category(const Glib::ustring& name);
+
+    protected:
+        std::map<Glib::ustring, shared_ptr<Category> > data_;
+    };
+
+    ///
+
+    list<shared_ptr<Category> >
+    CategoryModel::load_data()
+    {
+        list<shared_ptr<Category> > categories(
+            CategoryFactory::load_categories());
+
+        list<shared_ptr<Category> >::iterator it(categories.begin());
+        list<shared_ptr<Category> >::iterator end(categories.end());
+
+        for ( ; it != end; ++it)
+            data_[(*it)->get_name()] = *it;
+
+        return categories;
+    }
+
+    shared_ptr<Category>
+    CategoryModel::get_category(const Glib::ustring& name)
+    {
+        shared_ptr<Category> ptr;
+        map<Glib::ustring, shared_ptr<Category> >::iterator it = 
+            data_.find(name);
+
+        if (it != data_.end())
+            ptr = it->second;
+
+        return ptr;
+    }
+
+    ///
+
+    const int ITEM_ALL = 1;
+    const int ITEM_RECENT = 2;
+
     MainWindow::MainWindow(GtkWindow* cobject,
                            const Glib::RefPtr<Gnome::Glade::Xml>& glade)
         :
@@ -60,10 +116,10 @@
 
         browser_ = Browser::instance();
         tiles_.reset(new TileSet());
+        category_model_.reset(new CategoryModel());
+        reload_category_view();
 
         connect_signals();
-        
-        //browser_->dump_document_data();
     }
 
     MainWindow::~MainWindow()
@@ -153,8 +209,6 @@
         category_view_.reset(new CategoryView(category_vbox_));
         category_vbox_->pack_start(button_edit_category_, false, false);
 
-        add_default_category();
-
         category_view_->selection->set_select_function(
             sigc::mem_fun(*this, &MainWindow::on_category_selected));
     }
@@ -169,13 +223,34 @@
     }
 
     void
-    MainWindow::add_default_category()
+    MainWindow::reload_category_view()
     {
-        Gtk::TreeModel::Row row = *(category_view_->treemodel->append());
-        
-        row[category_view_->columns.col_id] = 1;
+        category_view_->treemodel->clear();
+
+        Gtk::TreeModel::Row row;
+
+        row = *(category_view_->treemodel->append());
+        row[category_view_->columns.col_id] = ITEM_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;
+        //TODO: verify the string and wrap in _()
+        row[category_view_->columns.col_name] = "Recent";
+
+
+        list<shared_ptr<Category> > categories(category_model_->load_data());
+        
+        list<shared_ptr<Category> >::iterator it(categories.begin());
+        list<shared_ptr<Category> >::iterator end(categories.end());
+
+        for ( ; it != end; ++it) {
+            row = *(category_view_->treemodel->append());
+            row[category_view_->columns.col_name] = (*it)->get_name();
+        }
+
+        category_view_->select_first();
     }
 
     void
@@ -247,8 +322,6 @@
     void
     MainWindow::on_tag_clicked(const Glib::ustring& tag)
     {
-        //g_debug("selected tag %s", tag.c_str());
-
         vector<shared_ptr<Document> > docs;
         browser_->get_documents_for_tag(tag, docs);
 
@@ -279,7 +352,7 @@
 
         dialog->run();
 
-        //TODO: update category treeview
+        reload_category_view();
     }
 
 } // namespace paperbox

Modified: trunk/src/main-window.hh
==============================================================================
--- trunk/src/main-window.hh	(original)
+++ trunk/src/main-window.hh	Thu Mar 13 20:02:48 2008
@@ -40,6 +40,7 @@
 namespace paperbox {
 
     class Browser;
+    class CategoryModel;
     class Document;
 
     class MainWindow : public Gtk::Window
@@ -57,7 +58,7 @@
         void setup_tiles();
         void setup_pane_pos();
         void setup_categories();
-        void add_default_category();
+        void reload_category_view();
 
         void connect_signals();
 
@@ -105,6 +106,8 @@
         Gtk::HBox*  category_buttons_hbox_;
         Gtk::Button button_edit_category_;
 
+        boost::shared_ptr<CategoryModel> category_model_;
+
         // tag cloud
         Gtk::VBox*  tag_cloud_vbox_;
         Gtk::Label  label_tags_;



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