|
|
@@ -51,6 +51,24 @@ void VFileList::initActions()
|
|
|
fileInfoAct->setStatusTip(tr("View and edit current note's information"));
|
|
|
connect(fileInfoAct, &QAction::triggered,
|
|
|
this, &VFileList::curFileInfo);
|
|
|
+
|
|
|
+ copyAct = new QAction(QIcon(":/resources/icons/copy.svg"),
|
|
|
+ tr("&Copy"), this);
|
|
|
+ copyAct->setStatusTip(tr("Copy selected notes"));
|
|
|
+ connect(copyAct, &QAction::triggered,
|
|
|
+ this, &VFileList::copySelectedFiles);
|
|
|
+
|
|
|
+ cutAct = new QAction(QIcon(":/resources/icons/cut.svg"),
|
|
|
+ tr("&Cut"), this);
|
|
|
+ cutAct->setStatusTip(tr("Cut selected notes"));
|
|
|
+ connect(cutAct, &QAction::triggered,
|
|
|
+ this, &VFileList::cutSelectedFiles);
|
|
|
+
|
|
|
+ pasteAct = new QAction(QIcon(":/resources/icons/paste.svg"),
|
|
|
+ tr("&Paste"), this);
|
|
|
+ pasteAct->setStatusTip(tr("Paste notes"));
|
|
|
+ connect(pasteAct, &QAction::triggered,
|
|
|
+ this, &VFileList::pasteFilesInCurDir);
|
|
|
}
|
|
|
|
|
|
void VFileList::setDirectory(QJsonObject dirJson)
|
|
|
@@ -88,6 +106,7 @@ void VFileList::updateFileList()
|
|
|
{
|
|
|
QString path = QDir(rootPath).filePath(relativePath);
|
|
|
|
|
|
+ fileList->clear();
|
|
|
if (!QDir(path).exists()) {
|
|
|
qDebug() << "invalid notebook directory:" << path;
|
|
|
QMessageBox msgBox(QMessageBox::Warning, tr("Warning"), tr("Invalid notebook directory."),
|
|
|
@@ -144,7 +163,8 @@ void VFileList::fileInfo(const QString &p_notebook, const QString &p_relativePat
|
|
|
defaultName = name;
|
|
|
continue;
|
|
|
}
|
|
|
- renameFile(p_notebook, p_relativePath, name);
|
|
|
+ copyFile(p_notebook, p_relativePath, p_notebook,
|
|
|
+ QDir(VUtils::basePathFromPath(p_relativePath)).filePath(name), true);
|
|
|
}
|
|
|
break;
|
|
|
} while (true);
|
|
|
@@ -252,8 +272,13 @@ void VFileList::contextMenuRequested(QPoint pos)
|
|
|
if (item) {
|
|
|
menu.addAction(deleteFileAct);
|
|
|
menu.addAction(fileInfoAct);
|
|
|
+ menu.addAction(copyAct);
|
|
|
+ menu.addAction(cutAct);
|
|
|
}
|
|
|
|
|
|
+ if (VUtils::opTypeInClipboard() == ClipboardOpType::CopyFile) {
|
|
|
+ menu.addAction(pasteAct);
|
|
|
+ }
|
|
|
menu.exec(fileList->mapToGlobal(pos));
|
|
|
}
|
|
|
|
|
|
@@ -306,52 +331,20 @@ QListWidgetItem* VFileList::createFileAndUpdateList(const QString &name)
|
|
|
file.close();
|
|
|
qDebug() << "create file:" << filePath;
|
|
|
|
|
|
- // Update current directory's config file to include this new file
|
|
|
- QJsonObject dirJson = VConfigManager::readDirectoryConfig(path);
|
|
|
- Q_ASSERT(!dirJson.isEmpty());
|
|
|
- QJsonObject fileJson;
|
|
|
- fileJson["name"] = name;
|
|
|
- QJsonArray fileArray = dirJson["files"].toArray();
|
|
|
- fileArray.push_front(fileJson);
|
|
|
- dirJson["files"] = fileArray;
|
|
|
- if (!VConfigManager::writeDirectoryConfig(path, dirJson)) {
|
|
|
- qWarning() << "error: fail to update directory's configuration file to add a new file"
|
|
|
- << name;
|
|
|
+ if (!addFileInConfig(filePath, 0)) {
|
|
|
file.remove();
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
- return insertFileListItem(fileJson, true);
|
|
|
+ return insertFileListItem(readFileInConfig(filePath), true);
|
|
|
}
|
|
|
|
|
|
void VFileList::deleteFileAndUpdateList(const QString &p_notebook,
|
|
|
const QString &p_relativePath)
|
|
|
{
|
|
|
- QString path = QDir(vnote->getNotebookPath(p_notebook)).filePath(VUtils::basePathFromPath(p_relativePath));
|
|
|
- QString fileName = VUtils::fileNameFromPath(p_relativePath);
|
|
|
- QString filePath = QDir(path).filePath(fileName);
|
|
|
+ QString filePath = QDir(vnote->getNotebookPath(p_notebook)).filePath(p_relativePath);
|
|
|
|
|
|
- // Update current directory's config file to exclude this file
|
|
|
- QJsonObject dirJson = VConfigManager::readDirectoryConfig(path);
|
|
|
- Q_ASSERT(!dirJson.isEmpty());
|
|
|
- QJsonArray fileArray = dirJson["files"].toArray();
|
|
|
- bool deleted = false;
|
|
|
- for (int i = 0; i < fileArray.size(); ++i) {
|
|
|
- QJsonObject ele = fileArray[i].toObject();
|
|
|
- if (ele["name"].toString() == fileName) {
|
|
|
- fileArray.removeAt(i);
|
|
|
- deleted = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (!deleted) {
|
|
|
- qWarning() << "error: fail to find" << fileName << "to delete";
|
|
|
- return;
|
|
|
- }
|
|
|
- dirJson["files"] = fileArray;
|
|
|
- if (!VConfigManager::writeDirectoryConfig(path, dirJson)) {
|
|
|
- qWarning() << "error: fail to update directory's configuration file to delete"
|
|
|
- << fileName;
|
|
|
+ if (!removeFileInConfig(filePath)) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -446,116 +439,291 @@ void VFileList::handleDirectoryRenamed(const QString ¬ebook,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// @p_relativePath contains the flie name
|
|
|
-void VFileList::renameFile(const QString &p_notebook,
|
|
|
- const QString &p_relativePath, const QString &p_newName)
|
|
|
+void VFileList::convertFileType(const QString ¬ebook, const QString &fileRelativePath,
|
|
|
+ DocType oldType, DocType newType)
|
|
|
{
|
|
|
- QString name = VUtils::fileNameFromPath(p_relativePath);
|
|
|
+ Q_ASSERT(oldType != newType);
|
|
|
+ QString filePath = QDir(vnote->getNotebookPath(notebook)).filePath(fileRelativePath);
|
|
|
+ QString fileText = VUtils::readFileFromDisk(filePath);
|
|
|
+ QTextEdit editor;
|
|
|
+ if (oldType == DocType::Markdown) {
|
|
|
+ editor.setPlainText(fileText);
|
|
|
+ fileText = editor.toHtml();
|
|
|
+ } else {
|
|
|
+ editor.setHtml(fileText);
|
|
|
+ fileText = editor.toPlainText();
|
|
|
+ }
|
|
|
+ VUtils::writeFileToDisk(filePath, fileText);
|
|
|
+}
|
|
|
+
|
|
|
+void VFileList::deleteLocalImages(const QString &filePath)
|
|
|
+{
|
|
|
+ if (!VUtils::isMarkdown(filePath)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ QVector<QString> images = VUtils::imagesFromMarkdownFile(filePath);
|
|
|
+ int deleted = 0;
|
|
|
+ for (int i = 0; i < images.size(); ++i) {
|
|
|
+ QFile file(images[i]);
|
|
|
+ if (file.remove()) {
|
|
|
+ ++deleted;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ qDebug() << "delete" << deleted << "images for" << filePath;
|
|
|
+}
|
|
|
+
|
|
|
+void VFileList::copySelectedFiles(bool p_isCut)
|
|
|
+{
|
|
|
+ QList<QListWidgetItem *> items = fileList->selectedItems();
|
|
|
+ if (items.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ QJsonArray files;
|
|
|
+ QDir dir(relativePath);
|
|
|
+ for (int i = 0; i < items.size(); ++i) {
|
|
|
+ QJsonObject itemJson = items[i]->data(Qt::UserRole).toJsonObject();
|
|
|
+ QString itemName = itemJson["name"].toString();
|
|
|
+ QJsonObject fileJson;
|
|
|
+ fileJson["notebook"] = notebook;
|
|
|
+ fileJson["relative_path"] = dir.filePath(itemName);
|
|
|
+ files.append(fileJson);
|
|
|
+ }
|
|
|
+
|
|
|
+ copyFileInfoToClipboard(files, p_isCut);
|
|
|
+}
|
|
|
+
|
|
|
+void VFileList::cutSelectedFiles()
|
|
|
+{
|
|
|
+ copySelectedFiles(true);
|
|
|
+}
|
|
|
+
|
|
|
+void VFileList::copyFileInfoToClipboard(const QJsonArray &p_files, bool p_isCut)
|
|
|
+{
|
|
|
+ QJsonObject clip;
|
|
|
+ clip["operation"] = (int)ClipboardOpType::CopyFile;
|
|
|
+ clip["is_cut"] = p_isCut;
|
|
|
+ clip["sources"] = p_files;
|
|
|
+
|
|
|
+ QClipboard *clipboard = QApplication::clipboard();
|
|
|
+ clipboard->setText(QJsonDocument(clip).toJson(QJsonDocument::Compact));
|
|
|
+}
|
|
|
+
|
|
|
+void VFileList::pasteFilesInCurDir()
|
|
|
+{
|
|
|
+ pasteFiles(notebook, relativePath);
|
|
|
+}
|
|
|
+
|
|
|
+void VFileList::pasteFiles(const QString &p_notebook, const QString &p_dirRelativePath)
|
|
|
+{
|
|
|
+ qDebug() << "paste files to" << p_notebook << p_dirRelativePath;
|
|
|
+ QClipboard *clipboard = QApplication::clipboard();
|
|
|
+ QString text = clipboard->text();
|
|
|
+ QJsonObject clip = QJsonDocument::fromJson(text.toLocal8Bit()).object();
|
|
|
+ Q_ASSERT(!clip.isEmpty() && clip["operation"] == (int)ClipboardOpType::CopyFile);
|
|
|
+
|
|
|
+ bool isCut = clip["is_cut"].toBool();
|
|
|
+ QJsonArray sources = clip["sources"].toArray();
|
|
|
+
|
|
|
+ int nrFiles = sources.size();
|
|
|
+ QDir destDir(p_dirRelativePath);
|
|
|
+ int nrPasted = 0;
|
|
|
+ for (int i = 0; i < nrFiles; ++i) {
|
|
|
+ QJsonObject file = sources[i].toObject();
|
|
|
+ QString srcNotebook = file["notebook"].toString();
|
|
|
+ QString srcRelativePath = file["relative_path"].toString();
|
|
|
+ bool ret = copyFile(srcNotebook, srcRelativePath, p_notebook,
|
|
|
+ destDir.filePath(VUtils::fileNameFromPath(srcRelativePath)), isCut);
|
|
|
+ if (ret) {
|
|
|
+ nrPasted++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ qDebug() << "pasted" << nrPasted << "files sucessfully";
|
|
|
+ clipboard->clear();
|
|
|
+}
|
|
|
+
|
|
|
+bool VFileList::copyFile(const QString &p_srcNotebook, const QString &p_srcRelativePath,
|
|
|
+ const QString &p_destNotebook, const QString &p_destRelativePath,
|
|
|
+ bool p_isCut)
|
|
|
+{
|
|
|
+ QString srcPath = QDir(vnote->getNotebookPath(p_srcNotebook)).filePath(p_srcRelativePath);
|
|
|
+ srcPath = QDir::cleanPath(srcPath);
|
|
|
+ QString destPath = QDir(vnote->getNotebookPath(p_destNotebook)).filePath(p_destRelativePath);
|
|
|
+ destPath = QDir::cleanPath(destPath);
|
|
|
+ if (srcPath == destPath) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
// If change the file type, we need to convert it
|
|
|
- DocType docType = VUtils::isMarkdown(name) ? DocType::Markdown : DocType::Html;
|
|
|
- DocType newDocType = VUtils::isMarkdown(p_newName) ? DocType::Markdown : DocType::Html;
|
|
|
+ bool needConversion = false;
|
|
|
+ DocType docType = VUtils::isMarkdown(srcPath) ? DocType::Markdown : DocType::Html;
|
|
|
+ DocType newDocType = VUtils::isMarkdown(destPath) ? DocType::Markdown : DocType::Html;
|
|
|
if (docType != newDocType) {
|
|
|
- if (editArea->isFileOpened(p_notebook, p_relativePath)) {
|
|
|
+ if (editArea->isFileOpened(p_srcNotebook, p_srcRelativePath)) {
|
|
|
QMessageBox msgBox(QMessageBox::Warning, tr("Warning"), QString("Rename will change the note type"),
|
|
|
QMessageBox::Ok | QMessageBox::Cancel, this);
|
|
|
msgBox.setDefaultButton(QMessageBox::Ok);
|
|
|
- msgBox.setInformativeText(QString("You should close the note %1 before continue").arg(name));
|
|
|
+ msgBox.setInformativeText(QString("You should close the note %1 before continue")
|
|
|
+ .arg(VUtils::fileNameFromPath(p_srcRelativePath)));
|
|
|
if (QMessageBox::Ok == msgBox.exec()) {
|
|
|
QJsonObject curItemJson;
|
|
|
- curItemJson["notebook"] = p_notebook;
|
|
|
- curItemJson["relative_path"] = p_relativePath;
|
|
|
+ curItemJson["notebook"] = p_srcNotebook;
|
|
|
+ curItemJson["relative_path"] = p_srcRelativePath;
|
|
|
curItemJson["is_forced"] = false;
|
|
|
if (!editArea->closeFile(curItemJson)) {
|
|
|
- return;
|
|
|
+ return false;
|
|
|
}
|
|
|
} else {
|
|
|
- return;
|
|
|
+ return false;
|
|
|
}
|
|
|
}
|
|
|
- convertFileType(p_notebook, p_relativePath, docType, newDocType);
|
|
|
+ // Convert it later
|
|
|
+ needConversion = true;
|
|
|
}
|
|
|
|
|
|
- QString path = QDir(vnote->getNotebookPath(p_notebook)).filePath(VUtils::basePathFromPath(p_relativePath));
|
|
|
- QFile file(QDir(path).filePath(name));
|
|
|
- QString newFilePath(QDir(path).filePath(p_newName));
|
|
|
- Q_ASSERT(file.exists());
|
|
|
- if (!file.rename(newFilePath)) {
|
|
|
- qWarning() << "error: fail to rename file" << name << "under" << path;
|
|
|
- QMessageBox msgBox(QMessageBox::Warning, tr("Warning"), QString("Could not rename note \"%1\" under \"%2\".")
|
|
|
- .arg(name).arg(path), QMessageBox::Ok, this);
|
|
|
- msgBox.setInformativeText(QString("Please check if there already exists a file named \"%1\".").arg(p_newName));
|
|
|
+ QVector<QString> images;
|
|
|
+ if (docType == DocType::Markdown) {
|
|
|
+ images = VUtils::imagesFromMarkdownFile(srcPath);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Copy the file
|
|
|
+ if (!VUtils::copyFile(srcPath, destPath, p_isCut)) {
|
|
|
+ QMessageBox msgBox(QMessageBox::Warning, tr("Warning"), QString("Fail to copy %1 from %2.")
|
|
|
+ .arg(p_srcRelativePath).arg(p_srcNotebook), QMessageBox::Ok, this);
|
|
|
+ msgBox.setInformativeText(QString("Please check if there already exists a file with the same name"));
|
|
|
msgBox.exec();
|
|
|
- return;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (needConversion) {
|
|
|
+ convertFileType(p_destNotebook, p_destRelativePath, docType, newDocType);
|
|
|
+ }
|
|
|
+
|
|
|
+ // We need to copy images when it is still markdown
|
|
|
+ if (!images.isEmpty()) {
|
|
|
+ if (newDocType == DocType::Markdown) {
|
|
|
+ QString dirPath = QDir(VUtils::basePathFromPath(destPath)).filePath("images");
|
|
|
+ VUtils::makeDirectory(dirPath);
|
|
|
+ int nrPasted = 0;
|
|
|
+ for (int i = 0; i < images.size(); ++i) {
|
|
|
+ if (!QFile(images[i]).exists()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ QString destImagePath = QDir(dirPath).filePath(VUtils::fileNameFromPath(images[i]));
|
|
|
+ if (VUtils::copyFile(images[i], destImagePath, p_isCut)) {
|
|
|
+ nrPasted++;
|
|
|
+ } else {
|
|
|
+ QMessageBox msgBox(QMessageBox::Warning, tr("Warning"), QString("Fail to copy image %1.")
|
|
|
+ .arg(images[i]), QMessageBox::Ok, this);
|
|
|
+ msgBox.setInformativeText(QString("Please check if there already exists a file with the same name and manually copy it"));
|
|
|
+ msgBox.exec();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ qDebug() << "pasted" << nrPasted << "images sucessfully";
|
|
|
+ } else {
|
|
|
+ // Delete the images
|
|
|
+ for (int i = 0; i < images.size(); ++i) {
|
|
|
+ QFile file(images[i]);
|
|
|
+ file.remove();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ int idx = -1;
|
|
|
+ if (p_isCut) {
|
|
|
+ // Remove src in the config
|
|
|
+ idx = removeFileInConfig(srcPath);
|
|
|
+ if (VUtils::basePathFromPath(srcPath) != VUtils::basePathFromPath(destPath)) {
|
|
|
+ idx = -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Add dest in the config
|
|
|
+ addFileInConfig(destPath, idx);
|
|
|
+
|
|
|
+ updateFileList();
|
|
|
+
|
|
|
+ if (p_isCut) {
|
|
|
+ emit fileRenamed(p_srcNotebook, p_srcRelativePath,
|
|
|
+ p_destNotebook, p_destRelativePath);
|
|
|
}
|
|
|
+ return true;
|
|
|
+}
|
|
|
|
|
|
- // Update directory's config file
|
|
|
- QJsonObject dirJson = VConfigManager::readDirectoryConfig(path);
|
|
|
+int VFileList::removeFileInConfig(const QString &p_filePath)
|
|
|
+{
|
|
|
+ QString dirPath = VUtils::basePathFromPath(p_filePath);
|
|
|
+ QString fileName = VUtils::fileNameFromPath(p_filePath);
|
|
|
+ // Update current directory's config file to exclude this file
|
|
|
+ QJsonObject dirJson = VConfigManager::readDirectoryConfig(dirPath);
|
|
|
Q_ASSERT(!dirJson.isEmpty());
|
|
|
QJsonArray fileArray = dirJson["files"].toArray();
|
|
|
- int index = 0;
|
|
|
- for (index = 0; index < fileArray.size(); ++index) {
|
|
|
- QJsonObject tmp = fileArray[index].toObject();
|
|
|
- if (tmp["name"].toString() == name) {
|
|
|
- tmp["name"] = p_newName;
|
|
|
- fileArray[index] = tmp;
|
|
|
+ bool deleted = false;
|
|
|
+ int idx = -1;
|
|
|
+ for (int i = 0; i < fileArray.size(); ++i) {
|
|
|
+ QJsonObject ele = fileArray[i].toObject();
|
|
|
+ if (ele["name"].toString() == fileName) {
|
|
|
+ fileArray.removeAt(i);
|
|
|
+ deleted = true;
|
|
|
+ idx = i;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- Q_ASSERT(index != fileArray.size());
|
|
|
- dirJson["files"] = fileArray;
|
|
|
- if (!VConfigManager::writeDirectoryConfig(path, dirJson)) {
|
|
|
- qWarning() << "error: fail to rename file"
|
|
|
- << name << "to" << p_newName;
|
|
|
- file.rename(name);
|
|
|
- return;
|
|
|
+ if (!deleted) {
|
|
|
+ qWarning() << "error: fail to find" << fileName << "to delete";
|
|
|
+ return idx;
|
|
|
}
|
|
|
-
|
|
|
- // Update item
|
|
|
- QListWidgetItem *item = findItem(p_notebook, p_relativePath);
|
|
|
- if (item) {
|
|
|
- QJsonObject itemJson = item->data(Qt::UserRole).toJsonObject();
|
|
|
- itemJson["name"] = p_newName;
|
|
|
- item->setData(Qt::UserRole, itemJson);
|
|
|
- item->setText(p_newName);
|
|
|
+ dirJson["files"] = fileArray;
|
|
|
+ if (!VConfigManager::writeDirectoryConfig(dirPath, dirJson)) {
|
|
|
+ qWarning() << "error: fail to update directory's configuration file to delete"
|
|
|
+ << fileName;
|
|
|
+ return idx;
|
|
|
}
|
|
|
-
|
|
|
- QString oldPath = QDir::cleanPath(p_relativePath);
|
|
|
- QString newPath = QDir::cleanPath(QDir(VUtils::basePathFromPath(p_relativePath)).filePath(p_newName));
|
|
|
- qDebug() << "file renamed" << oldPath << "to" << newPath;
|
|
|
- emit fileRenamed(p_notebook, oldPath, newPath);
|
|
|
+ return idx;
|
|
|
}
|
|
|
|
|
|
-void VFileList::convertFileType(const QString ¬ebook, const QString &fileRelativePath,
|
|
|
- DocType oldType, DocType newType)
|
|
|
+// @index = -1, add it to the end of the list
|
|
|
+bool VFileList::addFileInConfig(const QString &p_filePath, int p_index)
|
|
|
{
|
|
|
- Q_ASSERT(oldType != newType);
|
|
|
- QString filePath = QDir(vnote->getNotebookPath(notebook)).filePath(fileRelativePath);
|
|
|
- QString fileText = VUtils::readFileFromDisk(filePath);
|
|
|
- QTextEdit editor;
|
|
|
- if (oldType == DocType::Markdown) {
|
|
|
- editor.setPlainText(fileText);
|
|
|
- fileText = editor.toHtml();
|
|
|
- } else {
|
|
|
- editor.setHtml(fileText);
|
|
|
- fileText = editor.toPlainText();
|
|
|
+ QString dirPath = VUtils::basePathFromPath(p_filePath);
|
|
|
+ QString fileName = VUtils::fileNameFromPath(p_filePath);
|
|
|
+
|
|
|
+ // Update current directory's config file to include this file
|
|
|
+ QJsonObject dirJson = VConfigManager::readDirectoryConfig(dirPath);
|
|
|
+ Q_ASSERT(!dirJson.isEmpty());
|
|
|
+ QJsonObject fileJson;
|
|
|
+ fileJson["name"] = fileName;
|
|
|
+ QJsonArray fileArray = dirJson["files"].toArray();
|
|
|
+ if (p_index == -1) {
|
|
|
+ p_index = fileArray.size();
|
|
|
}
|
|
|
- VUtils::writeFileToDisk(filePath, fileText);
|
|
|
+ fileArray.insert(p_index, fileJson);
|
|
|
+ dirJson["files"] = fileArray;
|
|
|
+ if (!VConfigManager::writeDirectoryConfig(dirPath, dirJson)) {
|
|
|
+ qWarning() << "error: fail to update directory's configuration file to add a new file"
|
|
|
+ << fileName;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
-void VFileList::deleteLocalImages(const QString &filePath)
|
|
|
+QJsonObject VFileList::readFileInConfig(const QString &p_filePath)
|
|
|
{
|
|
|
- if (!VUtils::isMarkdown(filePath)) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ QString dirPath = VUtils::basePathFromPath(p_filePath);
|
|
|
+ QString fileName = VUtils::fileNameFromPath(p_filePath);
|
|
|
|
|
|
- QVector<QString> images = VUtils::imagesFromMarkdownFile(filePath);
|
|
|
- int deleted = 0;
|
|
|
- for (int i = 0; i < images.size(); ++i) {
|
|
|
- QFile file(images[i]);
|
|
|
- if (file.remove()) {
|
|
|
- ++deleted;
|
|
|
+ QJsonObject dirJson = VConfigManager::readDirectoryConfig(dirPath);
|
|
|
+ Q_ASSERT(!dirJson.isEmpty());
|
|
|
+
|
|
|
+ qDebug() << "config" << p_filePath;
|
|
|
+ QJsonArray fileArray = dirJson["files"].toArray();
|
|
|
+ for (int i = 0; i < fileArray.size(); ++i) {
|
|
|
+ QJsonObject ele = fileArray[i].toObject();
|
|
|
+ if (ele["name"].toString() == fileName) {
|
|
|
+ return ele;
|
|
|
}
|
|
|
}
|
|
|
- qDebug() << "delete" << deleted << "images for" << filePath;
|
|
|
+ return QJsonObject();
|
|
|
}
|