]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphincontroller.cpp
Start of refactoring so that the metadata widget can be moved outside of Dolphin...
[dolphin.git] / src / dolphincontroller.cpp
index 820d34a064cde1a84e006280241fc3b92a68dcc6..89d6509ca42c0e9edc62af903649bd6af0b0d171 100644 (file)
@@ -31,9 +31,11 @@ Qt::MouseButtons DolphinController::m_mouseButtons = Qt::NoButton;
 DolphinController::DolphinController(DolphinView* dolphinView) :
     QObject(dolphinView),
     m_zoomLevel(0),
+    m_nameFilter(),
     m_url(),
     m_dolphinView(dolphinView),
-    m_itemView(0)
+    m_itemView(0),
+    m_versionControlActions()
 {
 }
 
@@ -45,10 +47,16 @@ void DolphinController::setUrl(const KUrl& url)
 {
     if (m_url != url) {
         m_url = url;
+        emit cancelPreviews();
         emit urlChanged(url);
     }
 }
 
+void DolphinController::redirectToUrl(const KUrl& url)
+{
+    m_url = url;
+}
+
 void DolphinController::setItemView(QAbstractItemView* view)
 {
     if (m_itemView != 0) {
@@ -74,10 +82,11 @@ void DolphinController::triggerUrlChangeRequest(const KUrl& url)
     }
 }
 
-void DolphinController::triggerContextMenuRequest(const QPoint& pos)
+void DolphinController::triggerContextMenuRequest(const QPoint& pos,
+                                                  const QList<QAction*>& customActions)
 {
     emit activated();
-    emit requestContextMenu(pos);
+    emit requestContextMenu(pos, customActions);
 }
 
 void DolphinController::requestActivation()
@@ -103,6 +112,11 @@ void DolphinController::indicateSortOrderChange(Qt::SortOrder order)
     emit sortOrderChanged(order);
 }
 
+void DolphinController::indicateSortFoldersFirstChange(bool foldersFirst)
+{
+    emit sortFoldersFirstChanged(foldersFirst);
+}
+
 void DolphinController::indicateAdditionalInfoChange(const KFileItemDelegate::InformationList& info)
 {
     emit additionalInfoChanged(info);
@@ -113,6 +127,19 @@ void DolphinController::indicateActivationChange(bool active)
     emit activationChanged(active);
 }
 
+void DolphinController::setNameFilter(const QString& nameFilter)
+{
+    if (nameFilter != m_nameFilter) {
+        m_nameFilter = nameFilter;
+        emit nameFilterChanged(nameFilter);
+    }
+}
+
+QString DolphinController::nameFilter() const
+{
+    return m_nameFilter;
+}
+
 void DolphinController::setZoomLevel(int level)
 {
     Q_ASSERT(level >= ZoomLevelInfo::minimumLevel());
@@ -123,42 +150,34 @@ void DolphinController::setZoomLevel(int level)
     }
 }
 
+void DolphinController::setVersionControlActions(QList<QAction*> actions)
+{
+    m_versionControlActions = actions;
+}
+
+QList<QAction*> DolphinController::versionControlActions(const KFileItemList& items)
+{
+    emit requestVersionControlActions(items);
+    // All view implementations are connected with the signal requestVersionControlActions()
+    // (see ViewExtensionFactory) and will invoke DolphinController::setVersionControlActions(),
+    // so that the context dependent actions can be returned.
+    return m_versionControlActions;
+}
+
 void DolphinController::handleKeyPressEvent(QKeyEvent* event)
 {
     Q_ASSERT(m_itemView != 0);
 
     const QItemSelectionModel* selModel = m_itemView->selectionModel();
     const QModelIndex currentIndex = selModel->currentIndex();
-
-    if (currentIndex.isValid() && selModel->selectedIndexes().count() > 0) {
-        const int key = event->key();
-
-        if ((key == Qt::Key_Return) || (key == Qt::Key_Enter) || (key == Qt::Key_Right)) {
-
-            const QModelIndexList indexList = selModel->selectedIndexes();
-            const bool isColumnView = m_dolphinView->mode() == m_dolphinView->ColumnView;
-
-            if (key == Qt::Key_Right) {
-                if (isColumnView) {
-                    // If it is the right arrow key and in the column view-only.
-                    KFileItem curFileItem;
-                    foreach(const QModelIndex& index, indexList) {
-                        curFileItem = itemForIndex(index);
-                        if (!curFileItem.isFile()) {
-                            /* We want
-                            *  to make sure that the selected item
-                            *  is only a folder. If we did not have this check, it would be possible to use
-                            *  the right arrow to open a file when in the column view */
-                            emit itemTriggered(curFileItem);
-                        }
-                    }
-                }
-            } else {
-                //Else it is Return or Enter keypress, so it is okay to perform the action of triggering, on files also.
-                foreach(const QModelIndex& index, indexList) {
-                    emit itemTriggered(itemForIndex(index));
-                }
-            }
+    const bool trigger = currentIndex.isValid()
+                         && ((event->key() == Qt::Key_Return)
+                            || (event->key() == Qt::Key_Enter))
+                         && !selModel->selectedIndexes().isEmpty();
+    if (trigger) {
+        const QModelIndexList indexList = selModel->selectedIndexes();
+        foreach (const QModelIndex& index, indexList) {
+            emit itemTriggered(itemForIndex(index));
         }
     }
 }
@@ -182,6 +201,11 @@ void DolphinController::emitHideToolTip()
     emit hideToolTip();
 }
 
+void DolphinController::emitItemTriggered(const KFileItem& item)
+{
+    emit itemTriggered(item);
+}
+
 KFileItem DolphinController::itemForIndex(const QModelIndex& index) const
 {
     Q_ASSERT(m_itemView != 0);
@@ -231,6 +255,11 @@ void DolphinController::emitViewportEntered()
     emit viewportEntered();
 }
 
+void DolphinController::emitSelectionChanged()
+{
+    emit selectionChanged();
+}
+
 void DolphinController::updateMouseButtonState()
 {
     m_mouseButtons = QApplication::mouseButtons();