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 : 2012-04-04 0007 * Description : Web Service Tool dialog 0008 * 0009 * SPDX-FileCopyrightText: 2012-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #include "wstooldialog.h" 0016 0017 // Qt includes 0018 0019 #include <QIcon> 0020 #include <QAction> 0021 #include <QMenu> 0022 #include <QVBoxLayout> 0023 #include <QPushButton> 0024 0025 // KDE includes 0026 0027 #include <klocalizedstring.h> 0028 0029 // Local includes 0030 0031 #include "digikam_debug.h" 0032 #include "dpluginaboutdlg.h" 0033 0034 namespace Digikam 0035 { 0036 0037 class Q_DECL_HIDDEN WSToolDialog::Private 0038 { 0039 public: 0040 0041 explicit Private() 0042 : startButton (nullptr), 0043 mainWidget (nullptr), 0044 propagateReject(true) 0045 { 0046 } 0047 0048 QPushButton* startButton; 0049 QWidget* mainWidget; 0050 0051 bool propagateReject; 0052 }; 0053 0054 WSToolDialog::WSToolDialog(QWidget* const parent, const QString& objName) 0055 : DPluginDialog(parent, objName), 0056 d (new Private) 0057 { 0058 m_buttons->addButton(QDialogButtonBox::Close); 0059 m_buttons->button(QDialogButtonBox::Close)->setDefault(true); 0060 d->startButton = new QPushButton(i18nc("@action:button", "&Start"), this); 0061 d->startButton->setIcon(QIcon::fromTheme(QLatin1String("media-playback-start"))); 0062 m_buttons->addButton(d->startButton, QDialogButtonBox::ActionRole); 0063 0064 QVBoxLayout* const mainLayout = new QVBoxLayout(this); 0065 mainLayout->addWidget(m_buttons); 0066 setLayout(mainLayout); 0067 0068 connect(m_buttons, &QDialogButtonBox::rejected, 0069 this, &WSToolDialog::slotCloseClicked); 0070 } 0071 0072 WSToolDialog::~WSToolDialog() 0073 { 0074 delete d; 0075 } 0076 0077 void WSToolDialog::setMainWidget(QWidget* const widget) 0078 { 0079 if (d->mainWidget == widget) 0080 { 0081 return; 0082 } 0083 0084 layout()->removeWidget(m_buttons); 0085 0086 if (d->mainWidget) 0087 { 0088 // Replace existing widget 0089 0090 layout()->removeWidget(d->mainWidget); 0091 delete d->mainWidget; 0092 } 0093 0094 d->mainWidget = widget; 0095 layout()->addWidget(d->mainWidget); 0096 layout()->addWidget(m_buttons); 0097 } 0098 0099 void WSToolDialog::setRejectButtonMode(QDialogButtonBox::StandardButton button) 0100 { 0101 if (button == QDialogButtonBox::Close) 0102 { 0103 m_buttons->button(QDialogButtonBox::Close)->setText(i18n("Close")); 0104 m_buttons->button(QDialogButtonBox::Close)->setIcon(QIcon::fromTheme(QLatin1String("window-close"))); 0105 m_buttons->button(QDialogButtonBox::Close)->setToolTip(i18n("Close window")); 0106 d->propagateReject = true; 0107 } 0108 else if (button == QDialogButtonBox::Cancel) 0109 { 0110 m_buttons->button(QDialogButtonBox::Close)->setText(i18n("Cancel")); 0111 m_buttons->button(QDialogButtonBox::Close)->setIcon(QIcon::fromTheme(QLatin1String("dialog-cancel"))); 0112 m_buttons->button(QDialogButtonBox::Close)->setToolTip(i18n("Cancel current operation")); 0113 d->propagateReject = false; 0114 } 0115 else 0116 { 0117 qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Unexpected button mode passed"; 0118 } 0119 } 0120 0121 QPushButton* WSToolDialog::startButton() const 0122 { 0123 return d->startButton; 0124 } 0125 0126 void WSToolDialog::addButton(QAbstractButton* button, QDialogButtonBox::ButtonRole role) 0127 { 0128 m_buttons->addButton(button, role); 0129 } 0130 0131 void WSToolDialog::slotCloseClicked() 0132 { 0133 if (d->propagateReject) 0134 { 0135 reject(); 0136 } 0137 else 0138 { 0139 Q_EMIT cancelClicked(); 0140 } 0141 } 0142 0143 } // namespace Digikam 0144 0145 #include "moc_wstooldialog.cpp"