From feda8a7db8d1d7c5439aa8f8feef7cc0dd2b59a0 Mon Sep 17 00:00:00 2001 From: Unit 193 Date: Fri, 27 Jul 2018 23:51:12 -0400 Subject: New upstream version 3.2.1+dfsg1 --- SQLiteStudio3/sqlitestudio/main.cpp | 67 ++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 34 deletions(-) (limited to 'SQLiteStudio3/sqlitestudio/main.cpp') diff --git a/SQLiteStudio3/sqlitestudio/main.cpp b/SQLiteStudio3/sqlitestudio/main.cpp index 829d657..443006b 100644 --- a/SQLiteStudio3/sqlitestudio/main.cpp +++ b/SQLiteStudio3/sqlitestudio/main.cpp @@ -26,6 +26,7 @@ #include "dialogs/languagedialog.h" #include "dialogs/triggerdialog.h" #include "services/pluginmanager.h" +#include "singleapplication/singleapplication.h" #include #include #include @@ -35,10 +36,14 @@ #include #include #include +#ifdef Q_OS_WIN +# include +# include +#endif static bool listPlugins = false; -QString uiHandleCmdLineArgs() +QString uiHandleCmdLineArgs(bool applyOptions = true) { QCommandLineParser parser; parser.setApplicationDescription(QObject::tr("GUI interface to SQLiteStudio, a SQLite manager.")); @@ -68,19 +73,22 @@ QString uiHandleCmdLineArgs() parser.process(qApp->arguments()); - bool enableDebug = parser.isSet(debugOption) || parser.isSet(debugStdOutOption) || parser.isSet(sqlDebugOption) || parser.isSet(debugFileOption); - setUiDebug(enableDebug, !parser.isSet(debugStdOutOption), parser.value(debugFileOption)); - CompletionHelper::enableLemonDebug = parser.isSet(lemonDebugOption); - setSqlLoggingEnabled(parser.isSet(sqlDebugOption)); - setExecutorLoggingEnabled(parser.isSet(executorDebugOption)); - if (parser.isSet(sqlDebugDbNameOption)) - setSqlLoggingFilter(parser.value(sqlDebugDbNameOption)); - - if (parser.isSet(listPluginsOption)) - listPlugins = true; - - if (parser.isSet(masterConfigOption)) - Config::setMasterConfigFile(parser.value(masterConfigOption)); + if (applyOptions) + { + bool enableDebug = parser.isSet(debugOption) || parser.isSet(debugStdOutOption) || parser.isSet(sqlDebugOption) || parser.isSet(debugFileOption); + setUiDebug(enableDebug, !parser.isSet(debugStdOutOption), parser.value(debugFileOption)); + CompletionHelper::enableLemonDebug = parser.isSet(lemonDebugOption); + setSqlLoggingEnabled(parser.isSet(sqlDebugOption)); + setExecutorLoggingEnabled(parser.isSet(executorDebugOption)); + if (parser.isSet(sqlDebugDbNameOption)) + setSqlLoggingFilter(parser.value(sqlDebugDbNameOption)); + + if (parser.isSet(listPluginsOption)) + listPlugins = true; + + if (parser.isSet(masterConfigOption)) + Config::setMasterConfigFile(parser.value(masterConfigOption)); + } QStringList args = parser.positionalArguments(); if (args.size() > 0) @@ -89,29 +97,18 @@ QString uiHandleCmdLineArgs() return QString::null; } -bool updateRetryFunction(const QString& msg) -{ - QMessageBox mb(QMessageBox::Critical, QObject::tr("Error"), msg); - mb.addButton(QMessageBox::Retry); - mb.addButton(QMessageBox::Abort); - return (mb.exec() == QMessageBox::Retry); -} - int main(int argc, char *argv[]) { - QApplication a(argc, argv); + SingleApplication a(argc, argv, true, SingleApplication::ExcludeAppPath|SingleApplication::ExcludeAppVersion); -#ifdef PORTABLE_CONFIG - int retCode = 1; - UpdateManager::setRetryFunction(updateRetryFunction); - if (UpdateManager::handleUpdateOptions(a.arguments(), retCode)) - { - if (retCode) - QMessageBox::critical(nullptr, QObject::tr("Error"), UpdateManager::getStaticErrorMessage()); - - return retCode; - } + if (a.isSecondary()) { +#ifdef Q_OS_WIN + AllowSetForegroundWindow(DWORD( a.primaryPid())); #endif + QString dbToOpen = uiHandleCmdLineArgs(); + a.sendMessage(serializeToBytes(dbToOpen)); + return 0; + } qInstallMessageHandler(uiMessageHandler); @@ -135,7 +132,9 @@ int main(int argc, char *argv[]) MultiEditorBool::staticInit(); TriggerDialog::staticInit(); - MainWindow::getInstance(); + MainWindow* mainWin = MAINWINDOW; + + QObject::connect(&a, &SingleApplication::receivedMessage, mainWin, &MainWindow::messageFromSecondaryInstance); SQLITESTUDIO->initPlugins(); -- cgit v1.2.3