vnotebook.h 2.7 KB

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