refs #485, first version of a Gui/Core application class

Also specialized GUI application class for standard GUI
This commit is contained in:
Klaus Basan
2016-03-14 23:55:33 +00:00
committed by Mathew Sutcliffe
parent d9aac6427b
commit 158efe819a
27 changed files with 1170 additions and 506 deletions

View File

@@ -7,11 +7,9 @@
* contained in the LICENSE file.
*/
#include "swiftguistandard/guimodeenums.h"
#include "swiftlauncher.h"
#include "blackgui/guiapplication.h"
#include "blackcore/registermetadata.h"
#include "blackgui/guiutility.h"
#include "blackmisc/blackmiscfreefunctions.h"
#include "blackmisc/logmessage.h"
#include "blackmisc/icons.h"
#include "blackmisc/project.h"
@@ -27,75 +25,23 @@ using namespace BlackGui;
using namespace BlackMisc;
using namespace BlackCore;
enum CommandLineParseResult
{
CommandLineOk,
CommandLineError,
CommandLineVersionRequested,
CommandLineHelpRequested
};
CommandLineParseResult parseCommandLine(QCommandLineParser &parser, bool &installer, QString &errorMessage)
{
parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
parser.addOption({{"i", "installer"}, QCoreApplication::translate("main", "Installer setup.")});
QCommandLineOption helpOption = parser.addHelpOption();
QCommandLineOption versionOption = parser.addVersionOption();
if (!parser.parse(QCoreApplication::arguments()))
{
errorMessage = parser.errorText();
return CommandLineError;
}
// help/version
if (parser.isSet(helpOption)) { return CommandLineHelpRequested; }
if (parser.isSet(versionOption)) { return CommandLineVersionRequested; }
installer = parser.isSet("installer");
return CommandLineOk;
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
const QString appName("swift launcher");
a.setApplicationVersion(CProject::version());
a.setApplicationName(appName);
CGuiUtility::initSwiftGuiApplication(a, appName, CIcons::swift24());
// Process the actual command line arguments given by the user
QCommandLineParser parser;
parser.setApplicationDescription(appName);
QString errorMessage;
bool installer = false;
switch (parseCommandLine(parser, installer, errorMessage))
{
case CommandLineOk:
break;
case CommandLineError:
CGuiUtility::commandLineErrorMessage(errorMessage, parser);
return 1;
case CommandLineVersionRequested:
CGuiUtility::commandLineVersionRequested();
return 0;
case CommandLineHelpRequested:
CGuiUtility::commandLineHelpRequested(parser);
return 0;
}
CGuiApplication a(argc, argv, "swift launcher");
a.setWindowIcon(CIcons::swift24());
a.addParserOption({{"i", "installer"}, QCoreApplication::translate("main", "Installer setup."), "installer"});
a.parse();
// Dialog to decide external or internal core
CSwiftLauncher launcher;
launcher.setWindowIcon(CIcons::swift24());
if (launcher.exec() == QDialog::Rejected) { return 0; }
if (launcher.exec() == QDialog::Rejected) { return EXIT_SUCCESS; }
launcher.close();
QString exe(launcher.getExecutable());
QStringList exeArgs(launcher.getExecutableArgs());
Q_ASSERT_X(!exe.isEmpty(), Q_FUNC_INFO, "Missing executable");
CLogMessage(QCoreApplication::instance()).debug() << launcher.getCmdLine();
CLogMessage(QCoreApplication::instance()).info(launcher.getCmdLine());
QProcess::startDetached(exe, exeArgs);
return 0;
return EXIT_SUCCESS;
}

View File

@@ -9,6 +9,7 @@
#include "swiftlauncher.h"
#include "ui_swiftlauncher.h"
#include "blackgui/guiapplication.h"
#include "blackgui/stylesheetutility.h"
#include "blackcore/setupreader.h"
#include "blackmisc/dbusserver.h"
@@ -41,7 +42,6 @@ CSwiftLauncher::CSwiftLauncher(QWidget *parent) :
ui(new Ui::CSwiftLauncher)
{
ui->setupUi(this);
this->setWindowTitle(QCoreApplication::instance()->applicationName() + " " + CProject::versionStringDevBetaInfo());
this->init();
connect(ui->pb_CheckForUpdates, &QPushButton::pressed, this, &CSwiftLauncher::ps_loadSetup);
connect(ui->tb_SwiftCore, &QPushButton::pressed, this, &CSwiftLauncher::ps_startButtonPressed);
@@ -72,14 +72,14 @@ CEnableForFramelessWindow::WindowMode CSwiftLauncher::getWindowMode() const
return CEnableForFramelessWindow::WindowNormal;
}
GuiModes::CoreMode CSwiftLauncher::getCoreMode() const
CoreModes::CoreMode CSwiftLauncher::getCoreMode() const
{
if (ui->rb_SwiftStandalone->isChecked()) { return GuiModes::CoreInGuiProcess; }
if (ui->rb_SwiftCoreAudio->isChecked()) { return GuiModes::CoreExternalCoreAudio; }
if (ui->rb_SwiftCoreGuiAudio->isChecked()) { return GuiModes::CoreExternalAudioGui; }
if (ui->rb_SwiftStandalone->isChecked()) { return CoreModes::CoreInGuiProcess; }
if (ui->rb_SwiftCoreAudio->isChecked()) { return CoreModes::CoreExternalCoreAudio; }
if (ui->rb_SwiftCoreGuiAudio->isChecked()) { return CoreModes::CoreExternalAudioGui; }
Q_ASSERT_X(false, Q_FUNC_INFO, "wrong mode");
return GuiModes::CoreInGuiProcess;
return CoreModes::CoreInGuiProcess;
}
QString CSwiftLauncher::getDBusAddress() const
@@ -103,6 +103,7 @@ void CSwiftLauncher::mousePressEvent(QMouseEvent *event)
void CSwiftLauncher::init()
{
sGui->initMainApplicationWindow(this);
this->ui->lbl_NewVersionUrl->setTextFormat(Qt::RichText);
this->ui->lbl_NewVersionUrl->setTextInteractionFlags(Qt::TextBrowserInteraction);
this->ui->lbl_NewVersionUrl->setOpenExternalLinks(true);
@@ -210,7 +211,7 @@ bool CSwiftLauncher::setSwiftGuiExecutable()
m_executable = CProject::swiftGuiExecutableName();
QStringList args
{
"--core", GuiModes::coreModeToString(getCoreMode()),
"--core", CoreModes::coreModeToString(getCoreMode()),
"--window", CEnableForFramelessWindow::windowModeToString(getWindowMode())
};
if (!this->isStandaloneGuiSelected())

View File

@@ -16,10 +16,10 @@
#include <QScopedPointer>
#include "blackcore/data/globalsetup.h"
#include "blackcore/data/updateinfo.h"
#include "blackcore/coremodeenums.h"
#include "blackcore/settings/network.h"
#include "blackgui/enableforframelesswindow.h"
#include "blackgui/overlaymessagesframe.h"
#include "swiftguistandard/guimodeenums.h"
namespace Ui { class CSwiftLauncher; }
@@ -67,7 +67,7 @@ private:
BlackMisc::CSetting<BlackCore::Settings::Network::DBusServerAddress> m_dbusServerAddress { this };
//! Get core mode
GuiModes::CoreMode getCoreMode() const;
BlackCore::CoreModes::CoreMode getCoreMode() const;
//! select DBus address/mode
QString getDBusAddress() const;