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

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 "yourlsconfig.h"
0010 
0011 #include <QLineEdit>
0012 #include <QVBoxLayout>
0013 
0014 #include <KAboutData>
0015 #include <KPluginFactory>
0016 
0017 #include "passwordmanager.h"
0018 
0019 #include "yourlssettings.h"
0020 
0021 K_PLUGIN_CLASS_WITH_JSON(YourlsConfig, "choqok_yourls_config.json")
0022 
0023 YourlsConfig::YourlsConfig(QWidget *parent, const QVariantList &):
0024     KCModule(parent)
0025 {
0026     QVBoxLayout *layout = new QVBoxLayout(this);
0027     QWidget *wd = new QWidget(this);
0028     wd->setObjectName(QLatin1String("mYourlsCtl"));
0029     ui.setupUi(wd);
0030     addConfig(YourlsSettings::self(), wd);
0031     layout->addWidget(wd);
0032     connect(ui.kcfg_username, &QLineEdit::textChanged, this, &YourlsConfig::emitChanged);
0033     connect(ui.cfg_password, &QLineEdit::textChanged, this, &YourlsConfig::emitChanged);
0034 }
0035 
0036 YourlsConfig::~YourlsConfig()
0037 {
0038 
0039 }
0040 
0041 void YourlsConfig::load()
0042 {
0043     KCModule::load();
0044     ui.cfg_password->setText(Choqok::PasswordManager::self()->readPassword(QStringLiteral("yourls_%1")
0045                              .arg(ui.kcfg_username->text())));
0046 }
0047 
0048 void YourlsConfig::save()
0049 {
0050     KCModule::save();
0051     Choqok::PasswordManager::self()->writePassword(QStringLiteral("yourls_%1").arg(ui.kcfg_username->text()),
0052             ui.cfg_password->text());
0053 }
0054 
0055 void YourlsConfig::emitChanged()
0056 {
0057     Q_EMIT changed(true);
0058     disconnect(ui.kcfg_username, &QLineEdit::textChanged, this, &YourlsConfig::emitChanged);
0059     disconnect(ui.cfg_password, &QLineEdit::textChanged, this, &YourlsConfig::emitChanged);
0060 }
0061 
0062 #include "moc_yourlsconfig.cpp"
0063 #include "yourlsconfig.moc"