Generalize backward compatibility of linux launcher

This commit is contained in:
Ilya Fedin
2020-02-20 07:00:26 +04:00
committed by John Preston
parent ca1623f34a
commit 5bdc0db9e2
2 changed files with 43 additions and 49 deletions
@@ -44,12 +44,6 @@ int32 _trayIconCount = 0;
QImage _trayIconImageBack, _trayIconImage;
QString _trayIconThemeName, _trayIconName;
#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
bool UseUnityCount = false;
QString UnityCountDesktopFile;
QString UnityCountDBusPath = "/";
#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION
QString GetTrayIconName() {
const auto counter = Core::App().unreadBadge();
const auto muted = Core::App().unreadBadgeMuted();
@@ -222,6 +216,18 @@ bool IsSNIAvailable() {
return SNIAvailable;
}
bool UseUnityCounter() {
#ifdef TDESKTOP_DISABLE_DBUS_INTEGRATION
static const auto UnityCounter = false;
#else // TDESKTOP_DISABLE_DBUS_INTEGRATION
static const auto UnityCounter = QDBusInterface(
"com.canonical.Unity",
"/").isValid();
#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION
return UnityCounter;
}
quint32 djbStringHash(QString string) {
quint32 hash = 5381;
QByteArray chars = string.toLatin1();
@@ -375,8 +381,9 @@ void MainWindow::updateIconCounters() {
updateWindowIcon();
#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
if (UseUnityCount) {
if (UseUnityCounter()) {
const auto counter = Core::App().unreadBadge();
const auto launcherUrl = "application://" + GetLauncherFilename();
QVariantMap dbusUnityProperties;
if (counter > 0) {
// Gnome requires that count is a 64bit integer
@@ -384,16 +391,17 @@ void MainWindow::updateIconCounters() {
"count",
(qint64) ((counter > 9999)
? 9999
: (counter)));
: counter));
dbusUnityProperties.insert("count-visible", true);
} else {
dbusUnityProperties.insert("count-visible", false);
}
QDBusMessage signal = QDBusMessage::createSignal(
UnityCountDBusPath,
"/com/canonical/unity/launcherentry/"
+ QString::number(djbStringHash(launcherUrl)),
"com.canonical.Unity.LauncherEntry",
"Update");
signal << "application://" + UnityCountDesktopFile;
signal << launcherUrl;
signal << dbusUnityProperties;
QDBusConnection::sessionBus().send(signal);
}
@@ -432,34 +440,11 @@ void MainWindow::initTrayMenuHook() {
LOG(("System tray available: %1").arg(Logs::b(trayAvailable)));
cSetSupportTray(trayAvailable);
#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
if (QDBusInterface("com.canonical.Unity", "/").isValid()) {
const std::vector<QString> possibleDesktopFiles = {
GetLauncherFilename(),
"Telegram.desktop"
};
for (auto it = possibleDesktopFiles.begin();
it != possibleDesktopFiles.end(); it++) {
if (!QStandardPaths::locate(
QStandardPaths::ApplicationsLocation, *it).isEmpty()) {
UnityCountDesktopFile = *it;
LOG(("Found Unity Launcher entry %1!")
.arg(UnityCountDesktopFile));
UseUnityCount = true;
break;
}
}
if (!UseUnityCount) {
LOG(("Could not get Unity Launcher entry!"));
}
UnityCountDBusPath = "/com/canonical/unity/launcherentry/"
+ QString::number(
djbStringHash("application://" + UnityCountDesktopFile));
if (UseUnityCounter()) {
LOG(("Using Unity launcher counter."));
} else {
LOG(("Not using Unity Launcher count."));
LOG(("Not using Unity launcher counter."));
}
#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION
}
MainWindow::~MainWindow() {