File indexing completed on 2025-01-05 03:59:39

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2013-09-16
0007  * Description : Dialog to prompt users about versioning
0008  *
0009  * SPDX-FileCopyrightText: 2010-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0010  * SPDX-FileCopyrightText: 2013-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 "versioningpromptusersavedlg.h"
0017 
0018 // Qt includes
0019 
0020 #include <QToolButton>
0021 #include <QGridLayout>
0022 #include <QVBoxLayout>
0023 #include <QLabel>
0024 #include <QIcon>
0025 #include <QPushButton>
0026 #include <QDialogButtonBox>
0027 #include <QStyle>
0028 #include <QApplication>
0029 
0030 // KDE includes
0031 
0032 #include <klocalizedstring.h>
0033 
0034 // Local includes
0035 
0036 #include "digikam_globals.h"
0037 #include "dxmlguiwindow.h"
0038 
0039 namespace Digikam
0040 {
0041 
0042 class Q_DECL_HIDDEN VersioningPromptUserSaveDialog::Private
0043 {
0044 public:
0045 
0046     explicit Private()
0047         : clicked(QDialogButtonBox::NoButton),
0048           buttons(nullptr)
0049     {
0050     }
0051 
0052 public:
0053 
0054     QDialogButtonBox::StandardButton clicked;
0055     QDialogButtonBox*                buttons;
0056 };
0057 
0058 VersioningPromptUserSaveDialog::VersioningPromptUserSaveDialog(QWidget* const parent)
0059     : QDialog(parent),
0060       d      (new Private)
0061 {
0062     setWindowTitle(i18nc("@title:window", "Save?"));
0063 
0064     d->buttons = new QDialogButtonBox(QDialogButtonBox::Ok      |  // Save Changes
0065                                       QDialogButtonBox::Apply   |  // Save Changes as a New Version
0066                                       QDialogButtonBox::Discard |  // Discard Changes
0067                                       QDialogButtonBox::Help    |  // Online doc
0068                                       QDialogButtonBox::Cancel,
0069                                       this);
0070 
0071     d->buttons->button(QDialogButtonBox::Cancel)->setDefault(true);
0072 
0073     d->buttons->button(QDialogButtonBox::Ok)->setText(i18nc("@action:button", "Save Changes"));
0074     d->buttons->button(QDialogButtonBox::Ok)->setIcon(QIcon::fromTheme(QLatin1String("dialog-ok-apply")));
0075     d->buttons->button(QDialogButtonBox::Ok)->setToolTip(i18nc("@info:tooltip",
0076                                                                "Save the current changes. Note: The original image will never be overwritten."));
0077 
0078     d->buttons->button(QDialogButtonBox::Apply)->setText(i18nc("@action:button", "Save Changes as a New Version"));
0079     d->buttons->button(QDialogButtonBox::Apply)->setIcon(QIcon::fromTheme(QLatin1String("list-add")));
0080     d->buttons->button(QDialogButtonBox::Apply)->setToolTip(i18nc("@info:tooltip",
0081                                                                   "Save the current changes as a new version. "
0082                                                                   "The loaded file will remain unchanged, a new file will be created."));
0083 
0084     d->buttons->button(QDialogButtonBox::Discard)->setText(i18nc("@action:button", "Discard Changes"));
0085     d->buttons->button(QDialogButtonBox::Discard)->setIcon(QIcon::fromTheme(QLatin1String("task-reject")));
0086     d->buttons->button(QDialogButtonBox::Discard)->setToolTip(i18nc("@info:tooltip",
0087                                                                     "Discard the changes applied to the image during this editing session."));
0088 
0089     connect(d->buttons, SIGNAL(clicked(QAbstractButton*)),
0090             this, SLOT(slotButtonClicked(QAbstractButton*)));
0091 
0092     QWidget* const mainWidget = new QWidget;
0093 
0094     // -- Icon and Header --
0095 
0096     QLabel* const warningIcon = new QLabel;
0097     warningIcon->setPixmap(QIcon::fromTheme(QLatin1String("dialog-warning")).pixmap(style()->pixelMetric(QStyle::PM_MessageBoxIconSize, nullptr, this)));
0098     QLabel* const question    = new QLabel;
0099     question->setTextFormat(Qt::RichText);
0100     question->setText(i18nc("@label",
0101                             "The current image has been changed.\n"
0102                             "Do you wish to save your changes?"));
0103     QLabel* const editIcon    = new QLabel;
0104     editIcon->setPixmap(QIcon::fromTheme(QLatin1String("document-edit")).pixmap(style()->pixelMetric(QStyle::PM_MessageBoxIconSize, nullptr, this)));
0105 
0106     QHBoxLayout* const headerLayout = new QHBoxLayout;
0107     headerLayout->addWidget(warningIcon);
0108     headerLayout->addWidget(question, 10, Qt::AlignCenter);
0109     headerLayout->addWidget(editIcon);
0110     mainWidget->setLayout(headerLayout);
0111 
0112     // -- Layouts --
0113 
0114     QVBoxLayout* const vbx = new QVBoxLayout(this);
0115     vbx->addWidget(mainWidget);
0116     vbx->addWidget(d->buttons);
0117     setLayout(vbx);
0118 }
0119 
0120 VersioningPromptUserSaveDialog::~VersioningPromptUserSaveDialog()
0121 {
0122     delete d;
0123 }
0124 
0125 void VersioningPromptUserSaveDialog::slotButtonClicked(QAbstractButton* button)
0126 {
0127     d->clicked = d->buttons->standardButton(button);
0128 
0129     if      (d->clicked == QDialogButtonBox::Cancel)
0130     {
0131         reject();
0132 
0133         return;
0134     }
0135     else if (d->clicked == QDialogButtonBox::Help)
0136     {
0137         openOnlineDocumentation(QLatin1String("setup_application"), QLatin1String("editor_settings"), QLatin1String("versioning-settings"));
0138 
0139         return;
0140     }
0141 
0142     accept();
0143 }
0144 
0145 bool VersioningPromptUserSaveDialog::shallSave() const
0146 {
0147     return (d->clicked == QDialogButtonBox::Ok);
0148 }
0149 
0150 bool VersioningPromptUserSaveDialog::newVersion() const
0151 {
0152     return (d->clicked == QDialogButtonBox::Apply);
0153 }
0154 
0155 bool VersioningPromptUserSaveDialog::shallDiscard() const
0156 {
0157     return (d->clicked == QDialogButtonBox::Discard);
0158 }
0159 
0160 } // namespace Digikam
0161 
0162 #include "moc_versioningpromptusersavedlg.cpp"