]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinmainwindow.cpp
don't draw anything if the bounding rectangle is empty
[dolphin.git] / src / dolphinmainwindow.cpp
index 8f68724ac2c889ae883748011274e0a4226f4aae..ddabf21a4ff7d37a3b90fbeb64ba3e9ad45fdf36 100644 (file)
 #include <kicon.h>
 #include <kiconloader.h>
 #include <kio/netaccess.h>
-#include <kio/deletejob.h>
-#include <kio/renamedialog.h>
 #include <kinputdialog.h>
 #include <klocale.h>
 #include <kmenu.h>
+#include <kmenubar.h>
 #include <kmessagebox.h>
 #include <konqmimedata.h>
 #include <konq_operations.h>
@@ -78,6 +77,7 @@
 DolphinMainWindow::DolphinMainWindow(int id) :
     KXmlGuiWindow(0),
     m_newMenu(0),
+    m_showMenuBar(0),
     m_splitter(0),
     m_activeViewContainer(0),
     m_id(id)
@@ -89,9 +89,9 @@ DolphinMainWindow::DolphinMainWindow(int id) :
     new MainWindowAdaptor(this);
     QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id), this);
 
-    KonqUndoManager::incRef();
+    KonqFileUndoManager::incRef();
 
-    KonqUndoManager* undoManager = KonqUndoManager::self();
+    KonqFileUndoManager* undoManager = KonqFileUndoManager::self();
     undoManager->setUiInterface(new UndoUiInterface(this));
 
     connect(undoManager, SIGNAL(undoAvailable(bool)),
@@ -104,7 +104,7 @@ DolphinMainWindow::DolphinMainWindow(int id) :
 
 DolphinMainWindow::~DolphinMainWindow()
 {
-    KonqUndoManager::decRef();
+    KonqFileUndoManager::decRef();
     DolphinApplication::app()->removeMainWindow(this);
 }
 
@@ -123,11 +123,10 @@ void DolphinMainWindow::toggleViews()
     m_viewContainer[SecondaryView] = container;
 }
 
-void DolphinMainWindow::rename(const KUrl& oldUrl, const KUrl& newUrl)
+void DolphinMainWindow::slotDoingOperation(KonqFileUndoManager::CommandType commandType)
 {
     clearStatusBar();
-    KonqOperations::rename(this, oldUrl, newUrl);
-    m_undoCommandTypes.append(KonqUndoManager::RENAME);
+    m_undoCommandTypes.append(commandType);
 }
 
 void DolphinMainWindow::refreshViews()
@@ -484,34 +483,26 @@ void DolphinMainWindow::updateNewMenu()
 void DolphinMainWindow::rename()
 {
     clearStatusBar();
-    m_activeViewContainer->renameSelectedItems();
+    m_activeViewContainer->view()->renameSelectedItems();
 }
 
 void DolphinMainWindow::moveToTrash()
 {
     clearStatusBar();
-    const KUrl::List selectedUrls = m_activeViewContainer->view()->selectedUrls();
-    KonqOperations::del(this, KonqOperations::TRASH, selectedUrls);
-    m_undoCommandTypes.append(KonqUndoManager::TRASH);
+
+    DolphinView* view = m_activeViewContainer->view();
+
+    if (QApplication::keyboardModifiers() & Qt::ShiftModifier) {
+        view->deleteSelectedItems();
+    } else {
+        view->trashSelectedItems();
+    }
 }
 
 void DolphinMainWindow::deleteItems()
 {
     clearStatusBar();
-
-    const KUrl::List list = m_activeViewContainer->view()->selectedUrls();
-    const bool del = KonqOperations::askDeleteConfirmation(list,
-                     KonqOperations::DEL,
-                     KonqOperations::DEFAULT_CONFIRMATION,
-                     this);
-
-    if (del) {
-        KIO::Job* job = KIO::del(list);
-        connect(job, SIGNAL(result(KJob*)),
-                this, SLOT(slotHandleJobError(KJob*)));
-        connect(job, SIGNAL(result(KJob*)),
-                this, SLOT(slotDeleteFileFinished(KJob*)));
-    }
+    m_activeViewContainer->view()->deleteSelectedItems();
 }
 
 void DolphinMainWindow::properties()
@@ -535,24 +526,6 @@ void DolphinMainWindow::slotHandlePlacesError(const QString &message)
     }
 }
 
-void DolphinMainWindow::slotHandleJobError(KJob* job)
-{
-    if (job->error() != 0) {
-        DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
-        statusBar->setMessage(job->errorString(),
-                              DolphinStatusBar::Error);
-    }
-}
-
-void DolphinMainWindow::slotDeleteFileFinished(KJob* job)
-{
-    if (job->error() == 0) {
-        DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
-        statusBar->setMessage(i18nc("@info:status", "Delete operation completed."),
-                              DolphinStatusBar::OperationCompleted);
-    }
-}
-
 void DolphinMainWindow::slotUndoAvailable(bool available)
 {
     QAction* undoAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Undo));
@@ -561,31 +534,31 @@ void DolphinMainWindow::slotUndoAvailable(bool available)
     }
 
     if (available && (m_undoCommandTypes.count() > 0)) {
-        const KonqUndoManager::CommandType command = m_undoCommandTypes.takeFirst();
+        const KonqFileUndoManager::CommandType command = m_undoCommandTypes.takeFirst();
         DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
         switch (command) {
-        case KonqUndoManager::COPY:
+        case KonqFileUndoManager::COPY:
             statusBar->setMessage(i18nc("@info:status", "Copy operation completed."),
                                   DolphinStatusBar::OperationCompleted);
             break;
-        case KonqUndoManager::MOVE:
+        case KonqFileUndoManager::MOVE:
             statusBar->setMessage(i18nc("@info:status", "Move operation completed."),
                                   DolphinStatusBar::OperationCompleted);
             break;
-        case KonqUndoManager::LINK:
+        case KonqFileUndoManager::LINK:
             statusBar->setMessage(i18nc("@info:status", "Link operation completed."),
                                   DolphinStatusBar::OperationCompleted);
             break;
-        case KonqUndoManager::TRASH:
+        case KonqFileUndoManager::TRASH:
             statusBar->setMessage(i18nc("@info:status", "Move to trash operation completed."),
                                   DolphinStatusBar::OperationCompleted);
             break;
-        case KonqUndoManager::RENAME:
+        case KonqFileUndoManager::RENAME:
             statusBar->setMessage(i18nc("@info:status", "Renaming operation completed."),
                                   DolphinStatusBar::OperationCompleted);
             break;
 
-        case KonqUndoManager::MKDIR:
+        case KonqFileUndoManager::MKDIR:
             statusBar->setMessage(i18nc("@info:status", "Created folder."),
                                   DolphinStatusBar::OperationCompleted);
             break;
@@ -608,60 +581,22 @@ void DolphinMainWindow::slotUndoTextChanged(const QString& text)
 void DolphinMainWindow::undo()
 {
     clearStatusBar();
-    KonqUndoManager::self()->undo();
+    KonqFileUndoManager::self()->undo();
 }
 
 void DolphinMainWindow::cut()
 {
-    QMimeData* mimeData = new QMimeData();
-    const KUrl::List kdeUrls = m_activeViewContainer->view()->selectedUrls();
-    const KUrl::List mostLocalUrls;
-    KonqMimeData::populateMimeData(mimeData, kdeUrls, mostLocalUrls, true);
-    QApplication::clipboard()->setMimeData(mimeData);
+    m_activeViewContainer->view()->cutSelectedItems();
 }
 
 void DolphinMainWindow::copy()
 {
-    QMimeData* mimeData = new QMimeData();
-    const KUrl::List kdeUrls = m_activeViewContainer->view()->selectedUrls();
-    const KUrl::List mostLocalUrls;
-    KonqMimeData::populateMimeData(mimeData, kdeUrls, mostLocalUrls, false);
-
-    QApplication::clipboard()->setMimeData(mimeData);
+    m_activeViewContainer->view()->copySelectedItems();
 }
 
 void DolphinMainWindow::paste()
 {
-    QClipboard* clipboard = QApplication::clipboard();
-    const QMimeData* mimeData = clipboard->mimeData();
-
-    clearStatusBar();
-
-    const KUrl::List sourceUrls = KUrl::List::fromMimeData(mimeData);
-
-    // per default the pasting is done into the current Url of the view
-    KUrl destUrl(m_activeViewContainer->url());
-
-    // check whether the pasting should be done into a selected directory
-    KUrl::List selectedUrls = m_activeViewContainer->view()->selectedUrls();
-    if (selectedUrls.count() == 1) {
-        const KFileItem fileItem(S_IFDIR,
-                                 KFileItem::Unknown,
-                                 selectedUrls.first(),
-                                 true);
-        if (fileItem.isDir()) {
-            // only one item is selected which is a directory, hence paste
-            // into this directory
-            destUrl = selectedUrls.first();
-        }
-    }
-
-    if (KonqMimeData::decodeIsCutSelection(mimeData)) {
-        moveUrls(sourceUrls, destUrl);
-        clipboard->clear();
-    } else {
-        copyUrls(sourceUrls, destUrl);
-    }
+    m_activeViewContainer->view()->paste();
 }
 
 void DolphinMainWindow::updatePasteAction()
@@ -671,39 +606,9 @@ void DolphinMainWindow::updatePasteAction()
         return;
     }
 
-    QString text(i18nc("@action:inmenu", "Paste"));
-    QClipboard* clipboard = QApplication::clipboard();
-    const QMimeData* mimeData = clipboard->mimeData();
-
-    KUrl::List urls = KUrl::List::fromMimeData(mimeData);
-    if (!urls.isEmpty()) {
-        pasteAction->setEnabled(true);
-
-        pasteAction->setText(i18ncp("@action:inmenu", "Paste One File", "Paste %1 Files", urls.count()));
-    } else {
-        pasteAction->setEnabled(false);
-        pasteAction->setText(i18nc("@action:inmenu", "Paste"));
-    }
-
-    if (pasteAction->isEnabled()) {
-        KUrl::List urls = m_activeViewContainer->view()->selectedUrls();
-        const uint count = urls.count();
-        if (count > 1) {
-            // pasting should not be allowed when more than one file
-            // is selected
-            pasteAction->setEnabled(false);
-        } else if (count == 1) {
-            // Only one file is selected. Pasting is only allowed if this
-            // file is a directory.
-            // TODO: this doesn't work with remote protocols; instead we need a
-            // m_activeViewContainer->selectedFileItems() to get the real KFileItems
-            const KFileItem fileItem(S_IFDIR,
-                                     KFileItem::Unknown,
-                                     urls.first(),
-                                     true);
-            pasteAction->setEnabled(fileItem.isDir());
-        }
-    }
+    QPair<bool, QString> pasteInfo = m_activeViewContainer->view()->pasteInfo();
+    pasteAction->setEnabled(pasteInfo.first);
+    pasteAction->setText(pasteInfo.second);
 }
 
 void DolphinMainWindow::selectAll()
@@ -1013,6 +918,12 @@ void DolphinMainWindow::compareFiles()
 
 }
 
+void DolphinMainWindow::toggleShowMenuBar()
+{
+    const bool visible = menuBar()->isVisible();
+    menuBar()->setVisible(!visible);
+}
+
 void DolphinMainWindow::editSettings()
 {
     DolphinSettingsDialog dialog(this);
@@ -1117,21 +1028,13 @@ void DolphinMainWindow::setupActions()
     newWindow->setShortcut(Qt::CTRL | Qt::Key_N);
     connect(newWindow, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
 
-    KAction* rename = actionCollection()->addAction("rename");
-    rename->setText(i18nc("@action:inmenu File", "Rename..."));
-    rename->setShortcut(Qt::Key_F2);
+    KAction* rename = DolphinView::createRenameAction(actionCollection());
     connect(rename, SIGNAL(triggered()), this, SLOT(rename()));
 
-    KAction* moveToTrash = actionCollection()->addAction("move_to_trash");
-    moveToTrash->setText(i18nc("@action:inmenu File", "Move to Trash"));
-    moveToTrash->setIcon(KIcon("user-trash"));
-    moveToTrash->setShortcut(QKeySequence::Delete);
+    KAction* moveToTrash = DolphinView::createMoveToTrashAction(actionCollection());
     connect(moveToTrash, SIGNAL(triggered()), this, SLOT(moveToTrash()));
 
-    KAction* deleteAction = actionCollection()->addAction("delete");
-    deleteAction->setText(i18nc("@action:inmenu File", "Delete"));
-    deleteAction->setShortcut(Qt::SHIFT | Qt::Key_Delete);
-    deleteAction->setIcon(KIcon("edit-delete"));
+    KAction* deleteAction = DolphinView::createDeleteAction(actionCollection());
     connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItems()));
 
     KAction* properties = actionCollection()->addAction("properties");
@@ -1348,6 +1251,7 @@ void DolphinMainWindow::setupActions()
     connect(compareFiles, SIGNAL(triggered()), this, SLOT(compareFiles()));
 
     // setup 'Settings' menu
+    m_showMenuBar = KStandardAction::showMenubar(this, SLOT(toggleShowMenuBar()), actionCollection());
     KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
 }
 
@@ -1460,7 +1364,7 @@ void DolphinMainWindow::updateEditActions()
 
         QAction* renameAction = actionCollection()->action("rename");
         if (renameAction != 0) {
-            renameAction->setEnabled(list.count() >= 1);
+            renameAction->setEnabled(true);
         }
 
         bool enableMoveToTrash = true;
@@ -1536,19 +1440,19 @@ void DolphinMainWindow::updateGoActions()
 void DolphinMainWindow::copyUrls(const KUrl::List& source, const KUrl& dest)
 {
     KonqOperations::copy(this, KonqOperations::COPY, source, dest);
-    m_undoCommandTypes.append(KonqUndoManager::COPY);
+    m_undoCommandTypes.append(KonqFileUndoManager::COPY);
 }
 
 void DolphinMainWindow::moveUrls(const KUrl::List& source, const KUrl& dest)
 {
     KonqOperations::copy(this, KonqOperations::MOVE, source, dest);
-    m_undoCommandTypes.append(KonqUndoManager::MOVE);
+    m_undoCommandTypes.append(KonqFileUndoManager::MOVE);
 }
 
 void DolphinMainWindow::linkUrls(const KUrl::List& source, const KUrl& dest)
 {
     KonqOperations::copy(this, KonqOperations::LINK, source, dest);
-    m_undoCommandTypes.append(KonqUndoManager::LINK);
+    m_undoCommandTypes.append(KonqFileUndoManager::LINK);
 }
 
 void DolphinMainWindow::clearStatusBar()
@@ -1583,6 +1487,8 @@ void DolphinMainWindow::connectViewSignals(int viewIndex)
             this, SLOT(slotRequestItemInfo(KFileItem)));
     connect(view, SIGNAL(activated()),
             this, SLOT(toggleActiveView()));
+    connect(view, SIGNAL(doingOperation(KonqFileUndoManager::CommandType)),
+            this, SLOT(slotDoingOperation(KonqFileUndoManager::CommandType)));
 
     const KUrlNavigator* navigator = container->urlNavigator();
     connect(navigator, SIGNAL(urlChanged(const KUrl&)),
@@ -1631,7 +1537,7 @@ void DolphinMainWindow::toggleAdditionalInfo(const char* actionName,
 }
 
 DolphinMainWindow::UndoUiInterface::UndoUiInterface(DolphinMainWindow* mainWin) :
-    KonqUndoManager::UiInterface(mainWin),
+    KonqFileUndoManager::UiInterface(mainWin),
     m_mainWin(mainWin)
 {
     Q_ASSERT(m_mainWin != 0);