|
|
@ -34,6 +34,7 @@ |
|
|
|
#include <QDomDocument> |
|
|
|
#include <QDomDocument> |
|
|
|
#include <QXmlStreamWriter> |
|
|
|
#include <QXmlStreamWriter> |
|
|
|
#include <QModelIndex> |
|
|
|
#include <QModelIndex> |
|
|
|
|
|
|
|
#include <QtConcurrent> |
|
|
|
|
|
|
|
|
|
|
|
#include "frameworks/UBPlatformUtils.h" |
|
|
|
#include "frameworks/UBPlatformUtils.h" |
|
|
|
#include "frameworks/UBFileSystemUtils.h" |
|
|
|
#include "frameworks/UBFileSystemUtils.h" |
|
|
@ -98,7 +99,6 @@ UBPersistenceManager::UBPersistenceManager(QObject *pParent) |
|
|
|
mDocumentTreeStructureModel = new UBDocumentTreeModel(this); |
|
|
|
mDocumentTreeStructureModel = new UBDocumentTreeModel(this); |
|
|
|
createDocumentProxiesStructure(); |
|
|
|
createDocumentProxiesStructure(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
emit proxyListChanged(); |
|
|
|
emit proxyListChanged(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -123,6 +123,50 @@ UBPersistenceManager::~UBPersistenceManager() |
|
|
|
{ |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UBPersistenceManager::createDocumentProxiesStructure(const QFileInfoList &contentInfoList, bool interactive) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Create a QFutureWatcher and connect signals and slots.
|
|
|
|
|
|
|
|
QFutureWatcher<UBDocumentProxy*> futureWatcher; |
|
|
|
|
|
|
|
QObject::connect(&futureWatcher, &QFutureWatcher<void>::finished, &mProgress, &QProgressDialog::reset); |
|
|
|
|
|
|
|
QObject::connect(&futureWatcher, &QFutureWatcher<void>::progressRangeChanged, &mProgress, &QProgressDialog::setRange); |
|
|
|
|
|
|
|
QObject::connect(&futureWatcher, &QFutureWatcher<void>::progressValueChanged, &mProgress, &QProgressDialog::setValue); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Start the computation.
|
|
|
|
|
|
|
|
std::function<UBDocumentProxy* (QFileInfo contentInfo)> createDocumentProxyLambda = [=](QFileInfo contentInfo) { |
|
|
|
|
|
|
|
return createDocumentProxyStructure(contentInfo); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QFuture<UBDocumentProxy*> proxiesFuture = QtConcurrent::mapped(contentInfoList, createDocumentProxyLambda); |
|
|
|
|
|
|
|
futureWatcher.setFuture(proxiesFuture); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Display the dialog and start the event loop.
|
|
|
|
|
|
|
|
mProgress.exec(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
futureWatcher.waitForFinished(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QList<UBDocumentProxy*> proxies = futureWatcher.future().results(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (auto&& proxy : qAsConst(proxies)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (proxy) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QString docGroupName = proxy->metaData(UBSettings::documentGroupName).toString(); |
|
|
|
|
|
|
|
QModelIndex parentIndex = mDocumentTreeStructureModel->goTo(docGroupName); |
|
|
|
|
|
|
|
if (parentIndex.isValid()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (!interactive) |
|
|
|
|
|
|
|
mDocumentTreeStructureModel->addDocument(proxy, parentIndex); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
processInteractiveReplacementDialog(proxy); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
qDebug() << "something went wrong"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void UBPersistenceManager::createDocumentProxiesStructure(bool interactive) |
|
|
|
void UBPersistenceManager::createDocumentProxiesStructure(bool interactive) |
|
|
|
{ |
|
|
|
{ |
|
|
|
mDocumentRepositoryPath = UBSettings::userDocumentDirectory(); |
|
|
|
mDocumentRepositoryPath = UBSettings::userDocumentDirectory(); |
|
|
@ -130,8 +174,13 @@ void UBPersistenceManager::createDocumentProxiesStructure(bool interactive) |
|
|
|
QDir rootDir(mDocumentRepositoryPath); |
|
|
|
QDir rootDir(mDocumentRepositoryPath); |
|
|
|
rootDir.mkpath(rootDir.path()); |
|
|
|
rootDir.mkpath(rootDir.path()); |
|
|
|
|
|
|
|
|
|
|
|
QFileInfoList contentList = rootDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Time | QDir::Reversed); |
|
|
|
QFileInfoList contentInfoList = rootDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Time | QDir::Reversed); |
|
|
|
createDocumentProxiesStructure(contentList, interactive); |
|
|
|
|
|
|
|
|
|
|
|
mProgress.setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint); |
|
|
|
|
|
|
|
mProgress.setLabelText(QString("retrieving all your documents (found %1)").arg(contentInfoList.size())); |
|
|
|
|
|
|
|
mProgress.setCancelButton(nullptr); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
createDocumentProxiesStructure(contentInfoList, interactive); |
|
|
|
|
|
|
|
|
|
|
|
if (QFileInfo(mFoldersXmlStorageName).exists()) { |
|
|
|
if (QFileInfo(mFoldersXmlStorageName).exists()) { |
|
|
|
QDomDocument xmlDom; |
|
|
|
QDomDocument xmlDom; |
|
|
@ -158,12 +207,9 @@ void UBPersistenceManager::createDocumentProxiesStructure(bool interactive) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void UBPersistenceManager::createDocumentProxiesStructure(const QFileInfoList &contentInfo, bool interactive) |
|
|
|
UBDocumentProxy* UBPersistenceManager::createDocumentProxyStructure(QFileInfo& contentInfo) |
|
|
|
{ |
|
|
|
{ |
|
|
|
foreach(QFileInfo path, contentInfo) |
|
|
|
QString fullPath = contentInfo.absoluteFilePath(); |
|
|
|
{ |
|
|
|
|
|
|
|
QString fullPath = path.absoluteFilePath(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QDir dir(fullPath); |
|
|
|
QDir dir(fullPath); |
|
|
|
|
|
|
|
|
|
|
|
if (dir.entryList(QDir::Files | QDir::NoDotAndDotDot).size() > 0) |
|
|
|
if (dir.entryList(QDir::Files | QDir::NoDotAndDotDot).size() > 0) |
|
|
@ -174,12 +220,7 @@ void UBPersistenceManager::createDocumentProxiesStructure(const QFileInfoList &c |
|
|
|
|
|
|
|
|
|
|
|
if (docName.isEmpty()) { |
|
|
|
if (docName.isEmpty()) { |
|
|
|
qDebug() << "Group name and document name are empty in UBPersistenceManager::createDocumentProxiesStructure()"; |
|
|
|
qDebug() << "Group name and document name are empty in UBPersistenceManager::createDocumentProxiesStructure()"; |
|
|
|
continue; |
|
|
|
return nullptr; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QModelIndex parentIndex = mDocumentTreeStructureModel->goTo(docGroupName); |
|
|
|
|
|
|
|
if (!parentIndex.isValid()) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
UBDocumentProxy* docProxy = new UBDocumentProxy(fullPath); // managed in UBDocumentTreeNode
|
|
|
|
UBDocumentProxy* docProxy = new UBDocumentProxy(fullPath); // managed in UBDocumentTreeNode
|
|
|
@ -189,13 +230,13 @@ void UBPersistenceManager::createDocumentProxiesStructure(const QFileInfoList &c |
|
|
|
|
|
|
|
|
|
|
|
docProxy->setPageCount(sceneCount(docProxy)); |
|
|
|
docProxy->setPageCount(sceneCount(docProxy)); |
|
|
|
|
|
|
|
|
|
|
|
if (!interactive) |
|
|
|
docProxy->moveToThread(UBApplication::instance()->thread()); |
|
|
|
mDocumentTreeStructureModel->addDocument(docProxy, parentIndex); |
|
|
|
|
|
|
|
else |
|
|
|
return docProxy; |
|
|
|
processInteractiveReplacementDialog(docProxy); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
QDialog::DialogCode UBPersistenceManager::processInteractiveReplacementDialog(UBDocumentProxy *pProxy) |
|
|
|
QDialog::DialogCode UBPersistenceManager::processInteractiveReplacementDialog(UBDocumentProxy *pProxy) |
|
|
|
{ |
|
|
|
{ |
|
|
|