]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinmainwindow.cpp
Fix style-issues in items when not using Oxygen
[dolphin.git] / src / dolphinmainwindow.cpp
index 7d0e0992624a31bdb9cf9aac33efd2a504901efb..3f527d9a5c2b178a535738f6bbb90d63cb6f8106 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at>                  *
+ *   Copyright (C) 2006 by Peter Penz <peter.penz19@gmail.com>             *
  *   Copyright (C) 2006 by Stefan Monov <logixoul@gmail.com>               *
  *   Copyright (C) 2006 by Cvetoslav Ludmiloff <ludmiloff@gmail.com>       *
  *                                                                         *
 
 #include "dolphinmainwindow.h"
 
-#include <assert.h>
+#include <config-nepomuk.h>
 
-#include <kactioncollection.h>
-#include <ktoggleaction.h>
-#include <kbookmarkmanager.h>
-#include <kglobal.h>
-#include <kpropertiesdialog.h>
-#include <kicon.h>
-#include <kiconloader.h>
+#include "dolphinapplication.h"
+#include "dolphindockwidget.h"
+#include "dolphincontextmenu.h"
+#include "dolphinnewfilemenu.h"
+#include "dolphinviewcontainer.h"
+#ifdef HAVE_NEPOMUK
+    #include "panels/search/searchpanel.h"
+    #include <Nepomuk/ResourceManager>
+#endif
+#include "panels/folders/folderspanel.h"
+#include "panels/places/placespanel.h"
+#include "panels/information/informationpanel.h"
+#include "search/dolphinsearchbox.h"
+#include "search/dolphinsearchinformation.h"
+#include "settings/dolphinsettingsdialog.h"
+#include "statusbar/dolphinstatusbar.h"
+#include "views/dolphinviewactionhandler.h"
+#include "views/dolphinremoteencoding.h"
+#include "views/viewproperties.h"
+
+#ifndef Q_OS_WIN
+#include "panels/terminal/terminalpanel.h"
+#endif
+
+#include "dolphin_generalsettings.h"
+#include "dolphin_searchsettings.h"
+
+#include <KAcceleratorManager>
+#include <KAction>
+#include <KActionCollection>
+#include <KActionMenu>
+#include <KConfig>
+#include <KDesktopFile>
 #include <kdeversion.h>
-#include <kstatusbar.h>
-#include <kio/netaccess.h>
-#include <kfiledialog.h>
-#include <kconfig.h>
-#include <kurl.h>
-#include <kaction.h>
-#include <kstandardaction.h>
-#include <kmenu.h>
-#include <kio/renamedialog.h>
-#include <kinputdialog.h>
-#include <kshell.h>
-#include <kdesktopfile.h>
-#include <kstandarddirs.h>
-#include <kprotocolinfo.h>
-#include <kmessagebox.h>
-#include <kservice.h>
-#include <kstandarddirs.h>
-#include <krun.h>
-#include <klocale.h>
+#include <kdualaction.h>
+#include <KFileDialog>
+#include <KFilePlacesModel>
+#include <KGlobal>
+#include <KLineEdit>
+#include <KToolBar>
+#include <KIcon>
+#include <KIconLoader>
+#include <KIO/NetAccess>
+#include <KInputDialog>
+#include <KLocale>
+#include <KProtocolManager>
+#include <KMenu>
+#include <KMenuBar>
+#include <KMessageBox>
+#include <KFileItemListProperties>
 #include <konqmimedata.h>
-
-#include <qclipboard.h>
-#include <q3dragobject.h>
-//Added by qt3to4:
-#include <Q3ValueList>
-#include <QCloseEvent>
+#include <KProtocolInfo>
+#include <KRun>
+#include <KShell>
+#include <KStandardDirs>
+#include <kstatusbar.h>
+#include <KStandardAction>
+#include <ktabbar.h>
+#include <KToggleAction>
+#include <KUrlNavigator>
+#include <KUrl>
+#include <KUrlComboBox>
+#include <KToolInvocation>
+
+#include "views/dolphinplacesmodel.h"
+
+#include <QDesktopWidget>
+#include <QDBusMessage>
+#include <QKeyEvent>
+#include <QClipboard>
+#include <QToolButton>
 #include <QSplitter>
-#include <QDockWidget>
-
-#include "urlnavigator.h"
-#include "viewpropertiesdialog.h"
-#include "viewproperties.h"
-#include "dolphinsettings.h"
-#include "dolphinsettingsdialog.h"
-#include "dolphinstatusbar.h"
-#include "dolphinapplication.h"
-#include "undomanager.h"
-#include "progressindicator.h"
-#include "dolphinsettings.h"
-#include "bookmarkssidebarpage.h"
-#include "infosidebarpage.h"
-#include "generalsettings.h"
-#include "dolphinapplication.h"
 
+namespace {
+    // Used for GeneralSettings::version() to determine whether
+    // an updated version of Dolphin is running.
+    const int CurrentDolphinVersion = 200;
+};
+
+/*
+ * Menu shown when pressing the configure-button in the toolbar.
+ */
+class ToolBarMenu : public KMenu
+{
+public:
+    ToolBarMenu(QWidget* parent);
+    virtual ~ToolBarMenu();
+protected:
+    virtual void showEvent(QShowEvent* event);
+};
+
+/*
+ * Remembers the tab configuration if a tab has been closed.
+ * Each closed tab can be restored by the menu
+ * "Go -> Recently Closed Tabs".
+ */
+struct ClosedTab
+{
+    KUrl primaryUrl;
+    KUrl secondaryUrl;
+    bool isSplit;
+};
+Q_DECLARE_METATYPE(ClosedTab)
 
 DolphinMainWindow::DolphinMainWindow() :
-    KMainWindow(0),
-    m_splitter(0),
-    m_activeView(0)
-{
-    setObjectName("Dolphin");
-    m_view[PrimaryIdx] = 0;
-    m_view[SecondaryIdx] = 0;
-}
+    KXmlGuiWindow(0),
+    m_newFileMenu(0),
+    m_tabBar(0),
+    m_activeViewContainer(0),
+    m_centralWidgetLayout(0),
+    m_tabIndex(0),
+    m_viewTab(),
+    m_actionHandler(0),
+    m_remoteEncoding(0),
+    m_settingsDialog(),
+    m_toolBarSpacer(0),
+    m_openToolBarMenuButton(0),
+    m_updateToolBarTimer(0),
+    m_lastHandleUrlStatJob(0),
+    m_searchDockIsTemporaryVisible(false)
+{
+    DolphinPlacesModel::setModel(new KFilePlacesModel(this));
+    connect(DolphinPlacesModel::instance(), SIGNAL(errorMessage(QString)),
+            this, SLOT(showErrorMessage(QString)));
+
+    // Workaround for a X11-issue in combination with KModifierInfo
+    // (see DolphinContextMenu::initializeModifierKeyInfo() for
+    // more information):
+    DolphinContextMenu::initializeModifierKeyInfo();
+
+    setObjectName("Dolphin#");
+
+    m_viewTab.append(ViewTab());
+    ViewTab& viewTab = m_viewTab[m_tabIndex];
+    viewTab.wasActive = true; // The first opened tab is automatically active
+
+    KIO::FileUndoManager* undoManager = KIO::FileUndoManager::self();
+    undoManager->setUiInterface(new UndoUiInterface());
+
+    connect(undoManager, SIGNAL(undoAvailable(bool)),
+            this, SLOT(slotUndoAvailable(bool)));
+    connect(undoManager, SIGNAL(undoTextChanged(QString)),
+            this, SLOT(slotUndoTextChanged(QString)));
+    connect(undoManager, SIGNAL(jobRecordingStarted(CommandType)),
+            this, SLOT(clearStatusBar()));
+    connect(undoManager, SIGNAL(jobRecordingFinished(CommandType)),
+            this, SLOT(showCommand(CommandType)));
+
+    GeneralSettings* generalSettings = GeneralSettings::self();
+    const bool firstRun = (generalSettings->version() < 200);
+    if (firstRun) {
+        generalSettings->setViewPropsTimestamp(QDateTime::currentDateTime());
+    }
 
-DolphinMainWindow::~DolphinMainWindow()
-{
-    qDeleteAll(m_fileGroupActions);
-    m_fileGroupActions.clear();
+    setAcceptDrops(true);
 
-    DolphinApplication::app()->removeMainWindow(this);
-}
+    viewTab.splitter = new QSplitter(this);
+    viewTab.splitter->setChildrenCollapsible(false);
 
-void DolphinMainWindow::setActiveView(DolphinView* view)
-{
-    assert((view == m_view[PrimaryIdx]) || (view == m_view[SecondaryIdx]));
-    if (m_activeView == view) {
-        return;
-    }
+    setupActions();
+
+    const KUrl homeUrl(generalSettings->homeUrl());
+    setUrlAsCaption(homeUrl);
+    m_actionHandler = new DolphinViewActionHandler(actionCollection(), this);
+    connect(m_actionHandler, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar()));
+    connect(m_actionHandler, SIGNAL(createDirectory()), SLOT(createDirectory()));
+
+    viewTab.primaryView = createViewContainer(homeUrl, viewTab.splitter);
+
+    m_activeViewContainer = viewTab.primaryView;
+    connectViewSignals(m_activeViewContainer);
+    DolphinView* view = m_activeViewContainer->view();
+    m_activeViewContainer->show();
+    m_actionHandler->setCurrentView(view);
+
+    m_remoteEncoding = new DolphinRemoteEncoding(this, m_actionHandler);
+    connect(this, SIGNAL(urlChanged(KUrl)),
+            m_remoteEncoding, SLOT(slotAboutToOpenUrl()));
+
+    m_tabBar = new KTabBar(this);
+    m_tabBar->setMovable(true);
+    m_tabBar->setTabsClosable(true);
+    connect(m_tabBar, SIGNAL(currentChanged(int)),
+            this, SLOT(setActiveTab(int)));
+    connect(m_tabBar, SIGNAL(tabCloseRequested(int)),
+            this, SLOT(closeTab(int)));
+    connect(m_tabBar, SIGNAL(contextMenu(int,QPoint)),
+            this, SLOT(openTabContextMenu(int,QPoint)));
+    connect(m_tabBar, SIGNAL(newTabRequest()),
+            this, SLOT(openNewTab()));
+    connect(m_tabBar, SIGNAL(testCanDecode(const QDragMoveEvent*,bool&)),
+            this, SLOT(slotTestCanDecode(const QDragMoveEvent*,bool&)));
+    connect(m_tabBar, SIGNAL(mouseMiddleClick(int)),
+            this, SLOT(closeTab(int)));
+    connect(m_tabBar, SIGNAL(tabMoved(int,int)),
+            this, SLOT(slotTabMoved(int,int)));
+    connect(m_tabBar, SIGNAL(receivedDropEvent(int,QDropEvent*)),
+            this, SLOT(tabDropEvent(int,QDropEvent*)));
+
+    m_tabBar->blockSignals(true);  // signals get unblocked after at least 2 tabs are open
+
+    QWidget* centralWidget = new QWidget(this);
+    m_centralWidgetLayout = new QVBoxLayout(centralWidget);
+    m_centralWidgetLayout->setSpacing(0);
+    m_centralWidgetLayout->setMargin(0);
+    m_centralWidgetLayout->addWidget(m_tabBar);
+    m_centralWidgetLayout->addWidget(viewTab.splitter, 1);
+
+    setCentralWidget(centralWidget);
+    setupDockWidgets();
+    emit urlChanged(homeUrl);
 
-    m_activeView = view;
+    setupGUI(Keys | Save | Create | ToolBar);
+    stateChanged("new_file");
 
-    updateHistory();
+    QClipboard* clipboard = QApplication::clipboard();
+    connect(clipboard, SIGNAL(dataChanged()),
+            this, SLOT(updatePasteAction()));
+
+    if (generalSettings->splitView()) {
+        toggleSplitView();
+    }
     updateEditActions();
     updateViewActions();
     updateGoActions();
 
-    setCaption(m_activeView->url().fileName());
+    QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
+    showFilterBarAction->setChecked(generalSettings->filterBar());
+
+    if (firstRun) {
+        menuBar()->setVisible(false);
+        // Assure a proper default size if Dolphin runs the first time
+        resize(750, 500);
+    }
 
-    emit activeViewChanged();
+    const bool showMenu = !menuBar()->isHidden();
+    QAction* showMenuBarAction = actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar));
+    showMenuBarAction->setChecked(showMenu);  // workaround for bug #171080
+    if (!showMenu) {
+        createToolBarMenuButton();
+    }
 }
 
-void DolphinMainWindow::dropUrls(const KUrl::List& urls,
-                                 const KUrl& destination)
+DolphinMainWindow::~DolphinMainWindow()
 {
-    m_dropDestination = destination;
-    m_droppedUrls = urls;
-
-    /* KDE4-TODO
-    const ButtonState keyboardState = KApplication::keyboardMouseState();
-    const bool shiftPressed = (keyboardState & ShiftButton) > 0;
-    const bool controlPressed = (keyboardState & ControlButton) > 0;
-
-
+}
 
-    if (shiftPressed && controlPressed) {
-        // shortcut for 'Linke Here' is used
-        selectedIndex = 2;
-    }
-    else if (controlPressed) {
-        // shortcut for 'Copy Here' is used
-        selectedIndex = 1;
-    }
-    else if (shiftPressed) {
-        // shortcut for 'Move Here' is used
-        selectedIndex = 0;
+void DolphinMainWindow::openDirectories(const QList<KUrl>& dirs)
+{
+    if (dirs.isEmpty()) {
+        return;
     }
-    else*/ {
-        // no shortcut is used, hence open a popup menu
-        KMenu popup(this);
 
-        QAction* moveAction = popup.addAction(SmallIcon("goto"), i18n("&Move Here"));
-        connect(moveAction, SIGNAL(triggered()), this, SLOT(moveDroppedItems()));
+    if (dirs.count() == 1) {
+        m_activeViewContainer->setUrl(dirs.first());
+        return;
+    }
 
-        QAction* copyAction = popup.addAction(SmallIcon("editcopy"), i18n( "&Copy Here" ));
-        connect(copyAction, SIGNAL(triggered()), this, SLOT(copyDroppedItems()));
+    const int oldOpenTabsCount = m_viewTab.count();
 
-        QAction* linkAction = popup.addAction(i18n("&Link Here"));
-        connect(linkAction, SIGNAL(triggered()), this, SLOT(linkDroppedItems()));
+    const bool hasSplitView = GeneralSettings::splitView();
 
-        QAction* cancelAction = popup.addAction(SmallIcon("stop"), i18n("Cancel"));
-        popup.insertSeparator(cancelAction);
+    // Open each directory inside a new tab. If the "split view" option has been enabled,
+    // always show two directories within one tab.
+    QList<KUrl>::const_iterator it = dirs.begin();
+    while (it != dirs.end()) {
+        openNewTab(*it);
+        ++it;
 
-        popup.exec(QCursor::pos());
+        if (hasSplitView && (it != dirs.end())) {
+            const int tabIndex = m_viewTab.count() - 1;
+            m_viewTab[tabIndex].secondaryView->setUrl(*it);
+            ++it;
+        }
     }
 
-    m_droppedUrls.clear();
+    // Remove the previously opened tabs
+    for (int i = 0; i < oldOpenTabsCount; ++i) {
+        closeTab(0);
+    }
 }
 
-void DolphinMainWindow::refreshViews()
+void DolphinMainWindow::openFiles(const QList<KUrl>& files)
 {
-    const bool split = DolphinSettings::instance().generalSettings()->splitView();
-    const bool isPrimaryViewActive = (m_activeView == m_view[PrimaryIdx]);
-    KUrl url;
-    for (int i = PrimaryIdx; i <= SecondaryIdx; ++i) {
-       if (m_view[i] != 0) {
-            url = m_view[i]->url();
-
-            // delete view instance...
-            m_view[i]->close();
-            m_view[i]->deleteLater();
-            m_view[i] = 0;
-        }
+    if (files.isEmpty()) {
+        return;
+    }
 
-        if (split || (i == PrimaryIdx)) {
-            // ... and recreate it
-            ViewProperties props(url);
-            m_view[i] = new DolphinView(this,
-                                        m_splitter,
-                                        url,
-                                        props.viewMode(),
-                                        props.showHiddenFiles());
-            connectViewSignals(i);
-            m_view[i]->show();
+    // Get all distinct directories from 'files' and open a tab
+    // for each directory. If the "split view" option is enabled, two
+    // directories are shown inside one tab (see openDirectories()).
+    QList<KUrl> dirs;
+    foreach (const KUrl& url, files) {
+        const KUrl dir(url.directory());
+        if (!dirs.contains(dir)) {
+            dirs.append(dir);
         }
     }
 
-    m_activeView = isPrimaryViewActive ? m_view[PrimaryIdx] : m_view[SecondaryIdx];
-    assert(m_activeView != 0);
-
-    updateViewActions();
-    emit activeViewChanged();
+    openDirectories(dirs);
+
+    // Select the files. Although the files can be split between several
+    // tabs, there is no need to split 'files' accordingly, as
+    // the DolphinView will just ignore invalid selections.
+    const int tabCount = m_viewTab.count();
+    for (int i = 0; i < tabCount; ++i) {
+        m_viewTab[i].primaryView->view()->markUrlsAsSelected(files);
+        m_viewTab[i].primaryView->view()->markUrlAsCurrent(files.at(0));
+        if (m_viewTab[i].secondaryView) {
+            m_viewTab[i].secondaryView->view()->markUrlsAsSelected(files);
+            m_viewTab[i].secondaryView->view()->markUrlAsCurrent(files.at(0));
+        }
+    }
 }
 
-void DolphinMainWindow::slotViewModeChanged()
+void DolphinMainWindow::showCommand(CommandType command)
 {
-    updateViewActions();
+    DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
+    switch (command) {
+    case KIO::FileUndoManager::Copy:
+        statusBar->setMessage(i18nc("@info:status", "Successfully copied."),
+                              DolphinStatusBar::OperationCompleted);
+        break;
+    case KIO::FileUndoManager::Move:
+        statusBar->setMessage(i18nc("@info:status", "Successfully moved."),
+                              DolphinStatusBar::OperationCompleted);
+        break;
+    case KIO::FileUndoManager::Link:
+        statusBar->setMessage(i18nc("@info:status", "Successfully linked."),
+                              DolphinStatusBar::OperationCompleted);
+        break;
+    case KIO::FileUndoManager::Trash:
+        statusBar->setMessage(i18nc("@info:status", "Successfully moved to trash."),
+                              DolphinStatusBar::OperationCompleted);
+        break;
+    case KIO::FileUndoManager::Rename:
+        statusBar->setMessage(i18nc("@info:status", "Successfully renamed."),
+                              DolphinStatusBar::OperationCompleted);
+        break;
+
+    case KIO::FileUndoManager::Mkdir:
+        statusBar->setMessage(i18nc("@info:status", "Created folder."),
+                              DolphinStatusBar::OperationCompleted);
+        break;
+
+    default:
+        break;
+    }
 }
 
-void DolphinMainWindow::slotShowHiddenFilesChanged()
+void DolphinMainWindow::pasteIntoFolder()
 {
-    KToggleAction* showHiddenFilesAction =
-        static_cast<KToggleAction*>(actionCollection()->action("show_hidden_files"));
-    showHiddenFilesAction->setChecked(m_activeView->showHiddenFiles());
+    m_activeViewContainer->view()->pasteIntoFolder();
 }
 
-void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting)
+void DolphinMainWindow::changeUrl(const KUrl& url)
 {
-    QAction* action = 0;
-    switch (sorting) {
-        case DolphinView::SortByName:
-            action = actionCollection()->action("by_name");
-            break;
-        case DolphinView::SortBySize:
-            action = actionCollection()->action("by_size");
-            break;
-        case DolphinView::SortByDate:
-            action = actionCollection()->action("by_date");
-            break;
-        default:
-            break;
+    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;
     }
 
-    if (action != 0) {
-        KToggleAction* toggleAction = static_cast<KToggleAction*>(action);
-        toggleAction->setChecked(true);
+    DolphinViewContainer* view = activeViewContainer();
+    if (view) {
+        view->setUrl(url);
+        updateEditActions();
+        updateViewActions();
+        updateGoActions();
+        setUrlAsCaption(url);
+        if (m_viewTab.count() > 1) {
+            m_tabBar->setTabText(m_tabIndex, squeezedText(tabName(m_activeViewContainer->url())));
+        }
+        const QString iconName = KMimeType::iconNameForUrl(url);
+        m_tabBar->setTabIcon(m_tabIndex, KIcon(iconName));
+        emit urlChanged(url);
     }
 }
 
-void DolphinMainWindow::slotSortOrderChanged(Qt::SortOrder order)
+void DolphinMainWindow::slotEditableStateChanged(bool editable)
 {
-    KToggleAction* descending = static_cast<KToggleAction*>(actionCollection()->action("descending"));
-    const bool sortDescending = (order == Qt::Descending);
-    descending->setChecked(sortDescending);
+    KToggleAction* editableLocationAction =
+        static_cast<KToggleAction*>(actionCollection()->action("editable_location"));
+    editableLocationAction->setChecked(editable);
 }
 
-void DolphinMainWindow::slotSelectionChanged()
+void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection)
 {
     updateEditActions();
 
-    assert(m_view[PrimaryIdx] != 0);
-    int selectedUrlsCount = m_view[PrimaryIdx]->selectedUrls().count();
-    if (m_view[SecondaryIdx] != 0) {
-        selectedUrlsCount += m_view[SecondaryIdx]->selectedUrls().count();
+    Q_ASSERT(m_viewTab[m_tabIndex].primaryView);
+    int selectedUrlsCount = m_viewTab[m_tabIndex].primaryView->view()->selectedItemsCount();
+    if (m_viewTab[m_tabIndex].secondaryView) {
+        selectedUrlsCount += m_viewTab[m_tabIndex].secondaryView->view()->selectedItemsCount();
     }
 
     QAction* compareFilesAction = actionCollection()->action("compare_files");
-    compareFilesAction->setEnabled(selectedUrlsCount == 2);
-
-    m_activeView->updateStatusBar();
+    if (selectedUrlsCount == 2) {
+        compareFilesAction->setEnabled(isKompareInstalled());
+    } else {
+        compareFilesAction->setEnabled(false);
+    }
 
-    emit selectionChanged();
+    emit selectionChanged(selection);
 }
 
-void DolphinMainWindow::slotHistoryChanged()
+void DolphinMainWindow::slotRequestItemInfo(const KFileItem& item)
 {
-    updateHistory();
+    emit requestItemInfo(item);
 }
 
-void DolphinMainWindow::slotUrlChanged(const KUrl& url)
+void DolphinMainWindow::updateHistory()
 {
-    updateEditActions();
-    updateGoActions();
-    setCaption(url.fileName());
+    const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
+    const int index = urlNavigator->historyIndex();
+
+    QAction* backAction = actionCollection()->action("go_back");
+    if (backAction) {
+        backAction->setToolTip(i18nc("@info", "Go back"));
+        backAction->setEnabled(index < urlNavigator->historySize() - 1);
+    }
+
+    QAction* forwardAction = actionCollection()->action("go_forward");
+    if (forwardAction) {
+        forwardAction->setToolTip(i18nc("@info", "Go forward"));
+        forwardAction->setEnabled(index > 0);
+    }
 }
 
 void DolphinMainWindow::updateFilterBarAction(bool show)
 {
-    KToggleAction* showFilterBarAction =
-        static_cast<KToggleAction*>(actionCollection()->action("show_filter_bar"));
+    QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
     showFilterBarAction->setChecked(show);
 }
 
-void DolphinMainWindow::redo()
+void DolphinMainWindow::openNewMainWindow()
 {
-    UndoManager::instance().redo(this);
+    KRun::run("dolphin", KUrl::List(), this);
 }
 
-void DolphinMainWindow::undo()
+void DolphinMainWindow::openNewTab()
 {
-    UndoManager::instance().undo(this);
-}
+    const bool isUrlEditable =  m_activeViewContainer->urlNavigator()->isUrlEditable();
 
-void DolphinMainWindow::openNewMainWindow()
-{
-    DolphinApplication::app()->createMainWindow()->show();
-}
+    openNewTab(m_activeViewContainer->url());
+    m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
 
-void DolphinMainWindow::moveDroppedItems()
-{
-    moveUrls(m_droppedUrls, m_dropDestination);
-}
+    // The URL navigator of the new tab should have the same editable state
+    // as the current tab
+    KUrlNavigator* navigator = m_activeViewContainer->urlNavigator();
+    navigator->setUrlEditable(isUrlEditable);
 
-void DolphinMainWindow::copyDroppedItems()
-{
-    copyUrls(m_droppedUrls, m_dropDestination);
+    if (isUrlEditable) {
+        // If a new tab is opened and the URL is editable, assure that
+        // the user can edit the URL without manually setting the focus
+        navigator->setFocus();
+    }
 }
 
-void DolphinMainWindow::linkDroppedItems()
+void DolphinMainWindow::openNewTab(const KUrl& url)
 {
-    KIO::Job* job = KIO::link(m_droppedUrls, m_dropDestination);
-    addPendingUndoJob(job, DolphinCommand::Link, m_droppedUrls, m_dropDestination);
-}
+    QWidget* focusWidget = QApplication::focusWidget();
 
-void DolphinMainWindow::closeEvent(QCloseEvent* event)
-{
-    // KDE4-TODO
-    //KConfig* config = KGlobal::config();
-    //config->setGroup("General");
-    //config->writeEntry("First Run", false);
+    if (m_viewTab.count() == 1) {
+        // Only one view is open currently and hence no tab is shown at
+        // all. Before creating a tab for 'url', provide a tab for the current URL.
+        const KUrl currentUrl = m_activeViewContainer->url();
+        m_tabBar->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl)),
+                         squeezedText(tabName(currentUrl)));
+        m_tabBar->blockSignals(false);
+    }
+
+    m_tabBar->addTab(KIcon(KMimeType::iconNameForUrl(url)),
+                     squeezedText(tabName(url)));
 
-    DolphinSettings& settings = DolphinSettings::instance();
-    GeneralSettings* generalSettings = settings.generalSettings();
-    generalSettings->setFirstRun(false);
+    ViewTab viewTab;
+    viewTab.splitter = new QSplitter(this);
+    viewTab.splitter->setChildrenCollapsible(false);
+    viewTab.primaryView = createViewContainer(url, viewTab.splitter);
+    viewTab.primaryView->setActive(false);
+    connectViewSignals(viewTab.primaryView);
 
-    settings.save();
+    m_viewTab.append(viewTab);
 
-    KMainWindow::closeEvent(event);
+    actionCollection()->action("close_tab")->setEnabled(true);
+
+    // provide a split view, if the startup settings are set this way
+    if (GeneralSettings::splitView()) {
+        const int newTabIndex = m_viewTab.count() - 1;
+        createSecondaryView(newTabIndex);
+        viewTab.secondaryView->setActive(true);
+        viewTab.isPrimaryViewActive = false;
+    }
+
+    if (focusWidget) {
+        // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
+        // in background, assure that the previous focused widget gets the focus back.
+        focusWidget->setFocus();
+    }
 }
 
-void DolphinMainWindow::saveProperties(KConfig* config)
+void DolphinMainWindow::activateNextTab()
 {
-    config->setGroup("Primary view");
-    config->writeEntry("Url", m_view[PrimaryIdx]->url().url());
-    config->writeEntry("Editable Url", m_view[PrimaryIdx]->isUrlEditable());
-    if (m_view[SecondaryIdx] != 0) {
-        config->setGroup("Secondary view");
-        config->writeEntry("Url", m_view[SecondaryIdx]->url().url());
-        config->writeEntry("Editable Url", m_view[SecondaryIdx]->isUrlEditable());
+    if (m_viewTab.count() >= 2) {
+        const int tabIndex = (m_tabBar->currentIndex() + 1) % m_tabBar->count();
+        m_tabBar->setCurrentIndex(tabIndex);
     }
 }
 
-void DolphinMainWindow::readProperties(KConfig* config)
+void DolphinMainWindow::activatePrevTab()
 {
-    config->setGroup("Primary view");
-    m_view[PrimaryIdx]->setUrl(config->readEntry("Url"));
-    m_view[PrimaryIdx]->setUrlEditable(config->readEntry("Editable Url", false));
-    if (config->hasGroup("Secondary view")) {
-        config->setGroup("Secondary view");
-        if (m_view[SecondaryIdx] == 0) {
-            toggleSplitView();
+    if (m_viewTab.count() >= 2) {
+        int tabIndex = m_tabBar->currentIndex() - 1;
+        if (tabIndex == -1) {
+            tabIndex = m_tabBar->count() - 1;
         }
-        m_view[SecondaryIdx]->setUrl(config->readEntry("Url"));
-        m_view[SecondaryIdx]->setUrlEditable(config->readEntry("Editable Url", false));
-    }
-    else if (m_view[SecondaryIdx] != 0) {
-        toggleSplitView();
+        m_tabBar->setCurrentIndex(tabIndex);
     }
 }
 
-void DolphinMainWindow::createFolder()
+void DolphinMainWindow::openInNewTab()
 {
-    // Parts of the following code have been taken
-    // from the class KonqPopupMenu located in
-    // libqonq/konq_popupmenu.h of Konqueror.
-    // (Copyright (C) 2000  David Faure <faure@kde.org>,
-    // Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>)
-
-    clearStatusBar();
-
-    DolphinStatusBar* statusBar = m_activeView->statusBar();
-    const KUrl baseUrl(m_activeView->url());
-
-    QString name(i18n("New Folder"));
-    baseUrl.path(KUrl::AddTrailingSlash);
-
-
-    if (baseUrl.isLocalFile() && QFileInfo(baseUrl.path(KUrl::AddTrailingSlash) + name).exists()) {
-        name = KIO::RenameDialog::suggestName(baseUrl, i18n("New Folder"));
+    const KFileItemList list = m_activeViewContainer->view()->selectedItems();
+    if (list.isEmpty()) {
+        openNewTab(m_activeViewContainer->url());
+    } else if ((list.count() == 1) && list[0].isDir()) {
+        openNewTab(list[0].url());
     }
+}
 
-    bool ok = false;
-    name = KInputDialog::getText(i18n("New Folder"),
-                                 i18n("Enter folder name:" ),
-                                 name,
-                                 &ok,
-                                 this);
+void DolphinMainWindow::openInNewWindow()
+{
+    KUrl newWindowUrl;
 
-    if (!ok) {
-        // the user has pressed 'Cancel'
-        return;
+    const KFileItemList list = m_activeViewContainer->view()->selectedItems();
+    if (list.isEmpty()) {
+        newWindowUrl = m_activeViewContainer->url();
+    } else if ((list.count() == 1) && list[0].isDir()) {
+        newWindowUrl = list[0].url();
     }
 
-    assert(!name.isEmpty());
-
-    KUrl url;
-    if ((name[0] == '/') || (name[0] == '~')) {
-        url.setPath(KShell::tildeExpand(name));
+    if (!newWindowUrl.isEmpty()) {
+        KRun::run("dolphin", KUrl::List() << newWindowUrl, this);
     }
-    else {
-        name = KIO::encodeFileName(name);
-        url = baseUrl;
-        url.addPath(name);
+}
+
+void DolphinMainWindow::toggleActiveView()
+{
+    if (!m_viewTab[m_tabIndex].secondaryView) {
+        // only one view is available
+        return;
     }
-    ok = KIO::NetAccess::mkdir(url, this);
 
-    // TODO: provide message type hint
-    if (ok) {
-        statusBar->setMessage(i18n("Created folder %1.",url.path()),
-                              DolphinStatusBar::OperationCompleted);
+    Q_ASSERT(m_activeViewContainer);
+    Q_ASSERT(m_viewTab[m_tabIndex].primaryView);
 
-        DolphinCommand command(DolphinCommand::CreateFolder, KUrl::List(), url);
-        UndoManager::instance().addCommand(command);
-    }
-    else {
-        // Creating of the folder has been failed. Check whether the creating
-        // has been failed because a folder with the same name exists...
-        if (KIO::NetAccess::exists(url, true, this)) {
-            statusBar->setMessage(i18n("A folder named %1 already exists.",url.path()),
-                                  DolphinStatusBar::Error);
-        }
-        else {
-            statusBar->setMessage(i18n("Creating of folder %1 failed.",url.path()),
-                                  DolphinStatusBar::Error);
-        }
+    DolphinViewContainer* left  = m_viewTab[m_tabIndex].primaryView;
+    DolphinViewContainer* right = m_viewTab[m_tabIndex].secondaryView;
+    setActiveViewContainer(m_activeViewContainer == right ? left : right);
+}
 
+void DolphinMainWindow::showEvent(QShowEvent* event)
+{
+    KXmlGuiWindow::showEvent(event);
+    if (!event->spontaneous()) {
+        m_activeViewContainer->view()->setFocus();
     }
 }
 
-void DolphinMainWindow::createFile()
+void DolphinMainWindow::closeEvent(QCloseEvent* event)
 {
-    // Parts of the following code have been taken
-    // from the class KonqPopupMenu located in
-    // libqonq/konq_popupmenu.h of Konqueror.
-    // (Copyright (C) 2000  David Faure <faure@kde.org>,
-    // Copyright (C) 2001 Holger Freyther <freyther@yahoo.com>)
-
-    clearStatusBar();
+    // Find out if Dolphin is closed directly by the user or
+    // by the session manager because the session is closed
+    bool closedByUser = true;
+    DolphinApplication *application = qobject_cast<DolphinApplication*>(qApp);
+    if (application && application->sessionSaving()) {
+        closedByUser = false;
+    }
 
-    // TODO: const Entry& entry = m_createFileTemplates[QString(sender->name())];
-    // should be enough. Anyway: the implemantation of [] does a linear search internally too.
-    KSortableList<CreateFileEntry, QString>::ConstIterator it = m_createFileTemplates.begin();
-    KSortableList<CreateFileEntry, QString>::ConstIterator end = m_createFileTemplates.end();
-
-    const QString senderName(sender()->objectName());
-    bool found = false;
-    CreateFileEntry entry;
-    while (!found && (it != end)) {
-        if ((*it).key() == senderName) {
-            entry = (*it).value();
-            found = true;
+    if (m_viewTab.count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && closedByUser) {
+        // Ask the user if he really wants to quit and close all tabs.
+        // Open a confirmation dialog with 3 buttons:
+        // KDialog::Yes    -> Quit
+        // KDialog::No     -> Close only the current tab
+        // KDialog::Cancel -> do nothing
+        KDialog *dialog = new KDialog(this, Qt::Dialog);
+        dialog->setCaption(i18nc("@title:window", "Confirmation"));
+        dialog->setButtons(KDialog::Yes | KDialog::No | KDialog::Cancel);
+        dialog->setModal(true);
+        dialog->setButtonGuiItem(KDialog::Yes, KStandardGuiItem::quit());
+        dialog->setButtonGuiItem(KDialog::No, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close")));
+        dialog->setButtonGuiItem(KDialog::Cancel, KStandardGuiItem::cancel());
+        dialog->setDefaultButton(KDialog::Yes);
+
+        bool doNotAskAgainCheckboxResult = false;
+
+        const int result = KMessageBox::createKMessageBox(dialog,
+            QMessageBox::Warning,
+            i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
+            QStringList(),
+            i18n("Do not ask again"),
+            &doNotAskAgainCheckboxResult,
+            KMessageBox::Notify);
+
+        if (doNotAskAgainCheckboxResult) {
+            GeneralSettings::setConfirmClosingMultipleTabs(false);
         }
-        else {
-            ++it;
+
+        switch (result) {
+            case KDialog::Yes:
+                // Quit
+                break;
+            case KDialog::No:
+                // Close only the current tab
+              closeTab();
+            default:
+                event->ignore();
+                return;
         }
     }
 
-    DolphinStatusBar* statusBar = m_activeView->statusBar();
-    if (!found || !QFile::exists(entry.templatePath)) {
-        statusBar->setMessage(i18n("Could not create file."), DolphinStatusBar::Error);
-       return;
-    }
-
-    // Get the source path of the template which should be copied.
-    // The source path is part of the Url entry of the desktop file.
-    const int pos = entry.templatePath.lastIndexOf('/');
-    QString sourcePath(entry.templatePath.left(pos + 1));
-    sourcePath += KDesktopFile(entry.templatePath, true).readPathEntry("Url");
-
-    QString name(i18n(entry.name.toAscii()));
-    // Most entry names end with "..." (e. g. "HTML File..."), which is ok for
-    // menus but no good choice for a new file name -> remove the dots...
-    name.replace("...", QString::null);
-
-    // add the file extension to the name
-    name.append(sourcePath.right(sourcePath.length() - sourcePath.lastIndexOf('.')));
-
-    // Check whether a file with the current name already exists. If yes suggest automatically
-    // a unique file name (e. g. "HTML File" will be replaced by "HTML File_1").
-    const KUrl viewUrl(m_activeView->url());
-    const bool fileExists = viewUrl.isLocalFile() &&
-                            QFileInfo(viewUrl.path(KUrl::AddTrailingSlash) + KIO::encodeFileName(name)).exists();
-    if (fileExists) {
-        name = KIO::RenameDialog::suggestName(viewUrl, name);
-    }
-
-    // let the user change the suggested file name
-    bool ok = false;
-    name = KInputDialog::getText(entry.name,
-                                 entry.comment,
-                                 name,
-                                 &ok,
-                                 this);
-    if (!ok) {
-        // the user has pressed 'Cancel'
-        return;
-    }
+    GeneralSettings::setVersion(CurrentDolphinVersion);
+    GeneralSettings::self()->writeConfig();
 
-    // before copying the template to the destination path check whether a file
-    // with the given name already exists
-    const QString destPath(viewUrl.pathOrUrl() + "/" + KIO::encodeFileName(name));
-    const KUrl destUrl(destPath);
-    if (KIO::NetAccess::exists(destUrl, false, this)) {
-        statusBar->setMessage(i18n("A file named %1 already exists.",name),
-                              DolphinStatusBar::Error);
-        return;
+    if (m_searchDockIsTemporaryVisible) {
+        QDockWidget* searchDock = findChild<QDockWidget*>("searchDock");
+        if (searchDock) {
+            searchDock->hide();
+        }
+        m_searchDockIsTemporaryVisible = false;
     }
 
-    // copy the template to the destination path
-    const KUrl sourceUrl(sourcePath);
-    KIO::CopyJob* job = KIO::copyAs(sourceUrl, destUrl);
-    job->setDefaultPermissions(true);
-    if (KIO::NetAccess::synchronousRun(job, this)) {
-        statusBar->setMessage(i18n("Created file %1.",name),
-                              DolphinStatusBar::OperationCompleted);
+    KXmlGuiWindow::closeEvent(event);
+}
+
+void DolphinMainWindow::saveProperties(KConfigGroup& group)
+{
+    const int tabCount = m_viewTab.count();
+    group.writeEntry("Tab Count", tabCount);
+    group.writeEntry("Active Tab Index", m_tabBar->currentIndex());
 
-        KUrl::List list;
-        list.append(sourceUrl);
-        DolphinCommand command(DolphinCommand::CreateFile, list, destUrl);
-        UndoManager::instance().addCommand(command);
+    for (int i = 0; i < tabCount; ++i) {
+        const DolphinViewContainer* cont = m_viewTab[i].primaryView;
+        group.writeEntry(tabProperty("Primary URL", i), cont->url().url());
+        group.writeEntry(tabProperty("Primary Editable", i),
+                         cont->urlNavigator()->isUrlEditable());
 
-    }
-    else {
-        statusBar->setMessage(i18n("Creating of file %1 failed.",name),
-                              DolphinStatusBar::Error);
+        cont = m_viewTab[i].secondaryView;
+        if (cont) {
+            group.writeEntry(tabProperty("Secondary URL", i), cont->url().url());
+            group.writeEntry(tabProperty("Secondary Editable", i),
+                             cont->urlNavigator()->isUrlEditable());
+        }
     }
 }
 
-void DolphinMainWindow::rename()
+void DolphinMainWindow::readProperties(const KConfigGroup& group)
 {
-    clearStatusBar();
-    m_activeView->renameSelectedItems();
-}
+    const int tabCount = group.readEntry("Tab Count", 1);
+    for (int i = 0; i < tabCount; ++i) {
+        DolphinViewContainer* cont = m_viewTab[i].primaryView;
 
-void DolphinMainWindow::moveToTrash()
-{
-    clearStatusBar();
-    KUrl::List selectedUrls = m_activeView->selectedUrls();
-    KIO::Job* job = KIO::trash(selectedUrls);
-    addPendingUndoJob(job, DolphinCommand::Trash, selectedUrls, m_activeView->url());
-}
+        cont->setUrl(group.readEntry(tabProperty("Primary URL", i)));
+        const bool editable = group.readEntry(tabProperty("Primary Editable", i), false);
+        cont->urlNavigator()->setUrlEditable(editable);
 
-void DolphinMainWindow::deleteItems()
-{
-    clearStatusBar();
+        cont = m_viewTab[i].secondaryView;
+        const QString secondaryUrl = group.readEntry(tabProperty("Secondary URL", i));
+        if (!secondaryUrl.isEmpty()) {
+            if (!cont) {
+                // a secondary view should be shown, but no one is available
+                // currently -> create a new view
+                toggleSplitView();
+                cont = m_viewTab[i].secondaryView;
+                Q_ASSERT(cont);
+            }
 
-    KUrl::List list = m_activeView->selectedUrls();
-    const uint itemCount = list.count();
-    assert(itemCount >= 1);
+            cont->setUrl(secondaryUrl);
+            const bool editable = group.readEntry(tabProperty("Secondary Editable", i), false);
+            cont->urlNavigator()->setUrlEditable(editable);
+        } else if (cont) {
+            // no secondary view should be shown, but the default setting shows
+            // one already -> close the view
+            toggleSplitView();
+        }
 
-    QString text;
-    if (itemCount > 1) {
-        text = i18n("Do you really want to delete the %1 selected items?",itemCount);
-    }
-    else {
-        const KUrl& url = list.first();
-        text = i18n("Do you really want to delete '%1'?",url.fileName());
+        // openNewTab() needs to be called only tabCount - 1 times
+        if (i != tabCount - 1) {
+             openNewTab();
+        }
     }
 
-    const bool del = KMessageBox::warningContinueCancel(this,
-                                                        text,
-                                                        QString::null,
-                                                        KGuiItem(i18n("Delete"), KIcon("editdelete"))
-                                                       ) == KMessageBox::Continue;
-    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*)));
-    }
+    const int index = group.readEntry("Active Tab Index", 0);
+    m_tabBar->setCurrentIndex(index);
 }
 
-void DolphinMainWindow::properties()
+void DolphinMainWindow::updateNewMenu()
 {
-    const KFileItemList list = m_activeView->selectedItems();
-    new KPropertiesDialog(list, this);
+    m_newFileMenu->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
+    m_newFileMenu->checkUpToDate();
+    m_newFileMenu->setPopupFiles(activeViewContainer()->url());
 }
 
-void DolphinMainWindow::quit()
+void DolphinMainWindow::createDirectory()
 {
-    close();
+    m_newFileMenu->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
+    m_newFileMenu->setPopupFiles(activeViewContainer()->url());
+    m_newFileMenu->createDirectory();
 }
 
-void DolphinMainWindow::slotHandleJobError(KJob* job)
+void DolphinMainWindow::quit()
 {
-    if (job->error() != 0) {
-        m_activeView->statusBar()->setMessage(job->errorString(),
-                                              DolphinStatusBar::Error);
-    }
+    close();
 }
 
-void DolphinMainWindow::slotDeleteFileFinished(KJob* job)
+void DolphinMainWindow::showErrorMessage(const QString& message)
 {
-    if (job->error() == 0) {
-        m_activeView->statusBar()->setMessage(i18n("Delete operation completed."),
-                                               DolphinStatusBar::OperationCompleted);
-
-        // TODO: In opposite to the 'Move to Trash' operation in the class KFileIconView
-        // no rearranging of the item position is done when a file has been deleted.
-        // This is bypassed by reloading the view, but it might be worth to investigate
-        // deeper for the root of this issue.
-        m_activeView->reload();
+    if (!message.isEmpty()) {
+        DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
+        statusBar->setMessage(message, DolphinStatusBar::Error);
     }
 }
 
 void DolphinMainWindow::slotUndoAvailable(bool available)
 {
-    QAction* undoAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Undo));
-    if (undoAction != 0) {
+    QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
+    if (undoAction) {
         undoAction->setEnabled(available);
     }
 }
 
-void DolphinMainWindow::slotUndoTextChanged(const QString& text)
+void DolphinMainWindow::restoreClosedTab(QAction* action)
 {
-    QAction* undoAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Undo));
-    if (undoAction != 0) {
-        undoAction->setText(text);
+    if (action->data().toBool()) {
+        // clear all actions except the "Empty Recently Closed Tabs"
+        // action and the separator
+        QList<QAction*> actions = m_recentTabsMenu->menu()->actions();
+        const int count = actions.size();
+        for (int i = 2; i < count; ++i) {
+            m_recentTabsMenu->menu()->removeAction(actions.at(i));
+        }
+    } else {
+        const ClosedTab closedTab = action->data().value<ClosedTab>();
+        openNewTab(closedTab.primaryUrl);
+        m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
+
+        if (closedTab.isSplit) {
+            // create secondary view
+            toggleSplitView();
+            m_viewTab[m_tabIndex].secondaryView->setUrl(closedTab.secondaryUrl);
+        }
+
+        m_recentTabsMenu->removeAction(action);
+    }
+
+    if (m_recentTabsMenu->menu()->actions().count() == 2) {
+        m_recentTabsMenu->setEnabled(false);
     }
 }
 
-void DolphinMainWindow::slotRedoAvailable(bool available)
+void DolphinMainWindow::slotUndoTextChanged(const QString& text)
 {
-    QAction* redoAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Redo));
-    if (redoAction != 0) {
-        redoAction->setEnabled(available);
+    QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
+    if (undoAction) {
+        undoAction->setText(text);
     }
 }
 
-void DolphinMainWindow::slotRedoTextChanged(const QString& text)
+void DolphinMainWindow::undo()
 {
-    QAction* redoAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Redo));
-    if (redoAction != 0) {
-        redoAction->setText(text);
-    }
+    clearStatusBar();
+    KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
+    KIO::FileUndoManager::self()->undo();
 }
 
 void DolphinMainWindow::cut()
 {
-    QMimeData* mimeData = new QMimeData();
-    const KUrl::List kdeUrls = m_activeView->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_activeView->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_activeView->url());
-
-    // check whether the pasting should be done into a selected directory
-    KUrl::List selectedUrls = m_activeView->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();
-        }
-    }
+    m_activeViewContainer->view()->paste();
+}
 
-    if (KonqMimeData::decodeIsCutSelection(mimeData)) {
-        moveUrls(sourceUrls, destUrl);
-        clipboard->clear();
-    }
-    else {
-        copyUrls(sourceUrls, destUrl);
-    }
+void DolphinMainWindow::find()
+{
+    m_activeViewContainer->setSearchModeEnabled(true);
 }
 
-void DolphinMainWindow::updatePasteAction()
+void DolphinMainWindow::slotSearchLocationChanged()
 {
-    QAction* pasteAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Paste));
-    if (pasteAction == 0) {
+#ifdef HAVE_NEPOMUK
+    QDockWidget* searchDock = findChild<QDockWidget*>("searchDock");
+    if (!searchDock) {
         return;
     }
 
-    QString text(i18n("Paste"));
-    QClipboard* clipboard = QApplication::clipboard();
-    const QMimeData* mimeData = clipboard->mimeData();
-
-    KUrl::List urls = KUrl::List::fromMimeData(mimeData);
-    if (!urls.isEmpty()) {
-        pasteAction->setEnabled(true);
-
-        const int count = urls.count();
-        if (count == 1) {
-            pasteAction->setText(i18n("Paste 1 File"));
-        }
-        else {
-            pasteAction->setText(i18n("Paste %1 Files").arg(count));
-        }
-    }
-    else {
-        pasteAction->setEnabled(false);
-        pasteAction->setText(i18n("Paste"));
-    }
-
-    if (pasteAction->isEnabled()) {
-        KUrl::List urls = m_activeView->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_activeView->selectedFileItems() to get the real KFileItems
-            const KFileItem fileItem(S_IFDIR,
-                                     KFileItem::Unknown,
-                                     urls.first(),
-                                     true);
-            pasteAction->setEnabled(fileItem.isDir());
-        }
+    SearchPanel* searchPanel = qobject_cast<SearchPanel*>(searchDock->widget());
+    if (searchPanel) {
+        searchPanel->setSearchLocation(SearchSettings::location() == QLatin1String("FromHere")
+                                       ? SearchPanel::FromCurrentDir
+                                       : SearchPanel::Everywhere);
     }
+#endif
 }
 
-void DolphinMainWindow::selectAll()
+void DolphinMainWindow::updatePasteAction()
 {
-    clearStatusBar();
-    m_activeView->selectAll();
+    QAction* pasteAction = actionCollection()->action(KStandardAction::name(KStandardAction::Paste));
+    QPair<bool, QString> pasteInfo = m_activeViewContainer->view()->pasteInfo();
+    pasteAction->setEnabled(pasteInfo.first);
+    pasteAction->setText(pasteInfo.second);
 }
 
-void DolphinMainWindow::invertSelection()
+void DolphinMainWindow::selectAll()
 {
     clearStatusBar();
-    m_activeView->invertSelection();
-}
-void DolphinMainWindow::setIconsView()
-{
-    m_activeView->setMode(DolphinView::IconsView);
-}
-
-void DolphinMainWindow::setDetailsView()
-{
-    m_activeView->setMode(DolphinView::DetailsView);
-}
-
-void DolphinMainWindow::sortByName()
-{
-    m_activeView->setSorting(DolphinView::SortByName);
-}
 
-void DolphinMainWindow::sortBySize()
-{
-    m_activeView->setSorting(DolphinView::SortBySize);
-}
-
-void DolphinMainWindow::sortByDate()
-{
-    m_activeView->setSorting(DolphinView::SortByDate);
+    // if the URL navigator is editable and focused, select the whole
+    // URL instead of all items of the view
+
+    KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
+    QLineEdit* lineEdit = urlNavigator->editor()->lineEdit(); // krazy:exclude=qclasses
+    const bool selectUrl = urlNavigator->isUrlEditable() &&
+                           lineEdit->hasFocus();
+    if (selectUrl) {
+        lineEdit->selectAll();
+    } else {
+        m_activeViewContainer->view()->selectAll();
+    }
 }
 
-void DolphinMainWindow::toggleSortOrder()
+void DolphinMainWindow::invertSelection()
 {
-    const Qt::SortOrder order = (m_activeView->sortOrder() == Qt::Ascending) ?
-                                Qt::Descending :
-                                Qt::Ascending;
-    m_activeView->setSortOrder(order);
+    clearStatusBar();
+    m_activeViewContainer->view()->invertSelection();
 }
 
 void DolphinMainWindow::toggleSplitView()
 {
-    if (m_view[SecondaryIdx] == 0) {
-        const int newWidth = (m_view[PrimaryIdx]->width() - m_splitter->handleWidth()) / 2;
-        // create a secondary view
-        m_view[SecondaryIdx] = new DolphinView(this,
-                                               0,
-                                               m_view[PrimaryIdx]->url(),
-                                               m_view[PrimaryIdx]->mode(),
-                                               m_view[PrimaryIdx]->showHiddenFiles());
-        connectViewSignals(SecondaryIdx);
-        m_splitter->addWidget(m_view[SecondaryIdx]);
-        m_splitter->setSizes(QList<int>() << newWidth << newWidth);
-        m_view[SecondaryIdx]->show();
-    }
-    else {
+    if (!m_viewTab[m_tabIndex].secondaryView) {
+        createSecondaryView(m_tabIndex);
+        setActiveViewContainer(m_viewTab[m_tabIndex].secondaryView);
+    } else if (m_activeViewContainer == m_viewTab[m_tabIndex].secondaryView) {
         // remove secondary view
-        if (m_activeView == m_view[PrimaryIdx]) {
-            m_view[SecondaryIdx]->close();
-            m_view[SecondaryIdx]->deleteLater();
-            m_view[SecondaryIdx] = 0;
-            setActiveView(m_view[PrimaryIdx]);
-        }
-        else {
-            // The secondary view is active, hence from the users point of view
-            // the content of the secondary view should be moved to the primary view.
-            // From an implementation point of view it is more efficient to close
-            // the primary view and exchange the internal pointers afterwards.
-            m_view[PrimaryIdx]->close();
-            delete m_view[PrimaryIdx];
-            m_view[PrimaryIdx] = m_view[SecondaryIdx];
-            m_view[SecondaryIdx] = 0;
-            setActiveView(m_view[PrimaryIdx]);
-        }
+        m_viewTab[m_tabIndex].secondaryView->close();
+        m_viewTab[m_tabIndex].secondaryView->deleteLater();
+        m_viewTab[m_tabIndex].secondaryView = 0;
+
+        setActiveViewContainer(m_viewTab[m_tabIndex].primaryView);
+    } else {
+        // The primary view is active and should be closed. Hence from a users point of view
+        // the content of the secondary view should be moved to the primary view.
+        // From an implementation point of view it is more efficient to close
+        // the primary view and exchange the internal pointers afterwards.
+
+        m_viewTab[m_tabIndex].primaryView->close();
+        m_viewTab[m_tabIndex].primaryView->deleteLater();
+        m_viewTab[m_tabIndex].primaryView = m_viewTab[m_tabIndex].secondaryView;
+        m_viewTab[m_tabIndex].secondaryView = 0;
+
+        setActiveViewContainer(m_viewTab[m_tabIndex].primaryView);
     }
+
+    updateViewActions();
 }
 
 void DolphinMainWindow::reloadView()
 {
     clearStatusBar();
-    m_activeView->reload();
+    m_activeViewContainer->view()->reload();
 }
 
 void DolphinMainWindow::stopLoading()
 {
+    m_activeViewContainer->view()->stopLoading();
 }
 
-void DolphinMainWindow::togglePreview()
+void DolphinMainWindow::enableStopAction()
 {
-    clearStatusBar();
-
-    const KToggleAction* showPreviewAction =
-        static_cast<KToggleAction*>(actionCollection()->action("show_preview"));
-    const bool show = showPreviewAction->isChecked();
-    m_activeView->setShowPreview(show);
+    actionCollection()->action("stop")->setEnabled(true);
 }
 
-void DolphinMainWindow::toggleShowHiddenFiles()
+void DolphinMainWindow::disableStopAction()
 {
-    clearStatusBar();
-
-    const KToggleAction* showHiddenFilesAction =
-        static_cast<KToggleAction*>(actionCollection()->action("show_hidden_files"));
-    const bool show = showHiddenFilesAction->isChecked();
-    m_activeView->setShowHiddenFiles(show);
+    actionCollection()->action("stop")->setEnabled(false);
 }
 
 void DolphinMainWindow::showFilterBar()
 {
-    const KToggleAction* showFilterBarAction =
-        static_cast<KToggleAction*>(actionCollection()->action("show_filter_bar"));
-    const bool show = showFilterBarAction->isChecked();
-    m_activeView->slotShowFilterBar(show);
+    m_activeViewContainer->setFilterBarVisible(true);
 }
 
-void DolphinMainWindow::zoomIn()
+void DolphinMainWindow::toggleEditLocation()
 {
-    m_activeView->zoomIn();
-    updateViewActions();
-}
+    clearStatusBar();
 
-void DolphinMainWindow::zoomOut()
-{
-    m_activeView->zoomOut();
-    updateViewActions();
+    QAction* action = actionCollection()->action("editable_location");
+    KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
+    urlNavigator->setUrlEditable(action->isChecked());
 }
 
-void DolphinMainWindow::toggleEditLocation()
+void DolphinMainWindow::replaceLocation()
 {
-    clearStatusBar();
-
-    KToggleAction* action = static_cast<KToggleAction*>(actionCollection()->action("editable_location"));
+    KUrlNavigator* navigator = m_activeViewContainer->urlNavigator();
+    navigator->setUrlEditable(true);
+    navigator->setFocus();
 
-    bool editOrBrowse = action->isChecked();
-//    action->setChecked(action->setChecked);
-    m_activeView->setUrlEditable(editOrBrowse);
+    // select the whole text of the combo box editor
+    QLineEdit* lineEdit = navigator->editor()->lineEdit();  // krazy:exclude=qclasses
+    lineEdit->selectAll();
 }
 
-void DolphinMainWindow::editLocation()
+void DolphinMainWindow::togglePanelLockState()
 {
-    KToggleAction* action = static_cast<KToggleAction*>(actionCollection()->action("editable_location"));
-    action->setChecked(true);
-    m_activeView->setUrlEditable(true);
+    const bool newLockState = !GeneralSettings::lockPanels();
+    foreach (QObject* child, children()) {
+        DolphinDockWidget* dock = qobject_cast<DolphinDockWidget*>(child);
+        if (dock) {
+            dock->setLocked(newLockState);
+        }
+    }
+
+    GeneralSettings::setLockPanels(newLockState);
 }
 
-void DolphinMainWindow::adjustViewProperties()
+void DolphinMainWindow::slotPlacesPanelVisibilityChanged(bool visible)
 {
-    clearStatusBar();
-    ViewPropertiesDialog dlg(m_activeView);
-    dlg.exec();
+    const int tabCount = m_viewTab.count();
+    for (int i = 0; i < tabCount; ++i) {
+        ViewTab& tab = m_viewTab[i];
+        Q_ASSERT(tab.primaryView);
+        tab.primaryView->urlNavigator()->setPlacesSelectorVisible(!visible);
+        if (tab.secondaryView) {
+            tab.secondaryView->urlNavigator()->setPlacesSelectorVisible(!visible);
+        }
+    }
 }
 
 void DolphinMainWindow::goBack()
 {
-    clearStatusBar();
-    m_activeView->goBack();
+    KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
+    urlNavigator->goBack();
+
+    if (urlNavigator->locationState().isEmpty()) {
+        // An empty location state indicates a redirection URL,
+        // which must be skipped too
+        urlNavigator->goBack();
+    }
 }
 
 void DolphinMainWindow::goForward()
 {
-    clearStatusBar();
-    m_activeView->goForward();
+    m_activeViewContainer->urlNavigator()->goForward();
 }
 
 void DolphinMainWindow::goUp()
 {
-    clearStatusBar();
-    m_activeView->goUp();
+    m_activeViewContainer->urlNavigator()->goUp();
 }
 
 void DolphinMainWindow::goHome()
 {
-    clearStatusBar();
-    m_activeView->goHome();
+    m_activeViewContainer->urlNavigator()->goHome();
 }
 
-void DolphinMainWindow::openTerminal()
+void DolphinMainWindow::goBack(Qt::MouseButtons buttons)
 {
-    QString command("konsole --workdir \"");
-    command.append(m_activeView->url().path());
-    command.append('\"');
+    // The default case (left button pressed) is handled in goBack().
+    if (buttons == Qt::MidButton) {
+        KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator();
+        const int index = urlNavigator->historyIndex() + 1;
+        openNewTab(urlNavigator->locationUrl(index));
+    }
+}
 
-    KRun::runCommand(command, "Konsole", "konsole");
+void DolphinMainWindow::goForward(Qt::MouseButtons buttons)
+{
+    // The default case (left button pressed) is handled in goForward().
+    if (buttons == Qt::MidButton) {
+        KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator();
+        const int index = urlNavigator->historyIndex() - 1;
+        openNewTab(urlNavigator->locationUrl(index));
+    }
 }
 
-void DolphinMainWindow::findFile()
+void DolphinMainWindow::goUp(Qt::MouseButtons buttons)
 {
-    KRun::run("kfind", m_activeView->url());
+    // The default case (left button pressed) is handled in goUp().
+    if (buttons == Qt::MidButton) {
+        openNewTab(activeViewContainer()->url().upUrl());
+    }
 }
 
 void DolphinMainWindow::compareFiles()
@@ -935,42 +1032,43 @@ void DolphinMainWindow::compareFiles()
     // - both in the secondary view
     // - one in the primary view and the other in the secondary
     //   view
-    assert(m_view[PrimaryIdx] != 0);
+    Q_ASSERT(m_viewTab[m_tabIndex].primaryView);
 
     KUrl urlA;
     KUrl urlB;
-    KUrl::List urls = m_view[PrimaryIdx]->selectedUrls();
-
-    switch (urls.count()) {
-        case 0: {
-            assert(m_view[SecondaryIdx] != 0);
-            urls = m_view[SecondaryIdx]->selectedUrls();
-            assert(urls.count() == 2);
-            urlA = urls[0];
-            urlB = urls[1];
-            break;
-        }
 
-        case 1: {
-            urlA = urls[0];
-            assert(m_view[SecondaryIdx] != 0);
-            urls = m_view[SecondaryIdx]->selectedUrls();
-            assert(urls.count() == 1);
-            urlB = urls[0];
-            break;
-        }
+    KFileItemList items = m_viewTab[m_tabIndex].primaryView->view()->selectedItems();
 
-        case 2: {
-            urlA = urls[0];
-            urlB = urls[1];
-            break;
-        }
+    switch (items.count()) {
+    case 0: {
+        Q_ASSERT(m_viewTab[m_tabIndex].secondaryView);
+        items = m_viewTab[m_tabIndex].secondaryView->view()->selectedItems();
+        Q_ASSERT(items.count() == 2);
+        urlA = items[0].url();
+        urlB = items[1].url();
+        break;
+    }
 
-        default: {
-            // may not happen: compareFiles may only get invoked if 2
-            // files are selected
-            assert(false);
-        }
+    case 1: {
+        urlA = items[0].url();
+        Q_ASSERT(m_viewTab[m_tabIndex].secondaryView);
+        items = m_viewTab[m_tabIndex].secondaryView->view()->selectedItems();
+        Q_ASSERT(items.count() == 1);
+        urlB = items[0].url();
+        break;
+    }
+
+    case 2: {
+        urlA = items[0].url();
+        urlB = items[1].url();
+        break;
+    }
+
+    default: {
+        // may not happen: compareFiles may only get invoked if 2
+        // files are selected
+        Q_ASSERT(false);
+    }
     }
 
     QString command("kompare -c \"");
@@ -978,614 +1076,1225 @@ void DolphinMainWindow::compareFiles()
     command.append("\" \"");
     command.append(urlB.pathOrUrl());
     command.append('\"');
-    KRun::runCommand(command, "Kompare", "kompare");
+    KRun::runCommand(command, "Kompare", "kompare", this);
+}
 
+void DolphinMainWindow::toggleShowMenuBar()
+{
+    const bool visible = menuBar()->isVisible();
+    menuBar()->setVisible(!visible);
+    if (visible) {
+        createToolBarMenuButton();
+    } else {
+        deleteToolBarMenuButton();
+    }
+}
+
+void DolphinMainWindow::openTerminal()
+{
+    QString dir(QDir::homePath());
+
+    // If the given directory is not local, it can still be the URL of an
+    // ioslave using UDS_LOCAL_PATH which to be converted first.
+    KUrl url = KIO::NetAccess::mostLocalUrl(m_activeViewContainer->url(), this);
+
+    //If the URL is local after the above conversion, set the directory.
+    if (url.isLocalFile()) {
+        dir = url.toLocalFile();
+    }
+
+    KToolInvocation::invokeTerminal(QString(), dir);
 }
 
 void DolphinMainWindow::editSettings()
 {
-    // TODO: make a static method for opening the settings dialog
-    DolphinSettingsDialog dlg(this);
-    dlg.exec();
+    if (!m_settingsDialog) {
+        const KUrl url = activeViewContainer()->url();
+        DolphinSettingsDialog* settingsDialog = new DolphinSettingsDialog(url, this);
+        connect(settingsDialog, SIGNAL(settingsChanged()), this, SLOT(refreshViews()));
+        settingsDialog->setAttribute(Qt::WA_DeleteOnClose);
+        settingsDialog->show();
+        m_settingsDialog = settingsDialog;
+    } else {
+        m_settingsDialog.data()->raise();
+    }
 }
 
-void DolphinMainWindow::addUndoOperation(KJob* job)
+void DolphinMainWindow::setActiveTab(int index)
 {
-    if (job->error() != 0) {
-        slotHandleJobError(job);
+    Q_ASSERT(index >= 0);
+    Q_ASSERT(index < m_viewTab.count());
+    if (index == m_tabIndex) {
+        return;
     }
-    else {
-        const int id = job->progressId();
 
-        // set iterator to the executed command with the current id...
-        Q3ValueList<UndoInfo>::Iterator it = m_pendingUndoJobs.begin();
-        const Q3ValueList<UndoInfo>::Iterator end = m_pendingUndoJobs.end();
-        bool found = false;
-        while (!found && (it != end)) {
-            if ((*it).id == id) {
-                found = true;
-            }
-            else {
-                ++it;
-            }
-        }
+    // hide current tab content
+    ViewTab& hiddenTab = m_viewTab[m_tabIndex];
+    hiddenTab.isPrimaryViewActive = hiddenTab.primaryView->isActive();
+    hiddenTab.primaryView->setActive(false);
+    if (hiddenTab.secondaryView) {
+        hiddenTab.secondaryView->setActive(false);
+    }
+    QSplitter* splitter = m_viewTab[m_tabIndex].splitter;
+    splitter->hide();
+    m_centralWidgetLayout->removeWidget(splitter);
+
+    // show active tab content
+    m_tabIndex = index;
+
+    ViewTab& viewTab = m_viewTab[index];
+    m_centralWidgetLayout->addWidget(viewTab.splitter, 1);
+    viewTab.primaryView->show();
+    if (viewTab.secondaryView) {
+        viewTab.secondaryView->show();
+    }
+    viewTab.splitter->show();
 
-        if (found) {
-            DolphinCommand command = (*it).command;
-            if (command.type() == DolphinCommand::Trash) {
-                // To be able to perform an undo for the 'Move to Trash' operation
-                // all source Urls must be updated with the trash Url. E. g. when moving
-                // a file "test.txt" and a second file "test.txt" to the trash,
-                // then the filenames in the trash are "0-test.txt" and "1-test.txt".
-                QMap<QString, QString> metaData;
-                KIO::Job *kiojob = qobject_cast<KIO::Job*>( job );
-                if ( kiojob )
-                {
-                    metaData = kiojob->metaData();
-                }
-                KUrl::List newSourceUrls;
-
-                KUrl::List sourceUrls = command.source();
-                KUrl::List::Iterator sourceIt = sourceUrls.begin();
-                const KUrl::List::Iterator sourceEnd = sourceUrls.end();
-
-                while (sourceIt != sourceEnd) {
-                    QMap<QString, QString>::ConstIterator metaIt = metaData.find("trashUrl-" + (*sourceIt).path());
-                    if (metaIt != metaData.end()) {
-                        newSourceUrls.append(KUrl(metaIt.value()));
-                    }
-                    ++sourceIt;
-                }
-                command.setSource(newSourceUrls);
-            }
+    if (!viewTab.wasActive) {
+        viewTab.wasActive = true;
 
-            UndoManager::instance().addCommand(command);
-            m_pendingUndoJobs.erase(it);
-
-            DolphinStatusBar* statusBar = m_activeView->statusBar();
-            switch (command.type()) {
-                case DolphinCommand::Copy:
-                    statusBar->setMessage(i18n("Copy operation completed."),
-                                          DolphinStatusBar::OperationCompleted);
-                    break;
-                case DolphinCommand::Move:
-                    statusBar->setMessage(i18n("Move operation completed."),
-                                          DolphinStatusBar::OperationCompleted);
-                    break;
-                case DolphinCommand::Trash:
-                    statusBar->setMessage(i18n("Move to trash operation completed."),
-                                          DolphinStatusBar::OperationCompleted);
-                    break;
-                default:
-                    break;
-            }
+        // If the tab has not been activated yet the size of the KItemListView is
+        // undefined and results in an unwanted animation. To prevent this a
+        // reloading of the directory gets triggered.
+        viewTab.primaryView->view()->reload();
+        if (viewTab.secondaryView) {
+            viewTab.secondaryView->view()->reload();
         }
     }
+
+    setActiveViewContainer(viewTab.isPrimaryViewActive ? viewTab.primaryView :
+                                                         viewTab.secondaryView);
 }
 
-void DolphinMainWindow::init()
+void DolphinMainWindow::closeTab()
 {
-    // Check whether Dolphin runs the first time. If yes then
-    // a proper default window size is given at the end of DolphinMainWindow::init().
-    GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();
-    const bool firstRun = generalSettings->firstRun();
+    closeTab(m_tabBar->currentIndex());
+}
 
-    setAcceptDrops(true);
+void DolphinMainWindow::closeTab(int index)
+{
+    Q_ASSERT(index >= 0);
+    Q_ASSERT(index < m_viewTab.count());
+    if (m_viewTab.count() == 1) {
+        // the last tab may never get closed
+        return;
+    }
 
-    m_splitter = new QSplitter(this);
+    if (index == m_tabIndex) {
+        // The tab that should be closed is the active tab. Activate the
+        // previous tab before closing the tab.
+        m_tabBar->setCurrentIndex((index > 0) ? index - 1 : 1);
+    }
+    rememberClosedTab(index);
 
-    DolphinSettings& settings = DolphinSettings::instance();
+    // delete tab
+    m_viewTab[index].primaryView->deleteLater();
+    if (m_viewTab[index].secondaryView) {
+        m_viewTab[index].secondaryView->deleteLater();
+    }
+    m_viewTab[index].splitter->deleteLater();
+    m_viewTab.erase(m_viewTab.begin() + index);
 
-    KBookmarkManager* manager = settings.bookmarkManager();
-    assert(manager != 0);
-    KBookmarkGroup root = manager->root();
-    if (root.first().isNull()) {
-        root.addBookmark(manager, i18n("Home"), settings.generalSettings()->homeUrl(), "folder_home");
-        root.addBookmark(manager, i18n("Storage Media"), KUrl("media:/"), "blockdevice");
-        root.addBookmark(manager, i18n("Network"), KUrl("remote:/"), "network_local");
-        root.addBookmark(manager, i18n("Root"), KUrl("/"), "folder_red");
-        root.addBookmark(manager, i18n("Trash"), KUrl("trash:/"), "trashcan_full");
+    m_tabBar->blockSignals(true);
+    m_tabBar->removeTab(index);
+
+    if (m_tabIndex > index) {
+        m_tabIndex--;
+        Q_ASSERT(m_tabIndex >= 0);
     }
 
-    setupActions();
+    // if only one tab is left, also remove the tab entry so that
+    // 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);
+    }
+}
 
-    const KUrl& homeUrl = root.first().url();
-    setCaption(homeUrl.fileName());
-    ViewProperties props(homeUrl);
-    m_view[PrimaryIdx] = new DolphinView(this,
-                                         m_splitter,
-                                         homeUrl,
-                                         props.viewMode(),
-                                         props.showHiddenFiles());
-    connectViewSignals(PrimaryIdx);
-    m_view[PrimaryIdx]->show();
+void DolphinMainWindow::openTabContextMenu(int index, const QPoint& pos)
+{
+    KMenu menu(this);
 
-    m_activeView = m_view[PrimaryIdx];
+    QAction* newTabAction = menu.addAction(KIcon("tab-new"), i18nc("@action:inmenu", "New Tab"));
+    newTabAction->setShortcut(actionCollection()->action("new_tab")->shortcut());
 
-    setCentralWidget(m_splitter);
-    setupDockWidgets();
+    QAction* detachTabAction = menu.addAction(KIcon("tab-detach"), i18nc("@action:inmenu", "Detach Tab"));
 
-    setupGUI(Keys|Save|Create|ToolBar);
-    createGUI();
+    QAction* closeOtherTabsAction = menu.addAction(KIcon("tab-close-other"), i18nc("@action:inmenu", "Close Other Tabs"));
 
-    stateChanged("new_file");
-    setAutoSaveSettings();
+    QAction* closeTabAction = menu.addAction(KIcon("tab-close"), i18nc("@action:inmenu", "Close Tab"));
+    closeTabAction->setShortcut(actionCollection()->action("close_tab")->shortcut());
+    QAction* selectedAction = menu.exec(pos);
+    if (selectedAction == newTabAction) {
+        const ViewTab& tab = m_viewTab[index];
+        Q_ASSERT(tab.primaryView);
+        const KUrl url = tab.secondaryView && tab.secondaryView->isActive() ?
+                         tab.secondaryView->url() : tab.primaryView->url();
+        openNewTab(url);
+        m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
+    } else if (selectedAction == detachTabAction) {
+        const QString separator(QLatin1Char(' '));
+        QString command = QLatin1String("dolphin");
 
-    QClipboard* clipboard = QApplication::clipboard();
-    connect(clipboard, SIGNAL(dataChanged()),
-            this, SLOT(updatePasteAction()));
-    updatePasteAction();
-    updateGoActions();
+        const ViewTab& tab = m_viewTab[index];
+        Q_ASSERT(tab.primaryView);
 
-    setupCreateNewMenuActions();
+        command += separator + tab.primaryView->url().url();
+        if (tab.secondaryView) {
+            command += separator + tab.secondaryView->url().url();
+            command += separator + QLatin1String("-split");
+        }
 
-    loadSettings();
+        KRun::runCommand(command, this);
 
-    if (firstRun) {
-        // assure a proper default size if Dolphin runs the first time
-        resize(640, 480);
+        closeTab(index);
+    } else if (selectedAction == closeOtherTabsAction) {
+        const int count = m_tabBar->count();
+        for (int i = 0; i < index; ++i) {
+            closeTab(0);
+        }
+        for (int i = index + 1; i < count; ++i) {
+            closeTab(1);
+        }
+    } else if (selectedAction == closeTabAction) {
+        closeTab(index);
     }
 }
 
-void DolphinMainWindow::loadSettings()
+void DolphinMainWindow::slotTabMoved(int from, int to)
 {
-    GeneralSettings* settings = DolphinSettings::instance().generalSettings();
+    m_viewTab.move(from, to);
+    m_tabIndex = m_tabBar->currentIndex();
+}
 
-    KToggleAction* splitAction = static_cast<KToggleAction*>(actionCollection()->action("split_view"));
-    if (settings->splitView()) {
-        splitAction->setChecked(true);
-        toggleSplitView();
+void DolphinMainWindow::handlePlacesClick(const KUrl& url, Qt::MouseButtons buttons)
+{
+    if (buttons & Qt::MidButton) {
+        openNewTab(url);
+        m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
+    } else {
+        changeUrl(url);
     }
+}
 
-    updateViewActions();
+void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent* event, bool& canDecode)
+{
+    canDecode = KUrl::List::canDecode(event->mimeData());
 }
 
-void DolphinMainWindow::setupActions()
+void DolphinMainWindow::handleUrl(const KUrl& url)
 {
-    // setup 'File' menu
-    KAction *action = new KAction(KIcon("window_new"),  i18n( "New &Window" ), actionCollection(), "new_window" );
-    connect(action, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
+    delete m_lastHandleUrlStatJob;
+    m_lastHandleUrlStatJob = 0;
 
-    KAction* createFolder = new KAction(i18n("Folder..."), actionCollection(), "create_folder");
-    createFolder->setIcon(KIcon("folder"));
-    createFolder->setShortcut(Qt::Key_N);
-    connect(createFolder, SIGNAL(triggered()), this, SLOT(createFolder()));
+    if (url.isLocalFile() && QFileInfo(url.toLocalFile()).isDir()) {
+        activeViewContainer()->setUrl(url);
+    } else if (KProtocolManager::supportsListing(url)) {
+        // stat the URL to see if it is a dir or not
+        m_lastHandleUrlStatJob = KIO::stat(url, KIO::HideProgressInfo);
+        connect(m_lastHandleUrlStatJob, SIGNAL(result(KJob*)),
+                this, SLOT(slotHandleUrlStatFinished(KJob*)));
 
-    KAction* rename = new KAction(i18n("Rename"), actionCollection(), "rename");
-    rename->setShortcut(Qt::Key_F2);
-    connect(rename, SIGNAL(triggered()), this, SLOT(rename()));
+    } else {
+        new KRun(url, this);
+    }
+}
 
-    KAction* moveToTrash = new KAction(i18n("Move to Trash"), actionCollection(), "move_to_trash");
-    moveToTrash->setIcon(KIcon("edittrash"));
-    moveToTrash->setShortcut(QKeySequence::Delete);
-    connect(moveToTrash, SIGNAL(triggered()), this, SLOT(moveToTrash()));
+void DolphinMainWindow::slotHandleUrlStatFinished(KJob* job)
+{
+    m_lastHandleUrlStatJob = 0;
+    const KIO::UDSEntry entry = static_cast<KIO::StatJob*>(job)->statResult();
+    const KUrl url = static_cast<KIO::StatJob*>(job)->url();
+    if (entry.isDir()) {
+        activeViewContainer()->setUrl(url);
+    } else {
+        new KRun(url, this);
+    }
+}
 
-    KAction* deleteAction = new KAction(i18n("Delete"), actionCollection(), "delete");
-    deleteAction->setShortcut(Qt::ALT | Qt::Key_Delete);
-    deleteAction->setIcon(KIcon("editdelete"));
-    connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItems()));
+void DolphinMainWindow::tabDropEvent(int tab, QDropEvent* event)
+{
+    const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
+    if (!urls.isEmpty() && tab != -1) {
+        const ViewTab& viewTab = m_viewTab[tab];
+        const KUrl destPath = viewTab.isPrimaryViewActive ? viewTab.primaryView->url() : viewTab.secondaryView->url();
+        Q_UNUSED(destPath);
+        //DragAndDropHelper::instance().dropUrls(KFileItem(), destPath, event, m_tabBar);
+    }
+}
 
-    KAction* properties = new KAction(i18n("Propert&ies"), actionCollection(), "properties");
-    properties->setShortcut(Qt::Key_Alt | Qt::Key_Return);
-    connect(properties, SIGNAL(triggered()), this, SLOT(properties()));
+void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable)
+{
+    newFileMenu()->setEnabled(isFolderWritable);
+}
 
-    KStandardAction::quit(this, SLOT(quit()), actionCollection());
+void DolphinMainWindow::slotSearchModeChanged(bool enabled)
+{
+#ifdef HAVE_NEPOMUK
+    const DolphinSearchInformation& searchInfo = DolphinSearchInformation::instance();
+    if (!searchInfo.isIndexingEnabled()) {
+        return;
+    }
 
-    // setup 'Edit' menu
-    UndoManager& undoManager = UndoManager::instance();
-    KStandardAction::undo(this,
-                     SLOT(undo()),
-                     actionCollection());
-    connect(&undoManager, SIGNAL(undoAvailable(bool)),
-            this, SLOT(slotUndoAvailable(bool)));
-    connect(&undoManager, SIGNAL(undoTextChanged(const QString&)),
-            this, SLOT(slotUndoTextChanged(const QString&)));
-
-    KStandardAction::redo(this,
-                     SLOT(redo()),
-                     actionCollection());
-    connect(&undoManager, SIGNAL(redoAvailable(bool)),
-            this, SLOT(slotRedoAvailable(bool)));
-    connect(&undoManager, SIGNAL(redoTextChanged(const QString&)),
-            this, SLOT(slotRedoTextChanged(const QString&)));
-
-    KStandardAction::cut(this, SLOT(cut()), actionCollection());
-    KStandardAction::copy(this, SLOT(copy()), actionCollection());
-    KStandardAction::paste(this, SLOT(paste()), actionCollection());
+    QDockWidget* searchDock = findChild<QDockWidget*>("searchDock");
+    if (!searchDock) {
+        return;
+    }
 
-    KAction* selectAll = new KAction(i18n("Select All"), actionCollection(), "select_all");
-    selectAll->setShortcut(Qt::CTRL + Qt::Key_A);
-    connect(selectAll, SIGNAL(triggered()), this, SLOT(selectAll()));
+    if (enabled) {
+        if (!searchDock->isVisible()) {
+            m_searchDockIsTemporaryVisible = true;
+        }
+        searchDock->show();
+    } else {
+        if (searchDock->isVisible() && m_searchDockIsTemporaryVisible) {
+            searchDock->hide();
+        }
+        m_searchDockIsTemporaryVisible = false;
+    }
 
-    KAction* invertSelection = new KAction(i18n("Invert Selection"), actionCollection(), "invert_selection");
-    invertSelection->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_A);
-    connect(invertSelection, SIGNAL(triggered()), this, SLOT(invertSelection()));
+    SearchPanel* searchPanel = qobject_cast<SearchPanel*>(searchDock->widget());
+    if (!searchPanel) {
+        return;
+    }
 
-    // setup 'View' menu
-    KStandardAction::zoomIn(this,
-                       SLOT(zoomIn()),
-                       actionCollection());
+    if (enabled) {
+        SearchPanel::SearchLocation searchLocation = SearchPanel::Everywhere;
+        const KUrl url = m_activeViewContainer->url();
+        const bool isSearchUrl = (url.protocol() == QLatin1String("nepomuksearch"));
+        if ((SearchSettings::location() == QLatin1String("FromHere") && !isSearchUrl)) {
+            searchLocation = SearchPanel::FromCurrentDir;
+        }
+        searchPanel->setSearchLocation(searchLocation);
+    } else {
+        searchPanel->setSearchLocation(SearchPanel::Everywhere);
+    }
+#else
+    Q_UNUSED(enabled);
+#endif
+}
+
+void DolphinMainWindow::openContextMenu(const QPoint& pos,
+                                        const KFileItem& item,
+                                        const KUrl& url,
+                                        const QList<QAction*>& customActions)
+{
+    QWeakPointer<DolphinContextMenu> contextMenu = new DolphinContextMenu(this, pos, item, url);
+    contextMenu.data()->setCustomActions(customActions);
+    const DolphinContextMenu::Command command = contextMenu.data()->open();
+
+    switch (command) {
+    case DolphinContextMenu::OpenParentFolderInNewWindow: {
+        KRun::run("dolphin", KUrl::List() << item.url().upUrl(), this);
+        break;
+    }
+
+    case DolphinContextMenu::OpenParentFolderInNewTab:
+        openNewTab(item.url().upUrl());
+        break;
+
+    case DolphinContextMenu::None:
+    default:
+        break;
+    }
+
+    delete contextMenu.data();
+}
+
+void DolphinMainWindow::updateToolBarMenu()
+{
+    KMenu* menu = qobject_cast<KMenu*>(sender());
+    Q_ASSERT(menu);
+
+    // All actions get cleared by KMenu::clear(). The sub-menus are deleted
+    // by connecting to the aboutToHide() signal from the parent-menu.
+    menu->clear();
+
+    KActionCollection* ac = actionCollection();
+
+    // Add "Edit" actions
+    bool added = addActionToMenu(ac->action(KStandardAction::name(KStandardAction::Undo)), menu) |
+                 addActionToMenu(ac->action(KStandardAction::name(KStandardAction::Find)), menu) |
+                 addActionToMenu(ac->action("select_all"), menu) |
+                 addActionToMenu(ac->action("invert_selection"), menu);
+
+    if (added) {
+        menu->addSeparator();
+    }
 
-    KStandardAction::zoomOut(this,
-                        SLOT(zoomOut()),
-                        actionCollection());
+    // Add "View" actions
+    if (!GeneralSettings::showZoomSlider()) {
+        addActionToMenu(ac->action(KStandardAction::name(KStandardAction::ZoomIn)), menu);
+        addActionToMenu(ac->action(KStandardAction::name(KStandardAction::ZoomOut)), menu);
+        menu->addSeparator();
+    }
+
+    added = addActionToMenu(ac->action("view_mode"), menu) |
+            addActionToMenu(ac->action("sort"), menu) |
+            addActionToMenu(ac->action("additional_info"), menu) |
+            addActionToMenu(ac->action("show_preview"), menu) |
+            addActionToMenu(ac->action("show_in_groups"), menu) |
+            addActionToMenu(ac->action("show_hidden_files"), menu);
+
+    if (added) {
+        menu->addSeparator();
+    }
+
+    added = addActionToMenu(ac->action("split_view"), menu) |
+            addActionToMenu(ac->action("reload"), menu) |
+            addActionToMenu(ac->action("view_properties"), menu);
+    if (added) {
+        menu->addSeparator();
+    }
+
+    addActionToMenu(ac->action("panels"), menu);
+    KMenu* locationBarMenu = new KMenu(i18nc("@action:inmenu", "Location Bar"), menu);
+    locationBarMenu->addAction(ac->action("editable_location"));
+    locationBarMenu->addAction(ac->action("replace_location"));
+    menu->addMenu(locationBarMenu);
+
+    menu->addSeparator();
+
+    // Add "Go" menu
+    KMenu* goMenu = new KMenu(i18nc("@action:inmenu", "Go"), menu);
+    connect(menu, SIGNAL(aboutToHide()), goMenu, SLOT(deleteLater()));
+    goMenu->addAction(ac->action(KStandardAction::name(KStandardAction::Back)));
+    goMenu->addAction(ac->action(KStandardAction::name(KStandardAction::Forward)));
+    goMenu->addAction(ac->action(KStandardAction::name(KStandardAction::Up)));
+    goMenu->addAction(ac->action(KStandardAction::name(KStandardAction::Home)));
+    goMenu->addAction(ac->action("closed_tabs"));
+    menu->addMenu(goMenu);
+
+    // Add "Tool" menu
+    KMenu* toolsMenu = new KMenu(i18nc("@action:inmenu", "Tools"), menu);
+    connect(menu, SIGNAL(aboutToHide()), toolsMenu, SLOT(deleteLater()));
+    toolsMenu->addAction(ac->action("show_filter_bar"));
+    toolsMenu->addAction(ac->action("compare_files"));
+    toolsMenu->addAction(ac->action("open_terminal"));
+    toolsMenu->addAction(ac->action("change_remote_encoding"));
+    menu->addMenu(toolsMenu);
+
+    // Add "Settings" menu entries
+    addActionToMenu(ac->action(KStandardAction::name(KStandardAction::KeyBindings)), menu);
+    addActionToMenu(ac->action(KStandardAction::name(KStandardAction::ConfigureToolbars)), menu);
+    addActionToMenu(ac->action(KStandardAction::name(KStandardAction::Preferences)), menu);
+
+    // Add "Help" menu
+    KMenu* helpMenu = new KMenu(i18nc("@action:inmenu", "Help"), menu);
+    connect(menu, SIGNAL(aboutToHide()), helpMenu, SLOT(deleteLater()));
+    helpMenu->addAction(ac->action(KStandardAction::name(KStandardAction::HelpContents)));
+    helpMenu->addAction(ac->action(KStandardAction::name(KStandardAction::WhatsThis)));
+    helpMenu->addSeparator();
+    helpMenu->addAction(ac->action(KStandardAction::name(KStandardAction::ReportBug)));
+    helpMenu->addSeparator();
+    helpMenu->addAction(ac->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage)));
+    helpMenu->addSeparator();
+    helpMenu->addAction(ac->action(KStandardAction::name(KStandardAction::AboutApp)));
+    helpMenu->addAction(ac->action(KStandardAction::name(KStandardAction::AboutKDE)));
+    menu->addMenu(helpMenu);
+
+    menu->addSeparator();
+    addActionToMenu(ac->action(KStandardAction::name(KStandardAction::ShowMenubar)), menu);
+}
+
+void DolphinMainWindow::updateToolBar()
+{
+    if (!menuBar()->isVisible()) {
+        createToolBarMenuButton();
+    }
+}
+
+void DolphinMainWindow::slotToolBarSpacerDeleted()
+{
+    m_toolBarSpacer = 0;
+    m_updateToolBarTimer->start();
+}
+
+void DolphinMainWindow::slotToolBarMenuButtonDeleted()
+{
+    m_openToolBarMenuButton = 0;
+    m_updateToolBarTimer->start();
+}
+
+void DolphinMainWindow::slotToolBarIconSizeChanged(const QSize& iconSize)
+{
+    if (m_openToolBarMenuButton) {
+        m_openToolBarMenuButton->setIconSize(iconSize);
+    }
+}
+
+void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContainer)
+{
+    Q_ASSERT(viewContainer);
+    Q_ASSERT((viewContainer == m_viewTab[m_tabIndex].primaryView) ||
+             (viewContainer == m_viewTab[m_tabIndex].secondaryView));
+    if (m_activeViewContainer == viewContainer) {
+        return;
+    }
+
+    m_activeViewContainer->setActive(false);
+    m_activeViewContainer = viewContainer;
+
+    // Activating the view container might trigger a recursive setActiveViewContainer() call
+    // inside DolphinMainWindow::toggleActiveView() when having a split view. Temporary
+    // disconnect the activated() signal in this case:
+    disconnect(m_activeViewContainer->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
+    m_activeViewContainer->setActive(true);
+    connect(m_activeViewContainer->view(), SIGNAL(activated()), this, SLOT(toggleActiveView()));
+
+    m_actionHandler->setCurrentView(viewContainer->view());
+
+    updateHistory();
+    updateEditActions();
+    updateViewActions();
+    updateGoActions();
 
-    KToggleAction* iconsView = new KToggleAction(i18n("Icons"), actionCollection(), "icons");
-    iconsView->setShortcut(Qt::CTRL | Qt::Key_1);
-    iconsView->setIcon(KIcon("view_icon"));
-    connect(iconsView, SIGNAL(triggered()), this, SLOT(setIconsView()));
+    const KUrl url = m_activeViewContainer->url();
+    setUrlAsCaption(url);
+    if (m_viewTab.count() > 1) {
+        m_tabBar->setTabText(m_tabIndex, tabName(url));
+        m_tabBar->setTabIcon(m_tabIndex, KIcon(KMimeType::iconNameForUrl(url)));
+    }
+
+    emit urlChanged(url);
+}
+
+DolphinViewContainer* DolphinMainWindow::createViewContainer(const KUrl& url, QWidget* parent)
+{
+    DolphinViewContainer* container = new DolphinViewContainer(url, parent);
 
-    KToggleAction* detailsView = new KToggleAction(i18n("Details"), actionCollection(), "details");
-    detailsView->setShortcut(Qt::CTRL | Qt::Key_2);
-    detailsView->setIcon(KIcon("view_text"));
-    connect(detailsView, SIGNAL(triggered()), this, SLOT(setDetailsView()));
+    // The places-selector from the URL navigator should only be shown
+    // if the places dock is invisible
+    QDockWidget* placesDock = findChild<QDockWidget*>("placesDock");
+    container->urlNavigator()->setPlacesSelectorVisible(!placesDock || !placesDock->isVisible());
 
-    QActionGroup* viewModeGroup = new QActionGroup(this);
-    viewModeGroup->addAction(iconsView);
-    viewModeGroup->addAction(detailsView);
+    return container;
+}
 
-    KToggleAction* sortByName = new KToggleAction(i18n("By Name"), actionCollection(), "by_name");
-    connect(sortByName, SIGNAL(triggered()), this, SLOT(sortByName()));
+void DolphinMainWindow::setupActions()
+{
+    // setup 'File' menu
+    m_newFileMenu = new DolphinNewFileMenu(this);
+    KMenu* menu = m_newFileMenu->menu();
+    menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
+    menu->setIcon(KIcon("document-new"));
+    connect(menu, SIGNAL(aboutToShow()),
+            this, SLOT(updateNewMenu()));
+
+    KAction* newWindow = actionCollection()->addAction("new_window");
+    newWindow->setIcon(KIcon("window-new"));
+    newWindow->setText(i18nc("@action:inmenu File", "New &Window"));
+    newWindow->setShortcut(Qt::CTRL | Qt::Key_N);
+    connect(newWindow, SIGNAL(triggered()), this, SLOT(openNewMainWindow()));
+
+    KAction* newTab = actionCollection()->addAction("new_tab");
+    newTab->setIcon(KIcon("tab-new"));
+    newTab->setText(i18nc("@action:inmenu File", "New Tab"));
+    newTab->setShortcut(KShortcut(Qt::CTRL | Qt::Key_T, Qt::CTRL | Qt::SHIFT | Qt::Key_N));
+    connect(newTab, SIGNAL(triggered()), this, SLOT(openNewTab()));
+
+    KAction* closeTab = actionCollection()->addAction("close_tab");
+    closeTab->setIcon(KIcon("tab-close"));
+    closeTab->setText(i18nc("@action:inmenu File", "Close Tab"));
+    closeTab->setShortcut(Qt::CTRL | Qt::Key_W);
+    closeTab->setEnabled(false);
+    connect(closeTab, SIGNAL(triggered()), this, SLOT(closeTab()));
 
-    KToggleAction* sortBySize = new KToggleAction(i18n("By Size"), actionCollection(), "by_size");
-    connect(sortBySize, SIGNAL(triggered()), this, SLOT(sortBySize()));
+    KStandardAction::quit(this, SLOT(quit()), actionCollection());
 
-    KToggleAction* sortByDate = new KToggleAction(i18n("By Date"), actionCollection(), "by_date");
-    connect(sortByDate, SIGNAL(triggered()), this, SLOT(sortByDate()));
+    // setup 'Edit' menu
+    KStandardAction::undo(this,
+                          SLOT(undo()),
+                          actionCollection());
+
+    // need to remove shift+del from cut action, else the shortcut for deletejob
+    // doesn't work
+    KAction* cut = KStandardAction::cut(this, SLOT(cut()), actionCollection());
+    KShortcut cutShortcut = cut->shortcut();
+    cutShortcut.remove(Qt::SHIFT | Qt::Key_Delete, KShortcut::KeepEmpty);
+    cut->setShortcut(cutShortcut);
+    KStandardAction::copy(this, SLOT(copy()), actionCollection());
+    KAction* paste = KStandardAction::paste(this, SLOT(paste()), actionCollection());
+    // The text of the paste-action is modified dynamically by Dolphin
+    // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
+    // due to the long text, the text "Paste" is used:
+    paste->setIconText(i18nc("@action:inmenu Edit", "Paste"));
 
-    QActionGroup* sortGroup = new QActionGroup(this);
-    sortGroup->addAction(sortByName);
-    sortGroup->addAction(sortBySize);
-    sortGroup->addAction(sortByDate);
+    KStandardAction::find(this, SLOT(find()), actionCollection());
 
-    KToggleAction* sortDescending = new KToggleAction(i18n("Descending"), actionCollection(), "descending");
-    connect(sortDescending, SIGNAL(triggered()), this, SLOT(toggleSortOrder()));
+    KAction* selectAll = actionCollection()->addAction("select_all");
+    selectAll->setText(i18nc("@action:inmenu Edit", "Select All"));
+    selectAll->setShortcut(Qt::CTRL | Qt::Key_A);
+    connect(selectAll, SIGNAL(triggered()), this, SLOT(selectAll()));
 
-    KToggleAction* showPreview = new KToggleAction(i18n("Show Preview"), actionCollection(), "show_preview");
-    connect(showPreview, SIGNAL(triggered()), this, SLOT(togglePreview()));
+    KAction* invertSelection = actionCollection()->addAction("invert_selection");
+    invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
+    invertSelection->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_A);
+    connect(invertSelection, SIGNAL(triggered()), this, SLOT(invertSelection()));
 
-    KToggleAction* showHiddenFiles = new KToggleAction(i18n("Show Hidden Files"), actionCollection(), "show_hidden_files");
-    //showHiddenFiles->setShortcut(Qt::ALT | Qt::Key_      KDE4-TODO: what Qt-Key represents '.'?
-    connect(showHiddenFiles, SIGNAL(triggered()), this, SLOT(toggleShowHiddenFiles()));
+    // setup 'View' menu
+    // (note that most of it is set up in DolphinViewActionHandler)
 
-    KToggleAction* split = new KToggleAction(i18n("Split View"), actionCollection(), "split_view");
-    split->setShortcut(Qt::Key_F10);
-    split->setIcon(KIcon("view_left_right"));
+    KAction* split = actionCollection()->addAction("split_view");
+    split->setShortcut(Qt::Key_F3);
+    updateSplitAction();
     connect(split, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
 
-    KAction* reload = new KAction(actionCollection(), "reload");
-    reload->setText(i18n("Reload"));
+    KAction* reload = actionCollection()->addAction("reload");
+    reload->setText(i18nc("@action:inmenu View", "Reload"));
     reload->setShortcut(Qt::Key_F5);
-    reload->setIcon(KIcon("reload"));
+    reload->setIcon(KIcon("view-refresh"));
     connect(reload, SIGNAL(triggered()), this, SLOT(reloadView()));
 
-    KAction* stop = new KAction(i18n("Stop"), actionCollection(), "stop");
-    stop->setIcon(KIcon("stop"));
+    KAction* stop = actionCollection()->addAction("stop");
+    stop->setText(i18nc("@action:inmenu View", "Stop"));
+    stop->setToolTip(i18nc("@info", "Stop loading"));
+    stop->setIcon(KIcon("process-stop"));
     connect(stop, SIGNAL(triggered()), this, SLOT(stopLoading()));
 
-    KToggleAction* showFullLocation = new KToggleAction(i18n("Show Full Location"), actionCollection(), "editable_location");
-    showFullLocation->setShortcut(Qt::CTRL | Qt::Key_L);
-    connect(showFullLocation, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
-
-    KToggleAction* editLocation = new KToggleAction(i18n("Edit Location"), actionCollection(), "edit_location");
-    editLocation->setShortcut(Qt::Key_F6);
-    connect(editLocation, SIGNAL(triggered()), this, SLOT(editLocation()));
+    KToggleAction* editableLocation = actionCollection()->add<KToggleAction>("editable_location");
+    editableLocation->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
+    editableLocation->setShortcut(Qt::CTRL | Qt::Key_L);
+    connect(editableLocation, SIGNAL(triggered()), this, SLOT(toggleEditLocation()));
 
-    KAction* adjustViewProps = new KAction(i18n("Adjust View Properties..."), actionCollection(), "view_properties");
-    connect(adjustViewProps, SIGNAL(triggered()), this, SLOT(adjustViewProperties()));
+    KAction* replaceLocation = actionCollection()->addAction("replace_location");
+    replaceLocation->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
+    replaceLocation->setShortcut(Qt::Key_F6);
+    connect(replaceLocation, SIGNAL(triggered()), this, SLOT(replaceLocation()));
 
     // setup 'Go' menu
-    KStandardAction::back(this, SLOT(goBack()), actionCollection());
-    KStandardAction::forward(this, SLOT(goForward()), actionCollection());
-    KStandardAction::up(this, SLOT(goUp()), actionCollection());
+    KAction* backAction = KStandardAction::back(this, SLOT(goBack()), actionCollection());
+    connect(backAction, SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)), this, SLOT(goBack(Qt::MouseButtons)));
+    KShortcut backShortcut = backAction->shortcut();
+    backShortcut.setAlternate(Qt::Key_Backspace);
+    backAction->setShortcut(backShortcut);
+
+    m_recentTabsMenu = new KActionMenu(i18n("Recently Closed Tabs"), this);
+    m_recentTabsMenu->setIcon(KIcon("edit-undo"));
+    actionCollection()->addAction("closed_tabs", m_recentTabsMenu);
+    connect(m_recentTabsMenu->menu(), SIGNAL(triggered(QAction*)),
+            this, SLOT(restoreClosedTab(QAction*)));
+
+    QAction* action = new QAction(i18n("Empty Recently Closed Tabs"), m_recentTabsMenu);
+    action->setIcon(KIcon("edit-clear-list"));
+    action->setData(QVariant::fromValue(true));
+    m_recentTabsMenu->addAction(action);
+    m_recentTabsMenu->addSeparator();
+    m_recentTabsMenu->setEnabled(false);
+
+    KAction* forwardAction = KStandardAction::forward(this, SLOT(goForward()), actionCollection());
+    connect(forwardAction, SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)), this, SLOT(goForward(Qt::MouseButtons)));
+
+    KAction* upAction = KStandardAction::up(this, SLOT(goUp()), actionCollection());
+    connect(upAction, SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)), this, SLOT(goUp(Qt::MouseButtons)));
+
     KStandardAction::home(this, SLOT(goHome()), actionCollection());
 
     // setup 'Tools' menu
-    KAction* openTerminal = new KAction(i18n("Open Terminal"), actionCollection(), "open_terminal");
-    openTerminal->setShortcut(Qt::Key_F4);
-    openTerminal->setIcon(KIcon("konsole"));
-    connect(openTerminal, SIGNAL(triggered()), this, SLOT(openTerminal()));
-
-    KAction* findFile = new KAction(i18n("Find File..."), actionCollection(), "find_file");
-    findFile->setShortcut(Qt::Key_F);
-    findFile->setIcon(KIcon("filefind"));
-    connect(findFile, SIGNAL(triggered()), this, SLOT(findFile()));
-
-    KToggleAction* showFilterBar = new KToggleAction(i18n("Show Filter Bar"), actionCollection(), "show_filter_bar");
-    showFilterBar->setShortcut(Qt::Key_Slash);
+    KAction* showFilterBar = actionCollection()->addAction("show_filter_bar");
+    showFilterBar->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
+    showFilterBar->setIcon(KIcon("view-filter"));
+    showFilterBar->setShortcut(Qt::CTRL | Qt::Key_I);
     connect(showFilterBar, SIGNAL(triggered()), this, SLOT(showFilterBar()));
 
-    KAction* compareFiles = new KAction(i18n("Compare Files"), actionCollection(), "compare_files");
+    KAction* compareFiles = actionCollection()->addAction("compare_files");
+    compareFiles->setText(i18nc("@action:inmenu Tools", "Compare Files"));
     compareFiles->setIcon(KIcon("kompare"));
     compareFiles->setEnabled(false);
     connect(compareFiles, SIGNAL(triggered()), this, SLOT(compareFiles()));
 
+    KAction* openTerminal = actionCollection()->addAction("open_terminal");
+    openTerminal->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
+    openTerminal->setIcon(KIcon("utilities-terminal"));
+    openTerminal->setShortcut(Qt::SHIFT | Qt::Key_F4);
+    connect(openTerminal, SIGNAL(triggered()), this, SLOT(openTerminal()));
+
     // setup 'Settings' menu
+    KToggleAction* showMenuBar = KStandardAction::showMenubar(0, 0, actionCollection());
+    connect(showMenuBar, SIGNAL(triggered(bool)),                   // Fixes #286822
+            this, SLOT(toggleShowMenuBar()), Qt::QueuedConnection);
     KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
+
+    // not in menu actions
+    QList<QKeySequence> nextTabKeys;
+    nextTabKeys.append(KStandardShortcut::tabNext().primary());
+    nextTabKeys.append(QKeySequence(Qt::CTRL | Qt::Key_Tab));
+
+    QList<QKeySequence> prevTabKeys;
+    prevTabKeys.append(KStandardShortcut::tabPrev().primary());
+    prevTabKeys.append(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_Tab));
+
+    KAction* activateNextTab = actionCollection()->addAction("activate_next_tab");
+    activateNextTab->setText(i18nc("@action:inmenu", "Activate Next Tab"));
+    connect(activateNextTab, SIGNAL(triggered()), SLOT(activateNextTab()));
+    activateNextTab->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys : nextTabKeys);
+
+    KAction* activatePrevTab = actionCollection()->addAction("activate_prev_tab");
+    activatePrevTab->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
+    connect(activatePrevTab, SIGNAL(triggered()), SLOT(activatePrevTab()));
+    activatePrevTab->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys : prevTabKeys);
+
+    // for context menu
+    KAction* openInNewTab = actionCollection()->addAction("open_in_new_tab");
+    openInNewTab->setText(i18nc("@action:inmenu", "Open in New Tab"));
+    openInNewTab->setIcon(KIcon("tab-new"));
+    connect(openInNewTab, SIGNAL(triggered()), this, SLOT(openInNewTab()));
+
+    KAction* openInNewWindow = actionCollection()->addAction("open_in_new_window");
+    openInNewWindow->setText(i18nc("@action:inmenu", "Open in New Window"));
+    openInNewWindow->setIcon(KIcon("window-new"));
+    connect(openInNewWindow, SIGNAL(triggered()), this, SLOT(openInNewWindow()));
 }
 
 void DolphinMainWindow::setupDockWidgets()
 {
-    QDockWidget* shortcutsDock = new QDockWidget(i18n("Shortcuts"));
-    shortcutsDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
-    shortcutsDock->setWidget(new BookmarksSidebarPage(this));
-
-    shortcutsDock->toggleViewAction()->setObjectName("show_shortcuts_panel");
-    shortcutsDock->toggleViewAction()->setText(i18n("Show Shortcuts Panel"));
-    actionCollection()->insert(shortcutsDock->toggleViewAction());
+    const bool lock = GeneralSettings::lockPanels();
 
-    addDockWidget(Qt::LeftDockWidgetArea, shortcutsDock);
+    KDualAction* lockLayoutAction = actionCollection()->add<KDualAction>("lock_panels");
+    lockLayoutAction->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
+    lockLayoutAction->setActiveIcon(KIcon("object-unlocked"));
+    lockLayoutAction->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
+    lockLayoutAction->setInactiveIcon(KIcon("object-locked"));
+    lockLayoutAction->setActive(lock);
+    connect(lockLayoutAction, SIGNAL(triggered()), this, SLOT(togglePanelLockState()));
 
-    QDockWidget* infoDock = new QDockWidget(i18n("Information"));
+    // Setup "Information"
+    DolphinDockWidget* infoDock = new DolphinDockWidget(i18nc("@title:window", "Information"));
+    infoDock->setLocked(lock);
+    infoDock->setObjectName("infoDock");
     infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
-    infoDock->setWidget(new InfoSidebarPage(this));
+    Panel* infoPanel = new InformationPanel(infoDock);
+    infoPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
+    connect(infoPanel, SIGNAL(urlActivated(KUrl)), this, SLOT(handleUrl(KUrl)));
+    infoDock->setWidget(infoPanel);
 
-    infoDock->toggleViewAction()->setObjectName("show_info_panel");
-    infoDock->toggleViewAction()->setText(i18n("Show Information Panel"));
-    actionCollection()->insert(infoDock->toggleViewAction());
+    QAction* infoAction = infoDock->toggleViewAction();
+    createPanelAction(KIcon("dialog-information"), Qt::Key_F11, infoAction, "show_information_panel");
 
     addDockWidget(Qt::RightDockWidgetArea, infoDock);
+    connect(this, SIGNAL(urlChanged(KUrl)),
+            infoPanel, SLOT(setUrl(KUrl)));
+    connect(this, SIGNAL(selectionChanged(KFileItemList)),
+            infoPanel, SLOT(setSelection(KFileItemList)));
+    connect(this, SIGNAL(requestItemInfo(KFileItem)),
+            infoPanel, SLOT(requestDelayedItemInfo(KFileItem)));
+
+    // Setup "Folders"
+    DolphinDockWidget* foldersDock = new DolphinDockWidget(i18nc("@title:window", "Folders"));
+    foldersDock->setLocked(lock);
+    foldersDock->setObjectName("foldersDock");
+    foldersDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
+    FoldersPanel* foldersPanel = new FoldersPanel(foldersDock);
+    foldersPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
+    foldersDock->setWidget(foldersPanel);
+
+    QAction* foldersAction = foldersDock->toggleViewAction();
+    createPanelAction(KIcon("folder"), Qt::Key_F7, foldersAction, "show_folders_panel");
+
+    addDockWidget(Qt::LeftDockWidgetArea, foldersDock);
+    connect(this, SIGNAL(urlChanged(KUrl)),
+            foldersPanel, SLOT(setUrl(KUrl)));
+    connect(foldersPanel, SIGNAL(changeUrl(KUrl,Qt::MouseButtons)),
+            this, SLOT(handlePlacesClick(KUrl,Qt::MouseButtons)));
+
+    // Setup "Terminal"
+#ifndef Q_OS_WIN
+    DolphinDockWidget* terminalDock = new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
+    terminalDock->setLocked(lock);
+    terminalDock->setObjectName("terminalDock");
+    terminalDock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
+    Panel* terminalPanel = new TerminalPanel(terminalDock);
+    terminalPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
+    terminalDock->setWidget(terminalPanel);
+
+    connect(terminalPanel, SIGNAL(hideTerminalPanel()), terminalDock, SLOT(hide()));
+    connect(terminalDock, SIGNAL(visibilityChanged(bool)),
+            terminalPanel, SLOT(dockVisibilityChanged()));
+
+    QAction* terminalAction = terminalDock->toggleViewAction();
+    createPanelAction(KIcon("utilities-terminal"), Qt::Key_F4, terminalAction, "show_terminal_panel");
+
+    addDockWidget(Qt::BottomDockWidgetArea, terminalDock);
+    connect(this, SIGNAL(urlChanged(KUrl)),
+            terminalPanel, SLOT(setUrl(KUrl)));
+#endif
+
+    // Setup "Search"
+#ifdef HAVE_NEPOMUK
+    DolphinDockWidget* searchDock = new DolphinDockWidget(i18nc("@title:window", "Search"));
+    searchDock->setLocked(lock);
+    searchDock->setObjectName("searchDock");
+    searchDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
+    Panel* searchPanel = new SearchPanel(searchDock);
+    searchPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
+    connect(searchPanel, SIGNAL(urlActivated(KUrl)), this, SLOT(handleUrl(KUrl)));
+    searchDock->setWidget(searchPanel);
+
+    QAction* searchAction = searchDock->toggleViewAction();
+    createPanelAction(KIcon("system-search"), Qt::Key_F12, searchAction, "show_search_panel");
+    addDockWidget(Qt::RightDockWidgetArea, searchDock);
+    connect(this, SIGNAL(urlChanged(KUrl)),
+            searchPanel, SLOT(setUrl(KUrl)));
+#endif
+
+    if (GeneralSettings::version() < 200) {
+        infoDock->hide();
+        foldersDock->hide();
+#ifndef Q_OS_WIN
+        terminalDock->hide();
+#endif
+#ifdef HAVE_NEPOMUK
+        searchDock->hide();
+#endif
+    }
+
+    // Setup "Places"
+    DolphinDockWidget* placesDock = new DolphinDockWidget(i18nc("@title:window", "Places"));
+    placesDock->setLocked(lock);
+    placesDock->setObjectName("placesDock");
+    placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
+
+    PlacesPanel* placesPanel = new PlacesPanel(placesDock);
+    QAction* separator = new QAction(placesPanel);
+    separator->setSeparator(true);
+    QList<QAction*> placesActions;
+    placesActions.append(separator);
+    placesActions.append(lockLayoutAction);
+    placesPanel->addActions(placesActions);
+    placesPanel->setModel(DolphinPlacesModel::instance());
+    placesPanel->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+    placesDock->setWidget(placesPanel);
+
+    QAction* placesAction = placesDock->toggleViewAction();
+    createPanelAction(KIcon("bookmarks"), Qt::Key_F9, placesAction, "show_places_panel");
+
+    addDockWidget(Qt::LeftDockWidgetArea, placesDock);
+    connect(placesPanel, SIGNAL(urlChanged(KUrl,Qt::MouseButtons)),
+            this, SLOT(handlePlacesClick(KUrl,Qt::MouseButtons)));
+    connect(this, SIGNAL(urlChanged(KUrl)),
+            placesPanel, SLOT(setUrl(KUrl)));
+    connect(placesDock, SIGNAL(visibilityChanged(bool)),
+            this, SLOT(slotPlacesPanelVisibilityChanged(bool)));
+
+    // Add actions into the "Panels" menu
+    KActionMenu* panelsMenu = new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
+    actionCollection()->addAction("panels", panelsMenu);
+    panelsMenu->setDelayed(false);
+    const KActionCollection* ac = actionCollection();
+    panelsMenu->addAction(ac->action("show_places_panel"));
+    panelsMenu->addAction(ac->action("show_information_panel"));
+    panelsMenu->addAction(ac->action("show_folders_panel"));
+#ifndef Q_OS_WIN
+    panelsMenu->addAction(ac->action("show_terminal_panel"));
+#endif
+#ifdef HAVE_NEPOMUK
+    panelsMenu->addAction(ac->action("show_search_panel"));
+#endif
+    panelsMenu->addSeparator();
+    panelsMenu->addAction(lockLayoutAction);
 }
 
-void DolphinMainWindow::setupCreateNewMenuActions()
-{
-    // Parts of the following code have been taken
-    // from the class KNewMenu located in
-    // libqonq/knewmenu.h of Konqueror.
-    //  Copyright (C) 1998, 1999 David Faure <faure@kde.org>
-    //                2003       Sven Leiber <s.leiber@web.de>
-
-    QStringList files = actionCollection()->instance()->dirs()->findAllResources("templates");
-    for (QStringList::Iterator it = files.begin() ; it != files.end(); ++it) {
-        if ((*it)[0] != '.' ) {
-            KSimpleConfig config(*it, true);
-            config.setDesktopGroup();
-
-            // tricky solution to ensure that TextFile is at the beginning
-            // because this filetype is the most used (according kde-core discussion)
-            const QString name(config.readEntry("Name"));
-            QString key(name);
-
-            const QString path(config.readPathEntry("Url"));
-            if (!path.endsWith("emptydir")) {
-                if (path.endsWith("TextFile.txt")) {
-                    key = "1" + key;
-                }
-                else if (!KDesktopFile::isDesktopFile(path)) {
-                    key = "2" + key;
-                }
-                else if (path.endsWith("Url.desktop")){
-                    key = "3" + key;
-                }
-                else if (path.endsWith("Program.desktop")){
-                    key = "4" + key;
-                }
-                else {
-                    key = "5";
-                }
-
-                const QString icon(config.readEntry("Icon"));
-                const QString comment(config.readEntry("Comment"));
-                const QString type(config.readEntry("Type"));
-
-                const QString filePath(*it);
-
-
-                if (type == "Link") {
-                    CreateFileEntry entry;
-                    entry.name = name;
-                    entry.icon = icon;
-                    entry.comment = comment;
-                    entry.templatePath = filePath;
-                    m_createFileTemplates.insert(key, entry);
-                }
-            }
-        }
+void DolphinMainWindow::updateEditActions()
+{
+    const KFileItemList list = m_activeViewContainer->view()->selectedItems();
+    if (list.isEmpty()) {
+        stateChanged("has_no_selection");
+    } else {
+        stateChanged("has_selection");
+
+        KActionCollection* col = actionCollection();
+        QAction* renameAction      = col->action("rename");
+        QAction* moveToTrashAction = col->action("move_to_trash");
+        QAction* deleteAction      = col->action("delete");
+        QAction* cutAction         = col->action(KStandardAction::name(KStandardAction::Cut));
+        QAction* deleteWithTrashShortcut = col->action("delete_shortcut"); // see DolphinViewActionHandler
+
+        KFileItemListProperties capabilities(list);
+        const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving();
+
+        renameAction->setEnabled(capabilities.supportsMoving());
+        moveToTrashAction->setEnabled(enableMoveToTrash);
+        deleteAction->setEnabled(capabilities.supportsDeleting());
+        deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash);
+        cutAction->setEnabled(capabilities.supportsMoving());
     }
-    m_createFileTemplates.sort();
-
-    unplugActionList("create_actions");
-    KSortableList<CreateFileEntry, QString>::ConstIterator it = m_createFileTemplates.begin();
-    KSortableList<CreateFileEntry, QString>::ConstIterator end = m_createFileTemplates.end();
-    /* KDE4-TODO: don't port this code; use KNewMenu instead
-    while (it != end) {
-        CreateFileEntry entry = (*it).value();
-        KAction* action = new KAction(entry.name);
-        action->setIcon(entry.icon);
-        action->setName((*it).index());
-        connect(action, SIGNAL(activated()),
-                this, SLOT(createFile()));
-
-        const QChar section = ((*it).index()[0]);
-        switch (section) {
-            case '1':
-            case '2': {
-                m_fileGroupActions.append(action);
-                break;
-            }
+    updatePasteAction();
+}
 
-            case '3':
-            case '4': {
-                // TODO: not used yet. See documentation of DolphinMainWindow::linkGroupActions()
-                // and DolphinMainWindow::linkToDeviceActions() in the header file for details.
-                //m_linkGroupActions.append(action);
-                break;
-            }
+void DolphinMainWindow::updateViewActions()
+{
+    m_actionHandler->updateViewActions();
 
-            case '5': {
-                // TODO: not used yet. See documentation of DolphinMainWindow::linkGroupActions()
-                // and DolphinMainWindow::linkToDeviceActions() in the header file for details.
-                //m_linkToDeviceActions.append(action);
-                break;
-            }
-            default:
-                break;
+    QAction* showFilterBarAction = actionCollection()->action("show_filter_bar");
+    showFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible());
+
+    updateSplitAction();
+
+    QAction* editableLocactionAction = actionCollection()->action("editable_location");
+    const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
+    editableLocactionAction->setChecked(urlNavigator->isUrlEditable());
+}
+
+void DolphinMainWindow::updateGoActions()
+{
+    QAction* goUpAction = actionCollection()->action(KStandardAction::name(KStandardAction::Up));
+    const KUrl currentUrl = m_activeViewContainer->url();
+    goUpAction->setEnabled(currentUrl.upUrl() != currentUrl);
+}
+
+void DolphinMainWindow::createToolBarMenuButton()
+{
+    if (m_toolBarSpacer && m_openToolBarMenuButton) {
+        return;
+    }
+    Q_ASSERT(!m_toolBarSpacer);
+    Q_ASSERT(!m_openToolBarMenuButton);
+
+    m_toolBarSpacer = new QWidget(this);
+    m_toolBarSpacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
+
+    m_openToolBarMenuButton = new QToolButton(this);
+    m_openToolBarMenuButton->setIcon(KIcon("configure"));
+    m_openToolBarMenuButton->setPopupMode(QToolButton::InstantPopup);
+    m_openToolBarMenuButton->setToolTip(i18nc("@info:tooltip", "Configure and control Dolphin"));
+
+    KMenu* toolBarMenu = new ToolBarMenu(m_openToolBarMenuButton);
+    connect(toolBarMenu, SIGNAL(aboutToShow()), this, SLOT(updateToolBarMenu()));
+
+    m_openToolBarMenuButton->setMenu(toolBarMenu);
+
+    toolBar()->addWidget(m_toolBarSpacer);
+    toolBar()->addWidget(m_openToolBarMenuButton);
+    connect(toolBar(), SIGNAL(iconSizeChanged(QSize)), this, SLOT(slotToolBarIconSizeChanged(QSize)));
+
+    // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
+    // gets edited. In this case we must add them again. The adding is done asynchronously by
+    // m_updateToolBarTimer.
+    connect(m_toolBarSpacer, SIGNAL(destroyed()), this, SLOT(slotToolBarSpacerDeleted()));
+    connect(m_openToolBarMenuButton, SIGNAL(destroyed()), this, SLOT(slotToolBarMenuButtonDeleted()));
+    m_updateToolBarTimer = new QTimer(this);
+    m_updateToolBarTimer->setInterval(500);
+    connect(m_updateToolBarTimer, SIGNAL(timeout()), this, SLOT(updateToolBar()));
+}
+
+void DolphinMainWindow::deleteToolBarMenuButton()
+{
+    delete m_toolBarSpacer;
+    m_toolBarSpacer = 0;
+
+    delete m_openToolBarMenuButton;
+    m_openToolBarMenuButton = 0;
+
+    delete m_updateToolBarTimer;
+    m_updateToolBarTimer = 0;
+}
+
+bool DolphinMainWindow::addActionToMenu(QAction* action, KMenu* menu)
+{
+    Q_ASSERT(action);
+    Q_ASSERT(menu);
+
+    const KToolBar* toolBarWidget = toolBar();
+    foreach (const QWidget* widget, action->associatedWidgets()) {
+        if (widget == toolBarWidget) {
+            return false;
         }
-        ++it;
     }
 
-    plugActionList("create_file_group", m_fileGroupActions);
-    //plugActionList("create_link_group", m_linkGroupActions);
-    //plugActionList("link_to_device", m_linkToDeviceActions);*/
+    menu->addAction(action);
+    return true;
 }
 
-void DolphinMainWindow::updateHistory()
+void DolphinMainWindow::rememberClosedTab(int index)
 {
-    int index = 0;
-    const Q3ValueList<UrlNavigator::HistoryElem> list = m_activeView->urlHistory(index);
+    KMenu* tabsMenu = m_recentTabsMenu->menu();
 
-    QAction* backAction = actionCollection()->action("go_back");
-    if (backAction != 0) {
-        backAction->setEnabled(index < static_cast<int>(list.count()) - 1);
+    const QString primaryPath = m_viewTab[index].primaryView->url().path();
+    const QString iconName = KMimeType::iconNameForUrl(primaryPath);
+
+    QAction* action = new QAction(squeezedText(primaryPath), tabsMenu);
+
+    ClosedTab closedTab;
+    closedTab.primaryUrl = m_viewTab[index].primaryView->url();
+
+    if (m_viewTab[index].secondaryView) {
+        closedTab.secondaryUrl = m_viewTab[index].secondaryView->url();
+        closedTab.isSplit = true;
+    } else {
+        closedTab.isSplit = false;
     }
 
-    QAction* forwardAction = actionCollection()->action("go_forward");
-    if (forwardAction != 0) {
-        forwardAction->setEnabled(index > 0);
+    action->setData(QVariant::fromValue(closedTab));
+    action->setIcon(KIcon(iconName));
+
+    // add the closed tab menu entry after the separator and
+    // "Empty Recently Closed Tabs" entry
+    if (tabsMenu->actions().size() == 2) {
+        tabsMenu->addAction(action);
+    } else {
+        tabsMenu->insertAction(tabsMenu->actions().at(2), action);
     }
+
+    // assure that only up to 8 closed tabs are shown in the menu
+    if (tabsMenu->actions().size() > 8) {
+        tabsMenu->removeAction(tabsMenu->actions().last());
+    }
+    actionCollection()->action("closed_tabs")->setEnabled(true);
+    KAcceleratorManager::manage(tabsMenu);
 }
 
-void DolphinMainWindow::updateEditActions()
+void DolphinMainWindow::refreshViews()
 {
-    const KFileItemList list = m_activeView->selectedItems();
-    if (list.isEmpty()) {
-        stateChanged("has_no_selection");
-    }
-    else {
-        stateChanged("has_selection");
+    Q_ASSERT(m_viewTab[m_tabIndex].primaryView);
+
+    // remember the current active view, as because of
+    // the refreshing the active view might change to
+    // the secondary view
+    DolphinViewContainer* activeViewContainer = m_activeViewContainer;
 
-        QAction* renameAction = actionCollection()->action("rename");
-        if (renameAction != 0) {
-            renameAction->setEnabled(list.count() >= 1);
+    const int tabCount = m_viewTab.count();
+    for (int i = 0; i < tabCount; ++i) {
+        m_viewTab[i].primaryView->refresh();
+        if (m_viewTab[i].secondaryView) {
+            m_viewTab[i].secondaryView->refresh();
         }
+    }
 
-        bool enableMoveToTrash = true;
+    setActiveViewContainer(activeViewContainer);
 
-        KFileItemList::const_iterator it = list.begin();
-        const KFileItemList::const_iterator end = list.end();
-        while (it != end) {
-            KFileItem* item = *it;
-            const KUrl& url = item->url();
-            // only enable the 'Move to Trash' action for local files
-            if (!url.isLocalFile()) {
-                enableMoveToTrash = false;
-            }
-            ++it;
+    if (GeneralSettings::modifiedStartupSettings()) {
+        // The startup settings have been changed by the user (see bug #254947).
+        // Synchronize the split-view setting with the active view:
+        const bool splitView = GeneralSettings::splitView();
+        const ViewTab& activeTab = m_viewTab[m_tabIndex];
+        const bool toggle =    ( splitView && !activeTab.secondaryView)
+                            || (!splitView &&  activeTab.secondaryView);
+        if (toggle) {
+            toggleSplitView();
         }
-
-        QAction* moveToTrashAction = actionCollection()->action("move_to_trash");
-        moveToTrashAction->setEnabled(enableMoveToTrash);
     }
-    updatePasteAction();
 }
 
-void DolphinMainWindow::updateViewActions()
+void DolphinMainWindow::clearStatusBar()
 {
-    QAction* zoomInAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::ZoomIn));
-    if (zoomInAction != 0) {
-        zoomInAction->setEnabled(m_activeView->isZoomInPossible());
-    }
+    m_activeViewContainer->statusBar()->clear();
+}
 
-    QAction* zoomOutAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::ZoomOut));
-    if (zoomOutAction != 0) {
-        zoomOutAction->setEnabled(m_activeView->isZoomOutPossible());
+void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
+{
+    connect(container, SIGNAL(showFilterBarChanged(bool)),
+            this, SLOT(updateFilterBarAction(bool)));
+    connect(container, SIGNAL(writeStateChanged(bool)),
+            this, SLOT(slotWriteStateChanged(bool)));
+    connect(container, SIGNAL(searchModeChanged(bool)),
+            this, SLOT(slotSearchModeChanged(bool)));
+
+    const DolphinSearchBox* searchBox = container->searchBox();
+    connect(searchBox, SIGNAL(searchLocationChanged(SearchLocation)),
+            this, SLOT(slotSearchLocationChanged()));
+
+    DolphinView* view = container->view();
+    connect(view, SIGNAL(selectionChanged(KFileItemList)),
+            this, SLOT(slotSelectionChanged(KFileItemList)));
+    connect(view, SIGNAL(requestItemInfo(KFileItem)),
+            this, SLOT(slotRequestItemInfo(KFileItem)));
+    connect(view, SIGNAL(activated()),
+            this, SLOT(toggleActiveView()));
+    connect(view, SIGNAL(tabRequested(KUrl)),
+            this, SLOT(openNewTab(KUrl)));
+    connect(view, SIGNAL(requestContextMenu(QPoint,KFileItem,KUrl,QList<QAction*>)),
+            this, SLOT(openContextMenu(QPoint,KFileItem,KUrl,QList<QAction*>)));
+    connect(view, SIGNAL(startedPathLoading(KUrl)),
+            this, SLOT(enableStopAction()));
+    connect(view, SIGNAL(finishedPathLoading(KUrl)),
+            this, SLOT(disableStopAction()));
+
+    const KUrlNavigator* navigator = container->urlNavigator();
+    connect(navigator, SIGNAL(urlChanged(KUrl)),
+            this, SLOT(changeUrl(KUrl)));
+    connect(navigator, SIGNAL(historyChanged()),
+            this, SLOT(updateHistory()));
+    connect(navigator, SIGNAL(editableStateChanged(bool)),
+            this, SLOT(slotEditableStateChanged(bool)));
+    connect(navigator, SIGNAL(tabRequested(KUrl)),
+            this, SLOT(openNewTab(KUrl)));
+}
+
+void DolphinMainWindow::updateSplitAction()
+{
+    QAction* splitAction = actionCollection()->action("split_view");
+    if (m_viewTab[m_tabIndex].secondaryView) {
+        if (m_activeViewContainer == m_viewTab[m_tabIndex].secondaryView) {
+            splitAction->setText(i18nc("@action:intoolbar Close right view", "Close"));
+            splitAction->setToolTip(i18nc("@info", "Close right view"));
+            splitAction->setIcon(KIcon("view-right-close"));
+        } else {
+            splitAction->setText(i18nc("@action:intoolbar Close left view", "Close"));
+            splitAction->setToolTip(i18nc("@info", "Close left view"));
+            splitAction->setIcon(KIcon("view-left-close"));
+        }
+    } else {
+        splitAction->setText(i18nc("@action:intoolbar Split view", "Split"));
+        splitAction->setToolTip(i18nc("@info", "Split view"));
+        splitAction->setIcon(KIcon("view-right-new"));
     }
+}
 
-    QAction* action = 0;
-    switch (m_activeView->mode()) {
-        case DolphinView::IconsView:
-            action = actionCollection()->action("icons");
-            break;
-        case DolphinView::DetailsView:
-            action = actionCollection()->action("details");
-            break;
-        //case DolphinView::PreviewsView:
-        //    action = actionCollection()->action("previews");
-        //    break;
-        default:
-            break;
+QString DolphinMainWindow::tabName(const KUrl& url) const
+{
+    QString name;
+    if (url.equals(KUrl("file:///"))) {
+        name = '/';
+    } else {
+        name = url.fileName();
+        if (name.isEmpty()) {
+            name = url.protocol();
+        } else {
+            // Make sure that a '&' inside the directory name is displayed correctly
+            // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
+            name.replace('&', "&&");
+        }
     }
+    return name;
+}
 
-    if (action != 0) {
-        KToggleAction* toggleAction = static_cast<KToggleAction*>(action);
-        toggleAction->setChecked(true);
+bool DolphinMainWindow::isKompareInstalled() const
+{
+    static bool initialized = false;
+    static bool installed = false;
+    if (!initialized) {
+        // TODO: maybe replace this approach later by using a menu
+        // plugin like kdiff3plugin.cpp
+        installed = !KGlobal::dirs()->findExe("kompare").isEmpty();
+        initialized = true;
     }
+    return installed;
+}
 
-    slotSortingChanged(m_activeView->sorting());
-    slotSortOrderChanged(m_activeView->sortOrder());
+void DolphinMainWindow::createSecondaryView(int tabIndex)
+{
+    ViewTab& viewTab = m_viewTab[tabIndex];
 
-    KToggleAction* showFilterBarAction =
-        static_cast<KToggleAction*>(actionCollection()->action("show_filter_bar"));
-    showFilterBarAction->setChecked(m_activeView->isFilterBarVisible());
+    QSplitter* splitter = viewTab.splitter;
+    const int newWidth = (viewTab.primaryView->width() - splitter->handleWidth()) / 2;
 
-    KToggleAction* showHiddenFilesAction =
-        static_cast<KToggleAction*>(actionCollection()->action("show_hidden_files"));
-    showHiddenFilesAction->setChecked(m_activeView->showHiddenFiles());
+    const DolphinView* view = viewTab.primaryView->view();
+    viewTab.secondaryView = createViewContainer(view->url(), 0);
+    splitter->addWidget(viewTab.secondaryView);
+    splitter->setSizes(QList<int>() << newWidth << newWidth);
 
-    KToggleAction* splitAction = static_cast<KToggleAction*>(actionCollection()->action("split_view"));
-    splitAction->setChecked(m_view[SecondaryIdx] != 0);
+    connectViewSignals(viewTab.secondaryView);
+    viewTab.secondaryView->setActive(false);
+    viewTab.secondaryView->resize(newWidth, viewTab.primaryView->height());
+    viewTab.secondaryView->show();
 }
 
-void DolphinMainWindow::updateGoActions()
+QString DolphinMainWindow::tabProperty(const QString& property, int tabIndex) const
 {
-    QAction* goUpAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Up));
-    const KUrl& currentUrl = m_activeView->url();
-    goUpAction->setEnabled(currentUrl.upUrl() != currentUrl);
+    return "Tab " + QString::number(tabIndex) + ' ' + property;
 }
 
-void DolphinMainWindow::copyUrls(const KUrl::List& source, const KUrl& dest)
+void DolphinMainWindow::setUrlAsCaption(const KUrl& url)
 {
-    KIO::Job* job = KIO::copy(source, dest);
-    addPendingUndoJob(job, DolphinCommand::Copy, source, dest);
+    QString caption;
+    if (!url.isLocalFile()) {
+        caption.append(url.protocol() + " - ");
+        if (url.hasHost()) {
+            caption.append(url.host() + " - ");
+        }
+    }
+
+    const QString fileName = url.fileName().isEmpty() ? "/" : url.fileName();
+    caption.append(fileName);
+
+    setCaption(caption);
 }
 
-void DolphinMainWindow::moveUrls(const KUrl::List& source, const KUrl& dest)
+QString DolphinMainWindow::squeezedText(const QString& text) const
 {
-    KIO::Job* job = KIO::move(source, dest);
-    addPendingUndoJob(job, DolphinCommand::Move, source, dest);
+    const QFontMetrics fm = fontMetrics();
+    return fm.elidedText(text, Qt::ElideMiddle, fm.maxWidth() * 10);
 }
 
-void DolphinMainWindow::addPendingUndoJob(KIO::Job* job,
-                                          DolphinCommand::Type commandType,
-                                          const KUrl::List& source,
-                                          const KUrl& dest)
+void DolphinMainWindow::createPanelAction(const KIcon& icon,
+                                          const QKeySequence& shortcut,
+                                          QAction* dockAction,
+                                          const QString& actionName)
 {
-    connect(job, SIGNAL(result(KJob*)),
-            this, SLOT(addUndoOperation(KJob*)));
+    KAction* panelAction = actionCollection()->addAction(actionName);
+    panelAction->setCheckable(true);
+    panelAction->setChecked(dockAction->isChecked());
+    panelAction->setText(dockAction->text());
+    panelAction->setIcon(icon);
+    panelAction->setShortcut(shortcut);
 
-    UndoInfo undoInfo;
-    undoInfo.id = job->progressId();
-    undoInfo.command = DolphinCommand(commandType, source, dest);
-    m_pendingUndoJobs.append(undoInfo);
+    connect(panelAction, SIGNAL(triggered()), dockAction, SLOT(trigger()));
+    connect(dockAction, SIGNAL(toggled(bool)), panelAction, SLOT(setChecked(bool)));
 }
 
-void DolphinMainWindow::clearStatusBar()
+DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
+    KIO::FileUndoManager::UiInterface()
 {
-    m_activeView->statusBar()->clear();
 }
 
-void DolphinMainWindow::connectViewSignals(int viewIndex)
+DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
 {
-    DolphinView* view = m_view[viewIndex];
-    connect(view, SIGNAL(modeChanged()),
-            this, SLOT(slotViewModeChanged()));
-    connect(view, SIGNAL(showHiddenFilesChanged()),
-            this, SLOT(slotShowHiddenFilesChanged()));
-    connect(view, SIGNAL(sortingChanged(DolphinView::Sorting)),
-            this, SLOT(slotSortingChanged(DolphinView::Sorting)));
-    connect(view, SIGNAL(sortOrderChanged(Qt::SortOrder)),
-            this, SLOT(slotSortOrderChanged(Qt::SortOrder)));
-    connect(view, SIGNAL(selectionChanged()),
-            this, SLOT(slotSelectionChanged()));
-    connect(view, SIGNAL(showFilterBarChanged(bool)),
-            this, SLOT(updateFilterBarAction(bool)));
+}
 
-    const UrlNavigator* navigator = view->urlNavigator();
-    connect(navigator, SIGNAL(urlChanged(const KUrl&)),
-            this, SLOT(slotUrlChanged(const KUrl&)));
-    connect(navigator, SIGNAL(historyChanged()),
-            this, SLOT(slotHistoryChanged()));
+void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job)
+{
+    DolphinMainWindow* mainWin= qobject_cast<DolphinMainWindow *>(parentWidget());
+    if (mainWin) {
+        DolphinStatusBar* statusBar = mainWin->activeViewContainer()->statusBar();
+        statusBar->setMessage(job->errorString(), DolphinStatusBar::Error);
+    } else {
+        KIO::FileUndoManager::UiInterface::jobError(job);
+    }
+}
+
+ToolBarMenu::ToolBarMenu(QWidget* parent) :
+    KMenu(parent)
+{
+}
+
+ToolBarMenu::~ToolBarMenu()
+{
+}
+
+void ToolBarMenu::showEvent(QShowEvent* event)
+{
+    KMenu::showEvent(event);
+
+    // Adjust the position of the menu to be shown within the
+    // Dolphin window to reduce the cases that sub-menus might overlap
+    // the right screen border.
+    QPoint pos;
+    QWidget* button = parentWidget();
+    if (layoutDirection() == Qt::RightToLeft) {
+        pos = button->mapToGlobal(QPoint(0, button->height()));
+    } else {
+        pos = button->mapToGlobal(QPoint(button->width(), button->height()));
+        pos.rx() -= width();
+    }
+
+    // Assure that the menu is not shown outside the screen boundaries and
+    // that it does not overlap with the parent button.
+    const QRect screen = QApplication::desktop()->screenGeometry(QCursor::pos());
+    if (pos.x() < screen.x()) {
+        pos.rx() = screen.x();
+    } else if (pos.x() + width() > screen.x() + screen.width()) {
+        pos.rx() = screen.x() + screen.width() - width();
+    }
+
+    if (pos.y() < screen.y()) {
+        pos.ry() = screen.y();
+    } else if (pos.y() + height() > screen.y() + screen.height()) {
+        pos.ry() = button->mapToGlobal(QPoint(0, 0)).y() - height();
+    }
 
+    move(pos);
 }
 
 #include "dolphinmainwindow.moc"