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 DolphinSearchBox
;
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(const KUrl
& url
, QWidget
* parent
);
66 virtual ~DolphinViewContainer();
69 * Returns the current active URL, where all actions are applied.
70 * The URL navigator is synchronized with this URL.
75 * If \a active is true, the view container will marked as active. The active
76 * view container is defined as view where all actions are applied to.
78 void setActive(bool active
);
79 bool isActive() const;
81 const DolphinStatusBar
* statusBar() const;
82 DolphinStatusBar
* statusBar();
84 const KUrlNavigator
* urlNavigator() const;
85 KUrlNavigator
* urlNavigator();
87 const DolphinView
* view() const;
91 * Refreshes the view container to get synchronized with the (updated) Dolphin settings.
95 /** Returns true, if the filter bar is visible. */
96 bool isFilterBarVisible() const;
99 * Enables the search mode, if \p enabled is true. In the search mode the URL navigator
100 * will be hidden and replaced by a line editor that allows to enter a search term.
102 void setSearchModeEnabled(bool enabled
);
103 bool isSearchModeEnabled() const;
107 * Sets the current active URL, where all actions are applied. The
108 * URL navigator is synchronized with this URL. The signals
109 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
111 * @see DolphinViewContainer::urlNavigator()
113 void setUrl(const KUrl
& url
);
116 * Popups the filter bar above the status bar if \a show is true.
118 void showFilterBar(bool show
);
122 * Is emitted whenever the filter bar has changed its visibility state.
124 void showFilterBarChanged(bool shown
);
127 * Is emitted when the write state of the folder has been changed. The application
128 * should disable all actions like "Create New..." that depend on the write
131 void writeStateChanged(bool isFolderWritable
);
135 * Updates the number of items (= number of files + number of
136 * directories) in the statusbar. If files are selected, the number
137 * of selected files and the sum of the filesize is shown. The update
138 * is done asynchronously, as getting the sum of the
139 * filesizes can be an expensive operation.
141 void delayedStatusBarUpdate();
144 * Is invoked by DolphinViewContainer::delayedStatusBarUpdate() and
145 * updates the status bar synchronously.
147 void updateStatusBar();
149 void initializeProgress();
151 void updateProgress(int percent
);
154 * Assures that the viewport position is restored and updates the
155 * statusbar to reflect the current content.
157 void slotDirListerCompleted();
160 * Handles clicking on an item. If the item is a directory, the
161 * directory is opened in the view. If the item is a file, the file
162 * gets started by the corresponding application.
164 void slotItemTriggered(const KFileItem
& item
);
167 * Opens a the file \a url by opening the corresponding application.
168 * Is connected with the signal urlIsFile() from DolphinDirLister and will
169 * get invoked if the user manually has entered a file into the URL navigator.
171 void openFile(const KUrl
& url
);
174 * Shows the information for the item \a item inside the statusbar. If the
175 * item is null, the default statusbar information is shown.
177 void showItemInfo(const KFileItem
& item
);
179 /** Shows the information \a msg inside the statusbar. */
180 void showInfoMessage(const QString
& msg
);
182 /** Shows the error message \a msg inside the statusbar. */
183 void showErrorMessage(const QString
& msg
);
185 /** Shows the "operation completed" message \a msg inside the statusbar. */
186 void showOperationCompletedMessage(const QString
& msg
);
188 void closeFilterBar();
191 * Filters the currently shown items by \a nameFilter. All items
192 * which contain the given filter string will be shown.
194 void setNameFilter(const QString
& nameFilter
);
197 * Marks the view container as active
198 * (see DolphinViewContainer::setActive()).
203 * Saves the state of the current view: contents position,
206 void saveViewState();
209 * Restores the current view to show \a url and assures
210 * that the root URL of the view is respected.
212 void slotUrlNavigatorLocationChanged(const KUrl
& url
);
215 * Is connected with the URL navigator and drops the URLs
216 * above the destination \a destination.
218 void dropUrls(const KUrl
& destination
, QDropEvent
* event
);
221 * Is invoked when a redirection is done and changes the
222 * URL of the URL navigator to \a newUrl without triggering
223 * a reloading of the directory.
225 void redirect(const KUrl
& oldUrl
, const KUrl
& newUrl
);
227 /** Requests the focus for the view \a m_view. */
231 * Saves the currently used URL completion mode of
234 void saveUrlCompletionMode(KGlobalSettings::Completion completion
);
236 void slotHistoryChanged();
239 * Gets the search URL from the searchbox and starts searching.
240 * @param text Text the user has entered into the searchbox.
242 void startSearching(const QString
& text
);
243 void closeSearchBox();
246 bool isSearchUrl(const KUrl
& url
) const;
249 bool m_isFolderWritable
;
251 QVBoxLayout
* m_topLayout
;
252 KUrlNavigator
* m_urlNavigator
;
253 DolphinSearchBox
* m_searchBox
;
257 FilterBar
* m_filterBar
;
259 DolphinStatusBar
* m_statusBar
;
260 QTimer
* m_statusBarTimer
;
262 DolphinModel
* m_dolphinModel
;
263 DolphinDirLister
* m_dirLister
;
264 DolphinSortFilterProxyModel
* m_proxyModel
;
267 inline const DolphinStatusBar
* DolphinViewContainer::statusBar() const
272 inline DolphinStatusBar
* DolphinViewContainer::statusBar()
277 inline const KUrlNavigator
* DolphinViewContainer::urlNavigator() const
279 return m_urlNavigator
;
282 inline KUrlNavigator
* DolphinViewContainer::urlNavigator()
284 return m_urlNavigator
;
287 inline const DolphinView
* DolphinViewContainer::view() const
292 inline DolphinView
* DolphinViewContainer::view()
297 #endif // DOLPHINVIEWCONTAINER_H