File indexing completed on 2024-11-24 04:44:30

0001 /*
0002     SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "configwidget.h"
0008 
0009 #include "oxa/connectiontestjob.h"
0010 #include "settings.h"
0011 #include "ui_configwidget.h"
0012 
0013 #include <KConfigDialogManager>
0014 #include <KMessageBox>
0015 
0016 #include <KLocalizedString>
0017 #include <QPushButton>
0018 
0019 ConfigWidget::ConfigWidget(Settings *settings, QWidget *parent)
0020     : QWidget(parent)
0021 {
0022     Ui::ConfigWidget ui;
0023     ui.setupUi(this);
0024 
0025     ui.kcfg_BaseUrl->setWhatsThis(i18n("Enter the http or https URL to your Open-Xchange installation here."));
0026     ui.kcfg_Username->setWhatsThis(i18n("Enter the username of your Open-Xchange account here."));
0027     ui.kcfg_Password->setWhatsThis(i18n("Enter the password of your Open-Xchange account here."));
0028 
0029     mServerEdit = ui.kcfg_BaseUrl;
0030     mUserEdit = ui.kcfg_Username;
0031     mPasswordEdit = ui.kcfg_Password;
0032     mCheckConnectionButton = ui.checkConnectionButton;
0033 
0034     mManager = new KConfigDialogManager(this, settings);
0035 
0036     connect(mServerEdit, &QLineEdit::textChanged, this, &ConfigWidget::updateButtonState);
0037     connect(mUserEdit, &QLineEdit::textChanged, this, &ConfigWidget::updateButtonState);
0038     connect(mCheckConnectionButton, &QPushButton::clicked, this, &ConfigWidget::checkConnection);
0039 
0040     resize(QSize(410, 200));
0041 }
0042 
0043 void ConfigWidget::load()
0044 {
0045     mManager->updateWidgets();
0046 }
0047 
0048 void ConfigWidget::save() const
0049 {
0050     mManager->updateSettings();
0051 }
0052 
0053 void ConfigWidget::updateButtonState()
0054 {
0055     mCheckConnectionButton->setEnabled(!mServerEdit->text().isEmpty() && !mUserEdit->text().isEmpty());
0056 }
0057 
0058 void ConfigWidget::checkConnection()
0059 {
0060     auto job = new OXA::ConnectionTestJob(mServerEdit->text(), mUserEdit->text(), mPasswordEdit->text(), this);
0061     connect(job, &OXA::ConnectionTestJob::result, this, &ConfigWidget::checkConnectionJobFinished);
0062     job->start();
0063 
0064     QApplication::setOverrideCursor(Qt::WaitCursor);
0065 }
0066 
0067 void ConfigWidget::checkConnectionJobFinished(KJob *job)
0068 {
0069     QApplication::restoreOverrideCursor();
0070 
0071     if (job->error()) {
0072         KMessageBox::error(this, i18n("Unable to connect: %1", job->errorText()), i18n("Connection error"));
0073     } else {
0074         KMessageBox::information(this, i18n("Tested connection successfully."), i18n("Connection success"));
0075     }
0076 }
0077 
0078 #include "moc_configwidget.cpp"