Bläddra i källkod

remove support of legacy VNote2 notebook

Le Tan 1 månad sedan
förälder
incheckning
897e05eb6b

+ 0 - 3
src/core/vnotex.h

@@ -61,9 +61,6 @@ signals:
   // Requested to import a notebook.
   // Requested to import a notebook.
   void importNotebookRequested();
   void importNotebookRequested();
 
 
-  // Requested to import a legacy notebook from VNote 2.0.
-  void importLegacyNotebookRequested();
-
   void manageNotebooksRequested();
   void manageNotebooksRequested();
 
 
   // Requested to import files.
   // Requested to import files.

+ 0 - 2
src/widgets/CMakeLists.txt

@@ -14,9 +14,7 @@ target_sources(vnote PRIVATE
     dialogs/imageinsertdialog.cpp dialogs/imageinsertdialog.h
     dialogs/imageinsertdialog.cpp dialogs/imageinsertdialog.h
     dialogs/importfolderdialog.cpp dialogs/importfolderdialog.h
     dialogs/importfolderdialog.cpp dialogs/importfolderdialog.h
     dialogs/importfolderutils.cpp dialogs/importfolderutils.h
     dialogs/importfolderutils.cpp dialogs/importfolderutils.h
-    dialogs/importlegacynotebookdialog.cpp dialogs/importlegacynotebookdialog.h
     dialogs/importnotebookdialog.cpp dialogs/importnotebookdialog.h
     dialogs/importnotebookdialog.cpp dialogs/importnotebookdialog.h
-    dialogs/legacynotebookutils.cpp dialogs/legacynotebookutils.h
     dialogs/levellabelwithupbutton.cpp dialogs/levellabelwithupbutton.h
     dialogs/levellabelwithupbutton.cpp dialogs/levellabelwithupbutton.h
     dialogs/linkinsertdialog.cpp dialogs/linkinsertdialog.h
     dialogs/linkinsertdialog.cpp dialogs/linkinsertdialog.h
     dialogs/managenotebooksdialog.cpp dialogs/managenotebooksdialog.h
     dialogs/managenotebooksdialog.cpp dialogs/managenotebooksdialog.h

+ 0 - 83
src/widgets/dialogs/importfolderutils.cpp

@@ -1,6 +1,5 @@
 #include "importfolderutils.h"
 #include "importfolderutils.h"
 
 
-#include "legacynotebookutils.h"
 #include <QCoreApplication>
 #include <QCoreApplication>
 #include <core/exception.h>
 #include <core/exception.h>
 #include <notebook/nodeparameters.h>
 #include <notebook/nodeparameters.h>
@@ -45,85 +44,3 @@ void ImportFolderUtils::importFolderContents(Notebook *p_notebook, Node *p_node,
     }
     }
   }
   }
 }
 }
-
-void ImportFolderUtils::importFolderContentsByLegacyConfig(Notebook *p_notebook, Node *p_node,
-                                                           QString &p_errMsg) {
-  auto rootDir = p_node->toDir();
-
-  QJsonObject config;
-  try {
-    config = LegacyNotebookUtils::getFolderConfig(rootDir.absolutePath());
-  } catch (Exception &p_e) {
-    Utils::appendMsg(p_errMsg,
-                     ImportFolderUtilsTranslate::tr("Failed to read folder config (%1) (%2).")
-                         .arg(rootDir.absolutePath(), p_e.what()));
-    return;
-  }
-
-  // Remove the config file.
-  LegacyNotebookUtils::removeFolderConfigFile(rootDir.absolutePath());
-
-  // Folders.
-  LegacyNotebookUtils::forEachFolder(config, [&rootDir, p_notebook, p_node,
-                                              &p_errMsg](const QString &name) {
-    if (!rootDir.exists(name)) {
-      Utils::appendMsg(p_errMsg,
-                       ImportFolderUtilsTranslate::tr("Folder (%1) does not exist.").arg(name));
-      return;
-    }
-
-    if (p_notebook->isBuiltInFolder(p_node, name)) {
-      Utils::appendMsg(
-          p_errMsg,
-          ImportFolderUtilsTranslate::tr("Folder (%1) conflicts with built-in folder.").arg(name));
-      return;
-    }
-
-    QSharedPointer<Node> node;
-    try {
-      NodeParameters paras;
-      paras.m_createdTimeUtc =
-          LegacyNotebookUtils::getCreatedTimeUtcOfFolder(rootDir.filePath(name));
-      node = p_notebook->addAsNode(p_node, Node::Flag::Container, name, paras);
-    } catch (Exception &p_e) {
-      Utils::appendMsg(p_errMsg,
-                       ImportFolderUtilsTranslate::tr("Failed to add folder (%1) as node (%2).")
-                           .arg(name, p_e.what()));
-      return;
-    }
-
-    ImportFolderUtils::importFolderContentsByLegacyConfig(p_notebook, node.data(), p_errMsg);
-  });
-
-  // Files.
-  LegacyNotebookUtils::forEachFile(config, [&rootDir, p_notebook, p_node,
-                                            &p_errMsg](const LegacyNotebookUtils::FileInfo &info) {
-    if (!rootDir.exists(info.m_name)) {
-      Utils::appendMsg(
-          p_errMsg, ImportFolderUtilsTranslate::tr("File (%1) does not exist.").arg(info.m_name));
-      return;
-    }
-
-    if (p_notebook->isBuiltInFile(p_node, info.m_name)) {
-      Utils::appendMsg(p_errMsg,
-                       ImportFolderUtilsTranslate::tr("File (%1) conflicts with built-in file.")
-                           .arg(info.m_name));
-      return;
-    }
-
-    QSharedPointer<Node> node;
-    try {
-      NodeParameters paras;
-      paras.m_createdTimeUtc = info.m_createdTimeUtc;
-      paras.m_modifiedTimeUtc = info.m_modifiedTimeUtc;
-      paras.m_attachmentFolder = info.m_attachmentFolder;
-      paras.m_tags = info.m_tags;
-      node = p_notebook->addAsNode(p_node, Node::Flag::Content, info.m_name, paras);
-    } catch (Exception &p_e) {
-      Utils::appendMsg(p_errMsg,
-                       ImportFolderUtilsTranslate::tr("Failed to add file (%1) as node (%2).")
-                           .arg(info.m_name, p_e.what()));
-      return;
-    }
-  });
-}

+ 0 - 5
src/widgets/dialogs/importfolderutils.h

@@ -22,11 +22,6 @@ public:
   // @p_node has already been added.
   // @p_node has already been added.
   static void importFolderContents(Notebook *p_notebook, Node *p_node,
   static void importFolderContents(Notebook *p_notebook, Node *p_node,
                                    const QStringList &p_suffixes, QString &p_errMsg);
                                    const QStringList &p_suffixes, QString &p_errMsg);
-
-  // Process folder @p_node by legacy notebook config.
-  // @p_node has already been added.
-  static void importFolderContentsByLegacyConfig(Notebook *p_notebook, Node *p_node,
-                                                 QString &p_errMsg);
 };
 };
 } // namespace vnotex
 } // namespace vnotex
 
 

+ 0 - 149
src/widgets/dialogs/importlegacynotebookdialog.cpp

@@ -1,149 +0,0 @@
-#include "importlegacynotebookdialog.h"
-
-#include <QFileInfo>
-#include <QLineEdit>
-
-#include "../messageboxhelper.h"
-#include "importfolderutils.h"
-#include "legacynotebookutils.h"
-#include "notebookinfowidget.h"
-#include "notebookmgr.h"
-#include "vnotex.h"
-#include <exception.h>
-#include <utils/fileutils.h>
-#include <utils/pathutils.h>
-#include <utils/utils.h>
-
-using namespace vnotex;
-
-ImportLegacyNotebookDialog::ImportLegacyNotebookDialog(QWidget *p_parent)
-    : NewNotebookDialog(p_parent) {
-  setWindowTitle(tr("Open Legacy Notebook"));
-
-  m_infoWidget->setMode(NotebookInfoWidget::Mode::CreateFromLegacy);
-  m_infoWidget->getRootFolderPathLineEdit()->setFocus();
-}
-
-void ImportLegacyNotebookDialog::acceptedButtonClicked() {
-  if (isCompleted()) {
-    accept();
-    return;
-  }
-
-  // Warn user about the transformation.
-  int ret = MessageBoxHelper::questionOkCancel(
-      MessageBoxHelper::Warning,
-      tr("Once opened, the legacy notebook could no longer be recognized by legacy VNote!"),
-      QString(), tr("Welcome to VNoteX and the new VNote!"), this);
-  if (ret == QMessageBox::Ok && importLegacyNotebook()) {
-    accept();
-    return;
-  }
-}
-
-bool ImportLegacyNotebookDialog::validateRootFolderInput(QString &p_msg) {
-  const auto rootFolderPath = m_infoWidget->getRootFolderPath();
-  if (!QFileInfo::exists(rootFolderPath) || !PathUtils::isLegalPath(rootFolderPath)) {
-    Utils::appendMsg(p_msg, tr("Please specify a valid root folder to open."));
-    return false;
-  }
-
-  if (!LegacyNotebookUtils::isLegacyNotebookRootFolder(rootFolderPath)) {
-    Utils::appendMsg(p_msg, tr("Failed to recognize a legacy notebook from the root folder."));
-    return false;
-  }
-
-  // Check if there already exists one notebook with the same root folder.
-  {
-    auto &notebookMgr = VNoteX::getInst().getNotebookMgr();
-    auto notebook = notebookMgr.findNotebookByRootFolderPath(rootFolderPath);
-    if (notebook) {
-      Utils::appendMsg(p_msg, tr("There already exists a notebook (%1) with the same root folder.")
-                                  .arg(notebook->getName()));
-      return false;
-    }
-  }
-
-  return true;
-}
-
-bool ImportLegacyNotebookDialog::importLegacyNotebook() {
-  const auto rootFolderPath = m_infoWidget->getRootFolderPath();
-
-  auto &notebookMgr = VNoteX::getInst().getNotebookMgr();
-
-  QString imageFolder;
-  QString attachmentFolder;
-  QDateTime createdTimeUtc;
-
-  try {
-    imageFolder = LegacyNotebookUtils::getImageFolderOfNotebook(rootFolderPath);
-    if (imageFolder.isEmpty()) {
-      imageFolder = Notebook::c_defaultImageFolder;
-    }
-
-    attachmentFolder = LegacyNotebookUtils::getAttachmentFolderOfNotebook(rootFolderPath);
-    if (attachmentFolder.isEmpty()) {
-      attachmentFolder = Notebook::c_defaultAttachmentFolder;
-    }
-
-    createdTimeUtc = LegacyNotebookUtils::getCreatedTimeUtcOfFolder(rootFolderPath);
-  } catch (Exception &p_e) {
-    QString msg = tr("Failed to read legacy notebook configuration in (%1) (%2).")
-                      .arg(rootFolderPath, p_e.what());
-    qCritical() << msg;
-    setInformationText(msg, ScrollDialog::InformationLevel::Error);
-    return false;
-  }
-
-  auto paras = NotebookParameters::createNotebookParameters(
-      notebookMgr, m_infoWidget->getType(), m_infoWidget->getName(), m_infoWidget->getDescription(),
-      rootFolderPath, m_infoWidget->getIcon(), imageFolder, attachmentFolder, createdTimeUtc,
-      m_infoWidget->getBackend(), m_infoWidget->getVersionController(),
-      m_infoWidget->getConfigMgr());
-  paras->m_ensureEmptyRootFolder = false;
-  QSharedPointer<Notebook> nb;
-  try {
-    nb = notebookMgr.newNotebook(paras);
-  } catch (Exception &p_e) {
-    QString msg = tr("Failed to create notebook in (%1) (%2).").arg(rootFolderPath, p_e.what());
-    qCritical() << msg;
-    setInformationText(msg, ScrollDialog::InformationLevel::Error);
-    return false;
-  }
-
-  QString errMsg;
-
-  // Copy legacy recycle bin folder into new one or just delete it if it is empty.
-  {
-    auto legacyBinFolder = LegacyNotebookUtils::getRecycleBinFolderOfNotebook(rootFolderPath);
-    if (!legacyBinFolder.isEmpty()) {
-      auto binFolderPath = PathUtils::concatenateFilePath(rootFolderPath, legacyBinFolder);
-      if (PathUtils::isEmptyDir(binFolderPath)) {
-        FileUtils::removeDir(binFolderPath);
-      } else {
-        nb->moveDirToRecycleBin(binFolderPath);
-      }
-    }
-  }
-
-  auto rootNode = nb->getRootNode();
-
-  try {
-    ImportFolderUtils::importFolderContentsByLegacyConfig(nb.data(), rootNode.data(), errMsg);
-  } catch (Exception &p_e) {
-    errMsg = tr("Failed to import folder contents by legacy config in (%1) (%2).")
-                 .arg(rootFolderPath, p_e.what());
-  }
-
-  emit nb->nodeUpdated(rootNode.data());
-
-  if (!errMsg.isEmpty()) {
-    qWarning() << errMsg;
-    setInformationText(errMsg, ScrollDialog::InformationLevel::Error);
-    completeButStay();
-    return false;
-  }
-
-  return true;
-}

+ 0 - 22
src/widgets/dialogs/importlegacynotebookdialog.h

@@ -1,22 +0,0 @@
-#ifndef IMPORTLEGACYNOTEBOOKDIALOG_H
-#define IMPORTLEGACYNOTEBOOKDIALOG_H
-
-#include "newnotebookdialog.h"
-
-namespace vnotex {
-class ImportLegacyNotebookDialog : public NewNotebookDialog {
-  Q_OBJECT
-public:
-  explicit ImportLegacyNotebookDialog(QWidget *p_parent = nullptr);
-
-protected:
-  void acceptedButtonClicked() Q_DECL_OVERRIDE;
-
-  bool validateRootFolderInput(QString &p_msg) Q_DECL_OVERRIDE;
-
-private:
-  bool importLegacyNotebook();
-};
-} // namespace vnotex
-
-#endif // IMPORTLEGACYNOTEBOOKDIALOG_H

+ 0 - 90
src/widgets/dialogs/legacynotebookutils.cpp

@@ -1,90 +0,0 @@
-#include "legacynotebookutils.h"
-
-#include <QJsonArray>
-#include <QJsonDocument>
-
-#include <utils/fileutils.h>
-#include <utils/pathutils.h>
-#include <utils/utils.h>
-
-using namespace vnotex;
-
-const QString LegacyNotebookUtils::c_legacyFolderConfigFile = "_vnote.json";
-
-static QDateTime stringToDateTime(const QString &p_str) {
-  if (p_str.isEmpty()) {
-    return QDateTime::currentDateTimeUtc();
-  }
-  return Utils::dateTimeFromStringUniform(p_str);
-}
-
-bool LegacyNotebookUtils::isLegacyNotebookRootFolder(const QString &p_folderPath) {
-  return QFileInfo::exists(getFolderConfigFile(p_folderPath));
-}
-
-QDateTime LegacyNotebookUtils::getCreatedTimeUtcOfFolder(const QString &p_folderPath) {
-  auto ti = getFolderConfig(p_folderPath).value(QStringLiteral("created_time")).toString();
-  return stringToDateTime(ti);
-}
-
-QString LegacyNotebookUtils::getAttachmentFolderOfNotebook(const QString &p_folderPath) {
-  return getFolderConfig(p_folderPath).value(QStringLiteral("attachment_folder")).toString();
-}
-
-QString LegacyNotebookUtils::getImageFolderOfNotebook(const QString &p_folderPath) {
-  return getFolderConfig(p_folderPath).value(QStringLiteral("image_folder")).toString();
-}
-
-QString LegacyNotebookUtils::getRecycleBinFolderOfNotebook(const QString &p_folderPath) {
-  return getFolderConfig(p_folderPath).value(QStringLiteral("recycle_bin_folder")).toString();
-}
-
-QString LegacyNotebookUtils::getFolderConfigFile(const QString &p_folderPath) {
-  return PathUtils::concatenateFilePath(p_folderPath, c_legacyFolderConfigFile);
-}
-
-QJsonObject LegacyNotebookUtils::getFolderConfig(const QString &p_folderPath) {
-  auto configFile = getFolderConfigFile(p_folderPath);
-  return QJsonDocument::fromJson(FileUtils::readFile(configFile)).object();
-}
-
-void LegacyNotebookUtils::removeFolderConfigFile(const QString &p_folderPath) {
-  auto configFile = getFolderConfigFile(p_folderPath);
-  FileUtils::removeFile(configFile);
-}
-
-void LegacyNotebookUtils::forEachFolder(const QJsonObject &p_config,
-                                        std::function<void(const QString &p_name)> p_func) {
-  auto folderArray = p_config.value(QStringLiteral("sub_directories")).toArray();
-  for (int i = 0; i < folderArray.size(); ++i) {
-    const auto name = folderArray[i].toObject().value(QStringLiteral("name")).toString();
-    p_func(name);
-  }
-}
-
-void LegacyNotebookUtils::forEachFile(
-    const QJsonObject &p_config,
-    std::function<void(const LegacyNotebookUtils::FileInfo &p_info)> p_func) {
-  auto fileArray = p_config.value(QStringLiteral("files")).toArray();
-  for (int i = 0; i < fileArray.size(); ++i) {
-    const auto obj = fileArray[i].toObject();
-    FileInfo info;
-    info.m_name = obj.value(QStringLiteral("name")).toString();
-    {
-      auto ti = obj.value(QStringLiteral("created_time")).toString();
-      info.m_createdTimeUtc = stringToDateTime(ti);
-    }
-    {
-      auto ti = obj.value(QStringLiteral("created_time")).toString();
-      info.m_modifiedTimeUtc = stringToDateTime(ti);
-    }
-    info.m_attachmentFolder = obj.value(QStringLiteral("attachment_folder")).toString();
-    {
-      auto arr = obj.value(QStringLiteral("tags")).toArray();
-      for (int i = 0; i < arr.size(); ++i) {
-        info.m_tags << arr[i].toString();
-      }
-    }
-    p_func(info);
-  }
-}

+ 0 - 54
src/widgets/dialogs/legacynotebookutils.h

@@ -1,54 +0,0 @@
-#ifndef LEGACYNOTEBOOKUTILS_H
-#define LEGACYNOTEBOOKUTILS_H
-
-#include <QDateTime>
-#include <QJsonObject>
-#include <QStringList>
-
-#include <functional>
-
-namespace vnotex {
-class LegacyNotebookUtils {
-public:
-  struct FileInfo {
-    QString m_name;
-
-    QDateTime m_createdTimeUtc = QDateTime::currentDateTimeUtc();
-
-    QDateTime m_modifiedTimeUtc = QDateTime::currentDateTimeUtc();
-
-    QString m_attachmentFolder;
-
-    QStringList m_tags;
-  };
-
-  LegacyNotebookUtils() = delete;
-
-  static bool isLegacyNotebookRootFolder(const QString &p_folderPath);
-
-  static QDateTime getCreatedTimeUtcOfFolder(const QString &p_folderPath);
-
-  static QString getAttachmentFolderOfNotebook(const QString &p_folderPath);
-
-  static QString getImageFolderOfNotebook(const QString &p_folderPath);
-
-  static QString getRecycleBinFolderOfNotebook(const QString &p_folderPath);
-
-  static QJsonObject getFolderConfig(const QString &p_folderPath);
-
-  static void removeFolderConfigFile(const QString &p_folderPath);
-
-  static void forEachFolder(const QJsonObject &p_config,
-                            std::function<void(const QString &p_name)> p_func);
-
-  static void forEachFile(const QJsonObject &p_config,
-                          std::function<void(const LegacyNotebookUtils::FileInfo &p_info)> p_func);
-
-private:
-  static QString getFolderConfigFile(const QString &p_folderPath);
-
-  static const QString c_legacyFolderConfigFile;
-};
-} // namespace vnotex
-
-#endif // LEGACYNOTEBOOKUTILS_H

+ 0 - 2
src/widgets/mainwindow.cpp

@@ -310,8 +310,6 @@ void MainWindow::setupNotebookExplorer() {
           &NotebookExplorer::importFile);
           &NotebookExplorer::importFile);
   connect(&VNoteX::getInst(), &VNoteX::importFolderRequested, m_notebookExplorer,
   connect(&VNoteX::getInst(), &VNoteX::importFolderRequested, m_notebookExplorer,
           &NotebookExplorer::importFolder);
           &NotebookExplorer::importFolder);
-  connect(&VNoteX::getInst(), &VNoteX::importLegacyNotebookRequested, m_notebookExplorer,
-          &NotebookExplorer::importLegacyNotebook);
   connect(&VNoteX::getInst(), &VNoteX::manageNotebooksRequested, m_notebookExplorer,
   connect(&VNoteX::getInst(), &VNoteX::manageNotebooksRequested, m_notebookExplorer,
           &NotebookExplorer::manageNotebooks);
           &NotebookExplorer::manageNotebooks);
   connect(&VNoteX::getInst(), &VNoteX::locateNodeRequested, this, [this](Node *p_node) {
   connect(&VNoteX::getInst(), &VNoteX::locateNodeRequested, this, [this](Node *p_node) {

+ 0 - 6
src/widgets/notebookexplorer.cpp

@@ -8,7 +8,6 @@
 #include <QVBoxLayout>
 #include <QVBoxLayout>
 
 
 #include "dialogs/importfolderdialog.h"
 #include "dialogs/importfolderdialog.h"
-#include "dialogs/importlegacynotebookdialog.h"
 #include "dialogs/importnotebookdialog.h"
 #include "dialogs/importnotebookdialog.h"
 #include "dialogs/managenotebooksdialog.h"
 #include "dialogs/managenotebooksdialog.h"
 #include "dialogs/newfolderdialog.h"
 #include "dialogs/newfolderdialog.h"
@@ -395,11 +394,6 @@ void NotebookExplorer::importFolder() {
   }
   }
 }
 }
 
 
-void NotebookExplorer::importLegacyNotebook() {
-  ImportLegacyNotebookDialog dialog(VNoteX::getInst().getMainWindow());
-  dialog.exec();
-}
-
 void NotebookExplorer::manageNotebooks() {
 void NotebookExplorer::manageNotebooks() {
   ManageNotebooksDialog dialog(m_currentNotebook.data(), VNoteX::getInst().getMainWindow());
   ManageNotebooksDialog dialog(m_currentNotebook.data(), VNoteX::getInst().getMainWindow());
   dialog.exec();
   dialog.exec();

+ 0 - 2
src/widgets/notebookexplorer.h

@@ -55,8 +55,6 @@ public slots:
 
 
   void importFolder();
   void importFolder();
 
 
-  void importLegacyNotebook();
-
   void locateNode(Node *p_node);
   void locateNode(Node *p_node);
 
 
   void manageNotebooks();
   void manageNotebooks();

+ 1 - 5
src/widgets/toolbarhelper.cpp

@@ -77,13 +77,9 @@ QToolBar *ToolBarHelper::setupFileToolBar(MainWindow *p_win, QToolBar *p_toolBar
     btnMenu->addSeparator();
     btnMenu->addSeparator();
 
 
     // Import notebook.
     // Import notebook.
-    btnMenu->addAction(MainWindow::tr("Open Other Notebooks"), btnMenu,
+    btnMenu->addAction(MainWindow::tr("Open Notebook"), btnMenu,
                        []() { emit VNoteX::getInst().importNotebookRequested(); });
                        []() { emit VNoteX::getInst().importNotebookRequested(); });
 
 
-    // Import notebook of VNote 2.
-    btnMenu->addAction(MainWindow::tr("Open Legacy Notebooks Of VNote 2"), btnMenu,
-                       []() { emit VNoteX::getInst().importLegacyNotebookRequested(); });
-
     btnMenu->addSeparator();
     btnMenu->addSeparator();
 
 
     // Manage notebook.
     // Manage notebook.