| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/mimetypes/qmimetype.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | - | |||||||||||||
| 6 | - | |||||||||||||
| 7 | - | |||||||||||||
| 8 | - | |||||||||||||
| 9 | - | |||||||||||||
| 10 | - | |||||||||||||
| 11 | QMimeTypePrivate::QMimeTypePrivate() | - | ||||||||||||
| 12 | : loaded(false) | - | ||||||||||||
| 13 | {} | - | ||||||||||||
| 14 | - | |||||||||||||
| 15 | QMimeTypePrivate::QMimeTypePrivate(const QMimeType &other) | - | ||||||||||||
| 16 | : loaded(other.d->loaded), | - | ||||||||||||
| 17 | name(other.d->name), | - | ||||||||||||
| 18 | localeComments(other.d->localeComments), | - | ||||||||||||
| 19 | genericIconName(other.d->genericIconName), | - | ||||||||||||
| 20 | iconName(other.d->iconName), | - | ||||||||||||
| 21 | globPatterns(other.d->globPatterns) | - | ||||||||||||
| 22 | {} | - | ||||||||||||
| 23 | - | |||||||||||||
| 24 | void QMimeTypePrivate::clear() | - | ||||||||||||
| 25 | { | - | ||||||||||||
| 26 | name.clear(); | - | ||||||||||||
| 27 | localeComments.clear(); | - | ||||||||||||
| 28 | genericIconName.clear(); | - | ||||||||||||
| 29 | iconName.clear(); | - | ||||||||||||
| 30 | globPatterns.clear(); | - | ||||||||||||
| 31 | loaded = false; | - | ||||||||||||
| 32 | } | - | ||||||||||||
| 33 | - | |||||||||||||
| 34 | void QMimeTypePrivate::addGlobPattern(const QString &pattern) | - | ||||||||||||
| 35 | { | - | ||||||||||||
| 36 | globPatterns.append(pattern); | - | ||||||||||||
| 37 | } | - | ||||||||||||
| 38 | QMimeType::QMimeType() : | - | ||||||||||||
| 39 | d(new QMimeTypePrivate()) | - | ||||||||||||
| 40 | { | - | ||||||||||||
| 41 | } | - | ||||||||||||
| 42 | - | |||||||||||||
| 43 | - | |||||||||||||
| 44 | - | |||||||||||||
| 45 | - | |||||||||||||
| 46 | - | |||||||||||||
| 47 | QMimeType::QMimeType(const QMimeType &other) : | - | ||||||||||||
| 48 | d(other.d) | - | ||||||||||||
| 49 | { | - | ||||||||||||
| 50 | } | - | ||||||||||||
| 51 | - | |||||||||||||
| 52 | - | |||||||||||||
| 53 | - | |||||||||||||
| 54 | - | |||||||||||||
| 55 | - | |||||||||||||
| 56 | QMimeType &QMimeType::operator=(const QMimeType &other) | - | ||||||||||||
| 57 | { | - | ||||||||||||
| 58 | if (d != other.d) | - | ||||||||||||
| 59 | d = other.d; | - | ||||||||||||
| 60 | return *this; | - | ||||||||||||
| 61 | } | - | ||||||||||||
| 62 | - | |||||||||||||
| 63 | - | |||||||||||||
| 64 | - | |||||||||||||
| 65 | - | |||||||||||||
| 66 | - | |||||||||||||
| 67 | - | |||||||||||||
| 68 | QMimeType::QMimeType(const QMimeTypePrivate &dd) : | - | ||||||||||||
| 69 | d(new QMimeTypePrivate(dd)) | - | ||||||||||||
| 70 | { | - | ||||||||||||
| 71 | } | - | ||||||||||||
| 72 | QMimeType::~QMimeType() | - | ||||||||||||
| 73 | { | - | ||||||||||||
| 74 | } | - | ||||||||||||
| 75 | - | |||||||||||||
| 76 | - | |||||||||||||
| 77 | - | |||||||||||||
| 78 | - | |||||||||||||
| 79 | - | |||||||||||||
| 80 | - | |||||||||||||
| 81 | - | |||||||||||||
| 82 | bool QMimeType::operator==(const QMimeType &other) const | - | ||||||||||||
| 83 | { | - | ||||||||||||
| 84 | return d == other.d || d->name == other.d->name; | - | ||||||||||||
| 85 | } | - | ||||||||||||
| 86 | uint qHash(const QMimeType &key, uint seed) noexcept | - | ||||||||||||
| 87 | { | - | ||||||||||||
| 88 | return never executed: qHash(key.d->name, seed);return qHash(key.d->name, seed);never executed: return qHash(key.d->name, seed); | 0 | ||||||||||||
| 89 | } | - | ||||||||||||
| 90 | bool QMimeType::isValid() const | - | ||||||||||||
| 91 | { | - | ||||||||||||
| 92 | return !d->name.isEmpty(); | - | ||||||||||||
| 93 | } | - | ||||||||||||
| 94 | - | |||||||||||||
| 95 | - | |||||||||||||
| 96 | - | |||||||||||||
| 97 | - | |||||||||||||
| 98 | - | |||||||||||||
| 99 | - | |||||||||||||
| 100 | bool QMimeType::isDefault() const | - | ||||||||||||
| 101 | { | - | ||||||||||||
| 102 | return d->name == QMimeDatabasePrivate::instance()->defaultMimeType(); | - | ||||||||||||
| 103 | } | - | ||||||||||||
| 104 | - | |||||||||||||
| 105 | - | |||||||||||||
| 106 | - | |||||||||||||
| 107 | - | |||||||||||||
| 108 | - | |||||||||||||
| 109 | QString QMimeType::name() const | - | ||||||||||||
| 110 | { | - | ||||||||||||
| 111 | return d->name; | - | ||||||||||||
| 112 | } | - | ||||||||||||
| 113 | - | |||||||||||||
| 114 | - | |||||||||||||
| 115 | - | |||||||||||||
| 116 | - | |||||||||||||
| 117 | - | |||||||||||||
| 118 | - | |||||||||||||
| 119 | QString QMimeType::comment() const | - | ||||||||||||
| 120 | { | - | ||||||||||||
| 121 | QMimeDatabasePrivate::instance()->provider()->loadMimeTypePrivate(*d); | - | ||||||||||||
| 122 | - | |||||||||||||
| 123 | QStringList languageList; | - | ||||||||||||
| 124 | languageList << QLocale().name(); | - | ||||||||||||
| 125 | languageList << QLocale().uiLanguages(); | - | ||||||||||||
| 126 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(languageList)>::type> _container_((languageList)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (const QString &language = *_container_.i; _container_.control; _container_.control = 0): qAsConst(languageList)) { | - | ||||||||||||
| 127 | const QString lang = language == QLatin1String("C")
| 4-14 | ||||||||||||
| 128 | const QString comm = d->localeComments.value(lang); | - | ||||||||||||
| 129 | if (!comm.isEmpty()
| 4-14 | ||||||||||||
| 130 | return executed 14 times by 1 test: comm;return comm;Executed by:
executed 14 times by 1 test: return comm;Executed by:
| 14 | ||||||||||||
| 131 | const int pos = lang.indexOf(QLatin1Char('_')); | - | ||||||||||||
| 132 | if (pos != -1
| 0-4 | ||||||||||||
| 133 | - | |||||||||||||
| 134 | const QString shortLang = lang.left(pos); | - | ||||||||||||
| 135 | const QString commShort = d->localeComments.value(shortLang); | - | ||||||||||||
| 136 | if (!commShort.isEmpty()
| 0-4 | ||||||||||||
| 137 | return executed 4 times by 1 test: commShort;return commShort;Executed by:
executed 4 times by 1 test: return commShort;Executed by:
| 4 | ||||||||||||
| 138 | } never executed: end of block | 0 | ||||||||||||
| 139 | } never executed: end of block | 0 | ||||||||||||
| 140 | - | |||||||||||||
| 141 | - | |||||||||||||
| 142 | return never executed: d->name;return d->name;never executed: return d->name; | 0 | ||||||||||||
| 143 | } | - | ||||||||||||
| 144 | QString QMimeType::genericIconName() const | - | ||||||||||||
| 145 | { | - | ||||||||||||
| 146 | QMimeDatabasePrivate::instance()->provider()->loadGenericIcon(*d); | - | ||||||||||||
| 147 | if (d->genericIconName.isEmpty()) { | - | ||||||||||||
| 148 | - | |||||||||||||
| 149 | - | |||||||||||||
| 150 | - | |||||||||||||
| 151 | - | |||||||||||||
| 152 | - | |||||||||||||
| 153 | QString group = name(); | - | ||||||||||||
| 154 | const int slashindex = group.indexOf(QLatin1Char('/')); | - | ||||||||||||
| 155 | if (slashindex != -1) | - | ||||||||||||
| 156 | group = group.left(slashindex); | - | ||||||||||||
| 157 | return group + QLatin1String("-x-generic"); | - | ||||||||||||
| 158 | } | - | ||||||||||||
| 159 | return d->genericIconName; | - | ||||||||||||
| 160 | } | - | ||||||||||||
| 161 | - | |||||||||||||
| 162 | - | |||||||||||||
| 163 | - | |||||||||||||
| 164 | - | |||||||||||||
| 165 | - | |||||||||||||
| 166 | - | |||||||||||||
| 167 | - | |||||||||||||
| 168 | QString QMimeType::iconName() const | - | ||||||||||||
| 169 | { | - | ||||||||||||
| 170 | QMimeDatabasePrivate::instance()->provider()->loadIcon(*d); | - | ||||||||||||
| 171 | if (d->iconName.isEmpty()) { | - | ||||||||||||
| 172 | - | |||||||||||||
| 173 | d->iconName = name(); | - | ||||||||||||
| 174 | const int slashindex = d->iconName.indexOf(QLatin1Char('/')); | - | ||||||||||||
| 175 | if (slashindex != -1) | - | ||||||||||||
| 176 | d->iconName[slashindex] = QLatin1Char('-'); | - | ||||||||||||
| 177 | } | - | ||||||||||||
| 178 | return d->iconName; | - | ||||||||||||
| 179 | } | - | ||||||||||||
| 180 | - | |||||||||||||
| 181 | - | |||||||||||||
| 182 | - | |||||||||||||
| 183 | - | |||||||||||||
| 184 | - | |||||||||||||
| 185 | QStringList QMimeType::globPatterns() const | - | ||||||||||||
| 186 | { | - | ||||||||||||
| 187 | QMimeDatabasePrivate::instance()->provider()->loadMimeTypePrivate(*d); | - | ||||||||||||
| 188 | return d->globPatterns; | - | ||||||||||||
| 189 | } | - | ||||||||||||
| 190 | QStringList QMimeType::parentMimeTypes() const | - | ||||||||||||
| 191 | { | - | ||||||||||||
| 192 | return QMimeDatabasePrivate::instance()->provider()->parents(d->name); | - | ||||||||||||
| 193 | } | - | ||||||||||||
| 194 | - | |||||||||||||
| 195 | static void collectParentMimeTypes(const QString &mime, QStringList &allParents) | - | ||||||||||||
| 196 | { | - | ||||||||||||
| 197 | const QStringList parents = QMimeDatabasePrivate::instance()->provider()->parents(mime); | - | ||||||||||||
| 198 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(parents)>::type> _container_((parents)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (const QString &parent = *_container_.i; _container_.control; _container_.control = 0: parents) { | - | ||||||||||||
| 199 | - | |||||||||||||
| 200 | if (!allParents.contains(parent)
| 4-24 | ||||||||||||
| 201 | allParents.append(parent); executed 24 times by 1 test: allParents.append(parent);Executed by:
| 24 | ||||||||||||
| 202 | } executed 28 times by 1 test: end of blockExecuted by:
| 28 | ||||||||||||
| 203 | - | |||||||||||||
| 204 | - | |||||||||||||
| 205 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(parents)>::type> _container_((parents)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (const QString &parent = *_container_.i; _container_.control; _container_.control = 0: parents) | - | ||||||||||||
| 206 | {collectParentMimeTypes(parent, allParents); executed 28 times by 1 test: collectParentMimeTypes(parent, allParents);Executed by:
| 28 | ||||||||||||
| }} executed 36 times by 1 test: end of blockExecuted by:
| ||||||||||||||
| 208 | QStringList QMimeType::allAncestors() const | - | ||||||||||||
| 209 | { | - | ||||||||||||
| 210 | QStringList allParents; | - | ||||||||||||
| 211 | collectParentMimeTypes(d->name, allParents); | - | ||||||||||||
| 212 | return allParents; | - | ||||||||||||
| 213 | } | - | ||||||||||||
| 214 | QStringList QMimeType::aliases() const | - | ||||||||||||
| 215 | { | - | ||||||||||||
| 216 | return QMimeDatabasePrivate::instance()->provider()->listAliases(d->name); | - | ||||||||||||
| 217 | } | - | ||||||||||||
| 218 | - | |||||||||||||
| 219 | - | |||||||||||||
| 220 | - | |||||||||||||
| 221 | - | |||||||||||||
| 222 | - | |||||||||||||
| 223 | QStringList QMimeType::suffixes() const | - | ||||||||||||
| 224 | { | - | ||||||||||||
| 225 | QMimeDatabasePrivate::instance()->provider()->loadMimeTypePrivate(*d); | - | ||||||||||||
| 226 | - | |||||||||||||
| 227 | QStringList result; | - | ||||||||||||
| 228 | for (QForeachContainer<typename QtPrivate::remove_reference<decltypeconst QString &pattern : qAsConst(d->globPatterns)>::type> _container_((d->globPatterns)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (const QString &pattern = *_container_.i; _container_.control; _container_.control = 0))) { | - | ||||||||||||
| 229 | - | |||||||||||||
| 230 | if (pattern.startsWith(QLatin1String("*."))
| 4-2466 | ||||||||||||
| 231 | pattern.length() > 2
| 0-2466 | ||||||||||||
| 232 | pattern.indexOf(QLatin1Char('*'), 2) < 0
| 0-2466 | ||||||||||||
| 233 | const QString suffix = pattern.mid(2); | - | ||||||||||||
| 234 | result.append(suffix); | - | ||||||||||||
| 235 | } executed 2466 times by 23 tests: end of blockExecuted by:
| 2466 | ||||||||||||
| 236 | } executed 2470 times by 23 tests: end of blockExecuted by:
| 2470 | ||||||||||||
| 237 | - | |||||||||||||
| 238 | return executed 2448 times by 23 tests: result;return result;Executed by:
executed 2448 times by 23 tests: return result;Executed by:
| 2448 | ||||||||||||
| 239 | } | - | ||||||||||||
| 240 | - | |||||||||||||
| 241 | - | |||||||||||||
| 242 | - | |||||||||||||
| 243 | - | |||||||||||||
| 244 | - | |||||||||||||
| 245 | - | |||||||||||||
| 246 | QString QMimeType::preferredSuffix() const | - | ||||||||||||
| 247 | { | - | ||||||||||||
| 248 | const QStringList suffixList = suffixes(); | - | ||||||||||||
| 249 | return suffixList.isEmpty() ? QString() : suffixList.at(0); | - | ||||||||||||
| 250 | } | - | ||||||||||||
| 251 | - | |||||||||||||
| 252 | - | |||||||||||||
| 253 | - | |||||||||||||
| 254 | - | |||||||||||||
| 255 | - | |||||||||||||
| 256 | QString QMimeType::filterString() const | - | ||||||||||||
| 257 | { | - | ||||||||||||
| 258 | QMimeDatabasePrivate::instance()->provider()->loadMimeTypePrivate(*d); | - | ||||||||||||
| 259 | QString filter; | - | ||||||||||||
| 260 | - | |||||||||||||
| 261 | if (!d->globPatterns.empty()) { | - | ||||||||||||
| 262 | filter += comment() + QLatin1String(" ("); | - | ||||||||||||
| 263 | for (int i = 0; i < d->globPatterns.size(); ++i) { | - | ||||||||||||
| 264 | if (i != 0) | - | ||||||||||||
| 265 | filter += QLatin1Char(' '); | - | ||||||||||||
| 266 | filter += d->globPatterns.at(i); | - | ||||||||||||
| 267 | } | - | ||||||||||||
| 268 | filter += QLatin1Char(')'); | - | ||||||||||||
| 269 | } | - | ||||||||||||
| 270 | - | |||||||||||||
| 271 | return filter; | - | ||||||||||||
| 272 | } | - | ||||||||||||
| 273 | - | |||||||||||||
| 274 | - | |||||||||||||
| 275 | - | |||||||||||||
| 276 | - | |||||||||||||
| 277 | - | |||||||||||||
| 278 | - | |||||||||||||
| 279 | - | |||||||||||||
| 280 | bool QMimeType::inherits(const QString &mimeTypeName) const | - | ||||||||||||
| 281 | { | - | ||||||||||||
| 282 | if (d->name == mimeTypeName) | - | ||||||||||||
| 283 | return true; | - | ||||||||||||
| 284 | return QMimeDatabasePrivate::instance()->inherits(d->name, mimeTypeName); | - | ||||||||||||
| 285 | } | - | ||||||||||||
| 286 | - | |||||||||||||
| 287 | - | |||||||||||||
| 288 | QDebug operator<<(QDebug debug, const QMimeType &mime) | - | ||||||||||||
| 289 | { | - | ||||||||||||
| 290 | QDebugStateSaver saver(debug); | - | ||||||||||||
| 291 | if (!mime.isValid()) { | - | ||||||||||||
| 292 | debug.nospace() << "QMimeType(invalid)"; | - | ||||||||||||
| 293 | } else { | - | ||||||||||||
| 294 | debug.nospace() << "QMimeType(" << mime.name() << ")"; | - | ||||||||||||
| 295 | } | - | ||||||||||||
| 296 | return debug; | - | ||||||||||||
| 297 | } | - | ||||||||||||
| 298 | - | |||||||||||||
| 299 | - | |||||||||||||
| 300 | - | |||||||||||||
| Switch to Source code | Preprocessed file |