From b15b08e1f09320299a13bd4344663d6efb44d53f Mon Sep 17 00:00:00 2001 From: ck Date: Thu, 3 Dec 2009 17:09:27 +0100 Subject: Assistant: Small refactoring to prepare for upcoming functional change. Reviewed-by: kh1 --- tools/assistant/tools/assistant/main.cpp | 42 ++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/tools/assistant/tools/assistant/main.cpp b/tools/assistant/tools/assistant/main.cpp index 4d93a41..a80b4cc 100644 --- a/tools/assistant/tools/assistant/main.cpp +++ b/tools/assistant/tools/assistant/main.cpp @@ -132,6 +132,24 @@ QString indexFilesFolder(const QString &collectionFile) return indexFilesFolder; } +/* + * Returns the expected absolute file path of the cached collection file + * correspondinging to the given collection's file. + * It may or may not exist yet. + */ +QString cachedCollectionFile(const QHelpEngineCore &collection) +{ + const QString &filePath = collection.collectionFile(); + const QString &fileName = QFileInfo(filePath).fileName(); + const QString &cacheDir = CollectionConfiguration::cacheDir(collection); + const QString &dir = !cacheDir.isEmpty() + && CollectionConfiguration::cacheDirIsRelativeToCollection(collection) + ? QFileInfo(filePath).dir().absolutePath() + + QDir::separator() + cacheDir + : MainWindow::collectionFileDirectory(false, cacheDir); + return dir + QDir::separator() + fileName; +} + } // Anonymous namespace. int main(int argc, char *argv[]) @@ -238,26 +256,14 @@ int main(int argc, char *argv[]) return -1; } - QString fileName = QFileInfo(cmdCollectionFile).fileName(); - const QString &cacheDir = CollectionConfiguration::cacheDir(caller); - const QString dir = !cacheDir.isEmpty() - && CollectionConfiguration::cacheDirIsRelativeToCollection(caller) - ? QFileInfo(cmdCollectionFile).dir().absolutePath() - + QDir::separator() + cacheDir - : MainWindow::collectionFileDirectory(false, cacheDir); - - bool collectionFileExists = true; - QFileInfo fi(dir + QDir::separator() + fileName); - if (!fi.exists()) { - collectionFileExists = false; - if (!caller.copyCollectionFile(fi.absoluteFilePath())) { + const QString &cachedCollectionFilePath = cachedCollectionFile(caller); + if (!QFileInfo(cachedCollectionFilePath).exists()) { + if (!caller.copyCollectionFile(cachedCollectionFilePath)) { cmd.showMessage(caller.error(), true); return -1; } - } - - if (collectionFileExists) { - QHelpEngineCore user(fi.absoluteFilePath()); + } else { + QHelpEngineCore user(cachedCollectionFilePath); if (user.setupData()) { // some docs might have been un/registered bool docUpdate = CollectionConfiguration::docUpdatePending(caller); @@ -290,7 +296,7 @@ int main(int argc, char *argv[]) } } } - cmd.setCollectionFile(fi.absoluteFilePath()); + cmd.setCollectionFile(cachedCollectionFilePath); } if (!cmd.currentFilter().isEmpty()) { -- cgit v0.12