#include <QTimer>
#include <QScrollBar>
+#include <KDesktopFile>
+#include <KProtocolManager>
#include <KActionCollection>
#include <KColorScheme>
#include <KDirModel>
m_restoredContentsPosition(),
m_selectedUrls(),
m_clearSelectionBeforeSelectingNewItems(false),
+ m_markFirstNewlySelectedItemAsCurrent(false),
m_versionControlObserver(0)
{
m_topLayout = new QVBoxLayout(this);
while (it.hasNext()) {
const int index = it.next();
KFileItem item = m_model->fileItem(index);
+ const KUrl& url = openItemAsFolderUrl(item);
- if (item.isDir()) { // Open folders in new tabs
- emit tabRequested(item.url());
+ if (!url.isEmpty()) { // Open folders in new tabs
+ emit tabRequested(url);
} else {
items.append(item);
}
void DolphinView::slotItemMiddleClicked(int index)
{
- const KFileItem item = m_model->fileItem(index);
- if (item.isDir() || isTabsForFilesEnabled()) {
+ const KFileItem& item = m_model->fileItem(index);
+ const KUrl& url = openItemAsFolderUrl(item);
+ if (!url.isEmpty()) {
+ emit tabRequested(url);
+ } else if (isTabsForFilesEnabled()) {
emit tabRequested(item.url());
}
}
m_clearSelectionBeforeSelectingNewItems = true;
connect(op, SIGNAL(urlPasted(KUrl)), this, SLOT(slotUrlPasted(KUrl)));
}
+
+ setActive(true);
}
void DolphinView::slotModelChanged(KItemModelBase* current, KItemModelBase* previous)
void DolphinView::slotAboutToCreate(const KUrl::List& urls)
{
- m_selectedUrls << urls;
+ if (!urls.isEmpty()) {
+ if (m_markFirstNewlySelectedItemAsCurrent) {
+ markUrlAsCurrent(urls.first());
+ m_markFirstNewlySelectedItemAsCurrent = false;
+ }
+ m_selectedUrls << urls;
+ }
}
void DolphinView::slotSelectionChanged(const QSet<int>& current, const QSet<int>& previous)
return m_viewPropertiesContext;
}
+KUrl DolphinView::openItemAsFolderUrl(const KFileItem& item, const bool browseThroughArchives)
+{
+ if (item.isNull()) {
+ return KUrl();
+ }
+
+ KUrl url = item.targetUrl();
+
+ if (item.isDir()) {
+ return url;
+ }
+
+ if (item.isMimeTypeKnown()) {
+ const QString& mimetype = item.mimetype();
+
+ 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(mimetype);
+ if (!protocol.isEmpty()) {
+ url.setProtocol(protocol);
+ return url;
+ }
+ }
+
+ if (mimetype == QLatin1String("application/x-desktop")) {
+ // Redirect to the URL in Type=Link desktop files
+ KDesktopFile desktopFile(url.toLocalFile());
+ if (desktopFile.hasLinkType()) {
+ return desktopFile.readUrl();
+ }
+ }
+ }
+
+ return KUrl();
+}
+
void DolphinView::observeCreatedItem(const KUrl& url)
{
if (m_active) {
m_view->scrollToItem(currentIndex);
m_scrollToCurrentItem = false;
}
+
+ m_currentItemUrl = KUrl();
} else {
selectionManager->setCurrentItem(0);
}
- m_currentItemUrl = KUrl();
}
if (!m_restoredContentsPosition.isNull()) {
KonqOperations* op = KonqOperations::doPasteV2(this, url);
if (op) {
m_clearSelectionBeforeSelectingNewItems = true;
+ m_markFirstNewlySelectedItemAsCurrent = true;
connect(op, SIGNAL(aboutToCreate(KUrl::List)), this, SLOT(slotAboutToCreate(KUrl::List)));
}
}