11
11
#include " mainconfig.h"
12
12
#include " historymgr.h"
13
13
14
- #include " core/buffer/filetypehelper.h"
15
-
16
14
using namespace vnotex ;
17
15
18
16
bool SessionConfig::NotebookItem::operator ==(const NotebookItem &p_other) const
@@ -40,6 +38,34 @@ QJsonObject SessionConfig::NotebookItem::toJson() const
40
38
return jobj;
41
39
}
42
40
41
+ bool SessionConfig::QuickNoteScheme::operator ==(const QuickNoteScheme &p_other) const
42
+ {
43
+ return m_name == p_other.m_name &&
44
+ m_folderPath == p_other.m_folderPath &&
45
+ m_noteName == p_other.m_noteName &&
46
+ m_template == p_other.m_template ;
47
+ }
48
+
49
+ void SessionConfig::QuickNoteScheme::fromJson (const QJsonObject &p_jobj)
50
+ {
51
+ m_name = p_jobj[QStringLiteral (" name" )].toString ();
52
+ m_folderPath = p_jobj[QStringLiteral (" folder_path" )].toString ();
53
+ m_noteName = p_jobj[QStringLiteral (" note_name" )].toString ();
54
+ m_template = p_jobj[QStringLiteral (" template" )].toString ();
55
+ }
56
+
57
+ QJsonObject SessionConfig::QuickNoteScheme::toJson () const
58
+ {
59
+ QJsonObject jobj;
60
+
61
+ jobj[QStringLiteral (" name" )] = m_name;
62
+ jobj[QStringLiteral (" folder_path" )] = m_folderPath;
63
+ jobj[QStringLiteral (" note_name" )] = m_noteName;
64
+ jobj[QStringLiteral (" template" )] = m_template;
65
+
66
+ return jobj;
67
+ }
68
+
43
69
void SessionConfig::ExternalProgram::fromJson (const QJsonObject &p_jobj)
44
70
{
45
71
m_name = p_jobj[QStringLiteral (" name" )].toString ();
@@ -99,6 +125,8 @@ void SessionConfig::init()
99
125
100
126
loadHistory (sessionJobj);
101
127
128
+ loadQuickNoteSchemes (sessionJobj);
129
+
102
130
if (MainConfig::isVersionChanged ()) {
103
131
doVersionSpecificOverride ();
104
132
}
@@ -138,9 +166,6 @@ void SessionConfig::loadCore(const QJsonObject &p_session)
138
166
if (m_externalMediaDefaultPath.isEmpty ()) {
139
167
m_externalMediaDefaultPath = QDir::homePath ();
140
168
}
141
-
142
- m_quickNoteStoragePath = readString (coreObj, QStringLiteral (" quick_note_storage_path" ));
143
- m_quickNoteType = stringListToFileType (readStringList (coreObj, QStringLiteral (" quick_note_type" )));
144
169
}
145
170
146
171
QJsonObject SessionConfig::saveCore () const
@@ -156,8 +181,6 @@ QJsonObject SessionConfig::saveCore() const
156
181
coreObj[QStringLiteral (" flash_page" )] = m_flashPage;
157
182
writeStringList (coreObj, QStringLiteral (" quick_access" ), m_quickAccessFiles);
158
183
coreObj[QStringLiteral (" external_media_default_path" )] = m_externalMediaDefaultPath;
159
- coreObj[QStringLiteral (" quick_note_storage_path" )] = m_quickNoteStoragePath;
160
- writeStringList (coreObj, QStringLiteral (" quick_note_type" ), fileTypeToStringList (m_quickNoteType));
161
184
return coreObj;
162
185
}
163
186
@@ -242,6 +265,7 @@ QJsonObject SessionConfig::toJson() const
242
265
writeByteArray (obj, QStringLiteral (" notebook_explorer_session" ), m_notebookExplorerSession);
243
266
obj[QStringLiteral (" external_programs" )] = saveExternalPrograms ();
244
267
obj[QStringLiteral (" history" )] = saveHistory ();
268
+ obj[QStringLiteral (" quick_note_schemes" )] = saveQuickNoteSchemes ();
245
269
return obj;
246
270
}
247
271
@@ -465,6 +489,24 @@ QJsonArray SessionConfig::saveExternalPrograms() const
465
489
return arr;
466
490
}
467
491
492
+ void SessionConfig::loadQuickNoteSchemes (const QJsonObject &p_session)
493
+ {
494
+ const auto arr = p_session.value (QStringLiteral (" quick_note_schemes" )).toArray ();
495
+ m_quickNoteSchemes.resize (arr.size ());
496
+ for (int i = 0 ; i < arr.size (); ++i) {
497
+ m_quickNoteSchemes[i].fromJson (arr[i].toObject ());
498
+ }
499
+ }
500
+
501
+ QJsonArray SessionConfig::saveQuickNoteSchemes () const
502
+ {
503
+ QJsonArray arr;
504
+ for (const auto &scheme : m_quickNoteSchemes) {
505
+ arr.append (scheme.toJson ());
506
+ }
507
+ return arr;
508
+ }
509
+
468
510
const QVector<SessionConfig::ExternalProgram> &SessionConfig::getExternalPrograms () const
469
511
{
470
512
return m_externalPrograms;
@@ -549,40 +591,12 @@ QJsonObject SessionConfig::saveExportOption() const
549
591
return obj;
550
592
}
551
593
552
- const QString &SessionConfig::getQuickNoteStoragePath () const
594
+ const QVector<SessionConfig::QuickNoteScheme> &SessionConfig::getQuickNoteSchemes () const
553
595
{
554
- return m_quickNoteStoragePath ;
596
+ return m_quickNoteSchemes ;
555
597
}
556
598
557
- void SessionConfig::setQuickNoteStoragePath (const QString &p_path )
599
+ void SessionConfig::setQuickNoteSchemes (const QVector<QuickNoteScheme>& p_schemes )
558
600
{
559
- updateConfig (m_quickNoteStoragePath, p_path, this );
560
- }
561
-
562
- const QVector<int > &SessionConfig::getQuickNoteType () const
563
- {
564
- return m_quickNoteType;
565
- }
566
-
567
- void SessionConfig::setQuickNoteType (const QVector<int > &p_type)
568
- {
569
- updateConfig (m_quickNoteType, p_type, this );
570
- }
571
-
572
- QStringList SessionConfig::fileTypeToStringList (const QVector<int > &p_type) const
573
- {
574
- QStringList list;
575
- for (const int typ : p_type) {
576
- list << FileTypeHelper::getInst ().getFileType (typ).m_typeName ;
577
- }
578
- return list;
579
- }
580
-
581
- QVector<int > SessionConfig::stringListToFileType (const QStringList &p_strList) const
582
- {
583
- QVector<int > vec;
584
- for (const QString &str : p_strList) {
585
- vec.append (FileTypeHelper::getInst ().getFileTypeByName (str).m_type );
586
- }
587
- return vec;
601
+ updateConfig (m_quickNoteSchemes, p_schemes, this );
588
602
}
0 commit comments