vxnotebookconfigmgr.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #ifndef VXNOTEBOOKCONFIGMGR_H
  2. #define VXNOTEBOOKCONFIGMGR_H
  3. #include "bundlenotebookconfigmgr.h"
  4. #include <QDateTime>
  5. #include <QVector>
  6. #include <QRegExp>
  7. #include <core/global.h>
  8. class QJsonObject;
  9. namespace vnotex
  10. {
  11. namespace vx_node_config
  12. {
  13. struct NodeFileConfig;
  14. struct NodeFolderConfig;
  15. struct NodeConfig;
  16. }
  17. class NotebookDatabaseAccess;
  18. // Config manager for VNoteX's bundle notebook.
  19. class VXNotebookConfigMgr : public BundleNotebookConfigMgr
  20. {
  21. Q_OBJECT
  22. public:
  23. explicit VXNotebookConfigMgr(const QString &p_name,
  24. const QString &p_displayName,
  25. const QString &p_description,
  26. const QSharedPointer<INotebookBackend> &p_backend,
  27. QObject *p_parent = nullptr);
  28. QString getName() const Q_DECL_OVERRIDE;
  29. QString getDisplayName() const Q_DECL_OVERRIDE;
  30. QString getDescription() const Q_DECL_OVERRIDE;
  31. void createEmptySkeleton(const NotebookParameters &p_paras) Q_DECL_OVERRIDE;
  32. QSharedPointer<Node> loadRootNode() Q_DECL_OVERRIDE;
  33. void loadNode(Node *p_node) Q_DECL_OVERRIDE;
  34. void saveNode(const Node *p_node) Q_DECL_OVERRIDE;
  35. void renameNode(Node *p_node, const QString &p_name) Q_DECL_OVERRIDE;
  36. QSharedPointer<Node> newNode(Node *p_parent,
  37. Node::Flags p_flags,
  38. const QString &p_name,
  39. const QString &p_content) Q_DECL_OVERRIDE;
  40. QSharedPointer<Node> addAsNode(Node *p_parent,
  41. Node::Flags p_flags,
  42. const QString &p_name,
  43. const NodeParameters &p_paras) Q_DECL_OVERRIDE;
  44. QSharedPointer<Node> copyAsNode(Node *p_parent,
  45. Node::Flags p_flags,
  46. const QString &p_path) Q_DECL_OVERRIDE;
  47. QSharedPointer<Node> loadNodeByPath(const QSharedPointer<Node> &p_root,
  48. const QString &p_relativePath) Q_DECL_OVERRIDE;
  49. QSharedPointer<Node> copyNodeAsChildOf(const QSharedPointer<Node> &p_src,
  50. Node *p_dest,
  51. bool p_move) Q_DECL_OVERRIDE;
  52. void removeNode(const QSharedPointer<Node> &p_node, bool p_force = false, bool p_configOnly = false) Q_DECL_OVERRIDE;
  53. bool isBuiltInFile(const Node *p_node, const QString &p_name) const Q_DECL_OVERRIDE;
  54. bool isBuiltInFolder(const Node *p_node, const QString &p_name) const Q_DECL_OVERRIDE;
  55. QString fetchNodeImageFolderPath(Node *p_node);
  56. QString fetchNodeAttachmentFolderPath(Node *p_node) Q_DECL_OVERRIDE;
  57. QVector<QSharedPointer<ExternalNode>> fetchExternalChildren(Node *p_node) const Q_DECL_OVERRIDE;
  58. bool checkNodeExists(Node *p_node) Q_DECL_OVERRIDE;
  59. QStringList scanAndImportExternalFiles(Node *p_node) Q_DECL_OVERRIDE;
  60. private:
  61. void createEmptyRootNode();
  62. QSharedPointer<vx_node_config::NodeConfig> readNodeConfig(const QString &p_path) const;
  63. void writeNodeConfig(const QString &p_path, const vx_node_config::NodeConfig &p_config) const;
  64. void writeNodeConfig(const Node *p_node);
  65. QSharedPointer<Node> nodeConfigToNode(const vx_node_config::NodeConfig &p_config,
  66. const QString &p_name,
  67. Node *p_parent = nullptr);
  68. void loadFolderNode(Node *p_node, const vx_node_config::NodeConfig &p_config);
  69. QSharedPointer<vx_node_config::NodeConfig> nodeToNodeConfig(const Node *p_node) const;
  70. QSharedPointer<Node> newFileNode(Node *p_parent,
  71. const QString &p_name,
  72. const QString &p_content,
  73. bool p_create,
  74. const NodeParameters &p_paras);
  75. QSharedPointer<Node> newFolderNode(Node *p_parent,
  76. const QString &p_name,
  77. bool p_create,
  78. const NodeParameters &p_paras);
  79. QString getNodeConfigFilePath(const Node *p_node) const;
  80. void addChildNode(Node *p_parent, const QSharedPointer<Node> &p_child) const;
  81. QSharedPointer<Node> copyNodeAsChildOf(const QSharedPointer<Node> &p_src,
  82. Node *p_dest,
  83. bool p_move,
  84. bool p_updateDatabase);
  85. QSharedPointer<Node> copyFileNodeAsChildOf(const QSharedPointer<Node> &p_src,
  86. Node *p_dest,
  87. bool p_move,
  88. bool p_updateDatabase);
  89. QSharedPointer<Node> copyFolderNodeAsChildOf(const QSharedPointer<Node> &p_src,
  90. Node *p_dest,
  91. bool p_move,
  92. bool p_updateDatabase);
  93. QSharedPointer<Node> copyFileAsChildOf(const QString &p_srcPath, Node *p_dest);
  94. QSharedPointer<Node> copyFolderAsChildOf(const QString &p_srcPath, Node *p_dest);
  95. void removeFilesOfNode(Node *p_node, bool p_force);
  96. bool markRecycleBinNode(const QSharedPointer<Node> &p_root);
  97. void markNodeReadOnly(Node *p_node) const;
  98. void createRecycleBinNode(const QSharedPointer<Node> &p_root);
  99. // Generate node attachment folder.
  100. // @p_folderName: suggested folder name if not empty, may be renamed due to conflicts.
  101. // Return the attachment folder path.
  102. QString fetchNodeAttachmentFolder(const QString &p_nodePath, QString &p_folderName);
  103. void inheritNodeFlags(const Node *p_node, Node *p_child) const;
  104. bool isExcludedFromExternalNode(const QString &p_name) const;
  105. void removeNode(const QSharedPointer<Node> &p_node,
  106. bool p_force,
  107. bool p_configOnly,
  108. bool p_updateDatabase);
  109. NotebookDatabaseAccess *getDatabaseAccess() const;
  110. void updateNodeInDatabase(Node *p_node);
  111. void ensureNodeInDatabase(Node *p_node);
  112. void addNodeToDatabase(Node *p_node);
  113. bool nodeExistsInDatabase(const Node *p_node);
  114. void removeNodeFromDatabase(const Node *p_node);
  115. bool sameNotebook(const Node *p_node) const;
  116. static bool isLikelyImageFolder(const QString &p_dirPath);
  117. Info m_info;
  118. static bool s_initialized;
  119. static QVector<QRegExp> s_externalNodeExcludePatterns;
  120. // Name of the node's config file.
  121. static const QString c_nodeConfigName;
  122. // Name of the recycle bin folder which should be a child of the root node.
  123. static const QString c_recycleBinFolderName;
  124. };
  125. } // ns vnotex
  126. #endif // VXNOTEBOOKCONFIGMGR_H