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 <kfileitem.h>
25 #include <kfileitemdelegate.h>
26 #include <kglobalsettings.h>
29 #include <kurlnavigator.h>
31 #include <QElapsedTimer>
34 #include <views/dolphinview.h>
39 class DolphinSearchBox
;
40 class DolphinStatusBar
;
43 * @short Represents a view for the directory content
44 * including the navigation bar, filter bar and status bar.
46 * View modes for icons, details and columns are supported. Currently
47 * Dolphin allows to have up to two views inside the main window.
52 * @see DolphinStatusBar
54 class DolphinViewContainer
: public QWidget
59 DolphinViewContainer(const KUrl
& url
, QWidget
* parent
);
60 virtual ~DolphinViewContainer();
63 * Returns the current active URL, where all actions are applied.
64 * The URL navigator is synchronized with this URL.
69 * If \a active is true, the view container will marked as active. The active
70 * view container is defined as view where all actions are applied to.
72 void setActive(bool active
);
73 bool isActive() const;
75 const DolphinStatusBar
* statusBar() const;
76 DolphinStatusBar
* statusBar();
78 const KUrlNavigator
* urlNavigator() const;
79 KUrlNavigator
* urlNavigator();
81 const DolphinView
* view() const;
85 * Refreshes the view container to get synchronized with the (updated) Dolphin settings.
89 /** Returns true, if the filter bar is visible. */
90 bool isFilterBarVisible() const;
93 * Enables the search mode, if \p enabled is true. In the search mode the URL navigator
94 * will be hidden and replaced by a line editor that allows to enter a search term.
96 void setSearchModeEnabled(bool enabled
);
97 bool isSearchModeEnabled() const;
101 * Sets the current active URL, where all actions are applied. The
102 * URL navigator is synchronized with this URL. The signals
103 * KUrlNavigator::urlChanged() and KUrlNavigator::historyChanged()
105 * @see DolphinViewContainer::urlNavigator()
107 void setUrl(const KUrl
& url
);
110 * Popups the filter bar above the status bar if \a visible is true.
111 * It \a visible is true, it is assured that the filter bar gains
112 * the keyboard focus.
114 void setFilterBarVisible(bool visible
);
118 * Is emitted whenever the filter bar has changed its visibility state.
120 void showFilterBarChanged(bool shown
);
123 * Is emitted when the write state of the folder has been changed. The application
124 * should disable all actions like "Create New..." that depend on the write
127 void writeStateChanged(bool isFolderWritable
);
130 * Is emitted if the search mode has been enabled or disabled.
131 * (see DolphinViewContainer::setSearchModeEnabled() and
132 * DolphinViewContainer::isSearchModeEnabled())
134 void searchModeChanged(bool enabled
);
138 * Updates the number of items (= number of files + number of
139 * directories) in the statusbar. If files are selected, the number
140 * of selected files and the sum of the filesize is shown. The update
141 * is done asynchronously, as getting the sum of the
142 * filesizes can be an expensive operation.
144 void delayedStatusBarUpdate();
147 * Is invoked by DolphinViewContainer::delayedStatusBarUpdate() and
148 * updates the status bar synchronously.
150 void updateStatusBar();
152 void updateProgress(int percent
);
155 * Updates the statusbar to show an undetermined progress with the correct
156 * context information whether a searching or a directory loading is done.
158 void slotStartedPathLoading();
161 * Assures that the viewport position is restored and updates the
162 * statusbar to reflect the current content.
164 void slotFinishedPathLoading();
167 * Handles clicking on an item. If the item is a directory, the
168 * directory is opened in the view. If the item is a file, the file
169 * gets started by the corresponding application.
171 void slotItemTriggered(const KFileItem
& item
);
174 * Opens a the file \a url by opening the corresponding application.
175 * Is connected with the signal urlIsFile() from DolphinDirLister and will
176 * get invoked if the user manually has entered a file into the URL navigator.
178 void openFile(const KUrl
& url
);
181 * Shows the information for the item \a item inside the statusbar. If the
182 * item is null, the default statusbar information is shown.
184 void showItemInfo(const KFileItem
& item
);
186 /** Shows the information \a msg inside the statusbar. */
187 void showInfoMessage(const QString
& msg
);
189 /** Shows the error message \a msg inside the statusbar. */
190 void showErrorMessage(const QString
& msg
);
192 /** Shows the "operation completed" message \a msg inside the statusbar. */
193 void showOperationCompletedMessage(const QString
& msg
);
195 void closeFilterBar();
198 * Filters the currently shown items by \a nameFilter. All items
199 * which contain the given filter string will be shown.
201 void setNameFilter(const QString
& nameFilter
);
204 * Marks the view container as active
205 * (see DolphinViewContainer::setActive()).
210 * Saves the state of the current view: contents position,
213 void saveViewState();
216 * Restores the current view to show \a url and assures
217 * that the root URL of the view is respected.
219 void slotUrlNavigatorLocationChanged(const KUrl
& url
);
222 * Is connected with the URL navigator and drops the URLs
223 * above the destination \a destination.
225 void dropUrls(const KUrl
& destination
, QDropEvent
* event
);
228 * Is invoked when a redirection is done and changes the
229 * URL of the URL navigator to \a newUrl without triggering
230 * a reloading of the directory.
232 void redirect(const KUrl
& oldUrl
, const KUrl
& newUrl
);
234 /** Requests the focus for the view \a m_view. */
238 * Saves the currently used URL completion mode of
241 void saveUrlCompletionMode(KGlobalSettings::Completion completion
);
243 void slotHistoryChanged();
246 * Gets the search URL from the searchbox and starts searching.
247 * @param text Text the user has entered into the searchbox.
249 void startSearching(const QString
& text
);
250 void closeSearchBox();
253 * Stops the loading of a directory. Is connected with the "stopPressed" signal
254 * from the statusbar.
260 * @return True if the URL protocol is a search URL (e. g. nepomuksearch:// or filenamesearch://).
262 bool isSearchUrl(const KUrl
& url
) const;
265 QVBoxLayout
* m_topLayout
;
266 KUrlNavigator
* m_urlNavigator
;
267 DolphinSearchBox
* m_searchBox
;
271 FilterBar
* m_filterBar
;
273 DolphinStatusBar
* m_statusBar
;
274 QTimer
* m_statusBarTimer
; // Triggers a delayed update
275 QElapsedTimer m_statusBarTimestamp
; // Time in ms since last update
278 inline const DolphinStatusBar
* DolphinViewContainer::statusBar() const
283 inline DolphinStatusBar
* DolphinViewContainer::statusBar()
288 inline const KUrlNavigator
* DolphinViewContainer::urlNavigator() const
290 return m_urlNavigator
;
293 inline KUrlNavigator
* DolphinViewContainer::urlNavigator()
295 return m_urlNavigator
;
298 inline const DolphinView
* DolphinViewContainer::view() const
303 inline DolphinView
* DolphinViewContainer::view()
308 #endif // DOLPHINVIEWCONTAINER_H