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 kTrayIconName = "telegram"_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-01-24 01:39:46 +00:00
|
|
|
int32 _trayIconSize = 48;
|
2016-06-16 17:20:58 +00:00
|
|
|
bool _trayIconMuted = true;
|
|
|
|
int32 _trayIconCount = 0;
|
|
|
|
QImage _trayIconImageBack, _trayIconImage;
|
2020-01-24 01:39:46 +00:00
|
|
|
QString _trayIconThemeName, _trayIconName;
|
2020-01-21 12:51:39 +00:00
|
|
|
|
|
|
|
#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
|
2020-01-31 06:34:37 +00:00
|
|
|
bool UseUnityCount = false;
|
|
|
|
QString UnityCountDesktopFile;
|
|
|
|
QString UnityCountDBusPath = "/";
|
|
|
|
#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION
|
2016-06-16 17:20:58 +00:00
|
|
|
|
|
|
|
#define QT_RED 0
|
|
|
|
#define QT_GREEN 1
|
|
|
|
#define QT_BLUE 2
|
|
|
|
#define QT_ALPHA 3
|
|
|
|
|
2020-01-31 06:34:37 +00:00
|
|
|
QString GetTrayIconName() {
|
|
|
|
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-01-31 06:34:37 +00:00
|
|
|
QImage TrayIconImageGen() {
|
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-01-31 06:34:37 +00:00
|
|
|
const auto iconThemeName = QIcon::themeName();
|
|
|
|
const auto iconName = GetTrayIconName();
|
2020-02-06 11:34:28 +00:00
|
|
|
const auto desiredSize = QSize(_trayIconSize, _trayIconSize);
|
2020-01-24 01:39:46 +00:00
|
|
|
|
2020-01-31 06:34:37 +00:00
|
|
|
if (_trayIconImage.isNull()
|
2020-02-06 11:34:28 +00:00
|
|
|
|| _trayIconImage.size() != desiredSize
|
2020-01-31 06:34:37 +00:00
|
|
|
|| iconThemeName != _trayIconThemeName
|
|
|
|
|| iconName != _trayIconName
|
|
|
|
|| muted != _trayIconMuted
|
|
|
|
|| counterSlice != _trayIconCount) {
|
2020-01-24 01:39:46 +00:00
|
|
|
if (_trayIconImageBack.isNull()
|
2020-02-06 11:34:28 +00:00
|
|
|
|| _trayIconImageBack.size() != desiredSize
|
2020-01-24 01:39:46 +00:00
|
|
|
|| iconThemeName != _trayIconThemeName
|
|
|
|
|| iconName != _trayIconName) {
|
2020-02-06 11:34:28 +00:00
|
|
|
const auto hasPanelIcon = QIcon::hasThemeIcon(iconName);
|
2020-01-24 01:39:46 +00:00
|
|
|
|
2020-02-06 11:34:28 +00:00
|
|
|
if (hasPanelIcon || QIcon::hasThemeIcon(kTrayIconName.utf16())) {
|
|
|
|
QIcon systemIcon;
|
2020-01-24 01:39:46 +00:00
|
|
|
|
2020-02-06 11:34:28 +00:00
|
|
|
if (hasPanelIcon) {
|
|
|
|
systemIcon = QIcon::fromTheme(iconName);
|
|
|
|
} else {
|
|
|
|
systemIcon = QIcon::fromTheme(kTrayIconName.utf16());
|
|
|
|
}
|
2020-01-24 01:39:46 +00:00
|
|
|
|
2020-02-06 11:34:28 +00:00
|
|
|
if (systemIcon.actualSize(desiredSize) == desiredSize) {
|
|
|
|
_trayIconImageBack = systemIcon
|
|
|
|
.pixmap(desiredSize)
|
|
|
|
.toImage();
|
|
|
|
} else {
|
|
|
|
const auto biggestSize = systemIcon
|
|
|
|
.availableSizes()
|
|
|
|
.last();
|
|
|
|
|
|
|
|
_trayIconImageBack = systemIcon
|
|
|
|
.pixmap(biggestSize)
|
|
|
|
.toImage();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_trayIconImageBack = Core::App().logo();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_trayIconImageBack.size() != desiredSize) {
|
2020-01-24 01:39:46 +00:00
|
|
|
_trayIconImageBack = _trayIconImageBack.scaled(
|
2020-02-06 11:34:28 +00:00
|
|
|
desiredSize,
|
2020-01-24 01:39:46 +00:00
|
|
|
Qt::IgnoreAspectRatio,
|
|
|
|
Qt::SmoothTransformation);
|
|
|
|
}
|
|
|
|
|
|
|
|
_trayIconImageBack = _trayIconImageBack.convertToFormat(
|
|
|
|
QImage::Format_ARGB32);
|
|
|
|
|
2020-02-06 11:34:28 +00:00
|
|
|
const auto w = _trayIconImageBack.width();
|
|
|
|
const auto h = _trayIconImageBack.height();
|
2020-01-31 06:34:37 +00:00
|
|
|
const auto perline = _trayIconImageBack.bytesPerLine();
|
|
|
|
auto *bytes = _trayIconImageBack.bits();
|
2020-01-24 01:39:46 +00:00
|
|
|
|
2016-10-19 12:24:39 +00:00
|
|
|
for (int32 y = 0; y < h; ++y) {
|
|
|
|
for (int32 x = 0; x < w; ++x) {
|
|
|
|
int32 srcoff = y * perline + x * 4;
|
2020-01-24 01:39:46 +00:00
|
|
|
bytes[srcoff + QT_RED ] = qMax(
|
|
|
|
bytes[srcoff + QT_RED ],
|
|
|
|
uchar(224));
|
|
|
|
bytes[srcoff + QT_GREEN] = qMax(
|
|
|
|
bytes[srcoff + QT_GREEN],
|
|
|
|
uchar(165));
|
|
|
|
bytes[srcoff + QT_BLUE ] = qMax(
|
|
|
|
bytes[srcoff + QT_BLUE ],
|
|
|
|
uchar(44));
|
2016-10-19 12:24:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-24 01:39:46 +00:00
|
|
|
|
2016-10-19 12:24:39 +00:00
|
|
|
_trayIconImage = _trayIconImageBack;
|
2019-01-10 13:55:56 +00:00
|
|
|
_trayIconMuted = muted;
|
|
|
|
_trayIconCount = counterSlice;
|
2020-01-24 01:39:46 +00:00
|
|
|
_trayIconThemeName = iconThemeName;
|
|
|
|
_trayIconName = iconName;
|
|
|
|
|
2016-10-19 12:24:39 +00:00
|
|
|
if (counter > 0) {
|
|
|
|
QPainter p(&_trayIconImage);
|
|
|
|
int32 layerSize = -16;
|
2020-01-24 01:39:46 +00:00
|
|
|
|
2016-10-19 12:24:39 +00:00
|
|
|
if (_trayIconSize >= 48) {
|
|
|
|
layerSize = -32;
|
|
|
|
} else if (_trayIconSize >= 36) {
|
|
|
|
layerSize = -24;
|
|
|
|
} else if (_trayIconSize >= 32) {
|
|
|
|
layerSize = -20;
|
|
|
|
}
|
2020-01-24 01:39:46 +00:00
|
|
|
|
2016-10-31 12:29:26 +00:00
|
|
|
auto &bg = (muted ? st::trayCounterBgMute : st::trayCounterBg);
|
|
|
|
auto &fg = st::trayCounterFg;
|
2020-01-24 01:39:46 +00:00
|
|
|
|
|
|
|
auto layer = App::wnd()->iconWithCounter(
|
|
|
|
layerSize,
|
|
|
|
counter,
|
|
|
|
bg,
|
|
|
|
fg,
|
|
|
|
false);
|
|
|
|
|
|
|
|
p.drawImage(
|
|
|
|
_trayIconImage.width() - layer.width() - 1,
|
|
|
|
_trayIconImage.height() - layer.height() - 1,
|
|
|
|
layer);
|
2016-10-19 12:24:39 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-24 01:39:46 +00:00
|
|
|
|
2016-10-19 12:24:39 +00:00
|
|
|
return _trayIconImage;
|
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-06 11:34:28 +00:00
|
|
|
static const auto TrayIconFileNeeded = IsAppIndicator()
|
|
|
|
// Ubuntu's tray extension doesn't zoom image data, but zooms image file
|
|
|
|
|| DesktopEnvironment::IsGnome();
|
|
|
|
|
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-06 11:34:28 +00:00
|
|
|
const QImage &icon, QObject *parent) {
|
2020-01-31 06:34:37 +00:00
|
|
|
auto ret = std::make_unique<QTemporaryFile>(
|
|
|
|
TrayIconFileTemplate(),
|
|
|
|
parent);
|
|
|
|
ret->open();
|
|
|
|
icon.save(ret.get());
|
|
|
|
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
|
|
|
|
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
|
|
|
|
void MainWindow::setSNITrayIcon(
|
2020-02-06 11:34:28 +00:00
|
|
|
const QIcon &icon, const QImage &iconImage) {
|
2020-01-31 06:34:37 +00:00
|
|
|
if (!NeedTrayIconFile()) {
|
|
|
|
_sniTrayIcon->setIconByPixmap(icon);
|
|
|
|
_sniTrayIcon->setToolTipIconByPixmap(icon);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (qEnvironmentVariableIsSet(kDisableTrayCounter.utf8())) {
|
|
|
|
const auto iconName = GetTrayIconName();
|
|
|
|
_sniTrayIcon->setIconByName(iconName);
|
|
|
|
_sniTrayIcon->setToolTipIconByName(iconName);
|
|
|
|
} else if (NeedTrayIconFile()) {
|
2020-02-06 11:34:28 +00:00
|
|
|
_trayIconFile = TrayIconFile(iconImage, this);
|
2020-01-31 06:34:37 +00:00
|
|
|
|
|
|
|
if (_trayIconFile) {
|
|
|
|
_sniTrayIcon->setIconByName(_trayIconFile->fileName());
|
|
|
|
_sniTrayIcon->setToolTipIconByName(_trayIconFile->fileName());
|
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-02-06 11:34:28 +00:00
|
|
|
const auto iconImage = TrayIconImageGen();
|
|
|
|
const auto icon = QIcon(QPixmap::fromImage(iconImage));
|
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());
|
|
|
|
setSNITrayIcon(icon, iconImage);
|
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-01-31 06:34:37 +00:00
|
|
|
trayIcon->setIcon(icon);
|
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-01-31 06:34:37 +00:00
|
|
|
if (UseUnityCount) {
|
2020-01-24 01:39:46 +00:00
|
|
|
const auto counter = Core::App().unreadBadge();
|
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
|
|
|
|
: (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(
|
|
|
|
UnityCountDBusPath,
|
|
|
|
"com.canonical.Unity.LauncherEntry",
|
|
|
|
"Update");
|
|
|
|
signal << "application://" + UnityCountDesktopFile;
|
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
|
|
|
|
|
2020-02-06 11:34:28 +00:00
|
|
|
const auto iconImage = TrayIconImageGen();
|
|
|
|
const auto icon = QIcon(QPixmap::fromImage(iconImage));
|
2020-01-31 06:34:37 +00:00
|
|
|
|
|
|
|
if (IsSNIAvailable()) {
|
|
|
|
#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
|
|
|
|
if (_sniTrayIcon) {
|
2020-02-06 11:34:28 +00:00
|
|
|
setSNITrayIcon(icon, iconImage);
|
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-01-31 06:34:37 +00:00
|
|
|
trayIcon->setIcon(icon);
|
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-06 11:34:28 +00:00
|
|
|
if (!IsSNIAvailable() || IsAppIndicator()) {
|
2020-01-31 06:34:37 +00:00
|
|
|
_trayIconSize = 22;
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::psFirstShow() {
|
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-01-21 12:51:39 +00:00
|
|
|
#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
|
2018-12-07 17:59:14 +00:00
|
|
|
if (QDBusInterface("com.canonical.Unity", "/").isValid()) {
|
2020-01-31 06:34:37 +00:00
|
|
|
const std::vector<QString> possibleDesktopFiles = {
|
2020-01-30 18:41:24 +00:00
|
|
|
GetLauncherFilename(),
|
|
|
|
"Telegram.desktop"
|
|
|
|
};
|
|
|
|
|
2020-01-31 06:34:37 +00:00
|
|
|
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;
|
2020-01-30 18:41:24 +00:00
|
|
|
break;
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
2020-01-30 18:41:24 +00:00
|
|
|
}
|
2020-01-31 06:34:37 +00:00
|
|
|
if (!UseUnityCount) {
|
2020-01-30 18:41:24 +00:00
|
|
|
LOG(("Could not get Unity Launcher entry!"));
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
2020-01-31 06:34:37 +00:00
|
|
|
UnityCountDBusPath = "/com/canonical/unity/launcherentry/"
|
|
|
|
+ QString::number(
|
|
|
|
djbStringHash("application://" + UnityCountDesktopFile));
|
2016-06-16 12:59:54 +00:00
|
|
|
} else {
|
|
|
|
LOG(("Not using Unity Launcher count."));
|
|
|
|
}
|
2020-01-31 06:34:37 +00:00
|
|
|
#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION
|
2016-06-16 12:59:54 +00:00
|
|
|
|
|
|
|
show();
|
|
|
|
if (cWindowPos().maximized) {
|
2017-07-03 12:23:41 +00:00
|
|
|
DEBUG_LOG(("Window Pos: First show, setting maximized."));
|
2016-06-16 12:59:54 +00:00
|
|
|
setWindowState(Qt::WindowMaximized);
|
|
|
|
}
|
|
|
|
|
2020-01-31 06:34:37 +00:00
|
|
|
if ((cLaunchMode() == LaunchModeAutoStart && cStartMinimized())
|
|
|
|
|| cStartInTray()) {
|
2020-01-28 08:40:27 +00:00
|
|
|
// If I call hide() synchronously here after show() then on Ubuntu 14.04
|
|
|
|
// it will show a window frame with transparent window body, without content.
|
|
|
|
// And to be able to "Show from tray" one more hide() will be required.
|
|
|
|
crl::on_main(this, [=] {
|
|
|
|
setWindowState(Qt::WindowMinimized);
|
2020-01-31 06:34:37 +00:00
|
|
|
if (Global::WorkMode().value() == dbiwmTrayOnly
|
|
|
|
|| Global::WorkMode().value() == dbiwmWindowAndTray) {
|
2020-01-28 08:40:27 +00:00
|
|
|
hide();
|
|
|
|
} else {
|
|
|
|
show();
|
|
|
|
}
|
|
|
|
});
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
|
|
|
|
2016-11-04 11:14:47 +00:00
|
|
|
setPositionInited();
|
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
|