File indexing completed on 2024-12-22 04:40:47
0001 /* 0002 This file is part of Choqok, the KDE micro-blogging client 0003 0004 SPDX-FileCopyrightText: 2010-2012 Andrey Esin <gmlastik@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 "posterousconfig.h" 0010 0011 #include <QComboBox> 0012 #include <QLineEdit> 0013 #include <QRadioButton> 0014 #include <QVBoxLayout> 0015 0016 #include <KAboutData> 0017 #include <KLocalizedString> 0018 #include <KPluginFactory> 0019 #include <KMessageBox> 0020 0021 #include "accountmanager.h" 0022 #include "passwordmanager.h" 0023 0024 #include "posteroussettings.h" 0025 0026 K_PLUGIN_CLASS_WITH_JSON(PosterousConfig, "choqok_posterous_config.json") 0027 0028 PosterousConfig::PosterousConfig(QWidget *parent, const QVariantList &) : 0029 KCModule(parent) 0030 { 0031 QVBoxLayout *layout = new QVBoxLayout(this); 0032 QWidget *wd = new QWidget(this); 0033 wd->setObjectName(QLatin1String("mPosterousCtl")); 0034 ui.setupUi(wd); 0035 addConfig(PosterousSettings::self(), wd); 0036 layout->addWidget(wd); 0037 ui.cfg_password->setEchoMode(QLineEdit::Password); 0038 connect(ui.cfg_basic, &QRadioButton::clicked, this, &PosterousConfig::emitChanged); 0039 connect(ui.cfg_login, &QLineEdit::textChanged, this, &PosterousConfig::emitChanged); 0040 connect(ui.cfg_password, &QLineEdit::textChanged, this, &PosterousConfig::emitChanged); 0041 connect(ui.cfg_oauth, &QRadioButton::clicked, this, &PosterousConfig::emitChanged); 0042 connect(ui.cfg_accountsList, (void (QComboBox::*)(int))&QComboBox::currentIndexChanged, 0043 this, &PosterousConfig::emitChanged); 0044 } 0045 0046 PosterousConfig::~PosterousConfig() 0047 { 0048 0049 } 0050 0051 void PosterousConfig::load() 0052 { 0053 KCModule::load(); 0054 QList<Choqok::Account *> list = Choqok::AccountManager::self()->accounts(); 0055 for (Choqok::Account *acc: list) { 0056 if (acc->inherits("TwitterAccount")) { 0057 ui.cfg_accountsList->addItem(acc->alias()); 0058 } 0059 } 0060 PosterousSettings::self()->load(); 0061 ui.cfg_basic->setChecked(PosterousSettings::basic()); 0062 ui.cfg_login->setText(PosterousSettings::login()); 0063 ui.cfg_password->setText(Choqok::PasswordManager::self()->readPassword(QStringLiteral("posterous_%1") 0064 .arg(ui.cfg_login->text()))); 0065 ui.cfg_oauth->setChecked(PosterousSettings::oauth()); 0066 ui.cfg_accountsList->setCurrentText(PosterousSettings::alias()); 0067 emitChanged(); 0068 } 0069 0070 void PosterousConfig::save() 0071 { 0072 if (ui.cfg_accountsList->currentIndex() > -1) { 0073 PosterousSettings::setAlias(ui.cfg_accountsList->currentText()); 0074 //qDebug() << PosterousSettings::alias(); 0075 } else { 0076 PosterousSettings::setAlias(QString()); 0077 KMessageBox::error(this, i18n("You have to configure at least one Twitter account to use this plugin.")); 0078 } 0079 0080 PosterousSettings::setBasic(ui.cfg_basic->isChecked()); 0081 PosterousSettings::setLogin(ui.cfg_login->text()); 0082 Choqok::PasswordManager::self()->writePassword(QStringLiteral("posterous_%1").arg(ui.cfg_login->text()), 0083 ui.cfg_password->text()); 0084 PosterousSettings::setOauth(ui.cfg_oauth->isChecked()); 0085 PosterousSettings::self()->save(); 0086 KCModule::save(); 0087 } 0088 0089 void PosterousConfig::emitChanged() 0090 { 0091 ui.cfg_login->setEnabled(ui.cfg_basic->isChecked()); 0092 ui.cfg_password->setEnabled(ui.cfg_basic->isChecked()); 0093 ui.cfg_accountsList->setEnabled(ui.cfg_oauth->isChecked()); 0094 Q_EMIT changed(true); 0095 } 0096 0097 #include "moc_posterousconfig.cpp" 0098 #include "posterousconfig.moc"