Skip to content

Commit

Permalink
rename to Hue-QT, menu update optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
vchlum committed Nov 16, 2021
1 parent 5467605 commit 4ab05f0
Show file tree
Hide file tree
Showing 37 changed files with 713 additions and 382 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
cmake_minimum_required(VERSION 3.20)

project(
Hue-Lights-2
hue-qt
VERSION 0.1
DESCRIPTION "Hue Lights 2"
DESCRIPTION "Hue-QT"
LANGUAGES CXX
)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# hue-lights-2
# hue-qt

## Notice - the work is in progress
This is work in progress project for controlling Philips Hue Bridge and Philips Hue HDMI Syncbox. The application uses the QT framework and it targets Linux. The possibility to use it on Windows is open. Stay tuned.
Expand Down
12 changes: 6 additions & 6 deletions apps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
find_package(Qt6 COMPONENTS Widgets REQUIRED)

qt_add_executable(hue-lights-2
qt_add_executable(hue-qt
${CMAKE_SOURCE_DIR}/resources/resources.qrc
${CMAKE_SOURCE_DIR}/src/mainmenu.h
${CMAKE_SOURCE_DIR}/src/mainmenu.cpp
${CMAKE_SOURCE_DIR}/src/mainmenubridge.h
${CMAKE_SOURCE_DIR}/src/mainmenubridge.cpp
${CMAKE_SOURCE_DIR}/src/mainmenubridgeutils.h
${CMAKE_SOURCE_DIR}/src/mainmenubridgeutils.cpp
hue-lights-2.cpp)
hue-qt.cpp)

target_include_directories(hue-lights-2 PUBLIC ${CMAKE_SOURCE_DIR}/src/)
target_include_directories(hue-qt PUBLIC ${CMAKE_SOURCE_DIR}/src/)

target_link_libraries(hue-lights-2 PRIVATE Qt6::Widgets)
target_link_libraries(hue-lights-2 PRIVATE hue)
target_link_libraries(hue-lights-2 PRIVATE menu)
target_link_libraries(hue-qt PRIVATE Qt6::Widgets)
target_link_libraries(hue-qt PRIVATE hue)
target_link_libraries(hue-qt PRIVATE menu)
2 changes: 1 addition & 1 deletion apps/hue-lights-2.cpp → apps/hue-qt.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Hue Lights 2 - Application for controlling Philips Hue Bridge and HDMI Syncbox
/* Hue-QT - Application for controlling Philips Hue Bridge and HDMI Syncbox
* Copyright (C) 2021 Václav Chlumský
*
* This program is free software: you can redistribute it and/or modify
Expand Down
19 changes: 10 additions & 9 deletions include/hue/huebridge.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Hue Lights 2 - Application for controlling Philips Hue Bridge and HDMI Syncbox
/* Hue-QT - Application for controlling Philips Hue Bridge and HDMI Syncbox
* Copyright (C) 2021 Václav Chlumský
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -29,8 +29,8 @@ enum HueBridgeRequestTypes {
req_discovery_bridges,
req_discovery_bridge,
req_create_user,
req_bridge_status,
req_bridge_config,
req_bridge_status_v1,
req_bridge_config_v1,
req_bridge_status_v2
};

Expand Down Expand Up @@ -68,9 +68,9 @@ class HueBridge : public HueDevice
bool updateBridgeInfo(QJsonObject data);
QJsonObject dumpBridge();
void createUser();
void getStatus1();
void getConfig1();
void getStatus();
void getConfig();
void getStatus2();

private:
QString url_api_v1 = "http://%1/api";
Expand All @@ -81,21 +81,22 @@ class HueBridge : public HueDevice
QString client_key = "";
bool events_running = false;
QNetworkAccessManager *event_manager;
int event_retries = 0;

void readCreateUser(QString ret);
void runEvent();
void runEventStream();

signals:
void event(QJsonObject json);
void events(QJsonArray &json_array);
void userCreationFailed();
void userCreationSucceed();
void infoUpdated();
void statusV2(QJsonObject json);

private slots:
void bridgeRequestFinished(const QVariant type, const QString ret);
void startEvent();
void stopEvent();
void startEventStream();
void stopEventStream();
void eventRequestFinished(QNetworkReply *reply);
};
#endif // HUEBRIDGE_H
2 changes: 1 addition & 1 deletion include/hue/huebridgelist.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Hue Lights 2 - Application for controlling Philips Hue Bridge and HDMI Syncbox
/* Hue-QT - Application for controlling Philips Hue Bridge and HDMI Syncbox
* Copyright (C) 2021 Václav Chlumský
*
* This program is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion include/hue/huedevice.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Hue Lights 2 - Application for controlling Philips Hue Bridge and HDMI Syncbox
/* Hue-QT - Application for controlling Philips Hue Bridge and HDMI Syncbox
* Copyright (C) 2021 Václav Chlumský
*
* This program is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion include/hue/huelist.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Hue Lights 2 - Application for controlling Philips Hue Bridge and HDMI Syncbox
/* Hue-QT - Application for controlling Philips Hue Bridge and HDMI Syncbox
* Copyright (C) 2021 Václav Chlumský
*
* This program is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion include/hue/huesyncbox.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Hue Lights 2 - Application for controlling Philips Hue Bridge and HDMI Syncbox
/* Hue-QT - Application for controlling Philips Hue Bridge and HDMI Syncbox
* Copyright (C) 2021 Václav Chlumský
*
* This program is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion include/hue/huesyncboxlist.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Hue Lights 2 - Application for controlling Philips Hue Bridge and HDMI Syncbox
/* Hue-QT - Application for controlling Philips Hue Bridge and HDMI Syncbox
* Copyright (C) 2021 Václav Chlumský
*
* This program is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion include/hue/hueutils.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Hue Lights 2 - Application for controlling Philips Hue Bridge and HDMI Syncbox
/* Hue-QT - Application for controlling Philips Hue Bridge and HDMI Syncbox
* Copyright (C) 2021 Václav Chlumský
*
* This program is free software: you can redistribute it and/or modify
Expand Down
26 changes: 21 additions & 5 deletions include/menu/menubutton.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Hue Lights 2 - Application for controlling Philips Hue Bridge and HDMI Syncbox
/* Hue-QT - Application for controlling Philips Hue Bridge and HDMI Syncbox
* Copyright (C) 2021 Václav Chlumský
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -33,27 +33,43 @@ class MenuButton : public QPushButton
QString identifier;
bool has_slider;
bool has_switch;
bool all_items = false;
QLabel *label;
QLabel *icon;
MenuSlider *slider;
MenuSwitch *button_switch;
bool combined_state;

public slots:

signals:
void buttonRemoved(QString s);
void goBack();
public:
explicit MenuButton(QString item_id, bool use_slider, bool use_switch, QWidget *parent = 0);
explicit MenuButton(QString item_id, bool use_slider, int points, bool use_back, bool use_switch, QWidget *parent = 0);
~MenuButton() { emit buttonRemoved(id()); }
QString id();
void setText(QString text);
void setIcon(QString icon_name);
void setColor(QColor color);
void setSwitch(bool on);
void setSlider(int value);
void setAllItems(bool all);
bool allItems();
void setCombined(bool all);
bool combined();
};

class ClickableLabel : public QLabel
{
Q_OBJECT

public:
explicit ClickableLabel(QWidget* parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags());
~ClickableLabel();

signals:
void clicked();

protected:
void mousePressEvent(QMouseEvent* event);
};

#endif // MENUBUTTON_H
1 change: 1 addition & 0 deletions include/menu/menucolorpicker.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class ColorPicker : public QWidget
Q_OBJECT
public:
explicit ColorPicker(QWidget *parent = 0);
QSize sizeHint() const override;

signals:

Expand Down
2 changes: 1 addition & 1 deletion include/menu/menuexpendable.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Hue Lights 2 - Application for controlling Philips Hue Bridge and HDMI Syncbox
/* Hue-QT - Application for controlling Philips Hue Bridge and HDMI Syncbox
* Copyright (C) 2021 Václav Chlumský
*
* This program is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion include/menu/menuslider.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Hue Lights 2 - Application for controlling Philips Hue Bridge and HDMI Syncbox
/* Hue-QT - Application for controlling Philips Hue Bridge and HDMI Syncbox
* Copyright (C) 2021 Václav Chlumský
*
* This program is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion include/menu/menuswitch.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Hue Lights 2 - Application for controlling Philips Hue Bridge and HDMI Syncbox
/* Hue-QT - Application for controlling Philips Hue Bridge and HDMI Syncbox
* Copyright (C) 2021 Václav Chlumský
*
* This program is free software: you can redistribute it and/or modify
Expand Down
12 changes: 12 additions & 0 deletions resources/images/HueIcons/settingsSoftwareUpdate.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions resources/menu_resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
<qresource prefix="/">
<file>images/arrowdown.svg</file>
<file>images/arrowright.svg</file>

<file>images/HueIcons/settingsSoftwareUpdate.svg</file>
</qresource>
</RCC>
54 changes: 30 additions & 24 deletions src/huebridge.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Hue Lights 2 - Application for controlling Philips Hue Bridge and HDMI Syncbox
/* Hue-QT - Application for controlling Philips Hue Bridge and HDMI Syncbox
* Copyright (C) 2021 Václav Chlumský
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -32,8 +32,8 @@ HueBridge::HueBridge(QString ip, HueDevice *parent): HueDevice(ip, parent)

connect(this, SIGNAL(requestDeviceFinished(const QVariant, const QString)), this, SLOT(bridgeRequestFinished(const QVariant, const QString)));

connect(this, SIGNAL(connected()), this, SLOT(startEvent()));
connect(this, SIGNAL(disconnected()), this, SLOT(stopEvent()));
connect(this, SIGNAL(connected()), this, SLOT(startEventStream()));
connect(this, SIGNAL(disconnected()), this, SLOT(stopEventStream()));
}

void HueBridge::setUserName(QString s)
Expand Down Expand Up @@ -105,7 +105,7 @@ QJsonObject HueBridge::dumpBridge()

void HueBridge::createUser()
{
QString user = "hue-lights-2#";
QString user = "hue-qt#";
user += QHostInfo::localHostName().left(15);

QJsonObject json;
Expand All @@ -120,7 +120,7 @@ void HueBridge::createUser()
sendRequestPOST(url, (QNetworkRequest::Attribute) req_create_user, bytes);
}

void HueBridge::runEvent()
void HueBridge::runEventStream()
{
if (!events_running) {
return;
Expand All @@ -130,6 +130,8 @@ void HueBridge::runEvent()

QNetworkRequest request;
request.setUrl(QUrl(url));
request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork); // Events shouldn't be cached

foreach (const QStringList &header, request_headers) {
if (header.isEmpty()) {
break;
Expand All @@ -142,38 +144,42 @@ void HueBridge::runEvent()
}


void HueBridge::startEvent()
void HueBridge::startEventStream()
{
events_running = true;
runEvent();
event_retries = 0;
runEventStream();
}

void HueBridge::stopEvent()
void HueBridge::stopEventStream()
{
events_running = false;
}

void HueBridge::eventRequestFinished(QNetworkReply *reply)
{
if (reply->error()) {
qWarning() << "request reply on event stream error: " + reply->errorString();

runEvent();
return;
if(event_retries < 10) {
qWarning() << "request reply on event stream error: " + reply->errorString();
event_retries++;
runEventStream();
return;
} else {
qCritical() << "Unable to reconnect event stream, max retries reached";
return;
}
}

QString ret = reply->readAll();

QJsonArray json_array = QString2QJsonArray(ret);

if (json_array.size() > 0) {
for (int i = 0; i < json_array.size(); ++i) {
QJsonObject json = json_array[i].toObject();
emit event(json);
}
emit events(json_array);
}

runEvent();
event_retries = 0;
runEventStream();
}

void HueBridge::bridgeRequestFinished(const QVariant type, const QString ret)
Expand All @@ -187,7 +193,7 @@ void HueBridge::bridgeRequestFinished(const QVariant type, const QString ret)
break;
}

case req_bridge_status:
case req_bridge_status_v1:
{
break;
}
Expand All @@ -200,7 +206,7 @@ void HueBridge::bridgeRequestFinished(const QVariant type, const QString ret)
break;
}

case req_bridge_config:
case req_bridge_config_v1:
{
QString device_config = ret;
QJsonObject json = QString2QJsonObject(device_config);
Expand Down Expand Up @@ -245,19 +251,19 @@ void HueBridge::readCreateUser(QString ret)
}
}

void HueBridge::getStatus()
void HueBridge::getStatus1()
{
QString url = url_api_v1_user.arg(ip(), user_name, "");
sendRequestGET(url, (QNetworkRequest::Attribute) req_bridge_status);
sendRequestGET(url, (QNetworkRequest::Attribute) req_bridge_status_v1);
}

void HueBridge::getConfig()
void HueBridge::getConfig1()
{
QString url = url_api_v1_user.arg(ip(), user_name, "config");
sendRequestGET(url, (QNetworkRequest::Attribute) req_bridge_config);
sendRequestGET(url, (QNetworkRequest::Attribute) req_bridge_config_v1);
}

void HueBridge::getStatus2()
void HueBridge::getStatus()
{
QString url = url_api_v2.arg(ip());
sendRequestGET(url, (QNetworkRequest::Attribute) req_bridge_status_v2);
Expand Down
2 changes: 1 addition & 1 deletion src/huebridgediscovery.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Hue Lights 2 - Application for controlling Philips Hue Bridge and HDMI Syncbox
/* Hue-QT - Application for controlling Philips Hue Bridge and HDMI Syncbox
* Copyright (C) 2021 Václav Chlumský
*
* This program is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion src/huebridgelist.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Hue Lights 2 - Application for controlling Philips Hue Bridge and HDMI Syncbox
/* Hue-QT - Application for controlling Philips Hue Bridge and HDMI Syncbox
* Copyright (C) 2021 Václav Chlumský
*
* This program is free software: you can redistribute it and/or modify
Expand Down
Loading

0 comments on commit 4ab05f0

Please sign in to comment.