diff options
author | ck <qt-info@nokia.com> | 2009-12-04 09:40:13 (GMT) |
---|---|---|
committer | ck <qt-info@nokia.com> | 2009-12-04 09:41:04 (GMT) |
commit | 7c5d48e84159abd0a72eadb2e14e4c3b1441fdfb (patch) | |
tree | ca9f4f50827c56eec4e5e0d5cfa51a90a88b2b8f /tools | |
parent | 6001ef3bb9cdf41c5375a22cdaee85fffdf3b644 (diff) | |
download | Qt-7c5d48e84159abd0a72eadb2e14e4c3b1441fdfb.zip Qt-7c5d48e84159abd0a72eadb2e14e4c3b1441fdfb.tar.gz Qt-7c5d48e84159abd0a72eadb2e14e4c3b1441fdfb.tar.bz2 |
Assistant: More small refactorings + compile fix.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/assistant/tools/assistant/main.cpp | 86 |
1 files changed, 49 insertions, 37 deletions
diff --git a/tools/assistant/tools/assistant/main.cpp b/tools/assistant/tools/assistant/main.cpp index d009210..536095c 100644 --- a/tools/assistant/tools/assistant/main.cpp +++ b/tools/assistant/tools/assistant/main.cpp @@ -150,7 +150,7 @@ QString cachedCollectionFile(const QHelpEngineCore &collection) return dir + QDir::separator() + fileName; } -bool synchronizeDocs(const QHelpEngineCore &collection, +bool synchronizeDocs(QHelpEngineCore &collection, QHelpEngineCore &cachedCollection) { const QStringList &docs = collection.registeredDocumentations(); @@ -174,7 +174,7 @@ bool synchronizeDocs(const QHelpEngineCore &collection, */ QLatin1String intern("com.trolltech.com.assistantinternal-"); foreach (const QString &doc, cachedDocs) { - if (!collection.contains(doc) && !doc.startsWith(intern) + if (!docs.contains(doc) && !doc.startsWith(intern) && !cachedCollection.unregisterDocumentation(doc)) return false; } @@ -182,28 +182,62 @@ bool synchronizeDocs(const QHelpEngineCore &collection, return true; } -} // Anonymous namespace. +bool removeSearchIndex(const QString &collectionFile) +{ + QString path = QFileInfo(collectionFile).path(); + path += QLatin1Char('/') + indexFilesFolder(collectionFile); -int main(int argc, char *argv[]) + QLocalSocket localSocket; + localSocket.connectToServer(QString(QLatin1String("QtAssistant%1")) + .arg(QLatin1String(QT_VERSION_STR))); + + QDir dir(path); // check if there is no other instance ruinning + if (!dir.exists() || localSocket.waitForConnected()) + return false; + + QStringList lst = dir.entryList(QDir::Files | QDir::Hidden); + foreach (const QString &item, lst) + dir.remove(item); + return true; +} + +bool checkForSqlite(CmdLineParser &cmd) { -#ifndef Q_OS_WIN - // First do a quick search for arguments that imply command-line mode. + QSqlDatabase db; + QStringList sqlDrivers(db.drivers()); + if (!sqlDrivers.contains(QLatin1String("QSQLITE"))) { + cmd.showMessage(QObject::tr("Cannot load sqlite database driver!"), + true); + return false; + } + return true; +} + +bool useGui(int argc, char *argv[]) +{ + bool gui = true; +#ifndef Q_OS_WIN + // Look for arguments that imply command-line mode. const char * cmdModeArgs[] = { "-help", "-register", "-unregister", "-remove-search-index" }; - bool useGui = true; for (int i = 1; i < argc; ++i) { for (size_t j = 0; j < sizeof cmdModeArgs/sizeof *cmdModeArgs; ++j) { if(strcmp(argv[i], cmdModeArgs[j]) == 0) { - useGui = false; + gui = false; break; } } } - QApplication a(argc, argv, useGui); -#else - QApplication a(argc, argv); #endif + return gui; +} + +} // Anonymous namespace. + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv, useGui(argc, argv)); a.addLibraryPath(a.applicationDirPath() + QLatin1String("/plugins")); CmdLineParser cmd(a.arguments()); @@ -247,38 +281,16 @@ int main(int argc, char *argv[]) return 0; } + // TODO: Also remove search index of cached collection file? if (cmd.removeSearchIndex()) { QString file = cmdCollectionFile; if (file.isEmpty()) file = MainWindow::defaultHelpCollectionFileName(); - QString path = QFileInfo(file).path(); - path += QLatin1Char('/') + indexFilesFolder(file); - - QLocalSocket localSocket; - localSocket.connectToServer(QString(QLatin1String("QtAssistant%1")) - .arg(QLatin1String(QT_VERSION_STR))); - - QDir dir(path); // check if there is no other instance ruinning - if (!localSocket.waitForConnected() && dir.exists()) { - QStringList lst = dir.entryList(QDir::Files | QDir::Hidden); - foreach (const QString &item, lst) - dir.remove(item); - return 0; - } else { - return -1; - } + return removeSearchIndex(file) ? 0 : EXIT_FAILURE; } - { - QSqlDatabase db; - QStringList sqlDrivers(db.drivers()); - if (sqlDrivers.isEmpty() - || !sqlDrivers.contains(QLatin1String("QSQLITE"))) { - cmd.showMessage(QObject::tr("Cannot load sqlite database driver!"), - true); - return -1; - } - } + if (!checkForSqlite(cmd)) + return EXIT_FAILURE; if (!cmdCollectionFile.isEmpty()) { QHelpEngineCore caller(cmdCollectionFile); |