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-08-01
0007  * Description : new album creation dialog for remote web service.
0008  *
0009  * SPDX-FileCopyrightText: 2010 by Jens Mueller <tschenser at gmx dot de>
0010  * SPDX-FileCopyrightText: 2015 by Shourya Singh Gupta <shouryasgupta at gmail dot com>
0011  * SPDX-FileCopyrightText: 2018 by Thanh Trung Dinh <dinhthanhtrung1996 at gmail dot com>
0012  *
0013  * SPDX-License-Identifier: GPL-2.0-or-later
0014  *
0015  * ============================================================ */
0016 
0017 #include "wsnewalbumdialog.h"
0018 
0019 // Qt includes
0020 
0021 #include <QHBoxLayout>
0022 #include <QIcon>
0023 #include <QApplication>
0024 #include <QPushButton>
0025 
0026 // KDE includes
0027 
0028 #include <klocalizedstring.h>
0029 
0030 namespace Digikam
0031 {
0032 
0033 class Q_DECL_HIDDEN WSNewAlbumDialog::Private
0034 {
0035 public:
0036 
0037     explicit Private(QWidget* const widget, const QString& name)
0038       : toolName  (name),
0039         mainWidget(widget)
0040     {
0041         titleEdt       = new DTextEdit(1, nullptr);
0042         descEdt        = new DTextEdit(0, nullptr);
0043         locEdt         = new DTextEdit;
0044         dtEdt          = new QDateTimeEdit(QDateTime::currentDateTime());
0045 
0046         mainLayout     = new QVBoxLayout(mainWidget);
0047 
0048         albumBox       = new QGroupBox(i18nc("@title: album properties", "Album"), mainWidget);
0049         albumBoxLayout = new QGridLayout(albumBox);
0050 
0051         titleLabel     = new QLabel(i18nc("@label: album properties", "Title: "),       albumBox);
0052         dateLabel      = new QLabel(i18nc("@label: album properties", "Time Stamp: "),  albumBox);
0053         descLabel      = new QLabel(i18nc("@label: album properties", "Description: "), albumBox);
0054         locLabel       = new QLabel(i18nc("@label: album properties", "Location: "),    albumBox);
0055 
0056         buttonBox      = new QDialogButtonBox();
0057     }
0058 
0059     DTextEdit*         titleEdt;
0060     DTextEdit*         descEdt;
0061     DTextEdit*         locEdt;
0062     QDateTimeEdit*     dtEdt;
0063 
0064     QLabel*            titleLabel;
0065     QLabel*            dateLabel;
0066     QLabel*            descLabel;
0067     QLabel*            locLabel;
0068 
0069     QString            toolName;
0070     QDialogButtonBox*  buttonBox;
0071 
0072     QGridLayout*       albumBoxLayout;
0073     QGroupBox*         albumBox;
0074 
0075     QVBoxLayout*       mainLayout;
0076     QWidget*           mainWidget;
0077 };
0078 
0079 WSNewAlbumDialog::WSNewAlbumDialog(QWidget* const parent, const QString& toolName)
0080     : QDialog(parent),
0081       d      (new Private(this, toolName))
0082 {
0083     d->mainWidget->setMinimumSize(500, 500);
0084     setWindowTitle(QString(d->toolName + QLatin1String(" New Album")));
0085     setModal(false);
0086 
0087     const int spacing = qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing),
0088                              QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing));
0089 
0090     d->buttonBox->addButton(QDialogButtonBox::Ok);
0091     d->buttonBox->addButton(QDialogButtonBox::Cancel);
0092     d->buttonBox->button(QDialogButtonBox::Cancel)->setDefault(true);
0093     d->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
0094 
0095     connect(d->titleEdt, SIGNAL(textChanged()),
0096             this, SLOT(slotTextChanged()));
0097 
0098     connect(d->buttonBox, SIGNAL(accepted()),
0099             this, SLOT(accept()));
0100 
0101     connect(d->buttonBox, SIGNAL(rejected()),
0102             this, SLOT(reject()));
0103 
0104     d->albumBox->setLayout(d->albumBoxLayout);
0105     d->albumBox->setWhatsThis(i18nc("@info", "These are basic settings for the new %1 album.",d->toolName));
0106 
0107     d->titleEdt->setToolTip(i18nc("@info", "Title of the album that will be created (required)."));
0108 
0109     d->dtEdt->setDisplayFormat(QLatin1String("dd.MM.yyyy HH:mm"));
0110     d->dtEdt->setWhatsThis(i18nc("@info", "Date and Time of the album that will be created (optional)."));
0111 
0112     d->descEdt->setToolTip(i18nc("@info", "Description of the album that will be created (optional)."));
0113 
0114     d->locEdt->setToolTip(i18nc("@info", "Location of the album that will be created (optional)."));
0115 
0116     d->albumBoxLayout->addWidget(d->titleLabel, 0, 0);
0117     d->albumBoxLayout->addWidget(d->titleEdt,   0, 1);
0118     d->albumBoxLayout->addWidget(d->dateLabel,  1, 0);
0119     d->albumBoxLayout->addWidget(d->dtEdt,      1, 1);
0120     d->albumBoxLayout->addWidget(d->descLabel,  2, 0);
0121     d->albumBoxLayout->addWidget(d->descEdt,    2, 1);
0122     d->albumBoxLayout->addWidget(d->locLabel,   3, 0);
0123     d->albumBoxLayout->addWidget(d->locEdt,     3, 1);
0124     d->albumBoxLayout->setContentsMargins(spacing, spacing, spacing, spacing);
0125     d->albumBoxLayout->setSpacing(spacing);
0126 
0127     d->mainLayout->addWidget(d->albumBox);
0128     d->mainLayout->addWidget(d->buttonBox);
0129     d->mainLayout->setContentsMargins(spacing, spacing, spacing, spacing);
0130     d->mainLayout->setSpacing(spacing);
0131     setLayout(d->mainLayout);
0132 }
0133 
0134 WSNewAlbumDialog::~WSNewAlbumDialog()
0135 {
0136     delete d;
0137 }
0138 
0139 void WSNewAlbumDialog::slotTextChanged()
0140 {
0141     if (QString::compare(getTitleEdit()->text(), QLatin1String(""), Qt::CaseInsensitive) == 0)
0142     {
0143         d->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
0144     }
0145     else
0146     {
0147         d->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
0148     }
0149 }
0150 
0151 void WSNewAlbumDialog::hideDateTime()
0152 {
0153     d->dtEdt->hide();
0154     d->dateLabel->hide();
0155     d->albumBoxLayout->removeWidget(d->dtEdt);
0156     d->albumBoxLayout->removeWidget(d->dateLabel);
0157 }
0158 
0159 void WSNewAlbumDialog::hideDesc()
0160 {
0161     d->descEdt->hide();
0162     d->descLabel->hide();
0163     d->albumBoxLayout->removeWidget(d->descEdt);
0164     d->albumBoxLayout->removeWidget(d->descLabel);
0165 }
0166 
0167 void WSNewAlbumDialog::hideLocation()
0168 {
0169     d->locEdt->hide();
0170     d->locLabel->hide();
0171     d->albumBoxLayout->removeWidget(d->locEdt);
0172     d->albumBoxLayout->removeWidget(d->locLabel);
0173 }
0174 
0175 QWidget* WSNewAlbumDialog::getMainWidget() const
0176 {
0177     return d->mainWidget;
0178 }
0179 
0180 QGroupBox* WSNewAlbumDialog::getAlbumBox() const
0181 {
0182     return d->albumBox;
0183 }
0184 
0185 DTextEdit* WSNewAlbumDialog::getTitleEdit() const
0186 {
0187     return d->titleEdt;
0188 }
0189 
0190 DTextEdit* WSNewAlbumDialog::getDescEdit() const
0191 {
0192     return d->descEdt;
0193 }
0194 
0195 DTextEdit* WSNewAlbumDialog::getLocEdit() const
0196 {
0197     return d->locEdt;
0198 }
0199 
0200 QDateTimeEdit* WSNewAlbumDialog::getDateTimeEdit() const
0201 {
0202     return d->dtEdt;
0203 }
0204 
0205 void WSNewAlbumDialog::addToMainLayout(QWidget* const widget)
0206 {
0207     d->mainLayout->addWidget(widget);
0208     d->mainLayout->removeWidget(d->buttonBox);
0209     d->mainLayout->addWidget(d->buttonBox);
0210 }
0211 void WSNewAlbumDialog::setAlbumSuggestion(const QString& title)
0212 {
0213     d->titleEdt->setText(title);
0214     d->titleEdt->selectAll();
0215 }
0216 
0217 void WSNewAlbumDialog::getBaseAlbumProperties(WSAlbum& baseAlbum)
0218 {
0219     baseAlbum.title       = getTitleEdit()->text();
0220     baseAlbum.location    = getLocEdit()->text();
0221     baseAlbum.description = getDescEdit()->toPlainText();
0222 }
0223 
0224 QDialogButtonBox* WSNewAlbumDialog::getButtonBox() const
0225 {
0226     return d->buttonBox;
0227 }
0228 
0229 } // namespace Digikam
0230 
0231 #include "moc_wsnewalbumdialog.cpp"