1 /***************************************************************************
2 * Copyright (C) 2007 by Peter Penz <peter.penz@gmx.at> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
21 #ifndef DOLPHINVIEWCONTAINER_H
22 #define DOLPHINVIEWCONTAINER_H
24 #include "dolphinview.h"
26 #include <kfileitem.h>
27 #include <kfileitemdelegate.h>
28 #include <kglobalsettings.h>
31 #include <kurlnavigator.h>
33 #include <QtGui/QKeyEvent>
34 #include <QtCore/QLinkedList>
35 #include <QtGui/QListView>
36 #include <QtGui/QBoxLayout>
37 #include <QtGui/QWidget>
43 class DolphinDirLister
;
44 class DolphinMainWindow
;
45 class DolphinSortFilterProxyModel
;
46 class DolphinStatusBar
;
49 * @short Represents a view for the directory content
50 * including the navigation bar, filter bar and status bar.
52 * View modes for icons, details and columns are supported. Currently
53 * Dolphin allows to have up to two views inside the main window.
58 * @see DolphinStatusBar
60 class DolphinViewContainer
: public QWidget
65 DolphinViewContainer(DolphinMainWindow
* mainwindow
,
69 virtual ~DolphinViewContainer();
72 * Sets the current active URL, where all actions are applied. The
73 * URL navigator is synchronized with this URL. The signals
74 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
76 * @see DolphinViewContainer::urlNavigator()
78 void setUrl(const KUrl
& url
);
81 * Returns the current active URL, where all actions are applied.
82 * The URL navigator is synchronized with this URL.
84 const KUrl
& url() const;
87 * If \a active is true, the view container will marked as active. The active
88 * view container is defined as view where all actions are applied to.
90 void setActive(bool active
);
91 bool isActive() const;
93 const DolphinStatusBar
* statusBar() const;
94 DolphinStatusBar
* statusBar();
97 * Returns true, if the URL shown by the navigation bar is editable.
100 bool isUrlEditable() const;
102 const KUrlNavigator
* urlNavigator() const;
103 KUrlNavigator
* urlNavigator();
105 const DolphinView
* view() const;
109 * Refreshes the view container to get synchronized with the (updated) Dolphin settings.
113 /** Returns true, if the filter bar is visible. */
114 bool isFilterBarVisible() const;
118 * Popups the filter bar above the status bar if \a show is true.
120 void showFilterBar(bool show
);
124 * Is emitted whenever the filter bar has changed its visibility state.
126 void showFilterBarChanged(bool shown
);
130 * Updates the number of items (= number of files + number of
131 * directories) in the statusbar. If files are selected, the number
132 * of selected files and the sum of the filesize is shown. The update
133 * is done asynchronously, as getting the sum of the
134 * filesizes can be an expensive operation.
136 void delayedStatusBarUpdate();
139 * Is invoked by DolphinViewContainer::delayedStatusBarUpdate() and
140 * updates the status bar synchronously.
142 void updateStatusBar();
144 void initializeProgress();
146 void updateProgress(int percent
);
149 * Assures that the viewport position is restored and updates the
150 * statusbar to reflect the current content.
152 void slotDirListerCompleted();
155 * Handles clicking on an item. If the item is a directory, the
156 * directory is opened in the view. If the item is a file, the file
157 * gets started by the corresponding application.
159 void slotItemTriggered(const KFileItem
& item
);
162 * Opens a the file \a url by opening the corresponding application.
163 * Is connected with the signal urlIsFile() from DolphinDirLister and will
164 * get invoked if the user manually has entered a file into the URL navigator.
166 void openFile(const KUrl
& url
);
169 * Shows the information for the item \a item inside the statusbar. If the
170 * item is null, the default statusbar information is shown.
172 void showItemInfo(const KFileItem
& item
);
174 /** Shows the information \a msg inside the statusbar. */
175 void showInfoMessage(const QString
& msg
);
177 /** Shows the error message \a msg inside the statusbar. */
178 void showErrorMessage(const QString
& msg
);
180 /** Shows the "operation completed" message \a msg inside the statusbar. */
181 void showOperationCompletedMessage(const QString
& msg
);
183 void closeFilterBar();
186 * Filters the currently shown items by \a nameFilter. All items
187 * which contain the given filter string will be shown.
189 void setNameFilter(const QString
& nameFilter
);
192 * Opens the context menu on the current mouse position.
193 * @item File item context. If item is null, the context menu
194 * should be applied to \a url.
195 * @url URL which contains \a item.
196 * @customActions Actions that should be added to the context menu,
197 * if the file item is null.
199 void openContextMenu(const KFileItem
& item
,
201 const QList
<QAction
*>& customActions
);
204 * Saves the position of the contents to the
205 * current history element.
207 void saveContentsPos(int x
, int y
);
210 * Restores the contents position of the view, if the view
211 * is part of the history.
213 void restoreContentsPos();
216 * Marks the view container as active
217 * (see DolphinViewContainer::setActive()).
222 * Restores the current view to show \a url and assures
223 * that the root URL of the view is respected.
225 void restoreView(const KUrl
& url
);
228 * Saves the root URL of the current URL \a url
229 * into the URL navigator.
231 void saveRootUrl(const KUrl
& url
);
234 * Is connected with the URL navigator and drops the URLs
235 * above the destination \a destination.
237 void dropUrls(const KUrl
& destination
, QDropEvent
* event
);
240 * Is invoked when a redirection is done and changes the
241 * URL of the URL navigator to \a newUrl without triggering
242 * a reloading of the directory.
244 void redirect(const KUrl
& oldUrl
, const KUrl
& newUrl
);
246 /** Requests the focus for the view \a m_view. */
250 * Saves the currently used URL completion mode of
253 void saveUrlCompletionMode(KGlobalSettings::Completion completion
);
255 void slotHistoryChanged();
258 bool m_isFolderWritable
;
260 DolphinMainWindow
* m_mainWindow
;
261 QVBoxLayout
* m_topLayout
;
262 KUrlNavigator
* m_urlNavigator
;
266 FilterBar
* m_filterBar
;
268 DolphinStatusBar
* m_statusBar
;
269 QTimer
* m_statusBarTimer
;
271 DolphinModel
* m_dolphinModel
;
272 DolphinDirLister
* m_dirLister
;
273 DolphinSortFilterProxyModel
* m_proxyModel
;
276 inline const DolphinStatusBar
* DolphinViewContainer::statusBar() const
281 inline DolphinStatusBar
* DolphinViewContainer::statusBar()
286 inline const KUrlNavigator
* DolphinViewContainer::urlNavigator() const
288 return m_urlNavigator
;
291 inline KUrlNavigator
* DolphinViewContainer::urlNavigator()
293 return m_urlNavigator
;
296 inline const DolphinView
* DolphinViewContainer::view() const
301 inline DolphinView
* DolphinViewContainer::view()
306 #endif // DOLPHINVIEWCONTAINER_H