]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Allow renaming of items (note that currently the "rename multiple files" dialog is...
authorPeter Penz <peter.penz19@gmail.com>
Tue, 13 Mar 2007 17:31:54 +0000 (17:31 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Tue, 13 Mar 2007 17:31:54 +0000 (17:31 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=642219

src/dolphinmainwindow.cpp
src/dolphinmainwindow.h
src/dolphinview.cpp
src/renamedialog.cpp
src/renamedialog.h

index 561c235b7d95a81a4f706794dd9824da3a54edd8..5183f993d31971e0c895df9343a4ca2549ad0c4c 100644 (file)
@@ -22,8 +22,6 @@
 #include <config-kmetadata.h>\r
 #include "dolphinmainwindow.h"\r
 \r
 #include <config-kmetadata.h>\r
 #include "dolphinmainwindow.h"\r
 \r
-#include <assert.h>\r
-\r
 #include "bookmarkssidebarpage.h"\r
 #include "dolphinapplication.h"\r
 #include "dolphinnewmenu.h"\r
 #include "bookmarkssidebarpage.h"\r
 #include "dolphinapplication.h"\r
 #include "dolphinnewmenu.h"\r
@@ -58,6 +56,7 @@
 #include <kmenu.h>\r
 #include <kmessagebox.h>\r
 #include <konqmimedata.h>\r
 #include <kmenu.h>\r
 #include <kmessagebox.h>\r
 #include <konqmimedata.h>\r
+#include <konq_operations.h>\r
 #include <kpropertiesdialog.h>\r
 #include <kprotocolinfo.h>\r
 #include <ktoggleaction.h>\r
 #include <kpropertiesdialog.h>\r
 #include <kprotocolinfo.h>\r
 #include <ktoggleaction.h>\r
@@ -106,7 +105,7 @@ DolphinMainWindow::~DolphinMainWindow()
 \r
 void DolphinMainWindow::setActiveView(DolphinView* view)\r
 {\r
 \r
 void DolphinMainWindow::setActiveView(DolphinView* view)\r
 {\r
-    assert((view == m_view[PrimaryIdx]) || (view == m_view[SecondaryIdx]));\r
+    Q_ASSERT((view == m_view[PrimaryIdx]) || (view == m_view[SecondaryIdx]));\r
     if (m_activeView == view) {\r
         return;\r
     }\r
     if (m_activeView == view) {\r
         return;\r
     }\r
@@ -203,6 +202,12 @@ void DolphinMainWindow::dropUrls(const KUrl::List& urls,
     }\r
 }\r
 \r
     }\r
 }\r
 \r
+void DolphinMainWindow::rename(const KUrl& oldUrl, const KUrl& newUrl)\r
+{\r
+    KonqOperations::rename(this, oldUrl, newUrl);\r
+    m_undoCommandTypes.append(KonqUndoManager::RENAME);\r
+}\r
+\r
 void DolphinMainWindow::refreshViews()\r
 {\r
     const bool split = DolphinSettings::instance().generalSettings()->splitView();\r
 void DolphinMainWindow::refreshViews()\r
 {\r
     const bool split = DolphinSettings::instance().generalSettings()->splitView();\r
@@ -232,7 +237,7 @@ void DolphinMainWindow::refreshViews()
     }\r
 \r
     m_activeView = isPrimaryViewActive ? m_view[PrimaryIdx] : m_view[SecondaryIdx];\r
     }\r
 \r
     m_activeView = isPrimaryViewActive ? m_view[PrimaryIdx] : m_view[SecondaryIdx];\r
-    assert(m_activeView != 0);\r
+    Q_ASSERT(m_activeView != 0);\r
 \r
     updateViewActions();\r
     emit activeViewChanged();\r
 \r
     updateViewActions();\r
     emit activeViewChanged();\r
@@ -336,7 +341,7 @@ void DolphinMainWindow::slotSelectionChanged()
 {\r
     updateEditActions();\r
 \r
 {\r
     updateEditActions();\r
 \r
-    assert(m_view[PrimaryIdx] != 0);\r
+    Q_ASSERT(m_view[PrimaryIdx] != 0);\r
     int selectedUrlsCount = m_view[PrimaryIdx]->selectedUrls().count();\r
     if (m_view[SecondaryIdx] != 0) {\r
         selectedUrlsCount += m_view[SecondaryIdx]->selectedUrls().count();\r
     int selectedUrlsCount = m_view[PrimaryIdx]->selectedUrls().count();\r
     if (m_view[SecondaryIdx] != 0) {\r
         selectedUrlsCount += m_view[SecondaryIdx]->selectedUrls().count();\r
@@ -444,7 +449,7 @@ void DolphinMainWindow::moveToTrash()
     clearStatusBar();\r
     const KUrl::List selectedUrls = m_activeView->selectedUrls();\r
     KonqOperations::del(this, KonqOperations::TRASH, selectedUrls);\r
     clearStatusBar();\r
     const KUrl::List selectedUrls = m_activeView->selectedUrls();\r
     KonqOperations::del(this, KonqOperations::TRASH, selectedUrls);\r
-    m_undoOperations.append(KonqOperations::TRASH);\r
+    m_undoCommandTypes.append(KonqUndoManager::TRASH);\r
 }\r
 \r
 void DolphinMainWindow::deleteItems()\r
 }\r
 \r
 void DolphinMainWindow::deleteItems()\r
@@ -453,7 +458,7 @@ void DolphinMainWindow::deleteItems()
 \r
     KUrl::List list = m_activeView->selectedUrls();\r
     const uint itemCount = list.count();\r
 \r
     KUrl::List list = m_activeView->selectedUrls();\r
     const uint itemCount = list.count();\r
-    assert(itemCount >= 1);\r
+    Q_ASSERT(itemCount >= 1);\r
 \r
     QString text;\r
     if (itemCount > 1) {\r
 \r
     QString text;\r
     if (itemCount > 1) {\r
@@ -514,26 +519,36 @@ void DolphinMainWindow::slotUndoAvailable(bool available)
         undoAction->setEnabled(available);\r
     }\r
 \r
         undoAction->setEnabled(available);\r
     }\r
 \r
-    if (available && (m_undoOperations.count() > 0)) {\r
-        const KonqOperations::Operation op = m_undoOperations.takeFirst();\r
+    if (available && (m_undoCommandTypes.count() > 0)) {\r
+        const KonqUndoManager::CommandType command = m_undoCommandTypes.takeFirst();\r
         DolphinStatusBar* statusBar = m_activeView->statusBar();\r
         DolphinStatusBar* statusBar = m_activeView->statusBar();\r
-        switch (op) {\r
-            case KonqOperations::COPY:\r
+        switch (command) {\r
+            case KonqUndoManager::COPY:\r
                 statusBar->setMessage(i18n("Copy operation completed."),\r
                                       DolphinStatusBar::OperationCompleted);\r
                 break;\r
                 statusBar->setMessage(i18n("Copy operation completed."),\r
                                       DolphinStatusBar::OperationCompleted);\r
                 break;\r
-            case KonqOperations::MOVE:\r
+            case KonqUndoManager::MOVE:\r
                 statusBar->setMessage(i18n("Move operation completed."),\r
                                       DolphinStatusBar::OperationCompleted);\r
                 break;\r
                 statusBar->setMessage(i18n("Move operation completed."),\r
                                       DolphinStatusBar::OperationCompleted);\r
                 break;\r
-            case KonqOperations::LINK:\r
+            case KonqUndoManager::LINK:\r
                 statusBar->setMessage(i18n("Link operation completed."),\r
                                       DolphinStatusBar::OperationCompleted);\r
                 break;\r
                 statusBar->setMessage(i18n("Link operation completed."),\r
                                       DolphinStatusBar::OperationCompleted);\r
                 break;\r
-            case KonqOperations::TRASH:\r
+            case KonqUndoManager::TRASH:\r
                 statusBar->setMessage(i18n("Move to trash operation completed."),\r
                                       DolphinStatusBar::OperationCompleted);\r
                 break;\r
                 statusBar->setMessage(i18n("Move to trash operation completed."),\r
                                       DolphinStatusBar::OperationCompleted);\r
                 break;\r
+            case KonqUndoManager::RENAME:\r
+                statusBar->setMessage(i18n("Renaming operation completed."),\r
+                                      DolphinStatusBar::OperationCompleted);\r
+                break;\r
+\r
+           case KonqUndoManager::MKDIR:\r
+                statusBar->setMessage(i18n("Created directory."),\r
+                                      DolphinStatusBar::OperationCompleted);\r
+                break;\r
+\r
             default:\r
                 break;\r
         }\r
             default:\r
                 break;\r
         }\r
@@ -912,7 +927,7 @@ void DolphinMainWindow::compareFiles()
     // - both in the secondary view\r
     // - one in the primary view and the other in the secondary\r
     //   view\r
     // - both in the secondary view\r
     // - one in the primary view and the other in the secondary\r
     //   view\r
-    assert(m_view[PrimaryIdx] != 0);\r
+    Q_ASSERT(m_view[PrimaryIdx] != 0);\r
 \r
     KUrl urlA;\r
     KUrl urlB;\r
 \r
     KUrl urlA;\r
     KUrl urlB;\r
@@ -920,9 +935,9 @@ void DolphinMainWindow::compareFiles()
 \r
     switch (urls.count()) {\r
         case 0: {\r
 \r
     switch (urls.count()) {\r
         case 0: {\r
-            assert(m_view[SecondaryIdx] != 0);\r
+            Q_ASSERT(m_view[SecondaryIdx] != 0);\r
             urls = m_view[SecondaryIdx]->selectedUrls();\r
             urls = m_view[SecondaryIdx]->selectedUrls();\r
-            assert(urls.count() == 2);\r
+            Q_ASSERT(urls.count() == 2);\r
             urlA = urls[0];\r
             urlB = urls[1];\r
             break;\r
             urlA = urls[0];\r
             urlB = urls[1];\r
             break;\r
@@ -930,9 +945,9 @@ void DolphinMainWindow::compareFiles()
 \r
         case 1: {\r
             urlA = urls[0];\r
 \r
         case 1: {\r
             urlA = urls[0];\r
-            assert(m_view[SecondaryIdx] != 0);\r
+            Q_ASSERT(m_view[SecondaryIdx] != 0);\r
             urls = m_view[SecondaryIdx]->selectedUrls();\r
             urls = m_view[SecondaryIdx]->selectedUrls();\r
-            assert(urls.count() == 1);\r
+            Q_ASSERT(urls.count() == 1);\r
             urlB = urls[0];\r
             break;\r
         }\r
             urlB = urls[0];\r
             break;\r
         }\r
@@ -946,7 +961,7 @@ void DolphinMainWindow::compareFiles()
         default: {\r
             // may not happen: compareFiles may only get invoked if 2\r
             // files are selected\r
         default: {\r
             // may not happen: compareFiles may only get invoked if 2\r
             // files are selected\r
-            assert(false);\r
+            Q_ASSERT(false);\r
         }\r
     }\r
 \r
         }\r
     }\r
 \r
@@ -983,7 +998,7 @@ void DolphinMainWindow::init()
     DolphinSettings& settings = DolphinSettings::instance();\r
 \r
     KBookmarkManager* manager = settings.bookmarkManager();\r
     DolphinSettings& settings = DolphinSettings::instance();\r
 \r
     KBookmarkManager* manager = settings.bookmarkManager();\r
-    assert(manager != 0);\r
+    Q_ASSERT(manager != 0);\r
     KBookmarkGroup root = manager->root();\r
     if (root.first().isNull()) {\r
         root.addBookmark(manager, i18n("Home"), settings.generalSettings()->homeUrl(), "folder-home");\r
     KBookmarkGroup root = manager->root();\r
     if (root.first().isNull()) {\r
         root.addBookmark(manager, i18n("Home"), settings.generalSettings()->homeUrl(), "folder-home");\r
@@ -1437,19 +1452,19 @@ void DolphinMainWindow::updateGoActions()
 void DolphinMainWindow::copyUrls(const KUrl::List& source, const KUrl& dest)\r
 {\r
     KonqOperations::copy(this, KonqOperations::COPY, source, dest);\r
 void DolphinMainWindow::copyUrls(const KUrl::List& source, const KUrl& dest)\r
 {\r
     KonqOperations::copy(this, KonqOperations::COPY, source, dest);\r
-    m_undoOperations.append(KonqOperations::COPY);\r
+    m_undoCommandTypes.append(KonqUndoManager::COPY);\r
 }\r
 \r
 void DolphinMainWindow::moveUrls(const KUrl::List& source, const KUrl& dest)\r
 {\r
     KonqOperations::copy(this, KonqOperations::MOVE, source, dest);\r
 }\r
 \r
 void DolphinMainWindow::moveUrls(const KUrl::List& source, const KUrl& dest)\r
 {\r
     KonqOperations::copy(this, KonqOperations::MOVE, source, dest);\r
-    m_undoOperations.append(KonqOperations::MOVE);\r
+    m_undoCommandTypes.append(KonqUndoManager::MOVE);\r
 }\r
 \r
 void DolphinMainWindow::linkUrls(const KUrl::List& source, const KUrl& dest)\r
 {\r
     KonqOperations::copy(this, KonqOperations::LINK, source, dest);\r
 }\r
 \r
 void DolphinMainWindow::linkUrls(const KUrl::List& source, const KUrl& dest)\r
 {\r
     KonqOperations::copy(this, KonqOperations::LINK, source, dest);\r
-    m_undoOperations.append(KonqOperations::LINK);\r
+    m_undoCommandTypes.append(KonqUndoManager::LINK);\r
 }\r
 \r
 void DolphinMainWindow::clearStatusBar()\r
 }\r
 \r
 void DolphinMainWindow::clearStatusBar()\r
@@ -1489,7 +1504,7 @@ DolphinMainWindow::UndoUiInterface::UndoUiInterface(DolphinMainWindow* mainWin)
     KonqUndoManager::UiInterface(mainWin),\r
     m_mainWin(mainWin)\r
 {\r
     KonqUndoManager::UiInterface(mainWin),\r
     m_mainWin(mainWin)\r
 {\r
-    assert(m_mainWin != 0);\r
+    Q_ASSERT(m_mainWin != 0);\r
 }\r
 \r
 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()\r
 }\r
 \r
 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()\r
index ff9fbf6a96cb1f6c6ffa13c0fe2622ef8ca36b61..57d3708905cf584ec6d30bc1e32b6f7aaf853b17 100644 (file)
@@ -26,7 +26,6 @@
 
 #include <kmainwindow.h>
 #include <ksortablelist.h>
 
 #include <kmainwindow.h>
 #include <ksortablelist.h>
-#include <konq_operations.h>
 #include <konq_undo.h>
 
 #include <QList>
 #include <konq_undo.h>
 
 #include <QList>
@@ -73,19 +72,22 @@ public:
     DolphinView* activeView() const { return m_activeView; }
 
     /**
     DolphinView* activeView() const { return m_activeView; }
 
     /**
-     * Handles the dropping of Urls to the given
+     * Handles the dropping of URLs to the given
      * destination. A context menu with the options
      * 'Move Here', 'Copy Here', 'Link Here' and
      * 'Cancel' is offered to the user.
      * destination. A context menu with the options
      * 'Move Here', 'Copy Here', 'Link Here' and
      * 'Cancel' is offered to the user.
-     * @param urls        List of Urls which have been
+     * @param urls        List of URLs which have been
      *                    dropped.
      *                    dropped.
-     * @param destination Destination Url, where the
-     *                    list or Urls should be moved,
+     * @param destination Destination URL, where the
+     *                    list or URLs should be moved,
      *                    copied or linked to.
      */
     void dropUrls(const KUrl::List& urls,
                   const KUrl& destination);
 
      *                    copied or linked to.
      */
     void dropUrls(const KUrl::List& urls,
                   const KUrl& destination);
 
+    /** Renames the item represented by \a oldUrl to \a newUrl. */
+    void rename(const KUrl& oldUrl, const KUrl& newUrl);
+
     /**
      * Refreshs the views of the main window by recreating them dependent from
      * the given Dolphin settings.
     /**
      * Refreshs the views of the main window by recreating them dependent from
      * the given Dolphin settings.
@@ -146,7 +148,10 @@ private slots:
     /** Updates the 'Create New...' sub menu. */
     void updateNewMenu();
 
     /** Updates the 'Create New...' sub menu. */
     void updateNewMenu();
 
-    /** Renames the selected item of the active view. */
+    /**
+     * Let the user input a name for the selected item(s) and trigger
+     * a renaming afterwards.
+     */
     void rename();
 
     /** Moves the selected items of the active view to the trash. */
     void rename();
 
     /** Moves the selected items of the active view to the trash. */
@@ -307,16 +312,16 @@ private slots:
      */
     void adjustViewProperties();
 
      */
     void adjustViewProperties();
 
-    /** Goes back on step of the Url history. */
+    /** Goes back on step of the URL history. */
     void goBack();
 
     void goBack();
 
-    /** Goes forward one step of the Url history. */
+    /** Goes forward one step of the URL history. */
     void goForward();
 
     void goForward();
 
-    /** Goes up one hierarchy of the current Url. */
+    /** Goes up one hierarchy of the current URL. */
     void goUp();
 
     void goUp();
 
-    /** Goes to the home Url. */
+    /** Goes to the home URL. */
     void goHome();
 
     /** Opens a terminal for the current shown directory. */
     void goHome();
 
     /** Opens a terminal for the current shown directory. */
@@ -360,7 +365,7 @@ private slots:
 
     /**
      * Updates the caption of the main window and the state
 
     /**
      * Updates the caption of the main window and the state
-     * of all menu actions which depend from a changed Url.
+     * of all menu actions which depend from a changed URL.
      */
     void slotUrlChanged(const KUrl& url);
 
      */
     void slotUrlChanged(const KUrl& url);
 
@@ -430,7 +435,7 @@ private:
     DolphinView* m_view[SecondaryIdx + 1];
 
     /// remember pending undo operations until they are finished
     DolphinView* m_view[SecondaryIdx + 1];
 
     /// remember pending undo operations until they are finished
-    QList<KonqOperations::Operation> m_undoOperations;
+    QList<KonqUndoManager::CommandType> m_undoCommandTypes;
 };
 
 #endif // _DOLPHIN_H_
 };
 
 #endif // _DOLPHIN_H_
index 6569530cea1fc6705a2b5f100c1d7bf6fa0db836..3602d1563668b3ac85b065e8a5573651284e7757 100644 (file)
@@ -20,8 +20,6 @@
 
 #include "dolphinview.h"
 
 
 #include "dolphinview.h"
 
-#include <assert.h>
-
 #include <QApplication>
 #include <QClipboard>
 #include <QDropEvent>
 #include <QApplication>
 #include <QClipboard>
 #include <QDropEvent>
@@ -250,6 +248,7 @@ bool DolphinView::showHiddenFiles() const
 
 void DolphinView::renameSelectedItems()
 {
 
 void DolphinView::renameSelectedItems()
 {
+    DolphinView* view = mainWindow()->activeView();
     const KUrl::List urls = selectedUrls();
     if (urls.count() > 1) {
         // More than one item has been selected for renaming. Open
     const KUrl::List urls = selectedUrls();
     if (urls.count() > 1) {
         // More than one item has been selected for renaming. Open
@@ -259,10 +258,9 @@ void DolphinView::renameSelectedItems()
             return;
         }
 
             return;
         }
 
-        DolphinView* view = mainWindow()->activeView();
         const QString& newName = dialog.newName();
         if (newName.isEmpty()) {
         const QString& newName = dialog.newName();
         if (newName.isEmpty()) {
-            view->statusBar()->setMessage(i18n("The new item name is invalid."),
+            view->statusBar()->setMessage(dialog.errorString(),
                                           DolphinStatusBar::Error);
         }
         else {
                                           DolphinStatusBar::Error);
         }
         else {
@@ -271,13 +269,13 @@ void DolphinView::renameSelectedItems()
             //UndoManager& undoMan = UndoManager::instance();
             //undoMan.beginMacro();
 
             //UndoManager& undoMan = UndoManager::instance();
             //undoMan.beginMacro();
 
-            assert(newName.contains('#'));
+            Q_ASSERT(newName.contains('#'));
 
             const int urlsCount = urls.count();
 
             // iterate through all selected items and rename them...
             const int replaceIndex = newName.indexOf('#');
 
             const int urlsCount = urls.count();
 
             // iterate through all selected items and rename them...
             const int replaceIndex = newName.indexOf('#');
-            assert(replaceIndex >= 0);
+            Q_ASSERT(replaceIndex >= 0);
             for (int i = 0; i < urlsCount; ++i) {
                 const KUrl& source = urls[i];
                 QString number;
             for (int i = 0; i < urlsCount; ++i) {
                 const KUrl& source = urls[i];
                 QString number;
@@ -311,28 +309,26 @@ void DolphinView::renameSelectedItems()
     else {
         // Only one item has been selected for renaming. Use the custom
         // renaming mechanism from the views.
     else {
         // Only one item has been selected for renaming. Use the custom
         // renaming mechanism from the views.
-        assert(urls.count() == 1);
-        // TODO:
-        /*if (m_mode == DetailsView) {
-            Q3ListViewItem* item = m_iconsView->firstChild();
-            while (item != 0) {
-                if (item->isSelected()) {
-                    m_iconsView->rename(item, DolphinDetailsView::NameColumn);
-                    break;
-                }
-                item = item->nextSibling();
-            }
+        Q_ASSERT(urls.count() == 1);
+
+        // TODO: until KFileItemDelegate supports editing, use the the Dolphin
+        // rename dialog as temporary workaround:
+        RenameDialog dialog(urls);
+        if (dialog.exec() == QDialog::Rejected) {
+            return;
+        }
+
+        const QString& newName = dialog.newName();
+        if (newName.isEmpty()) {
+            view->statusBar()->setMessage(dialog.errorString(),
+                                          DolphinStatusBar::Error);
         }
         else {
         }
         else {
-            KFileIconViewItem* item = static_cast<KFileIconViewItem*>(m_iconsView->firstItem());
-            while (item != 0) {
-                if (item->isSelected()) {
-                    item->rename();
-                    break;
-                }
-                item = static_cast<KFileIconViewItem*>(item->nextItem());
-            }
-        }*/
+            const KUrl& oldUrl = urls.first();
+            KUrl newUrl = oldUrl.upUrl();
+            newUrl.addPath(newName);
+            m_mainWindow->rename(oldUrl, newUrl);
+        }
     }
 }
 
     }
 }
 
@@ -894,7 +890,7 @@ QString DolphinView::selectionStatusBarText() const
 
 void DolphinView::showFilterBar(bool show)
 {
 
 void DolphinView::showFilterBar(bool show)
 {
-    assert(m_filterBar != 0);
+    Q_ASSERT(m_filterBar != 0);
     if (show) {
         m_filterBar->show();
     }
     if (show) {
         m_filterBar->show();
     }
@@ -1001,7 +997,7 @@ void DolphinView::dropUrls(const KUrl::List& urls,
     KFileItem* directory = 0;
     if (isValidNameIndex(index)) {
         KFileItem* item = fileItem(index);
     KFileItem* directory = 0;
     if (isValidNameIndex(index)) {
         KFileItem* item = fileItem(index);
-        assert(item != 0);
+        Q_ASSERT(item != 0);
         if (item->isDir()) {
             // the URLs are dropped above a directory
             directory = item;
         if (item->isDir()) {
             // the URLs are dropped above a directory
             directory = item;
@@ -1073,8 +1069,8 @@ void DolphinView::createView()
         m_fileItemDelegate = 0;
     }
 
         m_fileItemDelegate = 0;
     }
 
-    assert(m_iconsView == 0);
-    assert(m_detailsView == 0);
+    Q_ASSERT(m_iconsView == 0);
+    Q_ASSERT(m_detailsView == 0);
 
     // ... and recreate it representing the current mode
     switch (m_mode) {
 
     // ... and recreate it representing the current mode
     switch (m_mode) {
@@ -1089,7 +1085,7 @@ void DolphinView::createView()
             break;
     }
 
             break;
     }
 
-    assert(view != 0);
+    Q_ASSERT(view != 0);
 
     m_fileItemDelegate = new KFileItemDelegate(view);
     view->setItemDelegate(m_fileItemDelegate);
 
     m_fileItemDelegate = new KFileItemDelegate(view);
     view->setItemDelegate(m_fileItemDelegate);
index 8aabb2f839b61b05211ee64b79e22f027fb2c3ad..e68feff8d29d4cc8957476148dd7441126fdf536 100644 (file)
@@ -1,6 +1,5 @@
 /***************************************************************************
 /***************************************************************************
- *   Copyright (C) 2006 by Peter Penz                                      *
- *   peter.penz@gmx.at                                                     *
+ *   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  *
  *                                                                         *
  *   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  *
  ***************************************************************************/
 
 #include "renamedialog.h"
  ***************************************************************************/
 
 #include "renamedialog.h"
-#include <klocale.h>
-#include <qlabel.h>
-#include <qlayout.h>
-#include <q3vbox.h>
-//Added by qt3to4:
-#include <Q3VBoxLayout>
-#include <assert.h>
+
 #include <klineedit.h>
 #include <klineedit.h>
+#include <klocale.h>
+
+#include <QLabel>
+#include <QVBoxLayout>
 
 RenameDialog::RenameDialog(const KUrl::List& items) :
     KDialog()
 
 RenameDialog::RenameDialog(const KUrl::List& items) :
     KDialog()
@@ -37,19 +34,23 @@ RenameDialog::RenameDialog(const KUrl::List& items) :
 
     setButtonGuiItem(Ok, KGuiItem(i18n("Rename"), "dialog-apply"));
 
 
     setButtonGuiItem(Ok, KGuiItem(i18n("Rename"), "dialog-apply"));
 
-    QWidget *page = new QWidget(this);
+    QWidgetpage = new QWidget(this);
     setMainWidget(page);
 
     setMainWidget(page);
 
-    Q3VBoxLayout* topLayout = new Q3VBoxLayout(page, 0, spacingHint());
+    QVBoxLayout* topLayout = new QVBoxLayout(page);
     topLayout->setMargin(KDialog::marginHint());
 
     const int itemCount = items.count();
     topLayout->setMargin(KDialog::marginHint());
 
     const int itemCount = items.count();
-    QLabel* editLabel = new QLabel(i18n("Rename the %1 selected items to:",itemCount),
+    QLabel* editLabel = new QLabel(i18n("Rename the %1 selected items to:", itemCount),
                                    page);
 
     m_lineEdit = new KLineEdit(page);
     m_newName = i18n("New name #");
                                    page);
 
     m_lineEdit = new KLineEdit(page);
     m_newName = i18n("New name #");
-    assert(itemCount > 1);
+
+    // TODO: reactivate assertion as soon as KFileItemDelegate supports renaming of
+    // single items
+    //Q_ASSERT(itemCount > 1);
+
     QString postfix(items[0].prettyUrl().section('.',1));
     if (postfix.length() > 0) {
         // The first item seems to have a postfix (e. g. 'jpg' or 'txt'). Now
     QString postfix(items[0].prettyUrl().section('.',1));
     if (postfix.length() > 0) {
         // The first item seems to have a postfix (e. g. 'jpg' or 'txt'). Now
@@ -88,8 +89,12 @@ void RenameDialog::slotButtonClicked(int button)
 {
     if (button==Ok) {
         m_newName = m_lineEdit->text();
 {
     if (button==Ok) {
         m_newName = m_lineEdit->text();
-        if (m_newName.contains('#') != 1) {
+        if (m_newName.isEmpty()) {
+            m_errorString = i18n("The new name is empty. A name with at least one character must be entered.");
+        }
+        else if (m_newName.contains('#') != 1) {
             m_newName.truncate(0);
             m_newName.truncate(0);
+            m_errorString = i18n("The name must contain exactly one # character.");
         }
     }
 
         }
     }
 
index 093484f2b62fca4f89bde8bda665fdcace3d546e..c08856f8c8aaac9870a076071e7fb37abbf2af86 100644 (file)
@@ -1,6 +1,5 @@
 /***************************************************************************
 /***************************************************************************
- *   Copyright (C) 2006 by Peter Penz                                      *
- *   peter.penz@gmx.at                                                     *
+ *   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  *
  *                                                                         *
  *   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  *
@@ -22,7 +21,8 @@
 
 #include <kdialog.h>
 #include <kurl.h>
 
 #include <kdialog.h>
 #include <kurl.h>
-#include <qstring.h>
+
+#include <QString>
 
 class KLineEdit;
 
 
 class KLineEdit;
 
@@ -35,10 +35,15 @@ class KLineEdit;
  * RenameDialog dialog(...);
  * if (dialog.exec() == QDialog::Accepted) {
  *     const QString& newName = dialog.newName();
  * RenameDialog dialog(...);
  * if (dialog.exec() == QDialog::Accepted) {
  *     const QString& newName = dialog.newName();
- *     // ... rename items corresponding to the new name
+ *     if (newName.isEmpty()) {
+ *         // an invalid name has been chosen, use
+ *         // dialog.errorString() to tell the user about this
+ *     }
+ *     else {
+ *         // rename items corresponding to the new name
+ *     }
  * }
  * \endcode
  * }
  * \endcode
- * @author Peter Penz
  */
 class RenameDialog : public KDialog
 {
  */
 class RenameDialog : public KDialog
 {
@@ -56,12 +61,18 @@ public:
      */
     const QString& newName() const { return m_newName; }
 
      */
     const QString& newName() const { return m_newName; }
 
+    /**
+     * Returns the error string, if Dialog::newName() returned an empty string.
+     */
+    const QString& errorString() const { return m_errorString; }
+
 protected slots:
     virtual void slotButtonClicked(int button);
 
 private:
     KLineEdit* m_lineEdit;
     QString m_newName;
 protected slots:
     virtual void slotButtonClicked(int button);
 
 private:
     KLineEdit* m_lineEdit;
     QString m_newName;
+    QString m_errorString;
 };
 
 #endif
 };
 
 #endif