]>
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
),
77 m_topLayout
= new QVBoxLayout(this);
78 m_topLayout
->setSpacing(0);
79 m_topLayout
->setMargin(0);
81 m_urlNavigator
= new KUrlNavigator(DolphinSettings::instance().placesModel(), url
, this);
82 connect(m_urlNavigator
, SIGNAL(urlsDropped(const KUrl::List
&, const KUrl
&)),
83 m_mainWindow
, SLOT(dropUrls(const KUrl::List
&, const KUrl
&)));
84 connect(m_urlNavigator
, SIGNAL(activated()),
85 this, SLOT(activate()));
87 const GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
88 m_urlNavigator
->setUrlEditable(settings
->editableUrl());
89 m_urlNavigator
->setHomeUrl(settings
->homeUrl());
91 m_dirLister
= new DolphinDirLister();
92 m_dirLister
->setAutoUpdate(true);
93 m_dirLister
->setMainWindow(window());
94 m_dirLister
->setDelayedMimeTypes(true);
96 m_dolphinModel
= new DolphinModel(this);
97 m_dolphinModel
->setDirLister(m_dirLister
);
98 m_dolphinModel
->setDropsAllowed(DolphinModel::DropOnDirectory
);
100 m_proxyModel
= new DolphinSortFilterProxyModel(this);
101 m_proxyModel
->setSourceModel(m_dolphinModel
);
102 m_proxyModel
->setFilterCaseSensitivity(Qt::CaseInsensitive
);
104 connect(m_dirLister
, SIGNAL(clear()),
105 this, SLOT(updateStatusBar()));
106 connect(m_dirLister
, SIGNAL(percent(int)),
107 this, SLOT(updateProgress(int)));
108 connect(m_dirLister
, SIGNAL(deleteItem(const KFileItem
&)),
109 this, SLOT(updateStatusBar()));
110 connect(m_dirLister
, SIGNAL(completed()),
111 this, SLOT(slotDirListerCompleted()));
112 connect(m_dirLister
, SIGNAL(infoMessage(const QString
&)),
113 this, SLOT(showInfoMessage(const QString
&)));
114 connect(m_dirLister
, SIGNAL(errorMessage(const QString
&)),
115 this, SLOT(showErrorMessage(const QString
&)));
117 m_view
= new DolphinView(this,
122 connect(m_view
, SIGNAL(urlChanged(const KUrl
&)),
123 m_urlNavigator
, SLOT(setUrl(const KUrl
&)));
124 connect(m_view
, SIGNAL(requestContextMenu(KFileItem
, const KUrl
&)),
125 this, SLOT(openContextMenu(KFileItem
, const KUrl
&)));
126 connect(m_view
, SIGNAL(contentsMoved(int, int)),
127 this, SLOT(saveContentsPos(int, int)));
128 connect(m_view
, SIGNAL(requestItemInfo(KFileItem
)),
129 this, SLOT(showItemInfo(KFileItem
)));
130 connect(m_view
, SIGNAL(errorMessage(const QString
&)),
131 this, SLOT(showErrorMessage(const QString
&)));
132 connect(m_view
, SIGNAL(infoMessage(const QString
&)),
133 this, SLOT(showInfoMessage(const QString
&)));
134 connect(m_view
, SIGNAL(operationCompletedMessage(const QString
&)),
135 this, SLOT(showOperationCompletedMessage(const QString
&)));
136 connect(m_view
, SIGNAL(itemTriggered(KFileItem
)),
137 this, SLOT(slotItemTriggered(KFileItem
)));
138 connect(m_view
, SIGNAL(startedPathLoading(const KUrl
&)),
139 this, SLOT(saveRootUrl(const KUrl
&)));
141 connect(m_urlNavigator
, SIGNAL(urlChanged(const KUrl
&)),
142 this, SLOT(restoreView(const KUrl
&)));
144 m_statusBar
= new DolphinStatusBar(this, url
);
145 connect(m_view
, SIGNAL(urlChanged(const KUrl
&)),
146 m_statusBar
, SLOT(updateSpaceInfoContent(const KUrl
&)));
148 m_filterBar
= new FilterBar(this);
149 m_filterBar
->setVisible(settings
->filterBar());
150 connect(m_filterBar
, SIGNAL(filterChanged(const QString
&)),
151 this, SLOT(setNameFilter(const QString
&)));
152 connect(m_filterBar
, SIGNAL(closeRequest()),
153 this, SLOT(closeFilterBar()));
155 m_topLayout
->addWidget(m_urlNavigator
);
156 m_topLayout
->addWidget(m_view
);
157 m_topLayout
->addWidget(m_filterBar
);
158 m_topLayout
->addWidget(m_statusBar
);
161 DolphinViewContainer::~DolphinViewContainer()
163 m_dirLister
->disconnect();
167 delete m_dolphinModel
;
169 m_dirLister
= 0; // deleted by m_dolphinModel
172 void DolphinViewContainer::setUrl(const KUrl
& newUrl
)
174 if (newUrl
!= m_currentUrl
) {
175 m_previousUrl
= m_currentUrl
;
176 m_currentUrl
= newUrl
;
177 m_urlNavigator
->setUrl(newUrl
);
181 const KUrl
& DolphinViewContainer::url() const
186 void DolphinViewContainer::setActive(bool active
)
188 m_urlNavigator
->setActive(active
);
189 m_view
->setActive(active
);
192 bool DolphinViewContainer::isActive() const
194 Q_ASSERT(m_view
->isActive() == m_urlNavigator
->isActive());
195 return m_view
->isActive();
198 bool DolphinViewContainer::isFilterBarVisible() const
200 return m_filterBar
->isVisible();
203 bool DolphinViewContainer::isUrlEditable() const
205 return m_urlNavigator
->isUrlEditable();
208 void DolphinViewContainer::updateProgress(int percent
)
210 if (!m_showProgress
) {
211 // Only show the directory loading progress if the status bar does
212 // not contain another progress information. This means that
213 // the directory loading progress information has the lowest priority.
214 const QString
progressText(m_statusBar
->progressText());
215 const QString
loadingText(i18nc("@info:progress", "Loading folder..."));
216 m_showProgress
= progressText
.isEmpty() || (progressText
== loadingText
);
217 if (m_showProgress
) {
218 m_statusBar
->setProgressText(loadingText
);
219 m_statusBar
->setProgress(0);
223 if (m_showProgress
) {
224 m_statusBar
->setProgress(percent
);
228 void DolphinViewContainer::slotDirListerCompleted()
230 if (m_showProgress
) {
231 m_statusBar
->setProgressText(QString());
232 m_statusBar
->setProgress(100);
233 m_showProgress
= false;
237 m_view
->setCurrentItem(m_previousUrl
);
238 QTimer::singleShot(100, this, SLOT(restoreContentsPos()));
241 void DolphinViewContainer::showItemInfo(const KFileItem
& item
)
244 m_statusBar
->clear();
246 m_statusBar
->setMessage(item
.getStatusBarInfo(), DolphinStatusBar::Default
);
250 void DolphinViewContainer::showInfoMessage(const QString
& msg
)
252 m_statusBar
->setMessage(msg
, DolphinStatusBar::Information
);
255 void DolphinViewContainer::showErrorMessage(const QString
& msg
)
257 m_statusBar
->setMessage(msg
, DolphinStatusBar::Error
);
260 void DolphinViewContainer::showOperationCompletedMessage(const QString
& msg
)
262 m_statusBar
->setMessage(msg
, DolphinStatusBar::OperationCompleted
);
265 void DolphinViewContainer::closeFilterBar()
268 emit
showFilterBarChanged(false);
271 QString
DolphinViewContainer::defaultStatusBarText() const
275 m_view
->calculateItemCount(fileCount
, folderCount
);
276 return KIO::itemsSummaryString(fileCount
+ folderCount
,
282 QString
DolphinViewContainer::selectionStatusBarText() const
285 const KFileItemList list
= m_view
->selectedItems();
286 if (list
.isEmpty()) {
287 // when an item is triggered, it is temporary selected but selectedItems()
288 // will return an empty list
294 KIO::filesize_t byteSize
= 0;
295 KFileItemList::const_iterator it
= list
.begin();
296 const KFileItemList::const_iterator end
= list
.end();
298 const KFileItem
& item
= *it
;
303 byteSize
+= item
.size();
308 if (folderCount
> 0) {
309 text
= i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount
);
316 const QString
sizeText(KIO::convertSize(byteSize
));
317 text
+= i18ncp("@info:status", "1 File selected (%2)", "%1 Files selected (%2)", fileCount
, sizeText
);
323 void DolphinViewContainer::showFilterBar(bool show
)
325 Q_ASSERT(m_filterBar
!= 0);
326 m_filterBar
->setVisible(show
);
329 void DolphinViewContainer::updateStatusBar()
331 // As the item count information is less important
332 // in comparison with other messages, it should only
334 // - the status bar is empty or
335 // - shows already the item count information or
336 // - shows only a not very important information
337 // - if any progress is given don't show the item count info at all
338 const QString
msg(m_statusBar
->message());
339 const bool updateStatusBarMsg
= (msg
.isEmpty() ||
340 (msg
== m_statusBar
->defaultText()) ||
341 (m_statusBar
->type() == DolphinStatusBar::Information
)) &&
342 (m_statusBar
->progress() == 100);
344 const QString
text(m_view
->hasSelection() ? selectionStatusBarText() : defaultStatusBarText());
345 m_statusBar
->setDefaultText(text
);
347 if (updateStatusBarMsg
) {
348 m_statusBar
->setMessage(text
, DolphinStatusBar::Default
);
352 void DolphinViewContainer::setNameFilter(const QString
& nameFilter
)
354 m_view
->setNameFilter(nameFilter
);
358 void DolphinViewContainer::openContextMenu(const KFileItem
& item
,
361 DolphinContextMenu
contextMenu(m_mainWindow
, item
, url
);
365 void DolphinViewContainer::saveContentsPos(int x
, int y
)
367 m_urlNavigator
->savePosition(x
, y
);
370 void DolphinViewContainer::restoreContentsPos()
372 if (!url().isEmpty()) {
373 const QPoint pos
= m_urlNavigator
->savedPosition();
374 m_view
->setContentsPosition(pos
.x(), pos
.y());
378 void DolphinViewContainer::activate()
383 void DolphinViewContainer::restoreView(const KUrl
& url
)
385 m_view
->updateView(url
, m_urlNavigator
->savedRootUrl());
388 void DolphinViewContainer::saveRootUrl(const KUrl
& url
)
391 m_urlNavigator
->saveRootUrl(m_view
->rootUrl());
394 void DolphinViewContainer::slotItemTriggered(const KFileItem
& item
)
396 KUrl url
= item
.targetUrl();
403 const GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
404 const bool browseThroughArchives
= settings
->browseThroughArchives();
405 if (browseThroughArchives
&& item
.isFile() && url
.isLocalFile()) {
406 // Generic mechanism for redirecting to tar:/<path>/ when clicking on a tar file,
407 // zip:/<path>/ when clicking on a zip file, etc.
408 // The .protocol file specifies the mimetype that the kioslave handles.
409 // Note that we don't use mimetype inheritance since we don't want to
410 // open OpenDocument files as zip folders...
411 const QString protocol
= KProtocolManager::protocolForArchiveMimetype(item
.mimetype());
412 if (!protocol
.isEmpty()) {
413 url
.setProtocol(protocol
);
422 #include "dolphinviewcontainer.moc"