vnotebook.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #ifndef VNOTEBOOK_H
  2. #define VNOTEBOOK_H
  3. #include <QObject>
  4. #include <QString>
  5. #include <QDateTime>
  6. class VDirectory;
  7. class VFile;
  8. class VNotebook : public QObject
  9. {
  10. Q_OBJECT
  11. public:
  12. VNotebook(const QString &name, const QString &path, QObject *parent = 0);
  13. ~VNotebook();
  14. // Open the root directory to load contents
  15. bool open();
  16. // Whether this notebook is opened.
  17. bool isOpened() const;
  18. // Close all the directory and files of this notebook.
  19. // Please make sure all files belonging to this notebook have been closed in the tab.
  20. void close();
  21. bool containsFile(const VFile *p_file) const;
  22. // Try to load the file @p_path.
  23. // Returns the corresponding VFile struct if @p_path is a note inside this notebook.
  24. // Otherwise, returns NULL.
  25. // If notebook is not opened currently, it will open itself and close itself
  26. // if @p_path is not inside this notebook.
  27. VFile *tryLoadFile(const QString &p_path);
  28. const QString &getName() const;
  29. const QString &getPath() const;
  30. VDirectory *getRootDir() const;
  31. void rename(const QString &p_name);
  32. static VNotebook *createNotebook(const QString &p_name, const QString &p_path,
  33. bool p_import, const QString &p_imageFolder,
  34. QObject *p_parent = 0);
  35. static bool deleteNotebook(VNotebook *p_notebook, bool p_deleteFiles);
  36. // Get the image folder for this notebook to use (not exactly the same as
  37. // m_imageFolder if it is empty).
  38. const QString &getImageFolder() const;
  39. // Return m_imageFolder.
  40. const QString &getImageFolderConfig() const;
  41. // Return m_recycleBinFolder.
  42. const QString &getRecycleBinFolder() const;
  43. // Get the recycle folder path for this notebook to use.
  44. QString getRecycleBinFolderPath() const;
  45. void setImageFolder(const QString &p_imageFolder);
  46. // Read configurations (excluding "sub_directories" and "files" section)
  47. // from root directory config file.
  48. bool readConfig();
  49. // Write configurations only related to notebook to root directory config file.
  50. bool writeConfigNotebook() const;
  51. // Return only the info of notebook part in json.
  52. QJsonObject toConfigJsonNotebook() const;
  53. // Need to check if this notebook has been opened.
  54. QDateTime getCreatedTimeUtc();
  55. signals:
  56. void contentChanged();
  57. private:
  58. // Serialize current instance to json.
  59. QJsonObject toConfigJson() const;
  60. // Write current instance to config file.
  61. bool writeToConfig() const;
  62. QString m_name;
  63. QString m_path;
  64. // Folder name to store images.
  65. // If not empty, VNote will store images in this folder within the same directory of the note.
  66. // Otherwise, VNote will use the global configured folder.
  67. QString m_imageFolder;
  68. // Folder name to store deleted files.
  69. // Could be relative or absolute.
  70. QString m_recycleBinFolder;
  71. // Parent is NULL for root directory
  72. VDirectory *m_rootDir;
  73. };
  74. inline VDirectory *VNotebook::getRootDir() const
  75. {
  76. return m_rootDir;
  77. }
  78. inline const QString &VNotebook::getRecycleBinFolder() const
  79. {
  80. return m_recycleBinFolder;
  81. }
  82. #endif // VNOTEBOOK_H