summaryrefslogtreecommitdiffstats
path: root/src/client/toolbar/toolbar.cpp
diff options
context:
space:
mode:
authorChristian Klinger2016-09-29 15:40:18 +0200
committerChristian Klinger2016-09-29 15:40:18 +0200
commit3d82bfc698165bb20f3c38d42f2b77ab855c1edf (patch)
tree2c170bcdd5c89259bb0b530fa11fdfe701c99850 /src/client/toolbar/toolbar.cpp
parentadded an information dialog that displays ip and hostname. (diff)
downloadpvs2-3d82bfc698165bb20f3c38d42f2b77ab855c1edf.tar.gz
pvs2-3d82bfc698165bb20f3c38d42f2b77ab855c1edf.tar.xz
pvs2-3d82bfc698165bb20f3c38d42f2b77ab855c1edf.zip
astyle.
Diffstat (limited to 'src/client/toolbar/toolbar.cpp')
-rw-r--r--src/client/toolbar/toolbar.cpp194
1 files changed, 100 insertions, 94 deletions
diff --git a/src/client/toolbar/toolbar.cpp b/src/client/toolbar/toolbar.cpp
index 0b97f31..724836f 100644
--- a/src/client/toolbar/toolbar.cpp
+++ b/src/client/toolbar/toolbar.cpp
@@ -78,7 +78,8 @@ Toolbar::Toolbar(QWidget *parent)
{
init();
}
-void Toolbar::exit() {
+void Toolbar::exit()
+{
this->close();
this->deleteLater();
qApp->quit();
@@ -90,7 +91,7 @@ void Toolbar::init()
/* Initialize the GUI */
_ui->setupUi(this);
- _onWorkspace2 = false;
+ _onWorkspace2 = false;
/* Set window properties */
setWindowFlags(Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint);
@@ -102,27 +103,27 @@ void Toolbar::init()
/* Create the connect window */
_connectWindow = new ConnectWindow(NULL);
- _connectWindow->setAvailableRooms(myRooms());
+ _connectWindow->setAvailableRooms(myRooms());
// Connect the signals
connect(_connectWindow, SIGNAL(disconnect()), this, SLOT(onDoDisconnect()));
connect(_connectWindow, SIGNAL(connected(ServerConnection*)), this, SLOT(onConnected(ServerConnection*)));
- /* Setup menu */
- initMenu();
+ /* Setup menu */
+ initMenu();
- /* setup manager button */
- _isManagerPc = isManagerPc();
- _ui->btnManager->setVisible(_isManagerPc);
- connect(_ui->btnManager, SIGNAL(clicked()), this, SLOT(onBtnManager()));
+ /* setup manager button */
+ _isManagerPc = isManagerPc();
+ _ui->btnManager->setVisible(_isManagerPc);
+ connect(_ui->btnManager, SIGNAL(clicked()), this, SLOT(onBtnManager()));
- /* setup lock desktop button*/
+ /* setup lock desktop button*/
SYSTEM_SETTINGS(conf);
- bool showLock = conf.value("showLockDesktopButton").toBool();
- if (showLock) {
- connect(_ui->btnLockDesktop, SIGNAL(clicked()), this, SLOT(onBtnLockDesktop()));
- } else {
- _ui->btnLockDesktop->setVisible(false);
- }
+ bool showLock = conf.value("showLockDesktopButton").toBool();
+ if (showLock) {
+ connect(_ui->btnLockDesktop, SIGNAL(clicked()), this, SLOT(onBtnLockDesktop()));
+ } else {
+ _ui->btnLockDesktop->setVisible(false);
+ }
/* Connect the signals from vnc server */
connect(VncServer::instance(), SIGNAL(started(int, QString&, QString&)), this, SLOT(onVncServerIsRunning(int)));
@@ -130,7 +131,7 @@ void Toolbar::init()
/* Set position */
const QDesktopWidget desktop;
const QRect primaryScreen = desktop.screenGeometry();
- move(primaryScreen.left() + (primaryScreen.width() - this->width())/2 , primaryScreen.top());
+ move(primaryScreen.left() + (primaryScreen.width() - this->width()) / 2 , primaryScreen.top());
/* Setup hide timer */
_hideTimer.setInterval(500);
@@ -149,16 +150,17 @@ void Toolbar::init()
* This function should be called once from the main init() function which in
* turn should only be called by the constructor.
**/
-void Toolbar::initMenu() {
+void Toolbar::initMenu()
+{
_menu = new QMenu(this);
_acnConnect = new QAction(tr("&Connect..."), this);
- _acnDisconnect = new QAction(tr("&Disconnect"), this);
- _acnDisconnect->setEnabled(false);
+ _acnDisconnect = new QAction(tr("&Disconnect"), this);
+ _acnDisconnect->setEnabled(false);
_acnInformation = new QAction(tr("&Information..."), this);
- _acnAbout= new QAction(tr("&What's this?"), this);
+ _acnAbout = new QAction(tr("&What's this?"), this);
_acnQuit = new QAction(tr("&Quit"), this);
- _menu->addAction(_acnConnect);
+ _menu->addAction(_acnConnect);
_menu->addAction(_acnDisconnect);
_menu->addSeparator();
_menu->addAction(_acnInformation);
@@ -167,16 +169,16 @@ void Toolbar::initMenu() {
_menu->addAction(_acnQuit);
_ui->cmdMenu->setMenu(_menu);
- /* only add a "quit"-button when the configuration allows it. */
+ /* only add a "quit"-button when the configuration allows it. */
SYSTEM_SETTINGS(conf);
- bool allow = conf.value("allowClientQuit").toBool();
- _acnQuit->setVisible(allow);
+ bool allow = conf.value("allowClientQuit").toBool();
+ _acnQuit->setVisible(allow);
// Connect the signals
connect(_menu, SIGNAL(aboutToHide()), this, SLOT(hideBar()));
connect(_acnConnect, SIGNAL(triggered()), _connectWindow, SLOT(doShow()));
- connect(_acnDisconnect, SIGNAL(triggered()), _connectWindow, SLOT(DoDisconnect()));
+ connect(_acnDisconnect, SIGNAL(triggered()), _connectWindow, SLOT(DoDisconnect()));
connect(_acnInformation, SIGNAL(triggered()), this, SLOT(showInformationDialog()));
connect(_acnAbout, SIGNAL(triggered()), this, SLOT(showAboutDialog()));
connect(_acnQuit, SIGNAL(triggered()), this, SLOT(exit()));
@@ -232,82 +234,85 @@ void Toolbar::enterEvent(QEvent* e)
/* returns true when the pc of this client is also eligible to be a manager */
-bool Toolbar::isManagerPc(){
- QList<Room> myRooms;
+bool Toolbar::isManagerPc()
+{
+ QList<Room> myRooms;
SYSTEM_SETTINGS(conf);
QStringList roomNames = conf.value("rooms").toStringList();
- /* go through all rooms and check if this client is a manager of the room. */
+ /* go through all rooms and check if this client is a manager of the room. */
for (auto roomName : roomNames) {
conf.beginGroup(roomName);
- QString mgrIP = conf.value("mgrIP").toString();
+ QString mgrIP = conf.value("mgrIP").toString();
- foreach (const QHostAddress &address, QNetworkInterface::allAddresses()) {
- QString ip = conf.value("ip").toString();
- if (address.toString() == mgrIP) {
- return true;
- }
+ foreach (const QHostAddress & address, QNetworkInterface::allAddresses()) {
+ QString ip = conf.value("ip").toString();
+ if (address.toString() == mgrIP) {
+ return true;
+ }
}
conf.endGroup();
}
- return false;
+ return false;
}
/* returns a sorted list of available rooms.
* (Available means that this client is configured to be in that room) */
-QList<Room> Toolbar::myRooms() {
+QList<Room> Toolbar::myRooms()
+{
- QList<Room> myRooms;
+ QList<Room> myRooms;
SYSTEM_SETTINGS(conf);
if (!conf.contains("rooms")) {
qDebug() << "Invalid config file!";
- return myRooms;
+ return myRooms;
}
QStringList roomNames = conf.value("rooms").toStringList();
- /* go through all rooms and check if this client is a member of the room. */
+ /* go through all rooms and check if this client is a member of the room. */
for (auto roomName : roomNames) {
conf.beginGroup(roomName);
if (!conf.contains("mgrIP")) {
qDebug() << "Invalid config file!";
return myRooms;
}
- QString mgrIP = conf.value("mgrIP").toString();
- int priority = conf.value("priority").toInt();
+ QString mgrIP = conf.value("mgrIP").toString();
+ int priority = conf.value("priority").toInt();
- foreach (const QHostAddress &address, QNetworkInterface::allAddresses()) {
+ foreach (const QHostAddress & address, QNetworkInterface::allAddresses()) {
int size = conf.beginReadArray("client");
for (int j = 0; j < size; ++j) {
conf.setArrayIndex(j);
QString ip = conf.value("ip").toString();
if (address != QHostAddress(QHostAddress::LocalHost)
- && ip == address.toString() ) {
- /* add this room to the list */
- Room r(roomName, mgrIP, priority);
- myRooms << r;
- break;
+ && ip == address.toString() ) {
+ /* add this room to the list */
+ Room r(roomName, mgrIP, priority);
+ myRooms << r;
+ break;
}
}
conf.endArray();
}
conf.endGroup();
}
- /* sort */
- qStableSort(myRooms.begin(), myRooms.end(), qGreater<Room>());
- return myRooms;
+ /* sort */
+ qStableSort(myRooms.begin(), myRooms.end(), qGreater<Room>());
+ return myRooms;
}
/** Identifies the responsible manager for this client by searching through the
* configuration file. The manager whose room has the highest priority is chosen. */
-QString Toolbar::identifyMgrIP() {
- QList<Room> rooms = myRooms();
- if (!rooms.empty()) {
- return rooms.first().mgr;
- } else {
- return "";
- }
+QString Toolbar::identifyMgrIP()
+{
+ QList<Room> rooms = myRooms();
+ if (!rooms.empty()) {
+ return rooms.first().mgr;
+ } else {
+ return "";
+ }
}
/*
@@ -321,13 +326,10 @@ QString Toolbar::identifyMgrIP() {
void Toolbar::cameraBlink()
{
static bool showEye = false;
- if (!showEye)
- {
+ if (!showEye) {
_ui->icon_cam->setPixmap(_beWatchedEye);
showEye = true;
- }
- else
- {
+ } else {
_ui->icon_cam->setPixmap(QPixmap()); // set empty pixmap for blinking effect
showEye = false;
}
@@ -358,15 +360,16 @@ void Toolbar::onVncServerIsRunning(int port)
* A slot for the onDisconnected signal of the ConnectWindow. This slot will
* change the UI according to the state fo the connection.
*/
-void Toolbar::onDisconnected() {
+void Toolbar::onDisconnected()
+{
if (_connection != NULL)
_connection->blockSignals(true);
_connection = NULL;
_ui->lblStatus->setStyleSheet("color:red");
_ui->lblStatus->setText(tr("Offline"));
- this->_acnConnect->setEnabled(true);
- this->_acnDisconnect->setEnabled(false);
+ this->_acnConnect->setEnabled(true);
+ this->_acnDisconnect->setEnabled(false);
}
/***************************************************************************//**
@@ -377,15 +380,14 @@ void Toolbar::onDisconnected() {
*/
void Toolbar::onConnected(ServerConnection* connection)
{
- this->_acnConnect->setEnabled(false);
- this->_acnDisconnect->setEnabled(true);
+ this->_acnConnect->setEnabled(false);
+ this->_acnDisconnect->setEnabled(true);
_ui->lblStatus->setStyleSheet("color:green");
_ui->lblStatus->setText(tr("Online"));
//
- if (_connection != NULL)
- {
+ if (_connection != NULL) {
disconnect(_connection, SIGNAL(disconnected()), this, SLOT(onDisconnected()));
_connection->blockSignals(true);
_connection->disconnectFromServer();
@@ -393,7 +395,7 @@ void Toolbar::onConnected(ServerConnection* connection)
_connection = connection;
connect(_connection, SIGNAL(disconnected()), this, SLOT(onDisconnected()));
connect(_connection, SIGNAL(openVnc(const QString&, int, const QString&, bool, bool, const QString&, const int, const QByteArray&)),
- _vnc, SLOT(open(const QString&, int, const QString&, bool, bool, const QString&, const int, const QByteArray&)));
+ _vnc, SLOT(open(const QString&, int, const QString&, bool, bool, const QString&, const int, const QByteArray&)));
connect(_connection, SIGNAL(closeVnc()), _vnc, SLOT(close()));
connect(_vnc, SIGNAL(running(const bool, const int)), _connection, SLOT(onVncViewerStartStop(const bool, const int)));
}
@@ -427,20 +429,21 @@ void Toolbar::hideBar()
void Toolbar::showAboutDialog()
{
QMessageBox msgBox(
- QMessageBox::NoIcon,
- tr("About PVS Client"),
- tr("The PVS - client is part of a software system for managing the "\
- "virtual data traffic within the computer pools, between the tutor's "\
- "and student's PCs. It has been developed to simplify the information "\
- "traffic in seminars and general eLearning."),
- QMessageBox::NoButton,
- this,
- Qt::Dialog|Qt::MSWindowsFixedSizeDialogHint|Qt::WindowStaysOnTopHint);
- msgBox.setIconPixmap(QIcon(":cam32.svg").pixmap(64,64));
+ QMessageBox::NoIcon,
+ tr("About PVS Client"),
+ tr("The PVS - client is part of a software system for managing the "\
+ "virtual data traffic within the computer pools, between the tutor's "\
+ "and student's PCs. It has been developed to simplify the information "\
+ "traffic in seminars and general eLearning."),
+ QMessageBox::NoButton,
+ this,
+ Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowStaysOnTopHint);
+ msgBox.setIconPixmap(QIcon(":cam32.svg").pixmap(64, 64));
msgBox.exec();
}
-void Toolbar::showInformationDialog() {
+void Toolbar::showInformationDialog()
+{
InformationDialog* d = new InformationDialog();
d->exec();
}
@@ -454,19 +457,21 @@ void Toolbar::showBar()
move(x(), primaryScreen.top());
}
/** call script to switch to workspace of the manager */
-void Toolbar::onBtnManager() {
- QProcess switchP;
- if (_onWorkspace2) {
- switchP.start("/bin/sh", QStringList() << "/opt/openslx/pvs2/switchBack.sh");
- } else {
- switchP.start("/bin/sh", QStringList() << "/opt/openslx/pvs2/switchToManager.sh");
- }
- _ui->btnManager->setDown(_onWorkspace2);
- _onWorkspace2 = !_onWorkspace2;
- switchP.waitForFinished();
+void Toolbar::onBtnManager()
+{
+ QProcess switchP;
+ if (_onWorkspace2) {
+ switchP.start("/bin/sh", QStringList() << "/opt/openslx/pvs2/switchBack.sh");
+ } else {
+ switchP.start("/bin/sh", QStringList() << "/opt/openslx/pvs2/switchToManager.sh");
+ }
+ _ui->btnManager->setDown(_onWorkspace2);
+ _onWorkspace2 = !_onWorkspace2;
+ switchP.waitForFinished();
}
-void Toolbar::onBtnLockDesktop() {
+void Toolbar::onBtnLockDesktop()
+{
qDebug() << "onBtnLockDesktop()";
if (this->lockDesktopP.state() == QProcess::NotRunning) {
_ui->btnLockDesktop->setEnabled(false);
@@ -479,7 +484,8 @@ void Toolbar::onBtnLockDesktop() {
}
}
-void Toolbar::enableLockBtn() {
+void Toolbar::enableLockBtn()
+{
_ui->btnLockDesktop->setEnabled(true);
}