File indexing completed on 2024-04-21 04:18:48
0001 // vim: set tabstop=4 shiftwidth=4 expandtab: 0002 /* 0003 Gwenview: an image viewer 0004 Copyright 2009 Aurélien Gâteau <agateau@kde.org> 0005 0006 This program is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU General Public License 0008 as published by the Free Software Foundation; either version 2 0009 of the License, or (at your option) any later version. 0010 0011 This program is distributed in the hope that it will be useful, 0012 but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 GNU General Public License for more details. 0015 0016 You should have received a copy of the GNU General Public License 0017 along with this program; if not, write to the Free Software 0018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA. 0019 0020 */ 0021 // Self 0022 #include "importerconfigdialog.h" 0023 0024 // Qt 0025 #include <QDateTime> 0026 0027 // KF 0028 0029 // Local 0030 #include "filenameformater.h" 0031 #include "importerconfig.h" 0032 #include "ui_importerconfigdialog.h" 0033 0034 namespace Gwenview 0035 { 0036 static const QString PREVIEW_FILENAME = QStringLiteral("PICT0012.JPG"); 0037 static const QDateTime PREVIEW_DATETIME = QDateTime(QDate(2009, 10, 25), QTime(17, 51, 18)); 0038 0039 struct ImporterConfigDialogPrivate : public Ui_ImporterConfigDialog { 0040 ImporterConfigDialog *q = nullptr; 0041 0042 void setupHelpText() 0043 { 0044 QString helpText = QStringLiteral("<ul>"); 0045 FileNameFormater::HelpMap map = FileNameFormater::helpMap(); 0046 FileNameFormater::HelpMap::ConstIterator it = map.constBegin(), end = map.constEnd(); 0047 for (; it != end; ++it) { 0048 const QString keyword = QLatin1Char('{') + it.key() + QLatin1Char('}'); 0049 const QString explanation = it.value().toHtmlEscaped(); 0050 const QString link = QStringLiteral("<a href='%1'>%1</a>").arg(keyword); 0051 helpText += 0052 QLatin1String("<li>") + i18nc("%1 is the importer keyword, %2 is keyword explanation", "%1: %2", link, explanation) + QLatin1String("</li>"); 0053 } 0054 helpText += QLatin1String("</ul>"); 0055 mRenameFormatHelpLabel->setText(helpText); 0056 0057 QObject::connect(mRenameFormatHelpLabel, SIGNAL(linkActivated(QString)), q, SLOT(slotHelpLinkActivated(QString))); 0058 } 0059 }; 0060 0061 ImporterConfigDialog::ImporterConfigDialog(QWidget *parent) 0062 : KConfigDialog(parent, QStringLiteral("Importer Settings"), ImporterConfig::self()) 0063 , d(new ImporterConfigDialogPrivate) 0064 { 0065 d->q = this; 0066 auto widget = new QWidget; 0067 d->setupUi(widget); 0068 setFaceType(KPageDialog::Plain); 0069 addPage(widget, QString()); 0070 0071 connect(d->kcfg_AutoRenameFormat, &QLineEdit::textChanged, this, &ImporterConfigDialog::updatePreview); 0072 0073 d->setupHelpText(); 0074 updatePreview(); 0075 } 0076 0077 ImporterConfigDialog::~ImporterConfigDialog() 0078 { 0079 delete d; 0080 } 0081 0082 void ImporterConfigDialog::slotHelpLinkActivated(const QString &keyword) 0083 { 0084 d->kcfg_AutoRenameFormat->insert(keyword); 0085 } 0086 0087 void ImporterConfigDialog::updatePreview() 0088 { 0089 FileNameFormater formater(d->kcfg_AutoRenameFormat->text()); 0090 d->mPreviewOutputLabel->setText(formater.format(QUrl::fromLocalFile('/' + PREVIEW_FILENAME), PREVIEW_DATETIME)); 0091 } 0092 0093 } // namespace 0094 0095 #include "moc_importerconfigdialog.cpp"