]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinmainwindow.cpp
Use PlacesItemModel instead of KFilePlacesModel
[dolphin.git] / src / dolphinmainwindow.cpp
index 6800daefbefc5d60ab5eee6fc6bd4572c012f31d..1ce51935f7b638cfeabec8b2565b58d5367f90c4 100644 (file)
 
 #include "dolphinmainwindow.h"
 
-#include <config-nepomuk.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"
@@ -49,7 +41,6 @@
 #endif
 
 #include "dolphin_generalsettings.h"
-#include "dolphin_searchsettings.h"
 
 #include <KAcceleratorManager>
 #include <KAction>
@@ -60,7 +51,6 @@
 #include <kdeversion.h>
 #include <kdualaction.h>
 #include <KFileDialog>
-#include <KFilePlacesModel>
 #include <KGlobal>
 #include <KLineEdit>
 #include <KToolBar>
@@ -89,8 +79,6 @@
 #include <KUrlComboBox>
 #include <KToolInvocation>
 
-#include "views/dolphinplacesmodel.h"
-
 #include <QDesktopWidget>
 #include <QDBusMessage>
 #include <QKeyEvent>
@@ -130,13 +118,8 @@ DolphinMainWindow::DolphinMainWindow() :
     m_settingsDialog(),
     m_controlButton(0),
     m_updateToolBarTimer(0),
-    m_lastHandleUrlStatJob(0),
-    m_searchDockIsTemporaryVisible(false)
+    m_lastHandleUrlStatJob(0)
 {
-    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):
@@ -386,6 +369,13 @@ void DolphinMainWindow::changeUrl(const KUrl& url)
     }
 }
 
+void DolphinMainWindow::slotTerminalDirectoryChanged(const KUrl& url)
+{
+    m_activeViewContainer->setAutoGrabFocus(false);
+    changeUrl(url);
+    m_activeViewContainer->setAutoGrabFocus(true);
+}
+
 void DolphinMainWindow::slotEditableStateChanged(bool editable)
 {
     KToggleAction* editableLocationAction =
@@ -508,6 +498,12 @@ void DolphinMainWindow::openNewTab(const KUrl& url)
     }
 }
 
+void DolphinMainWindow::openNewActivatedTab(const KUrl& url)
+{
+    openNewTab(url);
+    m_tabBar->setCurrentIndex(m_viewTab.count() - 1);
+}
+
 void DolphinMainWindow::activateNextTab()
 {
     if (m_viewTab.count() >= 2) {
@@ -631,14 +627,6 @@ void DolphinMainWindow::closeEvent(QCloseEvent* event)
     GeneralSettings::setVersion(CurrentDolphinVersion);
     GeneralSettings::self()->writeConfig();
 
-    if (m_searchDockIsTemporaryVisible) {
-        QDockWidget* searchDock = findChild<QDockWidget*>("searchDock");
-        if (searchDock) {
-            searchDock->hide();
-        }
-        m_searchDockIsTemporaryVisible = false;
-    }
-
     KXmlGuiWindow::closeEvent(event);
 }
 
@@ -799,23 +787,6 @@ void DolphinMainWindow::find()
     m_activeViewContainer->setSearchModeEnabled(true);
 }
 
-void DolphinMainWindow::slotSearchLocationChanged()
-{
-#ifdef HAVE_NEPOMUK
-    QDockWidget* searchDock = findChild<QDockWidget*>("searchDock");
-    if (!searchDock) {
-        return;
-    }
-
-    SearchPanel* searchPanel = qobject_cast<SearchPanel*>(searchDock->widget());
-    if (searchPanel) {
-        searchPanel->setSearchLocation(SearchSettings::location() == QLatin1String("FromHere")
-                                       ? SearchPanel::FromCurrentDir
-                                       : SearchPanel::Everywhere);
-    }
-#endif
-}
-
 void DolphinMainWindow::updatePasteAction()
 {
     QAction* pasteAction = actionCollection()->action(KStandardAction::name(KStandardAction::Paste));
@@ -1260,16 +1231,6 @@ void DolphinMainWindow::slotTabMoved(int from, int to)
     m_tabIndex = m_tabBar->currentIndex();
 }
 
-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);
-    }
-}
-
 void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent* event, bool& canDecode)
 {
     canDecode = KUrl::List::canDecode(event->mimeData());
@@ -1327,52 +1288,6 @@ void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable)
     newFileMenu()->setEnabled(isFolderWritable);
 }
 
-void DolphinMainWindow::slotSearchModeChanged(bool enabled)
-{
-#ifdef HAVE_NEPOMUK
-    const DolphinSearchInformation& searchInfo = DolphinSearchInformation::instance();
-    if (!searchInfo.isIndexingEnabled()) {
-        return;
-    }
-
-    QDockWidget* searchDock = findChild<QDockWidget*>("searchDock");
-    if (!searchDock) {
-        return;
-    }
-
-    if (enabled) {
-        if (!searchDock->isVisible()) {
-            m_searchDockIsTemporaryVisible = true;
-        }
-        searchDock->show();
-    } else {
-        if (searchDock->isVisible() && m_searchDockIsTemporaryVisible) {
-            searchDock->hide();
-        }
-        m_searchDockIsTemporaryVisible = false;
-    }
-
-    SearchPanel* searchPanel = qobject_cast<SearchPanel*>(searchDock->widget());
-    if (!searchPanel) {
-        return;
-    }
-
-    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,
@@ -1509,6 +1424,11 @@ void DolphinMainWindow::slotControlButtonDeleted()
     m_updateToolBarTimer->start();
 }
 
+void DolphinMainWindow::slotPanelErrorMessage(const QString& error)
+{
+    activeViewContainer()->showMessage(error, DolphinViewContainer::Error);
+}
+
 void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContainer)
 {
     Q_ASSERT(viewContainer);
@@ -1781,8 +1701,12 @@ void DolphinMainWindow::setupDockWidgets()
     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)));
+    connect(foldersPanel, SIGNAL(folderActivated(KUrl)),
+            this, SLOT(changeUrl(KUrl)));
+    connect(foldersPanel, SIGNAL(folderMiddleClicked(KUrl)),
+            this, SLOT(openNewActivatedTab(KUrl)));
+    connect(foldersPanel, SIGNAL(errorMessage(QString)),
+            this, SLOT(slotPanelErrorMessage(QString)));
 
     // Setup "Terminal"
 #ifndef Q_OS_WIN
@@ -1795,6 +1719,7 @@ void DolphinMainWindow::setupDockWidgets()
     terminalDock->setWidget(terminalPanel);
 
     connect(terminalPanel, SIGNAL(hideTerminalPanel()), terminalDock, SLOT(hide()));
+    connect(terminalPanel, SIGNAL(changeUrl(KUrl)), this, SLOT(slotTerminalDirectoryChanged(KUrl)));
     connect(terminalDock, SIGNAL(visibilityChanged(bool)),
             terminalPanel, SLOT(dockVisibilityChanged()));
 
@@ -1806,32 +1731,11 @@ void DolphinMainWindow::setupDockWidgets()
             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
     }
 
@@ -1842,22 +1746,19 @@ void DolphinMainWindow::setupDockWidgets()
     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);
+    placesPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
     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(placesPanel, SIGNAL(placeActivated(KUrl)),
+            this, SLOT(changeUrl(KUrl)));
+    connect(placesPanel, SIGNAL(placeMiddleClicked(KUrl)),
+            this, SLOT(openNewActivatedTab(KUrl)));
+    connect(placesPanel, SIGNAL(errorMessage(QString)),
+            this, SLOT(slotPanelErrorMessage(QString)));
     connect(this, SIGNAL(urlChanged(KUrl)),
             placesPanel, SLOT(setUrl(KUrl)));
     connect(placesDock, SIGNAL(visibilityChanged(bool)),
@@ -1873,9 +1774,6 @@ void DolphinMainWindow::setupDockWidgets()
     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);
@@ -2068,12 +1966,6 @@ void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
             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)),