vnotebook.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. void setImageFolder(const QString &p_imageFolder);
  42. // Read configurations (excluding "sub_directories" and "files" section)
  43. // from root directory config file.
  44. bool readConfig();
  45. // Write configurations (excluding "sub_directories" and "files" section)
  46. // to root directory config file.
  47. bool writeConfig() const;
  48. // Return only the info of notebook part in json.
  49. QJsonObject toConfigJsonNotebook() const;
  50. // Need to check if this notebook has been opened.
  51. QDateTime getCreatedTimeUtc();
  52. signals:
  53. void contentChanged();
  54. private:
  55. // Serialize current instance to json.
  56. QJsonObject toConfigJson() const;
  57. // Write current instance to config file.
  58. bool writeToConfig() const;
  59. QString m_name;
  60. QString m_path;
  61. // Folder name to store images.
  62. // If not empty, VNote will store images in this folder within the same directory of the note.
  63. // Otherwise, VNote will use the global configured folder.
  64. QString m_imageFolder;
  65. // Parent is NULL for root directory
  66. VDirectory *m_rootDir;
  67. };
  68. inline VDirectory *VNotebook::getRootDir() const
  69. {
  70. return m_rootDir;
  71. }
  72. #endif // VNOTEBOOK_H