]>
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>
46 #include "dolphinmodel.h"
47 #include "dolphincolumnview.h"
48 #include "dolphincontroller.h"
49 #include "dolphindropcontroller.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 "filterbar.h"
58 #include "kurlnavigator.h"
59 #include "viewproperties.h"
60 #include "dolphinsettings.h"
61 #include "dolphin_generalsettings.h"
63 DolphinViewContainer::DolphinViewContainer(DolphinMainWindow
* mainWindow
,
67 m_showProgress(false),
68 m_mainWindow(mainWindow
),
79 m_topLayout
= new QVBoxLayout(this);
80 m_topLayout
->setSpacing(0);
81 m_topLayout
->setMargin(0);
83 m_urlNavigator
= new KUrlNavigator(DolphinSettings::instance().placesModel(), url
, this);
84 connect(m_urlNavigator
, SIGNAL(urlsDropped(const KUrl
&, QDropEvent
*)),
85 this, SLOT(dropUrls(const KUrl
&, QDropEvent
*)));
86 connect(m_urlNavigator
, SIGNAL(activated()),
87 this, SLOT(activate()));
89 const GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
90 m_urlNavigator
->setUrlEditable(settings
->editableUrl());
91 m_urlNavigator
->setShowFullPath(settings
->showFullPath());
92 m_urlNavigator
->setHomeUrl(settings
->homeUrl());
94 m_dirLister
= new DolphinDirLister();
95 m_dirLister
->setAutoUpdate(true);
96 m_dirLister
->setMainWindow(window());
97 m_dirLister
->setDelayedMimeTypes(true);
99 m_dolphinModel
= new DolphinModel(this);
100 m_dolphinModel
->setDirLister(m_dirLister
);
101 m_dolphinModel
->setDropsAllowed(DolphinModel::DropOnDirectory
);
103 m_proxyModel
= new DolphinSortFilterProxyModel(this);
104 m_proxyModel
->setSourceModel(m_dolphinModel
);
105 m_proxyModel
->setFilterCaseSensitivity(Qt::CaseInsensitive
);
107 connect(m_dirLister
, SIGNAL(clear()),
108 this, SLOT(updateStatusBar()));
109 connect(m_dirLister
, SIGNAL(percent(int)),
110 this, SLOT(updateProgress(int)));
111 connect(m_dirLister
, SIGNAL(deleteItem(const KFileItem
&)),
112 this, SLOT(updateStatusBar()));
113 connect(m_dirLister
, SIGNAL(completed()),
114 this, SLOT(slotDirListerCompleted()));
115 connect(m_dirLister
, SIGNAL(infoMessage(const QString
&)),
116 this, SLOT(showInfoMessage(const QString
&)));
117 connect(m_dirLister
, SIGNAL(errorMessage(const QString
&)),
118 this, SLOT(showErrorMessage(const QString
&)));
120 m_view
= new DolphinView(this,
125 connect(m_view
, SIGNAL(urlChanged(const KUrl
&)),
126 m_urlNavigator
, SLOT(setUrl(const KUrl
&)));
127 connect(m_view
, SIGNAL(requestContextMenu(KFileItem
, const KUrl
&)),
128 this, SLOT(openContextMenu(KFileItem
, const KUrl
&)));
129 connect(m_view
, SIGNAL(contentsMoved(int, int)),
130 this, SLOT(saveContentsPos(int, int)));
131 connect(m_view
, SIGNAL(requestItemInfo(KFileItem
)),
132 this, SLOT(showItemInfo(KFileItem
)));
133 connect(m_view
, SIGNAL(errorMessage(const QString
&)),
134 this, SLOT(showErrorMessage(const QString
&)));
135 connect(m_view
, SIGNAL(infoMessage(const QString
&)),
136 this, SLOT(showInfoMessage(const QString
&)));
137 connect(m_view
, SIGNAL(operationCompletedMessage(const QString
&)),
138 this, SLOT(showOperationCompletedMessage(const QString
&)));
139 connect(m_view
, SIGNAL(itemTriggered(KFileItem
)),
140 this, SLOT(slotItemTriggered(KFileItem
)));
141 connect(m_view
, SIGNAL(startedPathLoading(const KUrl
&)),
142 this, SLOT(saveRootUrl(const KUrl
&)));
144 connect(m_urlNavigator
, SIGNAL(urlChanged(const KUrl
&)),
145 this, SLOT(restoreView(const KUrl
&)));
147 m_statusBar
= new DolphinStatusBar(this, url
);
148 connect(m_view
, SIGNAL(urlChanged(const KUrl
&)),
149 m_statusBar
, SLOT(updateSpaceInfoContent(const KUrl
&)));
151 m_filterBar
= new FilterBar(this);
152 m_filterBar
->setVisible(settings
->filterBar());
153 connect(m_filterBar
, SIGNAL(filterChanged(const QString
&)),
154 this, SLOT(setNameFilter(const QString
&)));
155 connect(m_filterBar
, SIGNAL(closeRequest()),
156 this, SLOT(closeFilterBar()));
158 m_topLayout
->addWidget(m_urlNavigator
);
159 m_topLayout
->addWidget(m_view
);
160 m_topLayout
->addWidget(m_filterBar
);
161 m_topLayout
->addWidget(m_statusBar
);
164 DolphinViewContainer::~DolphinViewContainer()
166 m_dirLister
->disconnect();
170 delete m_dolphinModel
;
172 m_dirLister
= 0; // deleted by m_dolphinModel
175 void DolphinViewContainer::setUrl(const KUrl
& newUrl
)
177 m_urlNavigator
->setUrl(newUrl
);
179 // Temporary disable the 'File'->'Create New...' menu until
180 // the write permissions can be checked in a fast way at
181 // DolphinViewContainer::slotDirListerCompleted().
182 m_mainWindow
->newMenu()->menu()->setEnabled(false);
185 const KUrl
& DolphinViewContainer::url() const
187 return m_urlNavigator
->url();
190 void DolphinViewContainer::setActive(bool active
)
192 m_urlNavigator
->setActive(active
);
193 m_view
->setActive(active
);
196 bool DolphinViewContainer::isActive() const
198 Q_ASSERT(m_view
->isActive() == m_urlNavigator
->isActive());
199 return m_view
->isActive();
202 bool DolphinViewContainer::isFilterBarVisible() const
204 return m_filterBar
->isVisible();
207 bool DolphinViewContainer::isUrlEditable() const
209 return m_urlNavigator
->isUrlEditable();
212 void DolphinViewContainer::updateProgress(int percent
)
214 if (!m_showProgress
) {
215 // Only show the directory loading progress if the status bar does
216 // not contain another progress information. This means that
217 // the directory loading progress information has the lowest priority.
218 const QString
progressText(m_statusBar
->progressText());
219 const QString
loadingText(i18nc("@info:progress", "Loading folder..."));
220 m_showProgress
= progressText
.isEmpty() || (progressText
== loadingText
);
221 if (m_showProgress
) {
222 m_statusBar
->setProgressText(loadingText
);
223 m_statusBar
->setProgress(0);
227 if (m_showProgress
) {
228 m_statusBar
->setProgress(percent
);
232 void DolphinViewContainer::slotDirListerCompleted()
234 if (m_showProgress
) {
235 m_statusBar
->setProgressText(QString());
236 m_statusBar
->setProgress(100);
237 m_showProgress
= false;
241 QTimer::singleShot(100, this, SLOT(restoreContentsPos()));
243 // Enable the 'File'->'Create New...' menu only if the directory
245 KMenu
* createNew
= m_mainWindow
->newMenu()->menu();
246 KFileItem item
= m_dirLister
->rootItem();
248 // it is unclear whether writing is supported
249 createNew
->setEnabled(true);
251 KonqFileItemCapabilities
capabilities(KFileItemList() << item
);
252 createNew
->setEnabled(capabilities
.supportsWriting());
256 void DolphinViewContainer::showItemInfo(const KFileItem
& item
)
259 m_statusBar
->clear();
261 m_statusBar
->setMessage(item
.getStatusBarInfo(), DolphinStatusBar::Default
);
265 void DolphinViewContainer::showInfoMessage(const QString
& msg
)
267 m_statusBar
->setMessage(msg
, DolphinStatusBar::Information
);
270 void DolphinViewContainer::showErrorMessage(const QString
& msg
)
272 m_statusBar
->setMessage(msg
, DolphinStatusBar::Error
);
275 void DolphinViewContainer::showOperationCompletedMessage(const QString
& msg
)
277 m_statusBar
->setMessage(msg
, DolphinStatusBar::OperationCompleted
);
280 void DolphinViewContainer::closeFilterBar()
283 m_filterBar
->clear();
284 emit
showFilterBarChanged(false);
287 QString
DolphinViewContainer::defaultStatusBarText() const
291 m_view
->calculateItemCount(fileCount
, folderCount
);
292 return KIO::itemsSummaryString(fileCount
+ folderCount
,
298 QString
DolphinViewContainer::selectionStatusBarText() const
301 const KFileItemList list
= m_view
->selectedItems();
302 if (list
.isEmpty()) {
303 // when an item is triggered, it is temporary selected but selectedItems()
304 // will return an empty list
310 KIO::filesize_t byteSize
= 0;
311 KFileItemList::const_iterator it
= list
.begin();
312 const KFileItemList::const_iterator end
= list
.end();
314 const KFileItem
& item
= *it
;
319 byteSize
+= item
.size();
324 if (folderCount
> 0) {
325 text
= i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount
);
332 const QString
sizeText(KIO::convertSize(byteSize
));
333 text
+= i18ncp("@info:status", "1 File selected (%2)", "%1 Files selected (%2)", fileCount
, sizeText
);
339 void DolphinViewContainer::showFilterBar(bool show
)
341 Q_ASSERT(m_filterBar
!= 0);
342 m_filterBar
->setVisible(show
);
345 void DolphinViewContainer::updateStatusBar()
347 // As the item count information is less important
348 // in comparison with other messages, it should only
350 // - the status bar is empty or
351 // - shows already the item count information or
352 // - shows only a not very important information
353 // - if any progress is given don't show the item count info at all
354 const QString
msg(m_statusBar
->message());
355 const bool updateStatusBarMsg
= (msg
.isEmpty() ||
356 (msg
== m_statusBar
->defaultText()) ||
357 (m_statusBar
->type() == DolphinStatusBar::Information
)) &&
358 (m_statusBar
->progress() == 100);
360 const QString
text(m_view
->hasSelection() ? selectionStatusBarText() : defaultStatusBarText());
361 m_statusBar
->setDefaultText(text
);
363 if (updateStatusBarMsg
) {
364 m_statusBar
->setMessage(text
, DolphinStatusBar::Default
);
368 void DolphinViewContainer::setNameFilter(const QString
& nameFilter
)
370 m_view
->setNameFilter(nameFilter
);
374 void DolphinViewContainer::openContextMenu(const KFileItem
& item
,
377 DolphinContextMenu
contextMenu(m_mainWindow
, item
, url
);
381 void DolphinViewContainer::saveContentsPos(int x
, int y
)
383 m_urlNavigator
->savePosition(x
, y
);
386 void DolphinViewContainer::restoreContentsPos()
388 if (!url().isEmpty()) {
389 const QPoint pos
= m_urlNavigator
->savedPosition();
390 m_view
->setContentsPosition(pos
.x(), pos
.y());
394 void DolphinViewContainer::activate()
399 void DolphinViewContainer::restoreView(const KUrl
& url
)
401 m_view
->updateView(url
, m_urlNavigator
->savedRootUrl());
404 void DolphinViewContainer::saveRootUrl(const KUrl
& url
)
407 m_urlNavigator
->saveRootUrl(m_view
->rootUrl());
410 void DolphinViewContainer::dropUrls(const KUrl
& destination
, QDropEvent
* event
)
412 DolphinDropController::dropUrls(KFileItem(), destination
, event
, this);
415 void DolphinViewContainer::slotItemTriggered(const KFileItem
& item
)
417 KUrl url
= item
.targetUrl();
424 const GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
425 const bool browseThroughArchives
= settings
->browseThroughArchives();
426 if (browseThroughArchives
&& item
.isFile() && url
.isLocalFile()) {
427 // Generic mechanism for redirecting to tar:/<path>/ when clicking on a tar file,
428 // zip:/<path>/ when clicking on a zip file, etc.
429 // The .protocol file specifies the mimetype that the kioslave handles.
430 // Note that we don't use mimetype inheritance since we don't want to
431 // open OpenDocument files as zip folders...
432 const QString protocol
= KProtocolManager::protocolForArchiveMimetype(item
.mimetype());
433 if (!protocol
.isEmpty()) {
434 url
.setProtocol(protocol
);
443 #include "dolphinviewcontainer.moc"