Changeset View
Changeset View
Standalone View
Standalone View
src/core/global.cpp
Show All 17 Lines | |||||
18 | 18 | | |||
19 | #include "global.h" | 19 | #include "global.h" | ||
20 | #include "kioglobal_p.h" | 20 | #include "kioglobal_p.h" | ||
21 | #include "faviconscache_p.h" | 21 | #include "faviconscache_p.h" | ||
22 | 22 | | |||
23 | #include <kprotocolinfo.h> | 23 | #include <kprotocolinfo.h> | ||
24 | #include <kconfig.h> | 24 | #include <kconfig.h> | ||
25 | #include <kconfiggroup.h> | 25 | #include <kconfiggroup.h> | ||
26 | #include <kdesktopfile.h> | ||||
26 | #include <klocalizedstring.h> | 27 | #include <klocalizedstring.h> | ||
27 | #include <ksharedconfig.h> | 28 | #include <ksharedconfig.h> | ||
28 | #include <qmimedatabase.h> | 29 | #include <qmimedatabase.h> | ||
30 | | ||||
31 | #include <QDirIterator> | ||||
29 | #include <QUrl> | 32 | #include <QUrl> | ||
30 | #include <QLocale> | 33 | #include <QLocale> | ||
31 | #include <QFileInfo> | 34 | #include <QFileInfo> | ||
32 | 35 | | |||
33 | #include "kiocoredebug.h" | 36 | #include "kiocoredebug.h" | ||
34 | 37 | | |||
35 | enum BinaryUnitDialect { | 38 | enum BinaryUnitDialect { | ||
36 | DefaultBinaryDialect = -1, ///< Used if no specific preference | 39 | DefaultBinaryDialect = -1, ///< Used if no specific preference | ||
▲ Show 20 Lines • Show All 257 Lines • ▼ Show 20 Line(s) | 296 | { | |||
294 | if (url.isLocalFile() | 297 | if (url.isLocalFile() | ||
295 | || !url.scheme().startsWith(QLatin1String("http"))) { | 298 | || !url.scheme().startsWith(QLatin1String("http"))) { | ||
296 | return QString(); | 299 | return QString(); | ||
297 | } | 300 | } | ||
298 | 301 | | |||
299 | return FavIconsCache::instance()->iconForUrl(url); | 302 | return FavIconsCache::instance()->iconForUrl(url); | ||
300 | } | 303 | } | ||
301 | 304 | | |||
305 | QString KIO::iconFromDirectoryFile(const QString &path) | ||||
306 | { | ||||
307 | const QString filePath = path + QLatin1String("/.directory"); | ||||
308 | if (!QFileInfo(filePath).isFile()) { // exists -and- is a file | ||||
309 | return QString(); | ||||
310 | } | ||||
311 | | ||||
312 | KDesktopFile cfg(filePath); | ||||
313 | QString icon = cfg.readIcon(); | ||||
314 | | ||||
315 | const KConfigGroup group = cfg.desktopGroup(); | ||||
316 | const QString emptyIcon = group.readEntry("EmptyIcon"); | ||||
317 | if (!emptyIcon.isEmpty()) { | ||||
318 | bool isDirEmpty = true; | ||||
319 | QDirIterator dirIt(path, QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); | ||||
320 | while (dirIt.hasNext()) { | ||||
321 | dirIt.next(); | ||||
322 | if (dirIt.fileName() != QLatin1String(".directory")) { | ||||
323 | isDirEmpty = false; | ||||
324 | break; | ||||
325 | } | ||||
326 | } | ||||
327 | if (isDirEmpty) { | ||||
328 | icon = emptyIcon; | ||||
329 | } | ||||
330 | } | ||||
331 | | ||||
332 | if (icon.startsWith(QLatin1String("./"))) { | ||||
333 | // path is relative with respect to the location | ||||
334 | // of the .directory file (#73463) | ||||
335 | return path + icon.mid(1); | ||||
336 | } | ||||
337 | return icon; | ||||
338 | } | ||||
339 | | ||||
340 | QString KIO::iconFromDesktopFile(const QString &path) | ||||
341 | { | ||||
342 | KDesktopFile cfg(path); | ||||
343 | const QString icon = cfg.readIcon(); | ||||
344 | if (cfg.hasLinkType()) { | ||||
345 | const KConfigGroup group = cfg.desktopGroup(); | ||||
346 | const QString emptyIcon = group.readEntry("EmptyIcon"); | ||||
347 | const QString type = cfg.readPath(); | ||||
348 | if (!emptyIcon.isEmpty()) { | ||||
349 | const QString u = cfg.readUrl(); | ||||
350 | const QUrl url(u); | ||||
351 | if (url.scheme() == QLatin1String("trash")) { | ||||
352 | // We need to find if the trash is empty, preferably without using a KIO job. | ||||
353 | // So instead kio_trash leaves an entry in its config file for us. | ||||
354 | KConfig trashConfig(QStringLiteral("trashrc"), KConfig::SimpleConfig); | ||||
355 | if (trashConfig.group("Status").readEntry("Empty", true)) { | ||||
356 | return emptyIcon; | ||||
357 | } | ||||
358 | } | ||||
359 | } | ||||
360 | } | ||||
361 | return icon; | ||||
362 | } | ||||
363 | | ||||
302 | QString KIO::iconNameForUrl(const QUrl &url) | 364 | QString KIO::iconNameForUrl(const QUrl &url) | ||
303 | { | 365 | { | ||
304 | const QLatin1String unknown("unknown"); | 366 | const QLatin1String unknown("unknown"); | ||
305 | if (url.scheme().isEmpty()) { // empty URL or relative URL (e.g. '~') | 367 | if (url.scheme().isEmpty()) { // empty URL or relative URL (e.g. '~') | ||
306 | return unknown; | 368 | return unknown; | ||
307 | } | 369 | } | ||
308 | QMimeDatabase db; | 370 | QMimeDatabase db; | ||
309 | const QMimeType mt = db.mimeTypeForUrl(url); | 371 | const QMimeType mt = db.mimeTypeForUrl(url); | ||
▲ Show 20 Lines • Show All 106 Lines • Show Last 20 Lines |