notebook.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. #ifndef NOTEBOOK_H
  2. #define NOTEBOOK_H
  3. #include <QObject>
  4. #include <QIcon>
  5. #include <QSharedPointer>
  6. #include "notebookparameters.h"
  7. #include "../global.h"
  8. #include "node.h"
  9. namespace vnotex
  10. {
  11. class INotebookBackend;
  12. class IVersionController;
  13. class INotebookConfigMgr;
  14. struct NodeParameters;
  15. // Base class of notebook.
  16. class Notebook : public QObject
  17. {
  18. Q_OBJECT
  19. public:
  20. Notebook(const NotebookParameters &p_paras,
  21. QObject *p_parent = nullptr);
  22. virtual ~Notebook();
  23. enum { InvalidId = 0 };
  24. ID getId() const;
  25. const QString &getType() const;
  26. const QString &getName() const;
  27. void setName(const QString &p_name);
  28. // Change the config and backend file as well.
  29. void updateName(const QString &p_name);
  30. const QString &getDescription() const;
  31. void setDescription(const QString &p_description);
  32. void updateDescription(const QString &p_description);
  33. // Use getRootFolderAbsolutePath() instead for access.
  34. const QString &getRootFolderPath() const;
  35. QString getRootFolderAbsolutePath() const;
  36. const QIcon &getIcon() const;
  37. void setIcon(const QIcon &p_icon);
  38. const QString &getImageFolder() const;
  39. const QString &getAttachmentFolder() const;
  40. const QDateTime &getCreatedTimeUtc() const;
  41. const QSharedPointer<INotebookBackend> &getBackend() const;
  42. const QSharedPointer<IVersionController> &getVersionController() const;
  43. const QSharedPointer<INotebookConfigMgr> &getConfigMgr() const;
  44. const QSharedPointer<Node> &getRootNode() const;
  45. QSharedPointer<Node> getRecycleBinNode() const;
  46. QSharedPointer<Node> newNode(Node *p_parent, Node::Type p_type, const QString &p_name);
  47. // Add @p_name under @p_parent to add as a new node @p_type.
  48. QSharedPointer<Node> addAsNode(Node *p_parent,
  49. Node::Type p_type,
  50. const QString &p_name,
  51. const NodeParameters &p_paras);
  52. // Copy @p_path to @p_parent and add as a new node @p_type.
  53. QSharedPointer<Node> copyAsNode(Node *p_parent,
  54. Node::Type p_type,
  55. const QString &p_path);
  56. virtual ID getNextNodeId() const = 0;
  57. virtual ID getAndUpdateNextNodeId() = 0;
  58. virtual void load(Node *p_node);
  59. virtual void save(const Node *p_node);
  60. virtual void rename(Node *p_node, const QString &p_name);
  61. virtual void updateNotebookConfig() = 0;
  62. virtual void removeNotebookConfig() = 0;
  63. // @p_path could be absolute or relative.
  64. virtual QSharedPointer<Node> loadNodeByPath(const QString &p_path);
  65. // Copy @p_src as a child of @p_dest. They may belong to different notebooks.
  66. virtual QSharedPointer<Node> copyNodeAsChildOf(const QSharedPointer<Node> &p_src, Node *p_dest, bool p_move);
  67. // Remove @p_node and delete all related files from disk.
  68. // @p_force: if true, will delete all files including files not tracked by configmgr.
  69. // @p_configOnly: if true, will just remove node from config.
  70. void removeNode(const QSharedPointer<Node> &p_node, bool p_force = false, bool p_configOnly = false);
  71. void removeNode(const Node *p_node, bool p_force = false, bool p_configOnly = false);
  72. void moveNodeToRecycleBin(const QSharedPointer<Node> &p_node);
  73. void moveNodeToRecycleBin(const Node *p_node);
  74. // Move @p_filePath to the recycle bin, without adding it as a child node.
  75. void moveFileToRecycleBin(const QString &p_filePath);
  76. // Move @p_dirPath to the recycle bin, without adding it as a child node.
  77. void moveDirToRecycleBin(const QString &p_dirPath);
  78. // Remove all files of this notebook from disk.
  79. virtual void remove() = 0;
  80. bool isRecycleBinNode(const Node *p_node) const;
  81. bool isNodeInRecycleBin(const Node *p_node) const;
  82. // Remove all children node of @p_node.
  83. // @p_force: if true, just delete all folders and files under @p_node.
  84. void emptyNode(const Node *p_node, bool p_force = false);
  85. // Whether @p_name is a built-in file under @p_node.
  86. bool isBuiltInFile(const Node *p_node, const QString &p_name) const;
  87. bool isBuiltInFolder(const Node *p_node, const QString &p_name) const;
  88. static const QString c_defaultAttachmentFolder;
  89. static const QString c_defaultImageFolder;
  90. signals:
  91. void updated();
  92. void nodeUpdated(const Node *p_node);
  93. private:
  94. QSharedPointer<Node> getOrCreateRecycleBinDateNode();
  95. // ID of this notebook.
  96. // Will be assigned uniquely once loaded.
  97. ID m_id;
  98. // Type of this notebook.
  99. QString m_type;
  100. // Name of this notebook.
  101. QString m_name;
  102. // Description of this notebook.
  103. QString m_description;
  104. // Path of the notebook root folder.
  105. QString m_rootFolderPath;
  106. QIcon m_icon;
  107. // Name of the folder to hold images.
  108. QString m_imageFolder;
  109. // Name of the folder to hold attachments.
  110. QString m_attachmentFolder;
  111. QDateTime m_createdTimeUtc;
  112. // Backend for file access and synchronization.
  113. QSharedPointer<INotebookBackend> m_backend;
  114. // Version controller.
  115. QSharedPointer<IVersionController> m_versionController;
  116. // Config manager to read/wirte config files.
  117. QSharedPointer<INotebookConfigMgr> m_configMgr;
  118. QSharedPointer<Node> m_root;
  119. };
  120. } // ns vnotex
  121. #endif // NOTEBOOK_H