Changeset View
Changeset View
Standalone View
Standalone View
krusader/krservices.cpp
Show All 28 Lines | |||||
29 | 29 | | |||
30 | #include <KConfigCore/KSharedConfig> | 30 | #include <KConfigCore/KSharedConfig> | ||
31 | #include <KIOCore/KProtocolManager> | 31 | #include <KIOCore/KProtocolManager> | ||
32 | #include <utility> | 32 | #include <utility> | ||
33 | 33 | | |||
34 | #include "krglobal.h" | 34 | #include "krglobal.h" | ||
35 | #include "defaults.h" | 35 | #include "defaults.h" | ||
36 | 36 | | |||
37 | QMap<QString, QString>* KrServices::slaveMap = nullptr; | | |||
38 | QSet<QString> KrServices::krarcArchiveMimetypes = KrServices::generateKrarcArchiveMimetypes(); | | |||
39 | #ifdef KRARC_QUERY_ENABLED | | |||
40 | QSet<QString> KrServices::isoArchiveMimetypes = QSet<QString>::fromList(KProtocolInfo::archiveMimetypes("iso")); | | |||
41 | #else | | |||
42 | QSet<QString> KrServices::isoArchiveMimetypes; | | |||
43 | #endif | | |||
44 | | ||||
45 | QString KrServices::GLOBAL_MESSAGE_PATTERN = "%{time hh:mm:ss.zzz}-%{type} %{category} %{function}@%{line} # %{message}"; | 37 | QString KrServices::GLOBAL_MESSAGE_PATTERN = "%{time hh:mm:ss.zzz}-%{type} %{category} %{function}@%{line} # %{message}"; | ||
46 | 38 | | |||
47 | QSet<QString> KrServices::generateKrarcArchiveMimetypes() | | |||
48 | { | | |||
49 | // Reminder: If a mime type is added/removed/modified in that | | |||
50 | // member function, it's important to research if the type has to | | |||
51 | // be added/removed/modified in the `krarc.protocol` file, or | | |||
52 | // in `KrArcBaseManager::getShortTypeFromMime(const QString &mime)` | | |||
53 | | ||||
54 | // Hard-code these proven mimetypes openable by krarc protocol. | | |||
55 | // They cannot be listed in krarc.protocol itself | | |||
56 | // because it would baffle other file managers (like Dolphin). | | |||
57 | QSet<QString> mimes; | | |||
58 | mimes += QString("application/x-deb"); | | |||
59 | mimes += QString("application/x-debian-package"); | | |||
60 | mimes += QString("application/vnd.debian.binary-package"); | | |||
61 | mimes += QString("application/x-java-archive"); | | |||
62 | mimes += QString("application/x-rpm"); | | |||
63 | mimes += QString("application/x-source-rpm"); | | |||
64 | mimes += QString("application/vnd.oasis.opendocument.chart"); | | |||
65 | mimes += QString("application/vnd.oasis.opendocument.database"); | | |||
66 | mimes += QString("application/vnd.oasis.opendocument.formula"); | | |||
67 | mimes += QString("application/vnd.oasis.opendocument.graphics"); | | |||
68 | mimes += QString("application/vnd.oasis.opendocument.presentation"); | | |||
69 | mimes += QString("application/vnd.oasis.opendocument.spreadsheet"); | | |||
70 | mimes += QString("application/vnd.oasis.opendocument.text"); | | |||
71 | mimes += QString("application/vnd.openxmlformats-officedocument.presentationml.presentation"); | | |||
72 | mimes += QString("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); | | |||
73 | mimes += QString("application/vnd.openxmlformats-officedocument.wordprocessingml.document"); | | |||
74 | mimes += QString("application/x-cbz"); | | |||
75 | mimes += QString("application/vnd.comicbook+zip"); | | |||
76 | mimes += QString("application/x-cbr"); | | |||
77 | mimes += QString("application/vnd.comicbook-rar"); | | |||
78 | mimes += QString("application/epub+zip"); | | |||
79 | mimes += QString("application/x-webarchive"); | | |||
80 | mimes += QString("application/x-plasma"); | | |||
81 | mimes += QString("application/vnd.rar"); | | |||
82 | | ||||
83 | #ifdef KRARC_QUERY_ENABLED | | |||
84 | mimes += QSet<QString>::fromList(KProtocolInfo::archiveMimetypes("krarc")); | | |||
85 | #endif | | |||
86 | | ||||
87 | return mimes; | | |||
88 | } | | |||
89 | | ||||
90 | bool KrServices::cmdExist(const QString& cmdName) | 39 | bool KrServices::cmdExist(const QString& cmdName) | ||
91 | { | 40 | { | ||
92 | // Reminder: If that function is modified, it's important to research if the | 41 | // Reminder: If that function is modified, it's important to research if the | ||
93 | // changes must also be applied to `KrServices::fullPathName()` | 42 | // changes must also be applied to `KrServices::fullPathName()` | ||
94 | // and `kio_krarcProtocol::fullPathName()` | 43 | // and `kio_krarcProtocol::fullPathName()` | ||
95 | 44 | | |||
96 | KConfigGroup group(krConfig, "Dependencies"); | 45 | KConfigGroup group(krConfig, "Dependencies"); | ||
97 | if (QFile(group.readEntry(cmdName, QString())).exists()) | 46 | if (QFile(group.readEntry(cmdName, QString())).exists()) | ||
Show All 37 Lines | |||||
135 | } | 84 | } | ||
136 | 85 | | |||
137 | bool KrServices::isExecutable(const QString &path) | 86 | bool KrServices::isExecutable(const QString &path) | ||
138 | { | 87 | { | ||
139 | QFileInfo info(path); | 88 | QFileInfo info(path); | ||
140 | return info.isFile() && info.isExecutable(); | 89 | return info.isFile() && info.isExecutable(); | ||
141 | } | 90 | } | ||
142 | 91 | | |||
143 | QString KrServices::registeredProtocol(const QString& mimetype) | | |||
144 | { | | |||
145 | if (slaveMap == nullptr) { | | |||
146 | slaveMap = new QMap<QString, QString>(); | | |||
147 | | ||||
148 | KConfigGroup group(krConfig, "Protocols"); | | |||
149 | QStringList protList = group.readEntry("Handled Protocols", QStringList()); | | |||
150 | for (auto & it : protList) { | | |||
151 | QStringList mimes = group.readEntry(QString("Mimes For %1").arg(it), QStringList()); | | |||
152 | for (auto & mime : mimes) | | |||
153 | (*slaveMap)[mime] = it; | | |||
154 | } | | |||
155 | } | | |||
156 | QString protocol = (*slaveMap)[mimetype]; | | |||
157 | if (protocol.isEmpty()) { | | |||
158 | if (krarcArchiveMimetypes.contains(mimetype)) { | | |||
159 | return "krarc"; | | |||
160 | } | | |||
161 | protocol = KProtocolManager::protocolForArchiveMimetype(mimetype); | | |||
162 | } | | |||
163 | return protocol; | | |||
164 | } | | |||
165 | | ||||
166 | bool KrServices::isoSupported(const QString& mimetype) | 92 | bool KrServices::isoSupported(const QString& mimetype) | ||
167 | { | 93 | { | ||
168 | return isoArchiveMimetypes.contains(mimetype); | 94 | #ifdef KRARC_QUERY_ENABLED | ||
169 | } | 95 | return KProtocolInfo::archiveMimetypes("iso").contains(mimetype); | ||
170 | 96 | #else | |||
171 | void KrServices::clearProtocolCache() | 97 | return false; | ||
172 | { | 98 | #endif | ||
173 | if (slaveMap) | | |||
174 | delete slaveMap; | | |||
175 | slaveMap = nullptr; | | |||
176 | } | 99 | } | ||
177 | 100 | | |||
178 | bool KrServices::fileToStringList(QTextStream *stream, QStringList& target, bool keepEmptyLines) | 101 | bool KrServices::fileToStringList(QTextStream *stream, QStringList& target, bool keepEmptyLines) | ||
179 | { | 102 | { | ||
180 | if (!stream) return false; | 103 | if (!stream) return false; | ||
181 | QString line; | 104 | QString line; | ||
182 | while (!stream->atEnd()) { | 105 | while (!stream->atEnd()) { | ||
183 | line = stream->readLine().trimmed(); | 106 | line = stream->readLine().trimmed(); | ||
▲ Show 20 Lines • Show All 152 Lines • Show Last 20 Lines |