]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinview.h
Remember and restore position of viewport when reloading or going back in history...
[dolphin.git] / src / dolphinview.h
index cffa52880d5722095c716f6fac543bca5a0c9d78..ebca53e99ae400da8696fdcb0ad43e068bfc3eb6 100644 (file)
  ***************************************************************************/
 
 
-#ifndef _DOLPHINVIEW_H_
-#define _DOLPHINVIEW_H_
+#ifndef DOLPHINVIEW_H
+#define DOLPHINVIEW_H
 
 #include <kparts/part.h>
 #include <kfileitem.h>
-#include <kfileiconview.h>
+#include <kfileitemdelegate.h>
 #include <kio/job.h>
 
-#include <urlnavigator.h>
-
-#include <QDropEvent>
+#include <QBoxLayout>
+#include <QKeyEvent>
 #include <QLinkedList>
 #include <QListView>
-#include <QMouseEvent>
-#include <QVBoxLayout>
 #include <QWidget>
 
 class DolphinController;
-class FilterBar;
+class KDirLister;
+class KFileItemDelegate;
 class KUrl;
 class KDirModel;
-class UrlNavigator;
+class DolphinColumnView;
 class DolphinDetailsView;
-class DolphinDirLister;
 class DolphinIconsView;
 class DolphinMainWindow;
 class DolphinSortFilterProxyModel;
-class DolphinStatusBar;
 class QModelIndex;
-class QPainter;
-class QTimer;
 class ViewProperties;
 
 /**
- * @short Represents a view for the directory content
- *        including the navigation bar, filter bar and status bar.
+ * @short Represents a view for the directory content.
  *
- * View modes for icons and details are supported. Currently
- * Dolphin allows to have up to two views inside the main window.
+ * View modes for icons, details and columns are supported. It's
+ * possible to adjust:
+ * - sort order
+ * - sort type
+ * - show hidden files
+ * - show previews
  *
  * @see DolphinIconsView
  * @see DolphinDetailsView
- * @see UrlNavigator
- * @see DolphinStatusBar
+ * @see DolphinColumnView
  */
 class DolphinView : public QWidget
 {
     Q_OBJECT
 
 public:
-       /**
-     * Defines the view mode for a directory. The view mode
-     * can be defined when constructing a DolphinView. The
-     * view mode is automatically updated if the directory itself
-     * defines a view mode (see class ViewProperties for details).
-     */
+    /**
+        * Defines the view mode for a directory. The view mode
+        * can be defined when constructing a DolphinView. The
+        * view mode is automatically updated if the directory itself
+        * defines a view mode (see class ViewProperties for details).
+        */
     enum Mode
     {
         /**
@@ -88,7 +84,12 @@ public:
          * for date, group and permissions.
          */
         DetailsView = 1,
-        MaxModeEnum = DetailsView
+
+        /**
+         * Each folder is shown in a separate column.
+         */
+        ColumnView = 2,
+        MaxModeEnum = ColumnView
     };
 
     /** Defines the sort order for the items of a directory. */
@@ -100,31 +101,54 @@ public:
         SortByPermissions,
         SortByOwner,
         SortByGroup,
-        MaxSortEnum = SortByGroup
+        SortByType,
+        MaxSortEnum = SortByType
     };
 
-    DolphinView(DolphinMainWindow* mainwindow,
-                QWidget *parent,
+    /**
+     * @param parent          Parent widget of the view.
+     * @param url             Specifies the content which should be shown.
+     * @param dirLister       Used directory lister. The lister is not owned
+     *                        by the view and won't get deleted.
+     * @param dirModel        Used directory model. The model is not owned
+     *                        by the view and won't get deleted.
+     * @param proxyModel      Used proxy model which specifies the sorting. The
+     *                        model is not owned by the view and won't get
+     *                        deleted.
+     * @param mode            Used display mode (IconsView, DetailsView or ColumnsView).
+     * @param showHiddenFiles If true, hidden files will be shown in the view.
+     */
+    DolphinView(QWidget* parent,
                 const KUrl& url,
-                Mode mode = IconsView,
-                bool showHiddenFiles = false);
+                KDirLister* dirLister,
+                KDirModel* dirModel,
+                DolphinSortFilterProxyModel* proxyModel,
+                Mode mode);
 
     virtual ~DolphinView();
 
     /**
-     * Sets the current active URL.
-     * The signals UrlNavigator::urlChanged() and UrlNavigator::historyChanged()
-     * are emitted.
+     * Returns the current active URL, where all actions are applied.
+     * The URL navigator is synchronized with this URL.
      */
-    void setUrl(const KUrl& url);
-
-    /** Returns the current active URL. */
     const KUrl& url() const;
 
     /**
-     * Returns true if the view is active and hence all actions are
-     * applied to this view.
+     * Returns the root URL of the view, which is defined as the first
+     * visible path of DolphinView::url(). Usually the root URL is
+     * equal to DolphinView::url(), but in the case of the column view
+     * when 2 columns are shown, the root URL might be:
+     * /home/peter/Documents
+     * and DolphinView::url() might return
+     * /home/peter/Documents/Music/
      */
+    KUrl rootUrl() const;
+
+    /**
+     * If \a active is true, the view will marked as active. The active
+     * view is defined as view where all actions are applied to.
+     */
+    void setActive(bool active);
     bool isActive() const;
 
     /**
@@ -157,10 +181,22 @@ public:
     bool showHiddenFiles() const;
 
     /**
-     * Triggers the renaming of the currently selected items, where
-     * the user must input a new name for the items.
+     * Summarizes all sorted items by their category \a categorized
+     * is true.
+     * If the view properties should be remembered for each directory
+     * (GeneralSettings::globalViewProps() returns false), then the
+     * categorized sorting setting will be be stored automatically.
+     */
+    void setCategorizedSorting(bool categorized);
+    bool categorizedSorting() const;
+
+    /**
+     * Returns true, if the categorized sorting is supported by the current
+     * used mode (see DolphinView::setMode()). Currently only DolphinView::IconsView
+     * supports categorizations. To check whether the categorized
+     * sorting is set, use DolphinView::categorizedSorting().
      */
-    void renameSelectedItems();
+    bool supportsCategorizedSorting() const;
 
     /**
      * Selects all items.
@@ -175,53 +211,11 @@ public:
      */
     void invertSelection();
 
-    /**
-     * Goes back one step in the URL history. The signals
-     * UrlNavigator::urlChanged() and UrlNavigator::historyChanged()
-     * are submitted.
-     */
-    void goBack();
-
-    /**
-     * Goes forward one step in the Url history. The signals
-     * UrlNavigator::urlChanged() and UrlNavigator::historyChanged()
-     * are submitted.
-     */
-    void goForward();
-
-    /**
-     * Goes up one step of the Url path. The signals
-     * UrlNavigator::urlChanged() and UrlNavigator::historyChanged()
-     * are submitted.
-     */
-    void goUp();
-
-    /**
-     * Goes to the home URL. The signals UrlNavigator::urlChanged()
-     * and UrlNavigator::historyChanged() are submitted.
-     */
-    void goHome();
-
-    /**
-     * Sets the URL of the navigation bar to an editable state
-     * if \a editable is true. If \a editable is false, each part of
-     * the location is presented by a button for a fast navigation.
-     */
-    void setUrlEditable(bool editable);
-
-    /**
-     * Returns the complete URL history. The index 0 indicates the oldest
-     * history element.
-     * @param index     Output parameter which indicates the current
-     *                  index of the location.
-     */
-    const QLinkedList<UrlNavigator::HistoryElem> urlHistory(int& index) const;
-
-    /**
-     * Returns true, if at least one item is selected.
-     */
+    /** Returns true, if at least one item is selected. */
     bool hasSelection() const;
 
+    void clearSelection();
+
     /**
      * Returns the selected items. The list is empty if no item has been
      * selected.
@@ -242,34 +236,14 @@ public:
     KFileItem* fileItem(const QModelIndex index) const;
 
     /**
-     * Renames the filename of the source URL by the new file name.
-     * If the new file name already exists, a dialog is opened which
-     * asks the user to enter a new name.
-     */
-    void rename(const KUrl& source, const QString& newName);
-
-    /** Returns the status bar of the view. */
-    DolphinStatusBar* statusBar() const;
-
-    /**
-     * Returns the x-position of the view content.
-     * The content of the view might be larger than the visible area
+     * Sets the upper left position of the view content
+     * to (x,y). The content of the view might be larger than the visible area
      * and hence a scrolling must be done.
      */
-    int contentsX() const;
+    void setContentsPosition(int x, int y);
 
-    /**
-     * Returns the y-position of the view content.
-     * The content of the view might be larger than the visible area
-     * and hence a scrolling must be done.
-     */
-    int contentsY() const;
-
-    /**
-     * Returns true, if the URL shown by the navigation bar is editable.
-     * @see UrlNavigator
-     */
-    bool isUrlEditable() const;
+    /** Returns the upper left position of the view content. */
+    QPoint contentsPosition() const;
 
     /** Increases the size of the current set view mode. */
     void zoomIn();
@@ -301,52 +275,43 @@ public:
     /** Returns the current used sort order (Qt::Ascending or Qt::Descending). */
     Qt::SortOrder sortOrder() const;
 
-    /** Refreshs the view settings by reading out the stored settings. */
-    void refreshSettings();
+    /** Sets the additional information which should be shown for the items. */
+    void setAdditionalInfo(KFileItemDelegate::AdditionalInformation info);
 
-    /** Returns the UrlNavigator of the view for read access. */
-    const UrlNavigator* urlNavigator() const { return m_urlNavigator; }
+    /** Returns the additional information which should be shown for the items. */
+    KFileItemDelegate::AdditionalInformation additionalInfo() const;
 
-    /**
-     * Triggers to request user information for the item given
-     * by the URL \a url. The signal requestItemInfo is emitted,
-     * which provides a way for widgets to get an indication to update
-     * the item information.
-     */
-    void emitRequestItemInfo(const KUrl& url);
-
-    /** Returns true, if the filter bar is visible. */
-    bool isFilterBarVisible() const;
+    /** Reloads the current directory. */
+    void reload();
 
     /**
-     * Return the DolphinMainWindow this View belongs to. It is guranteed
-     * that we have one.
+     * Refreshs the view to get synchronized with the (updated) Dolphin settings.
+     * This method only needs to get invoked if the view settings for the Icons View,
+     * Details View or Columns View have been changed.
      */
-    DolphinMainWindow* mainWindow() const ;
-
-    /** Reloads the current directory. */
-    void reload();
+    void refresh();
 
 public slots:
     /**
-     * Popups the filter bar above the status bar if \a show is true.
+     * Changes the directory to \a url. If the current directory is equal to
+     * \a url, nothing will be done (use DolphinView::reload() instead).
      */
-    void showFilterBar(bool show);
+    void setUrl(const KUrl& url);
 
     /**
-     * Updates the number of items (= number of files + number of
-     * directories) in the statusbar. If files are selected, the number
-     * of selected files and the sum of the filesize is shown.
+     * Request of a selection change. The view will do its best to accommodate
+     * the request, but it is not guaranteed that all items in \a selection
+     * will actually get selected. The view will e.g. not select items which
+     * are not in the currently displayed folder.
      */
-    void updateStatusBar();
+    void changeSelection(const KFileItemList& selection);
 
+signals:
     /**
-     * Requests the main window to set this view as active view, which
-     * means that all actions are applied to this view.
+     * Is emitted if the view has been activated by e. g. a mouse click.
      */
-    void requestActivation();
+    void activated();
 
-signals:
     /** Is emitted if URL of the view has been changed to \a url. */
     void urlChanged(const KUrl& url);
 
@@ -362,12 +327,18 @@ signals:
     /** Is emitted if the 'show hidden files' property has been changed. */
     void showHiddenFilesChanged();
 
+    /** Is emitted if the 'categorized sorting' property has been changed. */
+    void categorizedSortingChanged();
+
     /** Is emitted if the sorting by name, size or date has been changed. */
     void sortingChanged(DolphinView::Sorting sorting);
 
     /** Is emitted if the sort order (ascending or descending) has been changed. */
     void sortOrderChanged(Qt::SortOrder order);
 
+    /** Is emitted if the additional information for an item has been changed. */
+    void additionalInfoChanged(KFileItemDelegate::AdditionalInformation info);
+
     /**
      * Is emitted if information of an item is requested to be shown e. g. in the sidebar.
      * It the URL is empty, no item information request is pending.
@@ -378,52 +349,69 @@ signals:
     void contentsMoved(int x, int y);
 
     /**
-     * Is emitted whenever the selection has been changed. The current selection can
-     * be retrieved by mainWindow()->activeView()->selectedItems() or by
-     * mainWindow()->activeView()->selectedUrls().
+     * Is emitted whenever the selection has been changed.
      */
-    void selectionChanged();
+    void selectionChanged(const KFileItemList& selection);
 
     /**
-     * Is emitted whenever the filter bar has been turned show or hidden.
+     * Is emitted if a context menu is requested for the item \a item,
+     * which is part of \a url. If the item is 0, the context menu
+     * for the URL should be shown.
      */
-    void showFilterBarChanged(bool shown);
+    void requestContextMenu(KFileItem* item, const KUrl& url);
+
+    /**
+     * Is emitted if the URLs \a are dropped to the destination URL
+     * \a destination. No operation is done within the DolphinView, the
+     * receiver of the signal has to take care about the corresponding
+     * operation.
+     */
+    void urlsDropped(const KUrl::List& urls, const KUrl& destination);
+
+    /**
+     * Is emitted if an information message with the content \a msg
+     * should be shown.
+     */
+    void infoMessage(const QString& msg);
+
+    /**
+     * Is emitted if an error message with the content \a msg
+     * should be shown.
+     */
+    void errorMessage(const QString& msg);
 
 protected:
     /** @see QWidget::mouseReleaseEvent */
     virtual void mouseReleaseEvent(QMouseEvent* event);
 
 private slots:
-    void loadDirectory(const KUrl& kurl);
-    void triggerItem(const QModelIndex& index);
-    void updateProgress(int percent);
-
     /**
-     * Updates the number of items (= number of directories + number of files)
-     * and shows this information in the statusbar.
+     * Marks the view as active (DolphinView:isActive() will return true)
+     * and emits the 'activated' signal if it is not already active.
      */
-    void updateItemCount();
+    void activate();
 
     /**
-     * Restores the x- and y-position of the contents if the
-     * current view is part of the history.
+     * If the item specified by \a index is a directory, then this
+     * directory will be loaded. If the  item is a file, the corresponding
+     * application will get started.
      */
-    void restoreContentsPos();
-
-    /** Shows the information \a msg inside the statusbar. */
-    void showInfoMessage(const QString& msg);
-
-    /** Shows the error message \a msg inside the statusbar. */
-    void showErrorMessage(const QString& msg);
+    void triggerItem(const QModelIndex& index);
 
-    void emitSelectionChangedSignal();
-    void closeFilterBar();
+    /**
+     * Generates a preview image for each file item in \a items.
+     * The current preview settings (maximum size, 'Show Preview' menu)
+     * are respected.
+     */
+    void generatePreviews(const KFileItemList& items);
 
     /**
-     * Filters the currently shown items by \a nameFilter. All items
-     * which contain the given filter string will be shown.
+     * Replaces the icon of the item \a item by the preview pixmap
+     * \a pixmap.
      */
-    void changeNameFilter(const QString& nameFilter);
+    void showPreview(const KFileItem& item, const QPixmap& pixmap);
+
+    void emitSelectionChangedSignal();
 
     /**
      * Opens the context menu on position \a pos. The position
@@ -433,12 +421,12 @@ private slots:
     void openContextMenu(const QPoint& pos);
 
     /**
-     * Drops the URLs \a urls at the position \a pos.
-     * The position is used to check whether the dropping
-     * is done above an item or above the viewport.
+     * Drops the URLs \a urls to the index \a index. \a source
+     * indicates the widget where the dragging has been started from.
      */
     void dropUrls(const KUrl::List& urls,
-                  const QPoint& pos);
+                  const QModelIndex& index,
+                  QWidget* source);
 
     /**
      * Drops the URLs \a urls at the
@@ -464,29 +452,28 @@ private slots:
      */
     void emitContentsMoved();
 
-    /**
-     * Updates the activation state of the view by checking whether
-     * the currently active view is this view.
-     */
-    void updateActivationState();
-
-private:
-    void startDirLister(const KUrl& url, bool reload = false);
+    /** Applies an item effect to all cut items of the clipboard. */
+    void updateCutItems();
 
     /**
-     * Returns the default text of the status bar, if no item is
-     * selected.
+     * Updates the status bar to show hover information for the
+     * item with the index \a index. If currently other items are selected,
+     * no hover information is shown.
+     * @see DolphinView::clearHoverInformation()
      */
-    QString defaultStatusBarText() const;
+    void showHoverInformation(const QModelIndex& index);
 
     /**
-     * Returns the text for the status bar, if at least one item
-     * is selected.
+     * Clears the hover information shown in the status bar.
+     * @see DolphinView::showHoverInformation().
      */
-    QString selectionStatusBarText() const;
+    void clearHoverInformation();
+
+private:
+    void startDirLister(const KUrl& url, bool reload = false);
 
     /**
-     * Creates a new view representing the given view mode (DolphinView::viewMode()).
+     * Creates a new view representing the given view mode (DolphinView::mode()).
      * The current view will get deleted.
      */
     void createView();
@@ -503,28 +490,61 @@ private:
      */
     QAbstractItemView* itemView() const;
 
+    /**
+     * Returns true if the index is valid and represents
+     * the column KDirModel::Name.
+     */
+    bool isValidNameIndex(const QModelIndex& index) const;
+
+    /**
+     * Returns true, if the item \a item has been cut into
+     * the clipboard.
+     */
+    bool isCutItem(const KFileItem& item) const;
+
+    /** Applies an item effect to all cut items. */
+    void applyCutItemEffect();
+
+    /**
+     * Returns true, if the ColumnView is activated. As the column view
+     * requires some special handling for iterating through directories,
+     * this method has been introduced for convenience.
+     */
+    bool isColumnViewActive() const
+    {
+        return m_columnView != 0;
+    }
+
 private:
-    bool m_showProgress;
-    Mode m_mode;
+    /**
+     * Remembers the original pixmap for an item before
+     * the cut effect is applied.
+     */
+    struct CutItem
+    {
+        KUrl url;
+        QPixmap pixmap;
+    };
 
-    int m_iconSize;
-    int m_folderCount;
-    int m_fileCount;
+    bool m_active;
+    bool m_blockContentsMovedSignal;
+    bool m_initializeColumnView;
+    Mode m_mode;
 
     DolphinMainWindow* m_mainWindow;
     QVBoxLayout* m_topLayout;
-    UrlNavigator* m_urlNavigator;
 
     DolphinController* m_controller;
     DolphinIconsView* m_iconsView;
     DolphinDetailsView* m_detailsView;
-
-    FilterBar* m_filterBar;
-    DolphinStatusBar* m_statusBar;
+    DolphinColumnView* m_columnView;
+    KFileItemDelegate* m_fileItemDelegate;
 
     KDirModel* m_dirModel;
-    DolphinDirLister* m_dirLister;
+    KDirLister* m_dirLister;
     DolphinSortFilterProxyModel* m_proxyModel;
+
+    QList<CutItem> m_cutItemsCache;
 };
 
-#endif // _DOLPHINVIEW_H_
+#endif // DOLPHINVIEW_H