1 /* 2 * gnote 3 * 4 * Copyright (C) 2012-2015,2017,2019 Aurimas Cernius 5 * Copyright (C) 2009 Hubert Figuiere 6 * 7 * This program is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 22 23 24 #ifndef _NOTEBOOK_MANAGER_HPP__ 25 #define _NOTEBOOK_MANAGER_HPP__ 26 27 #include <sigc++/signal.h> 28 #include <gtkmm/liststore.h> 29 #include <gtkmm/treemodel.h> 30 #include <gtkmm/treemodelsort.h> 31 #include <gtkmm/treemodelfilter.h> 32 33 #include "notebooks/notebook.hpp" 34 #include "note.hpp" 35 #include "tag.hpp" 36 37 namespace gnote { 38 39 class IGnote; 40 41 42 namespace notebooks { 43 44 45 class NotebookManager 46 { 47 public: 48 typedef sigc::signal<void, const Note &, const Notebook::Ptr &> NotebookEventHandler; 49 50 NotebookManager(NoteManagerBase &); 51 void init(); 52 note_manager() const53 NoteManagerBase & note_manager() const 54 { 55 return m_note_manager; 56 } is_adding_notebook() const57 bool is_adding_notebook() const 58 { 59 return m_adding_notebook; 60 } 61 get_notebooks()62 Glib::RefPtr<Gtk::TreeModel> get_notebooks() 63 { return m_filteredNotebooks; } 64 /// <summary> 65 /// A Gtk.TreeModel that contains all of the items in the 66 /// NotebookManager TreeStore including SpecialNotebooks 67 /// which are used in the "Search All Notes" window. 68 /// </summary> 69 /// <param name="notebookName"> 70 /// A <see cref="System.String"/> 71 /// </param> 72 /// <returns> 73 /// A <see cref="Notebook"/> 74 /// </returns> get_notebooks_with_special_items()75 Glib::RefPtr<Gtk::TreeModel> get_notebooks_with_special_items() 76 { return m_notebooks_to_display; } 77 78 Notebook::Ptr get_notebook(const Glib::ustring & notebookName) const; 79 bool notebook_exists(const Glib::ustring & notebookName) const; 80 Notebook::Ptr get_or_create_notebook(const Glib::ustring &); 81 bool add_notebook(const Notebook::Ptr &); 82 void delete_notebook(const Notebook::Ptr &); 83 bool get_notebook_iter(const Notebook::Ptr &, Gtk::TreeIter & ); 84 Notebook::Ptr get_notebook_from_note(const NoteBase::Ptr &); 85 Notebook::Ptr get_notebook_from_tag(const Tag::Ptr &); 86 static bool is_notebook_tag(const Tag::Ptr &); 87 static Notebook::Ptr prompt_create_new_notebook(IGnote &, Gtk::Window *); 88 static Notebook::Ptr prompt_create_new_notebook(IGnote &, Gtk::Window *, const Note::List & notesToAdd); 89 static void prompt_delete_notebook(IGnote &, Gtk::Window *, const Notebook::Ptr &); 90 bool move_note_to_notebook (const Note::Ptr &, const Notebook::Ptr &); 91 signal_note_added_to_notebook()92 NotebookEventHandler & signal_note_added_to_notebook() 93 { return m_note_added_to_notebook; } 94 signal_note_removed_from_notebook()95 NotebookEventHandler & signal_note_removed_from_notebook() 96 { return m_note_removed_from_notebook; } 97 active_notes_notebook()98 Notebook::Ptr & active_notes_notebook() 99 { 100 return m_active_notes; 101 } 102 103 sigc::signal<void> signal_notebook_list_changed; 104 sigc::signal<void, const Note &, bool> signal_note_pin_status_changed; 105 private: 106 static int compare_notebooks_sort_func(const Gtk::TreeIter &, const Gtk::TreeIter &); 107 void load_notebooks(); 108 bool filter_notebooks_to_display(const Gtk::TreeIter &); 109 void on_active_notes_size_changed(); 110 static bool filter_notebooks(const Gtk::TreeIter &); 111 112 class ColumnRecord 113 : public Gtk::TreeModelColumnRecord 114 { 115 public: ColumnRecord()116 ColumnRecord() 117 { add(m_col1); } 118 Gtk::TreeModelColumn<Notebook::Ptr> m_col1; 119 }; 120 121 ColumnRecord m_column_types; 122 Glib::RefPtr<Gtk::ListStore> m_notebooks; 123 Glib::RefPtr<Gtk::TreeModelSort> m_sortedNotebooks; 124 Glib::RefPtr<Gtk::TreeModelFilter> m_notebooks_to_display; 125 Glib::RefPtr<Gtk::TreeModelFilter> m_filteredNotebooks; 126 // <summary> 127 // The key for this dictionary is Notebook.Name.ToLower (). 128 // </summary> 129 std::map<Glib::ustring, Gtk::TreeIter> m_notebookMap; 130 //object locker = new object (); 131 bool m_adding_notebook; 132 NotebookEventHandler m_note_added_to_notebook; 133 NotebookEventHandler m_note_removed_from_notebook; 134 Notebook::Ptr m_active_notes; 135 NoteManagerBase & m_note_manager; 136 }; 137 138 } 139 140 } 141 142 #endif 143