1 #include "../../shared/settings.h"
2 #include "../net/serverconnection.h"
3 #include "../vnc/vncwindow.h"
4 #include "../vnc/vncserver.h"
5 #include "../informationdialog/informationdialog.h"
6 #include "../clientapp/clientapp.h"
7 #include "../addons/addons.h"
10 #include "ui_toolbar.h"
12 #include <QNetworkInterface>
15 #include <QMouseEvent>
16 #include <QMessageBox>
34 , _beWatchedEye(
":eye")
36 qDebug() <<
"sessionName - constructor";
39 clientApp->connectWindow()->connectToSession(sessionName,
"");
58 , _beWatchedEye(
":eye")
60 qDebug() <<
"auto - constructor!";
68 clientApp->connectWindow()->connectToSession(
"", mgrIp);
84 :
QWidget(parent), _showTimer(this), _hideTimer(this), _hideCountdown(10), _blinkTimer(this), _beWatchedEye(
":eye")
98 _ui =
new Ui::Toolbar;
103 setWindowFlags(Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint);
104 setAttribute(Qt::WA_AlwaysShowToolTips);
105 setAttribute(Qt::WA_QuitOnClose,
false);
106 setAttribute(Qt::WA_DeleteOnClose,
false);
122 _ui->btnAttention->setVisible(
false);
123 _ui->btnAttention->setMaximumWidth(30);
132 const QRect availableScreen = QGuiApplication::primaryScreen()->availableGeometry();
153 auto *f =
new QFrame();
154 f->setFrameShape(QFrame::HLine);
155 f->setFrameShadow(QFrame::Sunken);
165 QList<QPushButton*> buttons;
166 QList<QAction*> menus;
167 auto settings =
clientApp->getSettings();
170 if (!buttons.isEmpty()) {
172 for (
auto i : buttons) {
173 _ui->buttonContainer->addWidget(i);
174 i->setVisible(
false);
179 _menu =
new QMenu(
this);
180 _acnConnect =
new QAction(tr(
"&Connect..."),
this);
184 _acnAbout =
new QAction(tr(
"&What's this?"),
this);
185 _acnQuit =
new QAction(tr(
"&Quit"),
this);
189 _menu->addSeparator();
190 for (
auto i : menus) {
192 i->setVisible(
false);
196 _menu->addSeparator();
201 bool allow = settings->value(
"allowClientQuit").toBool();
213 QTimer::singleShot(10, [=]() {
242 QWidget::enterEvent(e);
252 const QPoint currentPos = e->globalPos();
254 _lastDragPos = currentPos;
255 move(x() + offset.x(), y());
274 if (!conf->contains(
"rooms")) {
275 qDebug() <<
"Invalid config file!";
279 QStringList roomNames = conf->value(
"rooms").toStringList();
282 auto localAddresses = QNetworkInterface::allAddresses();
283 for (
auto roomName : roomNames) {
284 conf->beginGroup(roomName);
285 if (conf->contains(
"name")) {
286 roomName = conf->value(
"name").toString();
288 if (!conf->contains(
"mgrIP")) {
289 qDebug() <<
"Room " << roomName <<
" has no mgrIP: Invalid config file!";
291 QString mgrIP = conf->value(
"mgrIP").toString();
292 int priority = conf->value(
"priority").toInt();
294 if (mgrIP.length() != 0) {
295 foreach (
const QHostAddress & address, localAddresses) {
296 int size = conf->beginReadArray(
"client");
297 for (
int j = 0; j < size; ++j) {
298 conf->setArrayIndex(j);
299 QString ip = conf->value(
"ip").toString();
300 if (address != QHostAddress(QHostAddress::LocalHost)
301 && ip == address.toString() ) {
303 Room r(roomName, mgrIP, priority);
314 qStableSort(myRooms.begin(), myRooms.end(), qGreater<Room>());
322 if (!rooms.empty()) {
323 return rooms.first().mgr;
339 static bool showEye =
false;
344 _ui->icon_cam->setPixmap(QPixmap());
358 _ui->lblStatus->setStyleSheet(
"color:red");
359 _ui->lblStatus->setText(tr(
"Streaming"));
363 _ui->icon_cam->setPixmap(QPixmap());
364 _ui->lblStatus->setStyleSheet(
"color:green");
365 _ui->lblStatus->setText(tr(
"Online"));
376 if (connection !=
nullptr) {
379 _ui->lblStatus->setStyleSheet(
"color:red");
380 _ui->lblStatus->setText(tr(
"Offline"));
384 _ui->btnAttention->setVisible(
false);
401 _ui->btnAttention->setChecked(
false);
402 _ui->lblStatus->setStyleSheet(
"color:green");
403 _ui->lblStatus->setText(tr(
"Online"));
405 _ui->btnAttention->setVisible(
true);
422 clientApp->connection()->disconnectFromServer();
427 _ui->btnAttention->setChecked(on);
447 if (
_menu->isVisible() || this->underMouse())
489 tr(
"About PVS Client"),
490 tr(
"The PVS - client is part of a software system for managing the "\
491 "virtual data traffic within the computer pools, between the tutor's "\
492 "and student's PCs. It has been developed to simplify the information "\
493 "traffic in seminars and general eLearning."),
494 QMessageBox::NoButton,
496 Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowStaysOnTopHint);
497 msgBox.setIconPixmap(QIcon(
":cam32.svg").pixmap(64, 64));
510 const bool on =
clientApp->connection() !=
nullptr &&
_ui->btnAttention->isChecked();
511 if (on !=
_ui->btnAttention->isChecked()) {
512 _ui->btnAttention->setChecked(on);
515 if (
clientApp->connection() !=
nullptr) {
516 clientApp->connection()->sendAttention(on);
522 const QRect primaryScreen = QGuiApplication::primaryScreen()->geometry();
524 const int centerPos = primaryScreen.left() + (primaryScreen.width() - this->width()) / 2;
527 if (primaryScreen.height() > availableGeometry.height() && primaryScreen.y() < availableGeometry.y()) {
529 _yPos = primaryScreen.height() - this->height();
533 _yPos = primaryScreen.top();
536 move(centerPos,
_yPos);
QString getPeerAdress() const
void stop()
VncServer::stop.
void started(int port, const QString &ropass, const QString &rwpass)
static void initControls()
void DoDisconnect()
actually disconnects the connection
static void connectEvent(bool isLocal, const QString &address)
static void disconnectEvent()
void attentionChanged(bool state)
void disconnected(ServerConnection *connection)
void running(const bool isRunning, const int clientId)
static void loadFromPath(const QString &path, QList< QPushButton * > &buttons, QList< QAction * > &menuEntries)
void openVnc(const QString &host, int port, const QString &passwd, bool ro, bool fullscreen, const QString &caption, const int clientId, const QByteArray &rawThumb)
void connected(ServerConnection *connection)
void onVncViewerStartStop(bool started, int clientId)
This slot is triggered once the internal VNC viewer has started or stopped displaying a VNC stream...
void open(const QString &host, int port, const QString &passwd, bool ro, bool fullscreen, const QString &caption, const int clientId, const QByteArray &rawThumb)
Show the VNC client window and connect to the given VNC server.
bool isVncServerRunning() const
static VncServer * instance()
VncServer::instance.