/* # Copyright (c) 2009 - OpenSLX Project, Computer Center University of Freiburg # # This program is free software distributed under the GPL version 2. # See http://openslx.org/COPYING # # If you have any feedback please consult http://openslx.org/feedback and # send your suggestions, praise, or complaints to feedback@openslx.org # # General information about OpenSLX can be found at http://openslx.org/ # ----------------------------------------------------------------------------- # mainWindow.cpp This is the Main class for the pvsManager. The GUI is contructed here. # ----------------------------------------------------------------------------- */ #include #include #include #include #include #include #include using namespace std; // setting the IF-DEF Block for the touchgui and the normal gui, for later use #ifdef MAINWINDOW_USE_TOUCHGUI #include "ui_mainwindowtouch.h" #endif #ifdef MAINWINDOW_USE_NORMALGUI #include "ui_mainwindow.h" #endif #include #include #include #include //#include #include #include #include MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, flags), ui(new Ui::MainWindow) { ui->setupUi(this); myself = this; #ifdef MAINWINDOW_USE_NORMALGUI ui->horizontalSlider->setValue(100); ui->label_2->setText("100"); ui->separator->setVisible(false); conList = new ConnectionList(ui->ClWidget); ui->ClientGLayout->addWidget(conList); #endif conWin = new ConnectionWindow(ui->widget); ui->VconWinLayout->addWidget(conWin); bgimage = false; _aboutDialog = new AboutDialog(this); displayedClientNameEnum = 0; PVSConnectionManager::getManager(); //set the maximum width for list content #ifdef MAINWINDOW_USE_NORMALGUI ui->ClWidget->setMaximumWidth(160); ui->pvsLog->setReadOnly(true); ui->pvsLog->hide(); #endif onToggleLog(false); // add ourself to the log listeners, so we can output them too ConsoleLog addListener(this, &MainWindow::on_log_line); _firstResize = 1; _oldRatio = "100"; _isThumbnailrate = false; is_closeup = false; is_fullscreen = false; _isLockAll = false; locked = false; /* * _sessionName: The session name for this Connection * _pwdCon: Password needed to connect to the session with the name _sessionName */ _pwdCon = PVSConnectionManager::getManager()->setNeedPassword(false); _sessionName = PVSConnectionManager::getManager()->getSessionName(); _profileDialog = new profileDialog(this); #ifdef MAINWINDOW_USE_TOUCHGUI //only used for the touchgui // group actions (zoom, refresh and quality) so we get radio-buttons QActionGroup *zoomActionGroup = new QActionGroup(this); zoomActionGroup->addAction(ui->action_zoom_25); zoomActionGroup->addAction(ui->action_zoom_50); zoomActionGroup->addAction(ui->action_zoom_75); zoomActionGroup->addAction(ui->action_zoom_100); zoomActionGroup->addAction(ui->action_zoom_125); zoomActionGroup->addAction(ui->action_zoom_150); zoomActionGroup->addAction(ui->action_zoom_175); zoomActionGroup->addAction(ui->action_zoom_200); QActionGroup *refreshActionGroup = new QActionGroup(this); refreshActionGroup->addAction(ui->action_refresh_100); refreshActionGroup->addAction(ui->action_refresh_200); refreshActionGroup->addAction(ui->action_refresh_300); refreshActionGroup->addAction(ui->action_refresh_400); refreshActionGroup->addAction(ui->action_refresh_500); refreshActionGroup->addAction(ui->action_refresh_600); refreshActionGroup->addAction(ui->action_refresh_700); refreshActionGroup->addAction(ui->action_refresh_800); refreshActionGroup->addAction(ui->action_refresh_900); refreshActionGroup->addAction(ui->action_refresh_1000); QActionGroup *qualityActionGroup = new QActionGroup(this); qualityActionGroup->addAction(ui->action_quality_High); qualityActionGroup->addAction(ui->action_quality_Medium); qualityActionGroup->addAction(ui->action_quality_Low); // define the slots we want to use connect(ui->action_Info, SIGNAL(triggered()), this, SLOT(info())); connect(ui->action_Quit, SIGNAL(triggered()), this, SLOT(close())); connect(ui->action_Manage_Profiles, SIGNAL(triggered()), this, SLOT(createProfile())); connect(ui->action_Reset, SIGNAL(triggered()), this, SLOT(resetall())); connect(ui->action_Lock, SIGNAL(triggered()), this, SLOT(locksingle())); connect(ui->action_Unlock, SIGNAL(triggered()), this, SLOT(unlocksingle())); connect(ui->action_Project, SIGNAL(triggered()), this, SLOT(projecttoolbar())); connect(ui->action_Unproject, SIGNAL(triggered()), this, SLOT(unprojecttoolbar())); connect(ui->action_Set_as_Tutor_PC, SIGNAL(triggered()), this, SLOT(setdozenttoolbar())); connect(ui->action_Maximize, SIGNAL(triggered()), this, SLOT(closeUp())); connect(ui->action_Screenshot, SIGNAL(triggered()), this, SLOT(foto())); connect(ui->action_Lock_All, SIGNAL(triggered()), this, SLOT(lockalltoolbar())); connect(ui->action_Config_Network, SIGNAL(triggered()), this, SLOT(configureNetwork())); connect(ui->action_Show_Processes, SIGNAL(triggered()), this, SLOT(showProcesses())); connect(ui->action_Start_Processes, SIGNAL(triggered()), this, SLOT(startProcess())); connect(ui->action_About, SIGNAL(triggered()), _aboutDialog, SLOT(open())); connect(ui->action_Save_Profile, SIGNAL(triggered()), _profileDialog, SLOT(save())); connect(ui->action_Backgroundimage, SIGNAL(triggered()), this, SLOT(backgroundpicture())); connect(ui->action_Use_Password, SIGNAL(toggled(bool)), this, SLOT(setPasswordForConnection(bool))); // using QSignalMapper to get advanced signals&slots (Zoom, Refresh and Quality) QSignalMapper *zoomSignalMapper = new QSignalMapper(this); zoomSignalMapper->setMapping(ui->action_zoom_25, 25); zoomSignalMapper->setMapping(ui->action_zoom_50, 50); zoomSignalMapper->setMapping(ui->action_zoom_75, 75); zoomSignalMapper->setMapping(ui->action_zoom_100, 100); zoomSignalMapper->setMapping(ui->action_zoom_125, 125); zoomSignalMapper->setMapping(ui->action_zoom_150, 150); zoomSignalMapper->setMapping(ui->action_zoom_175, 175); zoomSignalMapper->setMapping(ui->action_zoom_200, 200); connect(ui->action_zoom_25, SIGNAL(triggered()), zoomSignalMapper, SLOT (map())); connect(ui->action_zoom_50, SIGNAL(triggered()), zoomSignalMapper, SLOT (map())); connect(ui->action_zoom_75, SIGNAL(triggered()), zoomSignalMapper, SLOT (map())); connect(ui->action_zoom_100, SIGNAL(triggered()), zoomSignalMapper, SLOT (map())); connect(ui->action_zoom_125, SIGNAL(triggered()), zoomSignalMapper, SLOT (map())); connect(ui->action_zoom_150, SIGNAL(triggered()), zoomSignalMapper, SLOT (map())); connect(ui->action_zoom_175, SIGNAL(triggered()), zoomSignalMapper, SLOT (map())); connect(ui->action_zoom_200, SIGNAL(triggered()), zoomSignalMapper, SLOT (map())); connect(zoomSignalMapper, SIGNAL(mapped(int)), this, SLOT(changeRatio(int))); QSignalMapper *refreshSignalMapper = new QSignalMapper(this); refreshSignalMapper->setMapping(ui->action_refresh_100, 100); refreshSignalMapper->setMapping(ui->action_refresh_200, 200); refreshSignalMapper->setMapping(ui->action_refresh_300, 300); refreshSignalMapper->setMapping(ui->action_refresh_400, 400); refreshSignalMapper->setMapping(ui->action_refresh_500, 500); refreshSignalMapper->setMapping(ui->action_refresh_600, 600); refreshSignalMapper->setMapping(ui->action_refresh_700, 700); refreshSignalMapper->setMapping(ui->action_refresh_800, 800); refreshSignalMapper->setMapping(ui->action_refresh_900, 900); refreshSignalMapper->setMapping(ui->action_refresh_1000, 1000); connect(ui->action_refresh_100, SIGNAL(triggered()), refreshSignalMapper, SLOT (map())); connect(ui->action_refresh_200, SIGNAL(triggered()), refreshSignalMapper, SLOT (map())); connect(ui->action_refresh_300, SIGNAL(triggered()), refreshSignalMapper, SLOT (map())); connect(ui->action_refresh_400, SIGNAL(triggered()), refreshSignalMapper, SLOT (map())); connect(ui->action_refresh_500, SIGNAL(triggered()), refreshSignalMapper, SLOT (map())); connect(ui->action_refresh_600, SIGNAL(triggered()), refreshSignalMapper, SLOT (map())); connect(ui->action_refresh_700, SIGNAL(triggered()), refreshSignalMapper, SLOT (map())); connect(ui->action_refresh_800, SIGNAL(triggered()), refreshSignalMapper, SLOT (map())); connect(ui->action_refresh_900, SIGNAL(triggered()), refreshSignalMapper, SLOT (map())); connect(ui->action_refresh_1000, SIGNAL(triggered()), refreshSignalMapper, SLOT (map())); connect(refreshSignalMapper, SIGNAL(mapped(int)), this, SLOT(changeRefresh(int))); QSignalMapper *qualitySignalMapper = new QSignalMapper(this); qualitySignalMapper->setMapping(ui->action_quality_High, 0); qualitySignalMapper->setMapping(ui->action_quality_Medium, 1); qualitySignalMapper->setMapping(ui->action_quality_Low, 2); connect(ui->action_quality_High, SIGNAL(triggered()), qualitySignalMapper, SLOT (map())); connect(ui->action_quality_Medium, SIGNAL(triggered()), qualitySignalMapper, SLOT (map())); connect(ui->action_quality_Low, SIGNAL(triggered()), qualitySignalMapper, SLOT (map())); connect(qualitySignalMapper, SIGNAL(mapped(int)), this, SLOT(setVNCQuality(int))); #else // toolbar and actions in pvsmgr connect(ui->action_Exit, SIGNAL(triggered()), this, SLOT(close())); ui->action_Exit->setStatusTip(tr("Exit")); connect(ui->action_Disconnect, SIGNAL(triggered()), this, SLOT(disconnect())); ui->action_Disconnect->setStatusTip(tr("Remove the vnc-Connection for the selected client(s)")); ui->action_Disconnect->setVisible(false);//we need it only for debug connect(ui->actionView, SIGNAL(triggered()), this, SLOT(closeUp())); ui->actionView->setStatusTip(tr("Show the selected client in the whole window")); connect(ui->actionFoto, SIGNAL(triggered()), this, SLOT(foto())); connect(ui->actionLock, SIGNAL(triggered()), this, SLOT(lockalltoolbar())); connect(ui->actionChat, SIGNAL(triggered()),this, SLOT(startChatDialog())); ui->actionFoto->setStatusTip(tr("Make a screenshot for the selected client(s)")); ui->actionLock->setStatusTip(tr("Lock or Unlock all Clients")); connect(ui->actionCreate_profile, SIGNAL(triggered()), this, SLOT(createProfile())); connect(ui->actionConfigure_Network, SIGNAL(triggered()), this, SLOT(configureNetwork())); connect(ui->actionShowProcesses, SIGNAL(triggered()), this, SLOT(showProcesses())); ui->actionShowProcesses->setStatusTip(tr("Show Processes of the selected Client")); connect(ui->actionStartProcess, SIGNAL(triggered()), this, SLOT(startProcess())); ui->actionStartProcess->setStatusTip(tr("Starts Process on the selected Client(s)")); connect(ui->actionShow_Username, SIGNAL(triggered()), this, SLOT(showusername())); connect(ui->actionShow_Hostname_IP, SIGNAL(triggered()), this, SLOT(showip())); connect(ui->actionShow_Fullname, SIGNAL(triggered()), this, SLOT(showname())); connect(ui->horizontalSlider, SIGNAL(valueChanged (int)), this, SLOT(changeRatio(int))); connect(ui->setPassword, SIGNAL(stateChanged (int)), this, SLOT(setPasswordForConnection(int))); connect(ui->vncQuality, SIGNAL(currentIndexChanged (int)), this, SLOT(setVNCQuality(int))); connect(ui->thumbStatus, SIGNAL(currentIndexChanged(int)), this, SLOT(changeStatus(int))); connect(ui->actionShow_Log, SIGNAL(toggled(bool)), this, SLOT(setLogConsoleDisabled(bool))); connect(ui->actionShow_Network, SIGNAL(toggled(bool)), this, SLOT(onToggleLog(bool))); connect(ui->actionShow_Chat, SIGNAL(toggled(bool)), this, SLOT(onToggleLog(bool))); connect(ui->actionShow_Terminal, SIGNAL(toggled(bool)), this, SLOT(onToggleLog(bool))); connect(ui->actionShow_Normal, SIGNAL(toggled(bool)), this, SLOT(onToggleLog(bool))); connect(ui->actionShow_Error, SIGNAL(toggled(bool)), this, SLOT(onToggleLog(bool))); connect(ui->actionAbout_pvs, SIGNAL(triggered()), _aboutDialog, SLOT(open())); connect(ui->actionSave_Profile, SIGNAL(triggered()), _profileDialog, SLOT(save())); #endif loadSettings(); //we load the appliocation settings setUnifiedTitleAndToolBarOnMac(true); #ifdef MAINWINDOW_USE_NORMALGUI statusBar()->showMessage(tr("The pvs manager")); #endif this->showMaximized(); // show the Mainwindow maximized // listen on port 29481 for incoming file transfers _serverSocket = new QTcpServer(); _serverSocket->listen(QHostAddress::Any, 29481); connect(_serverSocket, SIGNAL(newConnection()), this, SLOT(incomingFile())); #ifdef MAINWINDOW_USE_TOUCHGUI // Setup Help Dialog QWidget *_helpDialog = new QWidget; QWebView *helpView = new QWebView; helpView->load(QUrl("qrc:/help/pvsmgr_de_DE.html")); QPushButton *exitButton = new QPushButton("Exit"); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(helpView); layout->addWidget(exitButton); _helpDialog->setLayout(layout); connect(ui->action_Howto, SIGNAL(triggered()), _helpDialog, SLOT(show())); connect(exitButton, SIGNAL(clicked()), _helpDialog, SLOT(close())); #endif } MainWindow::~MainWindow() { delete ui; } /* * This signal is received when the mainwindow is going to be closed. * We have to check if the the chat-dialog is open. In this case we close * this dialog and accept the event, the rest will be execute from Qt. * Qt will be call the destroyer ~MainWindow(). */ void MainWindow::closeEvent(QCloseEvent *e) { if (sChatDialog.isVisible()) sChatDialog.close(); e->accept(); } MainWindow* MainWindow::getWindow() // catches the window { if (myself) { return myself; } else { return myself = new MainWindow; } } ConnectionWindow* MainWindow::getConnectionWindow() // catches the ConnectionWindow { if (conWin) { return conWin; } else { conWin = new ConnectionWindow; return conWin; } } ConnectionList* MainWindow::getConnectionList() // catches the ConnectionList { if (conList) return conList; else { conList = new ConnectionList; return conList; } } int MainWindow::getConnectionWindowWidth() // returns the width of the ConnectionWindow { return ui->widget->width(); } int MainWindow::getConnectionWindowHeight() // returns the height of the CoonectionWindow { return ui->widget->height(); } QStringList MainWindow::getProfilList() // loads the profile list { QSettings settings("openslx", "profiles"); profilList = settings.childGroups(); return profilList; } void MainWindow::loadSettings() { QSettings settings("openslx", "profiles"); QString current = settings.value("current", "default").toString(); currentProfi = current; _profilName = current; //When no profile is available, we define a default one whith 9 dummy screens if (current.compare("default") == 0) { setWindowTitle("PVSmgr - Default"); // QPoint pos1 = settings.value("default/1", QPoint(0, 0)).toPoint(); // MainWindow::getConnectionWindow()->addFrameBySettings("1", pos1); // QPoint pos2 = settings.value("default/2", QPoint(194, 0)).toPoint(); // MainWindow::getConnectionWindow()->addFrameBySettings("2", pos2); // QPoint pos3 = settings.value("default/3", QPoint(388, 0)).toPoint(); // MainWindow::getConnectionWindow()->addFrameBySettings("3", pos3); // QPoint pos4 = settings.value("default/4", QPoint(582, 0)).toPoint(); // MainWindow::getConnectionWindow()->addFrameBySettings("4", pos4); // QPoint pos5 = settings.value("default/5", QPoint(0, 173)).toPoint(); // MainWindow::getConnectionWindow()->addFrameBySettings("5", pos5); // QPoint pos6 = settings.value("default/6", QPoint(194, 173)).toPoint(); // MainWindow::getConnectionWindow()->addFrameBySettings("6", pos6); // QPoint pos7 = settings.value("default/7", QPoint(388, 173)).toPoint(); // MainWindow::getConnectionWindow()->addFrameBySettings("7", pos7); // QPoint pos8 = settings.value("default/8", QPoint(582, 173)).toPoint(); // MainWindow::getConnectionWindow()->addFrameBySettings("8", pos8); // QPoint pos9 = settings.value("default/9", QPoint(293, 346)).toPoint(); // MainWindow::getConnectionWindow()->addFrameBySettings("9", pos9); QString title = "PVSmgr - "; title.append(_profilName); title.append(" [" + _sessionName + " : "); title.append(_pwdCon + "]"); setWindowTitle(title); _info = title; } else { QString title = "PVSmgr - "; title.append(_profilName); title.append(" [" + _sessionName + " : "); title.append(_pwdCon + "]"); setWindowTitle(title); _info = title; settings.beginGroup(current); QStringList keys = settings.childKeys(); for (int i = 0; i < keys.size(); i++) { QString profil = current; profil = profil.append("/").append(keys.at(i)); QPoint pos = settings.value(keys.at(i)).toPoint(); MainWindow::getConnectionWindow()->addFrameBySettings(keys.at(i), pos); } } MainWindow::getConnectionWindow()->showFrameFromSettings(); } void MainWindow::loadProfile(QAction* actiontriggered) { QString profilename = actiontriggered->text(); loadSettings(profilename); } void MainWindow::loadSettings(QString profilname) // loads the current profile { QList AllFrameOnWindow = MainWindow::getConnectionWindow()->getAllFrameOnWindow(); if (AllFrameOnWindow.size() > 0) { _profilName = profilname; MainWindow::getConnectionWindow()->ClientLocationList.clear(); QSettings settings("openslx", "profiles"); settings.setValue("current", _profilName); ConnectionFrame* cFrame; foreach (cFrame, AllFrameOnWindow) { if (cFrame->isDummy()) { AllFrameOnWindow.removeOne(cFrame); MainWindow::getConnectionWindow()->removeFromList(cFrame); cFrame->deleteLater(); } } settings.beginGroup(_profilName); QStringList keys = settings.childKeys(); int rest = AllFrameOnWindow.size(); int init = 1; for (int i = 0; i < keys.size(); i++) { if (init <= rest) { ConnectionFrame* cF = AllFrameOnWindow.at(i); QString profil = _profilName; profil = profil.append("/").append(cF->getTaskbarTitle()); if (!cF->isDummy()) cF->move(settings.value(keys.at(i)).toPoint()); else cF->move( settings.value(profil, QPoint(10, (10 + (5 * i)))).toPoint()); init += 1; } else { MainWindow::getConnectionWindow()->addFrameBySettings( keys.at(i), settings.value(keys.at(i)).toPoint()); } } MainWindow::getConnectionWindow()->showFrameFromSettings(); QString title = "PVSmgr - "; title.append(_profilName); title.append(" [" + _sessionName + " : "); title.append(_pwdCon + "]"); setWindowTitle(title); _info = title; } } void MainWindow::saveSettings(QString profilname) { QList AllFrameOnWindow = MainWindow::getConnectionWindow()->getAllFrameOnWindow(); QSettings settings("openslx", "profiles"); settings.setValue("current", profilname); settings.setValue("size", QString("%1").arg(AllFrameOnWindow.size())); for (int i = 0; i < AllFrameOnWindow.size(); i++) { ConnectionFrame* current = AllFrameOnWindow.at(i); QString profil = ""; profil = settings.value("current").toString().append("/"); if (!current->isDummy()) profil.append(QString(current->getTaskbarTitle())); else profil.append(QString("%1").arg(i + 1)); settings.setValue(profil, current->pos()); } } void MainWindow::removeProfil(QString profilname) { QSettings settings("openslx", "profiles"); settings.remove(profilname); } void MainWindow::addConnection(PVSClient* newCon) { conWin->addConnection(newCon); if (!_chatListClients.contains(newCon->getUserName())) { _chatListClients.append(newCon->getUserName()); sChatDialog.chat_client_add(newCon->getUserName()); sChatDialog.chat_nicklist_update(); } // sChatDialog->chat_nicklist_update(newCon->getUserName()); _profileDialog->load(); } void MainWindow::removeConnection(PVSClient* newCon) { conWin->removeConnection(newCon); if (_chatListClients.contains(newCon->getUserName())) { _chatListClients.removeOne(newCon->getUserName()); sChatDialog.chat_client_remove(newCon->getUserName()); sChatDialog.chat_nicklist_update(); } } void MainWindow::onConnectionFailed(QString host) { #ifdef never // code is voided because the info-management will be overhauled sometime if (pwDiag) // assume this thing failed after the pw-question... so a wrong password, ey? { onPasswordFailed(host); return; } QString caption, secondary; if (host != "") { caption = ("PVSConnection with hostname \""); caption.append(host); caption.append("\" failed."); secondary = "PVSConnection attempt for this hostname failed.Maybe the host is not prepared to accept vnc connections. Please make sure hostname and (if needed) password are correct."; } else { caption = "No IP given"; secondary = "PVSConnection attempt for this host failed. There was either no or an errorous Hostname given."; } QMessageBox::information(*this, caption, secondary); /* Gtk::MessageDialog dialog(*this, Glib::ustring(caption)); dialog.set_secondary_text(secondary); dialog.run();*/ #endif } void MainWindow::onConnectionTerminated(PVSClient* newConnection) { #ifdef never // code is voided because the info-management will be overhauled sometime QString host; if (newConnection) { host = newConnection->getIp(); // copy hostname for message } else host = "spooky unknown"; // now inform QString caption, secondary; caption = "Hostname \""; caption.append(host); caption.append("\" terminated connection."); secondary = "The server has closed the connection to your client."; QMessageBox::information(*this, caption, secondary); /*Gtk::MessageDialog dialog(*this, Glib::ustring(caption)); dialog.set_secondary_text(secondary); dialog.run();*/ #endif } void MainWindow::onConnectionRemoved(PVSClient* newConnection) { // TODO this would be the place to handle the rest of the fullscreen issue conWin->onConnectionRemoved(newConnection); } void MainWindow::onPasswordFailed(QString Qhost) { #ifdef never // code is voided because the info-management will be overhauled sometime QString caption, secondary; if (Qhost != "") { caption = "Hostname \""; caption.append(Qhost); caption.append("\" refused password."); secondary = "You have entered no or a wrong password."; } else return; // unknown connection was terminated? too spooky QMessageBox::information(*this, caption, secondary); /* Gtk::MessageDialog dialog(*this, Glib::ustring(caption)); dialog.set_secondary_text(secondary); Gtk::Main::run(dialog);*/ #endif } void MainWindow::sendChatMsg(PVSMsg myMsg) { PVSConnectionManager::getManager()->onChat(myMsg); } void MainWindow::receiveChatMsg(QString nick_from, QString nick_to, QString msg) { sChatDialog.chat_receive(nick_from, nick_to, msg); } int MainWindow::getPrevWidth() // PVSConnectionManager::getManager()->getPrevWidth() { return prev_width; } void MainWindow::setPrevWidth(int newWidth) { if (newWidth > 100) prev_width = newWidth; else prev_width = 100; } int MainWindow::getPrevHeight() { return prev_height; } void MainWindow::setPrevHeight(int newHeight) { if (newHeight > 100) prev_height = newHeight; else prev_height = 100; } void MainWindow::changeEvent(QEvent *e) { QMainWindow::changeEvent(e); switch (e->type()) { case QEvent::LanguageChange: ui->retranslateUi(this); break; default: break; } } /* * The resize Event is called when the mainwindow is resized! * Whe need this event to resize the Frame on the Connectionwindow. * The Frames are resized proportionally to the new size of the mainwindow. * But this Function is called by Qt 3 times before the whole * mainwdow is constructed. We can only resize the Frame on Window and * get the initial size of the Connectionwindow after this 3 times. */ void MainWindow::resizeEvent(QResizeEvent *event) { if (bgimage == true) repaintbackgroundpicture(); // repaint the backgroundpicture scaled to the window size } void MainWindow::updatePos(ConnectionFrame* cf, int x, int y) { int posx = (x * cf->pos().x()) / _initW; int posy = (y * cf->pos().y()) / _initH; cf->move(posx, posy); /*QSize size = cf->sizeHint(); cf->setGeometry(x - size.rwidth(), y - size.rheight(), size.rwidth(), size.rheight());*/ } void MainWindow::on_log_line(LogEntry consoleEntry) { ConsoleLogger::LOG_LEVEL level = consoleEntry.getLevel(); if (level == ConsoleLogger::LOG_ERROR && !showError) return; if (level == ConsoleLogger::LOG_NORMAL && !showNormal) return; if (level == ConsoleLogger::LOG_NETWORK && !showNetwork) return; if (level == ConsoleLogger::LOG_TERMINAL && !showTerminal) return; if (level == ConsoleLogger::LOG_CHAT && !showChat) return; #ifdef MAINWINDOW_USE_NORMALGUI ui->pvsLog->insertPlainText(consoleEntry.getLine()); #endif } void MainWindow::onToggleLog(bool showtime) { if (showtime) ;//to kill the system warning due "unused variable" #ifdef MAINWINDOW_USE_NORMALGUI showError = ui->actionShow_Error->isChecked(); showTerminal = ui->actionShow_Terminal->isChecked(); showNetwork = ui->actionShow_Network->isChecked(); showChat = ui->actionShow_Chat->isChecked(); showNormal = ui->actionShow_Normal->isChecked(); #endif //showAtAll = ui->logAtAllAction->get_active(); ConsoleLog dump2Listener(this, &MainWindow::on_log_line); } void MainWindow::setLogConsoleDisabled(bool visible) { #ifdef MAINWINDOW_USE_NORMALGUI if (!visible) ui->pvsLog->hide(); else ui->pvsLog->show(); #endif } /*void MainWindow::close() { //sChatDialog.close(); QApplication::closeAllWindows(); }*/ void MainWindow::disconnect() { conWin->removeVNC(); } void MainWindow::lockUnlockAll() { if (_isLockAll) { //ui->actionLock set icon to unlock MainWindow::getConnectionWindow()->unlockAllStations(); _isLockAll = false; } else { //ui->actionLock set icon to lock MainWindow::getConnectionWindow()->lockAllStations(); _isLockAll = true; //tell the manager all the clients are locked } } void MainWindow::closeUp() { std::list* selectedClients = MainWindow::getConnectionList()->getSelectedClients(); if(selectedClients->size() != 1) // Cannot closeUp zero or more than one frames. return; PVSClient* pvsClient = PVSConnectionManager::getManager()->getClientFromIp(selectedClients->front()); closeUp(pvsClient->getConnectionFrame(), pvsClient); } void MainWindow::closeUp(ConnectionFrame* connFrame, PVSClient* pvsClient) { std::list* selectedClients = MainWindow::getConnectionList()->getSelectedClients(); if(selectedClients->size() != 1) // Cannot closeUp zero or more than one frames. return; if(!pvsClient) pvsClient = connFrame->getConnection(); // Do we already have a closeUp Frame? ConnectionFrame* closeupFrame = conWin->getCloseupFrame(); if(closeupFrame) { unCloseUp(closeupFrame); return; } _framePosOnCloseUp = connFrame->pos();//get the actualy position before run closeup if (pvsClient->getVNCConnection()) { conWin->setCloseupFrame(connFrame); _updatefreq = connFrame->getFrame()->getVNCClientThread()->getUpdatefreq(); connFrame->getFrame()->getVNCClientThread()->setUpdatefreq( 50); connFrame->move(5, 5); connFrame->setWindowFlags(Qt::WindowStaysOnTopHint); connFrame->raise(); connFrame->paintCloseUp(ui->widget->width(), ui->widget->height()); conWin->setCloseupFrame(connFrame); Frame* frame = connFrame->getFrame(); if(frame) frame->setCloseUp(true); } } void MainWindow::unCloseUp(ConnectionFrame* connFrame) { if(!connFrame) return; connFrame->setWindowFlags(Qt::Widget); connFrame->paintCloseUp( connFrame->getPrevWidth(), connFrame->getPrevHeight()); connFrame->move(_framePosOnCloseUp);//back to the position before the closeup if (connFrame->getConnection()->getVNCConnection()) connFrame->getFrame()->getVNCClientThread()->setUpdatefreq(_updatefreq); Frame* frame = connFrame->getFrame(); if(frame) frame->setCloseUp(false); conWin->setCloseupFrame(NULL); } // Perform some action if actionShowProcesses button was pressed void MainWindow::showProcesses() { if (PVSConnectionManager::getManager()->getConnections().size() > 0) { ProcessDialog procShowDialog(0,displayedClientNameEnum); procShowDialog.exec(); } } // Perform some action if actionStartProcess button was pressed void MainWindow::startProcess() { std::list* selectedClients = MainWindow::getConnectionList()->getSelectedClients(); if (selectedClients->size() >= 1) { ProcessesStartDialog procStartDialog; procToStart = ""; int result = procStartDialog.exec(); if (result == 1) //if result == 1 we clicked send on our button then //procToStart is set to the text that was given in our messageEdit { std::list::iterator itSelected; for (itSelected = selectedClients->begin(); itSelected != selectedClients->end(); itSelected++) { std::list listAll = PVSConnectionManager::getManager()->getConnections(); for (std::list::iterator itAll = listAll.begin(); itAll != listAll.end(); itAll++) { if ((*itSelected) == (*itAll)->getIp()) { (*itAll)->sendMessage(PVSCOMMAND, "STARTPROCESS", procToStart); break; } } } } } else { QString message = QString( tr( "This operation can only be performed if you have selected at least one Client!")); QMessageBox::information(this, "PVS", message); } } void MainWindow::foto() // makes a screenshot of the selected client { std::list* selectedClients = MainWindow::getConnectionList()->getSelectedClients(); if (selectedClients->size() > 0) { QString format = "png"; for (std::list::iterator tmpIt = selectedClients->begin(); tmpIt != selectedClients->end(); tmpIt++) { QString path = QDir::homePath().append("/").append(*tmpIt).append( ".png"); PVSClient * pvsClient = PVSConnectionManager::getManager()->getClientFromIp( (*tmpIt).toUtf8().data()); if (pvsClient->getVNCConnection()) { const QImage img = pvsClient->getConnectionFrame()->getFrame()->getImageForFoto(); if (!img.isNull()) img.save(path, format.toAscii()); } else qDebug("Cannot save screen: Image is null."); } } else { QString message = QString( tr( "This operation can only be performed for at least one selected Client!")); QMessageBox::information(this, "PVS", message); } } void MainWindow::createProfile() { _profileDialog->exec(); } void MainWindow::showusername() { displayedClientNameEnum = 2; MainWindow::getConnectionList()->setColumnHidden(2, false); MainWindow::getConnectionList()->setColumnHidden(0, true); MainWindow::getConnectionList()->setColumnHidden(1, true); } void MainWindow::showname() { displayedClientNameEnum = 0; MainWindow::getConnectionList()->setColumnHidden(0, false); MainWindow::getConnectionList()->setColumnHidden(1, true); MainWindow::getConnectionList()->setColumnHidden(2, true); } void MainWindow::showip() { displayedClientNameEnum = 1; MainWindow::getConnectionList()->setColumnHidden(1, false); MainWindow::getConnectionList()->setColumnHidden(2, true); MainWindow::getConnectionList()->setColumnHidden(0, true); } void MainWindow::incomingFile() { QTcpSocket *socket = _serverSocket->nextPendingConnection(); ServerFileTransfert* sft = new ServerFileTransfert(this); sft->receiveFileFromHost(socket); } void MainWindow::changeRatio(int ratio) // needed the change the size of the vnc-screens { if (!_isThumbnailrate) { #ifdef MAINWINDOW_USE_NORMALGUI QString str; str.append(QString("%1").arg(ratio)); ui->label_2->setText(str); #endif QList clients = MainWindow::getConnectionWindow()->getAllFrameOnWindow(); foreach (ConnectionFrame *client, clients) { int w = (client->init_w * ratio) / 100; int h = (client->init_h * ratio) / 100; client->setPrevWidth(w); client->setPrevHeight(h); client->paintCloseUp(w, h); client->setRatio(ratio); } } else changeRefresh(ratio); } void MainWindow::changeRefresh(int refresh) { int updatefreq = (refresh*500)/100; #ifdef MAINWINDOW_USE_NORMALGUI QString str; str.append(QString("%1").arg(updatefreq)); ui->label_2->setText(str); #endif std::list clients = PVSConnectionManager::getManager()->getConnections(); foreach (PVSClient* client, clients) { if (client->getVNCConnection()) client->getConnectionFrame()->getFrame()->getVNCClientThread()->setUpdatefreq(updatefreq); } } /* * We can change the status for the action that we want to assign to the thumbnails. * The actions are to be perform over the horizontalslider from QSlider only on the not dummies clients. * The dummies clients aren't involved. * We distingue two status: * -Thumbnailratio:hier we can change the ratio of the thumbnails. * -Thumbnailrate:we change the rate of the VNCClientThread of the frames. These actions are perform on the selected clients. * If no clients are selected, we change the ratio of the whole clients on the clientlist * */ void MainWindow::changeStatus(int index) { #ifdef MAINWINDOW_USE_NORMALGUI QString status = ui->thumbStatus->currentText(); if (status == "Thumbnailratio") { _isThumbnailrate = false; ui->label_3->setText("%"); std::list* selClients = getConnectionList()->getSelectedClients(); if (selClients->size() == 1) { PVSClient* pvsClient = PVSConnectionManager::getManager()->getClientFromIp( selClients->front().toStdString().c_str()); int ratio = pvsClient->getConnectionFrame()->getRatio(); ui->label_2->setText(QString::number(ratio)); ui->horizontalSlider->setValue(ratio); } else { ui->label_2->setText("100"); ui->horizontalSlider->setValue(100); } } else if (status == "Thumbnailrate") { _isThumbnailrate = true; ui->label_3->setText("ms"); std::list* selClients = getConnectionList()->getSelectedClients(); if (selClients->size() == 1) { PVSClient* pvsClient = PVSConnectionManager::getManager()->getClientFromIp( selClients->front().toStdString().c_str()); if (pvsClient->getVNCConnection()) { int updatefreq = pvsClient->getConnectionFrame()->getFrame()->getVNCClientThread()->getUpdatefreq(); int showfreq = (updatefreq * 100) / 500; ui->label_2->setText(QString::number(updatefreq)); ui->horizontalSlider->setValue(showfreq); } } else { ui->label_2->setText("500"); ui->horizontalSlider->setValue(100); } } #endif } /* * Going to run a new vncthread with quality: quality */ void MainWindow::setVNCQuality(int quality) { QList FrameList = MainWindow::getConnectionWindow()->getFrameList(); foreach (ConnectionFrame* frame, FrameList) { frame->resetConnectionWithQuality(quality); frame->update(); } } void MainWindow::setPasswordForConnection(bool enabled) { if (enabled) setPasswordForConnection(2); else setPasswordForConnection(0); } void MainWindow::setPasswordForConnection(int enabled) { if (enabled == 0)//the checkbox isn't checked, so no passowrd needed, we remove it in the titlebar { QString dummy = PVSConnectionManager::getManager()->setNeedPassword( false); _sessionName = PVSConnectionManager::getManager()->getSessionName(); QString title = "PVSmgr - "; title.append(_profilName); title.append(" [" + _sessionName + " : ]"); setWindowTitle(title); _info = title; } else if (enabled == 2) //password is needed, we show it in the titlebar { _pwdCon = PVSConnectionManager::getManager()->setNeedPassword(true); _sessionName = PVSConnectionManager::getManager()->getSessionName(); QString title = "PVSmgr - "; title.append(_profilName); title.append(" [" + _sessionName + " : "); title.append(_pwdCon + "]"); setWindowTitle(title); _info = title; } } //#endif void MainWindow::setindexback() //sets the index of the combobox back { // TODO: delete this } void MainWindow::clientlisthide() // hide or show the clientlist { #ifdef MAINWINDOW_USE_NORMALGUI if (locked1 == false) { ui->ClWidget->show(); locked1 = true; } else { ui->ClWidget->hide(); locked1 = false; } #endif } void MainWindow::lockalltoolbar() // locks all if a dozent is set { if (locked == false) { if (MainWindow::getConnectionWindow()->hasDozent) { MainWindow::getConnectionList()->on_lock_all(); locked = true; } else { QString message = QString( tr( "You have to set a Superclient-machine before performing this action.")); QMessageBox::information(this, "PVS", message); } } else { MainWindow::getConnectionList()->on_unlock_all(); locked = false; } } void MainWindow::locksingle() // locks a single client { MainWindow::getConnectionList()->on_lock(); } void MainWindow::unlocksingle() // unlocks a single client { MainWindow::getConnectionList()->on_unlock(); } void MainWindow::combobox1(int menuindex1) // defines the functions to call from the combobox { switch (menuindex1) // index comes from the slot definition { case 1: // Lock all MainWindow::getConnectionList()->on_lock_all(); break; case 2: // UnLock all MainWindow::getConnectionList()->on_unlock_all(); break; case 3: // UnProject all MainWindow::getConnectionList()->on_unproject_all(); break; case 4: //Background Picture backgroundpicture(); break; } } void MainWindow::resetall() // unlock and unproject all in toolbar { MainWindow::getConnectionList()->on_unlock_all(); MainWindow::getConnectionList()->on_unproject_all(); } void MainWindow::projecttoolbar() // projection from toolbar button { MainWindow::getConnectionList()->on_projection(); } void MainWindow::unprojecttoolbar() // unproject all in toolbar { MainWindow::getConnectionList()->on_unprojection(); } void MainWindow::backgroundpicture() { fileName = QFileDialog::getOpenFileName(this, tr("Open Image"), QDir::homePath(), tr("Image Files (*.png *.jpg *.svg)")); // user chooses a file QImage img(fileName); // set image QImage img2 = img.scaled(ui->widget->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); // scale it QString tmp("/tmp/tmp.png"); // set path for saving the scaled picture img2.save(tmp); // save it ui->widget->setStyleSheet("QWidget#widget {background-image: url(/tmp/tmp.png);" "background-repeat:no-repeat; background-position:center;}"); //set the picture as background bgimage = true; // for the resize event, set background true } void MainWindow::repaintbackgroundpicture() // same as backgroundpicture but called when mainwindow is resized { QImage img("/tmp/tmp.png"); QString tmp("/tmp/tmp.png"); QImage img2 = img.scaled(ui->widget->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); img2.save(tmp); ui->widget->setStyleSheet("QWidget#widget {background-image: url(/tmp/tmp.png);" "background-repeat:no-repeat; background-position:center;}"); //set the picture as background } void MainWindow::setdozenttoolbar() // set the dozents pc which is not locked with lockedall { std::list* selectedClients = MainWindow::getConnectionList()->getSelectedClients(); if (selectedClients->size() == 1) { PVSClient* pvsClient = PVSConnectionManager::getManager()->getClientFromIp( selectedClients->front().toStdString().c_str()); if (pvsClient->getVNCConnection()) pvsClient->getConnectionFrame()->getFrame()->setDozent(); } } void MainWindow::startChatDialog() { if (!sChatDialog.isVisible()) sChatDialog.show(); //show the chat dialog else sChatDialog.raise();//show the chat dialog on top level } void MainWindow::configureNetwork() { PVSServer* server = PVSConnectionManager::getManager()->getServer(); McastConfiguration mc(*(server->getMulticastConfiguration())); MulticastConfigDialog* mcd = new MulticastConfigDialog(&mc, this); int result = mcd->exec(); if(result == QDialog::Accepted) { server->multicastReconfigure(&mc); } } int MainWindow::getDisplayedClientNameEnum() { return displayedClientNameEnum; } void MainWindow::info() { QMessageBox::information(this, tr("Information"), _info); } MainWindow* MainWindow::myself = NULL; ConnectionList* MainWindow::conList = NULL; ConnectionWindow* MainWindow::conWin = NULL; bool MainWindow::_isLockAll = false;