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

@@ -8,20 +8,10 @@
*/
#include "swiftguistd.h"
#include "guimodeenums.h"
#include "blackgui/stylesheetutility.h"
#include "blackcore/registermetadata.h"
#include "blackcore/corefacadeconfig.h"
#include "blackgui/guiutility.h"
#include "blackmisc/blackmiscfreefunctions.h"
#include "blackmisc/logmessage.h"
#include "blackmisc/icons.h"
#include "blackmisc/loghandler.h"
#include "blackmisc/filelogger.h"
#include "swiftguistdapplication.h"
#include "blackgui/enableforframelesswindow.h"
#include <QtGlobal>
#include <QApplication>
#include <QMessageBox>
#include <QPushButton>
#include <QProcessEnvironment>
@@ -29,127 +19,14 @@ using namespace BlackGui;
using namespace BlackMisc;
using namespace BlackCore;
enum CommandLineParseResult
{
CommandLineOk,
CommandLineError,
CommandLineVersionRequested,
CommandLineHelpRequested
};
CommandLineParseResult parseCommandLine(QCommandLineParser &parser,
CEnableForFramelessWindow::WindowMode &windowMode,
GuiModes::CoreMode &coreMode,
QString &dBusAddress,
QString &errorMessage)
{
parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
// value core mode
QCommandLineOption modeOption(QStringList() << "c" << "core",
QCoreApplication::translate("main", "Core mode: (e)xternal, (g)ui (in GUI process), (l)ocalaudio (external, but local audio)."),
"coremode");
parser.addOption(modeOption);
// value DBus address
QCommandLineOption dBusOption(QStringList() << "dbus" << "dbus-address",
QCoreApplication::translate("main", "DBUS address."),
"dbusaddress");
parser.addOption(dBusOption);
// Window type
QCommandLineOption windowOption(QStringList() << "w" << "window",
QCoreApplication::translate("main", "Windows: (n)ormal, (f)rameless, (t)ool."),
"windowtype");
parser.addOption(windowOption);
// help/version
QCommandLineOption helpOption = parser.addHelpOption();
QCommandLineOption versionOption = parser.addVersionOption();
// evaluate
if (!parser.parse(QCoreApplication::arguments()))
{
errorMessage = parser.errorText();
return CommandLineError;
}
if (parser.isSet(helpOption)) { return CommandLineHelpRequested; }
if (parser.isSet(versionOption)) { return CommandLineVersionRequested; }
if (parser.isSet(dBusOption))
{
QString v(parser.value(dBusOption).trimmed());
dBusAddress = CDBusServer::normalizeAddress(v);
if (!CDBusServer::isDBusAvailable(dBusAddress))
{
errorMessage = "DBus server at " + dBusAddress + " can not be reached";
return CommandLineError;
}
}
if (parser.isSet(windowOption))
{
QString v(parser.value(windowOption).trimmed());
windowMode = CEnableForFramelessWindow::stringToWindowMode(v);
}
if (parser.isSet(modeOption))
{
QString v(parser.value(modeOption));
coreMode = GuiModes::stringToCoreMode(v);
}
return CommandLineOk;
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
const QString appName("swift pilot client GUI");
a.setApplicationVersion(CProject::version());
a.setApplicationName(appName);
// Process the actual command line arguments given by the user
QCommandLineParser parser;
parser.setApplicationDescription(appName);
CEnableForFramelessWindow::WindowMode windowMode = CEnableForFramelessWindow::WindowNormal;
GuiModes::CoreMode coreMode = GuiModes::CoreInGuiProcess;
QString dBusAddress, errorMessage;
switch (parseCommandLine(parser, windowMode, coreMode, dBusAddress, 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;
}
BlackCore::CCoreFacadeConfig runtimeConfig;
switch (coreMode)
{
case GuiModes::CoreExternalCoreAudio:
runtimeConfig = CCoreFacadeConfig::remote(dBusAddress);
break;
case GuiModes::CoreInGuiProcess:
runtimeConfig = CCoreFacadeConfig::local(dBusAddress);
break;
case GuiModes::CoreExternalAudioGui:
runtimeConfig = CCoreFacadeConfig::remoteLocalAudio(dBusAddress);
break;
}
CSwiftGuiStdApplication a(argc, argv);
a.startCoreFacade();
// show window
CGuiUtility::initSwiftGuiApplication(a, appName, CIcons::swift24());
CEnableForFramelessWindow::WindowMode windowMode = a.getWindowMode();
SwiftGuiStd w(windowMode);
w.init(runtimeConfig); // object is complete by now
w.show();
int r = a.exec();