]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinmainwindow.cpp
* Move code from DolphinDropController to DragAndDropHelper.
[dolphin.git] / src / dolphinmainwindow.cpp
index e14cb1c2d36fa95424bd368a14064b8708b3541e..edff432a4f65a72886d5e99f3779c9f63923385d 100644 (file)
@@ -21,7 +21,6 @@
 
 #include "dolphinmainwindow.h"
 #include "dolphinviewactionhandler.h"
-#include "dolphindropcontroller.h"
 
 #include <config-nepomuk.h>
 
@@ -58,6 +57,7 @@
 #include <kio/netaccess.h>
 #include <kinputdialog.h>
 #include <klocale.h>
+#include <kprotocolmanager.h>
 #include <kmenu.h>
 #include <kmenubar.h>
 #include <kmessagebox.h>
@@ -82,6 +82,8 @@
 #include <QSplitter>
 #include <QDockWidget>
 
+#include <kdebug.h>
+
 DolphinMainWindow::DolphinMainWindow(int id) :
     KXmlGuiWindow(0),
     m_newMenu(0),
@@ -108,6 +110,10 @@ DolphinMainWindow::DolphinMainWindow(int id) :
             this, SLOT(slotUndoAvailable(bool)));
     connect(undoManager, SIGNAL(undoTextChanged(const QString&)),
             this, SLOT(slotUndoTextChanged(const QString&)));
+    connect(undoManager, SIGNAL(jobRecordingStarted(CommandType)),
+            this, SLOT(clearStatusBar()));
+    connect(undoManager, SIGNAL(jobRecordingFinished(CommandType)),
+            this, SLOT(showCommand(CommandType)));
     connect(DolphinSettings::instance().placesModel(), SIGNAL(errorMessage(const QString&)),
             this, SLOT(slotHandlePlacesError(const QString&)));
 }
@@ -132,10 +138,39 @@ void DolphinMainWindow::toggleViews()
     m_viewTab[m_tabIndex].secondaryView = container;
 }
 
-void DolphinMainWindow::slotDoingOperation(KIO::FileUndoManager::CommandType commandType)
+void DolphinMainWindow::showCommand(CommandType command)
 {
-    clearStatusBar();
-    m_undoCommandTypes.append(commandType);
+    DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
+    switch (command) {
+    case KIO::FileUndoManager::Copy:
+        statusBar->setMessage(i18nc("@info:status", "Copy operation completed."),
+                              DolphinStatusBar::OperationCompleted);
+        break;
+    case KIO::FileUndoManager::Move:
+        statusBar->setMessage(i18nc("@info:status", "Move operation completed."),
+                              DolphinStatusBar::OperationCompleted);
+        break;
+    case KIO::FileUndoManager::Link:
+        statusBar->setMessage(i18nc("@info:status", "Link operation completed."),
+                              DolphinStatusBar::OperationCompleted);
+        break;
+    case KIO::FileUndoManager::Trash:
+        statusBar->setMessage(i18nc("@info:status", "Move to trash operation completed."),
+                              DolphinStatusBar::OperationCompleted);
+        break;
+    case KIO::FileUndoManager::Rename:
+        statusBar->setMessage(i18nc("@info:status", "Renaming operation completed."),
+                              DolphinStatusBar::OperationCompleted);
+        break;
+
+    case KIO::FileUndoManager::Mkdir:
+        statusBar->setMessage(i18nc("@info:status", "Created folder."),
+                              DolphinStatusBar::OperationCompleted);
+        break;
+
+    default:
+        break;
+    }
 }
 
 void DolphinMainWindow::refreshViews()
@@ -147,23 +182,17 @@ void DolphinMainWindow::refreshViews()
     // the secondary view
     DolphinViewContainer* activeViewContainer = m_activeViewContainer;
 
-    m_viewTab[m_tabIndex].primaryView->view()->refresh();
-    if (m_viewTab[m_tabIndex].secondaryView != 0) {
-        m_viewTab[m_tabIndex].secondaryView->view()->refresh();
+    const int tabCount = m_viewTab.count();
+    for (int i = 0; i < tabCount; ++i) {
+        m_viewTab[i].primaryView->refresh();
+        if (m_viewTab[i].secondaryView != 0) {
+            m_viewTab[i].secondaryView->refresh();
+        }
     }
 
     setActiveViewContainer(activeViewContainer);
 }
 
-void DolphinMainWindow::dropUrls(const KUrl::List& urls,
-                                 const KUrl& destination)
-{
-    DolphinDropController dropController(this);
-    connect(&dropController, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType)),
-            this, SLOT(slotDoingOperation(KIO::FileUndoManager::CommandType)));
-    dropController.dropUrls(urls, destination);
-}
-
 void DolphinMainWindow::pasteIntoFolder()
 {
     m_activeViewContainer->view()->pasteIntoFolder();
@@ -171,6 +200,13 @@ void DolphinMainWindow::pasteIntoFolder()
 
 void DolphinMainWindow::changeUrl(const KUrl& url)
 {
+    if (!KProtocolManager::supportsListing(url)) {
+        // The URL navigator only checks for validity, not
+        // if the URL can be listed. An error message is
+        // shown due to DolphinViewContainer::restoreView().
+        return;
+    }
+    
     DolphinViewContainer* view = activeViewContainer();
     if (view != 0) {
         view->setUrl(url);
@@ -278,6 +314,8 @@ void DolphinMainWindow::openNewTab(const KUrl& url)
     viewTab.primaryView->view()->reload();
 
     m_viewTab.append(viewTab);
+
+    actionCollection()->action("close_tab")->setEnabled(true);
 }
 
 void DolphinMainWindow::toggleActiveView()
@@ -375,42 +413,6 @@ void DolphinMainWindow::slotUndoAvailable(bool available)
     if (undoAction != 0) {
         undoAction->setEnabled(available);
     }
-
-    if (available && (m_undoCommandTypes.count() > 0)) {
-        const KIO::FileUndoManager::CommandType command = m_undoCommandTypes.takeFirst();
-        DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
-        switch (command) {
-        case KIO::FileUndoManager::Copy:
-            statusBar->setMessage(i18nc("@info:status", "Copy operation completed."),
-                                  DolphinStatusBar::OperationCompleted);
-            break;
-        case KIO::FileUndoManager::Move:
-            statusBar->setMessage(i18nc("@info:status", "Move operation completed."),
-                                  DolphinStatusBar::OperationCompleted);
-            break;
-        case KIO::FileUndoManager::Link:
-            statusBar->setMessage(i18nc("@info:status", "Link operation completed."),
-                                  DolphinStatusBar::OperationCompleted);
-            break;
-        case KIO::FileUndoManager::Trash:
-            statusBar->setMessage(i18nc("@info:status", "Move to trash operation completed."),
-                                  DolphinStatusBar::OperationCompleted);
-            break;
-        case KIO::FileUndoManager::Rename:
-            statusBar->setMessage(i18nc("@info:status", "Renaming operation completed."),
-                                  DolphinStatusBar::OperationCompleted);
-            break;
-
-        case KIO::FileUndoManager::Mkdir:
-            statusBar->setMessage(i18nc("@info:status", "Created folder."),
-                                  DolphinStatusBar::OperationCompleted);
-            break;
-
-        default:
-            break;
-        }
-
-    }
 }
 
 void DolphinMainWindow::slotUndoTextChanged(const QString& text)
@@ -637,7 +639,6 @@ void DolphinMainWindow::quickView()
 
     QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.plasma", "/Previewer", "", "openFile");
     foreach (const KUrl& url, urls) {
-        QList<QVariant> args;
         msg.setArguments(QList<QVariant>() << url.prettyUrl());
         QDBusConnection::sessionBus().send(msg);
     }
@@ -701,7 +702,7 @@ void DolphinMainWindow::closeTab(int index)
     if (index == m_tabIndex) {
         // The tab that should be closed is the active tab. Activate the
         // previous tab before closing the tab.
-        setActiveTab((index > 0) ? index - 1 : 1);
+        m_tabBar->setCurrentIndex((index > 0) ? index - 1 : 1);
     }
 
     // delete tab
@@ -724,6 +725,7 @@ void DolphinMainWindow::closeTab(int index)
     // closing the last tab is not possible
     if (m_viewTab.count() == 1) {
         m_tabBar->removeTab(0);
+        actionCollection()->action("close_tab")->setEnabled(false);
     } else {
         m_tabBar->blockSignals(false);
     }
@@ -772,6 +774,11 @@ void DolphinMainWindow::handlePlacesClick(const KUrl& url, Qt::MouseButtons butt
     }
 }
 
+void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent* event, bool& canDecode)
+{
+    canDecode = KUrl::List::canDecode(event->mimeData());
+}
+
 void DolphinMainWindow::init()
 {
     DolphinSettings& settings = DolphinSettings::instance();
@@ -816,6 +823,8 @@ void DolphinMainWindow::init()
             this, SLOT(openTabContextMenu(int, const QPoint&)));
     connect(m_tabBar, SIGNAL(newTabRequest()),
             this, SLOT(openNewTab()));
+    connect(m_tabBar, SIGNAL(testCanDecode(const QDragMoveEvent*, bool&)),
+            this, SLOT(slotTestCanDecode(const QDragMoveEvent*, bool&)));
     m_tabBar->blockSignals(true);  // signals get unblocked after at least 2 tabs are open
 
     QWidget* centralWidget = new QWidget(this);
@@ -825,15 +834,13 @@ void DolphinMainWindow::init()
     m_centralWidgetLayout->addWidget(m_tabBar);
     m_centralWidgetLayout->addWidget(m_viewTab[m_tabIndex].splitter);
 
-
     setCentralWidget(centralWidget);
     setupDockWidgets();
+    emit urlChanged(homeUrl);
 
     setupGUI(Keys | Save | Create | ToolBar);
-    createGUI();
 
     stateChanged("new_file");
-    setAutoSaveSettings();
 
     QClipboard* clipboard = QApplication::clipboard();
     connect(clipboard, SIGNAL(dataChanged()),
@@ -846,12 +853,15 @@ void DolphinMainWindow::init()
     }
     updateViewActions();
 
+    QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
+    showFilterBarAction->setChecked(generalSettings->filterBar());
+
     if (firstRun) {
         // assure a proper default size if Dolphin runs the first time
         resize(750, 500);
     }
 
-    emit urlChanged(homeUrl);
+    m_showMenuBar->setChecked(!menuBar()->isHidden());  // workaround for bug #171080
 }
 
 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContainer)
@@ -913,6 +923,7 @@ void DolphinMainWindow::setupActions()
 
     QAction* closeTab = new QAction(KIcon("tab-close"), i18nc("@action:inmenu File", "Close Tab"), this);
     closeTab->setShortcut(Qt::CTRL | Qt::Key_W);
+    closeTab->setEnabled(false);
     connect(closeTab, SIGNAL(triggered()), this, SLOT(closeTab()));
     actionCollection()->addAction("close_tab", closeTab);
 
@@ -997,7 +1008,7 @@ void DolphinMainWindow::setupActions()
     KAction* quickView = actionCollection()->addAction("quick_view");
     quickView->setText(i18nc("@action:inmenu Tools", "Quick View"));
     quickView->setIcon(KIcon("view-preview"));
-    quickView->setShortcut(Qt::Key_Space);
+    quickView->setShortcut(Qt::CTRL + Qt::Key_Return);
     quickView->setEnabled(false);
     connect(quickView, SIGNAL(triggered()), this, SLOT(quickView()));
 
@@ -1045,8 +1056,6 @@ void DolphinMainWindow::setupDockWidgets()
             this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
     connect(treeWidget, SIGNAL(changeSelection(KFileItemList)),
             this, SLOT(changeSelection(KFileItemList)));
-    connect(treeWidget, SIGNAL(urlsDropped(KUrl::List, KUrl)),
-            this, SLOT(dropUrls(KUrl::List, KUrl)));
 
     // setup "Terminal"
 #ifndef Q_OS_WIN
@@ -1160,8 +1169,6 @@ void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
             this, SLOT(slotRequestItemInfo(KFileItem)));
     connect(view, SIGNAL(activated()),
             this, SLOT(toggleActiveView()));
-    connect(view, SIGNAL(doingOperation(KIO::FileUndoManager::CommandType)),
-            this, SLOT(slotDoingOperation(KIO::FileUndoManager::CommandType)));
     connect(view, SIGNAL(tabRequested(const KUrl&)),
             this, SLOT(openNewTab(const KUrl&)));