bundlenotebook.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include "bundlenotebook.h"
  2. #include <QDebug>
  3. #include <notebookconfigmgr/bundlenotebookconfigmgr.h>
  4. #include <notebookconfigmgr/notebookconfig.h>
  5. #include <utils/fileutils.h>
  6. #include <core/historymgr.h>
  7. #include <notebookbackend/inotebookbackend.h>
  8. using namespace vnotex;
  9. BundleNotebook::BundleNotebook(const NotebookParameters &p_paras,
  10. const QSharedPointer<NotebookConfig> &p_notebookConfig,
  11. QObject *p_parent)
  12. : Notebook(p_paras, p_parent)
  13. {
  14. m_nextNodeId = p_notebookConfig->m_nextNodeId;
  15. m_history = p_notebookConfig->m_history;
  16. }
  17. BundleNotebookConfigMgr *BundleNotebook::getBundleNotebookConfigMgr() const
  18. {
  19. return dynamic_cast<BundleNotebookConfigMgr *>(getConfigMgr().data());
  20. }
  21. ID BundleNotebook::getNextNodeId() const
  22. {
  23. return m_nextNodeId;
  24. }
  25. ID BundleNotebook::getAndUpdateNextNodeId()
  26. {
  27. auto id = m_nextNodeId++;
  28. getBundleNotebookConfigMgr()->writeNotebookConfig();
  29. return id;
  30. }
  31. void BundleNotebook::updateNotebookConfig()
  32. {
  33. getBundleNotebookConfigMgr()->writeNotebookConfig();
  34. }
  35. void BundleNotebook::removeNotebookConfig()
  36. {
  37. getBundleNotebookConfigMgr()->removeNotebookConfig();
  38. }
  39. void BundleNotebook::remove()
  40. {
  41. // Remove all nodes.
  42. removeNode(getRootNode());
  43. // Remove notebook config.
  44. removeNotebookConfig();
  45. // Remove notebook root folder if it is empty.
  46. if (!FileUtils::removeDirIfEmpty(getRootFolderAbsolutePath())) {
  47. qInfo() << QString("root folder of notebook (%1) is not empty and needs manual clean up")
  48. .arg(getRootFolderAbsolutePath());
  49. }
  50. }
  51. const QVector<HistoryItem> &BundleNotebook::getHistory() const
  52. {
  53. return m_history;
  54. }
  55. void BundleNotebook::addHistory(const HistoryItem &p_item)
  56. {
  57. HistoryItem item(p_item);
  58. item.m_path = getBackend()->getRelativePath(item.m_path);
  59. HistoryMgr::insertHistoryItem(m_history, item);
  60. updateNotebookConfig();
  61. }
  62. void BundleNotebook::clearHistory()
  63. {
  64. m_history.clear();
  65. updateNotebookConfig();
  66. }