2007-06-07 21:10:48 +00:00
|
|
|
/***************************************************************************
|
2011-02-04 14:57:33 +00:00
|
|
|
* Copyright (C) 2007 by Peter Penz <peter.penz19@gmail.com> *
|
2007-06-07 21:10:48 +00:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the *
|
|
|
|
* Free Software Foundation, Inc., *
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "dolphinviewcontainer.h"
|
2011-02-04 14:43:21 +00:00
|
|
|
#include <KProtocolManager>
|
2007-06-07 21:10:48 +00:00
|
|
|
|
2011-02-04 14:49:45 +00:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QKeyEvent>
|
|
|
|
#include <QItemSelection>
|
|
|
|
#include <QBoxLayout>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QScrollBar>
|
2007-06-07 21:10:48 +00:00
|
|
|
|
2011-02-04 14:43:21 +00:00
|
|
|
#include <KDesktopFile>
|
|
|
|
#include <KFileItemDelegate>
|
|
|
|
#include <KFilePlacesModel>
|
|
|
|
#include <KGlobalSettings>
|
|
|
|
#include <KLocale>
|
|
|
|
#include <KIconEffect>
|
|
|
|
#include <KIO/NetAccess>
|
|
|
|
#include <KIO/PreviewJob>
|
|
|
|
#include <KMenu>
|
2008-07-19 16:51:29 +00:00
|
|
|
#include <knewmenu.h>
|
2007-06-07 21:10:48 +00:00
|
|
|
#include <konqmimedata.h>
|
|
|
|
#include <konq_operations.h>
|
2011-02-04 14:43:21 +00:00
|
|
|
#include <KShell>
|
|
|
|
#include <KUrl>
|
|
|
|
#include <KUrlComboBox>
|
|
|
|
#include <KUrlNavigator>
|
|
|
|
#include <KRun>
|
2007-06-07 21:10:48 +00:00
|
|
|
|
2010-03-30 20:19:32 +00:00
|
|
|
#include "dolphin_generalsettings.h"
|
2007-06-07 21:10:48 +00:00
|
|
|
#include "dolphinmainwindow.h"
|
2010-07-24 21:45:49 +00:00
|
|
|
#include "filterbar/filterbar.h"
|
2010-07-24 16:37:07 +00:00
|
|
|
#include "search/dolphinsearchbox.h"
|
2010-03-30 20:19:32 +00:00
|
|
|
#include "settings/dolphinsettings.h"
|
2009-08-01 20:01:51 +00:00
|
|
|
#include "statusbar/dolphinstatusbar.h"
|
2010-07-24 21:45:49 +00:00
|
|
|
#include "views/dolphincolumnview.h"
|
|
|
|
#include "views/dolphindetailsview.h"
|
2010-07-24 22:08:30 +00:00
|
|
|
#include "views/draganddrophelper.h"
|
2010-07-24 21:45:49 +00:00
|
|
|
#include "views/dolphiniconsview.h"
|
2010-07-24 22:08:30 +00:00
|
|
|
#include "views/dolphinmodel.h"
|
2010-07-24 21:45:49 +00:00
|
|
|
#include "views/dolphinviewcontroller.h"
|
|
|
|
#include "views/viewmodecontroller.h"
|
2010-07-24 22:08:30 +00:00
|
|
|
#include "views/viewproperties.h"
|
2007-06-07 21:10:48 +00:00
|
|
|
|
2010-01-25 07:58:24 +00:00
|
|
|
DolphinViewContainer::DolphinViewContainer(const KUrl& url, QWidget* parent) :
|
2007-06-07 21:10:48 +00:00
|
|
|
QWidget(parent),
|
|
|
|
m_topLayout(0),
|
|
|
|
m_urlNavigator(0),
|
2010-07-24 16:37:07 +00:00
|
|
|
m_searchBox(0),
|
2007-06-07 21:10:48 +00:00
|
|
|
m_view(0),
|
|
|
|
m_filterBar(0),
|
|
|
|
m_statusBar(0),
|
2009-07-11 17:48:05 +00:00
|
|
|
m_statusBarTimer(0),
|
2010-12-15 18:55:25 +00:00
|
|
|
m_statusBarTimestamp()
|
2007-06-07 21:10:48 +00:00
|
|
|
{
|
|
|
|
hide();
|
2008-05-07 20:50:27 +00:00
|
|
|
|
2007-06-07 21:10:48 +00:00
|
|
|
m_topLayout = new QVBoxLayout(this);
|
|
|
|
m_topLayout->setSpacing(0);
|
|
|
|
m_topLayout->setMargin(0);
|
|
|
|
|
|
|
|
m_urlNavigator = new KUrlNavigator(DolphinSettings::instance().placesModel(), url, this);
|
2008-10-01 21:39:35 +00:00
|
|
|
connect(m_urlNavigator, SIGNAL(urlsDropped(const KUrl&, QDropEvent*)),
|
|
|
|
this, SLOT(dropUrls(const KUrl&, QDropEvent*)));
|
2007-06-13 17:08:39 +00:00
|
|
|
connect(m_urlNavigator, SIGNAL(activated()),
|
|
|
|
this, SLOT(activate()));
|
2009-02-20 16:55:25 +00:00
|
|
|
connect(m_urlNavigator->editor(), SIGNAL(completionModeChanged(KGlobalSettings::Completion)),
|
|
|
|
this, SLOT(saveUrlCompletionMode(KGlobalSettings::Completion)));
|
2007-06-07 21:10:48 +00:00
|
|
|
|
|
|
|
const GeneralSettings* settings = DolphinSettings::instance().generalSettings();
|
|
|
|
m_urlNavigator->setUrlEditable(settings->editableUrl());
|
2008-08-03 14:53:30 +00:00
|
|
|
m_urlNavigator->setShowFullPath(settings->showFullPath());
|
2010-01-25 07:58:24 +00:00
|
|
|
m_urlNavigator->setHomeUrl(KUrl(settings->homeUrl()));
|
2009-02-20 16:55:25 +00:00
|
|
|
KUrlComboBox* editor = m_urlNavigator->editor();
|
|
|
|
editor->setCompletionMode(KGlobalSettings::Completion(settings->urlCompletionMode()));
|
2007-06-07 21:10:48 +00:00
|
|
|
|
2010-07-24 16:37:07 +00:00
|
|
|
m_searchBox = new DolphinSearchBox(this);
|
|
|
|
m_searchBox->hide();
|
|
|
|
connect(m_searchBox, SIGNAL(closeRequest()), this, SLOT(closeSearchBox()));
|
|
|
|
connect(m_searchBox, SIGNAL(search(QString)), this, SLOT(startSearching(QString)));
|
2010-10-10 16:13:24 +00:00
|
|
|
connect(m_searchBox, SIGNAL(returnPressed(QString)), this, SLOT(requestFocus()));
|
2010-07-24 16:37:07 +00:00
|
|
|
|
2011-01-09 13:58:35 +00:00
|
|
|
m_view = new DolphinView(url, this);
|
|
|
|
connect(m_view, SIGNAL(urlChanged(const KUrl&)), m_urlNavigator, SLOT(setUrl(const KUrl&)));
|
|
|
|
connect(m_view, SIGNAL(writeStateChanged(bool)), this, SIGNAL(writeStateChanged(bool)));
|
|
|
|
connect(m_view, SIGNAL(requestItemInfo(KFileItem)), this, SLOT(showItemInfo(KFileItem)));
|
|
|
|
connect(m_view, SIGNAL(errorMessage(const QString&)), this, SLOT(showErrorMessage(const QString&)));
|
|
|
|
connect(m_view, SIGNAL(infoMessage(const QString&)), this, SLOT(showInfoMessage(const QString&)));
|
|
|
|
connect(m_view, SIGNAL(itemTriggered(KFileItem)), this, SLOT(slotItemTriggered(KFileItem)));
|
|
|
|
connect(m_view, SIGNAL(redirection(KUrl, KUrl)), this, SLOT(redirect(KUrl, KUrl)));
|
|
|
|
connect(m_view, SIGNAL(startedPathLoading(KUrl)), this, SLOT(slotStartedPathLoading()));
|
|
|
|
connect(m_view, SIGNAL(finishedPathLoading(KUrl)), this, SLOT(slotFinishedPathLoading()));
|
|
|
|
connect(m_view, SIGNAL(itemCountChanged()), this, SLOT(delayedStatusBarUpdate()));
|
|
|
|
connect(m_view, SIGNAL(pathLoadingProgress(int)), this, SLOT(updateProgress(int)));
|
|
|
|
connect(m_view, SIGNAL(infoMessage(const QString&)), this, SLOT(showInfoMessage(const QString&)));
|
|
|
|
connect(m_view, SIGNAL(errorMessage(const QString&)), this, SLOT(showErrorMessage(const QString&)));
|
|
|
|
connect(m_view, SIGNAL(urlIsFileError(const KUrl&)), this, SLOT(openFile(const KUrl&)));
|
|
|
|
connect(m_view, SIGNAL(selectionChanged(const KFileItemList&)), this, SLOT(delayedStatusBarUpdate()));
|
|
|
|
connect(m_view, SIGNAL(operationCompletedMessage(const QString&)), this, SLOT(showOperationCompletedMessage(const QString&)));
|
2007-06-07 21:10:48 +00:00
|
|
|
|
|
|
|
connect(m_urlNavigator, SIGNAL(urlChanged(const KUrl&)),
|
2010-01-25 07:58:24 +00:00
|
|
|
this, SLOT(slotUrlNavigatorLocationChanged(const KUrl&)));
|
|
|
|
connect(m_urlNavigator, SIGNAL(urlAboutToBeChanged(const KUrl&)),
|
|
|
|
this, SLOT(saveViewState()));
|
2009-06-08 05:55:46 +00:00
|
|
|
connect(m_urlNavigator, SIGNAL(historyChanged()),
|
|
|
|
this, SLOT(slotHistoryChanged()));
|
2007-06-07 21:10:48 +00:00
|
|
|
|
2010-01-06 19:13:07 +00:00
|
|
|
// initialize status bar
|
2008-10-05 21:17:06 +00:00
|
|
|
m_statusBar = new DolphinStatusBar(this, m_view);
|
2010-11-20 17:17:35 +00:00
|
|
|
connect(m_statusBar, SIGNAL(stopPressed()), this, SLOT(stopLoading()));
|
|
|
|
|
2009-07-11 17:48:05 +00:00
|
|
|
m_statusBarTimer = new QTimer(this);
|
|
|
|
m_statusBarTimer->setSingleShot(true);
|
|
|
|
m_statusBarTimer->setInterval(300);
|
|
|
|
connect(m_statusBarTimer, SIGNAL(timeout()),
|
|
|
|
this, SLOT(updateStatusBar()));
|
2007-06-07 21:10:48 +00:00
|
|
|
|
2010-01-06 19:13:07 +00:00
|
|
|
KIO::FileUndoManager* undoManager = KIO::FileUndoManager::self();
|
|
|
|
connect(undoManager, SIGNAL(jobRecordingFinished(CommandType)),
|
|
|
|
this, SLOT(delayedStatusBarUpdate()));
|
|
|
|
|
|
|
|
// initialize filter bar
|
2007-06-07 21:10:48 +00:00
|
|
|
m_filterBar = new FilterBar(this);
|
|
|
|
m_filterBar->setVisible(settings->filterBar());
|
|
|
|
connect(m_filterBar, SIGNAL(filterChanged(const QString&)),
|
2007-10-09 22:32:54 +00:00
|
|
|
this, SLOT(setNameFilter(const QString&)));
|
2007-06-07 21:10:48 +00:00
|
|
|
connect(m_filterBar, SIGNAL(closeRequest()),
|
|
|
|
this, SLOT(closeFilterBar()));
|
2009-02-16 12:00:19 +00:00
|
|
|
connect(m_view, SIGNAL(urlChanged(const KUrl&)),
|
|
|
|
m_filterBar, SLOT(clear()));
|
2007-06-07 21:10:48 +00:00
|
|
|
|
|
|
|
m_topLayout->addWidget(m_urlNavigator);
|
2010-07-24 16:37:07 +00:00
|
|
|
m_topLayout->addWidget(m_searchBox);
|
2007-06-07 21:10:48 +00:00
|
|
|
m_topLayout->addWidget(m_view);
|
|
|
|
m_topLayout->addWidget(m_filterBar);
|
|
|
|
m_topLayout->addWidget(m_statusBar);
|
2010-07-24 16:37:07 +00:00
|
|
|
|
|
|
|
setSearchModeEnabled(isSearchUrl(url));
|
2007-06-07 21:10:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DolphinViewContainer::~DolphinViewContainer()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-01-25 07:58:24 +00:00
|
|
|
KUrl DolphinViewContainer::url() const
|
2007-06-07 21:10:48 +00:00
|
|
|
{
|
2010-01-25 07:58:24 +00:00
|
|
|
return m_urlNavigator->locationUrl();
|
2007-06-07 21:10:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinViewContainer::setActive(bool active)
|
|
|
|
{
|
|
|
|
m_urlNavigator->setActive(active);
|
|
|
|
m_view->setActive(active);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DolphinViewContainer::isActive() const
|
|
|
|
{
|
|
|
|
Q_ASSERT(m_view->isActive() == m_urlNavigator->isActive());
|
|
|
|
return m_view->isActive();
|
|
|
|
}
|
|
|
|
|
2008-10-06 18:15:53 +00:00
|
|
|
void DolphinViewContainer::refresh()
|
|
|
|
{
|
2010-11-05 17:02:58 +00:00
|
|
|
GeneralSettings* settings = DolphinSettings::instance().generalSettings();
|
|
|
|
if (settings->modifiedStartupSettings()) {
|
|
|
|
// The startup settings should only get applied if they have been
|
|
|
|
// modified by the user. Otherwise keep the (possibly) different current
|
|
|
|
// settings of the URL navigator and the filterbar.
|
|
|
|
m_urlNavigator->setUrlEditable(settings->editableUrl());
|
|
|
|
m_urlNavigator->setShowFullPath(settings->showFullPath());
|
2010-11-05 17:12:35 +00:00
|
|
|
setFilterBarVisible(settings->filterBar());
|
2010-11-05 17:02:58 +00:00
|
|
|
}
|
|
|
|
|
2008-10-06 18:15:53 +00:00
|
|
|
m_view->refresh();
|
|
|
|
m_statusBar->refresh();
|
|
|
|
}
|
|
|
|
|
2007-06-07 21:10:48 +00:00
|
|
|
bool DolphinViewContainer::isFilterBarVisible() const
|
|
|
|
{
|
|
|
|
return m_filterBar->isVisible();
|
|
|
|
}
|
|
|
|
|
2010-07-24 16:37:07 +00:00
|
|
|
void DolphinViewContainer::setSearchModeEnabled(bool enabled)
|
|
|
|
{
|
2010-10-27 17:08:02 +00:00
|
|
|
if (enabled == isSearchModeEnabled()) {
|
2010-12-19 12:03:46 +00:00
|
|
|
if (enabled && !m_searchBox->hasFocus()) {
|
|
|
|
m_searchBox->setFocus();
|
|
|
|
m_searchBox->selectAll();
|
|
|
|
}
|
2010-10-27 17:08:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-07-24 16:37:07 +00:00
|
|
|
m_searchBox->setVisible(enabled);
|
|
|
|
m_urlNavigator->setVisible(!enabled);
|
|
|
|
|
|
|
|
if (enabled) {
|
2011-02-04 21:13:50 +00:00
|
|
|
m_searchBox->setText(QString());
|
2011-02-04 19:55:52 +00:00
|
|
|
|
2010-11-01 12:31:44 +00:00
|
|
|
// Remember the most recent non-search URL as search path
|
|
|
|
// of the search-box, so that it can be restored
|
|
|
|
// when switching back to the URL navigator.
|
|
|
|
KUrl url = m_urlNavigator->locationUrl();
|
|
|
|
|
|
|
|
int index = m_urlNavigator->historyIndex();
|
|
|
|
const int historySize = m_urlNavigator->historySize();
|
|
|
|
while (isSearchUrl(url) && (index < historySize)) {
|
|
|
|
++index;
|
|
|
|
url = m_urlNavigator->locationUrl(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isSearchUrl(url)) {
|
|
|
|
m_searchBox->setSearchPath(url);
|
|
|
|
}
|
2010-07-24 16:37:07 +00:00
|
|
|
} else {
|
|
|
|
// Restore the URL for the URL navigator. If Dolphin has been
|
|
|
|
// started with a search-URL, the home URL is used as fallback.
|
|
|
|
const KUrl url = m_searchBox->searchPath();
|
2010-08-17 19:58:47 +00:00
|
|
|
if (url.isValid() && !url.isEmpty()) {
|
|
|
|
if (isSearchUrl(url)) {
|
|
|
|
m_urlNavigator->goHome();
|
|
|
|
} else {
|
|
|
|
m_urlNavigator->setLocationUrl(url);
|
|
|
|
}
|
2010-07-24 16:37:07 +00:00
|
|
|
}
|
|
|
|
}
|
2010-10-27 17:08:02 +00:00
|
|
|
|
|
|
|
emit searchModeChanged(enabled);
|
2010-07-24 16:37:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DolphinViewContainer::isSearchModeEnabled() const
|
|
|
|
{
|
|
|
|
return m_searchBox->isVisible();
|
|
|
|
}
|
|
|
|
|
2009-11-19 19:38:34 +00:00
|
|
|
void DolphinViewContainer::setUrl(const KUrl& newUrl)
|
|
|
|
{
|
2010-01-25 07:58:24 +00:00
|
|
|
if (newUrl != m_urlNavigator->locationUrl()) {
|
|
|
|
m_urlNavigator->setLocationUrl(newUrl);
|
2009-11-19 19:38:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-05 17:12:35 +00:00
|
|
|
void DolphinViewContainer::setFilterBarVisible(bool visible)
|
2008-12-17 10:35:02 +00:00
|
|
|
{
|
|
|
|
Q_ASSERT(m_filterBar != 0);
|
2010-11-05 17:12:35 +00:00
|
|
|
if (visible) {
|
2008-12-17 10:35:02 +00:00
|
|
|
m_filterBar->show();
|
2010-11-07 14:55:33 +00:00
|
|
|
m_filterBar->setFocus();
|
2010-12-19 12:03:46 +00:00
|
|
|
m_filterBar->selectAll();
|
2008-12-17 10:35:02 +00:00
|
|
|
} else {
|
|
|
|
closeFilterBar();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-11 17:48:05 +00:00
|
|
|
void DolphinViewContainer::delayedStatusBarUpdate()
|
|
|
|
{
|
2010-10-10 17:11:55 +00:00
|
|
|
if (m_statusBarTimer->isActive() && (m_statusBarTimestamp.elapsed() > 2000)) {
|
|
|
|
// No update of the statusbar has been done during the last 2 seconds,
|
|
|
|
// although an update has been requested. Trigger an immediate update.
|
|
|
|
m_statusBarTimer->stop();
|
|
|
|
updateStatusBar();
|
|
|
|
} else {
|
|
|
|
// Invoke updateStatusBar() with a small delay. This assures that
|
|
|
|
// when a lot of delayedStatusBarUpdates() are done in a short time,
|
|
|
|
// no bottleneck is given.
|
|
|
|
m_statusBarTimer->start();
|
|
|
|
}
|
2009-07-11 17:48:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinViewContainer::updateStatusBar()
|
|
|
|
{
|
2010-10-10 17:11:55 +00:00
|
|
|
m_statusBarTimestamp.start();
|
|
|
|
|
2009-07-11 17:48:05 +00:00
|
|
|
// As the item count information is less important
|
|
|
|
// in comparison with other messages, it should only
|
|
|
|
// be shown if:
|
|
|
|
// - the status bar is empty or
|
|
|
|
// - shows already the item count information or
|
|
|
|
// - shows only a not very important information
|
2010-10-10 17:11:55 +00:00
|
|
|
const QString newMessage = m_view->statusBarText();
|
|
|
|
const QString currentMessage = m_statusBar->message();
|
|
|
|
const bool updateStatusBarMsg = currentMessage.isEmpty()
|
|
|
|
|| (currentMessage == m_statusBar->defaultText())
|
|
|
|
|| (m_statusBar->type() == DolphinStatusBar::Information);
|
2009-07-11 17:48:05 +00:00
|
|
|
|
2010-10-10 17:11:55 +00:00
|
|
|
m_statusBar->setDefaultText(newMessage);
|
2009-07-11 17:48:05 +00:00
|
|
|
|
|
|
|
if (updateStatusBarMsg) {
|
2010-10-10 17:11:55 +00:00
|
|
|
m_statusBar->setMessage(newMessage, DolphinStatusBar::Default);
|
2009-07-11 17:48:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-10 22:54:37 +00:00
|
|
|
void DolphinViewContainer::updateProgress(int percent)
|
|
|
|
{
|
|
|
|
if (m_statusBar->progressText().isEmpty()) {
|
|
|
|
m_statusBar->setProgressText(i18nc("@info:progress", "Loading folder..."));
|
|
|
|
}
|
|
|
|
m_statusBar->setProgress(percent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinViewContainer::slotStartedPathLoading()
|
2009-11-13 21:03:19 +00:00
|
|
|
{
|
2010-07-24 16:37:07 +00:00
|
|
|
if (isSearchUrl(url())) {
|
|
|
|
// Search KIO-slaves usually don't provide any progress information. Give
|
2010-12-10 22:54:37 +00:00
|
|
|
// a hint to the user that a searching is done:
|
2010-07-24 16:37:07 +00:00
|
|
|
updateStatusBar();
|
2009-11-13 21:03:19 +00:00
|
|
|
m_statusBar->setProgressText(i18nc("@info", "Searching..."));
|
|
|
|
m_statusBar->setProgress(-1);
|
2010-12-10 22:54:37 +00:00
|
|
|
} else {
|
|
|
|
// Trigger an undetermined progress indication. The progress
|
|
|
|
// information in percent will be triggered by the percent() signal
|
|
|
|
// of the directory lister later.
|
|
|
|
updateProgress(-1);
|
2009-11-13 21:03:19 +00:00
|
|
|
}
|
2007-06-07 21:10:48 +00:00
|
|
|
}
|
|
|
|
|
2010-12-10 22:54:37 +00:00
|
|
|
void DolphinViewContainer::slotFinishedPathLoading()
|
2007-06-07 21:10:48 +00:00
|
|
|
{
|
2009-11-12 22:45:47 +00:00
|
|
|
if (!m_statusBar->progressText().isEmpty()) {
|
2007-06-07 21:10:48 +00:00
|
|
|
m_statusBar->setProgressText(QString());
|
|
|
|
m_statusBar->setProgress(100);
|
|
|
|
}
|
|
|
|
|
2010-12-15 18:55:25 +00:00
|
|
|
if (isSearchUrl(url()) && (m_view->items().count() == 0)) {
|
2009-11-13 22:48:07 +00:00
|
|
|
// The dir lister has been completed on a Nepomuk-URI and no items have been found. Instead
|
|
|
|
// of showing the default status bar information ("0 items") a more helpful information is given:
|
|
|
|
m_statusBar->setMessage(i18nc("@info:status", "No items found."), DolphinStatusBar::Information);
|
|
|
|
} else {
|
|
|
|
updateStatusBar();
|
|
|
|
}
|
2007-06-07 21:10:48 +00:00
|
|
|
}
|
|
|
|
|
2007-07-02 17:24:54 +00:00
|
|
|
void DolphinViewContainer::showItemInfo(const KFileItem& item)
|
2007-06-08 13:44:59 +00:00
|
|
|
{
|
2007-07-02 17:24:54 +00:00
|
|
|
if (item.isNull()) {
|
2009-07-29 21:56:37 +00:00
|
|
|
// Only clear the status bar if unimportant messages are shown.
|
|
|
|
// This prevents that information- or error-messages get hidden
|
|
|
|
// by moving the mouse above the viewport or when closing the
|
|
|
|
// context menu.
|
|
|
|
if (m_statusBar->type() == DolphinStatusBar::Default) {
|
|
|
|
m_statusBar->clear();
|
|
|
|
}
|
2007-07-02 17:24:54 +00:00
|
|
|
} else {
|
|
|
|
m_statusBar->setMessage(item.getStatusBarInfo(), DolphinStatusBar::Default);
|
2007-06-08 13:44:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-07 21:10:48 +00:00
|
|
|
void DolphinViewContainer::showInfoMessage(const QString& msg)
|
|
|
|
{
|
|
|
|
m_statusBar->setMessage(msg, DolphinStatusBar::Information);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinViewContainer::showErrorMessage(const QString& msg)
|
|
|
|
{
|
|
|
|
m_statusBar->setMessage(msg, DolphinStatusBar::Error);
|
|
|
|
}
|
|
|
|
|
2007-11-17 00:08:54 +00:00
|
|
|
void DolphinViewContainer::showOperationCompletedMessage(const QString& msg)
|
|
|
|
{
|
|
|
|
m_statusBar->setMessage(msg, DolphinStatusBar::OperationCompleted);
|
|
|
|
}
|
|
|
|
|
2007-06-07 21:10:48 +00:00
|
|
|
void DolphinViewContainer::closeFilterBar()
|
|
|
|
{
|
|
|
|
m_filterBar->hide();
|
2008-09-02 20:01:50 +00:00
|
|
|
m_filterBar->clear();
|
2008-12-16 18:37:02 +00:00
|
|
|
m_view->setFocus();
|
2007-06-07 21:10:48 +00:00
|
|
|
emit showFilterBarChanged(false);
|
|
|
|
}
|
|
|
|
|
2007-10-09 22:32:54 +00:00
|
|
|
void DolphinViewContainer::setNameFilter(const QString& nameFilter)
|
2007-06-07 21:10:48 +00:00
|
|
|
{
|
2007-10-09 22:32:54 +00:00
|
|
|
m_view->setNameFilter(nameFilter);
|
2009-07-11 17:48:05 +00:00
|
|
|
delayedStatusBarUpdate();
|
2007-06-07 21:10:48 +00:00
|
|
|
}
|
|
|
|
|
2010-01-25 07:58:24 +00:00
|
|
|
void DolphinViewContainer::activate()
|
2007-06-10 11:46:41 +00:00
|
|
|
{
|
2010-01-25 07:58:24 +00:00
|
|
|
setActive(true);
|
2007-06-10 11:46:41 +00:00
|
|
|
}
|
|
|
|
|
2010-01-25 07:58:24 +00:00
|
|
|
void DolphinViewContainer::saveViewState()
|
2007-06-13 17:08:39 +00:00
|
|
|
{
|
2010-01-25 07:58:24 +00:00
|
|
|
QByteArray locationState;
|
|
|
|
QDataStream stream(&locationState, QIODevice::WriteOnly);
|
|
|
|
m_view->saveState(stream);
|
|
|
|
m_urlNavigator->saveLocationState(locationState);
|
2007-06-13 17:08:39 +00:00
|
|
|
}
|
2007-06-10 11:46:41 +00:00
|
|
|
|
2010-01-25 07:58:24 +00:00
|
|
|
void DolphinViewContainer::slotUrlNavigatorLocationChanged(const KUrl& url)
|
2007-09-24 13:50:31 +00:00
|
|
|
{
|
2008-10-07 22:05:55 +00:00
|
|
|
if (KProtocolManager::supportsListing(url)) {
|
2010-11-01 12:31:44 +00:00
|
|
|
setSearchModeEnabled(isSearchUrl(url));
|
2010-07-24 16:37:07 +00:00
|
|
|
|
2010-01-25 07:58:24 +00:00
|
|
|
m_view->setUrl(url);
|
2010-10-10 16:13:24 +00:00
|
|
|
if (isActive() && !isSearchUrl(url)) {
|
2008-12-19 06:48:57 +00:00
|
|
|
// When an URL has been entered, the view should get the focus.
|
|
|
|
// The focus must be requested asynchronously, as changing the URL might create
|
2010-07-24 16:37:07 +00:00
|
|
|
// a new view widget.
|
2008-12-19 06:48:57 +00:00
|
|
|
QTimer::singleShot(0, this, SLOT(requestFocus()));
|
|
|
|
}
|
2008-11-13 18:15:12 +00:00
|
|
|
} else if (KProtocolManager::isSourceProtocol(url)) {
|
|
|
|
QString app = "konqueror";
|
|
|
|
if (url.protocol().startsWith(QLatin1String("http"))) {
|
|
|
|
showErrorMessage(i18nc("@info:status",
|
|
|
|
"Dolphin does not support web pages, the web browser has been launched"));
|
|
|
|
const KConfigGroup config(KSharedConfig::openConfig("kdeglobals"), "General");
|
|
|
|
const QString browser = config.readEntry("BrowserApplication");
|
|
|
|
if (!browser.isEmpty()) {
|
|
|
|
app = browser;
|
2009-04-15 17:14:30 +00:00
|
|
|
if (app.startsWith('!')) {
|
|
|
|
// a literal command has been configured, remove the '!' prefix
|
|
|
|
app = app.mid(1);
|
|
|
|
}
|
2008-11-13 18:15:12 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
showErrorMessage(i18nc("@info:status",
|
2008-12-12 06:55:26 +00:00
|
|
|
"Protocol not supported by Dolphin, Konqueror has been launched"));
|
2008-11-13 18:15:12 +00:00
|
|
|
}
|
2009-03-02 00:03:21 +00:00
|
|
|
|
2009-11-13 21:03:19 +00:00
|
|
|
const QString secureUrl = KShell::quoteArg(url.pathOrUrl());
|
2009-03-02 00:03:21 +00:00
|
|
|
const QString command = app + ' ' + secureUrl;
|
2008-11-13 18:15:12 +00:00
|
|
|
KRun::runCommand(command, app, app, this);
|
2008-10-07 22:05:55 +00:00
|
|
|
} else {
|
2008-11-13 18:15:12 +00:00
|
|
|
showErrorMessage(i18nc("@info:status", "Invalid protocol"));
|
2008-10-07 20:29:18 +00:00
|
|
|
}
|
2007-09-25 09:02:29 +00:00
|
|
|
}
|
|
|
|
|
2008-10-01 21:39:35 +00:00
|
|
|
void DolphinViewContainer::dropUrls(const KUrl& destination, QDropEvent* event)
|
|
|
|
{
|
2008-11-08 16:22:30 +00:00
|
|
|
DragAndDropHelper::instance().dropUrls(KFileItem(), destination, event, this);
|
2008-10-01 21:39:35 +00:00
|
|
|
}
|
|
|
|
|
2008-10-24 19:52:28 +00:00
|
|
|
void DolphinViewContainer::redirect(const KUrl& oldUrl, const KUrl& newUrl)
|
|
|
|
{
|
|
|
|
Q_UNUSED(oldUrl);
|
|
|
|
const bool block = m_urlNavigator->signalsBlocked();
|
|
|
|
m_urlNavigator->blockSignals(true);
|
2010-07-22 08:26:07 +00:00
|
|
|
|
2010-07-08 19:46:56 +00:00
|
|
|
// Assure that the location state is reset for redirection URLs. This
|
|
|
|
// allows to skip redirection URLs when going back or forward in the
|
|
|
|
// URL history.
|
|
|
|
m_urlNavigator->saveLocationState(QByteArray());
|
2010-01-25 07:58:24 +00:00
|
|
|
m_urlNavigator->setLocationUrl(newUrl);
|
2010-11-01 12:31:44 +00:00
|
|
|
setSearchModeEnabled(isSearchUrl(newUrl));
|
2010-07-22 08:26:07 +00:00
|
|
|
|
2008-10-24 19:52:28 +00:00
|
|
|
m_urlNavigator->blockSignals(block);
|
|
|
|
}
|
|
|
|
|
2008-12-19 06:41:26 +00:00
|
|
|
void DolphinViewContainer::requestFocus()
|
|
|
|
{
|
|
|
|
m_view->setFocus();
|
|
|
|
}
|
|
|
|
|
2009-02-20 16:55:25 +00:00
|
|
|
void DolphinViewContainer::saveUrlCompletionMode(KGlobalSettings::Completion completion)
|
|
|
|
{
|
|
|
|
DolphinSettings& settings = DolphinSettings::instance();
|
|
|
|
settings.generalSettings()->setUrlCompletionMode(completion);
|
|
|
|
settings.save();
|
|
|
|
}
|
|
|
|
|
2009-06-08 05:55:46 +00:00
|
|
|
void DolphinViewContainer::slotHistoryChanged()
|
|
|
|
{
|
2010-01-26 12:18:08 +00:00
|
|
|
QByteArray locationState = m_urlNavigator->locationState();
|
|
|
|
|
|
|
|
if (!locationState.isEmpty()) {
|
|
|
|
QDataStream stream(&locationState, QIODevice::ReadOnly);
|
|
|
|
m_view->restoreState(stream);
|
2009-06-08 05:55:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-24 16:37:07 +00:00
|
|
|
void DolphinViewContainer::startSearching(const QString &text)
|
|
|
|
{
|
|
|
|
Q_UNUSED(text);
|
|
|
|
const KUrl url = m_searchBox->urlForSearching();
|
|
|
|
if (url.isValid() && !url.isEmpty()) {
|
|
|
|
m_urlNavigator->setLocationUrl(url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinViewContainer::closeSearchBox()
|
|
|
|
{
|
|
|
|
setSearchModeEnabled(false);
|
|
|
|
}
|
|
|
|
|
2010-11-20 17:17:35 +00:00
|
|
|
void DolphinViewContainer::stopLoading()
|
|
|
|
{
|
|
|
|
m_view->stopLoading();
|
|
|
|
}
|
|
|
|
|
2010-07-24 16:37:07 +00:00
|
|
|
bool DolphinViewContainer::isSearchUrl(const KUrl& url) const
|
|
|
|
{
|
2010-11-01 12:31:44 +00:00
|
|
|
const QString protocol = url.protocol();
|
|
|
|
return protocol.contains("search") || (protocol == QLatin1String("nepomuk"));
|
2010-07-24 16:37:07 +00:00
|
|
|
}
|
|
|
|
|
2007-08-28 17:50:54 +00:00
|
|
|
void DolphinViewContainer::slotItemTriggered(const KFileItem& item)
|
|
|
|
{
|
2008-03-05 00:17:53 +00:00
|
|
|
KUrl url = item.targetUrl();
|
2007-08-28 17:50:54 +00:00
|
|
|
|
|
|
|
if (item.isDir()) {
|
|
|
|
m_view->setUrl(url);
|
2008-01-21 16:07:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-12-15 15:20:45 +00:00
|
|
|
|
2008-01-21 16:07:45 +00:00
|
|
|
const GeneralSettings* settings = DolphinSettings::instance().generalSettings();
|
2008-03-25 21:39:05 +00:00
|
|
|
const bool browseThroughArchives = settings->browseThroughArchives();
|
|
|
|
if (browseThroughArchives && item.isFile() && url.isLocalFile()) {
|
|
|
|
// Generic mechanism for redirecting to tar:/<path>/ when clicking on a tar file,
|
|
|
|
// zip:/<path>/ when clicking on a zip file, etc.
|
|
|
|
// The .protocol file specifies the mimetype that the kioslave handles.
|
|
|
|
// Note that we don't use mimetype inheritance since we don't want to
|
|
|
|
// open OpenDocument files as zip folders...
|
|
|
|
const QString protocol = KProtocolManager::protocolForArchiveMimetype(item.mimetype());
|
|
|
|
if (!protocol.isEmpty()) {
|
|
|
|
url.setProtocol(protocol);
|
2007-08-28 17:50:54 +00:00
|
|
|
m_view->setUrl(url);
|
2008-01-21 16:07:45 +00:00
|
|
|
return;
|
2007-08-28 17:50:54 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-21 16:07:45 +00:00
|
|
|
|
2010-03-09 07:13:51 +00:00
|
|
|
if (item.mimetype() == "application/x-desktop") {
|
|
|
|
// redirect to the url in Type=Link desktop files
|
|
|
|
KDesktopFile desktopFile(url.toLocalFile());
|
|
|
|
if (desktopFile.hasLinkType()) {
|
|
|
|
url = desktopFile.readUrl();
|
|
|
|
m_view->setUrl(url);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-21 16:07:45 +00:00
|
|
|
item.run();
|
2007-08-28 17:50:54 +00:00
|
|
|
}
|
|
|
|
|
2008-12-12 19:44:28 +00:00
|
|
|
void DolphinViewContainer::openFile(const KUrl& url)
|
|
|
|
{
|
|
|
|
const KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
|
|
|
|
slotItemTriggered(item);
|
|
|
|
}
|
|
|
|
|
2007-06-07 21:10:48 +00:00
|
|
|
#include "dolphinviewcontainer.moc"
|