]>
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, m_view
);
149 m_filterBar
= new FilterBar(this);
150 m_filterBar
->setVisible(settings
->filterBar());
151 connect(m_filterBar
, SIGNAL(filterChanged(const QString
&)),
152 this, SLOT(setNameFilter(const QString
&)));
153 connect(m_filterBar
, SIGNAL(closeRequest()),
154 this, SLOT(closeFilterBar()));
156 m_topLayout
->addWidget(m_urlNavigator
);
157 m_topLayout
->addWidget(m_view
);
158 m_topLayout
->addWidget(m_filterBar
);
159 m_topLayout
->addWidget(m_statusBar
);
162 DolphinViewContainer::~DolphinViewContainer()
164 m_dirLister
->disconnect();
168 delete m_dolphinModel
;
170 m_dirLister
= 0; // deleted by m_dolphinModel
173 void DolphinViewContainer::setUrl(const KUrl
& newUrl
)
175 m_urlNavigator
->setUrl(newUrl
);
177 // Temporary disable the 'File'->'Create New...' menu until
178 // the write permissions can be checked in a fast way at
179 // DolphinViewContainer::slotDirListerCompleted().
180 m_mainWindow
->newMenu()->menu()->setEnabled(false);
183 const KUrl
& DolphinViewContainer::url() const
185 return m_urlNavigator
->url();
188 void DolphinViewContainer::setActive(bool active
)
190 m_urlNavigator
->setActive(active
);
191 m_view
->setActive(active
);
194 bool DolphinViewContainer::isActive() const
196 Q_ASSERT(m_view
->isActive() == m_urlNavigator
->isActive());
197 return m_view
->isActive();
200 bool DolphinViewContainer::isFilterBarVisible() const
202 return m_filterBar
->isVisible();
205 bool DolphinViewContainer::isUrlEditable() const
207 return m_urlNavigator
->isUrlEditable();
210 void DolphinViewContainer::updateProgress(int percent
)
212 if (!m_showProgress
) {
213 // Only show the directory loading progress if the status bar does
214 // not contain another progress information. This means that
215 // the directory loading progress information has the lowest priority.
216 const QString
progressText(m_statusBar
->progressText());
217 const QString
loadingText(i18nc("@info:progress", "Loading folder..."));
218 m_showProgress
= progressText
.isEmpty() || (progressText
== loadingText
);
219 if (m_showProgress
) {
220 m_statusBar
->setProgressText(loadingText
);
221 m_statusBar
->setProgress(0);
225 if (m_showProgress
) {
226 m_statusBar
->setProgress(percent
);
230 void DolphinViewContainer::slotDirListerCompleted()
232 if (m_showProgress
) {
233 m_statusBar
->setProgressText(QString());
234 m_statusBar
->setProgress(100);
235 m_showProgress
= false;
239 QTimer::singleShot(100, this, SLOT(restoreContentsPos()));
241 // Enable the 'File'->'Create New...' menu only if the directory
243 KMenu
* createNew
= m_mainWindow
->newMenu()->menu();
244 KFileItem item
= m_dirLister
->rootItem();
246 // it is unclear whether writing is supported
247 createNew
->setEnabled(true);
249 KonqFileItemCapabilities
capabilities(KFileItemList() << item
);
250 createNew
->setEnabled(capabilities
.supportsWriting());
254 void DolphinViewContainer::showItemInfo(const KFileItem
& item
)
257 m_statusBar
->clear();
259 m_statusBar
->setMessage(item
.getStatusBarInfo(), DolphinStatusBar::Default
);
263 void DolphinViewContainer::showInfoMessage(const QString
& msg
)
265 m_statusBar
->setMessage(msg
, DolphinStatusBar::Information
);
268 void DolphinViewContainer::showErrorMessage(const QString
& msg
)
270 m_statusBar
->setMessage(msg
, DolphinStatusBar::Error
);
273 void DolphinViewContainer::showOperationCompletedMessage(const QString
& msg
)
275 m_statusBar
->setMessage(msg
, DolphinStatusBar::OperationCompleted
);
278 void DolphinViewContainer::closeFilterBar()
281 m_filterBar
->clear();
282 emit
showFilterBarChanged(false);
285 void DolphinViewContainer::showFilterBar(bool show
)
287 Q_ASSERT(m_filterBar
!= 0);
288 m_filterBar
->setVisible(show
);
291 void DolphinViewContainer::updateStatusBar()
293 // As the item count information is less important
294 // in comparison with other messages, it should only
296 // - the status bar is empty or
297 // - shows already the item count information or
298 // - shows only a not very important information
299 // - if any progress is given don't show the item count info at all
300 const QString
msg(m_statusBar
->message());
301 const bool updateStatusBarMsg
= (msg
.isEmpty() ||
302 (msg
== m_statusBar
->defaultText()) ||
303 (m_statusBar
->type() == DolphinStatusBar::Information
)) &&
304 (m_statusBar
->progress() == 100);
306 const QString
text(m_view
->statusBarText());
307 m_statusBar
->setDefaultText(text
);
309 if (updateStatusBarMsg
) {
310 m_statusBar
->setMessage(text
, DolphinStatusBar::Default
);
314 void DolphinViewContainer::setNameFilter(const QString
& nameFilter
)
316 m_view
->setNameFilter(nameFilter
);
320 void DolphinViewContainer::openContextMenu(const KFileItem
& item
,
323 DolphinContextMenu
contextMenu(m_mainWindow
, item
, url
);
327 void DolphinViewContainer::saveContentsPos(int x
, int y
)
329 m_urlNavigator
->savePosition(x
, y
);
332 void DolphinViewContainer::restoreContentsPos()
334 if (!url().isEmpty()) {
335 const QPoint pos
= m_urlNavigator
->savedPosition();
336 m_view
->setContentsPosition(pos
.x(), pos
.y());
340 void DolphinViewContainer::activate()
345 void DolphinViewContainer::restoreView(const KUrl
& url
)
347 m_view
->updateView(url
, m_urlNavigator
->savedRootUrl());
350 void DolphinViewContainer::saveRootUrl(const KUrl
& url
)
353 m_urlNavigator
->saveRootUrl(m_view
->rootUrl());
356 void DolphinViewContainer::dropUrls(const KUrl
& destination
, QDropEvent
* event
)
358 DolphinDropController::dropUrls(KFileItem(), destination
, event
, this);
361 void DolphinViewContainer::slotItemTriggered(const KFileItem
& item
)
363 KUrl url
= item
.targetUrl();
370 const GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
371 const bool browseThroughArchives
= settings
->browseThroughArchives();
372 if (browseThroughArchives
&& item
.isFile() && url
.isLocalFile()) {
373 // Generic mechanism for redirecting to tar:/<path>/ when clicking on a tar file,
374 // zip:/<path>/ when clicking on a zip file, etc.
375 // The .protocol file specifies the mimetype that the kioslave handles.
376 // Note that we don't use mimetype inheritance since we don't want to
377 // open OpenDocument files as zip folders...
378 const QString protocol
= KProtocolManager::protocolForArchiveMimetype(item
.mimetype());
379 if (!protocol
.isEmpty()) {
380 url
.setProtocol(protocol
);
389 #include "dolphinviewcontainer.moc"