#include <KMessageWidget>
#include <KProtocolManager>
#include <KShell>
+#include <kio_version.h>
#include <QApplication>
#include <QDesktopServices>
m_searchBox = new DolphinSearchBox(this);
m_searchBox->hide();
connect(m_searchBox, &DolphinSearchBox::activated, this, &DolphinViewContainer::activate);
+ connect(m_searchBox, &DolphinSearchBox::openRequest, this, &DolphinViewContainer::openSearchBox);
connect(m_searchBox, &DolphinSearchBox::closeRequest, this, &DolphinViewContainer::closeSearchBox);
connect(m_searchBox, &DolphinSearchBox::searchRequest, this, &DolphinViewContainer::startSearching);
connect(m_searchBox, &DolphinSearchBox::focusViewRequest, this, &DolphinViewContainer::requestFocus);
}
KIO::OpenUrlJob *job = new KIO::OpenUrlJob(item.targetUrl(), item.mimetype());
- job->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
+ // Auto*Warning*Handling, errors are put in a KMessageWidget by us in slotOpenUrlFinished.
+ job->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoWarningHandlingEnabled, this));
job->setShowOpenOrExecuteDialog(true);
connect(job, &KIO::OpenUrlJob::finished, this, &DolphinViewContainer::slotOpenUrlFinished);
job->start();
{
KService::List services = KApplicationTrader::queryByMimeType(item.mimetype());
- if (services.length() >= 2) {
- auto service = services.at(1);
+ int indexOfAppToOpenFileWith = 1;
+
+ // executable scripts
+ auto mimeType = item.currentMimeType();
+ if (item.isLocalFile() && mimeType.inherits(QStringLiteral("application/x-executable")) && mimeType.inherits(QStringLiteral("text/plain"))
+ && QFileInfo(item.localPath()).isExecutable()) {
+ KConfigGroup cfgGroup(KSharedConfig::openConfig(QStringLiteral("kiorc")), "Executable scripts");
+ const QString value = cfgGroup.readEntry("behaviourOnLaunch", "alwaysAsk");
+
+ // in case KIO::WidgetsOpenOrExecuteFileHandler::promptUserOpenOrExecute would not open the file
+ if (value != QLatin1String("open")) {
+ indexOfAppToOpenFileWith = 0;
+ }
+ }
+
+ if (services.length() >= indexOfAppToOpenFileWith + 1) {
+ auto service = services.at(indexOfAppToOpenFileWith);
KIO::ApplicationLauncherJob *job = new KIO::ApplicationLauncherJob(service, this);
job->setUrls({item.url()});
-#if KIO_VERSION >= QT_VERSION_CHECK(5, 98, 0)
job->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
-#else
- job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
-#endif
connect(job, &KIO::OpenUrlJob::finished, this, &DolphinViewContainer::slotOpenUrlFinished);
job->start();
}
}
if (KProtocolManager::supportsListing(url)) {
- setSearchModeEnabled(isSearchUrl(url));
+ const bool searchBoxInitialized = isSearchModeEnabled() && m_searchBox->text().isEmpty();
+ setSearchModeEnabled(isSearchUrl(url) || searchBoxInitialized);
+
m_view->setUrl(url);
tryRestoreViewState();
- if (m_autoGrabFocus && isActive() && !isSearchUrl(url)) {
+ if (m_autoGrabFocus && isActive() && !isSearchModeEnabled()) {
// When an URL has been entered, the view should get the focus.
// The focus must be requested asynchronously, as changing the URL might create
// a new view widget.
QDesktopServices::openUrl(url);
redirect(QUrl(), m_urlNavigator->locationUrl(1));
} else {
- showMessage(i18nc("@info:status", "Invalid protocol"), Error);
+ if (!url.scheme().isEmpty()) {
+ showMessage(i18nc("@info:status", "Invalid protocol '%1'", url.scheme()), Error);
+ } else {
+ showMessage(i18nc("@info:status", "Invalid protocol"), Error);
+ }
m_urlNavigator->goBack();
}
}
}
}
+void DolphinViewContainer::openSearchBox()
+{
+ setSearchModeEnabled(true);
+}
+
void DolphinViewContainer::closeSearchBox()
{
setSearchModeEnabled(false);