File indexing completed on 2024-05-19 04:58:06

0001 /*
0002     This file is part of Choqok, the KDE micro-blogging client
0003 
0004     SPDX-FileCopyrightText: 2008-2012 Mehrdad Momeny <mehrdad.momeny@gmail.com>
0005 
0006     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0007 */
0008 
0009 #include "addaccountdialog.h"
0010 
0011 #include <QPushButton>
0012 #include <QVBoxLayout>
0013 
0014 #include <KLocalizedString>
0015 #include <KMessageBox>
0016 
0017 #include "accountmanager.h"
0018 #include "accountsdebug.h"
0019 #include "editaccountwidget.h"
0020 
0021 AddAccountDialog::AddAccountDialog(ChoqokEditAccountWidget *addWidget, QWidget *parent, Qt::WindowFlags flags)
0022     : QDialog(parent, flags), widget(addWidget)
0023 {
0024     if (!widget) {
0025         this->deleteLater();
0026         return;
0027     }
0028 
0029     setWindowTitle(i18n("Add New Account"));
0030 
0031     QVBoxLayout *mainLayout = new QVBoxLayout;
0032     setLayout(mainLayout);
0033     mainLayout->addWidget(widget);
0034 
0035     QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
0036     QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
0037     okButton->setDefault(true);
0038     okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
0039     connect(buttonBox, &QDialogButtonBox::accepted, this, &AddAccountDialog::accept);
0040     connect(buttonBox, &QDialogButtonBox::rejected, this, &AddAccountDialog::reject);
0041     mainLayout->addWidget(buttonBox);
0042 }
0043 
0044 AddAccountDialog::~AddAccountDialog()
0045 {
0046 }
0047 
0048 void AddAccountDialog::accept()
0049 {
0050     qCDebug(CHOQOK);
0051     if (widget->validateData()) {
0052         if (Choqok::Account *acc = widget->apply()) {
0053             if (!Choqok::AccountManager::self()->registerAccount(acc)) {
0054                 KMessageBox::detailedError(this, i18n("The Account registration failed."),
0055                                             Choqok::AccountManager::self()->lastError());
0056             } else {
0057                 QDialog::accept();
0058             }
0059         }
0060     } else {
0061       KMessageBox::error(
0062           this, i18n("Cannot validate your input information.\nPlease check "
0063                      "the fields' data.\nMaybe a required field is empty?"));
0064     }
0065 }
0066 
0067 #include "moc_addaccountdialog.cpp"