Merge pull request #445 from frostworx/master

added optional QT5 support - LedDevicePhilipsHue needs proper fixes

Former-commit-id: a9b0dd2af92266ad137c4a3ac05dbeec6a6c102b
This commit is contained in:
tvdzwan
2016-01-13 22:43:15 +01:00
24 changed files with 214 additions and 9 deletions

View File

@@ -59,8 +59,11 @@ void BoblightClientConnection::readData()
while(bytes > 0)
{
// create message string (strip the newline)
#ifdef ENABLE_QT5
QString message = QString::fromLatin1(_receiveBuffer.data(), bytes-1);
#else
QString message = QString::fromAscii(_receiveBuffer.data(), bytes-1);
#endif
// remove message data from buffer
_receiveBuffer = _receiveBuffer.mid(bytes);

View File

@@ -17,7 +17,11 @@ set(BoblightServer_SOURCES
${CURRENT_SOURCE_DIR}/BoblightClientConnection.cpp
)
if(ENABLE_QT5)
qt5_wrap_cpp(BoblightServer_HEADERS_MOC ${BoblightServer_QT_HEADERS})
else(ENABLE_QT5)
qt4_wrap_cpp(BoblightServer_HEADERS_MOC ${BoblightServer_QT_HEADERS})
endif(ENABLE_QT5)
add_library(boblightserver
${BoblightServer_HEADERS}
@@ -26,6 +30,10 @@ add_library(boblightserver
${BoblightServer_HEADERS_MOC}
)
if(ENABLE_QT5)
qt5_use_modules(boblightserver Widgets)
endif(ENABLE_QT5)
target_link_libraries(boblightserver
hyperion
hyperion-utils

View File

@@ -27,9 +27,13 @@ SET(EffectEngineSOURCES
set(EffectEngine_RESOURCES ${CURRENT_SOURCE_DIR}/EffectEngine.qrc)
if(ENABLE_QT5)
QT5_WRAP_CPP(EffectEngineHEADERS_MOC ${EffectEngineQT_HEADERS})
qt5_add_resources(EffectEngine_RESOURCES_RCC ${EffectEngine_RESOURCES} OPTIONS "-no-compress")
else(ENABLE_QT5)
QT4_WRAP_CPP(EffectEngineHEADERS_MOC ${EffectEngineQT_HEADERS})
qt4_add_resources(EffectEngine_RESOURCES_RCC ${EffectEngine_RESOURCES} OPTIONS "-no-compress")
endif(ENABLE_QT5)
add_library(effectengine
${EffectEngineHEADERS}
@@ -39,6 +43,10 @@ add_library(effectengine
${EffectEngineSOURCES}
)
if(ENABLE_QT5)
qt5_use_modules(effectengine Widgets)
endif(ENABLE_QT5)
target_link_libraries(effectengine
hyperion
jsoncpp

View File

@@ -75,7 +75,11 @@ const std::list<EffectDefinition> &EffectEngine::getEffects() const
bool EffectEngine::loadEffectDefinition(const std::string &path, const std::string &effectConfigFile, EffectDefinition & effectDefinition)
{
#ifdef ENABLE_QT5
std::string fileName = path + QDir::separator().toLatin1() + effectConfigFile;
#else
std::string fileName = path + QDir::separator().toAscii() + effectConfigFile;
#endif
std::ifstream file(fileName.c_str());
if (!file.is_open())
@@ -110,7 +114,11 @@ bool EffectEngine::loadEffectDefinition(const std::string &path, const std::stri
// setup the definition
effectDefinition.name = config["name"].asString();
#ifdef ENABLE_QT5
effectDefinition.script = path + QDir::separator().toLatin1() + config["script"].asString();
#else
effectDefinition.script = path + QDir::separator().toAscii() + config["script"].asString();
#endif
effectDefinition.args = config["args"];
// return succes

View File

@@ -15,7 +15,11 @@ SET(AmlogicSOURCES
${CURRENT_SOURCE_DIR}/AmlogicGrabber.cpp
)
if(ENABLE_QT5)
QT5_WRAP_CPP(AmlogicHEADERS_MOC ${AmlogicQT_HEADERS})
else(ENABLE_QT5)
QT4_WRAP_CPP(AmlogicHEADERS_MOC ${AmlogicQT_HEADERS})
endif(ENABLE_QT5)
add_library(amlogic-grabber
${AmlogicHEADERS}

View File

@@ -21,7 +21,11 @@ SET(DispmanxGrabberSOURCES
${CURRENT_SOURCE_DIR}/DispmanxFrameGrabber.cpp
)
if(ENABLE_QT5)
QT5_WRAP_CPP(DispmanxGrabberHEADERS_MOC ${DispmanxGrabberQT_HEADERS})
else(ENABLE_QT5)
QT4_WRAP_CPP(DispmanxGrabberHEADERS_MOC ${DispmanxGrabberQT_HEADERS})
endif(ENABLE_QT5)
add_library(dispmanx-grabber
${DispmanxGrabberHEADERS}

View File

@@ -21,7 +21,11 @@ SET(FramebufferGrabberSOURCES
${CURRENT_SOURCE_DIR}/FramebufferFrameGrabber.cpp
)
if(ENABLE_QT5)
QT5_WRAP_CPP(FramebufferGrabberHEADERS_MOC ${FramebufferGrabberQT_HEADERS})
else(ENABLE_QT5)
QT4_WRAP_CPP(FramebufferGrabberHEADERS_MOC ${FramebufferGrabberQT_HEADERS})
endif(ENABLE_QT5)
add_library(framebuffer-grabber
${FramebufferGrabberHEADERS}

View File

@@ -16,7 +16,11 @@ SET(OsxGrabberSOURCES
${CURRENT_SOURCE_DIR}/OsxFrameGrabber.cpp
)
if(ENABLE_QT5)
QT5_WRAP_CPP(OsxGrabberHEADERS_MOC ${OsxGrabberQT_HEADERS})
else(ENABLE_QT5)
QT4_WRAP_CPP(OsxGrabberHEADERS_MOC ${OsxGrabberQT_HEADERS})
endif(ENABLE_QT5)
add_library(osx-grabber
${OsxGrabberHEADERS}

View File

@@ -16,7 +16,11 @@ SET(V4L2_SOURCES
${CURRENT_SOURCE_DIR}/V4L2Wrapper.cpp
)
if(ENABLE_QT5)
QT5_WRAP_CPP(V4L2_HEADERS_MOC ${V4L2_QT_HEADERS})
else(ENABLE_QT5)
QT4_WRAP_CPP(V4L2_HEADERS_MOC ${V4L2_QT_HEADERS})
endif(ENABLE_QT5)
add_library(v4l2-grabber
${V4L2_HEADERS}
@@ -25,6 +29,10 @@ add_library(v4l2-grabber
${V4L2_HEADERS_MOC}
)
if(ENABLE_QT5)
qt5_use_modules(v4l2-grabber Widgets)
endif(ENABLE_QT5)
target_link_libraries(v4l2-grabber
hyperion
${QT_LIBRARIES}

View File

@@ -22,7 +22,11 @@ SET(X11_SOURCES
${CURRENT_SOURCE_DIR}/X11Grabber.cpp
)
if(ENABLE_QT5)
QT5_WRAP_CPP(X11_HEADERS_MOC ${X11_QT_HEADERS})
else(ENABLE_QT5)
QT4_WRAP_CPP(X11_HEADERS_MOC ${X11_QT_HEADERS})
endif(ENABLE_QT5)
add_library(x11-grabber
${X11_HEADERS}

View File

@@ -36,9 +36,13 @@ set(Hyperion_RESOURCES
${CURRENT_SOURCE_DIR}/resource.qrc
)
if(ENABLE_QT5)
QT5_WRAP_CPP(Hyperion_HEADERS_MOC ${Hyperion_QT_HEADERS})
QT5_ADD_RESOURCES(Hyperion_RESOURCES_RCC ${Hyperion_RESOURCES} OPTIONS "-no-compress")
else(ENABLE_QT5)
QT4_WRAP_CPP(Hyperion_HEADERS_MOC ${Hyperion_QT_HEADERS})
QT4_ADD_RESOURCES(Hyperion_RESOURCES_RCC ${Hyperion_RESOURCES} OPTIONS "-no-compress")
endif(ENABLE_QT5)
add_library(hyperion
${Hyperion_HEADERS}
@@ -48,6 +52,10 @@ add_library(hyperion
${Hyperion_RESOURCES_RCC}
)
if(ENABLE_QT5)
qt5_use_modules(hyperion Widgets)
endif(ENABLE_QT5)
target_link_libraries(hyperion
blackborder
hyperion-utils

View File

@@ -20,10 +20,13 @@ set(JsonServer_SOURCES
set(JsonServer_RESOURCES
${CURRENT_SOURCE_DIR}/JsonSchemas.qrc
)
if(ENABLE_QT5)
qt5_wrap_cpp(JsonServer_HEADERS_MOC ${JsonServer_QT_HEADERS})
qt5_add_resources(JsonServer_RESOURCES_RCC ${JsonServer_RESOURCES} OPTIONS "-no-compress")
else(ENABLE_QT5)
qt4_wrap_cpp(JsonServer_HEADERS_MOC ${JsonServer_QT_HEADERS})
qt4_add_resources(JsonServer_RESOURCES_RCC ${JsonServer_RESOURCES} OPTIONS "-no-compress")
endif(ENABLE_QT5)
add_library(jsonserver
${JsonServer_HEADERS}
@@ -34,6 +37,10 @@ add_library(jsonserver
${JsonServer_RESOURCES_RCC}
)
if(ENABLE_QT5)
qt5_use_modules(jsonserver Widgets Network)
endif(ENABLE_QT5)
target_link_libraries(jsonserver
hyperion
hyperion-utils

View File

@@ -106,8 +106,12 @@ if(ENABLE_TINKERFORGE)
)
endif(ENABLE_TINKERFORGE)
if(ENABLE_QT5)
QT5_WRAP_CPP(Leddevice_HEADERS_MOC ${Leddevice_QT_HEADERS})
else(ENABLE_QT5)
QT4_WRAP_CPP(Leddevice_HEADERS_MOC ${Leddevice_QT_HEADERS})
endif(ENABLE_QT5)
add_library(leddevice
${Leddevice_HEADERS}
@@ -116,6 +120,10 @@ add_library(leddevice
${Leddevice_SOURCES}
)
if(ENABLE_QT5)
qt5_use_modules(leddevice Widgets Network)
endif(ENABLE_QT5)
target_link_libraries(leddevice
hyperion-utils
serialport

View File

@@ -7,7 +7,12 @@
// qt includes
#include <QtCore/qmath.h>
#include <QUrl>
#ifdef ENABLE_QT5
#else
#include <QHttpRequestHeader>
#endif
#include <QEventLoop>
#include <set>
@@ -144,14 +149,22 @@ LedDevicePhilipsHue::LedDevicePhilipsHue(const std::string& output, const std::s
int transitiontime, std::vector<unsigned int> lightIds) :
host(output.c_str()), username(username.c_str()), switchOffOnBlack(switchOffOnBlack), transitiontime(
transitiontime), lightIds(lightIds) {
#ifdef ENABLE_QT5
#else
http = new QHttp(host);
timer.setInterval(3000);
timer.setSingleShot(true);
connect(&timer, SIGNAL(timeout()), this, SLOT(restoreStates()));
#endif
}
LedDevicePhilipsHue::~LedDevicePhilipsHue() {
#ifdef ENABLE_QT5
#else
delete http;
#endif
}
int LedDevicePhilipsHue::write(const std::vector<ColorRgb> & ledValues) {
@@ -201,21 +214,32 @@ int LedDevicePhilipsHue::write(const std::vector<ColorRgb> & ledValues) {
// Next light id.
idx++;
}
#ifdef ENABLE_QT5
#else
timer.start();
#endif
return 0;
}
int LedDevicePhilipsHue::switchOff() {
#ifdef ENABLE_QT5
#else
timer.stop();
// If light states have been saved before, ...
if (areStatesSaved()) {
// ... restore them.
restoreStates();
}
#endif
return 0;
}
void LedDevicePhilipsHue::put(QString route, QString content) {
#ifdef ENABLE_QT5
#else
QString url = QString("/api/%1/%2").arg(username).arg(route);
QHttpRequestHeader header("PUT", url);
header.setValue("Host", host);
@@ -229,9 +253,13 @@ void LedDevicePhilipsHue::put(QString route, QString content) {
http->request(header, content.toAscii());
// Go into the loop until the request is finished.
loop.exec();
#endif
}
QByteArray LedDevicePhilipsHue::get(QString route) {
#ifdef ENABLE_QT5
return 0;
#else
QString url = QString("/api/%1/%2").arg(username).arg(route);
// Event loop to block until request finished.
QEventLoop loop;
@@ -243,6 +271,7 @@ QByteArray LedDevicePhilipsHue::get(QString route) {
loop.exec();
// Read all data of the response.
return http->readAll();
#endif
}
QString LedDevicePhilipsHue::getStateRoute(unsigned int lightId) {

View File

@@ -4,11 +4,14 @@
#include <string>
// Qt includes
#ifdef ENABLE_QT5
#include <QNetworkAccessManager>
#else
#include <QObject>
#include <QString>
#include <QHttp>
#include <QTimer>
#endif
// Leddevice includes
#include <leddevice/LedDevice.h>
@@ -165,9 +168,14 @@ private:
/// User name for the API ("newdeveloper")
QString username;
/// Qhttp object for sending requests.
#ifdef ENABLE_QT5
// TODO QNetworkAcessManager stuff
#else
QHttp* http;
/// Use timer to reset lights when we got into "GRABBINGMODE_OFF".
QTimer timer;
#endif
///
bool switchOffOnBlack;
/// Transition time in multiples of 100 ms.

View File

@@ -34,7 +34,11 @@ protobuf_generate_cpp(ProtoServer_PROTO_SRCS ProtoServer_PROTO_HDRS
${ProtoServer_PROTOS}
)
if(ENABLE_QT5)
qt5_wrap_cpp(ProtoServer_HEADERS_MOC ${ProtoServer_QT_HEADERS})
else(ENABLE_QT5)
qt4_wrap_cpp(ProtoServer_HEADERS_MOC ${ProtoServer_QT_HEADERS})
endif(ENABLE_QT5)
add_library(protoserver
${ProtoServer_HEADERS}
@@ -45,6 +49,9 @@ add_library(protoserver
${ProtoServer_PROTO_SRCS}
${ProtoServer_PROTO_HDRS}
)
if(ENABLE_QT5)
qt5_use_modules(protoserver Widgets)
endif(ENABLE_QT5)
target_link_libraries(protoserver
hyperion

View File

@@ -15,7 +15,11 @@ SET(XBMCVideoChecker_SOURCES
${CURRENT_SOURCE_DIR}/XBMCVideoChecker.cpp
)
if(ENABLE_QT5)
QT5_WRAP_CPP(XBMCVideoChecker_HEADERS_MOC ${XBMCVideoChecker_QT_HEADERS})
else(ENABLE_QT5)
QT4_WRAP_CPP(XBMCVideoChecker_HEADERS_MOC ${XBMCVideoChecker_QT_HEADERS})
endif(ENABLE_QT5)
add_library(xbmcvideochecker
${XBMCVideoChecker_HEADERS}
@@ -24,6 +28,10 @@ add_library(xbmcvideochecker
${XBMCVideoChecker_SOURCES}
)
if(ENABLE_QT5)
qt5_use_modules(xbmcvideochecker Widgets)
endif(ENABLE_QT5)
target_link_libraries(xbmcvideochecker
hyperion
${QT_LIBRARIES})