mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 08:36:52 +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)
|
||||
{
|
||||
parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
|
||||
parser.addOption({{"s", "session"}, QCoreApplication::translate("main", "Use session bus.")});
|
||||
parser.addOption({{"y", "system"}, QCoreApplication::translate("main", "Use system bus.")});
|
||||
parser.addOption({{"p", "p2p"}, QCoreApplication::translate("main", "Use P2P bus with address.")});
|
||||
parser.addOption({{"d", "dbus"}, QCoreApplication::translate("main", "DBus options: session, system, p2p."), "dbus"});
|
||||
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 versionOption = parser.addVersionOption();
|
||||
@@ -58,49 +58,33 @@ CommandLineParseResult parseCommandLine(QCommandLineParser &parser, CSwiftCore::
|
||||
if (parser.isSet(helpOption)) { return CommandLineHelpRequested; }
|
||||
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.";
|
||||
return CommandLineError;
|
||||
setup->m_dbusAddress = CDBusServer::p2pAddress();
|
||||
}
|
||||
setup->m_dbusAddress = CDBusServer::sessionDBusServer();
|
||||
}
|
||||
|
||||
if (parser.isSet("system"))
|
||||
{
|
||||
if (parser.isSet("session") || parser.isSet("p2p"))
|
||||
else if (v.contains("sys"))
|
||||
{
|
||||
*errorMessage = "Multiple DBus types set at the same time.";
|
||||
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;
|
||||
setup->m_dbusAddress = CDBusServer::systemDBusServer(); // default
|
||||
}
|
||||
}
|
||||
|
||||
if (parser.isSet("minimized"))
|
||||
{
|
||||
setup->m_minimzed = true;
|
||||
}
|
||||
if (parser.isSet("minimized")) { setup->m_minimzed = true; }
|
||||
if (parser.isSet("start")) { setup->m_start = true; }
|
||||
if (parser.isSet("coreaudio")) { setup->m_coreAudio = true; }
|
||||
|
||||
return CommandLineOk;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
const QString appName("swiftcore");
|
||||
const QString appName("swift core");
|
||||
a.setApplicationVersion(CProject::version());
|
||||
a.setApplicationName(appName);
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription(appName);
|
||||
|
||||
|
||||
@@ -31,17 +31,19 @@ CSwiftCore::CSwiftCore(const SetupInfo &info, QWidget *parent) :
|
||||
ui(new Ui::CSwiftCore)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
const QString name("swiftcore " + CProject::version());
|
||||
SystemTrayMode mode = MinimizeToTray | QuitOnClose;
|
||||
setSystemTrayMode(mode);
|
||||
setToolTip(name);
|
||||
const QString name(QCoreApplication::instance()->applicationName() + " " + CProject::version());
|
||||
setSystemTrayMode(MinimizeToTray | QuitOnClose);
|
||||
setSystemTrayToolTip(name);
|
||||
setWindowTitle(name);
|
||||
setWindowIcon(CIcons::swiftNova24());
|
||||
setWindowIconText(name);
|
||||
|
||||
initLogDisplay();
|
||||
initSlots();
|
||||
initStyleSheet();
|
||||
startCore(info);
|
||||
initDBusMode(info);
|
||||
|
||||
if (info.m_start) { startCore(info); }
|
||||
}
|
||||
|
||||
void CSwiftCore::initStyleSheet()
|
||||
@@ -56,6 +58,23 @@ void CSwiftCore::initStyleSheet()
|
||||
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()
|
||||
{ }
|
||||
|
||||
@@ -123,7 +142,10 @@ void CSwiftCore::startCore(const SetupInfo &setup)
|
||||
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
|
||||
|
||||
// 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);
|
||||
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_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 "";
|
||||
}
|
||||
|
||||
@@ -37,8 +37,10 @@ public:
|
||||
{
|
||||
SetupInfo() {}
|
||||
|
||||
bool m_minimzed = false; //!< Start minimized to tray
|
||||
QString m_dbusAddress; //!< DBus address (session, system, p2p)
|
||||
bool m_minimzed = false; //!< Start minimized to tray
|
||||
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
|
||||
@@ -61,6 +63,8 @@ private:
|
||||
void initSlots();
|
||||
void initLogDisplay();
|
||||
void initStyleSheet();
|
||||
void initDBusMode(const SetupInfo &setup);
|
||||
|
||||
void startCore(const SetupInfo &setup);
|
||||
void stopCore();
|
||||
QString getDBusAddress() const;
|
||||
|
||||
Reference in New Issue
Block a user