Changeset View
Changeset View
Standalone View
Standalone View
src/utils/filenameutils.cpp
- This file was copied from src/views/renamedialog.h.
1 | /*************************************************************************** | 1 | /*************************************************************************** | ||
---|---|---|---|---|---|
2 | * Copyright (C) 2006-2010 by Peter Penz (peter.penz@gmx.at) * | 2 | * Copyright (C) 2018 by Emirald Mateli <aldo.mateli@gmail.com> * | ||
3 | * * | 3 | * * | ||
4 | * This program is free software; you can redistribute it and/or modify * | 4 | * This program is free software; you can redistribute it and/or modify * | ||
5 | * it under the terms of the GNU General Public License as published by * | 5 | * it under the terms of the GNU General Public License as published by * | ||
6 | * the Free Software Foundation; either version 2 of the License, or * | 6 | * the Free Software Foundation; either version 2 of the License, or * | ||
7 | * (at your option) any later version. * | 7 | * (at your option) any later version. * | ||
8 | * * | 8 | * * | ||
9 | * This program is distributed in the hope that it will be useful, * | 9 | * This program is distributed in the hope that it will be useful, * | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
12 | * GNU General Public License for more details. * | 12 | * GNU General Public License for more details. * | ||
13 | * * | 13 | * * | ||
14 | * You should have received a copy of the GNU General Public License * | 14 | * You should have received a copy of the GNU General Public License * | ||
15 | * along with this program; if not, write to the * | 15 | * along with this program; if not, write to the * | ||
16 | * Free Software Foundation, Inc., * | 16 | * Free Software Foundation, Inc., * | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * | 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * | ||
18 | ***************************************************************************/ | 18 | ***************************************************************************/ | ||
19 | 19 | | |||
20 | #ifndef RENAMEDIALOG_H | 20 | #include <QString> | ||
21 | #define RENAMEDIALOG_H | 21 | #include <QMimeDatabase> | ||
22 | #include <QFileInfo> | ||||
23 | #include "filenameutils.h" | ||||
22 | 24 | | |||
23 | #include "dolphin_export.h" | 25 | QString FileNameUtils::getSuffix(const QString &file) { | ||
26 | QString extension = QMimeDatabase().suffixForFileName(file); | ||||
24 | 27 | | |||
25 | #include <KFileItem> | 28 | if (!extension.isEmpty()) { | ||
29 | return extension.prepend(QLatin1Char('.')); | ||||
30 | } | ||||
26 | 31 | | |||
27 | #include <QDialog> | 32 | QString suffix = QFileInfo(file).suffix(); | ||
28 | #include <QString> | 33 | | ||
34 | if (!suffix.isEmpty()) { | ||||
35 | suffix.prepend(QLatin1Char('.')); | ||||
36 | } | ||||
29 | 37 | | |||
30 | class QLineEdit; | 38 | return suffix; | ||
31 | class QSpinBox; | 39 | } | ||
32 | class QPushButton; | | |||
33 | class KJob; | | |||
34 | /** | | |||
35 | * @brief Dialog for renaming a variable number of files. | | |||
36 | */ | | |||
37 | class DOLPHIN_EXPORT RenameDialog : public QDialog | | |||
38 | { | | |||
39 | Q_OBJECT | | |||
40 | | ||||
41 | public: | | |||
42 | explicit RenameDialog(QWidget* parent, const KFileItemList& items); | | |||
43 | ~RenameDialog() override; | | |||
44 | | ||||
45 | signals: | | |||
46 | void renamingFinished(const QList<QUrl>& urls); | | |||
47 | | ||||
48 | private slots: | | |||
49 | void slotAccepted(); | | |||
50 | void slotTextChanged(const QString& newName); | | |||
51 | void slotFileRenamed(const QUrl& oldUrl, const QUrl& newUrl); | | |||
52 | void slotResult(KJob* job); | | |||
53 | | ||||
54 | protected: | | |||
55 | void showEvent(QShowEvent* event) override; | | |||
56 | | ||||
57 | private: | | |||
58 | bool m_renameOneItem; | | |||
59 | QList<QUrl> m_renamedItems; | | |||
60 | QString m_newName; | | |||
61 | QLineEdit* m_lineEdit; | | |||
62 | KFileItemList m_items; | | |||
63 | bool m_allExtensionsDifferent; | | |||
64 | QSpinBox* m_spinBox; | | |||
65 | QPushButton* m_okButton; | | |||
66 | }; | | |||
67 | 40 | | |||
68 | #endif | 41 | QString FileNameUtils::getName(const QString &file) { | ||
42 | return file.left(file.length() - getSuffix(file).length()); | ||||
43 | } |