delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / apps / konqueror / src / konqsettings.cpp
blob246efa089301739a760579a65430f06612595918
1 /* This file is part of the KDE project
2 Copyright (C) 1999, 2007 David Faure <faure@kde.org>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #include "konqsettings.h"
21 #include <kprotocolmanager.h>
22 #include "kglobalsettings.h"
23 #include <ksharedconfig.h>
24 #include <kglobal.h>
25 #include <kmimetype.h>
26 #include <kdesktopfile.h>
27 #include <kdebug.h>
28 #include <assert.h>
29 #include <kconfiggroup.h>
31 class KonqEmbedSettingsSingleton
33 public:
34 KonqFMSettings self;
36 K_GLOBAL_STATIC(KonqEmbedSettingsSingleton, globalEmbedSettings)
38 KonqFMSettings* KonqFMSettings::settings()
40 return &globalEmbedSettings->self;
43 //static
44 void KonqFMSettings::reparseConfiguration()
46 if (globalEmbedSettings.exists()) {
47 globalEmbedSettings->self.init(true);
50 KonqFMSettings::KonqFMSettings()
52 init(false);
55 KonqFMSettings::~KonqFMSettings()
59 void KonqFMSettings::init(bool reparse)
61 if (reparse)
62 fileTypesConfig()->reparseConfiguration();
63 m_embedMap = fileTypesConfig()->entryMap("EmbedSettings");
66 KSharedConfig::Ptr KonqFMSettings::fileTypesConfig()
68 if (!m_fileTypesConfig) {
69 m_fileTypesConfig = KSharedConfig::openConfig("filetypesrc", KConfig::NoGlobals);
71 return m_fileTypesConfig;
74 static bool alwaysEmbedMimeTypeGroup(const QString& mimeType)
76 if ( mimeType.startsWith("inode") || mimeType.startsWith("Browser") || mimeType.startsWith("Konqueror"))
77 return true; //always embed mimetype inode/*, Browser/* and Konqueror/*
78 return false;
81 bool KonqFMSettings::shouldEmbed(const QString & _mimeType) const
83 KMimeType::Ptr mime = KMimeType::mimeType(_mimeType, KMimeType::ResolveAliases);
84 if (!mime) {
85 kWarning() << "Unknown mimetype" << _mimeType;
86 return false; // unknown mimetype!
88 const QString mimeType = mime->name();
90 // First check in user's settings whether to embed or not
91 // 1 - in the filetypesrc config file (written by the configuration module)
92 QMap<QString, QString>::const_iterator it = m_embedMap.find( QString::fromLatin1("embed-")+mimeType );
93 if ( it != m_embedMap.end() ) {
94 kDebug(1202) << mimeType << it.value();
95 return it.value() == QLatin1String("true");
97 // 2 - in the configuration for the group if nothing was found in the mimetype
98 if (alwaysEmbedMimeTypeGroup(mimeType))
99 return true; //always embed mimetype inode/*, Browser/* and Konqueror/*
100 const QString mimeTypeGroup = mimeType.left(mimeType.indexOf('/'));
101 it = m_embedMap.find( QString::fromLatin1("embed-")+mimeTypeGroup );
102 if ( it != m_embedMap.end() ) {
103 kDebug(1202) << mimeType << "group setting:" << it.value();
104 return it.value() == QLatin1String("true");
106 // 2 bis - configuration for group of parent mimetype, if different
107 if (mimeType[0].isLower()) {
108 QStringList parents;
109 parents.append(mimeType);
110 while (!parents.isEmpty()) {
111 const QString parent = parents.takeFirst();
112 if (alwaysEmbedMimeTypeGroup(parent)) {
113 return true;
115 KMimeType::Ptr mime = KMimeType::mimeType(parent);
116 Q_ASSERT(mime); // how could the -parent- be null?
117 if (mime)
118 parents += mime->parentMimeTypes();
122 // 3 - if no config found, use default.
123 // Note: if you change those defaults, also change settings/filetypes/mimetypedata.cpp !
124 // Embedding is false by default except for image/* and for zip, tar etc.
125 const bool hasLocalProtocolRedirect = !KProtocolManager::protocolForArchiveMimetype(mimeType).isEmpty();
126 if ( mimeTypeGroup == "image" || hasLocalProtocolRedirect )
127 return true;
128 return false;