From: Peter Penz Date: Tue, 10 Jun 2008 17:22:24 +0000 (+0000) Subject: Just use KMimeType::extractKnownExtension() instead of the custom implementation... X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/8fd40e72aa7d9599d7f4e9a5b421ab9307f15b79 Just use KMimeType::extractKnownExtension() instead of the custom implementation. Thanks to David Faure for the hint! svn path=/trunk/KDE/kdebase/apps/; revision=819137 --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d138a2290..b37494566 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,5 @@ add_subdirectory( pics ) -add_subdirectory( tests ) find_package(QImageBlitz REQUIRED) diff --git a/src/renamedialog.cpp b/src/renamedialog.cpp index 3e9b39327..02dd2e9f6 100644 --- a/src/renamedialog.cpp +++ b/src/renamedialog.cpp @@ -65,8 +65,9 @@ RenameDialog::RenameDialog(QWidget *parent, const KFileItemList& items) : } m_lineEdit = new KLineEdit(page); - QString extension = extensionString(items[0].url().prettyUrl()); + QString extension = KMimeType::extractKnownExtension(items[0].url().prettyUrl()); if (extension.length() > 0) { + extension.insert(0, '.'); // The first item seems to have a extension (e. g. '.jpg' or '.txt'). Now // check whether all other URLs have the same extension. If this is the // case, add this extension to the name suggestion. @@ -107,7 +108,8 @@ RenameDialog::RenameDialog(QWidget *parent, const KFileItemList& items) : } RenameDialog::~RenameDialog() -{} +{ +} void RenameDialog::slotButtonClicked(int button) { @@ -125,36 +127,4 @@ void RenameDialog::slotButtonClicked(int button) KDialog::slotButtonClicked(button); } -QString RenameDialog::extensionString(const QString& name) -{ - QString extension; - - const QStringList strings = name.split('.'); - const int size = strings.size(); - for (int i = size - 1; i >= 0; --i) { - const QString& str = strings.at(i); - - // Sub strings like "9", "12", "99", ... which contain only - // numbers don't count as extension. Usually they are version - // numbers like in "cmake-2.4.5". - bool isNumeric = false; - str.toInt(&isNumeric); - if (isNumeric) { - break; - } - - // Extensions may not contain a space and the maximum length - // should not exceed 4 characters. This prevents that strings like - // "Open office.org writer documentation.pdf" get ".org writer documentation.pdf" - // as extension. - if (str.contains(' ') || (str.length() > 4)) { - break; - } - - extension.insert(0, '.' + str); - } - - return extension; -} - #include "renamedialog.moc" diff --git a/src/renamedialog.h b/src/renamedialog.h index 998475733..931b89cb0 100644 --- a/src/renamedialog.h +++ b/src/renamedialog.h @@ -81,22 +81,6 @@ public: protected slots: virtual void slotButtonClicked(int button); -private: - /** - * Returns the extension string for a filename, which contains all - * file extensions. Version numbers like in "cmake-2.4.5" don't count - * as file extension. If the version numbers follow after a valid extension, they - * are part of the extension string. - * - * Examples (name -> extension string): - * "Image.gif" -> ".gif" - * "package.tar.gz" -> ".tar.gz" - * "cmake-2.4.5" -> "" - * "Image.1.12.gif" -> ".gif" - * "Image.tar.1.12.gz" -> ".tar.1.12.gz" - */ - static QString extensionString(const QString& name); - private: bool m_renameOneItem; KLineEdit* m_lineEdit; diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt deleted file mode 100644 index 5379aacad..000000000 --- a/src/tests/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} ) -include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/.. ) - -########### renamedialogtest ############### - - -kde4_add_unit_test(renamedialogtest renamedialogtest.cpp) - -target_link_libraries(renamedialogtest dolphinprivate ${QT_QTTEST_LIBRARY}) - - - ############################################ - diff --git a/src/tests/renamedialogtest.cpp b/src/tests/renamedialogtest.cpp deleted file mode 100644 index dc2adffd9..000000000 --- a/src/tests/renamedialogtest.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "renamedialogtest.h" -#include -#include - -QTEST_KDEMAIN(RenameDialogTest, NoGUI) - -void RenameDialogTest::testExtensionString() -{ - QString result; - - result = RenameDialog::extensionString("Image.gif"); - QCOMPARE(result, QString(".gif")); - - result = RenameDialog::extensionString("package.tar.gz"); - QCOMPARE(result, QString(".tar.gz")); - - result = RenameDialog::extensionString("cmake-2.4.5"); - QCOMPARE(result, QString()); - - result = RenameDialog::extensionString("Image.1.12.gif"); - QCOMPARE(result, QString(".gif")); - - result = RenameDialog::extensionString("Image.tar.1.12.gz"); - QCOMPARE(result, QString(".gz")); - - result = RenameDialog::extensionString("Open office.org writer documentation.pdf"); - QCOMPARE(result, QString(".pdf")); - - result = RenameDialog::extensionString("Test.toolongextension.pdf"); - QCOMPARE(result, QString(".pdf")); - - result = RenameDialog::extensionString("Test.x x.pdf"); - QCOMPARE(result, QString(".pdf")); -} - -#include "renamedialogtest.moc" diff --git a/src/tests/renamedialogtest.h b/src/tests/renamedialogtest.h deleted file mode 100644 index 0aabc62a5..000000000 --- a/src/tests/renamedialogtest.h +++ /dev/null @@ -1,33 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef RENAMEDIALOGTEST_H -#define RENAMEDIALOGTEST_H - -#include - -class RenameDialogTest : public QObject -{ - Q_OBJECT - -private slots: - void testExtensionString(); -}; - -#endif