this);
addAction(openParentInNewTabAction);
+ addSeparator();
+ } else if (!DolphinView::openItemAsFolderUrl(m_fileInfo).isEmpty()) {
+ // insert 'Open in new window' and 'Open in new tab' entries
+ addAction(m_mainWindow->actionCollection()->action("open_in_new_window"));
+ addAction(m_mainWindow->actionCollection()->action("open_in_new_tab"));
+
addSeparator();
}
} else {
bool selectionHasOnlyDirs = true;
foreach (const KFileItem& item, m_selectedItems) {
- if (!item.isDir()) {
+ const KUrl& url = DolphinView::openItemAsFolderUrl(item);
+ if (url.isEmpty()) {
selectionHasOnlyDirs = false;
break;
}
openNewTab(m_activeViewContainer->url());
} else {
foreach (const KFileItem& item, list) {
- if (item.isDir()) {
- openNewTab(item.url());
+ const KUrl& url = DolphinView::openItemAsFolderUrl(item);
+ if (!url.isEmpty()) {
+ openNewTab(url);
}
}
}
const KFileItemList list = m_activeViewContainer->view()->selectedItems();
if (list.isEmpty()) {
newWindowUrl = m_activeViewContainer->url();
- } else if ((list.count() == 1) && list[0].isDir()) {
- newWindowUrl = list[0].url();
+ } else if (list.count() == 1) {
+ const KFileItem& item = list.first();
+ newWindowUrl = DolphinView::openItemAsFolderUrl(item);
}
if (!newWindowUrl.isEmpty()) {
// 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;
- }
- }
-
- 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;
- }
- }
-
item.run();
}
#include <QTimer>
#include <QScrollBar>
+#include <KDesktopFile>
+#include <KProtocolManager>
#include <KActionCollection>
#include <KColorScheme>
#include <KDirModel>
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());
}
}
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) {
void setViewPropertiesContext(const QString& context);
QString viewPropertiesContext() const;
+ /**
+ * Checks if the given \a item can be opened as folder (e.g. archives).
+ * This function will also adjust the \a url (e.g. change the protocol).
+ * @return a valid and adjusted url if the item can be opened as folder,
+ * otherwise return an empty url.
+ */
+ static KUrl openItemAsFolderUrl(const KFileItem& item, const bool browseThroughArchives = true);
+
public slots:
/**
* Changes the directory to \a url. If the current directory is equal to