/
note.h
394 lines (229 loc) · 10.8 KB
/
note.h
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
#ifndef NOTE_H
#define NOTE_H
#include <utils/misc.h>
#include <QDateTime>
class Bookmark;
class NoteSubFolder;
class QRegularExpression;
class QFile;
class QUrl;
class QSqlQuery;
#define NOTE_TEXT_ENCRYPTION_PRE_STRING "<!-- BEGIN ENCRYPTED TEXT --"
#define NOTE_TEXT_ENCRYPTION_POST_STRING "-- END ENCRYPTED TEXT -->"
#define BOTAN_SALT "Gj3%36/SmPoe12$snNAs-A-_.),?faQ1@!f32"
class Note {
public:
explicit Note();
int getId() const;
QString getName() const;
QString getFileName() const;
QString getNoteText() const;
bool getHasDirtyData() const;
void setHasDirtyData(const bool hasDirtyData);
void setName(QString text);
void setNoteText(QString text);
qint64 getCryptoKey() const;
QString getCryptoPassword() const;
void setCryptoKey(const qint64 cryptoKey);
static bool addNote(const QString &name, const QString &fileName,
const QString &text);
static Note fetch(int id);
static Note fetchByName(const QRegularExpression ®Exp,
int noteSubFolderId = -1);
static Note fetchByFileName(const QString &fileName,
int noteSubFolderId = -1);
static Note fetchByFileName(const QString &fileName,
const QString ¬eSubFolderPathData);
static Note fetchByName(const QString &name, int noteSubFolderId = -1);
static Note fetchByName(const QString &name,
const QString ¬eSubFolderPathData,
const QString& pathDataSeparator = QStringLiteral("\n"));
static int fetchNoteIdByName(const QString &name, int noteSubFolderId = -1);
static QVector<Note> fetchAll(int limit = -1);
static QVector<int> fetchAllNotTaggedIds();
static int countAllNotTagged(int activeNoteSubFolderId = -1);
static QVector<Note> search(const QString &text);
static QVector<QString> searchAsNameListInCurrentNoteSubFolder(
const QString &text, bool searchInNameOnly = false);
static QVector<QString> searchAsNameList(const QString &text,
bool searchInNameOnly = false);
static QStringList fetchNoteNamesInCurrentNoteSubFolder();
static QStringList fetchNoteNames();
static QStringList fetchNoteFileNames();
static Note noteFromQuery(const QSqlQuery &query);
bool store();
bool storeNewText(QString text);
bool storeNoteTextFileToDisk();
static QString defaultNoteFileExtension();
static QStringList customNoteFileExtensionList(
const QString &prefix = QString());
static QString getFullFilePathForFile(const QString &fileName);
QString getFilePathRelativeToNote(const Note ¬e) const;
static int storeDirtyNotesToDisk(Note ¤tNote,
bool *currentNoteChanged = Q_NULLPTR,
bool *noteWasRenamed = Q_NULLPTR);
bool updateNoteTextFromDisk();
friend QDebug operator<<(QDebug dbg, const Note ¬e);
void createFromFile(QFile &file, int noteSubFolderId = 0,
bool withNoteNameHook = false);
static bool deleteAll();
bool fileExists() const;
bool fileWriteable() const;
bool exists() const;
static bool noteIdExists(int id);
bool refetch();
Note fillFromQuery(const QSqlQuery &query);
bool fillByFileName(const QString &fileName, int noteSubFolderId = -1);
bool removeNoteFile();
bool remove(bool withFile = false);
QString toMarkdownHtml(const QString ¬esPath, int maxImageWidth = 980,
bool forExport = false, bool decrypt = true,
bool base64Images = false);
bool isFetched() const;
bool copyToPath(const QString &destinationPath,
QString noteFolderPath = QString());
bool moveToPath(const QString &destinationPath,
const QString ¬eFolderPath = QString());
static QString generateTextForLink(QString text);
static qint64 qint64Hash(const QString &str);
QString encryptNoteText();
QString fetchDecryptedNoteText() const;
QString getDecryptedNoteText() const;
bool hasEncryptedNoteText() const;
void setCryptoPassword(const QString &password);
bool canDecryptNoteText() const;
static bool expireCryptoKeys();
QUrl fullNoteFileUrl() const;
QString fullNoteFilePath() const;
QString fullNoteFileDirPath() const;
static QString encodeCssFont(const QFont &refFont);
void setDecryptedNoteText(QString text);
bool storeNewDecryptedText(QString text);
void setDecryptedText(QString text);
QDateTime getFileLastModified() const;
QDateTime getFileCreated() const;
QDateTime getModified() const;
static int countAll();
static bool allowDifferentFileName();
bool renameNoteFile(QString newName);
QString fileNameSuffix() const;
bool modifyNoteTextFileNameFromQMLHook();
static QVector<int> searchInNotes(QString query,
bool ignoreNoteSubFolder = false,
int noteSubFolderId = -1);
int countSearchTextInNote(const QString &search) const;
static QStringList buildQueryStringList(
QString searchString, bool escapeForRegularExpression = false,
bool removeSearchPrefix = false);
QString fileBaseName(bool withFullName = false);
NoteSubFolder getNoteSubFolder() const;
void setNoteSubFolder(const NoteSubFolder ¬eSubFolder);
void setNoteSubFolderId(int id);
static QVector<Note> fetchAllByNoteSubFolderId(int noteSubFolderId);
static QVector<int> fetchAllIdsByNoteSubFolderId(int noteSubFolderId);
static QVector<int> noteIdListFromNoteList(const QVector<Note> ¬eList);
static int countByNoteSubFolderId(int noteSubFolderId = 0,
bool recursive = false);
int getNoteSubFolderId() const;
bool isInCurrentNoteSubFolder() const;
QString relativeNoteFilePath(QString separator = QString()) const;
QString relativeNoteSubFolderPath() const;
QString noteSubFolderPathData() const;
bool isSameFile(const Note ¬e) const;
QString getShareUrl() const;
void setShareUrl(QString url);
int getShareId() const;
void setShareId(int id);
unsigned int getSharePermissions() const;
bool isShareEditAllowed() const;
void setSharePermissions(unsigned int permissions);
bool isShared() const;
static Note fetchByShareId(int shareId);
int getFileSize() const;
static Note updateOrCreateFromFile(QFile &file,
const NoteSubFolder ¬eSubFolder,
bool withNoteNameHook = false);
static QVector<int> fetchAllIds(int limit = -1, int offset = -1);
QVector<int> findLinkedNoteIds() const;
void handleNoteMoving(const Note &oldNote) const;
static QString createNoteHeader(const QString &name);
QString getInsertMediaMarkdown(QFile *file, bool addNewLine = true,
bool returnUrlOnly = false,
QString title = QString());
QString getInsertAttachmentMarkdown(QFile *file,
QString fileName = QString(),
bool returnUrlOnly = false);
static bool scaleDownImageFileIfNeeded(QFile &file);
QString downloadUrlToMedia(const QUrl &url, bool returnUrlOnly = false);
QString importMediaFromBase64(
QString &data, const QString &imageSuffix = QStringLiteral("dat"));
bool canWriteToNoteFile();
static QString generateNoteFileNameFromName(const QString &name);
void generateFileNameFromName();
QString textToMarkdownHtml(QString str, const QString ¬esPath,
int maxImageWidth = 980, bool forExport = false,
bool base64Images = false);
QStringList getMediaFileList();
static Note fetchByUrlString(const QString &urlString);
static QVector<int> fetchAllIdsByNoteTextPart(const QString &textPart);
QStringList getAttachmentsFileList() const;
QString getNotePreviewText(bool asHtml = false, int lines = 3) const;
static QString generateMultipleNotesPreviewText(const QVector<Note> ¬es);
bool handleNoteTextFileName();
QString getNoteIdURL() const;
static QString cleanupFileName(QString name);
static QString extendedCleanupFileName(QString name);
QVector<Bookmark> getParsedBookmarks() const;
QString getParsedBookmarksWebServiceJsonText() const;
void resetNoteTextHtmlConversionHash();
QString getFileURLFromFileName(QString fileName,
bool urlDecodeFileName = false) const;
static bool fileUrlIsNoteInCurrentNoteFolder(const QUrl &url);
static bool fileUrlIsExistingNoteInCurrentNoteFolder(const QUrl &url);
static QString fileUrlInCurrentNoteFolderToRelativePath(const QUrl &url);
QString relativeFilePath(const QString &path) const;
static Note fetchByFileUrl(const QUrl &url);
static Note fetchByRelativeFilePath(const QString &relativePath);
QString getNoteUrlForLinkingTo(const Note ¬e,
bool forceLegacy = false) const;
QString mediaUrlStringForFileName(const QString &fileName) const;
QString attachmentUrlStringForFileName(const QString &fileName) const;
Note fetchByRelativeFileName(const QString &fileName) const;
bool updateRelativeMediaFileLinks();
bool updateRelativeAttachmentFileLinks();
static Utils::Misc::ExternalImageHash *externalImageHash();
static QString urlEncodeNoteUrl(const QString &url);
static QString urlDecodeNoteUrl(QString url);
QStringList getNoteTextLines() const;
bool stripTrailingSpaces(int skipLine = -1);
QString detectNewlineCharacters();
static bool isNameSearch(const QString &searchTerm);
static QString removeNameSearchPrefix(QString searchTerm);
protected:
int _id;
int _noteSubFolderId;
QString _name;
QString _fileName;
QString _noteTextHtml;
QString _noteTextHtmlConversionHash;
QString _noteText;
QString _decryptedNoteText;
QString _cryptoPassword;
QString _shareUrl;
QDateTime _fileCreated;
QDateTime _fileLastModified;
QDateTime _created;
QDateTime _modified;
qint64 _cryptoKey;
int _fileSize;
int _shareId;
unsigned int _sharePermissions;
bool _hasDirtyData;
QRegularExpression getEncryptedNoteTextRegularExpression() const;
QString getEncryptedNoteText() const;
static const QString getNoteURL(const QString &baseName);
static const QString getNoteURLFromFileName(const QString &fileName);
void restoreCreatedDate();
};
Q_DECLARE_TYPEINFO(Note, Q_MOVABLE_TYPE);
#endif // NOTE_H