]>
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 void DolphinViewContainer::refresh()
203 m_statusBar
->refresh();
206 bool DolphinViewContainer::isFilterBarVisible() const
208 return m_filterBar
->isVisible();
211 bool DolphinViewContainer::isUrlEditable() const
213 return m_urlNavigator
->isUrlEditable();
216 void DolphinViewContainer::updateProgress(int percent
)
218 if (!m_showProgress
) {
219 // Only show the directory loading progress if the status bar does
220 // not contain another progress information. This means that
221 // the directory loading progress information has the lowest priority.
222 const QString
progressText(m_statusBar
->progressText());
223 const QString
loadingText(i18nc("@info:progress", "Loading folder..."));
224 m_showProgress
= progressText
.isEmpty() || (progressText
== loadingText
);
225 if (m_showProgress
) {
226 m_statusBar
->setProgressText(loadingText
);
227 m_statusBar
->setProgress(0);
231 if (m_showProgress
) {
232 m_statusBar
->setProgress(percent
);
236 void DolphinViewContainer::slotDirListerCompleted()
238 if (m_showProgress
) {
239 m_statusBar
->setProgressText(QString());
240 m_statusBar
->setProgress(100);
241 m_showProgress
= false;
245 QTimer::singleShot(100, this, SLOT(restoreContentsPos()));
247 // Enable the 'File'->'Create New...' menu only if the directory
249 KMenu
* createNew
= m_mainWindow
->newMenu()->menu();
250 KFileItem item
= m_dirLister
->rootItem();
252 // it is unclear whether writing is supported
253 createNew
->setEnabled(true);
255 KonqFileItemCapabilities
capabilities(KFileItemList() << item
);
256 createNew
->setEnabled(capabilities
.supportsWriting());
260 void DolphinViewContainer::showItemInfo(const KFileItem
& item
)
263 m_statusBar
->clear();
265 m_statusBar
->setMessage(item
.getStatusBarInfo(), DolphinStatusBar::Default
);
269 void DolphinViewContainer::showInfoMessage(const QString
& msg
)
271 m_statusBar
->setMessage(msg
, DolphinStatusBar::Information
);
274 void DolphinViewContainer::showErrorMessage(const QString
& msg
)
276 m_statusBar
->setMessage(msg
, DolphinStatusBar::Error
);
279 void DolphinViewContainer::showOperationCompletedMessage(const QString
& msg
)
281 m_statusBar
->setMessage(msg
, DolphinStatusBar::OperationCompleted
);
284 void DolphinViewContainer::closeFilterBar()
287 m_filterBar
->clear();
288 emit
showFilterBarChanged(false);
291 void DolphinViewContainer::showFilterBar(bool show
)
293 Q_ASSERT(m_filterBar
!= 0);
294 m_filterBar
->setVisible(show
);
297 void DolphinViewContainer::updateStatusBar()
299 // As the item count information is less important
300 // in comparison with other messages, it should only
302 // - the status bar is empty or
303 // - shows already the item count information or
304 // - shows only a not very important information
305 // - if any progress is given don't show the item count info at all
306 const QString
msg(m_statusBar
->message());
307 const bool updateStatusBarMsg
= (msg
.isEmpty() ||
308 (msg
== m_statusBar
->defaultText()) ||
309 (m_statusBar
->type() == DolphinStatusBar::Information
)) &&
310 (m_statusBar
->progress() == 100);
312 const QString
text(m_view
->statusBarText());
313 m_statusBar
->setDefaultText(text
);
315 if (updateStatusBarMsg
) {
316 m_statusBar
->setMessage(text
, DolphinStatusBar::Default
);
320 void DolphinViewContainer::setNameFilter(const QString
& nameFilter
)
322 m_view
->setNameFilter(nameFilter
);
326 void DolphinViewContainer::openContextMenu(const KFileItem
& item
,
329 DolphinContextMenu
contextMenu(m_mainWindow
, item
, url
);
333 void DolphinViewContainer::saveContentsPos(int x
, int y
)
335 m_urlNavigator
->savePosition(x
, y
);
338 void DolphinViewContainer::restoreContentsPos()
340 if (!url().isEmpty()) {
341 const QPoint pos
= m_urlNavigator
->savedPosition();
342 m_view
->setContentsPosition(pos
.x(), pos
.y());
346 void DolphinViewContainer::activate()
351 void DolphinViewContainer::restoreView(const KUrl
& url
)
353 m_view
->updateView(url
, m_urlNavigator
->savedRootUrl());
356 void DolphinViewContainer::saveRootUrl(const KUrl
& url
)
359 m_urlNavigator
->saveRootUrl(m_view
->rootUrl());
362 void DolphinViewContainer::dropUrls(const KUrl
& destination
, QDropEvent
* event
)
364 DolphinDropController::dropUrls(KFileItem(), destination
, event
, this);
367 void DolphinViewContainer::slotItemTriggered(const KFileItem
& item
)
369 KUrl url
= item
.targetUrl();
376 const GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
377 const bool browseThroughArchives
= settings
->browseThroughArchives();
378 if (browseThroughArchives
&& item
.isFile() && url
.isLocalFile()) {
379 // Generic mechanism for redirecting to tar:/<path>/ when clicking on a tar file,
380 // zip:/<path>/ when clicking on a zip file, etc.
381 // The .protocol file specifies the mimetype that the kioslave handles.
382 // Note that we don't use mimetype inheritance since we don't want to
383 // open OpenDocument files as zip folders...
384 const QString protocol
= KProtocolManager::protocolForArchiveMimetype(item
.mimetype());
385 if (!protocol
.isEmpty()) {
386 url
.setProtocol(protocol
);
395 #include "dolphinviewcontainer.moc"