Just use KMimeType::extractKnownExtension() instead of the custom implementation. Thanks to David Faure for the hint!

svn path=/trunk/KDE/kdebase/apps/; revision=819137
This commit is contained in:
Peter Penz 2008-06-10 17:22:24 +00:00
parent 68885c7eeb
commit 916b3a808e
6 changed files with 4 additions and 152 deletions

View file

@ -1,6 +1,5 @@
add_subdirectory( pics )
add_subdirectory( tests )
find_package(QImageBlitz REQUIRED)

View file

@ -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"

View file

@ -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;

View file

@ -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})
############################################

View file

@ -1,55 +0,0 @@
/***************************************************************************
* Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
* *
* 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 <qtest_kde.h>
#include <renamedialog.h>
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"

View file

@ -1,33 +0,0 @@
/***************************************************************************
* Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
* *
* 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 <QObject>
class RenameDialogTest : public QObject
{
Q_OBJECT
private slots:
void testExtensionString();
};
#endif