]>
cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinviewcontainer.cpp
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 ***************************************************************************/
20 #include "dolphinviewcontainer.h"
21 #include <kprotocolmanager.h>
23 #include <QtGui/QApplication>
24 #include <QtGui/QClipboard>
25 #include <QtGui/QKeyEvent>
26 #include <QtGui/QItemSelection>
27 #include <QtGui/QBoxLayout>
28 #include <QtCore/QTimer>
29 #include <QtGui/QScrollBar>
31 #include <kfileitemdelegate.h>
32 #include <kfileplacesmodel.h>
33 #include <kglobalsettings.h>
35 #include <kiconeffect.h>
36 #include <kio/netaccess.h>
37 #include <kio/previewjob.h>
39 #include <kmimetyperesolver.h>
41 #include <konqmimedata.h>
42 #include <konq_fileitemcapabilities.h>
43 #include <konq_operations.h>
47 #include "dolphinmodel.h"
48 #include "dolphincolumnview.h"
49 #include "dolphincontroller.h"
50 #include "dolphinstatusbar.h"
51 #include "dolphinmainwindow.h"
52 #include "dolphindirlister.h"
53 #include "dolphinsortfilterproxymodel.h"
54 #include "dolphindetailsview.h"
55 #include "dolphiniconsview.h"
56 #include "dolphincontextmenu.h"
57 #include "draganddrophelper.h"
58 #include "filterbar.h"
59 #include "kurlnavigator.h"
60 #include "viewproperties.h"
61 #include "dolphinsettings.h"
62 #include "dolphin_generalsettings.h"
64 DolphinViewContainer::DolphinViewContainer(DolphinMainWindow
* mainWindow
,
68 m_showProgress(false),
69 m_mainWindow(mainWindow
),
80 m_topLayout
= new QVBoxLayout(this);
81 m_topLayout
->setSpacing(0);
82 m_topLayout
->setMargin(0);
84 m_urlNavigator
= new KUrlNavigator(DolphinSettings::instance().placesModel(), url
, this);
85 connect(m_urlNavigator
, SIGNAL(urlsDropped(const KUrl
&, QDropEvent
*)),
86 this, SLOT(dropUrls(const KUrl
&, QDropEvent
*)));
87 connect(m_urlNavigator
, SIGNAL(activated()),
88 this, SLOT(activate()));
90 const GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
91 m_urlNavigator
->setUrlEditable(settings
->editableUrl());
92 m_urlNavigator
->setShowFullPath(settings
->showFullPath());
93 m_urlNavigator
->setHomeUrl(settings
->homeUrl());
95 m_dirLister
= new DolphinDirLister();
96 m_dirLister
->setAutoUpdate(true);
97 m_dirLister
->setMainWindow(window());
98 m_dirLister
->setDelayedMimeTypes(true);
100 m_dolphinModel
= new DolphinModel(this);
101 m_dolphinModel
->setDirLister(m_dirLister
);
102 m_dolphinModel
->setDropsAllowed(DolphinModel::DropOnDirectory
);
104 m_proxyModel
= new DolphinSortFilterProxyModel(this);
105 m_proxyModel
->setSourceModel(m_dolphinModel
);
106 m_proxyModel
->setFilterCaseSensitivity(Qt::CaseInsensitive
);
108 connect(m_dirLister
, SIGNAL(clear()),
109 this, SLOT(updateStatusBar()));
110 connect(m_dirLister
, SIGNAL(percent(int)),
111 this, SLOT(updateProgress(int)));
112 connect(m_dirLister
, SIGNAL(deleteItem(const KFileItem
&)),
113 this, SLOT(updateStatusBar()));
114 connect(m_dirLister
, SIGNAL(completed()),
115 this, SLOT(slotDirListerCompleted()));
116 connect(m_dirLister
, SIGNAL(infoMessage(const QString
&)),
117 this, SLOT(showInfoMessage(const QString
&)));
118 connect(m_dirLister
, SIGNAL(errorMessage(const QString
&)),
119 this, SLOT(showErrorMessage(const QString
&)));
121 m_view
= new DolphinView(this,
126 connect(m_view
, SIGNAL(urlChanged(const KUrl
&)),
127 m_urlNavigator
, SLOT(setUrl(const KUrl
&)));
128 connect(m_view
, SIGNAL(requestContextMenu(KFileItem
, const KUrl
&)),
129 this, SLOT(openContextMenu(KFileItem
, const KUrl
&)));
130 connect(m_view
, SIGNAL(contentsMoved(int, int)),
131 this, SLOT(saveContentsPos(int, int)));
132 connect(m_view
, SIGNAL(requestItemInfo(KFileItem
)),
133 this, SLOT(showItemInfo(KFileItem
)));
134 connect(m_view
, SIGNAL(errorMessage(const QString
&)),
135 this, SLOT(showErrorMessage(const QString
&)));
136 connect(m_view
, SIGNAL(infoMessage(const QString
&)),
137 this, SLOT(showInfoMessage(const QString
&)));
138 connect(m_view
, SIGNAL(operationCompletedMessage(const QString
&)),
139 this, SLOT(showOperationCompletedMessage(const QString
&)));
140 connect(m_view
, SIGNAL(itemTriggered(KFileItem
)),
141 this, SLOT(slotItemTriggered(KFileItem
)));
142 connect(m_view
, SIGNAL(startedPathLoading(const KUrl
&)),
143 this, SLOT(saveRootUrl(const KUrl
&)));
144 connect(m_view
, SIGNAL(redirection(KUrl
, KUrl
)),
145 this, SLOT(redirect(KUrl
, KUrl
)));
147 connect(m_urlNavigator
, SIGNAL(urlChanged(const KUrl
&)),
148 this, SLOT(restoreView(const KUrl
&)));
150 m_statusBar
= new DolphinStatusBar(this, m_view
);
152 m_filterBar
= new FilterBar(this);
153 m_filterBar
->setVisible(settings
->filterBar());
154 connect(m_filterBar
, SIGNAL(filterChanged(const QString
&)),
155 this, SLOT(setNameFilter(const QString
&)));
156 connect(m_filterBar
, SIGNAL(closeRequest()),
157 this, SLOT(closeFilterBar()));
159 m_topLayout
->addWidget(m_urlNavigator
);
160 m_topLayout
->addWidget(m_view
);
161 m_topLayout
->addWidget(m_filterBar
);
162 m_topLayout
->addWidget(m_statusBar
);
165 DolphinViewContainer::~DolphinViewContainer()
167 m_dirLister
->disconnect();
171 delete m_dolphinModel
;
173 m_dirLister
= 0; // deleted by m_dolphinModel
176 void DolphinViewContainer::setUrl(const KUrl
& newUrl
)
178 m_urlNavigator
->setUrl(newUrl
);
179 if (newUrl
!= m_urlNavigator
->url()) {
180 // Temporary disable the 'File'->'Create New...' menu until
181 // the write permissions can be checked in a fast way at
182 // DolphinViewContainer::slotDirListerCompleted().
183 m_mainWindow
->newMenu()->menu()->setEnabled(false);
187 const KUrl
& DolphinViewContainer::url() const
189 return m_urlNavigator
->url();
192 void DolphinViewContainer::setActive(bool active
)
194 m_urlNavigator
->setActive(active
);
195 m_view
->setActive(active
);
198 bool DolphinViewContainer::isActive() const
200 Q_ASSERT(m_view
->isActive() == m_urlNavigator
->isActive());
201 return m_view
->isActive();
204 void DolphinViewContainer::refresh()
207 m_statusBar
->refresh();
210 bool DolphinViewContainer::isFilterBarVisible() const
212 return m_filterBar
->isVisible();
215 bool DolphinViewContainer::isUrlEditable() const
217 return m_urlNavigator
->isUrlEditable();
220 void DolphinViewContainer::updateProgress(int percent
)
222 if (!m_showProgress
) {
223 // Only show the directory loading progress if the status bar does
224 // not contain another progress information. This means that
225 // the directory loading progress information has the lowest priority.
226 const QString
progressText(m_statusBar
->progressText());
227 const QString
loadingText(i18nc("@info:progress", "Loading folder..."));
228 m_showProgress
= progressText
.isEmpty() || (progressText
== loadingText
);
229 if (m_showProgress
) {
230 m_statusBar
->setProgressText(loadingText
);
231 m_statusBar
->setProgress(0);
235 if (m_showProgress
) {
236 m_statusBar
->setProgress(percent
);
240 void DolphinViewContainer::slotDirListerCompleted()
242 if (m_showProgress
) {
243 m_statusBar
->setProgressText(QString());
244 m_statusBar
->setProgress(100);
245 m_showProgress
= false;
249 QTimer::singleShot(100, this, SLOT(restoreContentsPos()));
251 // Enable the 'File'->'Create New...' menu only if the directory
253 KMenu
* createNew
= m_mainWindow
->newMenu()->menu();
254 KFileItem item
= m_dirLister
->rootItem();
256 // it is unclear whether writing is supported
257 createNew
->setEnabled(true);
259 KonqFileItemCapabilities
capabilities(KFileItemList() << item
);
260 createNew
->setEnabled(capabilities
.supportsWriting());
264 void DolphinViewContainer::showItemInfo(const KFileItem
& item
)
267 m_statusBar
->clear();
269 m_statusBar
->setMessage(item
.getStatusBarInfo(), DolphinStatusBar::Default
);
273 void DolphinViewContainer::showInfoMessage(const QString
& msg
)
275 m_statusBar
->setMessage(msg
, DolphinStatusBar::Information
);
278 void DolphinViewContainer::showErrorMessage(const QString
& msg
)
280 m_statusBar
->setMessage(msg
, DolphinStatusBar::Error
);
283 void DolphinViewContainer::showOperationCompletedMessage(const QString
& msg
)
285 m_statusBar
->setMessage(msg
, DolphinStatusBar::OperationCompleted
);
288 void DolphinViewContainer::closeFilterBar()
291 m_filterBar
->clear();
292 emit
showFilterBarChanged(false);
295 void DolphinViewContainer::showFilterBar(bool show
)
297 Q_ASSERT(m_filterBar
!= 0);
298 m_filterBar
->setVisible(show
);
301 void DolphinViewContainer::updateStatusBar()
303 // As the item count information is less important
304 // in comparison with other messages, it should only
306 // - the status bar is empty or
307 // - shows already the item count information or
308 // - shows only a not very important information
309 // - if any progress is given don't show the item count info at all
310 const QString
msg(m_statusBar
->message());
311 const bool updateStatusBarMsg
= (msg
.isEmpty() ||
312 (msg
== m_statusBar
->defaultText()) ||
313 (m_statusBar
->type() == DolphinStatusBar::Information
)) &&
314 (m_statusBar
->progress() == 100);
316 const QString
text(m_view
->statusBarText());
317 m_statusBar
->setDefaultText(text
);
319 if (updateStatusBarMsg
) {
320 m_statusBar
->setMessage(text
, DolphinStatusBar::Default
);
324 void DolphinViewContainer::setNameFilter(const QString
& nameFilter
)
326 m_view
->setNameFilter(nameFilter
);
330 void DolphinViewContainer::openContextMenu(const KFileItem
& item
,
333 DolphinContextMenu
contextMenu(m_mainWindow
, item
, url
);
337 void DolphinViewContainer::saveContentsPos(int x
, int y
)
339 m_urlNavigator
->savePosition(x
, y
);
342 void DolphinViewContainer::restoreContentsPos()
344 if (!url().isEmpty()) {
345 const QPoint pos
= m_urlNavigator
->savedPosition();
346 m_view
->setContentsPosition(pos
.x(), pos
.y());
350 void DolphinViewContainer::activate()
355 void DolphinViewContainer::restoreView(const KUrl
& url
)
357 if (KProtocolManager::supportsListing(url
)) {
358 m_view
->updateView(url
, m_urlNavigator
->savedRootUrl());
359 } else if (KProtocolManager::isSourceProtocol(url
)) {
360 QString app
= "konqueror";
361 if (url
.protocol().startsWith(QLatin1String("http"))) {
362 showErrorMessage(i18nc("@info:status",
363 "Dolphin does not support web pages, the web browser has been launched"));
364 const KConfigGroup
config(KSharedConfig::openConfig("kdeglobals"), "General");
365 const QString browser
= config
.readEntry("BrowserApplication");
366 if (!browser
.isEmpty()) {
370 showErrorMessage(i18nc("@info:status",
371 "Protocol not supported by Dolphin, Konqueror has been launched"));
373 const QString command
= app
+ ' ' + url
.pathOrUrl();
374 KRun::runCommand(command
, app
, app
, this);
376 showErrorMessage(i18nc("@info:status", "Invalid protocol"));
380 void DolphinViewContainer::saveRootUrl(const KUrl
& url
)
383 m_urlNavigator
->saveRootUrl(m_view
->rootUrl());
386 void DolphinViewContainer::dropUrls(const KUrl
& destination
, QDropEvent
* event
)
388 DragAndDropHelper::instance().dropUrls(KFileItem(), destination
, event
, this);
391 void DolphinViewContainer::redirect(const KUrl
& oldUrl
, const KUrl
& newUrl
)
394 const bool block
= m_urlNavigator
->signalsBlocked();
395 m_urlNavigator
->blockSignals(true);
396 m_urlNavigator
->setUrl(newUrl
);
397 m_urlNavigator
->blockSignals(block
);
400 void DolphinViewContainer::slotItemTriggered(const KFileItem
& item
)
402 KUrl url
= item
.targetUrl();
409 const GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
410 const bool browseThroughArchives
= settings
->browseThroughArchives();
411 if (browseThroughArchives
&& item
.isFile() && url
.isLocalFile()) {
412 // Generic mechanism for redirecting to tar:/<path>/ when clicking on a tar file,
413 // zip:/<path>/ when clicking on a zip file, etc.
414 // The .protocol file specifies the mimetype that the kioslave handles.
415 // Note that we don't use mimetype inheritance since we don't want to
416 // open OpenDocument files as zip folders...
417 const QString protocol
= KProtocolManager::protocolForArchiveMimetype(item
.mimetype());
418 if (!protocol
.isEmpty()) {
419 url
.setProtocol(protocol
);
428 #include "dolphinviewcontainer.moc"