]>
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 "dolphinstatusbar.h"
50 #include "dolphinmainwindow.h"
51 #include "dolphindirlister.h"
52 #include "dolphinsortfilterproxymodel.h"
53 #include "dolphindetailsview.h"
54 #include "dolphiniconsview.h"
55 #include "dolphincontextmenu.h"
56 #include "filterbar.h"
57 #include "kurlnavigator.h"
58 #include "viewproperties.h"
59 #include "dolphinsettings.h"
60 #include "dolphin_generalsettings.h"
62 DolphinViewContainer::DolphinViewContainer(DolphinMainWindow
* mainWindow
,
66 m_showProgress(false),
67 m_mainWindow(mainWindow
),
78 m_topLayout
= new QVBoxLayout(this);
79 m_topLayout
->setSpacing(0);
80 m_topLayout
->setMargin(0);
82 m_urlNavigator
= new KUrlNavigator(DolphinSettings::instance().placesModel(), url
, this);
83 connect(m_urlNavigator
, SIGNAL(urlsDropped(const KUrl::List
&, const KUrl
&)),
84 m_mainWindow
, SLOT(dropUrls(const KUrl::List
&, const KUrl
&)));
85 connect(m_urlNavigator
, SIGNAL(activated()),
86 this, SLOT(activate()));
88 const GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
89 m_urlNavigator
->setUrlEditable(settings
->editableUrl());
90 m_urlNavigator
->setShowFullPath(settings
->showFullPath());
91 m_urlNavigator
->setHomeUrl(settings
->homeUrl());
93 m_dirLister
= new DolphinDirLister();
94 m_dirLister
->setAutoUpdate(true);
95 m_dirLister
->setMainWindow(window());
96 m_dirLister
->setDelayedMimeTypes(true);
98 m_dolphinModel
= new DolphinModel(this);
99 m_dolphinModel
->setDirLister(m_dirLister
);
100 m_dolphinModel
->setDropsAllowed(DolphinModel::DropOnDirectory
);
102 m_proxyModel
= new DolphinSortFilterProxyModel(this);
103 m_proxyModel
->setSourceModel(m_dolphinModel
);
104 m_proxyModel
->setFilterCaseSensitivity(Qt::CaseInsensitive
);
106 connect(m_dirLister
, SIGNAL(clear()),
107 this, SLOT(updateStatusBar()));
108 connect(m_dirLister
, SIGNAL(percent(int)),
109 this, SLOT(updateProgress(int)));
110 connect(m_dirLister
, SIGNAL(deleteItem(const KFileItem
&)),
111 this, SLOT(updateStatusBar()));
112 connect(m_dirLister
, SIGNAL(completed()),
113 this, SLOT(slotDirListerCompleted()));
114 connect(m_dirLister
, SIGNAL(infoMessage(const QString
&)),
115 this, SLOT(showInfoMessage(const QString
&)));
116 connect(m_dirLister
, SIGNAL(errorMessage(const QString
&)),
117 this, SLOT(showErrorMessage(const QString
&)));
119 m_view
= new DolphinView(this,
124 connect(m_view
, SIGNAL(urlChanged(const KUrl
&)),
125 m_urlNavigator
, SLOT(setUrl(const KUrl
&)));
126 connect(m_view
, SIGNAL(requestContextMenu(KFileItem
, const KUrl
&)),
127 this, SLOT(openContextMenu(KFileItem
, const KUrl
&)));
128 connect(m_view
, SIGNAL(contentsMoved(int, int)),
129 this, SLOT(saveContentsPos(int, int)));
130 connect(m_view
, SIGNAL(requestItemInfo(KFileItem
)),
131 this, SLOT(showItemInfo(KFileItem
)));
132 connect(m_view
, SIGNAL(errorMessage(const QString
&)),
133 this, SLOT(showErrorMessage(const QString
&)));
134 connect(m_view
, SIGNAL(infoMessage(const QString
&)),
135 this, SLOT(showInfoMessage(const QString
&)));
136 connect(m_view
, SIGNAL(operationCompletedMessage(const QString
&)),
137 this, SLOT(showOperationCompletedMessage(const QString
&)));
138 connect(m_view
, SIGNAL(itemTriggered(KFileItem
)),
139 this, SLOT(slotItemTriggered(KFileItem
)));
140 connect(m_view
, SIGNAL(startedPathLoading(const KUrl
&)),
141 this, SLOT(saveRootUrl(const KUrl
&)));
143 connect(m_urlNavigator
, SIGNAL(urlChanged(const KUrl
&)),
144 this, SLOT(restoreView(const KUrl
&)));
146 m_statusBar
= new DolphinStatusBar(this, url
);
147 connect(m_view
, SIGNAL(urlChanged(const KUrl
&)),
148 m_statusBar
, SLOT(updateSpaceInfoContent(const KUrl
&)));
150 m_filterBar
= new FilterBar(this);
151 m_filterBar
->setVisible(settings
->filterBar());
152 connect(m_filterBar
, SIGNAL(filterChanged(const QString
&)),
153 this, SLOT(setNameFilter(const QString
&)));
154 connect(m_filterBar
, SIGNAL(closeRequest()),
155 this, SLOT(closeFilterBar()));
157 m_topLayout
->addWidget(m_urlNavigator
);
158 m_topLayout
->addWidget(m_view
);
159 m_topLayout
->addWidget(m_filterBar
);
160 m_topLayout
->addWidget(m_statusBar
);
163 DolphinViewContainer::~DolphinViewContainer()
165 m_dirLister
->disconnect();
169 delete m_dolphinModel
;
171 m_dirLister
= 0; // deleted by m_dolphinModel
174 void DolphinViewContainer::setUrl(const KUrl
& newUrl
)
176 m_urlNavigator
->setUrl(newUrl
);
178 // Temporary disable the 'File'->'Create New...' menu until
179 // the write permissions can be checked in a fast way at
180 // DolphinViewContainer::slotDirListerCompleted().
181 m_mainWindow
->newMenu()->menu()->setEnabled(false);
184 const KUrl
& DolphinViewContainer::url() const
186 return m_urlNavigator
->url();
189 void DolphinViewContainer::setActive(bool active
)
191 m_urlNavigator
->setActive(active
);
192 m_view
->setActive(active
);
195 bool DolphinViewContainer::isActive() const
197 Q_ASSERT(m_view
->isActive() == m_urlNavigator
->isActive());
198 return m_view
->isActive();
201 bool DolphinViewContainer::isFilterBarVisible() const
203 return m_filterBar
->isVisible();
206 bool DolphinViewContainer::isUrlEditable() const
208 return m_urlNavigator
->isUrlEditable();
211 void DolphinViewContainer::updateProgress(int percent
)
213 if (!m_showProgress
) {
214 // Only show the directory loading progress if the status bar does
215 // not contain another progress information. This means that
216 // the directory loading progress information has the lowest priority.
217 const QString
progressText(m_statusBar
->progressText());
218 const QString
loadingText(i18nc("@info:progress", "Loading folder..."));
219 m_showProgress
= progressText
.isEmpty() || (progressText
== loadingText
);
220 if (m_showProgress
) {
221 m_statusBar
->setProgressText(loadingText
);
222 m_statusBar
->setProgress(0);
226 if (m_showProgress
) {
227 m_statusBar
->setProgress(percent
);
231 void DolphinViewContainer::slotDirListerCompleted()
233 if (m_showProgress
) {
234 m_statusBar
->setProgressText(QString());
235 m_statusBar
->setProgress(100);
236 m_showProgress
= false;
240 QTimer::singleShot(100, this, SLOT(restoreContentsPos()));
242 // Enable the 'File'->'Create New...' menu only if the directory
244 KMenu
* createNew
= m_mainWindow
->newMenu()->menu();
245 KFileItem item
= m_dirLister
->rootItem();
247 // it is unclear whether writing is supported
248 createNew
->setEnabled(true);
250 KonqFileItemCapabilities
capabilities(KFileItemList() << item
);
251 createNew
->setEnabled(capabilities
.supportsWriting());
255 void DolphinViewContainer::showItemInfo(const KFileItem
& item
)
258 m_statusBar
->clear();
260 m_statusBar
->setMessage(item
.getStatusBarInfo(), DolphinStatusBar::Default
);
264 void DolphinViewContainer::showInfoMessage(const QString
& msg
)
266 m_statusBar
->setMessage(msg
, DolphinStatusBar::Information
);
269 void DolphinViewContainer::showErrorMessage(const QString
& msg
)
271 m_statusBar
->setMessage(msg
, DolphinStatusBar::Error
);
274 void DolphinViewContainer::showOperationCompletedMessage(const QString
& msg
)
276 m_statusBar
->setMessage(msg
, DolphinStatusBar::OperationCompleted
);
279 void DolphinViewContainer::closeFilterBar()
282 m_filterBar
->clear();
283 emit
showFilterBarChanged(false);
286 QString
DolphinViewContainer::defaultStatusBarText() const
290 m_view
->calculateItemCount(fileCount
, folderCount
);
291 return KIO::itemsSummaryString(fileCount
+ folderCount
,
297 QString
DolphinViewContainer::selectionStatusBarText() const
300 const KFileItemList list
= m_view
->selectedItems();
301 if (list
.isEmpty()) {
302 // when an item is triggered, it is temporary selected but selectedItems()
303 // will return an empty list
309 KIO::filesize_t byteSize
= 0;
310 KFileItemList::const_iterator it
= list
.begin();
311 const KFileItemList::const_iterator end
= list
.end();
313 const KFileItem
& item
= *it
;
318 byteSize
+= item
.size();
323 if (folderCount
> 0) {
324 text
= i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount
);
331 const QString
sizeText(KIO::convertSize(byteSize
));
332 text
+= i18ncp("@info:status", "1 File selected (%2)", "%1 Files selected (%2)", fileCount
, sizeText
);
338 void DolphinViewContainer::showFilterBar(bool show
)
340 Q_ASSERT(m_filterBar
!= 0);
341 m_filterBar
->setVisible(show
);
344 void DolphinViewContainer::updateStatusBar()
346 // As the item count information is less important
347 // in comparison with other messages, it should only
349 // - the status bar is empty or
350 // - shows already the item count information or
351 // - shows only a not very important information
352 // - if any progress is given don't show the item count info at all
353 const QString
msg(m_statusBar
->message());
354 const bool updateStatusBarMsg
= (msg
.isEmpty() ||
355 (msg
== m_statusBar
->defaultText()) ||
356 (m_statusBar
->type() == DolphinStatusBar::Information
)) &&
357 (m_statusBar
->progress() == 100);
359 const QString
text(m_view
->hasSelection() ? selectionStatusBarText() : defaultStatusBarText());
360 m_statusBar
->setDefaultText(text
);
362 if (updateStatusBarMsg
) {
363 m_statusBar
->setMessage(text
, DolphinStatusBar::Default
);
367 void DolphinViewContainer::setNameFilter(const QString
& nameFilter
)
369 m_view
->setNameFilter(nameFilter
);
373 void DolphinViewContainer::openContextMenu(const KFileItem
& item
,
376 DolphinContextMenu
contextMenu(m_mainWindow
, item
, url
);
380 void DolphinViewContainer::saveContentsPos(int x
, int y
)
382 m_urlNavigator
->savePosition(x
, y
);
385 void DolphinViewContainer::restoreContentsPos()
387 if (!url().isEmpty()) {
388 const QPoint pos
= m_urlNavigator
->savedPosition();
389 m_view
->setContentsPosition(pos
.x(), pos
.y());
393 void DolphinViewContainer::activate()
398 void DolphinViewContainer::restoreView(const KUrl
& url
)
400 m_view
->updateView(url
, m_urlNavigator
->savedRootUrl());
403 void DolphinViewContainer::saveRootUrl(const KUrl
& url
)
406 m_urlNavigator
->saveRootUrl(m_view
->rootUrl());
409 void DolphinViewContainer::slotItemTriggered(const KFileItem
& item
)
411 KUrl url
= item
.targetUrl();
418 const GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
419 const bool browseThroughArchives
= settings
->browseThroughArchives();
420 if (browseThroughArchives
&& item
.isFile() && url
.isLocalFile()) {
421 // Generic mechanism for redirecting to tar:/<path>/ when clicking on a tar file,
422 // zip:/<path>/ when clicking on a zip file, etc.
423 // The .protocol file specifies the mimetype that the kioslave handles.
424 // Note that we don't use mimetype inheritance since we don't want to
425 // open OpenDocument files as zip folders...
426 const QString protocol
= KProtocolManager::protocolForArchiveMimetype(item
.mimetype());
427 if (!protocol
.isEmpty()) {
428 url
.setProtocol(protocol
);
437 #include "dolphinviewcontainer.moc"