]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinmainwindow.cpp
avoid unnecessary copies by using const & in foreach
[dolphin.git] / src / dolphinmainwindow.cpp
index b165e1cb30d038892a03f6eeffaf4dd73d0b35aa..48956e0936803a0ea127cc4834956fc6dd00640f 100644 (file)
@@ -32,6 +32,7 @@
 #include "dolphinsettingsdialog.h"
 #include "dolphinstatusbar.h"
 #include "dolphinviewcontainer.h"
+#include "fileitemcapabilities.h"
 #include "infosidebarpage.h"
 #include "metadatawidget.h"
 #include "mainwindowadaptor.h"
@@ -101,10 +102,8 @@ DolphinMainWindow::DolphinMainWindow(int id) :
     new MainWindowAdaptor(this);
     QDBusConnection::sessionBus().registerObject(QString("/dolphin/MainWindow%1").arg(m_id), this);
 
-    KonqFileUndoManager::incRef();
-
     KonqFileUndoManager* undoManager = KonqFileUndoManager::self();
-    undoManager->setUiInterface(new UndoUiInterface(this));
+    undoManager->setUiInterface(new UndoUiInterface());
 
     connect(undoManager, SIGNAL(undoAvailable(bool)),
             this, SLOT(slotUndoAvailable(bool)));
@@ -116,7 +115,6 @@ DolphinMainWindow::DolphinMainWindow(int id) :
 
 DolphinMainWindow::~DolphinMainWindow()
 {
-    KonqFileUndoManager::decRef();
     DolphinApplication::app()->removeMainWindow(this);
 }
 
@@ -436,6 +434,7 @@ void DolphinMainWindow::slotUndoTextChanged(const QString& text)
 void DolphinMainWindow::undo()
 {
     clearStatusBar();
+    KonqFileUndoManager::self()->uiInterface()->setParentWidget(this);
     KonqFileUndoManager::self()->undo();
 }
 
@@ -457,10 +456,6 @@ void DolphinMainWindow::paste()
 void DolphinMainWindow::updatePasteAction()
 {
     QAction* pasteAction = actionCollection()->action(KStandardAction::name(KStandardAction::Paste));
-    if (pasteAction == 0) {
-        return;
-    }
-
     QPair<bool, QString> pasteInfo = m_activeViewContainer->view()->pasteInfo();
     pasteAction->setEnabled(pasteInfo.first);
     pasteAction->setText(pasteInfo.second);
@@ -813,6 +808,8 @@ void DolphinMainWindow::init()
             this, SLOT(closeTab(int)));
     connect(m_tabBar, SIGNAL(contextMenu(int, const QPoint&)),
             this, SLOT(openTabContextMenu(int, const QPoint&)));
+    connect(m_tabBar, SIGNAL(newTabRequest()),
+            this, SLOT(openNewTab()));
     m_tabBar->blockSignals(true);  // signals get unblocked after at least 2 tabs are open
 
     QWidget* centralWidget = new QWidget(this);
@@ -1108,26 +1105,11 @@ void DolphinMainWindow::updateEditActions()
     } else {
         stateChanged("has_selection");
 
-        QAction* renameAction = actionCollection()->action("rename");
-        if (renameAction != 0) {
-            renameAction->setEnabled(true);
-        }
-
-        bool enableMoveToTrash = true;
-
-        KFileItemList::const_iterator it = list.begin();
-        const KFileItemList::const_iterator end = list.end();
-        while (it != end) {
-            const KUrl& url = (*it).url();
-            // only enable the 'Move to Trash' action for local files
-            if (!url.isLocalFile()) {
-                enableMoveToTrash = false;
-            }
-            ++it;
-        }
-
-        QAction* moveToTrashAction = actionCollection()->action("move_to_trash");
-        moveToTrashAction->setEnabled(enableMoveToTrash);
+        FileItemCapabilities capabilities(list);
+        actionCollection()->action("rename")->setEnabled(capabilities.supportsMoving());
+        const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving();
+        actionCollection()->action("move_to_trash")->setEnabled(enableMoveToTrash);
+        actionCollection()->action("delete")->setEnabled(capabilities.supportsDeleting());
     }
     updatePasteAction();
 }
@@ -1206,11 +1188,9 @@ QString DolphinMainWindow::tabName(const KUrl& url) const
     return url.equals(KUrl("file:///")) ? "/" : url.fileName();
 }
 
-DolphinMainWindow::UndoUiInterface::UndoUiInterface(DolphinMainWindow* mainWin) :
-    KonqFileUndoManager::UiInterface(mainWin),
-    m_mainWin(mainWin)
+DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
+    KonqFileUndoManager::UiInterface()
 {
-    Q_ASSERT(m_mainWin != 0);
 }
 
 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
@@ -1219,8 +1199,13 @@ DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
 
 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job)
 {
-    DolphinStatusBar* statusBar = m_mainWin->activeViewContainer()->statusBar();
-    statusBar->setMessage(job->errorString(), DolphinStatusBar::Error);
+    DolphinMainWindow* mainWin= qobject_cast<DolphinMainWindow *>(parentWidget());
+    if (mainWin) {
+        DolphinStatusBar* statusBar = mainWin->activeViewContainer()->statusBar();
+        statusBar->setMessage(job->errorString(), DolphinStatusBar::Error);
+    } else {
+        KonqFileUndoManager::UiInterface::jobError(job);
+    }
 }
 
 #include "dolphinmainwindow.moc"