]>
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>
38 #include <kmimetyperesolver.h>
39 #include <konqmimedata.h>
40 #include <konq_operations.h>
43 #include "dolphinmodel.h"
44 #include "dolphincolumnview.h"
45 #include "dolphincontroller.h"
46 #include "dolphinstatusbar.h"
47 #include "dolphinmainwindow.h"
48 #include "dolphindirlister.h"
49 #include "dolphinsortfilterproxymodel.h"
50 #include "dolphindetailsview.h"
51 #include "dolphiniconsview.h"
52 #include "dolphincontextmenu.h"
53 #include "filterbar.h"
54 #include "kurlnavigator.h"
55 #include "viewproperties.h"
56 #include "dolphinsettings.h"
57 #include "dolphin_generalsettings.h"
59 DolphinViewContainer::DolphinViewContainer(DolphinMainWindow
* mainWindow
,
63 m_showProgress(false),
64 m_mainWindow(mainWindow
),
75 m_topLayout
= new QVBoxLayout(this);
76 m_topLayout
->setSpacing(0);
77 m_topLayout
->setMargin(0);
79 m_urlNavigator
= new KUrlNavigator(DolphinSettings::instance().placesModel(), url
, this);
80 connect(m_urlNavigator
, SIGNAL(urlsDropped(const KUrl::List
&, const KUrl
&)),
81 m_mainWindow
, SLOT(dropUrls(const KUrl::List
&, const KUrl
&)));
82 connect(m_urlNavigator
, SIGNAL(activated()),
83 this, SLOT(activate()));
85 const GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
86 m_urlNavigator
->setUrlEditable(settings
->editableUrl());
87 m_urlNavigator
->setHomeUrl(settings
->homeUrl());
89 m_dirLister
= new DolphinDirLister();
90 m_dirLister
->setAutoUpdate(true);
91 m_dirLister
->setMainWindow(window());
92 m_dirLister
->setDelayedMimeTypes(true);
94 m_dolphinModel
= new DolphinModel(this);
95 m_dolphinModel
->setDirLister(m_dirLister
);
96 m_dolphinModel
->setDropsAllowed(DolphinModel::DropOnDirectory
);
98 m_proxyModel
= new DolphinSortFilterProxyModel(this);
99 m_proxyModel
->setSourceModel(m_dolphinModel
);
100 m_proxyModel
->setFilterCaseSensitivity(Qt::CaseInsensitive
);
102 connect(m_dirLister
, SIGNAL(clear()),
103 this, SLOT(updateStatusBar()));
104 connect(m_dirLister
, SIGNAL(percent(int)),
105 this, SLOT(updateProgress(int)));
106 connect(m_dirLister
, SIGNAL(deleteItem(const KFileItem
&)),
107 this, SLOT(updateStatusBar()));
108 connect(m_dirLister
, SIGNAL(completed()),
109 this, SLOT(slotDirListerCompleted()));
110 connect(m_dirLister
, SIGNAL(infoMessage(const QString
&)),
111 this, SLOT(showInfoMessage(const QString
&)));
112 connect(m_dirLister
, SIGNAL(errorMessage(const QString
&)),
113 this, SLOT(showErrorMessage(const QString
&)));
115 m_view
= new DolphinView(this,
120 connect(m_view
, SIGNAL(urlChanged(const KUrl
&)),
121 m_urlNavigator
, SLOT(setUrl(const KUrl
&)));
122 connect(m_view
, SIGNAL(requestContextMenu(KFileItem
, const KUrl
&)),
123 this, SLOT(openContextMenu(KFileItem
, const KUrl
&)));
124 connect(m_view
, SIGNAL(contentsMoved(int, int)),
125 this, SLOT(saveContentsPos(int, int)));
126 connect(m_view
, SIGNAL(requestItemInfo(KFileItem
)),
127 this, SLOT(showItemInfo(KFileItem
)));
128 connect(m_view
, SIGNAL(errorMessage(const QString
&)),
129 this, SLOT(showErrorMessage(const QString
&)));
130 connect(m_view
, SIGNAL(infoMessage(const QString
&)),
131 this, SLOT(showInfoMessage(const QString
&)));
132 connect(m_view
, SIGNAL(operationCompletedMessage(const QString
&)),
133 this, SLOT(showOperationCompletedMessage(const QString
&)));
134 connect(m_view
, SIGNAL(itemTriggered(KFileItem
)),
135 this, SLOT(slotItemTriggered(KFileItem
)));
136 connect(m_view
, SIGNAL(startedPathLoading(const KUrl
&)),
137 this, SLOT(saveRootUrl(const KUrl
&)));
139 connect(m_urlNavigator
, SIGNAL(urlChanged(const KUrl
&)),
140 this, SLOT(restoreView(const KUrl
&)));
142 m_statusBar
= new DolphinStatusBar(this, url
);
143 connect(m_view
, SIGNAL(urlChanged(const KUrl
&)),
144 m_statusBar
, SLOT(updateSpaceInfoContent(const KUrl
&)));
146 m_filterBar
= new FilterBar(this);
147 m_filterBar
->setVisible(settings
->filterBar());
148 connect(m_filterBar
, SIGNAL(filterChanged(const QString
&)),
149 this, SLOT(setNameFilter(const QString
&)));
150 connect(m_filterBar
, SIGNAL(closeRequest()),
151 this, SLOT(closeFilterBar()));
153 m_topLayout
->addWidget(m_urlNavigator
);
154 m_topLayout
->addWidget(m_view
);
155 m_topLayout
->addWidget(m_filterBar
);
156 m_topLayout
->addWidget(m_statusBar
);
159 DolphinViewContainer::~DolphinViewContainer()
161 m_dirLister
->disconnect();
165 delete m_dolphinModel
;
167 m_dirLister
= 0; // deleted by m_dolphinModel
170 void DolphinViewContainer::setUrl(const KUrl
& newUrl
)
172 m_urlNavigator
->setUrl(newUrl
);
175 const KUrl
& DolphinViewContainer::url() const
177 return m_urlNavigator
->url();
180 void DolphinViewContainer::setActive(bool active
)
182 m_urlNavigator
->setActive(active
);
183 m_view
->setActive(active
);
186 bool DolphinViewContainer::isActive() const
188 Q_ASSERT(m_view
->isActive() == m_urlNavigator
->isActive());
189 return m_view
->isActive();
192 bool DolphinViewContainer::isFilterBarVisible() const
194 return m_filterBar
->isVisible();
197 bool DolphinViewContainer::isUrlEditable() const
199 return m_urlNavigator
->isUrlEditable();
202 void DolphinViewContainer::updateProgress(int percent
)
204 if (!m_showProgress
) {
205 // Only show the directory loading progress if the status bar does
206 // not contain another progress information. This means that
207 // the directory loading progress information has the lowest priority.
208 const QString
progressText(m_statusBar
->progressText());
209 const QString
loadingText(i18nc("@info:progress", "Loading folder..."));
210 m_showProgress
= progressText
.isEmpty() || (progressText
== loadingText
);
211 if (m_showProgress
) {
212 m_statusBar
->setProgressText(loadingText
);
213 m_statusBar
->setProgress(0);
217 if (m_showProgress
) {
218 m_statusBar
->setProgress(percent
);
222 void DolphinViewContainer::slotDirListerCompleted()
224 if (m_showProgress
) {
225 m_statusBar
->setProgressText(QString());
226 m_statusBar
->setProgress(100);
227 m_showProgress
= false;
231 QTimer::singleShot(100, this, SLOT(restoreContentsPos()));
234 void DolphinViewContainer::showItemInfo(const KFileItem
& item
)
237 m_statusBar
->clear();
239 m_statusBar
->setMessage(item
.getStatusBarInfo(), DolphinStatusBar::Default
);
243 void DolphinViewContainer::showInfoMessage(const QString
& msg
)
245 m_statusBar
->setMessage(msg
, DolphinStatusBar::Information
);
248 void DolphinViewContainer::showErrorMessage(const QString
& msg
)
250 m_statusBar
->setMessage(msg
, DolphinStatusBar::Error
);
253 void DolphinViewContainer::showOperationCompletedMessage(const QString
& msg
)
255 m_statusBar
->setMessage(msg
, DolphinStatusBar::OperationCompleted
);
258 void DolphinViewContainer::closeFilterBar()
261 emit
showFilterBarChanged(false);
264 QString
DolphinViewContainer::defaultStatusBarText() const
268 m_view
->calculateItemCount(fileCount
, folderCount
);
269 return KIO::itemsSummaryString(fileCount
+ folderCount
,
275 QString
DolphinViewContainer::selectionStatusBarText() const
278 const KFileItemList list
= m_view
->selectedItems();
279 if (list
.isEmpty()) {
280 // when an item is triggered, it is temporary selected but selectedItems()
281 // will return an empty list
287 KIO::filesize_t byteSize
= 0;
288 KFileItemList::const_iterator it
= list
.begin();
289 const KFileItemList::const_iterator end
= list
.end();
291 const KFileItem
& item
= *it
;
296 byteSize
+= item
.size();
301 if (folderCount
> 0) {
302 text
= i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount
);
309 const QString
sizeText(KIO::convertSize(byteSize
));
310 text
+= i18ncp("@info:status", "1 File selected (%2)", "%1 Files selected (%2)", fileCount
, sizeText
);
316 void DolphinViewContainer::showFilterBar(bool show
)
318 Q_ASSERT(m_filterBar
!= 0);
319 m_filterBar
->setVisible(show
);
322 void DolphinViewContainer::updateStatusBar()
324 // As the item count information is less important
325 // in comparison with other messages, it should only
327 // - the status bar is empty or
328 // - shows already the item count information or
329 // - shows only a not very important information
330 // - if any progress is given don't show the item count info at all
331 const QString
msg(m_statusBar
->message());
332 const bool updateStatusBarMsg
= (msg
.isEmpty() ||
333 (msg
== m_statusBar
->defaultText()) ||
334 (m_statusBar
->type() == DolphinStatusBar::Information
)) &&
335 (m_statusBar
->progress() == 100);
337 const QString
text(m_view
->hasSelection() ? selectionStatusBarText() : defaultStatusBarText());
338 m_statusBar
->setDefaultText(text
);
340 if (updateStatusBarMsg
) {
341 m_statusBar
->setMessage(text
, DolphinStatusBar::Default
);
345 void DolphinViewContainer::setNameFilter(const QString
& nameFilter
)
347 m_view
->setNameFilter(nameFilter
);
351 void DolphinViewContainer::openContextMenu(const KFileItem
& item
,
354 DolphinContextMenu
contextMenu(m_mainWindow
, item
, url
);
358 void DolphinViewContainer::saveContentsPos(int x
, int y
)
360 m_urlNavigator
->savePosition(x
, y
);
363 void DolphinViewContainer::restoreContentsPos()
365 if (!url().isEmpty()) {
366 const QPoint pos
= m_urlNavigator
->savedPosition();
367 m_view
->setContentsPosition(pos
.x(), pos
.y());
371 void DolphinViewContainer::activate()
376 void DolphinViewContainer::restoreView(const KUrl
& url
)
378 m_view
->updateView(url
, m_urlNavigator
->savedRootUrl());
381 void DolphinViewContainer::saveRootUrl(const KUrl
& url
)
384 m_urlNavigator
->saveRootUrl(m_view
->rootUrl());
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"