Changeset View
Changeset View
Standalone View
Standalone View
src/core/kfileitem.cpp
Show All 20 Lines | |||||
21 | #include "kfileitem.h" | 21 | #include "kfileitem.h" | ||
22 | 22 | | |||
23 | #include "kioglobal_p.h" | 23 | #include "kioglobal_p.h" | ||
24 | #include "kiocoredebug.h" | 24 | #include "kiocoredebug.h" | ||
25 | #include "../pathhelpers_p.h" | 25 | #include "../pathhelpers_p.h" | ||
26 | 26 | | |||
27 | #include <QDate> | 27 | #include <QDate> | ||
28 | #include <QDir> | 28 | #include <QDir> | ||
29 | #include <QDirIterator> | | |||
30 | #include <QFile> | 29 | #include <QFile> | ||
31 | #include <QMap> | 30 | #include <QMap> | ||
32 | #include <QDataStream> | 31 | #include <QDataStream> | ||
33 | #include <QMimeDatabase> | 32 | #include <QMimeDatabase> | ||
34 | #include <QDebug> | 33 | #include <QDebug> | ||
35 | #include <qplatformdefs.h> | 34 | #include <qplatformdefs.h> | ||
36 | 35 | | |||
37 | #include <klocalizedstring.h> | 36 | #include <klocalizedstring.h> | ||
▲ Show 20 Lines • Show All 789 Lines • ▼ Show 20 Line(s) | 790 | { | |||
827 | //qDebug() << "finding comment for " << url.url() << " : " << d->m_mimeType->name(); | 826 | //qDebug() << "finding comment for " << url.url() << " : " << d->m_mimeType->name(); | ||
828 | if (!comment.isEmpty()) { | 827 | if (!comment.isEmpty()) { | ||
829 | return comment; | 828 | return comment; | ||
830 | } else { | 829 | } else { | ||
831 | return mime.name(); | 830 | return mime.name(); | ||
832 | } | 831 | } | ||
833 | } | 832 | } | ||
834 | 833 | | |||
835 | static QString iconFromDirectoryFile(const QString &path) | | |||
836 | { | | |||
837 | const QString filePath = path + QLatin1String("/.directory"); | | |||
838 | if (!QFileInfo(filePath).isFile()) { // exists -and- is a file | | |||
839 | return QString(); | | |||
840 | } | | |||
841 | | ||||
842 | KDesktopFile cfg(filePath); | | |||
843 | QString icon = cfg.readIcon(); | | |||
844 | | ||||
845 | const KConfigGroup group = cfg.desktopGroup(); | | |||
846 | const QString emptyIcon = group.readEntry("EmptyIcon"); | | |||
847 | if (!emptyIcon.isEmpty()) { | | |||
848 | bool isDirEmpty = true; | | |||
849 | QDirIterator dirIt(path, QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); | | |||
850 | while (dirIt.hasNext()) { | | |||
851 | dirIt.next(); | | |||
852 | if (dirIt.fileName() != QLatin1String(".directory")) { | | |||
853 | isDirEmpty = false; | | |||
854 | break; | | |||
855 | } | | |||
856 | } | | |||
857 | if (isDirEmpty) { | | |||
858 | icon = emptyIcon; | | |||
859 | } | | |||
860 | } | | |||
861 | | ||||
862 | if (icon.startsWith(QLatin1String("./"))) { | | |||
863 | // path is relative with respect to the location | | |||
864 | // of the .directory file (#73463) | | |||
865 | return path + icon.mid(1); | | |||
866 | } | | |||
867 | return icon; | | |||
868 | } | | |||
869 | | ||||
870 | static QString iconFromDesktopFile(const QString &path) | | |||
871 | { | | |||
872 | KDesktopFile cfg(path); | | |||
873 | const QString icon = cfg.readIcon(); | | |||
874 | if (cfg.hasLinkType()) { | | |||
875 | const KConfigGroup group = cfg.desktopGroup(); | | |||
876 | const QString emptyIcon = group.readEntry("EmptyIcon"); | | |||
877 | const QString type = cfg.readPath(); | | |||
878 | if (!emptyIcon.isEmpty()) { | | |||
879 | const QString u = cfg.readUrl(); | | |||
880 | const QUrl url(u); | | |||
881 | if (url.scheme() == QLatin1String("trash")) { | | |||
882 | // We need to find if the trash is empty, preferably without using a KIO job. | | |||
883 | // So instead kio_trash leaves an entry in its config file for us. | | |||
884 | KConfig trashConfig(QStringLiteral("trashrc"), KConfig::SimpleConfig); | | |||
885 | if (trashConfig.group("Status").readEntry("Empty", true)) { | | |||
886 | return emptyIcon; | | |||
887 | } | | |||
888 | } | | |||
889 | } | | |||
890 | } | | |||
891 | return icon; | | |||
892 | } | | |||
893 | | ||||
894 | QString KFileItem::iconName() const | 834 | QString KFileItem::iconName() const | ||
895 | { | 835 | { | ||
896 | if (!d) { | 836 | if (!d) { | ||
897 | return QString(); | 837 | return QString(); | ||
898 | } | 838 | } | ||
899 | 839 | | |||
900 | if (d->m_useIconNameCache && !d->m_iconName.isEmpty()) { | 840 | if (d->m_useIconNameCache && !d->m_iconName.isEmpty()) { | ||
901 | return d->m_iconName; | 841 | return d->m_iconName; | ||
Show All 15 Lines | 856 | if (!d->m_guessedMimeType.isEmpty()) { | |||
917 | mime = db.mimeTypeForName(d->m_guessedMimeType); | 857 | mime = db.mimeTypeForName(d->m_guessedMimeType); | ||
918 | } else { | 858 | } else { | ||
919 | mime = currentMimeType(); | 859 | mime = currentMimeType(); | ||
920 | } | 860 | } | ||
921 | 861 | | |||
922 | const bool delaySlowOperations = d->m_delayedMimeTypes; | 862 | const bool delaySlowOperations = d->m_delayedMimeTypes; | ||
923 | 863 | | |||
924 | if (isLocalUrl && !delaySlowOperations && mime.inherits(QStringLiteral("application/x-desktop"))) { | 864 | if (isLocalUrl && !delaySlowOperations && mime.inherits(QStringLiteral("application/x-desktop"))) { | ||
925 | d->m_iconName = iconFromDesktopFile(url.toLocalFile()); | 865 | d->m_iconName = KIO::iconFromDesktopFile(url.toLocalFile()); | ||
926 | if (!d->m_iconName.isEmpty()) { | 866 | if (!d->m_iconName.isEmpty()) { | ||
927 | d->m_useIconNameCache = d->m_bMimeTypeKnown; | 867 | d->m_useIconNameCache = d->m_bMimeTypeKnown; | ||
928 | return d->m_iconName; | 868 | return d->m_iconName; | ||
929 | } | 869 | } | ||
930 | } | 870 | } | ||
931 | 871 | | |||
932 | if (isLocalUrl && !delaySlowOperations && isDir()) { | 872 | if (isLocalUrl && !delaySlowOperations && isDir()) { | ||
933 | if (isDirectoryMounted(url)) { | 873 | if (isDirectoryMounted(url)) { | ||
934 | d->m_iconName = iconFromDirectoryFile(url.toLocalFile()); | 874 | d->m_iconName = KIO::iconFromDirectoryFile(url.toLocalFile()); | ||
935 | if (!d->m_iconName.isEmpty()) { | 875 | if (!d->m_iconName.isEmpty()) { | ||
936 | d->m_useIconNameCache = d->m_bMimeTypeKnown; | 876 | d->m_useIconNameCache = d->m_bMimeTypeKnown; | ||
937 | return d->m_iconName; | 877 | return d->m_iconName; | ||
938 | } | 878 | } | ||
939 | } | 879 | } | ||
940 | 880 | | |||
941 | d->m_iconName = KIOPrivate::iconForStandardPath(url.toLocalFile()); | 881 | d->m_iconName = KIOPrivate::iconForStandardPath(url.toLocalFile()); | ||
942 | if (!d->m_iconName.isEmpty()) { | 882 | if (!d->m_iconName.isEmpty()) { | ||
▲ Show 20 Lines • Show All 638 Lines • Show Last 20 Lines |