/
notebook.cpp
207 lines (170 loc) · 5.93 KB
/
notebook.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
* gnote
*
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <boost/format.hpp>
//#include <glibmm/i18n.h>
#include "string.hpp"
#include "gnote.hpp"
#include "notemanager.hpp"
#include "notebook.hpp"
#include "tag.hpp"
#include "tagmanager.hpp"
#include <iostream>
namespace gnote {
namespace notebooks {
const char * Notebook::NOTEBOOK_TAG_PREFIX = "notebook:";
/// <summary>
/// Construct a new Notebook with a given name
/// </summary>
/// <param name="name">
/// A <see cref="System.String"/>. This is the name that will be used
/// to identify the notebook.
/// </param>
Notebook::Notebook(const std::string & name, bool is_special)
{
// is special assume the name as is, and we don't want a tag.
if(is_special) {
m_name = name;
}
else {
set_name(name);
m_tag = TagManager::obj().get_or_create_system_tag ( std::string(NOTEBOOK_TAG_PREFIX) + name);
}
}
/// <summary>
/// Construct a new Notebook with the specified notebook system tag.
/// </summary>
/// <param name="notebookTag">
/// A <see cref="Tag"/>. This must be a system notebook tag.
/// </param>
Notebook::Notebook(const Tag::Ptr & notebookTag)
{
std::cout << __PRETTY_FUNCTION__ << std::endl;
// Parse the notebook name from the tag name
std::string systemNotebookPrefix = std::string(Tag::SYSTEM_TAG_PREFIX)
+ NOTEBOOK_TAG_PREFIX;
std::string notebookName = sharp::string_substring(notebookTag->name(),
systemNotebookPrefix.length());
set_name(notebookName);
m_tag = notebookTag;
}
void Notebook::set_name(const std::string & value)
{
std::string trimmedName = value;
if(!trimmedName.empty()) {
m_name = trimmedName;
m_normalized_name = sharp::string_to_lower(trimmedName);
// The templateNoteTite should show the name of the
// notebook. For example, if the name of the notebooks
// "Meetings", the templateNoteTitle should be "Meetings
// Notebook Template". Translators should place the
// name of the notebook accordingly using "%1%".
// FIXME: TRANSLATE
//std::string format = _("%1% Notebook Template");
//m_template_note_title = str(boost::format(format) % m_name);
std::string format = "%1% Notebook Template";
m_template_note_title = str(boost::format(format) % m_name);
}
}
std::string Notebook::get_normalized_name() const
{
return m_normalized_name;
}
Tag::Ptr Notebook::get_tag() const
{
return m_tag;
}
// BEGIN Notebook::get_template_note()
Note::Ptr Notebook::get_template_note() const {
std::cout << "Notebook:: get template note()";
NoteManager & noteManager = Gnote::obj().default_note_manager();
Note::Ptr note = noteManager.find (m_template_note_title);
std::cout << "Notebook:: find note";
if (!note) {
std::cout << "Notebook:: no note";
// FIXME: need to get a unique name as well as uuid
// we should have a default create() function which fills all this junk in...
note = noteManager.create_new_note("New Note", "");
//note = noteManager.create (m_template_note_title,
// NoteManager::get_note_template_content (
// m_template_note_title));
// Flag this as a template note
//qDebug() << "Notebook:: get or create sys tag 2";
Tag::Ptr tag = TagManager::obj().get_or_create_system_tag (TagManager::TEMPLATE_NOTE_SYSTEM_TAG);
note->add_tag (tag);
// Add on the notebook system tag so Tomboy
// will persist the tag/notebook across sessions
// if no other notes are added to the notebook.
//qDebug() << "Notebook:: get or create sys tag 3";
tag = TagManager::obj().get_or_create_system_tag (NOTEBOOK_TAG_PREFIX + get_name());
note->add_tag (tag);
//note->queue_save (Note::CONTENT_CHANGED);
}
else
std::cout << "Notebook:: note found";
return note;
} // END Notebook::get_template_note()
/// <summary>
/// Returns true when the specified note exists in the notebook
/// </summary>
/// <param name="note">
/// A <see cref="Note"/>
/// </param>
/// <returns>
/// A <see cref="System.Boolean"/>
/// </returns>
bool Notebook::contains_note(const Note::Ptr & note)
{
// FIXME: IMPLEMENT
// return true;
return note->contains_tag (m_tag);
}
std::string Notebook::normalize(const std::string & s)
{
return sharp::string_to_lower(sharp::string_trim(s));
}
Tag::Ptr SpecialNotebook::get_tag() const
{
return Tag::Ptr();
}
Note::Ptr SpecialNotebook::get_template_note() const
{
return Gnote::obj().default_note_manager().get_or_create_template_note();
}
AllNotesNotebook::AllNotesNotebook()
// FIXME: i18n
//: SpecialNotebook(_("All Notes"))
: SpecialNotebook("All Notes")
{
}
std::string AllNotesNotebook::get_normalized_name() const
{
return "___NotebookManager___AllNotes__Notebook___";
}
UnfiledNotesNotebook::UnfiledNotesNotebook()
//: SpecialNotebook(_("Unfiled Notes"))
: SpecialNotebook("Unfiled Notes")
{
}
std::string UnfiledNotesNotebook::get_normalized_name() const
{
return "___NotebookManager___UnfiledNotes__Notebook___";
}
} // namespace gnote {
} // namespace notebooks {
// Sun Nov 25 18:38:18 PST 2012