]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphincontroller.h
Restore the "Edit->Selection" menu from Konqueror 3 for file
[dolphin.git] / src / dolphincontroller.h
index 6425816a8b2e8e6fdada4597d3072b6e26716275..8aebdcac47338396b22b57132d0e36b4db6d18b1 100644 (file)
 #include <QtCore/QObject>
 #include <libdolphin_export.h>
 
+class QAbstractItemView;
 class DolphinView;
 class KUrl;
-class QBrush;
 class QPoint;
-class QRect;
-class QWidget;
 
 // TODO: get rid of all the state duplications in the controller and allow read access
 // to the Dolphin view for all view implementations
@@ -40,13 +38,15 @@ class QWidget;
  *        implementations.
  *
  * The abstract Dolphin view (see DolphinView) represents the parent of the controller.
+ * The lifetime of the controller is equal to the lifetime of the Dolphin view.
  * The controller is passed to the current view implementation
  * (see DolphinIconsView, DolphinDetailsView and DolphinColumnView)
- * by passing it in the constructor:
+ * by passing it in the constructor and informing the controller about the change
+ * of the view implementation:
  *
  * \code
- * DolphinController* controller = new DolphinController(dolphinView);
  * QAbstractItemView* view = new DolphinIconsView(parent, controller);
+ * controller->setItemView(view);
  * \endcode
  *
  * The communication of the view implementations to the abstract view is done by:
@@ -56,20 +56,23 @@ class QWidget;
  * - indicateDroppedUrls()
  * - indicateSortingChange()
  * - indicateSortOrderChanged()
- * - setZoomInPossible()
- * - setZoomOutPossible()
+ * - indicateSortFoldersFirstChanged()
  * - triggerItem()
+ * - requestTab()
+ * - handleKeyPressEvent()
  * - emitItemEntered()
  * - emitViewportEntered()
+ * - emitSelectionChanged()
+ * - replaceUrlByClipboard()
+ * - hideToolTip()
+ * - setVersionControlActions()
  *
  * The communication of the abstract view to the view implementations is done by:
  * - setUrl()
- * - setShowHiddenFiles()
- * - setShowPreview()
- * - setAdditionalInfoCount()
  * - indicateActivationChange()
- * - triggerZoomIn()
- * - triggerZoomOut()
+ * - setNameFilter()
+ * - setZoomLevel()
+ * - versionControlActions()
  */
 class LIBDOLPHINPRIVATE_EXPORT DolphinController : public QObject
 {
@@ -80,7 +83,7 @@ public:
     virtual ~DolphinController();
 
     /**
-     * Allows read access for the the view implementation to the abstract
+     * Allows read access for the view implementation to the abstract
      * Dolphin view.
      */
     const DolphinView* dolphinView() const;
@@ -94,6 +97,21 @@ public:
     void setUrl(const KUrl& url);
     const KUrl& url() const;
 
+    /**
+     * Sets the URL to \a url and does nothing else. Called when
+     * a redirection happens.
+     */
+    void redirectToUrl(const KUrl& url);
+
+    /**
+     * Changes the current item view where the controller is working. This
+     * is only necessary for views like the tree view, where internally
+     * several QAbstractItemView instances are used.
+     */
+    void setItemView(QAbstractItemView* view);
+
+    QAbstractItemView* itemView() const;
+
     /**
      * Allows a view implementation to request an URL change to \a url.
      * The signal requestUrlChange() is emitted and the abstract Dolphin view
@@ -109,9 +127,11 @@ public:
      * should be invoked by the view implementation when a context
      * menu should be opened. The abstract Dolphin view itself
      * takes care itself to get the selected items depending from
-     * \a pos.
+     * \a pos. It is possible to define a custom list of actions for
+     * the context menu by \a customActions.
      */
-    void triggerContextMenuRequest(const QPoint& pos);
+    void triggerContextMenuRequest(const QPoint& pos,
+                                   const QList<QAction*>& customActions = QList<QAction*>());
 
     /**
      * Requests an activation of the view and emits the signal
@@ -126,15 +146,13 @@ public:
      * Indicates that URLs are dropped above a destination. This method
      * should be invoked by the view implementation. The abstract Dolphin view
      * will start the corresponding action (copy, move, link).
-     * @param urls      URLs that are dropped above a destination.
+     * @param destItem  Item of the destination (can be null, see KFileItem::isNull()).
      * @param destPath  Path of the destination.
-     * @param destItem  Destination item (can be null, see KFileItem::isNull()).
-     * @param source    Pointer to the view implementation which invoked this method.
+     * @param event     Drop event
      */
-    void indicateDroppedUrls(const KUrl::List& urls,
+    void indicateDroppedUrls(const KFileItem& destItem,
                              const KUrl& destPath,
-                             const KFileItem& destItem,
-                             QWidget* source);
+                             QDropEvent* event);
 
     /**
      * Informs the abstract Dolphin view about a sorting change done inside
@@ -152,6 +170,15 @@ public:
      */
     void indicateSortOrderChange(Qt::SortOrder order);
 
+    /**
+     * Informs the abstract Dolphin view about a change between separate sorting
+     * (with folders first) and mixed sorting of files and folders done inside
+     * the view implementation. This method should be invoked by the view
+     * implementation (e. g. the details view uses this method in combination
+     * with the details header).
+     */
+    void indicateSortFoldersFirstChange(bool foldersFirst);
+
     /**
      * Informs the abstract Dolphin view about an additional information change
      * done inside the view implementation. This method should be invoked by the
@@ -161,87 +188,117 @@ public:
     void indicateAdditionalInfoChange(const KFileItemDelegate::InformationList& info);
 
     /**
-     * Informs the view implementation about a change of the show hidden files
-     * state and is invoked by the abstract Dolphin view.
-     * The signal showHiddenFilesChanged() is emitted.
+     * Informs the view implementation about a change of the activation
+     * state and is invoked by the abstract Dolphin view. The signal
+     * activationChanged() is emitted.
      */
-    void setShowHiddenFiles(bool show);
-    bool showHiddenFiles() const;
+    void indicateActivationChange(bool active);
 
     /**
-     * Informs the view implementation about a change of the show preview
-     * state and is invoked by the abstract Dolphin view.
-     * The signal showPreviewChanged() is emitted.
+     * Sets the zoom level to \a level and emits the signal zoomLevelChanged().
+     * It must be assured that the used level is inside the range
+     * DolphinController::zoomLevelMinimum() and
+     * DolphinController::zoomLevelMaximum().
+     * Is invoked by the abstract Dolphin view.
      */
-    void setShowPreview(bool show);
-    bool showPreview() const;
+    void setZoomLevel(int level);
+    int zoomLevel() const;
 
     /**
-     * Informs the view implementation about a change of the number of
-     * additional informations and is invoked by the abstract Dolphin view.
-     * The signal additionalInfoCountChanged() is emitted.
+     * Sets the available version control actions. Is called by the view
+     * implementation as soon as the controller has send the signal
+     * requestVersionControlActions().
      */
-    //void setAdditionalInfoCount(int count);
-    //bool additionalInfoCount() const;
+    void setVersionControlActions(QList<QAction*> actions);
 
     /**
-     * Informs the view implementation about a change of the activation
-     * state and is invoked by the abstract Dolphin view. The signal
-     * activationChanged() is emitted.
+     * Returns the version control actions that are provided for the items \p items.
+     * Is called by the abstract Dolphin view to show the version control actions
+     * inside the context menu.
      */
-    void indicateActivationChange(bool active);
+    QList<QAction*> versionControlActions(const KFileItemList& items);
 
     /**
-     * Tells the view implementation to zoom in by emitting the signal zoomIn()
+     * Sets the name filter to \a and emits the signal nameFilterChanged().
+     */
+    void setNameFilter(const QString& nameFilter);
+    QString nameFilter() const;
+
+    /**
+     * Tells the view implementation to zoom out by emitting the signal zoomOut()
      * and is invoked by the abstract Dolphin view.
      */
-    void triggerZoomIn();
+    void triggerZoomOut();
 
     /**
-     * Is invoked by the view implementation to indicate whether a zooming in
-     * is possible. The abstract Dolphin view updates the corresponding menu
-     * action depending on this state.
+     * Should be invoked in each view implementation whenever a key has been
+     * pressed. If the selection model of \a view is not empty and
+     * the return key has been pressed, the selected items will get triggered.
      */
-    void setZoomInPossible(bool possible);
-    bool isZoomInPossible() const;
+    void handleKeyPressEvent(QKeyEvent* event);
 
     /**
-     * Tells the view implementation to zoom out by emitting the signal zoomOut()
-     * and is invoked by the abstract Dolphin view.
+     * Replaces the URL of the abstract Dolphin view  with the content
+     * of the clipboard as URL. If the clipboard contains no text,
+     * nothing will be done.
      */
-    void triggerZoomOut();
+    void replaceUrlByClipboard();
+
+    /** Emits the signal hideToolTip(). */
+    void emitHideToolTip();
 
     /**
-     * Is invoked by the view implementation to indicate whether a zooming out
-     * is possible. The abstract Dolphin view updates the corresponding menu
-     * action depending on this state.
+     * Emits the signal itemTriggered() for the item \a item.
+     * The method can be used by the view implementations to
+     * trigger an item directly without mouse interaction.
+     * If the item triggering is done by the mouse, it is recommended
+     * to use QAbstractItemView::triggerItem(), as this will check
+     * the used mouse buttons to execute the correct action.
      */
-    void setZoomOutPossible(bool possible);
-    bool isZoomOutPossible() const;
+    void emitItemTriggered(const KFileItem& item);
 
-    // TODO: remove this method when the issue #160611 is solved in Qt 4.4
-    static void drawHoverIndication(QWidget* widget,
-                                    const QRect& bounds,
-                                    const QBrush& brush);
+    /**
+     * Returns the file item for the proxy index \a index of the view \a view.
+     */
+    KFileItem itemForIndex(const QModelIndex& index) const;
 
 public slots:
     /**
-     * Emits the signal itemTriggered(). The method should be invoked by the
-     * controller parent whenever the user has triggered an item. */
-    void triggerItem(const KFileItem& item);
+     * Emits the signal itemTriggered() if the file item for the index \a index
+     * is not null and the left mouse button has been pressed. If the item is
+     * null, the signal itemEntered() is emitted.
+     * The method should be invoked by the view implementations whenever the
+     * user has triggered an item with the mouse (see
+     * QAbstractItemView::clicked() or QAbstractItemView::doubleClicked()).
+     */
+    void triggerItem(const QModelIndex& index);
+
+    /**
+     * Emits the signal tabRequested(), if the file item for the index \a index
+     * represents a directory and when the middle mouse button has been pressed.
+     * The method should be invoked by the view implementation.
+     */
+    void requestTab(const QModelIndex& index);
 
     /**
-     * Emits the signal itemEntered(). The method should be invoked by
-     * the controller parent whenever the mouse cursor is above an item.
+     * Emits the signal itemEntered() if the file item for the index \a index
+     * is not null. The method should be invoked by the view implementation
+     * whenever the mouse cursor is above an item.
      */
-    void emitItemEntered(const KFileItem& item);
+    void emitItemEntered(const QModelIndex& index);
 
     /**
      * Emits the signal viewportEntered(). The method should be invoked by
-     * the controller parent whenever the mouse cursor is above the viewport.
+     * the view implementation whenever the mouse cursor is above the viewport.
      */
     void emitViewportEntered();
 
+    /**
+     * Emits the signal selectionChanged(). The method should be invoked by
+     * the view implementation whenever the selection has been changed.
+     */
+    void emitSelectionChanged();
+
 signals:
     /**
      * Is emitted if the URL for the Dolphin controller has been changed
@@ -258,12 +315,14 @@ signals:
     /**
      * Is emitted if a context menu should be opened (see triggerContextMenuRequest()).
      * The abstract Dolphin view connects to this signal and will open the context menu.
-     * @param pos       Position relative to the view widget where the
-     *                  context menu should be opened. It is recommended
-     *                  to get the corresponding model index from
-     *                  this position.
+     * @param pos           Position relative to the view widget where the
+     *                      context menu should be opened. It is recommended
+     *                      to get the corresponding model index from
+     *                      this position.
+     * @param customActions List of actions that is added to the context menu when
+     *                      the menu is opened above the viewport.
      */
-    void requestContextMenu(const QPoint& pos);
+    void requestContextMenu(const QPoint& pos, QList<QAction*> customActions);
 
     /**
      * Is emitted if the view has been activated by e. g. a mouse click.
@@ -273,16 +332,14 @@ signals:
     void activated();
 
     /**
-     * Is emitted if the URLs \a urls have been dropped to the destination
+     * Is emitted if URLs have been dropped to the destination
      * path \a destPath. If the URLs have been dropped above an item of
      * the destination path, the item is indicated by \a destItem
-     * (can be null, see KFileItem::isNull()). \a source indicates
-     * the widget where the dragging has been started from.
+     * (can be null, see KFileItem::isNull()).
      */
-    void urlsDropped(const KUrl::List& urls,
+    void urlsDropped(const KFileItem& destItem,
                      const KUrl& destPath,
-                     const KFileItem& destItem,
-                     QWidget* source);
+                     QDropEvent* event);
 
     /**
      * Is emitted if the sorting has been changed to \a sorting by
@@ -301,35 +358,19 @@ signals:
     void sortOrderChanged(Qt::SortOrder order);
 
     /**
-     * Is emitted if the additional info has been changed to \a info
-     * by the view implementation. The abstract Dolphin view connects
+     * Is emitted if 'sort folders first' has been changed to \a foldersFirst
+     * by the view implementation (see indicateSortOrderChanged().
+     * The abstract Dolphin view connects
      * to this signal to update its menu actions.
      */
-    void additionalInfoChanged(const KFileItemDelegate::InformationList& info);
-
-    /**
-     * Is emitted if the state for showing hidden files has been
-     * changed to \a show by the abstract Dolphin view. The view
-     * implementation might connect to this signal if custom
-     * updates are required in this case.
-     */
-    void showHiddenFilesChanged(bool show);
-
-    /**
-     * Is emitted if the state for showing previews has been
-     * changed to \a show by the abstract Dolphin view.
-     * The view implementation might connect to this signal if custom
-     * updates are required in this case.
-     */
-    void showPreviewChanged(bool show);
+    void sortFoldersFirstChanged(bool foldersFirst);
 
     /**
-     * Is emitted if the number of additional informations has been
-     * changed to \a count by the abstract Dolphin view.
-     * The view implementation might connect to this signal if custom
-     * updates are required in this case.
+     * Is emitted if the additional info has been changed to \a info
+     * by the view implementation. The abstract Dolphin view connects
+     * to this signal to update its menu actions.
      */
-    //void additionalInfoCountChanged(int count);
+    void additionalInfoChanged(const KFileItemDelegate::InformationList& info);
 
     /**
      * Is emitted if the activation state has been changed to \a active
@@ -354,33 +395,65 @@ signals:
      */
     void itemEntered(const KFileItem& item);
 
+    /**
+     * Is emitted if a new tab should be opened for the URL \a url.
+     */
+    void tabRequested(const KUrl& url);
+
     /**
      * Is emitted if the mouse cursor has entered
-     * the viewport (see emitViewportEntered().
+     * the viewport (see emitViewportEntered()).
      * The abstract Dolphin view connects to this signal.
      */
     void viewportEntered();
 
     /**
-     * Is emitted if the view should zoom in. The view implementation
-     * must connect to this signal if it supports zooming.
+     * Is emitted whenever the selection of the view implementation
+     * has been changed (see emitSelectionChanged()). The abstract
+     * Dolphin view connects to this signal.
      */
-    void zoomIn();
+    void selectionChanged();
 
     /**
-     * Is emitted if the view should zoom out. The view implementation
+     * Is emitted if the view should respect the name filter \a nameFilter. The view
+     * implementation must connect to this signal if it supports name filters.
+     */
+    void nameFilterChanged(const QString& nameFilter);
+
+    /**
+     * Is emitted if the view should change the zoom to \a level. The view implementation
      * must connect to this signal if it supports zooming.
      */
-    void zoomOut();
+    void zoomLevelChanged(int level);
+
+    /**
+     * Is emitted if the abstract view should hide an open tooltip.
+     */
+    void hideToolTip();
+
+    /**
+     * Is emitted if pending previews should be canceled (e. g. because of an URL change).
+     */
+    void cancelPreviews();
+
+    /**
+     * Requests the view implementation to invoke DolphinController::setVersionControlActions(),
+     * so that they can be returned with DolphinController::versionControlActions() for
+     * the abstract Dolphin view.
+     */
+    void requestVersionControlActions(const KFileItemList& items);
+
+private slots:
+    void updateMouseButtonState();
 
 private:
-    bool m_showHiddenFiles;
-    bool m_showPreview;
-    bool m_zoomInPossible;
-    bool m_zoomOutPossible;
-    //int m_additionalInfoCount;
+    int m_zoomLevel;
+    QString m_nameFilter;
+    static Qt::MouseButtons m_mouseButtons; // TODO: this is a workaround until  Qt-issue 176832 has been fixed
     KUrl m_url;
     DolphinView* m_dolphinView;
+    QAbstractItemView* m_itemView;
+    QList<QAction*> m_versionControlActions;
 };
 
 inline const DolphinView* DolphinController::dolphinView() const
@@ -393,39 +466,14 @@ inline const KUrl& DolphinController::url() const
     return m_url;
 }
 
-inline bool DolphinController::showHiddenFiles() const
-{
-    return m_showHiddenFiles;
-}
-
-inline bool DolphinController::showPreview() const
-{
-    return m_showPreview;
-}
-
-/*inline bool DolphinController::additionalInfoCount() const
-{
-    return m_additionalInfoCount;
-}*/
-
-inline void DolphinController::setZoomInPossible(bool possible)
-{
-    m_zoomInPossible = possible;
-}
-
-inline bool DolphinController::isZoomInPossible() const
-{
-    return m_zoomInPossible;
-}
-
-inline void DolphinController::setZoomOutPossible(bool possible)
+inline QAbstractItemView* DolphinController::itemView() const
 {
-    m_zoomOutPossible = possible;
+    return m_itemView;
 }
 
-inline bool DolphinController::isZoomOutPossible() const
+inline int DolphinController::zoomLevel() const
 {
-    return m_zoomOutPossible;
+    return m_zoomLevel;
 }
 
 #endif