mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 10:55:32 +08:00
refs #507, core
* revised parameter handling * adjusted to changes in CProject
This commit is contained in:
committed by
Mathew Sutcliffe
parent
864ca20be3
commit
54cb61db19
@@ -40,10 +40,10 @@ enum CommandLineParseResult
|
|||||||
CommandLineParseResult parseCommandLine(QCommandLineParser &parser, CSwiftCore::SetupInfo *setup, QString *errorMessage)
|
CommandLineParseResult parseCommandLine(QCommandLineParser &parser, CSwiftCore::SetupInfo *setup, QString *errorMessage)
|
||||||
{
|
{
|
||||||
parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
|
parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
|
||||||
parser.addOption({{"s", "session"}, QCoreApplication::translate("main", "Use session bus.")});
|
parser.addOption({{"d", "dbus"}, QCoreApplication::translate("main", "DBus options: session, system, p2p."), "dbus"});
|
||||||
parser.addOption({{"y", "system"}, QCoreApplication::translate("main", "Use system bus.")});
|
|
||||||
parser.addOption({{"p", "p2p"}, QCoreApplication::translate("main", "Use P2P bus with address.")});
|
|
||||||
parser.addOption({{"m", "minimized"}, QCoreApplication::translate("main", "Start minimized in system tray.")});
|
parser.addOption({{"m", "minimized"}, QCoreApplication::translate("main", "Start minimized in system tray.")});
|
||||||
|
parser.addOption({{"r", "start"}, QCoreApplication::translate("main", "Start the server.")});
|
||||||
|
parser.addOption({{"c", "coreaudio"}, QCoreApplication::translate("main", "Audio in core.")});
|
||||||
|
|
||||||
QCommandLineOption helpOption = parser.addHelpOption();
|
QCommandLineOption helpOption = parser.addHelpOption();
|
||||||
QCommandLineOption versionOption = parser.addVersionOption();
|
QCommandLineOption versionOption = parser.addVersionOption();
|
||||||
@@ -58,49 +58,33 @@ CommandLineParseResult parseCommandLine(QCommandLineParser &parser, CSwiftCore::
|
|||||||
if (parser.isSet(helpOption)) { return CommandLineHelpRequested; }
|
if (parser.isSet(helpOption)) { return CommandLineHelpRequested; }
|
||||||
if (parser.isSet(versionOption)) { return CommandLineVersionRequested; }
|
if (parser.isSet(versionOption)) { return CommandLineVersionRequested; }
|
||||||
|
|
||||||
if (parser.isSet("session"))
|
setup->m_dbusAddress = CDBusServer::sessionDBusServer(); // default
|
||||||
|
if (parser.isSet("dbus"))
|
||||||
{
|
{
|
||||||
if (parser.isSet("system") || parser.isSet("p2p"))
|
QString v(parser.value("dbus").trimmed().toLower());
|
||||||
|
if (v.startsWith("p2p") || v.contains("peer") || v.contains("tcp:") || v.contains("host"))
|
||||||
{
|
{
|
||||||
*errorMessage = "Multiple DBus types set at the same time.";
|
setup->m_dbusAddress = CDBusServer::p2pAddress();
|
||||||
return CommandLineError;
|
|
||||||
}
|
}
|
||||||
setup->m_dbusAddress = CDBusServer::sessionDBusServer();
|
else if (v.contains("sys"))
|
||||||
}
|
|
||||||
|
|
||||||
if (parser.isSet("system"))
|
|
||||||
{
|
|
||||||
if (parser.isSet("session") || parser.isSet("p2p"))
|
|
||||||
{
|
{
|
||||||
*errorMessage = "Multiple DBus types set at the same time.";
|
setup->m_dbusAddress = CDBusServer::systemDBusServer(); // default
|
||||||
return CommandLineError;
|
|
||||||
}
|
|
||||||
setup->m_dbusAddress = CDBusServer::systemDBusServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parser.isSet("p2p"))
|
|
||||||
{
|
|
||||||
const QString address = CDBusServer::fixAddressToDBusAddress(parser.value("p2p"));
|
|
||||||
Q_UNUSED(address);
|
|
||||||
|
|
||||||
if (parser.isSet("session") || parser.isSet("system"))
|
|
||||||
{
|
|
||||||
*errorMessage = "Multiple DBus types set at the same time.";
|
|
||||||
return CommandLineError;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parser.isSet("minimized"))
|
if (parser.isSet("minimized")) { setup->m_minimzed = true; }
|
||||||
{
|
if (parser.isSet("start")) { setup->m_start = true; }
|
||||||
setup->m_minimzed = true;
|
if (parser.isSet("coreaudio")) { setup->m_coreAudio = true; }
|
||||||
}
|
|
||||||
return CommandLineOk;
|
return CommandLineOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
const QString appName("swiftcore");
|
const QString appName("swift core");
|
||||||
|
a.setApplicationVersion(CProject::version());
|
||||||
|
a.setApplicationName(appName);
|
||||||
QCommandLineParser parser;
|
QCommandLineParser parser;
|
||||||
parser.setApplicationDescription(appName);
|
parser.setApplicationDescription(appName);
|
||||||
|
|
||||||
|
|||||||
@@ -31,17 +31,19 @@ CSwiftCore::CSwiftCore(const SetupInfo &info, QWidget *parent) :
|
|||||||
ui(new Ui::CSwiftCore)
|
ui(new Ui::CSwiftCore)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
const QString name("swiftcore " + CProject::version());
|
const QString name(QCoreApplication::instance()->applicationName() + " " + CProject::version());
|
||||||
SystemTrayMode mode = MinimizeToTray | QuitOnClose;
|
setSystemTrayMode(MinimizeToTray | QuitOnClose);
|
||||||
setSystemTrayMode(mode);
|
setSystemTrayToolTip(name);
|
||||||
setToolTip(name);
|
|
||||||
setWindowTitle(name);
|
setWindowTitle(name);
|
||||||
setWindowIcon(CIcons::swiftNova24());
|
setWindowIcon(CIcons::swiftNova24());
|
||||||
setWindowIconText(name);
|
setWindowIconText(name);
|
||||||
|
|
||||||
initLogDisplay();
|
initLogDisplay();
|
||||||
initSlots();
|
initSlots();
|
||||||
initStyleSheet();
|
initStyleSheet();
|
||||||
startCore(info);
|
initDBusMode(info);
|
||||||
|
|
||||||
|
if (info.m_start) { startCore(info); }
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSwiftCore::initStyleSheet()
|
void CSwiftCore::initStyleSheet()
|
||||||
@@ -56,6 +58,23 @@ void CSwiftCore::initStyleSheet()
|
|||||||
this->setStyleSheet(s);
|
this->setStyleSheet(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSwiftCore::initDBusMode(const CSwiftCore::SetupInfo &setup)
|
||||||
|
{
|
||||||
|
if (setup.m_dbusAddress.startsWith(CDBusServer::sessionDBusServer()))
|
||||||
|
{
|
||||||
|
this->ui->rb_SessionBus->setChecked(true);
|
||||||
|
}
|
||||||
|
else if (setup.m_dbusAddress.startsWith(CDBusServer::systemDBusServer()))
|
||||||
|
{
|
||||||
|
this->ui->rb_SystemBus->setChecked(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->ui->rb_P2PBus->setChecked(true);
|
||||||
|
this->ui->le_P2PAddress->setText(setup.m_dbusAddress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CSwiftCore::~CSwiftCore()
|
CSwiftCore::~CSwiftCore()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
@@ -123,7 +142,10 @@ void CSwiftCore::startCore(const SetupInfo &setup)
|
|||||||
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
|
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
|
||||||
|
|
||||||
// context
|
// context
|
||||||
createRuntime(CRuntimeConfig::forCoreAllLocalInDBus(setup.m_dbusAddress), this);
|
this->createRuntime(setup.m_coreAudio ?
|
||||||
|
CRuntimeConfig::forCoreAllLocalInDBus(setup.m_dbusAddress) :
|
||||||
|
CRuntimeConfig::forCoreAllLocalInDBusNoAudio(setup.m_dbusAddress),
|
||||||
|
this);
|
||||||
CEnableForRuntime::setRuntimeForComponents(this->getRuntime(), this);
|
CEnableForRuntime::setRuntimeForComponents(this->getRuntime(), this);
|
||||||
connect(ui->le_CommandLineInput, &CCommandInput::commandEntered, getRuntime(), &CRuntime::parseCommandLine);
|
connect(ui->le_CommandLineInput, &CCommandInput::commandEntered, getRuntime(), &CRuntime::parseCommandLine);
|
||||||
}
|
}
|
||||||
@@ -149,6 +171,6 @@ QString CSwiftCore::getDBusAddress() const
|
|||||||
if (ui->rb_SystemBus->isChecked()) { return CDBusServer::systemDBusServer(); }
|
if (ui->rb_SystemBus->isChecked()) { return CDBusServer::systemDBusServer(); }
|
||||||
if (ui->rb_P2PBus->isChecked()) { return CDBusServer::fixAddressToDBusAddress(ui->le_P2PAddress->text()); }
|
if (ui->rb_P2PBus->isChecked()) { return CDBusServer::fixAddressToDBusAddress(ui->le_P2PAddress->text()); }
|
||||||
|
|
||||||
Q_ASSERT_X(false, Q_FUNC_INFO, "The impossible happend!");
|
Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong DBus address");
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,8 +37,10 @@ public:
|
|||||||
{
|
{
|
||||||
SetupInfo() {}
|
SetupInfo() {}
|
||||||
|
|
||||||
bool m_minimzed = false; //!< Start minimized to tray
|
bool m_minimzed = false; //!< Start minimized to tray
|
||||||
QString m_dbusAddress; //!< DBus address (session, system, p2p)
|
bool m_start = false; //!< Start server when core is started
|
||||||
|
bool m_coreAudio = false; //!< Audio in core
|
||||||
|
QString m_dbusAddress; //!< DBus address (session, system, p2p)
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Constructor
|
//! Constructor
|
||||||
@@ -61,6 +63,8 @@ private:
|
|||||||
void initSlots();
|
void initSlots();
|
||||||
void initLogDisplay();
|
void initLogDisplay();
|
||||||
void initStyleSheet();
|
void initStyleSheet();
|
||||||
|
void initDBusMode(const SetupInfo &setup);
|
||||||
|
|
||||||
void startCore(const SetupInfo &setup);
|
void startCore(const SetupInfo &setup);
|
||||||
void stopCore();
|
void stopCore();
|
||||||
QString getDBusAddress() const;
|
QString getDBusAddress() const;
|
||||||
|
|||||||
Reference in New Issue
Block a user