File indexing completed on 2025-01-19 03:55:41
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2015-16-05 0007 * Description : a dialog to select user for Web Service tools 0008 * 0009 * SPDX-FileCopyrightText: 2015 by Shourya Singh Gupta <shouryasgupta at gmail dot com> 0010 * SPDX-FileCopyrightText: 2016-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #include "wsselectuserdlg.h" 0017 0018 // Qt includes 0019 0020 #include <QPushButton> 0021 #include <QLabel> 0022 #include <QVBoxLayout> 0023 #include <QDialogButtonBox> 0024 #include <QIcon> 0025 #include <QComboBox> 0026 0027 // KDE includes 0028 0029 #include <klocalizedstring.h> 0030 #include <ksharedconfig.h> 0031 #include <kconfiggroup.h> 0032 0033 namespace Digikam 0034 { 0035 0036 class Q_DECL_HIDDEN WSSelectUserDlg::Private 0037 { 0038 public: 0039 0040 explicit Private() 0041 : userComboBox(nullptr), 0042 label (nullptr), 0043 okButton (nullptr) 0044 { 0045 } 0046 0047 QComboBox* userComboBox; 0048 QLabel* label; 0049 QPushButton* okButton; 0050 QString userName; 0051 QString serviceName; 0052 }; 0053 0054 WSSelectUserDlg::WSSelectUserDlg(QWidget* const parent, const QString& serviceName) 0055 : QDialog(parent), 0056 d (new Private) 0057 { 0058 d->serviceName = serviceName; 0059 0060 setWindowTitle(i18nc("@title:window", "Account Selector")); 0061 setModal(true); 0062 0063 QDialogButtonBox* const buttonBox = new QDialogButtonBox(); 0064 QPushButton* const buttonNewAccount = new QPushButton(buttonBox); 0065 buttonNewAccount->setText(i18n("Add another account")); 0066 buttonNewAccount->setIcon(QIcon::fromTheme(QLatin1String("network-workgroup"))); 0067 0068 buttonBox->addButton(buttonNewAccount, QDialogButtonBox::AcceptRole); 0069 buttonBox->addButton(QDialogButtonBox::Ok); 0070 buttonBox->addButton(QDialogButtonBox::Close); 0071 0072 buttonBox->button(QDialogButtonBox::Close)->setDefault(true); 0073 0074 d->okButton = buttonBox->button(QDialogButtonBox::Ok); 0075 0076 if (d->serviceName == QLatin1String("23")) 0077 { 0078 setWindowIcon(QIcon::fromTheme(QLatin1String("hq"))); 0079 } 0080 else 0081 { 0082 setWindowIcon(QIcon::fromTheme(QLatin1String("dk-flickr"))); 0083 } 0084 0085 d->userName = QString(); 0086 d->label = new QLabel(this); 0087 d->label->setText(i18n("Choose the %1 account to use for exporting images:", d->serviceName)); 0088 d->userComboBox = new QComboBox(this); 0089 0090 QVBoxLayout* const mainLayout = new QVBoxLayout(this); 0091 mainLayout->addWidget(d->label); 0092 mainLayout->addWidget(d->userComboBox); 0093 mainLayout->addWidget(buttonBox); 0094 setLayout(mainLayout); 0095 0096 connect(buttonBox, SIGNAL(accepted()), 0097 this, SLOT(accept())); 0098 0099 connect(buttonBox, SIGNAL(rejected()), 0100 this, SLOT(reject())); 0101 0102 connect(buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), 0103 this, SLOT(slotOkClicked())); 0104 0105 connect(buttonNewAccount, SIGNAL(clicked()), 0106 this, SLOT(slotNewAccountClicked())); 0107 } 0108 0109 WSSelectUserDlg::~WSSelectUserDlg() 0110 { 0111 delete d->userComboBox; 0112 delete d->label; 0113 delete d; 0114 } 0115 0116 void WSSelectUserDlg::reactivate() 0117 { 0118 KSharedConfigPtr config = KSharedConfig::openConfig(); 0119 0120 d->userComboBox->clear(); 0121 0122 Q_FOREACH (const QString& group, config->groupList()) 0123 { 0124 if (!(group.contains(d->serviceName))) 0125 { 0126 continue; 0127 } 0128 0129 KConfigGroup grp = config->group(group); 0130 0131 if (QString::compare(grp.readEntry(QLatin1String("username")), QString(), Qt::CaseInsensitive) == 0) 0132 { 0133 continue; 0134 } 0135 0136 d->userComboBox->addItem(grp.readEntry(QLatin1String("username"))); 0137 } 0138 0139 d->okButton->setEnabled(d->userComboBox->count() > 0); 0140 0141 exec(); 0142 } 0143 0144 void WSSelectUserDlg::slotOkClicked() 0145 { 0146 d->userName = d->userComboBox->currentText(); 0147 } 0148 0149 void WSSelectUserDlg::slotNewAccountClicked() 0150 { 0151 d->userName = QString(); 0152 } 0153 0154 QString WSSelectUserDlg::getUserName() const 0155 { 0156 return d->userName; 0157 } 0158 0159 } // namespace Digikam 0160 0161 #include "moc_wsselectuserdlg.cpp"