]>
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
);
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);
186 const KUrl
& DolphinViewContainer::url() const
188 return m_urlNavigator
->url();
191 void DolphinViewContainer::setActive(bool active
)
193 m_urlNavigator
->setActive(active
);
194 m_view
->setActive(active
);
197 bool DolphinViewContainer::isActive() const
199 Q_ASSERT(m_view
->isActive() == m_urlNavigator
->isActive());
200 return m_view
->isActive();
203 void DolphinViewContainer::refresh()
206 m_statusBar
->refresh();
209 bool DolphinViewContainer::isFilterBarVisible() const
211 return m_filterBar
->isVisible();
214 bool DolphinViewContainer::isUrlEditable() const
216 return m_urlNavigator
->isUrlEditable();
219 void DolphinViewContainer::updateProgress(int percent
)
221 if (!m_showProgress
) {
222 // Only show the directory loading progress if the status bar does
223 // not contain another progress information. This means that
224 // the directory loading progress information has the lowest priority.
225 const QString
progressText(m_statusBar
->progressText());
226 const QString
loadingText(i18nc("@info:progress", "Loading folder..."));
227 m_showProgress
= progressText
.isEmpty() || (progressText
== loadingText
);
228 if (m_showProgress
) {
229 m_statusBar
->setProgressText(loadingText
);
230 m_statusBar
->setProgress(0);
234 if (m_showProgress
) {
235 m_statusBar
->setProgress(percent
);
239 void DolphinViewContainer::slotDirListerCompleted()
241 if (m_showProgress
) {
242 m_statusBar
->setProgressText(QString());
243 m_statusBar
->setProgress(100);
244 m_showProgress
= false;
248 QTimer::singleShot(100, this, SLOT(restoreContentsPos()));
250 // Enable the 'File'->'Create New...' menu only if the directory
252 KMenu
* createNew
= m_mainWindow
->newMenu()->menu();
253 KFileItem item
= m_dirLister
->rootItem();
255 // it is unclear whether writing is supported
256 createNew
->setEnabled(true);
258 KonqFileItemCapabilities
capabilities(KFileItemList() << item
);
259 createNew
->setEnabled(capabilities
.supportsWriting());
263 void DolphinViewContainer::showItemInfo(const KFileItem
& item
)
266 m_statusBar
->clear();
268 m_statusBar
->setMessage(item
.getStatusBarInfo(), DolphinStatusBar::Default
);
272 void DolphinViewContainer::showInfoMessage(const QString
& msg
)
274 m_statusBar
->setMessage(msg
, DolphinStatusBar::Information
);
277 void DolphinViewContainer::showErrorMessage(const QString
& msg
)
279 m_statusBar
->setMessage(msg
, DolphinStatusBar::Error
);
282 void DolphinViewContainer::showOperationCompletedMessage(const QString
& msg
)
284 m_statusBar
->setMessage(msg
, DolphinStatusBar::OperationCompleted
);
287 void DolphinViewContainer::closeFilterBar()
290 m_filterBar
->clear();
291 emit
showFilterBarChanged(false);
294 void DolphinViewContainer::showFilterBar(bool show
)
296 Q_ASSERT(m_filterBar
!= 0);
297 m_filterBar
->setVisible(show
);
300 void DolphinViewContainer::updateStatusBar()
302 // As the item count information is less important
303 // in comparison with other messages, it should only
305 // - the status bar is empty or
306 // - shows already the item count information or
307 // - shows only a not very important information
308 // - if any progress is given don't show the item count info at all
309 const QString
msg(m_statusBar
->message());
310 const bool updateStatusBarMsg
= (msg
.isEmpty() ||
311 (msg
== m_statusBar
->defaultText()) ||
312 (m_statusBar
->type() == DolphinStatusBar::Information
)) &&
313 (m_statusBar
->progress() == 100);
315 const QString
text(m_view
->statusBarText());
316 m_statusBar
->setDefaultText(text
);
318 if (updateStatusBarMsg
) {
319 m_statusBar
->setMessage(text
, DolphinStatusBar::Default
);
323 void DolphinViewContainer::setNameFilter(const QString
& nameFilter
)
325 m_view
->setNameFilter(nameFilter
);
329 void DolphinViewContainer::openContextMenu(const KFileItem
& item
,
332 DolphinContextMenu
contextMenu(m_mainWindow
, item
, url
);
336 void DolphinViewContainer::saveContentsPos(int x
, int y
)
338 m_urlNavigator
->savePosition(x
, y
);
341 void DolphinViewContainer::restoreContentsPos()
343 if (!url().isEmpty()) {
344 const QPoint pos
= m_urlNavigator
->savedPosition();
345 m_view
->setContentsPosition(pos
.x(), pos
.y());
349 void DolphinViewContainer::activate()
354 void DolphinViewContainer::restoreView(const KUrl
& url
)
356 if (KProtocolManager::supportsListing(url
)) {
357 m_view
->updateView(url
, m_urlNavigator
->savedRootUrl());
359 // The URL navigator only checks for validity, not
360 // if the URL can be listed.
361 showErrorMessage(i18nc("@info:status", "Protocol not supported by Dolphin, Konqueror has been launched"));
362 QString command
= "konqueror " + url
.pathOrUrl();
363 KRun::runCommand(command
, "konqueror", "konqueror", this);
367 void DolphinViewContainer::saveRootUrl(const KUrl
& url
)
370 m_urlNavigator
->saveRootUrl(m_view
->rootUrl());
373 void DolphinViewContainer::dropUrls(const KUrl
& destination
, QDropEvent
* event
)
375 DragAndDropHelper::instance().dropUrls(KFileItem(), destination
, event
, this);
378 void DolphinViewContainer::redirect(const KUrl
& oldUrl
, const KUrl
& newUrl
)
381 const bool block
= m_urlNavigator
->signalsBlocked();
382 m_urlNavigator
->blockSignals(true);
383 m_urlNavigator
->setUrl(newUrl
);
384 m_urlNavigator
->blockSignals(block
);
387 void DolphinViewContainer::slotItemTriggered(const KFileItem
& item
)
389 KUrl url
= item
.targetUrl();
396 const GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
397 const bool browseThroughArchives
= settings
->browseThroughArchives();
398 if (browseThroughArchives
&& item
.isFile() && url
.isLocalFile()) {
399 // Generic mechanism for redirecting to tar:/<path>/ when clicking on a tar file,
400 // zip:/<path>/ when clicking on a zip file, etc.
401 // The .protocol file specifies the mimetype that the kioslave handles.
402 // Note that we don't use mimetype inheritance since we don't want to
403 // open OpenDocument files as zip folders...
404 const QString protocol
= KProtocolManager::protocolForArchiveMimetype(item
.mimetype());
405 if (!protocol
.isEmpty()) {
406 url
.setProtocol(protocol
);
415 #include "dolphinviewcontainer.moc"