Feature #3172 - Add stop service feature to GUI

This commit is contained in:
Nick Bolton 2012-07-28 18:54:50 +00:00
parent 49c1a5e9a1
commit ede57b0c81
3 changed files with 67 additions and 59 deletions

View File

@ -27,14 +27,7 @@
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QGridLayout">
<item row="6" column="7">
<widget class="QPushButton" name="m_pButtonToggleStart">
<property name="text">
<string>&amp;Start</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="8">
<item row="1" column="0" colspan="12">
<widget class="QGroupBox" name="m_pGroupServer">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
@ -127,7 +120,7 @@
</layout>
</widget>
</item>
<item row="2" column="0" colspan="8">
<item row="2" column="0" colspan="12">
<widget class="QGroupBox" name="m_pGroupClient">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
@ -168,7 +161,7 @@
</property>
</widget>
</item>
<item row="3" column="0" colspan="8">
<item row="3" column="0" colspan="12">
<widget class="QGroupBox" name="m_pGroupLog">
<property name="title">
<string>Log</string>
@ -223,7 +216,7 @@
<string/>
</property>
<property name="pixmap">
<pixmap>:/res/icons/16x16/warning.png</pixmap>
<pixmap resource="Synergy.qrc">:/res/icons/16x16/warning.png</pixmap>
</property>
</widget>
</item>
@ -237,7 +230,21 @@
</property>
</widget>
</item>
<item row="6" column="6">
<item row="6" column="11">
<widget class="QPushButton" name="m_pButtonToggleStart">
<property name="text">
<string>&amp;Start</string>
</property>
</widget>
</item>
<item row="6" column="10">
<widget class="QPushButton" name="m_pButtonApply">
<property name="text">
<string>&amp;Apply</string>
</property>
</widget>
</item>
<item row="6" column="9">
<widget class="QCheckBox" name="m_pElevateCheckBox">
<property name="text">
<string>&amp;Elevate</string>
@ -330,7 +337,9 @@
</property>
</action>
</widget>
<resources/>
<resources>
<include location="Synergy.qrc"/>
</resources>
<connections>
<connection>
<sender>m_pButtonToggleStart</sender>

View File

@ -119,7 +119,7 @@ void MainWindow::wizardFinished()
void MainWindow::onModeChanged(bool firstRun, bool forceServiceApply)
{
refreshStartButton();
refreshApplyButton();
stopSynergy();
@ -130,7 +130,7 @@ void MainWindow::onModeChanged(bool firstRun, bool forceServiceApply)
disconnect(m_pButtonToggleStart, SIGNAL(clicked()), m_pActionStartSynergy, SLOT(trigger()));
connect(m_pButtonToggleStart, SIGNAL(clicked()), m_pActionStartSynergy, SLOT(trigger()));
if (firstRun || forceServiceApply)
if (forceServiceApply)
{
startSynergy();
}
@ -149,16 +149,9 @@ void MainWindow::onModeChanged(bool firstRun, bool forceServiceApply)
m_pElevateCheckBox->setEnabled(appConfig().processMode() == Service);
}
void MainWindow::refreshStartButton()
void MainWindow::refreshApplyButton()
{
if (appConfig().processMode() == Service)
{
m_pButtonToggleStart->setText(tr("&Apply"));
}
else
{
m_pButtonToggleStart->setText(tr("&Start"));
}
m_pButtonApply->setEnabled(appConfig().processMode() == Service);
}
void MainWindow::setStatus(const QString &status)
@ -294,22 +287,7 @@ void MainWindow::logOutput()
{
if (!line.isEmpty())
{
appendLogRaw(line);
if (line.contains("has connected") ||
line.contains("connected to server"))
{
// only set connected state and hide, if we get
// "has connected" message. this is a little bit
// hacky, but it works for now (until we have IPC).
setSynergyState(synergyConnected);
// only hide once after each new connection.
if (!m_alreadyHidden && appConfig().autoHide())
{
hide();
m_alreadyHidden = true;
}
}
appendLogRaw(line);
}
}
}
@ -344,9 +322,29 @@ void MainWindow::appendLogError(const QString& text)
void MainWindow::appendLogRaw(const QString& text)
{
foreach(QString line, text.split(QRegExp("\r|\n|\r\n")))
if (!line.isEmpty())
foreach(QString line, text.split(QRegExp("\r|\n|\r\n"))) {
if (!line.isEmpty()) {
m_pLogOutput->append(line);
updateStateFromLogLine(line);
}
}
}
void MainWindow::updateStateFromLogLine(const QString &line)
{
// TODO: implement ipc connection state messages to replace this hack.
if (line.contains("started server") ||
line.contains("connected to server"))
{
setSynergyState(synergyConnected);
// only hide once after each new connection.
if (!m_alreadyHidden && appConfig().autoHide())
{
hide();
m_alreadyHidden = true;
}
}
}
void MainWindow::clearLog()
@ -435,15 +433,7 @@ void MainWindow::startSynergy()
if (!m_pLogOutput->toPlainText().isEmpty())
appendLogRaw("");
if (desktopMode)
{
appendLogNote("starting " + QString(synergyType() == synergyServer ? "server" : "client"));
}
if (serviceMode)
{
appendLogNote("applying service mode: " + QString(synergyType() == synergyServer ? "server" : "client"));
}
appendLogNote("starting " + QString(synergyType() == synergyServer ? "server" : "client"));
// show command if debug log level...
if (appConfig().logLevel() >= 4) {
@ -575,7 +565,11 @@ bool MainWindow::serverArgs(QStringList& args, QString& app)
void MainWindow::stopSynergy()
{
if (synergyProcess())
if (appConfig().processMode() == Service) {
// send empty command to stop service from laucning anything.
m_IpcClient.sendCommand("", m_ElevateProcess);
}
else if (synergyProcess())
{
appendLogNote("stopping synergy");
@ -583,10 +577,10 @@ void MainWindow::stopSynergy()
synergyProcess()->close();
delete synergyProcess();
setSynergyProcess(NULL);
setSynergyState(synergyDisconnected);
}
setSynergyState(synergyDisconnected);
// HACK: deleting the object deletes the physical file, which is
// bad, since it could be in use by the Windows service!
//delete m_pTempConfigFile;
@ -617,10 +611,6 @@ void MainWindow::synergyFinished(int exitCode, QProcess::ExitStatus)
void MainWindow::setSynergyState(qSynergyState state)
{
// ignore state stuff when in service mode (for now anyway).
if (appConfig().processMode() == Service)
return;
if (synergyState() == state)
return;
@ -747,3 +737,8 @@ void MainWindow::on_m_pElevateCheckBox_toggled(bool checked)
settings().setValue("elevateChecked", checked);
settings().sync();
}
void MainWindow::on_m_pButtonApply_clicked()
{
startSynergy();
}

View File

@ -112,7 +112,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
void logOutput();
void logError();
void updateFound(const QString& version);
void refreshStartButton();
void refreshApplyButton();
void wizardFinished();
protected:
@ -135,6 +135,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
void setStatus(const QString& status);
void sendIpcMessage(qIpcMessageType type, const char* buffer, bool showErrors);
void onModeChanged(bool firstRun, bool forceServiceApply);
void updateStateFromLogLine(const QString& line);
private:
QSettings& m_Settings;
@ -151,6 +152,9 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
IpcClient m_IpcClient;
bool m_ElevateProcess;
bool m_SuppressElevateWarning;
private slots:
void on_m_pButtonApply_clicked();
};
#endif