#include "ServicesDialog.h" #include "ServiceWidget.h" #include "Configurator.h" #include "HelpBrowser.h" #include #include #include #include #include ServicesDialog::ServicesDialog(QWidget *parent):QDialog(parent),_layout(this) { int y = 0; _welcome = new QLabel(tr("Welcome to your Federated Computer\n" "We can automatically configure these services for you:"), this); _layout.addWidget(_welcome, y, 0); _knownServicesScroller = new QScrollArea(this); _knownServices = new QWidget(this); QBoxLayout *ksLayout = new QBoxLayout(QBoxLayout::TopToBottom, _knownServices); _layout.addWidget(_knownServicesScroller, ++y, 0); _usLabel = new QLabel(tr("Your subscription also includes the following services, which can not currently be auto-configured, but you can configure them manually:"), this); _layout.addWidget(_usLabel, ++y, 0); _unknownServicesScroller = new QScrollArea(this); _unknownServices = new QWidget(this); QBoxLayout *usLayout = new QBoxLayout(QBoxLayout::TopToBottom, _unknownServices); _layout.addWidget(_unknownServicesScroller, ++y, 0); int k = 0, u = 0; for(auto i : app->services()) { ServiceWidget *w; if(i.title == "Nextcloud" || i.title == "Panel") { w=new ServiceWidget(i, _knownServices); ksLayout->addWidget(w, ++k); } else { 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); _knownServicesScroller->setWidget(_knownServices); _unknownServicesScroller->setWidget(_unknownServices); _buttons = new ButtonRow(this); QPushButton *ok = new QPushButton(tr("&OK"), _buttons); connect(ok, &QPushButton::clicked, this, &QDialog::accept); ok->setDefault(true); QPushButton *cancel = new QPushButton(tr("&Cancel"), _buttons); connect(cancel, &QPushButton::clicked, this, &QDialog::reject); _buttons->add(ok); _buttons->add(cancel); _layout.addWidget(_buttons, ++y, 0); 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 if(e) QDialog::resizeEvent(e); int const w = _knownServicesScroller->width(); _knownServices->setFixedWidth(w); _unknownServices->setFixedWidth(w); }