=== modified file 'debian/changelog'
--- debian/changelog	2015-07-29 17:00:47 +0000
+++ debian/changelog	2017-02-17 01:01:40 +0000
@@ -1,3 +1,13 @@
+sni-qt (0.2.7+15.10.20150729-0ubuntu2) UNRELEASED; urgency=medium
+
+  * statusnotifieritem: reset app usertime on activation to ensure
+    compiz will raise it (LP: #627195)
+  * IconCache: get the proper theme path based on the fact we're using a
+    themed icon or not (LP: #1600136)
+  * fsutils: always use $XDG_RUNTIME_DIR if it's set for saving icons
+
+ -- Marco Trevisan (Treviño) <mail@3v1n0.net>  Fri, 17 Feb 2017 01:59:03 +0100
+
 sni-qt (0.2.7+15.10.20150729-0ubuntu1) wily; urgency=low
 
   [ Robert Bruce Park ]

=== modified file 'src/fsutils.cpp'
--- src/fsutils.cpp	2011-10-14 21:41:08 +0000
+++ src/fsutils.cpp	2017-02-17 01:01:40 +0000
@@ -32,16 +32,31 @@
 
 QString generateTempDir(const QString& prefix)
 {
-    QDir dir = QDir::temp();
+    QDir dir;
+    QString path = QString::fromUtf8(getenv("XDG_RUNTIME_DIR"));
+
+    if (!path.isEmpty()) {
+        dir.setPath(path);
+    } else if (!getenv("SNAP")) {
+        dir = QDir::temp();
+    } else {
+        // Try to get the .cache from $XDG_CACHE_HOME, if it's not set,
+        // it has to be in ~/.cache as per XDG standard
+        path = QString::fromUtf8(getenv("XDG_CACHE_HOME"));
+        if (path.isEmpty()) {
+            path = QDir::cleanPath(QDir::homePath() + "/.cache");
+        }
+
+        dir.setPath(path);
+    }
+
     if (!dir.mkpath(".")) {
         qCritical("Failed to generate temporary file for prefix %s: could not create %s",
             qPrintable(prefix), qPrintable(dir.path()));
         return QString();
     }
 
-    QString tmpl = QString("%1/%2-XXXXXX")
-        .arg(dir.path())
-        .arg(prefix);
+    QString tmpl = QDir::cleanPath(dir.path() + '/' + prefix + "-XXXXXX");
     QByteArray ba = QFile::encodeName(tmpl);
     const char* name = mkdtemp(ba.data());
     if (!name) {

=== modified file 'src/iconcache.cpp'
--- src/iconcache.cpp	2011-10-10 16:37:00 +0000
+++ src/iconcache.cpp	2017-02-17 01:01:40 +0000
@@ -26,7 +26,6 @@
 #include <QDateTime>
 #include <QDebug>
 #include <QDir>
-#include <QIcon>
 #include <QList>
 
 const int IconCache::MaxIconCount = 20;
@@ -86,8 +85,18 @@
     }
 }
 
-QString IconCache::themePath() const
+QString IconCache::themePath(const QIcon& icon) const
 {
+    if (!icon.isNull() && !icon.name().isEmpty() && QIcon::hasThemeIcon(icon.name())) {
+        QString dataHome = QString::fromUtf8(getenv("XDG_DATA_HOME"));
+
+        if (dataHome.isEmpty()) {
+            dataHome = QDir::homePath() + "/.local/share";
+        }
+
+        return QDir::cleanPath(dataHome + "/icons");
+    }
+
     return m_themePath;
 }
 

=== modified file 'src/iconcache.h'
--- src/iconcache.h	2011-10-10 16:37:00 +0000
+++ src/iconcache.h	2017-02-17 01:01:40 +0000
@@ -19,6 +19,7 @@
 
 // Qt
 #include <QObject>
+#include <QIcon>
 #include <QStringList>
 
 class QIcon;
@@ -35,8 +36,7 @@
 
     static const int MaxIconCount;
 
-    QString themePath() const;
-
+    QString themePath(const QIcon& icon = QIcon()) const;
     QString nameForIcon(const QIcon& icon) const;
 
     // Internal, testing only

=== modified file 'src/statusnotifieritem.cpp'
--- src/statusnotifieritem.cpp	2015-07-04 13:55:52 +0000
+++ src/statusnotifieritem.cpp	2017-02-17 01:01:40 +0000
@@ -36,6 +36,10 @@
 #include <QTranslator>
 #include <QWheelEvent>
 
+#if defined(Q_WS_X11)
+#include <QX11Info>
+#endif
+
 static const char* SNI_CATEGORY_PROPERTY = "_sni_qt_category";
 static const char* DEFAULT_CATEGORY = "ApplicationStatus";
 
@@ -174,7 +178,7 @@
 void StatusNotifierItem::Activate(int, int)
 {
     SNI_DEBUG;
-    sendActivated(QSystemTrayIcon::Trigger);
+    sendActivatedByTrigger();
 }
 
 void StatusNotifierItem::ContextMenu(int, int)
@@ -200,7 +204,7 @@
 
 QString StatusNotifierItem::iconThemePath() const
 {
-    return m_iconCache->themePath();
+    return m_iconCache->themePath(trayIcon->icon());
 }
 
 QString StatusNotifierItem::iconName() const
@@ -288,6 +292,12 @@
 
 void StatusNotifierItem::sendActivatedByTrigger()
 {
+#if defined(Q_WS_X11)
+    // Workarounds LP: #627195
+    if (QString::fromUtf8(getenv("XDG_CURRENT_DESKTOP")).split(':').contains("Unity")) {
+        QX11Info::setAppUserTime(0);
+    }
+#endif
     sendActivated(QSystemTrayIcon::Trigger);
 }
 

=== modified file 'tests/auto/fsutilstest.cpp'
--- tests/auto/fsutilstest.cpp	2011-10-15 12:32:18 +0000
+++ tests/auto/fsutilstest.cpp	2017-02-17 01:01:40 +0000
@@ -49,6 +49,7 @@
     {
         QDir::setCurrent(m_baseDirName);
         m_sandBoxDirName = m_baseDirName + "/sandbox";
+        setenv("XDG_RUNTIME_DIR", m_sandBoxDirName.toLocal8Bit().constData(), 1 /*overwrite*/);
         setenv("TMPDIR", m_sandBoxDirName.toLocal8Bit().constData(), 1 /*overwrite*/);
     }
 

=== modified file 'tests/auto/iconcachetest.cpp'
--- tests/auto/iconcachetest.cpp	2011-10-10 16:37:00 +0000
+++ tests/auto/iconcachetest.cpp	2017-02-17 01:01:40 +0000
@@ -73,6 +73,32 @@
         QVERIFY(info.isDir());
     }
 
+    void testThemePathForIcon()
+    {
+        QList<int> sizes = QList<int>() << 16 << 22 << 32;
+        QIcon icon = createTestIcon(sizes, Qt::red);
+
+        IconCache cache(m_sandBoxDirName);
+        QString themePath = cache.themePath(icon);
+        QCOMPARE(themePath, m_sandBoxDirName + "/icons");
+
+        QFileInfo info(themePath);
+        QVERIFY(info.isDir());
+    }
+
+    void testThemePathForThemedIcons()
+    {
+        IconCache cache(m_sandBoxDirName);
+        QIcon icon = QIcon::fromTheme("indicator-messages");
+        QString themePath = cache.themePath(icon);
+
+        if (icon.name().isEmpty()) {
+            QSKIP("Icon has not been found in theme, so there's nothing to test here", SkipSingle);
+        }
+
+        QCOMPARE(themePath, QDir::homePath() + "/.local/share/icons");
+    }
+
     void testPixmapIcon()
     {
         IconCache cache(m_sandBoxDirName);
@@ -82,7 +108,7 @@
 
         QString name = cache.nameForIcon(icon);
         Q_FOREACH(int size, sizes) {
-            QString dirName = cache.themePath() + QString("/hicolor/%1x%1/apps").arg(size);
+            QString dirName = cache.themePath(icon) + QString("/hicolor/%1x%1/apps").arg(size);
             QVERIFY(QFile::exists(dirName));
             QImage image;
             QVERIFY(image.load(dirName + "/" + name + ".png"));

