X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/8d5c0f960827e6ada4b94447ae3c841356e6bd60..7cb193de1074e226b6fb3fe0f71da577b54f3589:/src/dolphinviewcontainer.cpp diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp index 8a566cffd..2a45152bd 100644 --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -67,7 +68,9 @@ DolphinViewContainer::DolphinViewContainer(const KUrl& url, QWidget* parent) : 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 @@ -95,6 +98,7 @@ DolphinViewContainer::DolphinViewContainer(const KUrl& url, QWidget* parent) : 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())); @@ -105,12 +109,15 @@ DolphinViewContainer::DolphinViewContainer(const KUrl& url, QWidget* parent) : 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))); @@ -118,6 +125,7 @@ DolphinViewContainer::DolphinViewContainer(const KUrl& url, QWidget* parent) : 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_view, SIGNAL(activated()), this, SLOT(activate())); connect(m_urlNavigator, SIGNAL(urlAboutToBeChanged(KUrl)), this, SLOT(slotUrlNavigatorLocationAboutToBeChanged(KUrl))); @@ -125,6 +133,8 @@ DolphinViewContainer::DolphinViewContainer(const KUrl& url, QWidget* parent) : 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); @@ -153,8 +163,10 @@ DolphinViewContainer::DolphinViewContainer(const KUrl& url, QWidget* parent) : 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); @@ -185,6 +197,7 @@ KUrl DolphinViewContainer::url() const void DolphinViewContainer::setActive(bool active) { + m_searchBox->setActive(active); m_urlNavigator->setActive(active); m_view->setActive(active); @@ -302,36 +315,18 @@ void DolphinViewContainer::setSearchModeEnabled(bool enabled) m_urlNavigator->setVisible(!enabled); if (enabled) { - KUrl url = m_urlNavigator->locationUrl(); - m_searchBox->setText(QString()); - m_searchBox->setReadOnly(isSearchUrl(url), url); - - // 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. - 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); - } + const KUrl& locationUrl = m_urlNavigator->locationUrl(); + m_searchBox->fromSearchUrl(locationUrl); } 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(); - if (url.isValid() && !url.isEmpty()) { - if (isSearchUrl(url)) { - m_urlNavigator->goHome(); - } else { - m_urlNavigator->setLocationUrl(url); - } + KUrl url = m_searchBox->searchPath(); + if (url.isEmpty() || !url.isValid() || isSearchUrl(url)) { + url = GeneralSettings::self()->homeUrl(); } + m_urlNavigator->setLocationUrl(url); } } @@ -443,7 +438,7 @@ void DolphinViewContainer::slotDirectoryLoadingCompleted() } 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 { @@ -451,6 +446,16 @@ void DolphinViewContainer::slotDirectoryLoadingCompleted() } } +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); @@ -464,38 +469,21 @@ void DolphinViewContainer::slotItemActivated(const KFileItem& item) // 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:// when clicking on a tar file, - // zip:// 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) @@ -503,15 +491,13 @@ 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); } @@ -553,6 +539,8 @@ void DolphinViewContainer::slotUrlNavigatorLocationAboutToBeChanged(const KUrl& void DolphinViewContainer::slotUrlNavigatorLocationChanged(const KUrl& url) { + slotReturnPressed(); + if (KProtocolManager::supportsListing(url)) { setSearchModeEnabled(isSearchUrl(url)); m_view->setUrl(url); @@ -595,10 +583,37 @@ void DolphinViewContainer::slotUrlNavigatorLocationChanged(const KUrl& url) 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) @@ -636,6 +651,13 @@ void DolphinViewContainer::slotHistoryChanged() } } +void DolphinViewContainer::slotReturnPressed() +{ + if (!GeneralSettings::editableUrl()) { + m_urlNavigator->setUrlEditable(false); + } +} + void DolphinViewContainer::startSearching() { const KUrl url = m_searchBox->urlForSearching(); @@ -669,7 +691,7 @@ void DolphinViewContainer::showErrorMessage(const QString& msg) 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()