Help browser, panel login

This commit is contained in:
Bernhard Rosenkränzer 2024-09-03 18:59:36 +02:00
parent 32af5c8e93
commit 2216fedeaa
10 changed files with 102 additions and 10 deletions

View File

@ -13,6 +13,8 @@ public:
Configurator(int &argc, char **&argv); Configurator(int &argc, char **&argv);
QNetworkAccessManager &nam() { return _nam; } QNetworkAccessManager &nam() { return _nam; }
QString baseUrl() const { return "https://dashboard." + _loginDialog->domain(); } 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); QByteArray download(QUrl const &url);
void waitForDownload(QNetworkReply *r) const; void waitForDownload(QNetworkReply *r) const;
Services const &services() const { return _services; } Services const &services() const { return _services; }

View File

@ -2,5 +2,5 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_SOURCE_DIR}) include_directories(${CMAKE_SOURCE_DIR})
include_directories(${CMAKE_SOURCE_DIR}/lib) include_directories(${CMAKE_SOURCE_DIR}/lib)
add_library(dialogs STATIC FederatedLogin.cpp ServicesDialog.cpp) 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 fed) target_link_libraries(dialogs Qt${QT_VERSION}::Core Qt${QT_VERSION}::Gui Qt${QT_VERSION}::Widgets Qt${QT_VERSION}::WebEngineWidgets fed)

20
dialogs/HelpBrowser.cpp Normal file
View File

@ -0,0 +1,20 @@
#include "HelpBrowser.h"
#include <QToolBar>
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();
}

17
dialogs/HelpBrowser.h Normal file
View File

@ -0,0 +1,17 @@
#pragma once
#include <QMainWindow>
#include <QBoxLayout>
#include <QUrl>
#include <QWebEngineView>
#include <QCloseEvent>
class HelpBrowser:public QMainWindow {
Q_OBJECT
public:
HelpBrowser(QUrl const &url, QWidget *parent = nullptr);
protected:
void closeEvent(QCloseEvent *e) override;
protected:
QWebEngineView * _browser;
};

View File

@ -1,7 +1,11 @@
#include "ServicesDialog.h" #include "ServicesDialog.h"
#include "ServiceWidget.h" #include "ServiceWidget.h"
#include "Configurator.h" #include "Configurator.h"
#include "HelpBrowser.h"
#include <QWebEngineView>
#include <QWebEngineHttpRequest>
#include <QUrlQuery>
#include <QScrollBar> #include <QScrollBar>
#include <iostream> #include <iostream>
@ -23,13 +27,16 @@ ServicesDialog::ServicesDialog(QWidget *parent):QDialog(parent),_layout(this) {
_layout.addWidget(_unknownServicesScroller, ++y, 0); _layout.addWidget(_unknownServicesScroller, ++y, 0);
int k = 0, u = 0; int k = 0, u = 0;
for(auto i : app->services()) { for(auto i : app->services()) {
ServiceWidget *w;
if(i.title == "Nextcloud" || i.title == "Panel") { if(i.title == "Nextcloud" || i.title == "Panel") {
ServiceWidget *w=new ServiceWidget(i, _knownServices); w=new ServiceWidget(i, _knownServices);
ksLayout->addWidget(w, ++k); ksLayout->addWidget(w, ++k);
} else { } else {
ServiceWidget *w=new ServiceWidget(i, _unknownServices); w=new ServiceWidget(i, _unknownServices);
usLayout->addWidget(w, ++u); usLayout->addWidget(w, ++u);
} }
connect(w, &ServiceWidget::goClicked, this, &ServicesDialog::configureService);
connect(w, &ServiceWidget::helpClicked, this, &ServicesDialog::serviceHelp);
} }
_knownServicesScroller->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); _knownServicesScroller->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
_unknownServicesScroller->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); _unknownServicesScroller->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
@ -47,6 +54,35 @@ ServicesDialog::ServicesDialog(QWidget *parent):QDialog(parent),_layout(this) {
resizeEvent(0); resizeEvent(0);
} }
void ServicesDialog::configureService() {
ServiceWidget *w=qobject_cast<ServiceWidget*>(sender());
if(!w)
return;
QWebEngineView *v = new QWebEngineView(static_cast<QWidget*>(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<ServiceWidget*>(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) { void ServicesDialog::resizeEvent(QResizeEvent *e) {
// Make sure the known services and unknown services // Make sure the known services and unknown services
// lists always use the full width available // lists always use the full width available

View File

@ -12,7 +12,10 @@
class ServicesDialog:public QDialog { class ServicesDialog:public QDialog {
Q_OBJECT Q_OBJECT
public: public:
ServicesDialog(QWidget *parent=0); ServicesDialog(QWidget *parent=nullptr);
protected Q_SLOTS:
void configureService();
void serviceHelp();
protected: protected:
void resizeEvent(QResizeEvent *e) override; void resizeEvent(QResizeEvent *e) override;
protected: protected:

View File

@ -15,7 +15,7 @@ Service::Service(QJsonObject const &o) {
LDAP = o["LDAP"].toBool(); LDAP = o["LDAP"].toBool();
} }
QPixmap const &Service::pixmap() { QPixmap const &Service::pixmap() const {
if(_image.isNull()) if(_image.isNull())
_image.loadFromData(app->download(app->baseUrl() + image)); _image.loadFromData(app->download(app->baseUrl() + image));

View File

@ -8,7 +8,7 @@
struct Service { struct Service {
Service(QJsonObject const &o); Service(QJsonObject const &o);
QPixmap const &pixmap(); QPixmap const &pixmap() const;
QString title; QString title;
QUrl url; QUrl url;
@ -19,7 +19,7 @@ struct Service {
bool LDAP; bool LDAP;
protected: protected:
QPixmap _image; mutable QPixmap _image;
}; };
class Services:public QList<Service> { class Services:public QList<Service> {

View File

@ -1,11 +1,17 @@
#include "ServiceWidget.h" #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 = new QLabel(this);
_icon->setPixmap(s.pixmap().scaled(32, 32)); _icon->setPixmap(s.pixmap().scaled(32, 32));
_layout.addWidget(_icon); _layout.addWidget(_icon);
_label = new QLabel(this); _label = new QLabel(this);
_label->setText("<h3>" + s.title + "</h3>" + s.description); _label->setText("<h3>" + s.title + "</h3>" + s.description);
_layout.addWidget(_label); _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);
} }

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <QWidget> #include <QWidget>
#include <QPushButton>
#include <QBoxLayout> #include <QBoxLayout>
#include <QLabel> #include <QLabel>
@ -10,8 +11,15 @@ class ServiceWidget:public QWidget {
Q_OBJECT Q_OBJECT
public: public:
ServiceWidget(Service &s, QWidget *parent=0); ServiceWidget(Service &s, QWidget *parent=0);
Service const &service() const { return _s; }
Q_SIGNALS:
void goClicked();
void helpClicked();
protected: protected:
Service _s;
QBoxLayout _layout; QBoxLayout _layout;
QLabel * _icon; QLabel * _icon;
QLabel * _label; QLabel * _label;
QPushButton * _go;
QPushButton * _help;
}; };