1 /*
2  * gnote
3  *
4  * Copyright (C) 2010-2014,2017,2019-2020 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 #include <glibmm/i18n.h>
23 
24 #include "iconmanager.hpp"
25 #include "ignote.hpp"
26 #include "notemanager.hpp"
27 #include "notebookmanager.hpp"
28 #include "specialnotebooks.hpp"
29 
30 
31 namespace gnote {
32 namespace notebooks {
33 
34 
get_tag() const35 Tag::Ptr SpecialNotebook::get_tag() const
36 {
37   return Tag::Ptr();
38 }
39 
get_template_note() const40 Note::Ptr SpecialNotebook::get_template_note() const
41 {
42   return std::static_pointer_cast<Note>(m_note_manager.get_or_create_template_note());
43 }
44 
45 
AllNotesNotebook(NoteManagerBase & manager)46 AllNotesNotebook::AllNotesNotebook(NoteManagerBase & manager)
47   : SpecialNotebook(manager, _("All"))
48 {
49 }
50 
get_normalized_name() const51 Glib::ustring AllNotesNotebook::get_normalized_name() const
52 {
53   return "___NotebookManager___AllNotes__Notebook___";
54 }
55 
contains_note(const Note::Ptr & note,bool include_system)56 bool AllNotesNotebook::contains_note(const Note::Ptr & note, bool include_system)
57 {
58   if(include_system) {
59     return true;
60   }
61   return !is_template_note(note);
62 }
63 
add_note(const Note::Ptr &)64 bool AllNotesNotebook::add_note(const Note::Ptr &)
65 {
66   return false;
67 }
68 
get_icon(IconManager & m)69 Glib::RefPtr<Gdk::Pixbuf> AllNotesNotebook::get_icon(IconManager & m)
70 {
71   return m.get_icon(IconManager::FILTER_NOTE_ALL, 22);
72 }
73 
74 
UnfiledNotesNotebook(NoteManagerBase & manager)75 UnfiledNotesNotebook::UnfiledNotesNotebook(NoteManagerBase & manager)
76   : SpecialNotebook(manager, _("Unfiled"))
77 {
78 }
79 
get_normalized_name() const80 Glib::ustring UnfiledNotesNotebook::get_normalized_name() const
81 {
82   return "___NotebookManager___UnfiledNotes__Notebook___";
83 }
84 
contains_note(const Note::Ptr & note,bool include_system)85 bool UnfiledNotesNotebook::contains_note(const Note::Ptr & note, bool include_system)
86 {
87   bool contains = m_note_manager.notebook_manager().get_notebook_from_note(note) == nullptr;
88   if(!contains || include_system) {
89     return contains;
90   }
91   return !is_template_note(note);
92 }
93 
add_note(const Note::Ptr & note)94 bool UnfiledNotesNotebook::add_note(const Note::Ptr & note)
95 {
96   m_note_manager.notebook_manager().move_note_to_notebook(note, Notebook::Ptr());
97   return true;
98 }
99 
get_icon(IconManager & m)100 Glib::RefPtr<Gdk::Pixbuf> UnfiledNotesNotebook::get_icon(IconManager & m)
101 {
102   return m.get_icon(IconManager::FILTER_NOTE_UNFILED, 22);
103 }
104 
105 
PinnedNotesNotebook(NoteManagerBase & manager)106 PinnedNotesNotebook::PinnedNotesNotebook(NoteManagerBase & manager)
107   : SpecialNotebook(manager, C_("notebook", "Important"))
108 {
109 }
110 
get_normalized_name() const111 Glib::ustring PinnedNotesNotebook::get_normalized_name() const
112 {
113   return "___NotebookManager___PinnedNotes__Notebook___";
114 }
115 
contains_note(const Note::Ptr & note,bool)116 bool PinnedNotesNotebook::contains_note(const Note::Ptr & note, bool)
117 {
118   return note->is_pinned();
119 }
120 
add_note(const Note::Ptr & note)121 bool PinnedNotesNotebook::add_note(const Note::Ptr & note)
122 {
123   note->set_pinned(true);
124   return true;
125 }
126 
get_icon(IconManager & m)127 Glib::RefPtr<Gdk::Pixbuf> PinnedNotesNotebook::get_icon(IconManager & m)
128 {
129   return m.get_icon(IconManager::PIN_DOWN, 22);
130 }
131 
132 
ActiveNotesNotebook(NoteManagerBase & manager)133 ActiveNotesNotebook::ActiveNotesNotebook(NoteManagerBase & manager)
134   : SpecialNotebook(manager, _("Active"))
135 {
136   manager.signal_note_deleted
137     .connect(sigc::mem_fun(*this, &ActiveNotesNotebook::on_note_deleted));
138 }
139 
get_normalized_name() const140 Glib::ustring ActiveNotesNotebook::get_normalized_name() const
141 {
142   return "___NotebookManager___ActiveNotes__Notebook___";
143 }
144 
contains_note(const Note::Ptr & note,bool include_system)145 bool ActiveNotesNotebook::contains_note(const Note::Ptr & note, bool include_system)
146 {
147   bool contains = m_notes.find(note) != m_notes.end();
148   if(!contains || include_system) {
149     return contains;
150   }
151   return !is_template_note(note);
152 }
153 
add_note(const Note::Ptr & note)154 bool ActiveNotesNotebook::add_note(const Note::Ptr & note)
155 {
156   if(m_notes.insert(note).second) {
157     signal_size_changed();
158   }
159 
160   return true;
161 }
162 
get_icon(IconManager & m)163 Glib::RefPtr<Gdk::Pixbuf> ActiveNotesNotebook::get_icon(IconManager & m)
164 {
165   return m.get_icon(IconManager::ACTIVE_NOTES, 22);
166 }
167 
on_note_deleted(const NoteBase::Ptr & note)168 void ActiveNotesNotebook::on_note_deleted(const NoteBase::Ptr & note)
169 {
170   std::set<Note::Ptr>::iterator iter = m_notes.find(std::static_pointer_cast<Note>(note));
171   if(iter != m_notes.end()) {
172     m_notes.erase(iter);
173     signal_size_changed();
174   }
175 }
176 
empty()177 bool ActiveNotesNotebook::empty()
178 {
179   if(m_notes.size() == 0) {
180     return true;
181   }
182 
183   // ignore template notes
184   Tag::Ptr templ_tag = template_tag();
185   for(const Note::Ptr & note : m_notes) {
186     if(!note->contains_tag(templ_tag)) {
187       return false;
188     }
189   }
190 
191   return true;
192 }
193 
194 
195 }
196 }
197 
198