From a98536b9fbda7d7fb2ff78906c1a2d6331f33df2 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Wed, 15 Nov 2017 10:05:29 +0100 Subject: port to qt5 * got rid of the Win32/X11 differentiation * due to QT5, additional packages are needed to compile ** libqt5x11extras5-dev ** libqt5svg5-dev --- CMakeLists.txt | 93 ++++++++++--------- src/client/connectwindow/connectwindow.h | 2 +- src/client/toolbar/toolbar.h | 2 +- src/client/util/platform/blankscreen.cpp | 100 +++++++++++++++++++++ src/client/util/platform/blankscreen_Win32.cpp | 41 --------- src/client/util/platform/blankscreen_X11.cpp | 100 --------------------- src/client/vnc/vncwindow.h | 2 +- src/server/clicklabel/clicklabel.h | 2 +- src/server/connectionframe/connectionframe.h | 2 +- src/server/mainwindow/mainwindow.cpp | 2 +- src/server/mainwindow/mainwindow.h | 2 +- src/server/sessionnamewindow/sessionnamewindow.cpp | 2 +- src/server/sessionnamewindow/sessionnamewindow.h | 2 +- src/server/util/platform/screensaver.cpp | 74 +++++++++++++++ src/server/util/platform/screensaver_X11.cpp | 74 --------------- 15 files changed, 235 insertions(+), 265 deletions(-) create mode 100644 src/client/util/platform/blankscreen.cpp delete mode 100644 src/client/util/platform/blankscreen_Win32.cpp delete mode 100644 src/client/util/platform/blankscreen_X11.cpp create mode 100644 src/server/util/platform/screensaver.cpp delete mode 100644 src/server/util/platform/screensaver_X11.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index adcaa9f..23da4de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,10 +17,15 @@ SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -std=c++0x" ) SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) # this command finds libraries and sets all required variables -FIND_PACKAGE(Qt4 4.7.0 REQUIRED) +FIND_PACKAGE(Qt5 COMPONENTS Widgets Network X11Extras LinguistTools Svg REQUIRED) FIND_PACKAGE(X11 REQUIRED) FIND_PACKAGE(VNC REQUIRED) +SET(CMAKE_AUTOMOC ON) +SET(CMAKE_AUTORCC ON) +SET(CMAKE_AUTOUIC ON) +SET(CMAKE_AUTOUIC_SEARCH_PATHS gui/server_normal gui/client) + # some includes INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR} @@ -45,7 +50,7 @@ ENDIF() #ENDIF() # TODO: Detect this somehow -SET(SYSDEP_SUFFIX _X11) +#SET(SYSDEP_SUFFIX _X11) ################################################################################ # Variables @@ -55,7 +60,7 @@ SET(SYSDEP_SUFFIX _X11) FILE(GLOB PVSMGR_SRCS src/server/*.cpp src/server/*/*.cpp - src/server/util/platform/*${SYSDEP_SUFFIX}.cpp + src/server/util/platform/*.cpp src/shared/*.cpp ) @@ -63,7 +68,7 @@ FILE(GLOB PVSMGR_SRCS FILE(GLOB PVSCLIENT_SRCS src/client/*.cpp src/client/*/*.cpp - src/client/util/platform/*${SYSDEP_SUFFIX}.cpp + src/client/util/platform/*.cpp src/shared/*.cpp ) @@ -73,28 +78,28 @@ FILE(GLOB PVSCLIENT_SRCS ################################################################################ # .ui files -FILE(GLOB PVSMGR_UIS - gui/server_normal/*.ui -) +#FILE(GLOB PVSMGR_UIS +# gui/server_normal/*.ui +#) -FILE(GLOB PVSCLIENT_UIS - gui/client/*.ui -) +#FILE(GLOB PVSCLIENT_UIS +# gui/client/*.ui +#) # .qrc files SET(PVSMGR_RCS pvsmgr.qrc) SET(PVSCLIENT_RCS pvsclient.qrc) # includes all header files that should be treated with moc -FILE(GLOB PVSMGR_MOC_HDRS - src/server/*/*.h -) +#FILE(GLOB PVSMGR_MOC_HDRS +# src/server/*/*.h +#) -FILE(GLOB PVSCLIENT_MOC_HDRS - src/client/*.h - src/client/*/*.h - src/client/*/*/*.h -) +#FILE(GLOB PVSCLIENT_MOC_HDRS +# src/client/*.h +# src/client/*/*.h +# src/client/*/*/*.h +#) # i18n FILE(GLOB PVSMGR_TSS @@ -108,42 +113,42 @@ FILE(GLOB PVSCLIENT_TSS # include Qt modules #SET(QT_USE_QTDBUS TRUE) -SET(QT_USE_QTNETWORK TRUE) -SET(QT_USE_QTSVG TRUE) +#SET(QT_USE_QTNETWORK TRUE) +#SET(QT_USE_QTSVG TRUE) #SET(QT_USE_QTWEBKIT TRUE) # add some useful macros and variables # (QT_USE_FILE is a variable defined by FIND_PACKAGE( Qt4 ) that contains # a path to CMake script) -INCLUDE(${QT_USE_FILE}) +#INCLUDE(${QT_USE_FILE}) # this will run rcc on .qrc files -QT4_ADD_RESOURCES(PVSMGR_RC_SRCS ${PVSMGR_RCS}) -QT4_ADD_RESOURCES(PVSCLIENT_RC_SRCS ${PVSCLIENT_RCS}) +#QT4_ADD_RESOURCES(PVSMGR_RC_SRCS ${PVSMGR_RCS}) +#QT4_ADD_RESOURCES(PVSCLIENT_RC_SRCS ${PVSCLIENT_RCS}) # this will run uic on .ui files -QT4_WRAP_UI(PVSMGR_UI_HDRS ${PVSMGR_UIS}) -QT4_WRAP_UI(PVSCLIENT_UI_HDRS ${PVSCLIENT_UIS}) +#QT4_WRAP_UI(PVSMGR_UI_HDRS ${PVSMGR_UIS}) +#QT4_WRAP_UI(PVSCLIENT_UI_HDRS ${PVSCLIENT_UIS}) # this will run moc -QT4_WRAP_CPP(PVSMGR_MOC_SRCS ${PVSMGR_MOC_HDRS}) -QT4_WRAP_CPP(PVSCLIENT_MOC_SRCS ${PVSCLIENT_MOC_HDRS}) +#QT4_WRAP_CPP(PVSMGR_MOC_SRCS ${PVSMGR_MOC_HDRS}) +#QT4_WRAP_CPP(PVSCLIENT_MOC_SRCS ${PVSCLIENT_MOC_HDRS}) option(UPDATE_TRANSLATIONS "Update .ts files (WARNING: make clean will delete the .ts files!)") if(PVSMGR_TSS) if (UPDATE_TRANSLATIONS) - QT4_CREATE_TRANSLATION(PVSMGR_QMS ${PVSMGR_SRCS} ${PVSMGR_UI_HDRS} ${PVSMGR_TSS} OPTIONS -noobsolete) + QT5_CREATE_TRANSLATION(PVSMGR_QMS ${PVSMGR_SRCS} ${PVSMGR_UI_HDRS} ${PVSMGR_TSS} OPTIONS -noobsolete) message(STATUS ".tr files have been updated") else (UPDATE_TRANSLATIONS) - QT4_ADD_TRANSLATION(PVSMGR_QMS ${PVSMGR_TSS}) + QT5_ADD_TRANSLATION(PVSMGR_QMS ${PVSMGR_TSS}) endif (UPDATE_TRANSLATIONS) endif(PVSMGR_TSS) if(PVSCLIENT_TSS) if (UPDATE_TRANSLATIONS) - QT4_CREATE_TRANSLATION(PVSCLIENT_QMS ${PVSCLIENT_SRCS} ${PVSCLIENT_UI_HDRS} ${PVSCLIENT_TSS} OPTIONS -noobsolete) + QT5_CREATE_TRANSLATION(PVSCLIENT_QMS ${PVSCLIENT_SRCS} ${PVSCLIENT_UI_HDRS} ${PVSCLIENT_TSS} OPTIONS -noobsolete) message(STATUS ".tr files have been updated") else (UPDATE_TRANSLATIONS) - QT4_ADD_TRANSLATION(PVSCLIENT_QMS ${PVSCLIENT_TSS}) + QT5_ADD_TRANSLATION(PVSCLIENT_QMS ${PVSCLIENT_TSS}) endif (UPDATE_TRANSLATIONS) endif(PVSCLIENT_TSS) @@ -153,30 +158,36 @@ endif(PVSCLIENT_TSS) ADD_EXECUTABLE(pvsmgr ${PVSMGR_SRCS} - ${PVSMGR_MOC_SRCS} - ${PVSMGR_UI_HDRS} - ${PVSMGR_RC_SRCS} - ${PVSMGR_QMS} + ${PVSMGR_RCS} +# ${PVSMGR_MOC_SRCS} +# ${PVSMGR_UI_HDRS} +# ${PVSMGR_RC_SRCS} +# ${PVSMGR_QMS} ) ADD_EXECUTABLE(pvsclient ${PVSCLIENT_SRCS} - ${PVSCLIENT_MOC_SRCS} - ${PVSCLIENT_UI_HDRS} - ${PVSCLIENT_RC_SRCS} - ${PVSCLIENT_QMS} + ${PVSCLIENT_RCS} +# ${PVSCLIENT_MOC_SRCS} +# ${PVSCLIENT_UI_HDRS} +# ${PVSCLIENT_RC_SRCS} +# ${PVSCLIENT_QMS} ) # link TARGET_LINK_LIBRARIES(pvsmgr - ${QT_LIBRARIES} + Qt5::Network + Qt5::Widgets + Qt5::Svg + Qt5::X11Extras # ${VNC_LIBRARIES} ${X11_LIBRARIES} ${X11_Xscreensaver_LIB} ) TARGET_LINK_LIBRARIES(pvsclient - ${QT_LIBRARIES} + Qt5::Network + Qt5::Widgets ${VNC_LIBRARIES} ${X11_LIBRARIES} ) diff --git a/src/client/connectwindow/connectwindow.h b/src/client/connectwindow/connectwindow.h index 53af662..51b1bf2 100644 --- a/src/client/connectwindow/connectwindow.h +++ b/src/client/connectwindow/connectwindow.h @@ -16,7 +16,7 @@ #ifndef PVSCONNECTWINDOW_H_ #define PVSCONNECTWINDOW_H_ -#include +#include #include #include #include diff --git a/src/client/toolbar/toolbar.h b/src/client/toolbar/toolbar.h index 47f385c..347871f 100644 --- a/src/client/toolbar/toolbar.h +++ b/src/client/toolbar/toolbar.h @@ -14,7 +14,7 @@ #ifndef PVSCLIENTGUI_H_ #define PVSCLIENTGUI_H_ -#include +#include #include "../util/room.h" class ServerConnection; diff --git a/src/client/util/platform/blankscreen.cpp b/src/client/util/platform/blankscreen.cpp new file mode 100644 index 0000000..ee644ca --- /dev/null +++ b/src/client/util/platform/blankscreen.cpp @@ -0,0 +1,100 @@ + +#include "blankscreen.h" + +#include +#include +#include +#include + +#include +#include + +#include +#include + +struct BlankScreen_Sysdep { + Display *dpy; +}; + +BlankScreen::BlankScreen() : QDialog(NULL) +{ + _sysdep = new BlankScreen_Sysdep; + _sysdep->dpy = XOpenDisplay(NULL); + if (_sysdep->dpy == NULL) + return; + + setWindowFlags(Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint); + setStyleSheet("background-color:#000"); + + _locked = false; + QTimer *upper = new QTimer(this); + connect(upper, SIGNAL(timeout()), this, SLOT(timer_moveToTop())); + upper->start(1111); +} + +BlankScreen::~BlankScreen() +{ + unlock(); + if (_sysdep->dpy != NULL) { + XCloseDisplay(_sysdep->dpy); + } + delete _sysdep; +} + +bool BlankScreen::lock(const QString& message) +{ + if (_locked) + return true; + if (_sysdep->dpy == NULL) + return false; + + _message = message; + + this->setGeometry(QApplication::desktop()->geometry()); + this->showFullScreen(); + this->activateWindow(); + this->raise(); + + // grabbing of keyboard and mouse + XGrabKeyboard(_sysdep->dpy, DefaultRootWindow(_sysdep->dpy) , false, GrabModeAsync, GrabModeAsync, CurrentTime); + XGrabPointer(_sysdep->dpy, DefaultRootWindow(_sysdep->dpy) , false, 0, GrabModeAsync, GrabModeAsync, None, 0, CurrentTime); + + + QProcess ungrabP; + ungrabP.start("/bin/bash", QStringList() << "/opt/openslx/pvs2/kb-lock.sh"); + ungrabP.waitForFinished(); + + _locked = true; + return true; +} + +bool BlankScreen::unlock() +{ + this->hide(); + if (!_locked) + return true; + if (_sysdep->dpy == NULL) + return false; + + // ungrabbing of keyboard and mouse + XUngrabPointer(_sysdep->dpy, CurrentTime); + XUngrabKeyboard(_sysdep->dpy, CurrentTime); + + XFlush(_sysdep->dpy); + + /* start the kb-unlock.sh script */ + QProcess regrabP; + regrabP.start("/bin/bash", QStringList() << "/opt/openslx/pvs2/kb-unlock.sh"); + regrabP.waitForFinished(); + + _locked = false; + return true; +} + +void BlankScreen::timer_moveToTop() +{ + if (this->isHidden()) + return; + activateWindow(); + raise(); +} diff --git a/src/client/util/platform/blankscreen_Win32.cpp b/src/client/util/platform/blankscreen_Win32.cpp deleted file mode 100644 index 1d1dd12..0000000 --- a/src/client/util/platform/blankscreen_Win32.cpp +++ /dev/null @@ -1,41 +0,0 @@ - -#include "blankscreen.h" -#include - -struct BlankScreen_Sysdep { - - bool locked; - QWidget* blankwin; - - QString lockMsg; - int blackColor, whiteColor; - int offX, offY; -}; - -BlankScreen::BlankScreen() -{ - _sysdep = new BlankScreen_Sysdep; - _sysdep->blankwin = new QWidget(0, Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); - _sysdep->blankwin->setWindowState(Qt::WindowFullScreen); - _sysdep->blankwin->show(); -} - -BlankScreen::~BlankScreen() -{ - delete _sysdep; -} - -void BlankScreen::draw(bool force) -{ - -} - -bool BlankScreen::lock(const QString& message) -{ - return true; -} - -bool BlankScreen::unlock() -{ - return true; -} diff --git a/src/client/util/platform/blankscreen_X11.cpp b/src/client/util/platform/blankscreen_X11.cpp deleted file mode 100644 index ee644ca..0000000 --- a/src/client/util/platform/blankscreen_X11.cpp +++ /dev/null @@ -1,100 +0,0 @@ - -#include "blankscreen.h" - -#include -#include -#include -#include - -#include -#include - -#include -#include - -struct BlankScreen_Sysdep { - Display *dpy; -}; - -BlankScreen::BlankScreen() : QDialog(NULL) -{ - _sysdep = new BlankScreen_Sysdep; - _sysdep->dpy = XOpenDisplay(NULL); - if (_sysdep->dpy == NULL) - return; - - setWindowFlags(Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint); - setStyleSheet("background-color:#000"); - - _locked = false; - QTimer *upper = new QTimer(this); - connect(upper, SIGNAL(timeout()), this, SLOT(timer_moveToTop())); - upper->start(1111); -} - -BlankScreen::~BlankScreen() -{ - unlock(); - if (_sysdep->dpy != NULL) { - XCloseDisplay(_sysdep->dpy); - } - delete _sysdep; -} - -bool BlankScreen::lock(const QString& message) -{ - if (_locked) - return true; - if (_sysdep->dpy == NULL) - return false; - - _message = message; - - this->setGeometry(QApplication::desktop()->geometry()); - this->showFullScreen(); - this->activateWindow(); - this->raise(); - - // grabbing of keyboard and mouse - XGrabKeyboard(_sysdep->dpy, DefaultRootWindow(_sysdep->dpy) , false, GrabModeAsync, GrabModeAsync, CurrentTime); - XGrabPointer(_sysdep->dpy, DefaultRootWindow(_sysdep->dpy) , false, 0, GrabModeAsync, GrabModeAsync, None, 0, CurrentTime); - - - QProcess ungrabP; - ungrabP.start("/bin/bash", QStringList() << "/opt/openslx/pvs2/kb-lock.sh"); - ungrabP.waitForFinished(); - - _locked = true; - return true; -} - -bool BlankScreen::unlock() -{ - this->hide(); - if (!_locked) - return true; - if (_sysdep->dpy == NULL) - return false; - - // ungrabbing of keyboard and mouse - XUngrabPointer(_sysdep->dpy, CurrentTime); - XUngrabKeyboard(_sysdep->dpy, CurrentTime); - - XFlush(_sysdep->dpy); - - /* start the kb-unlock.sh script */ - QProcess regrabP; - regrabP.start("/bin/bash", QStringList() << "/opt/openslx/pvs2/kb-unlock.sh"); - regrabP.waitForFinished(); - - _locked = false; - return true; -} - -void BlankScreen::timer_moveToTop() -{ - if (this->isHidden()) - return; - activateWindow(); - raise(); -} diff --git a/src/client/vnc/vncwindow.h b/src/client/vnc/vncwindow.h index 29f2e98..3247b12 100644 --- a/src/client/vnc/vncwindow.h +++ b/src/client/vnc/vncwindow.h @@ -14,7 +14,7 @@ #ifndef CLIENTVNCVIEWER_H_ #define CLIENTVNCVIEWER_H_ -#include +#include class VncThread; class QPainter; diff --git a/src/server/clicklabel/clicklabel.h b/src/server/clicklabel/clicklabel.h index 4d730a9..4c5a898 100644 --- a/src/server/clicklabel/clicklabel.h +++ b/src/server/clicklabel/clicklabel.h @@ -1,7 +1,7 @@ #ifndef _CLICKLABEL_H_ #define _CLICKLABEL_H_ -#include +#include #include /** diff --git a/src/server/connectionframe/connectionframe.h b/src/server/connectionframe/connectionframe.h index 7f338a8..72f57f3 100644 --- a/src/server/connectionframe/connectionframe.h +++ b/src/server/connectionframe/connectionframe.h @@ -1,6 +1,6 @@ #ifndef _CONNECTIONFRAME_H_ #define _CONNECTIONFRAME_H_ -#include +#include #include "../net/client.h" class MainWindow; diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp index 2eab581..d4819cf 100644 --- a/src/server/mainwindow/mainwindow.cpp +++ b/src/server/mainwindow/mainwindow.cpp @@ -16,7 +16,7 @@ // Self #include "mainwindow.h" // QT stuff -#include +#include #include #include #include diff --git a/src/server/mainwindow/mainwindow.h b/src/server/mainwindow/mainwindow.h index 27bf264..ac59481 100644 --- a/src/server/mainwindow/mainwindow.h +++ b/src/server/mainwindow/mainwindow.h @@ -1,7 +1,7 @@ #ifndef _MAINWINDOW_H_ #define _MAINWINDOW_H_ -#include +#include #include #include "../net/client.h" diff --git a/src/server/sessionnamewindow/sessionnamewindow.cpp b/src/server/sessionnamewindow/sessionnamewindow.cpp index cc4d751..c171f53 100644 --- a/src/server/sessionnamewindow/sessionnamewindow.cpp +++ b/src/server/sessionnamewindow/sessionnamewindow.cpp @@ -14,7 +14,7 @@ # ----------------------------------------------------------------------------- */ -#include +#include #include "sessionnamewindow.h" #include "../serverapp/serverapp.h" #include "../numerickeyboard/numerickeyboard.h" diff --git a/src/server/sessionnamewindow/sessionnamewindow.h b/src/server/sessionnamewindow/sessionnamewindow.h index 2338def..e46b895 100644 --- a/src/server/sessionnamewindow/sessionnamewindow.h +++ b/src/server/sessionnamewindow/sessionnamewindow.h @@ -1,7 +1,7 @@ #ifndef _SESSIONNAMEWINDOW_H_ #define _SESSIONNAMEWINDOW_H_ -#include +#include namespace Ui diff --git a/src/server/util/platform/screensaver.cpp b/src/server/util/platform/screensaver.cpp new file mode 100644 index 0000000..efffba9 --- /dev/null +++ b/src/server/util/platform/screensaver.cpp @@ -0,0 +1,74 @@ +#include "screensaver.h" + +#include +#include +#include +#include + +#ifdef X11_Xscreensaver_FOUND +# include +#endif +#ifdef X11_dpms_FOUND +#include +#endif + +namespace { + + Display *display = NULL; + bool extensionSupported = false; + bool dpmsSupported = false; + + bool init() + { + if (display != NULL) { + return true; + } + display = QX11Info::display(); + if (display == NULL) { + return false; + } +#ifdef X11_Xscreensaver_FOUND + int dummy; + extensionSupported = (XScreenSaverQueryExtension(display, &dummy, &dummy) == True); +#endif +#ifdef X11_dpms_FOUND + dpmsSupported = (DPMSCapable(display) == True); +#endif + return true; + } + +} + +namespace ScreenSaver { + + void allowSaverAndStandby(bool allow) + { + if (!init()) + return; +#ifdef X11_Xscreensaver_FOUND + if (extensionSupported) { + XScreenSaverSuspend(display, allow ? False : True); + return; + } +#endif + // TODO: Maybe try some fallback, call xset, or trigger some event periodically + } + + void forceUnlockAndScreenOn() + { + if (!init()) + return; + QProcess process; + process.start("xscreensaver-command", QStringList() << "-deactivate"); + process.waitForFinished(100); +#ifdef X11_dpms_FOUND + CARD16 power_level; + BOOL state; + if (DPMSInfo(display, &power_level, &state) && state) { + DPMSForceLevel(display, DPMSModeOn); + return; + } +#endif + } + +} diff --git a/src/server/util/platform/screensaver_X11.cpp b/src/server/util/platform/screensaver_X11.cpp deleted file mode 100644 index efffba9..0000000 --- a/src/server/util/platform/screensaver_X11.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include "screensaver.h" - -#include -#include -#include -#include - -#ifdef X11_Xscreensaver_FOUND -# include -#endif -#ifdef X11_dpms_FOUND -#include -#endif - -namespace { - - Display *display = NULL; - bool extensionSupported = false; - bool dpmsSupported = false; - - bool init() - { - if (display != NULL) { - return true; - } - display = QX11Info::display(); - if (display == NULL) { - return false; - } -#ifdef X11_Xscreensaver_FOUND - int dummy; - extensionSupported = (XScreenSaverQueryExtension(display, &dummy, &dummy) == True); -#endif -#ifdef X11_dpms_FOUND - dpmsSupported = (DPMSCapable(display) == True); -#endif - return true; - } - -} - -namespace ScreenSaver { - - void allowSaverAndStandby(bool allow) - { - if (!init()) - return; -#ifdef X11_Xscreensaver_FOUND - if (extensionSupported) { - XScreenSaverSuspend(display, allow ? False : True); - return; - } -#endif - // TODO: Maybe try some fallback, call xset, or trigger some event periodically - } - - void forceUnlockAndScreenOn() - { - if (!init()) - return; - QProcess process; - process.start("xscreensaver-command", QStringList() << "-deactivate"); - process.waitForFinished(100); -#ifdef X11_dpms_FOUND - CARD16 power_level; - BOOL state; - if (DPMSInfo(display, &power_level, &state) && state) { - DPMSForceLevel(display, DPMSModeOn); - return; - } -#endif - } - -} -- cgit v1.2.3-55-g7522