2016-06-16 12:59:54 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-06-16 12:59:54 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-06-16 12:59:54 +00:00
|
|
|
*/
|
|
|
|
#include "platform/linux/main_window_linux.h"
|
|
|
|
|
2016-11-04 08:23:50 +00:00
|
|
|
#include "styles/style_window.h"
|
2016-06-16 17:20:58 +00:00
|
|
|
#include "platform/linux/linux_libs.h"
|
2020-01-30 18:41:24 +00:00
|
|
|
#include "platform/linux/specific_linux.h"
|
2017-02-26 17:19:35 +00:00
|
|
|
#include "platform/linux/linux_desktop_environment.h"
|
2016-10-03 15:07:50 +00:00
|
|
|
#include "platform/platform_notifications_manager.h"
|
2018-01-25 14:19:14 +00:00
|
|
|
#include "history/history.h"
|
2016-06-16 12:59:54 +00:00
|
|
|
#include "mainwindow.h"
|
2019-01-21 13:42:21 +00:00
|
|
|
#include "core/application.h"
|
2020-01-31 06:34:37 +00:00
|
|
|
#include "core/sandbox.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "facades.h"
|
|
|
|
#include "app.h"
|
2019-09-08 20:15:42 +00:00
|
|
|
|
2020-02-06 11:34:28 +00:00
|
|
|
#include <QtCore/QSize>
|
|
|
|
|
2020-01-21 12:51:39 +00:00
|
|
|
#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
|
2018-12-07 17:59:14 +00:00
|
|
|
#include <QtDBus>
|
2020-01-31 06:34:37 +00:00
|
|
|
#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION
|
2016-06-16 12:59:54 +00:00
|
|
|
|
|
|
|
namespace Platform {
|
|
|
|
namespace {
|
|
|
|
|
2020-01-31 06:34:37 +00:00
|
|
|
constexpr auto kDisableTrayCounter = "TDESKTOP_DISABLE_TRAY_COUNTER"_cs;
|
|
|
|
constexpr auto kPanelTrayIconName = "telegram-panel"_cs;
|
|
|
|
constexpr auto kMutePanelTrayIconName = "telegram-mute-panel"_cs;
|
|
|
|
constexpr auto kAttentionPanelTrayIconName = "telegram-attention-panel"_cs;
|
|
|
|
constexpr auto kSNIWatcherService = "org.kde.StatusNotifierWatcher"_cs;
|
|
|
|
constexpr auto kTrayIconFilename = "tdesktop-trayicon-XXXXXX.png"_cs;
|
2016-06-16 17:20:58 +00:00
|
|
|
|
2020-02-21 15:35:22 +00:00
|
|
|
bool TrayIconMuted = true;
|
|
|
|
int32 TrayIconCount = 0;
|
|
|
|
base::flat_map<int, QImage> TrayIconImageBack;
|
|
|
|
QIcon TrayIcon;
|
|
|
|
QString TrayIconThemeName, TrayIconName;
|
2020-01-21 12:51:39 +00:00
|
|
|
|
2020-02-20 01:13:15 +00:00
|
|
|
QString GetPanelIconName() {
|
2020-01-31 06:34:37 +00:00
|
|
|
const auto counter = Core::App().unreadBadge();
|
|
|
|
const auto muted = Core::App().unreadBadgeMuted();
|
|
|
|
|
|
|
|
return (counter > 0)
|
|
|
|
? (muted
|
|
|
|
? kMutePanelTrayIconName.utf16()
|
|
|
|
: kAttentionPanelTrayIconName.utf16())
|
|
|
|
: kPanelTrayIconName.utf16();
|
|
|
|
}
|
2016-06-16 17:20:58 +00:00
|
|
|
|
2020-02-20 01:13:15 +00:00
|
|
|
QString GetTrayIconName() {
|
2020-02-26 11:38:31 +00:00
|
|
|
const auto iconName = GetIconName();
|
2020-02-20 01:13:15 +00:00
|
|
|
const auto panelIconName = GetPanelIconName();
|
|
|
|
|
|
|
|
if (QIcon::hasThemeIcon(panelIconName)) {
|
|
|
|
return panelIconName;
|
2020-02-26 11:38:31 +00:00
|
|
|
} else if (QIcon::hasThemeIcon(iconName)) {
|
|
|
|
return iconName;
|
2020-02-20 01:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2020-02-21 15:35:22 +00:00
|
|
|
QIcon TrayIconGen() {
|
|
|
|
const auto iconThemeName = QIcon::themeName();
|
|
|
|
const auto iconName = GetTrayIconName();
|
|
|
|
|
|
|
|
if (qEnvironmentVariableIsSet(kDisableTrayCounter.utf8())
|
|
|
|
&& !iconName.isEmpty()) {
|
|
|
|
if (TrayIcon.isNull()
|
|
|
|
|| iconThemeName != TrayIconThemeName
|
|
|
|
|| iconName != TrayIconName) {
|
|
|
|
TrayIcon = QIcon::fromTheme(iconName);
|
|
|
|
TrayIconThemeName = iconThemeName;
|
|
|
|
TrayIconName = iconName;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TrayIcon;
|
|
|
|
}
|
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
const auto counter = Core::App().unreadBadge();
|
|
|
|
const auto muted = Core::App().unreadBadgeMuted();
|
2018-12-04 10:32:06 +00:00
|
|
|
const auto counterSlice = (counter >= 1000)
|
|
|
|
? (1000 + (counter % 100))
|
|
|
|
: counter;
|
2020-01-24 01:39:46 +00:00
|
|
|
|
2020-02-21 15:35:22 +00:00
|
|
|
if (TrayIcon.isNull()
|
|
|
|
|| iconThemeName != TrayIconThemeName
|
|
|
|
|| iconName != TrayIconName
|
|
|
|
|| muted != TrayIconMuted
|
|
|
|
|| counterSlice != TrayIconCount) {
|
|
|
|
QIcon result;
|
|
|
|
QIcon systemIcon;
|
|
|
|
|
|
|
|
const auto iconSizes = {
|
|
|
|
16,
|
|
|
|
22,
|
|
|
|
24,
|
|
|
|
32,
|
|
|
|
48,
|
|
|
|
64
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const auto iconSize : iconSizes) {
|
|
|
|
auto ¤tImageBack = TrayIconImageBack[iconSize];
|
|
|
|
const auto desiredSize = QSize(iconSize, iconSize);
|
|
|
|
|
|
|
|
if (currentImageBack.isNull()
|
|
|
|
|| iconThemeName != TrayIconThemeName
|
|
|
|
|| iconName != TrayIconName) {
|
|
|
|
if (!iconName.isEmpty()) {
|
|
|
|
if(systemIcon.isNull()) {
|
|
|
|
systemIcon = QIcon::fromTheme(iconName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (systemIcon.actualSize(desiredSize) == desiredSize) {
|
|
|
|
currentImageBack = systemIcon
|
|
|
|
.pixmap(desiredSize)
|
|
|
|
.toImage();
|
|
|
|
} else {
|
|
|
|
const auto availableSizes = systemIcon
|
|
|
|
.availableSizes();
|
|
|
|
|
|
|
|
const auto biggestSize = ranges::max_element(
|
|
|
|
availableSizes,
|
|
|
|
std::less<>(),
|
|
|
|
&QSize::width);
|
|
|
|
|
|
|
|
currentImageBack = systemIcon
|
|
|
|
.pixmap(*biggestSize)
|
|
|
|
.toImage();
|
|
|
|
}
|
2020-02-06 11:34:28 +00:00
|
|
|
} else {
|
2020-02-21 15:35:22 +00:00
|
|
|
currentImageBack = Core::App().logo();
|
|
|
|
}
|
2020-02-06 11:34:28 +00:00
|
|
|
|
2020-02-21 15:35:22 +00:00
|
|
|
if (currentImageBack.size() != desiredSize) {
|
|
|
|
currentImageBack = currentImageBack.scaled(
|
|
|
|
desiredSize,
|
|
|
|
Qt::IgnoreAspectRatio,
|
|
|
|
Qt::SmoothTransformation);
|
2020-02-06 11:34:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-21 15:35:22 +00:00
|
|
|
auto iconImage = currentImageBack;
|
|
|
|
TrayIconMuted = muted;
|
|
|
|
TrayIconCount = counterSlice;
|
|
|
|
TrayIconThemeName = iconThemeName;
|
|
|
|
TrayIconName = iconName;
|
|
|
|
|
|
|
|
if (!qEnvironmentVariableIsSet(kDisableTrayCounter.utf8())
|
|
|
|
&& counter > 0) {
|
|
|
|
QPainter p(&iconImage);
|
|
|
|
int32 layerSize = -16;
|
|
|
|
|
|
|
|
if (iconSize >= 48) {
|
|
|
|
layerSize = -32;
|
|
|
|
} else if (iconSize >= 36) {
|
|
|
|
layerSize = -24;
|
|
|
|
} else if (iconSize >= 32) {
|
|
|
|
layerSize = -20;
|
|
|
|
}
|
2020-01-24 01:39:46 +00:00
|
|
|
|
2020-02-21 15:35:22 +00:00
|
|
|
auto &bg = muted
|
|
|
|
? st::trayCounterBgMute
|
|
|
|
: st::trayCounterBg;
|
|
|
|
|
|
|
|
auto &fg = st::trayCounterFg;
|
2020-01-24 01:39:46 +00:00
|
|
|
|
2020-02-21 15:35:22 +00:00
|
|
|
auto layer = App::wnd()->iconWithCounter(
|
|
|
|
layerSize,
|
|
|
|
counter,
|
|
|
|
bg,
|
|
|
|
fg,
|
|
|
|
false);
|
2020-01-24 01:39:46 +00:00
|
|
|
|
2020-02-21 15:35:22 +00:00
|
|
|
p.drawImage(
|
|
|
|
iconImage.width() - layer.width() - 1,
|
|
|
|
iconImage.height() - layer.height() - 1,
|
|
|
|
layer);
|
|
|
|
}
|
2020-01-24 01:39:46 +00:00
|
|
|
|
2020-02-21 15:35:22 +00:00
|
|
|
result.addPixmap(App::pixmapFromImageInPlace(
|
|
|
|
std::move(iconImage)));
|
2016-10-19 12:24:39 +00:00
|
|
|
}
|
2020-02-21 15:35:22 +00:00
|
|
|
|
|
|
|
TrayIcon = result;
|
2016-10-19 12:24:39 +00:00
|
|
|
}
|
2020-01-24 01:39:46 +00:00
|
|
|
|
2020-02-21 15:35:22 +00:00
|
|
|
return TrayIcon;
|
2016-06-16 17:20:58 +00:00
|
|
|
}
|
|
|
|
|
2020-02-06 11:34:28 +00:00
|
|
|
bool IsAppIndicator() {
|
|
|
|
#ifdef TDESKTOP_DISABLE_DBUS_INTEGRATION
|
|
|
|
static const auto AppIndicator = false;
|
|
|
|
#else // TDESKTOP_DISABLE_DBUS_INTEGRATION
|
|
|
|
static const auto AppIndicator = QDBusInterface(
|
|
|
|
qsl("com.canonical.indicator.application"),
|
|
|
|
qsl("/com/canonical/indicator/application/service"),
|
|
|
|
qsl("com.canonical.indicator.application.service")).isValid()
|
|
|
|
|| QDBusInterface(
|
|
|
|
qsl("org.ayatana.indicator.application"),
|
|
|
|
qsl("/org/ayatana/indicator/application/service"),
|
|
|
|
qsl("org.ayatana.indicator.application.service")).isValid();
|
|
|
|
#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION
|
|
|
|
|
|
|
|
return AppIndicator;
|
|
|
|
}
|
|
|
|
|
2020-01-31 06:34:37 +00:00
|
|
|
#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
|
|
|
|
static bool NeedTrayIconFile() {
|
|
|
|
// Hack for indicator-application, which doesn't handle icons sent across D-Bus:
|
|
|
|
// save the icon to a temp file and set the icon name to that filename.
|
2020-02-21 15:35:22 +00:00
|
|
|
static const auto TrayIconFileNeeded = IsAppIndicator();
|
2020-01-31 06:34:37 +00:00
|
|
|
return TrayIconFileNeeded;
|
2016-06-16 17:20:58 +00:00
|
|
|
}
|
|
|
|
|
2020-01-31 06:34:37 +00:00
|
|
|
static inline QString TrayIconFileTemplate() {
|
|
|
|
static const auto TempFileTemplate = AppRuntimeDirectory()
|
|
|
|
+ kTrayIconFilename.utf16();
|
|
|
|
return TempFileTemplate;
|
2016-06-16 17:20:58 +00:00
|
|
|
}
|
|
|
|
|
2020-01-31 06:34:37 +00:00
|
|
|
std::unique_ptr<QTemporaryFile> TrayIconFile(
|
2020-02-21 15:35:22 +00:00
|
|
|
const QIcon &icon,
|
|
|
|
int size,
|
|
|
|
QObject *parent) {
|
2020-01-31 06:34:37 +00:00
|
|
|
auto ret = std::make_unique<QTemporaryFile>(
|
|
|
|
TrayIconFileTemplate(),
|
|
|
|
parent);
|
|
|
|
ret->open();
|
2020-02-21 15:35:22 +00:00
|
|
|
icon.pixmap(size).save(ret.get());
|
2020-01-31 06:34:37 +00:00
|
|
|
ret->close();
|
|
|
|
return ret;
|
2016-06-16 17:20:58 +00:00
|
|
|
}
|
2020-01-31 06:34:37 +00:00
|
|
|
#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION
|
|
|
|
|
|
|
|
bool IsSNIAvailable() {
|
|
|
|
static const auto SNIAvailable = [&] {
|
|
|
|
#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
|
|
|
|
QDBusInterface systrayHost(
|
|
|
|
kSNIWatcherService.utf16(),
|
|
|
|
qsl("/StatusNotifierWatcher"),
|
|
|
|
kSNIWatcherService.utf16());
|
2016-06-16 17:20:58 +00:00
|
|
|
|
2020-01-31 06:34:37 +00:00
|
|
|
return systrayHost.isValid()
|
|
|
|
&& systrayHost
|
|
|
|
.property("IsStatusNotifierHostRegistered")
|
|
|
|
.toBool();
|
|
|
|
#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}();
|
|
|
|
|
|
|
|
return SNIAvailable;
|
|
|
|
}
|
2016-06-16 17:20:58 +00:00
|
|
|
|
2020-02-20 03:00:26 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-12-07 17:59:14 +00:00
|
|
|
quint32 djbStringHash(QString string) {
|
2020-01-02 11:25:52 +00:00
|
|
|
quint32 hash = 5381;
|
|
|
|
QByteArray chars = string.toLatin1();
|
|
|
|
for(int i = 0; i < chars.length(); i++){
|
|
|
|
hash = (hash << 5) + hash + chars[i];
|
|
|
|
}
|
|
|
|
return hash;
|
2018-12-07 17:59:14 +00:00
|
|
|
}
|
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
} // namespace
|
|
|
|
|
2019-06-06 11:20:21 +00:00
|
|
|
MainWindow::MainWindow(not_null<Window::Controller*> controller)
|
|
|
|
: Window::MainWindow(controller) {
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
|
|
|
|
2017-01-01 16:45:20 +00:00
|
|
|
bool MainWindow::hasTrayIcon() const {
|
2020-01-31 06:34:37 +00:00
|
|
|
#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
|
|
|
|
return trayIcon || _sniTrayIcon;
|
2017-08-07 11:57:34 +00:00
|
|
|
#else
|
|
|
|
return trayIcon;
|
2020-01-31 06:34:37 +00:00
|
|
|
#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
|
|
|
|
2020-01-31 06:34:37 +00:00
|
|
|
void MainWindow::psShowTrayMenu() {
|
|
|
|
if (!IsSNIAvailable()) {
|
|
|
|
_trayIconMenuXEmbed->popup(QCursor::pos());
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-31 06:34:37 +00:00
|
|
|
void MainWindow::psTrayMenuUpdated() {
|
|
|
|
#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
|
|
|
|
if (IsSNIAvailable()) {
|
|
|
|
if (_sniTrayIcon && trayIconMenu) {
|
|
|
|
_sniTrayIcon->setContextMenu(trayIconMenu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
|
|
|
|
2020-01-31 06:34:37 +00:00
|
|
|
#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
|
2020-02-21 15:35:22 +00:00
|
|
|
void MainWindow::setSNITrayIcon(const QIcon &icon) {
|
2020-02-20 01:13:15 +00:00
|
|
|
const auto iconName = GetTrayIconName();
|
|
|
|
|
|
|
|
if (qEnvironmentVariableIsSet(kDisableTrayCounter.utf8())
|
|
|
|
&& !iconName.isEmpty()) {
|
2020-01-31 06:34:37 +00:00
|
|
|
_sniTrayIcon->setIconByName(iconName);
|
|
|
|
_sniTrayIcon->setToolTipIconByName(iconName);
|
|
|
|
} else if (NeedTrayIconFile()) {
|
2020-02-21 15:35:22 +00:00
|
|
|
_trayIconFile = TrayIconFile(icon, 22, this);
|
|
|
|
_trayToolTipIconFile = TrayIconFile(icon, 48, this);
|
2020-01-31 06:34:37 +00:00
|
|
|
|
|
|
|
if (_trayIconFile) {
|
|
|
|
_sniTrayIcon->setIconByName(_trayIconFile->fileName());
|
2020-02-21 15:35:22 +00:00
|
|
|
_sniTrayIcon->setToolTipIconByName(
|
|
|
|
_trayToolTipIconFile->fileName());
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
2020-02-16 08:01:05 +00:00
|
|
|
} else {
|
|
|
|
_sniTrayIcon->setIconByPixmap(icon);
|
|
|
|
_sniTrayIcon->setToolTipIconByPixmap(icon);
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-31 06:34:37 +00:00
|
|
|
void MainWindow::attachToSNITrayIcon() {
|
|
|
|
_sniTrayIcon->setToolTipTitle(AppName.utf16());
|
|
|
|
connect(_sniTrayIcon,
|
|
|
|
&StatusNotifierItem::activateRequested,
|
|
|
|
this,
|
|
|
|
[=](const QPoint &) {
|
|
|
|
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
|
|
|
handleTrayIconActication(QSystemTrayIcon::Trigger);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
connect(_sniTrayIcon,
|
|
|
|
&StatusNotifierItem::secondaryActivateRequested,
|
|
|
|
this,
|
|
|
|
[=](const QPoint &) {
|
|
|
|
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
|
|
|
handleTrayIconActication(QSystemTrayIcon::MiddleClick);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
updateTrayMenu();
|
|
|
|
}
|
|
|
|
#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION
|
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
void MainWindow::psSetupTrayIcon() {
|
2020-01-31 06:34:37 +00:00
|
|
|
if (IsSNIAvailable()) {
|
|
|
|
#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
|
|
|
|
LOG(("Using SNI tray icon."));
|
|
|
|
if (!_sniTrayIcon) {
|
|
|
|
_sniTrayIcon = new StatusNotifierItem(
|
|
|
|
QCoreApplication::applicationName(),
|
|
|
|
this);
|
|
|
|
|
2020-02-06 11:34:28 +00:00
|
|
|
_sniTrayIcon->setTitle(AppName.utf16());
|
2020-02-21 15:35:22 +00:00
|
|
|
setSNITrayIcon(TrayIconGen());
|
2020-01-31 06:34:37 +00:00
|
|
|
|
|
|
|
attachToSNITrayIcon();
|
|
|
|
}
|
2016-11-11 07:51:53 +00:00
|
|
|
updateIconCounters();
|
2020-01-31 06:34:37 +00:00
|
|
|
#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION
|
2016-06-16 12:59:54 +00:00
|
|
|
} else {
|
2016-10-19 12:24:39 +00:00
|
|
|
LOG(("Using Qt tray icon."));
|
2020-01-31 06:34:37 +00:00
|
|
|
|
|
|
|
if (!_trayIconMenuXEmbed) {
|
|
|
|
_trayIconMenuXEmbed = new Ui::PopupMenu(nullptr, trayIconMenu);
|
|
|
|
_trayIconMenuXEmbed->deleteOnHide(false);
|
|
|
|
}
|
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
if (!trayIcon) {
|
|
|
|
trayIcon = new QSystemTrayIcon(this);
|
2020-02-21 15:35:22 +00:00
|
|
|
trayIcon->setIcon(TrayIconGen());
|
2016-06-21 14:19:24 +00:00
|
|
|
|
2019-04-12 13:21:01 +00:00
|
|
|
attachToTrayIcon(trayIcon);
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
2016-11-11 07:51:53 +00:00
|
|
|
updateIconCounters();
|
2016-06-16 12:59:54 +00:00
|
|
|
|
|
|
|
trayIcon->show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
void MainWindow::workmodeUpdated(DBIWorkMode mode) {
|
2016-06-16 12:59:54 +00:00
|
|
|
if (!cSupportTray()) return;
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
if (mode == dbiwmWindowOnly) {
|
2020-01-31 06:34:37 +00:00
|
|
|
if (IsSNIAvailable()) {
|
|
|
|
#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
|
|
|
|
if (_sniTrayIcon) {
|
|
|
|
_sniTrayIcon->setContextMenu(0);
|
|
|
|
_sniTrayIcon->deleteLater();
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
2020-01-31 06:34:37 +00:00
|
|
|
_sniTrayIcon = 0;
|
|
|
|
#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION
|
2016-06-16 12:59:54 +00:00
|
|
|
} else {
|
|
|
|
if (trayIcon) {
|
|
|
|
trayIcon->setContextMenu(0);
|
|
|
|
trayIcon->deleteLater();
|
|
|
|
}
|
|
|
|
trayIcon = 0;
|
|
|
|
}
|
|
|
|
} else {
|
2020-01-31 06:34:37 +00:00
|
|
|
psSetupTrayIcon();
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-11 07:51:53 +00:00
|
|
|
void MainWindow::unreadCounterChangedHook() {
|
|
|
|
setWindowTitle(titleText());
|
|
|
|
updateIconCounters();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::updateIconCounters() {
|
2017-05-12 15:27:19 +00:00
|
|
|
updateWindowIcon();
|
2016-06-16 12:59:54 +00:00
|
|
|
|
2020-01-21 12:51:39 +00:00
|
|
|
#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
|
2020-02-20 03:00:26 +00:00
|
|
|
if (UseUnityCounter()) {
|
2020-01-24 01:39:46 +00:00
|
|
|
const auto counter = Core::App().unreadBadge();
|
2020-02-20 03:00:26 +00:00
|
|
|
const auto launcherUrl = "application://" + GetLauncherFilename();
|
2018-12-07 17:59:14 +00:00
|
|
|
QVariantMap dbusUnityProperties;
|
2016-06-16 12:59:54 +00:00
|
|
|
if (counter > 0) {
|
2018-12-07 17:59:14 +00:00
|
|
|
// Gnome requires that count is a 64bit integer
|
2020-01-31 06:34:37 +00:00
|
|
|
dbusUnityProperties.insert(
|
|
|
|
"count",
|
|
|
|
(qint64) ((counter > 9999)
|
|
|
|
? 9999
|
2020-02-20 03:00:26 +00:00
|
|
|
: counter));
|
2018-12-07 17:59:14 +00:00
|
|
|
dbusUnityProperties.insert("count-visible", true);
|
2016-06-16 12:59:54 +00:00
|
|
|
} else {
|
2018-12-07 17:59:14 +00:00
|
|
|
dbusUnityProperties.insert("count-visible", false);
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
2020-01-31 06:34:37 +00:00
|
|
|
QDBusMessage signal = QDBusMessage::createSignal(
|
2020-02-20 03:00:26 +00:00
|
|
|
"/com/canonical/unity/launcherentry/"
|
|
|
|
+ QString::number(djbStringHash(launcherUrl)),
|
2020-01-31 06:34:37 +00:00
|
|
|
"com.canonical.Unity.LauncherEntry",
|
|
|
|
"Update");
|
2020-02-20 03:00:26 +00:00
|
|
|
signal << launcherUrl;
|
2018-12-07 17:59:14 +00:00
|
|
|
signal << dbusUnityProperties;
|
|
|
|
QDBusConnection::sessionBus().send(signal);
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
2020-01-31 06:34:37 +00:00
|
|
|
#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION
|
|
|
|
|
|
|
|
if (IsSNIAvailable()) {
|
|
|
|
#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
|
|
|
|
if (_sniTrayIcon) {
|
2020-02-21 15:35:22 +00:00
|
|
|
setSNITrayIcon(TrayIconGen());
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
2020-01-31 06:34:37 +00:00
|
|
|
#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION
|
2016-06-16 12:59:54 +00:00
|
|
|
} else if (trayIcon) {
|
2020-02-21 15:35:22 +00:00
|
|
|
trayIcon->setIcon(TrayIconGen());
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-16 17:20:58 +00:00
|
|
|
void MainWindow::LibsLoaded() {
|
2020-01-31 06:34:37 +00:00
|
|
|
#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
|
|
|
|
qDBusRegisterMetaType<ToolTip>();
|
|
|
|
qDBusRegisterMetaType<IconPixmap>();
|
|
|
|
qDBusRegisterMetaType<IconPixmapList>();
|
|
|
|
#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
|
|
|
|
2020-02-12 08:09:17 +00:00
|
|
|
void MainWindow::initTrayMenuHook() {
|
2020-01-31 06:34:37 +00:00
|
|
|
const auto trayAvailable = IsSNIAvailable()
|
|
|
|
|| QSystemTrayIcon::isSystemTrayAvailable();
|
|
|
|
|
|
|
|
LOG(("System tray available: %1").arg(Logs::b(trayAvailable)));
|
|
|
|
cSetSupportTray(trayAvailable);
|
2016-06-16 12:59:54 +00:00
|
|
|
|
2020-02-20 03:00:26 +00:00
|
|
|
if (UseUnityCounter()) {
|
|
|
|
LOG(("Using Unity launcher counter."));
|
2016-06-16 12:59:54 +00:00
|
|
|
} else {
|
2020-02-20 03:00:26 +00:00
|
|
|
LOG(("Not using Unity launcher counter."));
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow() {
|
2020-01-31 06:34:37 +00:00
|
|
|
#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
|
|
|
|
delete _sniTrayIcon;
|
|
|
|
#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION
|
|
|
|
|
|
|
|
delete _trayIconMenuXEmbed;
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Platform
|