summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHarald Sitter <sitter@kde.org>2013-04-11 11:51:33 +0200
committerHarald Sitter <sitter@kde.org>2013-04-11 11:51:33 +0200
commite80327f333e724ae394e582e358181a67fb2ff4d (patch)
tree92da0d8f798ba0c70076d458dc1725f4cc1848a3 /src
parentSVN_SILENT made messages (.desktop file) (diff)
downloadrekonq-e80327f333e724ae394e582e358181a67fb2ff4d.tar.xz
honor filetype setting WRT embedding
there are 3 distinct states a filetype can have WRT kpart embeding - always embed - never embed - do whatever the parent node does (e.g. application/foo would take the setting of application) since the logic to determine which of those it is going to be we are using a bit of code imported from konqueror deciding in a boolean fashion whether or not we are supposed to embed or not. this is particularly non- intrusive as the decision directly relates to whether a kpart is created, if not the file will simply be krun'. this change is using static functions for the imported code. rationale being that they are in fact static and not having them reflected in the header makes them all the easier to remove should a better solution arise in the future. with that in mind: while the code is copy'n'pastable it seems like a good idea to move this into some shared library in the long term such that konqueror and rekonq (and any other kpart enabled app) can use the same code. REVIEW: 109942 BUG: 240400 BUG: 279423
Diffstat (limited to 'src')
-rw-r--r--src/webtab/webpage.cpp72
1 files changed, 71 insertions, 1 deletions
diff --git a/src/webtab/webpage.cpp b/src/webtab/webpage.cpp
index 479997e4..ce5a802f 100644
--- a/src/webtab/webpage.cpp
+++ b/src/webtab/webpage.cpp
@@ -64,6 +64,8 @@
#include <KWebWallet>
#include <KProtocolInfo>
#include <KRun>
+#include <KMimeType>
+#include <KProtocolManager>
#include <KIO/Job>
#include <KIO/JobUiDelegate>
@@ -335,6 +337,72 @@ WebPage *WebPage::createWindow(QWebPage::WebWindowType type)
}
+// From Konqueror's konqsettings.cpp
+static bool alwaysEmbedMimeTypeGroup(const QString &mimeType)
+{
+ if (mimeType.startsWith("inode") || mimeType.startsWith("Browser"))
+ return true;
+ return false;
+}
+
+
+// From Konqueror's konqsettings.cpp.
+// config and m_embedMap were manually added to make the function static.
+// TODO: Probably should be moved into some library for KDE Frameworks...
+static bool shouldEmbed(const QString &_mimeType)
+{
+ KSharedConfig::Ptr config = KSharedConfig::openConfig("filetypesrc", KConfig::NoGlobals);
+ QMap<QString, QString> m_embedMap = config->entryMap("EmbedSettings");
+
+ KMimeType::Ptr mime = KMimeType::mimeType(_mimeType, KMimeType::ResolveAliases);
+ if (!mime) {
+ kWarning() << "Unknown mimetype" << _mimeType;
+ return false; // unknown mimetype!
+ }
+ const QString mimeType = mime->name();
+
+ // First check in user's settings whether to embed or not
+ // 1 - in the filetypesrc config file (written by the configuration module)
+ QMap<QString, QString>::const_iterator it = m_embedMap.find( QString::fromLatin1("embed-")+mimeType );
+ if ( it != m_embedMap.end() ) {
+ kDebug() << mimeType << it.value();
+ return it.value() == QLatin1String("true");
+ }
+ // 2 - in the configuration for the group if nothing was found in the mimetype
+ if (alwaysEmbedMimeTypeGroup(mimeType))
+ return true; //always embed mimetype inode/*, Browser/* and Konqueror/*
+ const QString mimeTypeGroup = mimeType.left(mimeType.indexOf('/'));
+ it = m_embedMap.find( QString::fromLatin1("embed-")+mimeTypeGroup );
+ if ( it != m_embedMap.end() ) {
+ kDebug() << mimeType << "group setting:" << it.value();
+ return it.value() == QLatin1String("true");
+ }
+ // 2 bis - configuration for group of parent mimetype, if different
+ if (mimeType[0].isLower()) {
+ QStringList parents;
+ parents.append(mimeType);
+ while (!parents.isEmpty()) {
+ const QString parent = parents.takeFirst();
+ if (alwaysEmbedMimeTypeGroup(parent)) {
+ return true;
+ }
+ KMimeType::Ptr mime = KMimeType::mimeType(parent);
+ Q_ASSERT(mime); // how could the -parent- be null?
+ if (mime)
+ parents += mime->parentMimeTypes();
+ }
+ }
+
+ // 3 - if no config found, use default.
+ // Note: if you change those defaults, also change keditfiletype/mimetypedata.cpp !
+ // Embedding is false by default except for image/* and for zip, tar etc.
+ const bool hasLocalProtocolRedirect = !KProtocolManager::protocolForArchiveMimetype(mimeType).isEmpty();
+ if (mimeTypeGroup == "image" || mimeTypeGroup == "multipart" || hasLocalProtocolRedirect)
+ return true;
+ return false;
+}
+
+
void WebPage::handleUnsupportedContent(QNetworkReply *reply)
{
Q_ASSERT(reply);
@@ -472,7 +540,9 @@ void WebPage::handleUnsupportedContent(QNetworkReply *reply)
webAppMode = true;
// case KParts::BrowserRun::Embed
- KParts::ReadOnlyPart *pa = KMimeTypeTrader::createPartInstanceFromQuery<KParts::ReadOnlyPart>(_mimeType, view(), this, QString());
+ KParts::ReadOnlyPart *pa = 0;
+ if (shouldEmbed(_mimeType)) // Only create the KPart if we are actually supposed to embed.
+ pa = KMimeTypeTrader::createPartInstanceFromQuery<KParts::ReadOnlyPart>(_mimeType, view(), this, QString());
if (pa && !webAppMode)
{
_isOnRekonqPage = true;