#include <KDesktopFile>
#include <KFileItemDelegate>
+#include <KFileItemActions>
#include <KFilePlacesModel>
#include <KLocale>
#include <KIconEffect>
#include <KUrlNavigator>
#include <KRun>
+#ifdef KActivities_FOUND
+#include <KActivities/ResourceInstance>
+#endif
+
#include "dolphin_generalsettings.h"
#include "filterbar/filterbar.h"
#include "search/dolphinsearchbox.h"
#include "statusbar/dolphinstatusbar.h"
-#include "views/dolphinplacesmodel.h"
#include "views/draganddrophelper.h"
#include "views/viewmodecontroller.h"
#include "views/viewproperties.h"
m_statusBar(0),
m_statusBarTimer(0),
m_statusBarTimestamp(),
- m_autoGrabFocus(true)
+ m_autoGrabFocus(true),
+ m_dropDestination(),
+ m_dropEvent(0)
+#ifdef KActivities_FOUND
+ , m_activityResourceInstance(0)
+#endif
{
hide();
m_topLayout->setSpacing(0);
m_topLayout->setMargin(0);
- m_urlNavigator = new KUrlNavigator(DolphinPlacesModel::instance(), url, this);
+ m_urlNavigator = new KUrlNavigator(new KFilePlacesModel(this), url, this);
connect(m_urlNavigator, SIGNAL(urlsDropped(KUrl,QDropEvent*)),
this, SLOT(dropUrls(KUrl,QDropEvent*)));
connect(m_urlNavigator, SIGNAL(activated()),
m_searchBox = new DolphinSearchBox(this);
m_searchBox->hide();
+ connect(m_searchBox, SIGNAL(activated()), this, SLOT(activate()));
connect(m_searchBox, SIGNAL(closeRequest()), this, SLOT(closeSearchBox()));
connect(m_searchBox, SIGNAL(searchRequest()), this, SLOT(startSearching()));
connect(m_searchBox, SIGNAL(returnPressed(QString)), this, SLOT(requestFocus()));
m_view = new DolphinView(url, this);
connect(m_view, SIGNAL(urlChanged(KUrl)), m_urlNavigator, SLOT(setUrl(KUrl)));
+ connect(m_view, SIGNAL(urlChanged(KUrl)), m_messageWidget, SLOT(hide()));
connect(m_view, SIGNAL(writeStateChanged(bool)), this, SIGNAL(writeStateChanged(bool)));
connect(m_view, SIGNAL(requestItemInfo(KFileItem)), this, SLOT(showItemInfo(KFileItem)));
connect(m_view, SIGNAL(itemActivated(KFileItem)), this, SLOT(slotItemActivated(KFileItem)));
+ connect(m_view, SIGNAL(itemsActivated(KFileItemList)), this, SLOT(slotItemsActivated(KFileItemList)));
connect(m_view, SIGNAL(redirection(KUrl,KUrl)), this, SLOT(redirect(KUrl,KUrl)));
connect(m_view, SIGNAL(directoryLoadingStarted()), this, SLOT(slotDirectoryLoadingStarted()));
connect(m_view, SIGNAL(directoryLoadingCompleted()), this, SLOT(slotDirectoryLoadingCompleted()));
+ connect(m_view, SIGNAL(directoryLoadingCanceled()), this, SLOT(slotDirectoryLoadingCanceled()));
connect(m_view, SIGNAL(itemCountChanged()), this, SLOT(delayedStatusBarUpdate()));
connect(m_view, SIGNAL(directoryLoadingProgress(int)), this, SLOT(updateDirectoryLoadingProgress(int)));
connect(m_view, SIGNAL(directorySortingProgress(int)), this, SLOT(updateDirectorySortingProgress(int)));
connect(m_view, SIGNAL(selectionChanged(KFileItemList)), this, SLOT(delayedStatusBarUpdate()));
connect(m_view, SIGNAL(urlAboutToBeChanged(KUrl)), this, SLOT(slotViewUrlAboutToBeChanged(KUrl)));
connect(m_view, SIGNAL(errorMessage(QString)), this, SLOT(showErrorMessage(QString)));
+ connect(m_view, SIGNAL(urlIsFileError(KUrl)), this, SLOT(slotUrlIsFileError(KUrl)));
connect(m_urlNavigator, SIGNAL(urlAboutToBeChanged(KUrl)),
this, SLOT(slotUrlNavigatorLocationAboutToBeChanged(KUrl)));
this, SLOT(slotUrlNavigatorLocationChanged(KUrl)));
connect(m_urlNavigator, SIGNAL(historyChanged()),
this, SLOT(slotHistoryChanged()));
+ connect(m_urlNavigator, SIGNAL(returnPressed()),
+ this, SLOT(slotReturnPressed()));
// Initialize status bar
m_statusBar = new DolphinStatusBar(this);
this, SLOT(setNameFilter(QString)));
connect(m_filterBar, SIGNAL(closeRequest()),
this, SLOT(closeFilterBar()));
+ connect(m_filterBar, SIGNAL(focusViewRequest()),
+ this, SLOT(requestFocus()));
connect(m_view, SIGNAL(urlChanged(KUrl)),
- m_filterBar, SLOT(clear()));
+ m_filterBar, SLOT(slotUrlChanged()));
m_topLayout->addWidget(m_urlNavigator);
m_topLayout->addWidget(m_searchBox);
m_topLayout->addWidget(m_statusBar);
setSearchModeEnabled(isSearchUrl(url));
+
+ // Initialize kactivities resource instance
+
+ #ifdef KActivities_FOUND
+ m_activityResourceInstance = new KActivities::ResourceInstance(
+ window()->winId(), url);
+ m_activityResourceInstance->setParent(this);
+ #endif
}
DolphinViewContainer::~DolphinViewContainer()
void DolphinViewContainer::setActive(bool active)
{
+ m_searchBox->setActive(active);
m_urlNavigator->setActive(active);
m_view->setActive(active);
+
+ #ifdef KActivities_FOUND
+ if (active) {
+ m_activityResourceInstance->notifyFocusedIn();
+ } else {
+ m_activityResourceInstance->notifyFocusedOut();
+ }
+ #endif
}
bool DolphinViewContainer::isActive() const
m_searchBox->setSearchPath(url);
}
} else {
+ m_view->setViewPropertiesContext(QString());
+
// 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();
return m_searchBox->isVisible();
}
+QString DolphinViewContainer::placesText() const
+{
+ QString text;
+
+ if (isSearchModeEnabled()) {
+ text = m_searchBox->searchPath().fileName() + QLatin1String(": ") + m_searchBox->text();
+ } else {
+ text = url().fileName();
+ if (text.isEmpty()) {
+ text = url().host();
+ }
+ }
+
+ return text;
+}
+
void DolphinViewContainer::setUrl(const KUrl& newUrl)
{
if (newUrl != m_urlNavigator->locationUrl()) {
m_urlNavigator->setLocationUrl(newUrl);
}
+
+ #ifdef KActivities_FOUND
+ m_activityResourceInstance->setUri(newUrl);
+ #endif
}
void DolphinViewContainer::setFilterBarVisible(bool visible)
}
if (isSearchUrl(url()) && m_view->itemsCount() == 0) {
- // The dir lister has been completed on a Nepomuk-URI and no items have been found. Instead
+ // The dir lister has been completed on a Baloo-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->setText(i18nc("@info:status", "No items found."));
} else {
}
}
+void DolphinViewContainer::slotDirectoryLoadingCanceled()
+{
+ if (!m_statusBar->progressText().isEmpty()) {
+ m_statusBar->setProgressText(QString());
+ m_statusBar->setProgress(100);
+ }
+
+ m_statusBar->setText(QString());
+}
+
+void DolphinViewContainer::slotUrlIsFileError(const KUrl& url)
+{
+ const KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
+ slotItemActivated(item);
+}
+
void DolphinViewContainer::slotItemActivated(const KFileItem& item)
{
// It is possible to activate items on inactive views by
// results in an active view.
m_view->setActive(true);
- KUrl url = item.targetUrl();
-
- if (item.isDir()) {
+ const KUrl& url = DolphinView::openItemAsFolderUrl(item, GeneralSettings::browseThroughArchives());
+ if (!url.isEmpty()) {
m_view->setUrl(url);
return;
}
- if (GeneralSettings::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);
- m_view->setUrl(url);
- return;
- }
- }
+ item.run();
+}
- if (item.mimetype() == QLatin1String("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;
- }
- }
+void DolphinViewContainer::slotItemsActivated(const KFileItemList& items)
+{
+ Q_ASSERT(items.count() >= 2);
- item.run();
+ KFileItemActions fileItemActions(this);
+ fileItemActions.runPreferredApplications(items, QString());
}
void DolphinViewContainer::showItemInfo(const KFileItem& item)
if (item.isNull()) {
m_statusBar->resetToDefaultText();
} else {
- const QString text = item.isDir() ? item.text() : item.getStatusBarInfo();
- m_statusBar->setText(text);
+ m_statusBar->setText(item.getStatusBarInfo());
}
}
void DolphinViewContainer::closeFilterBar()
{
- m_filterBar->hide();
- m_filterBar->clear();
+ m_filterBar->closeFilterBar();
m_view->setFocus();
emit showFilterBarChanged(false);
}
void DolphinViewContainer::slotUrlNavigatorLocationChanged(const KUrl& url)
{
+ slotReturnPressed();
+
if (KProtocolManager::supportsListing(url)) {
setSearchModeEnabled(isSearchUrl(url));
m_view->setUrl(url);
} else if (KProtocolManager::isSourceProtocol(url)) {
QString app = "konqueror";
if (url.protocol().startsWith(QLatin1String("http"))) {
- showMessage(i18nc("@info:status",
+ showMessage(i18nc("@info:status", // krazy:exclude=qmethods
"Dolphin does not support web pages, the web browser has been launched"),
Information);
void DolphinViewContainer::dropUrls(const KUrl& destination, QDropEvent* event)
{
- const QString error = DragAndDropHelper::dropUrls(KFileItem(), destination, event);
+ m_dropDestination = destination;
+
+ const QMimeData* mimeData = event->mimeData();
+ QMimeData* mimeDataCopy = new QMimeData;
+ foreach (const QString& format, mimeData->formats()) {
+ mimeDataCopy->setData(format, mimeData->data(format));
+ }
+
+ m_dropEvent.reset(new QDropEvent(event->pos(),
+ event->possibleActions(),
+ mimeDataCopy,
+ event->mouseButtons(),
+ event->keyboardModifiers()));
+
+ QTimer::singleShot(0, this, SLOT(dropUrlsDelayed()));
+}
+
+void DolphinViewContainer::dropUrlsDelayed()
+{
+ if (m_dropEvent.isNull()) {
+ return;
+ }
+
+ QString error;
+ DragAndDropHelper::dropUrls(KFileItem(), m_dropDestination, m_dropEvent.data(), error);
if (!error.isEmpty()) {
showMessage(error, Error);
}
+
+ delete m_dropEvent->mimeData();
+ m_dropEvent.reset();
}
void DolphinViewContainer::redirect(const KUrl& oldUrl, const KUrl& newUrl)
}
}
+void DolphinViewContainer::slotReturnPressed()
+{
+ if (!GeneralSettings::editableUrl()) {
+ m_urlNavigator->setUrlEditable(false);
+ }
+}
+
void DolphinViewContainer::startSearching()
{
const KUrl url = m_searchBox->urlForSearching();
if (url.isValid() && !url.isEmpty()) {
+ m_view->setViewPropertiesContext("search");
m_urlNavigator->setLocationUrl(url);
}
}
bool DolphinViewContainer::isSearchUrl(const KUrl& url) const
{
const QString protocol = url.protocol();
- return protocol.contains("search") || (protocol == QLatin1String("nepomuk"));
+ return protocol.contains("search");
}
void DolphinViewContainer::saveViewState()