1111#include " mainconfig.h"
1212#include " historymgr.h"
1313
14- #include " core/buffer/filetypehelper.h"
15-
1614using namespace vnotex ;
1715
1816bool SessionConfig::NotebookItem::operator ==(const NotebookItem &p_other) const
@@ -40,6 +38,34 @@ QJsonObject SessionConfig::NotebookItem::toJson() const
4038 return jobj;
4139}
4240
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+
4369void SessionConfig::ExternalProgram::fromJson (const QJsonObject &p_jobj)
4470{
4571 m_name = p_jobj[QStringLiteral (" name" )].toString ();
@@ -99,6 +125,8 @@ void SessionConfig::init()
99125
100126 loadHistory (sessionJobj);
101127
128+ loadQuickNoteSchemes (sessionJobj);
129+
102130 if (MainConfig::isVersionChanged ()) {
103131 doVersionSpecificOverride ();
104132 }
@@ -138,9 +166,6 @@ void SessionConfig::loadCore(const QJsonObject &p_session)
138166 if (m_externalMediaDefaultPath.isEmpty ()) {
139167 m_externalMediaDefaultPath = QDir::homePath ();
140168 }
141-
142- m_quickNoteStoragePath = readString (coreObj, QStringLiteral (" quick_note_storage_path" ));
143- m_quickNoteType = stringListToFileType (readStringList (coreObj, QStringLiteral (" quick_note_type" )));
144169}
145170
146171QJsonObject SessionConfig::saveCore () const
@@ -156,8 +181,6 @@ QJsonObject SessionConfig::saveCore() const
156181 coreObj[QStringLiteral (" flash_page" )] = m_flashPage;
157182 writeStringList (coreObj, QStringLiteral (" quick_access" ), m_quickAccessFiles);
158183 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));
161184 return coreObj;
162185}
163186
@@ -242,6 +265,7 @@ QJsonObject SessionConfig::toJson() const
242265 writeByteArray (obj, QStringLiteral (" notebook_explorer_session" ), m_notebookExplorerSession);
243266 obj[QStringLiteral (" external_programs" )] = saveExternalPrograms ();
244267 obj[QStringLiteral (" history" )] = saveHistory ();
268+ obj[QStringLiteral (" quick_note_schemes" )] = saveQuickNoteSchemes ();
245269 return obj;
246270}
247271
@@ -465,6 +489,24 @@ QJsonArray SessionConfig::saveExternalPrograms() const
465489 return arr;
466490}
467491
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+
468510const QVector<SessionConfig::ExternalProgram> &SessionConfig::getExternalPrograms () const
469511{
470512 return m_externalPrograms;
@@ -549,40 +591,12 @@ QJsonObject SessionConfig::saveExportOption() const
549591 return obj;
550592}
551593
552- const QString &SessionConfig::getQuickNoteStoragePath () const
594+ const QVector<SessionConfig::QuickNoteScheme> &SessionConfig::getQuickNoteSchemes () const
553595{
554- return m_quickNoteStoragePath ;
596+ return m_quickNoteSchemes ;
555597}
556598
557- void SessionConfig::setQuickNoteStoragePath (const QString &p_path )
599+ void SessionConfig::setQuickNoteSchemes (const QVector<QuickNoteScheme>& p_schemes )
558600{
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 );
588602}
0 commit comments