+void RenameDialog::renameItems()
+{
+ // Currently the items are sorted by the selection order, resort
+ // them by the filename. This assures that the new sort order is similar to
+ // the current filename sort order.
+ qSort(m_items.begin(), m_items.end(), lessThan);
+
+ // Iterate through all items and rename them...
+ int index = 1;
+ foreach (const KFileItem& item, m_items) {
+ const QString newName = indexedName(m_newName, index, QLatin1Char('#'));
+ ++index;
+
+ const KUrl oldUrl = item.url();
+ if (oldUrl.fileName() != newName) {
+ KUrl newUrl = oldUrl;
+ newUrl.setFileName(newName);
+ KonqOperations::rename(this, oldUrl, newUrl);
+ }
+ }
+}
+
+QString RenameDialog::indexedName(const QString& name, int index, const QChar& indexPlaceHolder)
+{
+ QString newName = name;
+
+ QString indexString = QString::number(index);
+
+ // Insert leading zeros if necessary
+ const int minIndexLength = name.count(indexPlaceHolder);
+ while (indexString.length() < minIndexLength) {
+ indexString.prepend(QLatin1Char('0'));
+ }
+
+ // Replace the index placeholders by the indexString
+ const int placeHolderStart = newName.indexOf(indexPlaceHolder);
+ newName.replace(placeHolderStart, minIndexLength, indexString);
+
+ return newName;
+}