X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/a05db2f0d081a67f306141e2f31442eea49dd71b..32b51b7b92e16cfaf1121cbe80ca267fc8bb0718:/src/views/renamedialog.cpp diff --git a/src/views/renamedialog.cpp b/src/views/renamedialog.cpp index abb37b897..d3c80e3da 100644 --- a/src/views/renamedialog.cpp +++ b/src/views/renamedialog.cpp @@ -23,6 +23,7 @@ #include #include #include +#include //TODO port to QCollator #include #include @@ -30,15 +31,6 @@ #include #include -/** - * Helper function for sorting items with qSort() in - * DolphinView::renameSelectedItems(). - */ -bool lessThan(const KFileItem& item1, const KFileItem& item2) -{ - return KStringHandler::naturalCompare(item1.name(), item2.name()) < 0; -} - RenameDialog::RenameDialog(QWidget *parent, const KFileItemList& items) : KDialog(parent), m_renameOneItem(false), @@ -71,7 +63,7 @@ RenameDialog::RenameDialog(QWidget *parent, const KFileItemList& items) : QLabel* editLabel = 0; if (m_renameOneItem) { m_newName = items.first().name(); - editLabel = new QLabel(i18nc("@label:textbox", "Rename the item %1 to:", m_newName), + editLabel = new QLabel(xi18nc("@label:textbox", "Rename the item %1 to:", m_newName), page); editLabel->setTextFormat(Qt::PlainText); } else { @@ -83,11 +75,11 @@ RenameDialog::RenameDialog(QWidget *parent, const KFileItemList& items) : } m_lineEdit = new KLineEdit(page); - connect(m_lineEdit, SIGNAL(textChanged(QString)), this, SLOT(slotTextChanged(QString))); + connect(m_lineEdit, &KLineEdit::textChanged, this, &RenameDialog::slotTextChanged); int selectionLength = m_newName.length(); if (m_renameOneItem) { - const QString fileName = items.first().url().prettyUrl(); + const QString fileName = items.first().url().toDisplayString(); const QString extension = KMimeType::extractKnownExtension(fileName.toLower()); // If the current item is a directory, select the whole file name. @@ -110,7 +102,7 @@ RenameDialog::RenameDialog(QWidget *parent, const KFileItemList& items) : if (!m_renameOneItem) { QSet extensions; foreach (const KFileItem& item, m_items) { - const QString extension = KMimeType::extractKnownExtension(item.url().prettyUrl().toLower()); + const QString extension = KMimeType::extractKnownExtension(item.url().toDisplayString().toLower()); if (extensions.contains(extension)) { m_allExtensionsDifferent = false; @@ -136,6 +128,20 @@ RenameDialog::~RenameDialog() { } +void RenameDialog::renameItem(const KFileItem &item, const QString& newName) +{ + const KUrl oldUrl = item.url(); + KUrl newUrl = oldUrl; + newUrl.setFileName(KIO::encodeFileName(newName)); + + QWidget* widget = parentWidget(); + if (!widget) { + widget = this; + } + + KonqOperations::rename(widget, oldUrl, newUrl); +} + void RenameDialog::slotButtonClicked(int button) { if (button == KDialog::Ok) { @@ -143,10 +149,7 @@ void RenameDialog::slotButtonClicked(int button) if (m_renameOneItem) { Q_ASSERT(m_items.count() == 1); - const KUrl oldUrl = m_items.first().url(); - KUrl newUrl = oldUrl; - newUrl.setFileName(KIO::encodeFileName(m_newName)); - KonqOperations::rename(this, oldUrl, newUrl); + renameItem(m_items.first(), m_newName); } else { renameItems(); } @@ -189,9 +192,7 @@ void RenameDialog::renameItems() } if (oldUrl.fileName() != newName) { - KUrl newUrl = oldUrl; - newUrl.setFileName(KIO::encodeFileName(newName)); - KonqOperations::rename(this, oldUrl, newUrl); + renameItem(item, newName); } } } @@ -215,4 +216,3 @@ QString RenameDialog::indexedName(const QString& name, int index, const QChar& i return newName; } -#include "renamedialog.moc"