game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
homeassistant_panel.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// homeassistant_panel.h
4// ==============================================================================
5// Embedded Home Assistant web panel using QWebEngineView
6// ==============================================================================
7
8#pragma once
9
10#include <QInputDialog>
11#include <QLineEdit>
12#include <QPushButton>
13#include <QVBoxLayout>
14#include <QWebEnginePage>
15#include <QWebEngineProfile>
16#include <QWebEngineView>
17#include <QWidget>
18
19class ThemeManager;
20
21// Custom page that intercepts navigation to external URLs
22class HAWebEnginePage : public QWebEnginePage
23{
24 Q_OBJECT
25
26 public:
27 using QWebEnginePage::QWebEnginePage;
28
29 protected:
30 bool acceptNavigationRequest(const QUrl& url, NavigationType type, bool isMainFrame) override;
31 QWebEnginePage* createWindow(WebWindowType type) override;
32};
33
34class HomeAssistantPanel : public QWidget
35{
36 Q_OBJECT
37
38 public:
39 explicit HomeAssistantPanel(QWidget* parent = nullptr, ThemeManager* themeManager = nullptr);
40 ~HomeAssistantPanel() override;
41
42 void loadDashboard();
43 void setUrl(const QString& url);
44 QString url() const
45 {
46 return haUrl_;
47 }
48
49 signals:
50 void titleChanged(const QString& title);
51
52 public slots:
53 void applyTheme();
54
55 private slots:
56 void onUrlChanged(const QUrl& url);
57 void onLoadStarted();
58 void onLoadFinished(bool ok);
59 void onBackClicked();
60 void onForwardClicked();
61 void onRefreshClicked();
62 void onHomeClicked();
63 void onSettingsClicked();
64
65 private:
66 void setupUI();
67 void ensureWebView();
68 void loadSettings();
69 void saveSettings();
70
71 QWebEngineView* webView_ = nullptr;
72 QWebEngineProfile* profile_ = nullptr;
73 QWidget* navWidget_ = nullptr;
74 QPushButton* backBtn_ = nullptr;
75 QPushButton* forwardBtn_ = nullptr;
76 QPushButton* refreshBtn_ = nullptr;
77 QPushButton* homeBtn_ = nullptr;
78 QPushButton* settingsBtn_ = nullptr;
79 QVBoxLayout* layout_ = nullptr;
80
81 QString haUrl_;
82 bool dashboardLoaded_ = false; // Track if we've ever loaded content
83
84 static constexpr const char* DEFAULT_HA_URL = "https://ha.castlenug.org";
85 static constexpr const char* SETTINGS_KEY_URL = "homeassistant/url";
86
87 ThemeManager* themeManager_;
88};
QWebEnginePage * createWindow(WebWindowType type) override
bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame) override
HomeAssistantPanel(QWidget *parent=nullptr, ThemeManager *themeManager=nullptr)
void titleChanged(const QString &title)
void setUrl(const QString &url)