+ disconnect(m_view, SIGNAL(roleEditingFinished(int,QByteArray,QVariant)),
+ this, SLOT(slotRoleEditingFinished(int,QByteArray,QVariant)));
+
+ if (index < 0 || index >= m_model->count()) {
+ return;
+ }
+
+ if (role == "text") {
+ const KFileItem oldItem = m_model->fileItem(index);
+ const QString newName = value.toString();
+ if (!newName.isEmpty() && newName != oldItem.text() && newName != QLatin1String(".") && newName != QLatin1String("..")) {
+ const KUrl oldUrl = oldItem.url();
+
+ const KUrl newUrl(url().path(KUrl::AddTrailingSlash) + newName);
+ const bool newNameExistsAlready = (m_model->index(newUrl) >= 0);
+ if (!newNameExistsAlready) {
+ // Only change the data in the model if no item with the new name
+ // is in the model yet. If there is an item with the new name
+ // already, calling KonqOperations::rename() will open a dialog
+ // asking for a new name, and KFileItemModel will update the
+ // data when the dir lister signals that the file name has changed.
+ QHash<QByteArray, QVariant> data;
+ data.insert(role, value);
+ m_model->setData(index, data);
+ }
+
+ KonqOperations* op = KonqOperations::renameV2(this, oldUrl, newName);
+ if (op) {
+ connect(op, SIGNAL(renamingFailed(KUrl,KUrl)), SLOT(slotRenamingFailed(KUrl,KUrl)));
+ }
+ }
+ }