[gnote] Reuse Notebook::contains_note for filtering



commit d30f31e9b8db186dd66102448ba7f41d925e2d5b
Author: Aurimas Äernius <aurisc4 gmail com>
Date:   Sat Nov 10 19:07:45 2012 +0200

    Reuse Notebook::contains_note for filtering
    
    When selected notebook changes, use Notebook::contains_note
    when filtering notes in selected notebook.
    Make this method virtual and reimplement it in special notebooks
    to make them also work properly.

 src/notebooks/notebook.cpp |   19 +++++++++++++++++++
 src/notebooks/notebook.hpp |    5 ++++-
 src/searchnoteswidget.cpp  |   15 ++-------------
 3 files changed, 25 insertions(+), 14 deletions(-)
---
diff --git a/src/notebooks/notebook.cpp b/src/notebooks/notebook.cpp
index fea0575..f020573 100644
--- a/src/notebooks/notebook.cpp
+++ b/src/notebooks/notebook.cpp
@@ -27,6 +27,7 @@
 #include "gnote.hpp"
 #include "notemanager.hpp"
 #include "notebooks/notebook.hpp"
+#include "notebooks/notebookmanager.hpp"
 #include "tagmanager.hpp"
 
 namespace gnote {
@@ -215,6 +216,12 @@ namespace notebooks {
   }
 
 
+  bool AllNotesNotebook::contains_note(const Note::Ptr &)
+  {
+    return true;
+  }
+
+
   UnfiledNotesNotebook::UnfiledNotesNotebook()
     : SpecialNotebook(_("Unfiled Notes"))
   {
@@ -226,6 +233,12 @@ namespace notebooks {
   }
 
 
+  bool UnfiledNotesNotebook::contains_note(const Note::Ptr & note)
+  {
+    return !notebooks::NotebookManager::instance().get_notebook_from_note(note);
+  }
+
+
   PinnedNotesNotebook::PinnedNotesNotebook()
     : SpecialNotebook(_("Pinned Notes"))
   {
@@ -236,5 +249,11 @@ namespace notebooks {
     return "___NotebookManager___PinnedNotes__Notebook___";
   }
 
+
+  bool PinnedNotesNotebook::contains_note(const Note::Ptr & note)
+  {
+    return note->is_pinned();
+  }
+
 }
 }
diff --git a/src/notebooks/notebook.hpp b/src/notebooks/notebook.hpp
index d22edcb..ad311b5 100644
--- a/src/notebooks/notebook.hpp
+++ b/src/notebooks/notebook.hpp
@@ -51,7 +51,7 @@ public:
   Note::Ptr find_template_note() const;
   virtual Note::Ptr   get_template_note() const;
   Note::Ptr create_notebook_note();
-  bool contains_note(const Note::Ptr &);
+  virtual bool contains_note(const Note::Ptr &);
   static std::string normalize(const std::string & s);
 ////
   virtual ~Notebook()
@@ -100,6 +100,7 @@ public:
   typedef std::tr1::shared_ptr<AllNotesNotebook> Ptr;
   AllNotesNotebook();
   virtual std::string get_normalized_name() const;
+  virtual bool        contains_note(const Note::Ptr &);
 };
 
 
@@ -115,6 +116,7 @@ public:
   typedef std::tr1::shared_ptr<UnfiledNotesNotebook> Ptr;
   UnfiledNotesNotebook();
   virtual std::string get_normalized_name() const;
+  virtual bool        contains_note(const Note::Ptr &);
 };
 
 
@@ -125,6 +127,7 @@ public:
   typedef std::tr1::shared_ptr<PinnedNotesNotebook> Ptr;
   PinnedNotesNotebook();
   virtual std::string get_notmalized_name() const;
+  virtual bool        contains_note(const Note::Ptr &);
 };
 
 
diff --git a/src/searchnoteswidget.cpp b/src/searchnoteswidget.cpp
index 32cecb7..c30aab9 100644
--- a/src/searchnoteswidget.cpp
+++ b/src/searchnoteswidget.cpp
@@ -768,19 +768,8 @@ bool SearchNotesWidget::filter_notes(const Gtk::TreeIter & iter)
   }
 
   notebooks::Notebook::Ptr selected_notebook = get_selected_notebook();
-  if(std::tr1::dynamic_pointer_cast<notebooks::UnfiledNotesNotebook>(selected_notebook)) {
-    // If the note belongs to a notebook, return false
-    // since the only notes that should be shown in this
-    // case are notes that are unfiled (not in a notebook).
-    if(notebooks::NotebookManager::instance().get_notebook_from_note(note)) {
-      return false;
-    }
-  }
-  else if(std::tr1::dynamic_pointer_cast<notebooks::PinnedNotesNotebook>(selected_notebook)) {
-    // Filter out unpinned notes
-    if(!note->is_pinned()) {
-      return false;
-    }
+  if(!selected_notebook || !selected_notebook->contains_note(note)) {
+    return false;
   }
 
   bool passes_search_filter = filter_by_search(note);



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