Resolve #4230 more user friendly dialog when client is detected

This commit is contained in:
Xinyu Hou 2014-11-18 11:00:31 +00:00
parent 30f478ad5c
commit b2435cdaef
6 changed files with 303 additions and 42 deletions

View File

@ -13,7 +13,8 @@ FORMS += res/MainWindowBase.ui \
res/ActionDialogBase.ui \ res/ActionDialogBase.ui \
res/HotkeyDialogBase.ui \ res/HotkeyDialogBase.ui \
res/SettingsDialogBase.ui \ res/SettingsDialogBase.ui \
res/SetupWizardBase.ui res/SetupWizardBase.ui \
res/AddClientDialogBase.ui
SOURCES += src/main.cpp \ SOURCES += src/main.cpp \
src/MainWindow.cpp \ src/MainWindow.cpp \
src/AboutDialog.cpp \ src/AboutDialog.cpp \
@ -47,7 +48,8 @@ SOURCES += src/main.cpp \
src/ZeroconfRegister.cpp \ src/ZeroconfRegister.cpp \
src/ZeroconfBrowser.cpp \ src/ZeroconfBrowser.cpp \
src/ZeroconfService.cpp \ src/ZeroconfService.cpp \
src/DataDownloader.cpp src/DataDownloader.cpp \
src/AddClientDialog.cpp
HEADERS += src/MainWindow.h \ HEADERS += src/MainWindow.h \
src/AboutDialog.h \ src/AboutDialog.h \
src/ServerConfig.h \ src/ServerConfig.h \
@ -81,7 +83,8 @@ HEADERS += src/MainWindow.h \
src/ZeroconfRecord.h \ src/ZeroconfRecord.h \
src/ZeroconfBrowser.h \ src/ZeroconfBrowser.h \
src/ZeroconfService.h \ src/ZeroconfService.h \
src/DataDownloader.h src/DataDownloader.h \
src/AddClientDialog.h
RESOURCES += res/Synergy.qrc RESOURCES += res/Synergy.qrc
RC_FILE = res/win/Synergy.rc RC_FILE = res/win/Synergy.rc
macx { macx {

View File

@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AddClientDialog</class>
<widget class="QDialog" name="AddClientDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>350</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QDialogButtonBox" name="m_pDialogButtonBox">
<property name="geometry">
<rect>
<x>50</x>
<y>320</y>
<width>341</width>
<height>20</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Ignore</set>
</property>
<property name="centerButtons">
<bool>false</bool>
</property>
</widget>
<widget class="QWidget" name="gridLayoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>381</width>
<height>301</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout"/>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>m_pDialogButtonBox</sender>
<signal>accepted()</signal>
<receiver>AddClientDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>m_pDialogButtonBox</sender>
<signal>rejected()</signal>
<receiver>AddClientDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -0,0 +1,121 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2014 Synergy Si, Inc.
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "AddClientDialog.h"
#include "ui_AddClientDialogBase.h"
#include <QPushButton>
#include <QLabel>
AddClientDialog::AddClientDialog(QWidget *parent) :
QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
Ui::AddClientDialog(),
m_AddResult(kAddClientIgnore)
{
setupUi(this);
m_pLabelHead = new QLabel(this);
m_pLabelHead->setText("Client wants to connect...");
gridLayout->addWidget(m_pLabelHead, 0, 1, 1, 1, Qt::AlignCenter);
QIcon icon(":res/icons/64x64/video-display.png");
QSize IconSize(32,32);
m_pButtonLeft = new QPushButton(this);
m_pButtonLeft->setIcon(icon);
m_pButtonLeft->setIconSize(IconSize);
gridLayout->addWidget(m_pButtonLeft, 2, 0, 1, 1, Qt::AlignCenter);
connect(m_pButtonLeft, SIGNAL(clicked()), this, SLOT(handleButtonLeft()));
m_pButtonUp = new QPushButton(this);
m_pButtonUp->setIcon(icon);
m_pButtonUp->setIconSize(IconSize);
gridLayout->addWidget(m_pButtonUp, 1, 1, 1, 1, Qt::AlignCenter);
connect(m_pButtonUp, SIGNAL(clicked()), this, SLOT(handleButtonUp()));
m_pButtonRight = new QPushButton(this);
m_pButtonRight->setIcon(icon);
m_pButtonRight->setIconSize(IconSize);
gridLayout->addWidget(m_pButtonRight, 2, 2, 1, 1, Qt::AlignCenter);
connect(m_pButtonRight, SIGNAL(clicked()), this, SLOT(handleButtonRight()));
m_pButtonDown = new QPushButton(this);
m_pButtonDown->setIcon(icon);
m_pButtonDown->setIconSize(IconSize);
gridLayout->addWidget(m_pButtonDown, 3, 1, 1, 1, Qt::AlignCenter);
connect(m_pButtonDown, SIGNAL(clicked()), this, SLOT(handleButtonDown()));
m_pLabelCenter = new QLabel(this);
m_pLabelCenter->setPixmap(QPixmap(":res/icons/64x64/video-display.png"));
gridLayout->addWidget(m_pLabelCenter, 2, 1, 1, 1, Qt::AlignCenter);
QPushButton* advanced = m_pDialogButtonBox->addButton("Advanced",
QDialogButtonBox::HelpRole);
connect(advanced, SIGNAL(clicked()), this, SLOT(handleButtonAdvanced()));
}
AddClientDialog::~AddClientDialog()
{
delete m_pButtonUp;
delete m_pButtonDown;
delete m_pButtonLeft;
delete m_pButtonRight;
delete m_pLabelHead;
delete m_pLabelCenter;
}
void AddClientDialog::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
retranslateUi(this);
break;
default:
break;
}
}
void AddClientDialog::handleButtonLeft()
{
m_AddResult = kAddClientLeft;
close();
}
void AddClientDialog::handleButtonUp()
{
m_AddResult = kAddClientUp;
close();
}
void AddClientDialog::handleButtonRight()
{
m_AddResult = kAddClientRight;
close();
}
void AddClientDialog::handleButtonDown()
{
m_AddResult = kAddClientDown;
close();
}
void AddClientDialog::handleButtonAdvanced()
{
m_AddResult = kAddClientOther;
close();
}

View File

@ -0,0 +1,66 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2014 Synergy Si, Inc.
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ADDCLIENTDIALOG_H
#define ADDCLIENTDIALOG_H
#include "ui_AddClientDialogBase.h"
#include <QDialog>
class QPushButton;
class QLabel;
enum {
kAddClientRight,
kAddClientLeft,
kAddClientUp,
kAddClientDown,
kAddClientOther,
kAddClientIgnore
};
class AddClientDialog : public QDialog, public Ui::AddClientDialog
{
Q_OBJECT
public:
AddClientDialog(QWidget *parent = 0);
~AddClientDialog();
int getAddResult() { return m_AddResult; }
protected:
void changeEvent(QEvent *e);
private slots:
void handleButtonLeft();
void handleButtonUp();
void handleButtonRight();
void handleButtonDown();
void handleButtonAdvanced();
private:
QPushButton* m_pButtonLeft;
QPushButton* m_pButtonUp;
QPushButton* m_pButtonRight;
QPushButton* m_pButtonDown;
QLabel* m_pLabelCenter;
QLabel* m_pLabelHead;
int m_AddResult;
};
#endif // ADDCLIENTDIALOG_H

View File

@ -19,6 +19,7 @@
#include "ServerConfig.h" #include "ServerConfig.h"
#include "Hotkey.h" #include "Hotkey.h"
#include "MainWindow.h" #include "MainWindow.h"
#include "AddClientDialog.h"
#include <QtCore> #include <QtCore>
#include <QMessageBox> #include <QMessageBox>
@ -39,13 +40,6 @@ static const struct
}; };
enum {
kAddClientRight,
kAddClientLeft,
kAddClientOther,
kAddClientIgnore
};
const int serverDefaultIndex = 7; const int serverDefaultIndex = 7;
ServerConfig::ServerConfig(QSettings* settings, int numColumns, int numRows , ServerConfig::ServerConfig(QSettings* settings, int numColumns, int numRows ,
@ -294,7 +288,7 @@ int ServerConfig::autoAddScreen(const QString name)
return kAutoAddScreenOk; return kAutoAddScreenOk;
} }
int result = showAddClientMsgBox(name); int result = showAddClientDialog(name);
if (result == kAddClientIgnore) { if (result == kAddClientIgnore) {
return kAutoAddScreenIgnore; return kAutoAddScreenIgnore;
@ -314,6 +308,15 @@ int ServerConfig::autoAddScreen(const QString name)
offset = -1; offset = -1;
dirIndex = 1; dirIndex = 1;
} }
else if (result == kAddClientUp) {
offset = -5;
dirIndex = 2;
}
else if (result == kAddClientDown) {
offset = 5;
dirIndex = 3;
}
int idx = adjacentScreenIndex(startIndex, neighbourDirs[dirIndex].x, int idx = adjacentScreenIndex(startIndex, neighbourDirs[dirIndex].x,
neighbourDirs[dirIndex].y); neighbourDirs[dirIndex].y);
@ -364,37 +367,11 @@ bool ServerConfig::fixNoServer(const QString& name, int& index)
return fixed; return fixed;
} }
int ServerConfig::showAddClientMsgBox(const QString& clientName) int ServerConfig::showAddClientDialog(const QString& clientName)
{ {
int result = kAddClientIgnore; AddClientDialog addClientDialog(m_pMainWindow);
QWidget* w = dynamic_cast<QWidget*>(m_pMainWindow); addClientDialog.exec();
QMessageBox msgBox(w); int result = addClientDialog.getAddResult();
msgBox.setIcon(QMessageBox::Question);
msgBox.setWindowTitle(QObject::tr("Incoming client"));
msgBox.setText(QObject::tr(
"A new client wants to connect. Which side\n"
"of this screen is the client (%1) located?")
.arg(clientName));
QPushButton* left = msgBox.addButton(QObject::tr("Left"), QMessageBox::AcceptRole);
QPushButton* right = msgBox.addButton(QObject::tr("Right"), QMessageBox::AcceptRole);
QPushButton* other = msgBox.addButton(QObject::tr("Other"), QMessageBox::AcceptRole);
QPushButton* ignore = msgBox.addButton(QObject::tr("Ignore"), QMessageBox::RejectRole);
msgBox.setDefaultButton(ignore);
msgBox.exec();
QAbstractButton* button = msgBox.clickedButton();
QPushButton* clickedButton = dynamic_cast<QPushButton*>(button);
if (clickedButton == right) {
result = kAddClientRight;
}
else if (clickedButton == left) {
result = kAddClientLeft;
}
else if (clickedButton == other) {
result = kAddClientOther;
}
return result; return result;
} }

View File

@ -95,7 +95,7 @@ class ServerConfig : public BaseConfig
private: private:
bool findScreenName(const QString& name, int& index); bool findScreenName(const QString& name, int& index);
bool fixNoServer(const QString& name, int& index); bool fixNoServer(const QString& name, int& index);
int showAddClientMsgBox(const QString& clientName); int showAddClientDialog(const QString& clientName);
void addToFirstEmptyGrid(const QString& clientName); void addToFirstEmptyGrid(const QString& clientName);
private: private: