2024-09-03 13:40:08 +00:00
# include "ServicesDialog.h"
# include "ServiceWidget.h"
# include "Configurator.h"
2024-09-03 16:59:36 +00:00
# include "HelpBrowser.h"
2024-09-03 13:40:08 +00:00
2024-09-03 16:59:36 +00:00
# include <QWebEngineView>
# include <QWebEngineHttpRequest>
# include <QUrlQuery>
2024-09-03 13:40:08 +00:00
# include <QScrollBar>
# include <iostream>
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 ( ) ) {
2024-09-03 16:59:36 +00:00
ServiceWidget * w ;
2024-09-03 13:40:08 +00:00
if ( i . title = = " Nextcloud " | | i . title = = " Panel " ) {
2024-09-03 16:59:36 +00:00
w = new ServiceWidget ( i , _knownServices ) ;
2024-09-03 13:40:08 +00:00
ksLayout - > addWidget ( w , + + k ) ;
} else {
2024-09-03 16:59:36 +00:00
w = new ServiceWidget ( i , _unknownServices ) ;
2024-09-03 13:40:08 +00:00
usLayout - > addWidget ( w , + + u ) ;
}
2024-09-03 16:59:36 +00:00
connect ( w , & ServiceWidget : : goClicked , this , & ServicesDialog : : configureService ) ;
connect ( w , & ServiceWidget : : helpClicked , this , & ServicesDialog : : serviceHelp ) ;
2024-09-03 13:40:08 +00:00
}
_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 ) ;
}
2024-09-03 16:59:36 +00:00
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 ( ) ;
}
2024-09-03 13:40:08 +00:00
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 ) ;
}