File indexing completed on 2024-05-05 04:19:18
0001 // vim: set tabstop=4 shiftwidth=4 expandtab: 0002 /* 0003 Gwenview: an image viewer 0004 Copyright 2018 Aurélien Gâteau <agateau@kde.org> 0005 Copyright 2018 Peter Mühlenpfordt <devel@ukn8.de> 0006 0007 This program is free software; you can redistribute it and/or 0008 modify it under the terms of the GNU General Public License 0009 as published by the Free Software Foundation; either version 2 0010 of the License, or (at your option) any later version. 0011 0012 This program is distributed in the hope that it will be useful, 0013 but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0015 GNU General Public License for more details. 0016 0017 You should have received a copy of the GNU General Public License 0018 along with this program; if not, write to the Free Software 0019 Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA. 0020 0021 */ 0022 // Self 0023 #include "renamedialog.h" 0024 0025 // Qt 0026 #include <QMimeDatabase> 0027 #include <QPushButton> 0028 0029 // KF 0030 #include <KGuiItem> 0031 #include <KLocalizedString> 0032 0033 // Local 0034 #include <ui_renamedialog.h> 0035 0036 namespace Gwenview 0037 { 0038 struct RenameDialogPrivate : public Ui_RenameDialog { 0039 }; 0040 0041 RenameDialog::RenameDialog(QWidget *parent) 0042 : QDialog(parent) 0043 , d(new RenameDialogPrivate) 0044 { 0045 d->setupUi(this); 0046 0047 QPushButton *okButton = d->mButtonBox->button(QDialogButtonBox::Ok); 0048 KGuiItem::assign(okButton, KGuiItem(i18nc("@action:button", "Rename"), QStringLiteral("edit-rename"))); 0049 0050 connect(d->mFilename, &QLineEdit::textChanged, this, &RenameDialog::updateButtons); 0051 } 0052 0053 RenameDialog::~RenameDialog() 0054 { 0055 delete d; 0056 } 0057 0058 void RenameDialog::setFilename(const QString &filename) 0059 { 0060 d->mFilename->setText(filename); 0061 d->mFilenameLabel->setText(xi18n("Rename <filename>%1</filename> to:", filename)); 0062 0063 const QMimeDatabase db; 0064 const QString extension = db.suffixForFileName(filename); 0065 int selectionLength = filename.length(); 0066 if (!extension.isEmpty()) { 0067 // The filename contains an extension. Assure that only the filename 0068 // gets selected. 0069 selectionLength -= extension.length() + 1; 0070 } 0071 d->mFilename->setSelection(0, selectionLength); 0072 } 0073 0074 QString RenameDialog::filename() const 0075 { 0076 return d->mFilename->text(); 0077 } 0078 0079 void RenameDialog::updateButtons() 0080 { 0081 const bool enableButton = !d->mFilename->text().isEmpty(); 0082 d->mButtonBox->button(QDialogButtonBox::Ok)->setEnabled(enableButton); 0083 } 0084 0085 } // namespace 0086 0087 #include "moc_renamedialog.cpp"