~ci-train-bot/appmenu-qt5/appmenu-qt5-ubuntu-xenial-2467

« back to all changes in this revision

Viewing changes to src/iconcache.cpp

  • Committer: Bileto Bot
  • Date: 2017-02-16 22:57:38 UTC
  • mfrom: (41.1.3 appmenu-xenial)
  • Revision ID: ci-train-bot@canonical.com-20170216225738-y8r74elaha9ltz55
* IconCache: get the proper theme path based on the fact we're using a
  themed icon or not (LP: #1600136)
* IconCache: use $XDG_RUNTIME_DIR as preferred place where to save
  icons
* AppMenuPlatformMenuBar: Don't initialize X11 related functions in
  other environments (LP: #1606246)

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
IconCache::IconCache(QObject *parent):
31
31
    QObject(parent),
32
 
    m_temporaryDir(Q_NULLPTR),
33
 
    m_initialized(false)
 
32
    m_temporaryDir(Q_NULLPTR)
34
33
{
35
34
}
36
35
 
41
40
    }
42
41
}
43
42
 
44
 
QString IconCache::themePath()
 
43
QString IconCache::themePath(const QIcon &icon)
45
44
{
46
 
    if (!m_initialized) {
47
 
        QString path = QDir::tempPath() + QStringLiteral("/iconcache-XXXXXX");
 
45
    if (!m_temporaryDir) {
 
46
        QString dir;
 
47
        QString runtimeDir = QString::fromUtf8(getenv("XDG_RUNTIME_DIR"));
 
48
 
 
49
        if (!runtimeDir.isEmpty()) {
 
50
            dir = runtimeDir;
 
51
            QDir d(dir);
 
52
            if (!d.exists()) {
 
53
                d.mkpath(".");
 
54
            }
 
55
        } else if (!getenv("SNAP")) {
 
56
            dir = QDir::tempPath();
 
57
        } else {
 
58
            // Try to get the .cache from $XDG_CACHE_HOME, if it's not set,
 
59
            // it has to be in ~/.cache as per XDG standard
 
60
            dir = QString::fromUtf8(getenv("XDG_CACHE_HOME"));
 
61
            if (dir.isEmpty()) {
 
62
                dir = QDir::cleanPath(QDir::homePath() + QStringLiteral("/.cache"));
 
63
            }
 
64
 
 
65
            QDir d(dir);
 
66
            if (!d.exists()) {
 
67
                d.mkpath(".");
 
68
            }
 
69
        }
 
70
 
 
71
        QString path = dir + QStringLiteral("/qt-tray-iconcache-XXXXXX");
48
72
        m_temporaryDir = new QTemporaryDir(path);
49
 
        m_initialized = true;
50
 
    }
 
73
    }
 
74
 
 
75
    if (!icon.isNull() && !icon.name().isEmpty() && QIcon::hasThemeIcon(icon.name())) {
 
76
        QString dataHome = QString::fromUtf8(getenv("XDG_DATA_HOME"));
 
77
 
 
78
        if (dataHome.isEmpty()) {
 
79
            dataHome = QDir::homePath() + "/.local/share";
 
80
        }
 
81
 
 
82
        return QDir::cleanPath(dataHome + "/icons");
 
83
    }
 
84
 
51
85
    return m_temporaryDir->path();
52
86
}
53
87