From 2216fedeaa5057ee961a8cd78c2af678c27f7596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20Rosenkr=C3=A4nzer?= Date: Tue, 3 Sep 2024 18:59:36 +0200 Subject: [PATCH] Help browser, panel login --- Configurator.h | 2 ++ dialogs/CMakeLists.txt | 4 ++-- dialogs/HelpBrowser.cpp | 20 +++++++++++++++++++ dialogs/HelpBrowser.h | 17 ++++++++++++++++ dialogs/ServicesDialog.cpp | 40 ++++++++++++++++++++++++++++++++++++-- dialogs/ServicesDialog.h | 5 ++++- lib/Service.cpp | 2 +- lib/Service.h | 4 ++-- lib/ServiceWidget.cpp | 10 ++++++++-- lib/ServiceWidget.h | 8 ++++++++ 10 files changed, 102 insertions(+), 10 deletions(-) create mode 100644 dialogs/HelpBrowser.cpp create mode 100644 dialogs/HelpBrowser.h diff --git a/Configurator.h b/Configurator.h index f96c575..a8fd769 100644 --- a/Configurator.h +++ b/Configurator.h @@ -13,6 +13,8 @@ public: Configurator(int &argc, char **&argv); QNetworkAccessManager &nam() { return _nam; } QString baseUrl() const { return "https://dashboard." + _loginDialog->domain(); } + QString user() const { return _loginDialog->user(); } + QString password() const { return _loginDialog->password(); } QByteArray download(QUrl const &url); void waitForDownload(QNetworkReply *r) const; Services const &services() const { return _services; } diff --git a/dialogs/CMakeLists.txt b/dialogs/CMakeLists.txt index da4b607..6a94f64 100644 --- a/dialogs/CMakeLists.txt +++ b/dialogs/CMakeLists.txt @@ -2,5 +2,5 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${CMAKE_SOURCE_DIR}) include_directories(${CMAKE_SOURCE_DIR}/lib) -add_library(dialogs STATIC FederatedLogin.cpp ServicesDialog.cpp) -target_link_libraries(dialogs Qt${QT_VERSION}::Core Qt${QT_VERSION}::Gui Qt${QT_VERSION}::Widgets fed) +add_library(dialogs STATIC FederatedLogin.cpp ServicesDialog.cpp HelpBrowser.cpp) +target_link_libraries(dialogs Qt${QT_VERSION}::Core Qt${QT_VERSION}::Gui Qt${QT_VERSION}::Widgets Qt${QT_VERSION}::WebEngineWidgets fed) diff --git a/dialogs/HelpBrowser.cpp b/dialogs/HelpBrowser.cpp new file mode 100644 index 0000000..12a3e17 --- /dev/null +++ b/dialogs/HelpBrowser.cpp @@ -0,0 +1,20 @@ +#include "HelpBrowser.h" +#include + +HelpBrowser::HelpBrowser(QUrl const &url, QWidget *parent):QMainWindow(parent) { + _browser = new QWebEngineView(this); + _browser->load(url); + QToolBar *tb = addToolBar(tr("Main toolbar")); + QAction *back = new QAction(tr("Back"), tb); + connect(back, &QAction::triggered, _browser, &QWebEngineView::back); + tb->addAction(back); + QAction *forward = new QAction(tr("Forward"), tb); + connect(forward, &QAction::triggered, _browser, &QWebEngineView::forward); + tb->addAction(forward); + setCentralWidget(_browser); +} + +void HelpBrowser::closeEvent(QCloseEvent *e) { + QMainWindow::closeEvent(e); + deleteLater(); +} diff --git a/dialogs/HelpBrowser.h b/dialogs/HelpBrowser.h new file mode 100644 index 0000000..64b1530 --- /dev/null +++ b/dialogs/HelpBrowser.h @@ -0,0 +1,17 @@ +#pragma once + +#include +#include +#include +#include +#include + +class HelpBrowser:public QMainWindow { + Q_OBJECT +public: + HelpBrowser(QUrl const &url, QWidget *parent = nullptr); +protected: + void closeEvent(QCloseEvent *e) override; +protected: + QWebEngineView * _browser; +}; diff --git a/dialogs/ServicesDialog.cpp b/dialogs/ServicesDialog.cpp index f0cbff1..d6a2669 100644 --- a/dialogs/ServicesDialog.cpp +++ b/dialogs/ServicesDialog.cpp @@ -1,7 +1,11 @@ #include "ServicesDialog.h" #include "ServiceWidget.h" #include "Configurator.h" +#include "HelpBrowser.h" +#include +#include +#include #include #include @@ -23,13 +27,16 @@ ServicesDialog::ServicesDialog(QWidget *parent):QDialog(parent),_layout(this) { _layout.addWidget(_unknownServicesScroller, ++y, 0); int k = 0, u = 0; for(auto i : app->services()) { + ServiceWidget *w; if(i.title == "Nextcloud" || i.title == "Panel") { - ServiceWidget *w=new ServiceWidget(i, _knownServices); + w=new ServiceWidget(i, _knownServices); ksLayout->addWidget(w, ++k); } else { - ServiceWidget *w=new ServiceWidget(i, _unknownServices); + w=new ServiceWidget(i, _unknownServices); usLayout->addWidget(w, ++u); } + connect(w, &ServiceWidget::goClicked, this, &ServicesDialog::configureService); + connect(w, &ServiceWidget::helpClicked, this, &ServicesDialog::serviceHelp); } _knownServicesScroller->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); _unknownServicesScroller->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); @@ -47,6 +54,35 @@ ServicesDialog::ServicesDialog(QWidget *parent):QDialog(parent),_layout(this) { resizeEvent(0); } +void ServicesDialog::configureService() { + ServiceWidget *w=qobject_cast(sender()); + if(!w) + return; + + QWebEngineView *v = new QWebEngineView(static_cast(nullptr)); + if(w->service().title == "Panel") { + QWebEngineHttpRequest req = QWebEngineHttpRequest::postRequest(w->service().url, { + {"user_id", app->user()}, + {"password", app->password()} + }); + v->load(req); + } else + v->load(w->service().url); + v->show(); +} + +void ServicesDialog::serviceHelp() { + ServiceWidget *w=qobject_cast(sender()); + if(!w) + return; + + Service const &s = w->service(); + HelpBrowser *viewer = new HelpBrowser(s.documentationUrl); + viewer->setWindowIcon(s.pixmap()); + viewer->setWindowTitle(QString("%1 help").arg(s.title)); + viewer->show(); +} + void ServicesDialog::resizeEvent(QResizeEvent *e) { // Make sure the known services and unknown services // lists always use the full width available diff --git a/dialogs/ServicesDialog.h b/dialogs/ServicesDialog.h index 9b16014..ea73c81 100644 --- a/dialogs/ServicesDialog.h +++ b/dialogs/ServicesDialog.h @@ -12,7 +12,10 @@ class ServicesDialog:public QDialog { Q_OBJECT public: - ServicesDialog(QWidget *parent=0); + ServicesDialog(QWidget *parent=nullptr); +protected Q_SLOTS: + void configureService(); + void serviceHelp(); protected: void resizeEvent(QResizeEvent *e) override; protected: diff --git a/lib/Service.cpp b/lib/Service.cpp index df6ba63..5eea463 100644 --- a/lib/Service.cpp +++ b/lib/Service.cpp @@ -15,7 +15,7 @@ Service::Service(QJsonObject const &o) { LDAP = o["LDAP"].toBool(); } -QPixmap const &Service::pixmap() { +QPixmap const &Service::pixmap() const { if(_image.isNull()) _image.loadFromData(app->download(app->baseUrl() + image)); diff --git a/lib/Service.h b/lib/Service.h index 1d6552f..6ba2be8 100644 --- a/lib/Service.h +++ b/lib/Service.h @@ -8,7 +8,7 @@ struct Service { Service(QJsonObject const &o); - QPixmap const &pixmap(); + QPixmap const &pixmap() const; QString title; QUrl url; @@ -19,7 +19,7 @@ struct Service { bool LDAP; protected: - QPixmap _image; + mutable QPixmap _image; }; class Services:public QList { diff --git a/lib/ServiceWidget.cpp b/lib/ServiceWidget.cpp index 14e1b5d..610379d 100644 --- a/lib/ServiceWidget.cpp +++ b/lib/ServiceWidget.cpp @@ -1,11 +1,17 @@ #include "ServiceWidget.h" -ServiceWidget::ServiceWidget(Service &s, QWidget *parent):QWidget(parent),_layout(QBoxLayout::LeftToRight, this) { +ServiceWidget::ServiceWidget(Service &s, QWidget *parent):QWidget(parent),_layout(QBoxLayout::LeftToRight, this),_s(s) { + _layout.setSpacing(4); _icon = new QLabel(this); _icon->setPixmap(s.pixmap().scaled(32, 32)); _layout.addWidget(_icon); _label = new QLabel(this); _label->setText("

" + s.title + "

" + s.description); _layout.addWidget(_label); - _layout.setSpacing(4); + _go = new QPushButton(tr("Go"), this); + _layout.addWidget(_go); + connect(_go, &QPushButton::clicked, this, &ServiceWidget::goClicked); + _help = new QPushButton(tr("Help"), this); + _layout.addWidget(_help); + connect(_help, &QPushButton::clicked, this, &ServiceWidget::helpClicked); } diff --git a/lib/ServiceWidget.h b/lib/ServiceWidget.h index f0a6d38..89b2dfd 100644 --- a/lib/ServiceWidget.h +++ b/lib/ServiceWidget.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -10,8 +11,15 @@ class ServiceWidget:public QWidget { Q_OBJECT public: ServiceWidget(Service &s, QWidget *parent=0); + Service const &service() const { return _s; } +Q_SIGNALS: + void goClicked(); + void helpClicked(); protected: + Service _s; QBoxLayout _layout; QLabel * _icon; QLabel * _label; + QPushButton * _go; + QPushButton * _help; };