mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 06:35:14 +00:00
Generalize Unity Integration to not depend on libunity
This commit is contained in:
committed by
John Preston
parent
c66b2b2291
commit
add2356c8a
@@ -220,11 +220,6 @@ f_g_list_free g_list_free = nullptr;
|
||||
f_g_list_free_full g_list_free_full = nullptr;
|
||||
f_g_error_free g_error_free = nullptr;
|
||||
f_g_slist_free g_slist_free = nullptr;
|
||||
#ifndef TDESKTOP_DISABLE_UNITY_INTEGRATION
|
||||
f_unity_launcher_entry_set_count unity_launcher_entry_set_count = nullptr;
|
||||
f_unity_launcher_entry_set_count_visible unity_launcher_entry_set_count_visible = nullptr;
|
||||
f_unity_launcher_entry_get_for_desktop_id unity_launcher_entry_get_for_desktop_id = nullptr;
|
||||
#endif // !TDESKTOP_DISABLE_UNITY_INTEGRATION
|
||||
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
|
||||
|
||||
void start() {
|
||||
@@ -288,17 +283,6 @@ void start() {
|
||||
LOG(("Could not load gtk-x11-2.0!"));
|
||||
}
|
||||
|
||||
#ifndef TDESKTOP_DISABLE_UNITY_INTEGRATION
|
||||
if (DesktopEnvironment::TryUnityCounter()) {
|
||||
QLibrary lib_unity(qstr("unity"), 9, 0);
|
||||
loadLibrary(lib_unity, "unity", 9);
|
||||
|
||||
load(lib_unity, "unity_launcher_entry_get_for_desktop_id", unity_launcher_entry_get_for_desktop_id);
|
||||
load(lib_unity, "unity_launcher_entry_set_count", unity_launcher_entry_set_count);
|
||||
load(lib_unity, "unity_launcher_entry_set_count_visible", unity_launcher_entry_set_count_visible);
|
||||
}
|
||||
#endif // !TDESKTOP_DISABLE_UNITY_INTEGRATION
|
||||
|
||||
if (gtkLoaded) {
|
||||
startLibNotify();
|
||||
}
|
||||
|
@@ -20,9 +20,6 @@ extern "C" {
|
||||
#define signals public
|
||||
} // extern "C"
|
||||
|
||||
#ifndef TDESKTOP_DISABLE_UNITY_INTEGRATION
|
||||
#include <unity/unity/unity.h>
|
||||
#endif // !TDESKTOP_DISABLE_UNITY_INTEGRATION
|
||||
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
|
||||
|
||||
namespace Platform {
|
||||
@@ -364,17 +361,6 @@ extern f_g_error_free g_error_free;
|
||||
|
||||
typedef void (*f_g_slist_free)(GSList *list);
|
||||
extern f_g_slist_free g_slist_free;
|
||||
|
||||
#ifndef TDESKTOP_DISABLE_UNITY_INTEGRATION
|
||||
typedef void (*f_unity_launcher_entry_set_count)(UnityLauncherEntry* self, gint64 value);
|
||||
extern f_unity_launcher_entry_set_count unity_launcher_entry_set_count;
|
||||
|
||||
typedef void (*f_unity_launcher_entry_set_count_visible)(UnityLauncherEntry* self, gboolean value);
|
||||
extern f_unity_launcher_entry_set_count_visible unity_launcher_entry_set_count_visible;
|
||||
|
||||
typedef UnityLauncherEntry* (*f_unity_launcher_entry_get_for_desktop_id)(const gchar* desktop_id);
|
||||
extern f_unity_launcher_entry_get_for_desktop_id unity_launcher_entry_get_for_desktop_id;
|
||||
#endif // !TDESKTOP_DISABLE_UNITY_INTEGRATION
|
||||
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
|
||||
|
||||
} // namespace Libs
|
||||
|
@@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "core/application.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "storage/localstorage.h"
|
||||
#include <QtDBus>
|
||||
|
||||
namespace Platform {
|
||||
namespace {
|
||||
@@ -36,6 +37,8 @@ int32 _trayIconSize = 22;
|
||||
bool _trayIconMuted = true;
|
||||
int32 _trayIconCount = 0;
|
||||
QImage _trayIconImageBack, _trayIconImage;
|
||||
QString _desktopFile;
|
||||
QString _dbusPath = "/";
|
||||
|
||||
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
|
||||
void _trayIconPopup(GtkStatusIcon *status_icon, guint button, guint32 activate_time, gpointer popup_menu) {
|
||||
@@ -177,11 +180,17 @@ static gboolean _trayIconCheck(gpointer/* pIn*/) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#ifndef TDESKTOP_DISABLE_UNITY_INTEGRATION
|
||||
UnityLauncherEntry *_psUnityLauncherEntry = nullptr;
|
||||
#endif // !TDESKTOP_DISABLE_UNITY_INTEGRATION
|
||||
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
|
||||
|
||||
quint32 djbStringHash(QString string) {
|
||||
quint32 hash = 5381;
|
||||
QByteArray chars = string.toLatin1();
|
||||
for(int i = 0; i < chars.length(); i++){
|
||||
hash = (hash << 5) + hash + chars[i];
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
MainWindow::MainWindow() {
|
||||
@@ -336,16 +345,20 @@ void MainWindow::updateIconCounters() {
|
||||
|
||||
const auto counter = Core::App().unreadBadge();
|
||||
|
||||
#if !defined(TDESKTOP_DISABLE_GTK_INTEGRATION) && !defined(TDESKTOP_DISABLE_UNITY_INTEGRATION)
|
||||
if (_psUnityLauncherEntry) {
|
||||
if (useUnityCount) {
|
||||
QVariantMap dbusUnityProperties;
|
||||
if (counter > 0) {
|
||||
Libs::unity_launcher_entry_set_count(_psUnityLauncherEntry, (counter > 9999) ? 9999 : counter);
|
||||
Libs::unity_launcher_entry_set_count_visible(_psUnityLauncherEntry, TRUE);
|
||||
// Gnome requires that count is a 64bit integer
|
||||
dbusUnityProperties.insert("count", (qint64) ((counter > 9999) ? 9999 : (counter)));
|
||||
dbusUnityProperties.insert("count-visible", true);
|
||||
} else {
|
||||
Libs::unity_launcher_entry_set_count_visible(_psUnityLauncherEntry, FALSE);
|
||||
dbusUnityProperties.insert("count-visible", false);
|
||||
}
|
||||
QDBusMessage signal = QDBusMessage::createSignal(_dbusPath, "com.canonical.Unity.LauncherEntry", "Update");
|
||||
signal << "application://" + _desktopFile;
|
||||
signal << dbusUnityProperties;
|
||||
QDBusConnection::sessionBus().send(signal);
|
||||
}
|
||||
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION && !TDESKTOP_DISABLE_UNITY_INTEGRATION
|
||||
|
||||
if (noQtTrayIcon) {
|
||||
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
|
||||
@@ -441,15 +454,6 @@ void MainWindow::LibsLoaded() {
|
||||
if (useStatusIcon) {
|
||||
DEBUG_LOG(("Status icon api loaded!"));
|
||||
}
|
||||
|
||||
#ifndef TDESKTOP_DISABLE_UNITY_INTEGRATION
|
||||
useUnityCount = (Libs::unity_launcher_entry_get_for_desktop_id != nullptr)
|
||||
&& (Libs::unity_launcher_entry_set_count != nullptr)
|
||||
&& (Libs::unity_launcher_entry_set_count_visible != nullptr);
|
||||
if (useUnityCount) {
|
||||
DEBUG_LOG(("Unity count api loaded!"));
|
||||
}
|
||||
#endif // !TDESKTOP_DISABLE_UNITY_INTEGRATION
|
||||
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
|
||||
}
|
||||
|
||||
@@ -544,23 +548,29 @@ void MainWindow::psCreateTrayIcon() {
|
||||
void MainWindow::psFirstShow() {
|
||||
psCreateTrayIcon();
|
||||
|
||||
#if !defined(TDESKTOP_DISABLE_GTK_INTEGRATION) && !defined(TDESKTOP_DISABLE_UNITY_INTEGRATION)
|
||||
if (useUnityCount) {
|
||||
_psUnityLauncherEntry = Libs::unity_launcher_entry_get_for_desktop_id("telegramdesktop.desktop");
|
||||
if (_psUnityLauncherEntry) {
|
||||
LOG(("Found Unity Launcher entry telegramdesktop.desktop!"));
|
||||
} else {
|
||||
_psUnityLauncherEntry = Libs::unity_launcher_entry_get_for_desktop_id("Telegram.desktop");
|
||||
if (_psUnityLauncherEntry) {
|
||||
LOG(("Found Unity Launcher entry Telegram.desktop!"));
|
||||
if (QDBusInterface("com.canonical.Unity", "/").isValid()) {
|
||||
auto snapName = QString::fromLatin1(qgetenv("SNAP_NAME"));
|
||||
if(snapName.isEmpty()) {
|
||||
if(!QStandardPaths::locate(QStandardPaths::ApplicationsLocation, "telegramdesktop.desktop").isEmpty()) {
|
||||
_desktopFile = "telegramdesktop.desktop";
|
||||
LOG(("Found Unity Launcher entry telegramdesktop.desktop!"));
|
||||
useUnityCount=true;
|
||||
} else if(!QStandardPaths::locate(QStandardPaths::ApplicationsLocation, "Telegram.desktop").isEmpty()) {
|
||||
_desktopFile = "telegramdesktop.desktop";
|
||||
LOG(("Found Unity Launcher entry telegramdesktop.desktop!"));
|
||||
useUnityCount=true;
|
||||
} else {
|
||||
LOG(("Could not get Unity Launcher entry!"));
|
||||
}
|
||||
} else {
|
||||
LOG(("SNAP Enviroment detected, setting Launcher entry to %1-telegramdesktop.desktop!").arg(snapName));
|
||||
_desktopFile = snapName + "_telegramdesktop.desktop";
|
||||
useUnityCount=true;
|
||||
}
|
||||
_dbusPath = "/com/canonical/unity/launcherentry/" + QString::number(djbStringHash("application://" + _desktopFile));
|
||||
} else {
|
||||
LOG(("Not using Unity Launcher count."));
|
||||
}
|
||||
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION && !TDESKTOP_DISABLE_GTK_INTEGRATION
|
||||
|
||||
psUpdateMargins();
|
||||
|
||||
@@ -613,12 +623,6 @@ MainWindow::~MainWindow() {
|
||||
Libs::g_object_unref(_trayIndicator);
|
||||
_trayIndicator = nullptr;
|
||||
}
|
||||
#ifndef TDESKTOP_DISABLE_UNITY_INTEGRATION
|
||||
if (_psUnityLauncherEntry) {
|
||||
Libs::g_object_unref(_psUnityLauncherEntry);
|
||||
_psUnityLauncherEntry = nullptr;
|
||||
}
|
||||
#endif // ! TDESKTOP_DISABLE_UNITY_INTEGRATION
|
||||
#endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user