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"
|
2020-01-30 18:41:24 +00:00
|
|
|
#include "platform/linux/specific_linux.h"
|
2018-01-25 14:19:14 +00:00
|
|
|
#include "history/history.h"
|
2020-03-04 05:45:44 +00:00
|
|
|
#include "history/history_widget.h"
|
|
|
|
#include "history/history_inner_widget.h"
|
|
|
|
#include "main/main_account.h" // Account::sessionChanges.
|
2020-06-26 08:27:54 +00:00
|
|
|
#include "main/main_session.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"
|
2020-03-04 05:45:44 +00:00
|
|
|
#include "boxes/peer_list_controllers.h"
|
|
|
|
#include "boxes/about_box.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"
|
2020-06-24 07:56:16 +00:00
|
|
|
#include "window/window_controller.h"
|
2020-03-04 05:45:44 +00:00
|
|
|
#include "window/window_session_controller.h"
|
|
|
|
#include "ui/widgets/input_fields.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-03-04 05:45:44 +00:00
|
|
|
#include <QtGui/QWindow>
|
2020-02-06 11:34:28 +00:00
|
|
|
|
2020-08-08 12:07:13 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-03-03 01:24:13 +00:00
|
|
|
#include <QtDBus/QDBusInterface>
|
|
|
|
#include <QtDBus/QDBusConnection>
|
|
|
|
#include <QtDBus/QDBusConnectionInterface>
|
2020-03-10 10:17:19 +00:00
|
|
|
#include <QtDBus/QDBusServiceWatcher>
|
2020-03-03 01:24:13 +00:00
|
|
|
#include <QtDBus/QDBusMessage>
|
|
|
|
#include <QtDBus/QDBusReply>
|
|
|
|
#include <QtDBus/QDBusError>
|
|
|
|
#include <QtDBus/QDBusMetaType>
|
2020-08-08 12:07:13 +00:00
|
|
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2016-06-16 12:59:54 +00:00
|
|
|
|
2020-08-01 12:33:45 +00:00
|
|
|
#include <glib.h>
|
|
|
|
|
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;
|
2020-03-12 12:49:04 +00:00
|
|
|
constexpr auto kForcePanelIcon = "TDESKTOP_FORCE_PANEL_ICON"_cs;
|
2020-01-31 06:34:37 +00:00
|
|
|
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;
|
2020-03-03 01:24:13 +00:00
|
|
|
constexpr auto kPropertiesInterface = "org.freedesktop.DBus.Properties"_cs;
|
2020-01-31 06:34:37 +00:00
|
|
|
constexpr auto kTrayIconFilename = "tdesktop-trayicon-XXXXXX.png"_cs;
|
2016-06-16 17:20:58 +00:00
|
|
|
|
2020-03-04 05:45:44 +00:00
|
|
|
constexpr auto kAppMenuService = "com.canonical.AppMenu.Registrar"_cs;
|
|
|
|
constexpr auto kAppMenuObjectPath = "/com/canonical/AppMenu/Registrar"_cs;
|
|
|
|
constexpr auto kAppMenuInterface = kAppMenuService;
|
|
|
|
|
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-03-10 10:17:19 +00:00
|
|
|
bool SNIAvailable = false;
|
2020-05-03 11:45:32 +00:00
|
|
|
bool AppMenuSupported = false;
|
2020-03-10 10:17:19 +00:00
|
|
|
|
2020-03-03 01:24:13 +00:00
|
|
|
QString GetPanelIconName(int counter, bool muted) {
|
2020-01-31 06:34:37 +00:00
|
|
|
return (counter > 0)
|
|
|
|
? (muted
|
|
|
|
? kMutePanelTrayIconName.utf16()
|
|
|
|
: kAttentionPanelTrayIconName.utf16())
|
|
|
|
: kPanelTrayIconName.utf16();
|
|
|
|
}
|
2016-06-16 17:20:58 +00:00
|
|
|
|
2020-03-03 01:24:13 +00:00
|
|
|
QString GetTrayIconName(int counter, bool muted) {
|
2020-02-26 11:38:31 +00:00
|
|
|
const auto iconName = GetIconName();
|
2020-03-03 01:24:13 +00:00
|
|
|
const auto panelIconName = GetPanelIconName(counter, muted);
|
2020-02-20 01:13:15 +00:00
|
|
|
|
2020-03-17 19:13:11 +00:00
|
|
|
if (QIcon::hasThemeIcon(panelIconName)
|
|
|
|
|| qEnvironmentVariableIsSet(kForcePanelIcon.utf8())) {
|
2020-02-20 01:13:15 +00:00
|
|
|
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-03-05 19:46:46 +00:00
|
|
|
int GetCounterSlice(int counter) {
|
|
|
|
return (counter >= 1000)
|
|
|
|
? (1000 + (counter % 100))
|
|
|
|
: counter;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsIconRegenerationNeeded(
|
|
|
|
int counter,
|
|
|
|
bool muted,
|
|
|
|
const QString &iconThemeName = QIcon::themeName()) {
|
|
|
|
const auto iconName = GetTrayIconName(counter, muted);
|
|
|
|
const auto counterSlice = GetCounterSlice(counter);
|
|
|
|
|
|
|
|
return TrayIcon.isNull()
|
|
|
|
|| iconThemeName != TrayIconThemeName
|
|
|
|
|| iconName != TrayIconName
|
|
|
|
|| muted != TrayIconMuted
|
|
|
|
|| counterSlice != TrayIconCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateIconRegenerationNeeded(
|
|
|
|
const QIcon &icon,
|
|
|
|
int counter,
|
|
|
|
bool muted,
|
|
|
|
const QString &iconThemeName) {
|
|
|
|
const auto iconName = GetTrayIconName(counter, muted);
|
|
|
|
const auto counterSlice = GetCounterSlice(counter);
|
|
|
|
|
|
|
|
TrayIcon = icon;
|
|
|
|
TrayIconMuted = muted;
|
|
|
|
TrayIconCount = counterSlice;
|
|
|
|
TrayIconThemeName = iconThemeName;
|
|
|
|
TrayIconName = iconName;
|
|
|
|
}
|
|
|
|
|
2020-03-03 01:24:13 +00:00
|
|
|
QIcon TrayIconGen(int counter, bool muted) {
|
2020-02-21 15:35:22 +00:00
|
|
|
const auto iconThemeName = QIcon::themeName();
|
2020-03-05 19:46:46 +00:00
|
|
|
|
|
|
|
if (!IsIconRegenerationNeeded(counter, muted, iconThemeName)) {
|
|
|
|
return TrayIcon;
|
|
|
|
}
|
|
|
|
|
2020-03-03 01:24:13 +00:00
|
|
|
const auto iconName = GetTrayIconName(counter, muted);
|
2020-02-21 15:35:22 +00:00
|
|
|
|
|
|
|
if (qEnvironmentVariableIsSet(kDisableTrayCounter.utf8())
|
|
|
|
&& !iconName.isEmpty()) {
|
2020-03-05 19:46:46 +00:00
|
|
|
const auto result = QIcon::fromTheme(iconName);
|
|
|
|
UpdateIconRegenerationNeeded(result, counter, muted, iconThemeName);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
QIcon result;
|
|
|
|
QIcon systemIcon;
|
|
|
|
|
|
|
|
const auto iconSizes = {
|
|
|
|
16,
|
|
|
|
22,
|
|
|
|
24,
|
|
|
|
32,
|
|
|
|
48,
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const auto iconSize : iconSizes) {
|
|
|
|
auto ¤tImageBack = TrayIconImageBack[iconSize];
|
|
|
|
const auto desiredSize = QSize(iconSize, iconSize);
|
|
|
|
|
|
|
|
if (currentImageBack.isNull()
|
2020-02-21 15:35:22 +00:00
|
|
|
|| iconThemeName != TrayIconThemeName
|
|
|
|
|| iconName != TrayIconName) {
|
2020-03-05 19:46:46 +00:00
|
|
|
if (!iconName.isEmpty()) {
|
2020-03-17 19:13:11 +00:00
|
|
|
if (systemIcon.isNull()) {
|
2020-03-05 19:46:46 +00:00
|
|
|
systemIcon = QIcon::fromTheme(iconName);
|
|
|
|
}
|
2020-02-21 15:35:22 +00:00
|
|
|
|
2020-03-05 19:46:46 +00:00
|
|
|
if (systemIcon.actualSize(desiredSize) == desiredSize) {
|
|
|
|
currentImageBack = systemIcon
|
|
|
|
.pixmap(desiredSize)
|
|
|
|
.toImage();
|
|
|
|
} else {
|
2020-03-16 11:43:15 +00:00
|
|
|
const auto availableSizes = systemIcon.availableSizes();
|
2020-02-21 15:35:22 +00:00
|
|
|
|
2020-03-05 19:46:46 +00:00
|
|
|
const auto biggestSize = ranges::max_element(
|
|
|
|
availableSizes,
|
|
|
|
std::less<>(),
|
|
|
|
&QSize::width);
|
2020-01-24 01:39:46 +00:00
|
|
|
|
2020-03-05 19:46:46 +00:00
|
|
|
currentImageBack = systemIcon
|
|
|
|
.pixmap(*biggestSize)
|
|
|
|
.toImage();
|
2020-02-21 15:35:22 +00:00
|
|
|
}
|
2020-03-05 19:46:46 +00:00
|
|
|
} else {
|
|
|
|
currentImageBack = Core::App().logo();
|
|
|
|
}
|
2020-02-06 11:34:28 +00:00
|
|
|
|
2020-03-05 19:46:46 +00:00
|
|
|
if (currentImageBack.size() != desiredSize) {
|
|
|
|
currentImageBack = currentImageBack.scaled(
|
|
|
|
desiredSize,
|
|
|
|
Qt::IgnoreAspectRatio,
|
|
|
|
Qt::SmoothTransformation);
|
2020-02-06 11:34:28 +00:00
|
|
|
}
|
2020-03-05 19:46:46 +00:00
|
|
|
}
|
2020-02-06 11:34:28 +00:00
|
|
|
|
2020-03-05 19:46:46 +00:00
|
|
|
auto iconImage = currentImageBack;
|
2020-01-24 01:39:46 +00:00
|
|
|
|
2020-03-05 19:46:46 +00:00
|
|
|
if (!qEnvironmentVariableIsSet(kDisableTrayCounter.utf8())
|
|
|
|
&& counter > 0) {
|
2020-05-18 14:24:20 +00:00
|
|
|
const auto &bg = muted
|
2020-03-05 19:46:46 +00:00
|
|
|
? st::trayCounterBgMute
|
|
|
|
: st::trayCounterBg;
|
2020-05-18 14:24:20 +00:00
|
|
|
const auto &fg = st::trayCounterFg;
|
|
|
|
if (iconSize >= 22) {
|
|
|
|
auto layerSize = -16;
|
|
|
|
if (iconSize >= 48) {
|
|
|
|
layerSize = -32;
|
|
|
|
} else if (iconSize >= 36) {
|
|
|
|
layerSize = -24;
|
|
|
|
} else if (iconSize >= 32) {
|
|
|
|
layerSize = -20;
|
|
|
|
}
|
|
|
|
const auto layer = App::wnd()->iconWithCounter(
|
|
|
|
layerSize,
|
|
|
|
counter,
|
|
|
|
bg,
|
|
|
|
fg,
|
|
|
|
false);
|
|
|
|
|
|
|
|
QPainter p(&iconImage);
|
|
|
|
p.drawImage(
|
|
|
|
iconImage.width() - layer.width() - 1,
|
|
|
|
iconImage.height() - layer.height() - 1,
|
|
|
|
layer);
|
|
|
|
} else {
|
|
|
|
App::wnd()->placeSmallCounter(iconImage, 16, counter, bg, QPoint(), fg);
|
|
|
|
}
|
2016-10-19 12:24:39 +00:00
|
|
|
}
|
2020-02-21 15:35:22 +00:00
|
|
|
|
2020-03-05 19:46:46 +00:00
|
|
|
result.addPixmap(App::pixmapFromImageInPlace(
|
|
|
|
std::move(iconImage)));
|
2016-10-19 12:24:39 +00:00
|
|
|
}
|
2020-01-24 01:39:46 +00:00
|
|
|
|
2020-03-05 19:46:46 +00:00
|
|
|
UpdateIconRegenerationNeeded(result, counter, muted, iconThemeName);
|
|
|
|
|
|
|
|
return result;
|
2016-06-16 17:20:58 +00:00
|
|
|
}
|
|
|
|
|
2020-08-08 12:07:13 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-03-03 01:24:13 +00:00
|
|
|
bool IsIndicatorApplication() {
|
2020-08-04 05:32:04 +00:00
|
|
|
// 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-06-01 10:20:51 +00:00
|
|
|
static const auto Result = [] {
|
2020-03-03 01:24:13 +00:00
|
|
|
const auto interface = QDBusConnection::sessionBus().interface();
|
2016-06-16 17:20:58 +00:00
|
|
|
|
2020-04-13 09:20:19 +00:00
|
|
|
if (!interface) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-03-03 01:24:13 +00:00
|
|
|
const auto ubuntuIndicator = interface->isServiceRegistered(
|
|
|
|
qsl("com.canonical.indicator.application"));
|
|
|
|
|
|
|
|
const auto ayatanaIndicator = interface->isServiceRegistered(
|
|
|
|
qsl("org.ayatana.indicator.application"));
|
|
|
|
|
|
|
|
return ubuntuIndicator || ayatanaIndicator;
|
|
|
|
}();
|
|
|
|
|
2020-06-01 10:20:51 +00:00
|
|
|
return Result;
|
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,
|
2020-07-12 22:47:55 +00:00
|
|
|
QObject *parent = nullptr) {
|
2020-03-03 01:24:13 +00:00
|
|
|
static const auto templateName = AppRuntimeDirectory()
|
|
|
|
+ kTrayIconFilename.utf16();
|
|
|
|
|
2020-07-12 22:47:55 +00:00
|
|
|
const auto dpr = style::DevicePixelRatio();
|
|
|
|
const auto desiredSize = QSize(22 * dpr, 22 * dpr);
|
2020-03-16 11:43:15 +00:00
|
|
|
|
2020-01-31 06:34:37 +00:00
|
|
|
auto ret = std::make_unique<QTemporaryFile>(
|
2020-03-03 01:24:13 +00:00
|
|
|
templateName,
|
2020-01-31 06:34:37 +00:00
|
|
|
parent);
|
2020-03-03 01:24:13 +00:00
|
|
|
|
2020-01-31 06:34:37 +00:00
|
|
|
ret->open();
|
2020-03-16 11:43:15 +00:00
|
|
|
|
|
|
|
if (icon.actualSize(desiredSize) == desiredSize) {
|
|
|
|
icon.pixmap(desiredSize).save(ret.get());
|
|
|
|
} else {
|
|
|
|
const auto availableSizes = icon.availableSizes();
|
|
|
|
|
|
|
|
const auto biggestSize = ranges::max_element(
|
|
|
|
availableSizes,
|
|
|
|
std::less<>(),
|
|
|
|
&QSize::width);
|
|
|
|
|
|
|
|
icon
|
|
|
|
.pixmap(*biggestSize)
|
|
|
|
.scaled(
|
|
|
|
desiredSize,
|
|
|
|
Qt::IgnoreAspectRatio,
|
|
|
|
Qt::SmoothTransformation)
|
|
|
|
.save(ret.get());
|
|
|
|
}
|
|
|
|
|
2020-01-31 06:34:37 +00:00
|
|
|
ret->close();
|
2020-03-03 01:24:13 +00:00
|
|
|
|
2020-01-31 06:34:37 +00:00
|
|
|
return ret;
|
2016-06-16 17:20:58 +00:00
|
|
|
}
|
2020-03-28 03:34:13 +00:00
|
|
|
|
|
|
|
bool UseUnityCounter() {
|
2020-06-01 10:20:51 +00:00
|
|
|
static const auto Result = QDBusInterface(
|
2020-03-28 03:34:13 +00:00
|
|
|
"com.canonical.Unity",
|
|
|
|
"/").isValid();
|
|
|
|
|
2020-06-01 10:20:51 +00:00
|
|
|
return Result;
|
2020-03-28 03:34:13 +00:00
|
|
|
}
|
2020-08-08 12:07:13 +00:00
|
|
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-01-31 06:34:37 +00:00
|
|
|
|
|
|
|
bool IsSNIAvailable() {
|
2020-08-08 12:07:13 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-03-10 10:17:19 +00:00
|
|
|
auto message = QDBusMessage::createMethodCall(
|
|
|
|
kSNIWatcherService.utf16(),
|
|
|
|
qsl("/StatusNotifierWatcher"),
|
|
|
|
kPropertiesInterface.utf16(),
|
|
|
|
qsl("Get"));
|
|
|
|
|
|
|
|
message.setArguments({
|
|
|
|
kSNIWatcherService.utf16(),
|
|
|
|
qsl("IsStatusNotifierHostRegistered")
|
|
|
|
});
|
2020-01-31 06:34:37 +00:00
|
|
|
|
2020-03-10 10:17:19 +00:00
|
|
|
const QDBusReply<QVariant> reply = QDBusConnection::sessionBus().call(
|
|
|
|
message);
|
2020-01-31 06:34:37 +00:00
|
|
|
|
2020-03-10 10:17:19 +00:00
|
|
|
if (reply.isValid()) {
|
|
|
|
return reply.value().toBool();
|
|
|
|
} else if (reply.error().type() != QDBusError::ServiceUnknown) {
|
|
|
|
LOG(("SNI Error: %1").arg(reply.error().message()));
|
|
|
|
}
|
2020-08-08 12:07:13 +00:00
|
|
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-03-10 10:17:19 +00:00
|
|
|
|
|
|
|
return false;
|
2020-01-31 06:34:37 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2020-08-08 12:07:13 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-05-03 11:45:32 +00:00
|
|
|
bool IsAppMenuSupported() {
|
|
|
|
const auto interface = QDBusConnection::sessionBus().interface();
|
2020-04-13 09:20:19 +00:00
|
|
|
|
2020-05-03 11:45:32 +00:00
|
|
|
if (!interface) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-03-04 05:45:44 +00:00
|
|
|
|
2020-05-03 11:45:32 +00:00
|
|
|
return interface->isServiceRegistered(kAppMenuService.utf16());
|
2020-03-04 05:45:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RegisterAppMenu(uint winId, const QDBusObjectPath &menuPath) {
|
|
|
|
auto message = QDBusMessage::createMethodCall(
|
|
|
|
kAppMenuService.utf16(),
|
|
|
|
kAppMenuObjectPath.utf16(),
|
|
|
|
kAppMenuInterface.utf16(),
|
|
|
|
qsl("RegisterWindow"));
|
|
|
|
|
|
|
|
message.setArguments({
|
|
|
|
winId,
|
|
|
|
QVariant::fromValue(menuPath)
|
|
|
|
});
|
|
|
|
|
|
|
|
QDBusConnection::sessionBus().send(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnregisterAppMenu(uint winId) {
|
|
|
|
auto message = QDBusMessage::createMethodCall(
|
|
|
|
kAppMenuService.utf16(),
|
|
|
|
kAppMenuObjectPath.utf16(),
|
|
|
|
kAppMenuInterface.utf16(),
|
|
|
|
qsl("UnregisterWindow"));
|
|
|
|
|
|
|
|
message.setArguments({
|
|
|
|
winId
|
|
|
|
});
|
|
|
|
|
|
|
|
QDBusConnection::sessionBus().send(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendKeySequence(
|
|
|
|
Qt::Key key,
|
|
|
|
Qt::KeyboardModifiers modifiers = Qt::NoModifier) {
|
|
|
|
const auto focused = QApplication::focusWidget();
|
|
|
|
if (qobject_cast<QLineEdit*>(focused)
|
|
|
|
|| qobject_cast<QTextEdit*>(focused)
|
|
|
|
|| qobject_cast<HistoryInner*>(focused)) {
|
|
|
|
QApplication::postEvent(
|
|
|
|
focused,
|
|
|
|
new QKeyEvent(QEvent::KeyPress, key, modifiers));
|
|
|
|
|
|
|
|
QApplication::postEvent(
|
|
|
|
focused,
|
|
|
|
new QKeyEvent(QEvent::KeyRelease, key, modifiers));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ForceDisabled(QAction *action, bool disabled) {
|
|
|
|
if (action->isEnabled()) {
|
|
|
|
if (disabled) action->setDisabled(true);
|
|
|
|
} else if (!disabled) {
|
|
|
|
action->setDisabled(false);
|
|
|
|
}
|
|
|
|
}
|
2020-08-08 12:07:13 +00:00
|
|
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-03-04 05:45:44 +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
|
|
|
}
|
|
|
|
|
2020-03-03 01:24:13 +00:00
|
|
|
void MainWindow::initHook() {
|
2020-03-10 10:17:19 +00:00
|
|
|
SNIAvailable = IsSNIAvailable();
|
|
|
|
|
|
|
|
const auto trayAvailable = SNIAvailable
|
2020-03-03 01:24:13 +00:00
|
|
|
|| QSystemTrayIcon::isSystemTrayAvailable();
|
|
|
|
|
|
|
|
LOG(("System tray available: %1").arg(Logs::b(trayAvailable)));
|
2020-07-22 12:10:17 +00:00
|
|
|
Platform::SetTrayIconSupported(trayAvailable);
|
2020-03-03 01:24:13 +00:00
|
|
|
|
2020-08-08 12:07:13 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-03-16 11:43:15 +00:00
|
|
|
auto sniWatcher = new QDBusServiceWatcher(
|
2020-03-10 10:17:19 +00:00
|
|
|
kSNIWatcherService.utf16(),
|
|
|
|
QDBusConnection::sessionBus(),
|
|
|
|
QDBusServiceWatcher::WatchForOwnerChange,
|
|
|
|
this);
|
|
|
|
|
2020-03-16 11:43:15 +00:00
|
|
|
connect(
|
2020-03-10 10:17:19 +00:00
|
|
|
sniWatcher,
|
|
|
|
&QDBusServiceWatcher::serviceOwnerChanged,
|
|
|
|
this,
|
2020-08-28 16:14:19 +00:00
|
|
|
[=](
|
|
|
|
const QString &service,
|
|
|
|
const QString &oldOwner,
|
|
|
|
const QString &newOwner) {
|
|
|
|
handleSNIOwnerChanged(service, oldOwner, newOwner);
|
|
|
|
});
|
2020-03-14 12:13:33 +00:00
|
|
|
|
2020-05-03 11:45:32 +00:00
|
|
|
AppMenuSupported = IsAppMenuSupported();
|
|
|
|
|
|
|
|
auto appMenuWatcher = new QDBusServiceWatcher(
|
|
|
|
kAppMenuService.utf16(),
|
|
|
|
QDBusConnection::sessionBus(),
|
|
|
|
QDBusServiceWatcher::WatchForOwnerChange,
|
|
|
|
this);
|
|
|
|
|
|
|
|
connect(
|
|
|
|
appMenuWatcher,
|
|
|
|
&QDBusServiceWatcher::serviceOwnerChanged,
|
|
|
|
this,
|
2020-08-28 16:14:19 +00:00
|
|
|
[=](
|
|
|
|
const QString &service,
|
|
|
|
const QString &oldOwner,
|
|
|
|
const QString &newOwner) {
|
|
|
|
handleAppMenuOwnerChanged(service, oldOwner, newOwner);
|
|
|
|
});
|
2020-05-03 11:45:32 +00:00
|
|
|
|
|
|
|
if (AppMenuSupported) {
|
2020-03-28 03:34:13 +00:00
|
|
|
LOG(("Using D-Bus global menu."));
|
|
|
|
} else {
|
|
|
|
LOG(("Not using D-Bus global menu."));
|
|
|
|
}
|
2020-03-10 10:17:19 +00:00
|
|
|
|
2020-03-03 01:24:13 +00:00
|
|
|
if (UseUnityCounter()) {
|
|
|
|
LOG(("Using Unity launcher counter."));
|
|
|
|
} else {
|
|
|
|
LOG(("Not using Unity launcher counter."));
|
|
|
|
}
|
2020-08-08 12:07:13 +00:00
|
|
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-04-25 04:43:19 +00:00
|
|
|
|
2020-05-02 10:00:13 +00:00
|
|
|
updateWaylandDecorationColors();
|
|
|
|
|
2020-04-25 04:43:19 +00:00
|
|
|
style::PaletteChanged(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
updateWaylandDecorationColors();
|
|
|
|
}, lifetime());
|
2020-03-03 01:24:13 +00:00
|
|
|
}
|
|
|
|
|
2017-01-01 16:45:20 +00:00
|
|
|
bool MainWindow::hasTrayIcon() const {
|
2020-08-08 12:07:13 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-04-13 02:06:31 +00:00
|
|
|
return trayIcon || (SNIAvailable && _sniTrayIcon);
|
2017-08-07 11:57:34 +00:00
|
|
|
#else
|
|
|
|
return trayIcon;
|
2020-08-08 12:07:13 +00:00
|
|
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
|
|
|
|
2020-01-31 06:34:37 +00:00
|
|
|
void MainWindow::psShowTrayMenu() {
|
2020-03-10 10:17:19 +00:00
|
|
|
_trayIconMenuXEmbed->popup(QCursor::pos());
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
|
|
|
|
2020-01-31 06:34:37 +00:00
|
|
|
void MainWindow::psTrayMenuUpdated() {
|
2020-08-08 12:07:13 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-03-10 10:17:19 +00:00
|
|
|
if (_sniTrayIcon && trayIconMenu) {
|
|
|
|
_sniTrayIcon->setContextMenu(trayIconMenu);
|
2020-01-31 06:34:37 +00:00
|
|
|
}
|
2020-08-08 12:07:13 +00:00
|
|
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
|
|
|
|
2020-08-08 12:07:13 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-03-17 19:13:11 +00:00
|
|
|
void MainWindow::setSNITrayIcon(int counter, bool muted) {
|
2020-03-03 01:24:13 +00:00
|
|
|
const auto iconName = GetTrayIconName(counter, muted);
|
2020-02-20 01:13:15 +00:00
|
|
|
|
|
|
|
if (qEnvironmentVariableIsSet(kDisableTrayCounter.utf8())
|
2020-03-17 19:13:11 +00:00
|
|
|
&& !iconName.isEmpty()
|
|
|
|
&& (!InSnap()
|
2020-03-12 12:49:04 +00:00
|
|
|
|| qEnvironmentVariableIsSet(kForcePanelIcon.utf8()))) {
|
2020-03-05 19:46:46 +00:00
|
|
|
if (_sniTrayIcon->iconName() == iconName) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-31 06:34:37 +00:00
|
|
|
_sniTrayIcon->setIconByName(iconName);
|
|
|
|
_sniTrayIcon->setToolTipIconByName(iconName);
|
2020-03-03 01:24:13 +00:00
|
|
|
} else if (IsIndicatorApplication()) {
|
2020-03-17 19:13:11 +00:00
|
|
|
if (!IsIconRegenerationNeeded(counter, muted)
|
2020-07-15 18:45:59 +00:00
|
|
|
&& _trayIconFile
|
|
|
|
&& _sniTrayIcon->iconName() == _trayIconFile->fileName()) {
|
2020-03-05 19:46:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-03 01:24:13 +00:00
|
|
|
const auto icon = TrayIconGen(counter, muted);
|
2020-07-12 22:47:55 +00:00
|
|
|
_trayIconFile = TrayIconFile(icon, this);
|
2020-01-31 06:34:37 +00:00
|
|
|
|
|
|
|
if (_trayIconFile) {
|
2020-03-03 01:24:13 +00:00
|
|
|
// indicator-application doesn't support tooltips
|
2020-01-31 06:34:37 +00:00
|
|
|
_sniTrayIcon->setIconByName(_trayIconFile->fileName());
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
2020-02-16 08:01:05 +00:00
|
|
|
} else {
|
2020-03-17 19:13:11 +00:00
|
|
|
if (!IsIconRegenerationNeeded(counter, muted)
|
2020-07-15 18:45:59 +00:00
|
|
|
&& !_sniTrayIcon->iconPixmap().isEmpty()
|
|
|
|
&& _sniTrayIcon->iconName().isEmpty()) {
|
2020-03-05 19:46:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-03 01:24:13 +00:00
|
|
|
const auto icon = TrayIconGen(counter, muted);
|
2020-02-16 08:01:05 +00:00
|
|
|
_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();
|
|
|
|
}
|
2020-03-10 10:17:19 +00:00
|
|
|
|
2020-08-28 16:14:19 +00:00
|
|
|
void MainWindow::handleSNIOwnerChanged(
|
2020-03-10 10:17:19 +00:00
|
|
|
const QString &service,
|
|
|
|
const QString &oldOwner,
|
|
|
|
const QString &newOwner) {
|
2020-03-18 23:12:36 +00:00
|
|
|
if (Global::WorkMode().value() == dbiwmWindowOnly) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-10 10:17:19 +00:00
|
|
|
if (oldOwner.isEmpty() && !newOwner.isEmpty()) {
|
|
|
|
LOG(("Switching to SNI tray icon..."));
|
|
|
|
} else if (!oldOwner.isEmpty() && newOwner.isEmpty()) {
|
|
|
|
LOG(("Switching to Qt tray icon..."));
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (trayIcon) {
|
|
|
|
trayIcon->setContextMenu(0);
|
|
|
|
trayIcon->deleteLater();
|
|
|
|
}
|
|
|
|
trayIcon = nullptr;
|
|
|
|
|
2020-06-29 12:55:04 +00:00
|
|
|
SNIAvailable = !newOwner.isEmpty();
|
2020-03-10 10:17:19 +00:00
|
|
|
|
|
|
|
const auto trayAvailable = SNIAvailable
|
|
|
|
|| QSystemTrayIcon::isSystemTrayAvailable();
|
|
|
|
|
2020-07-22 12:10:17 +00:00
|
|
|
Platform::SetTrayIconSupported(trayAvailable);
|
2020-03-10 10:17:19 +00:00
|
|
|
|
2020-07-22 12:10:17 +00:00
|
|
|
if (trayAvailable) {
|
2020-03-10 10:17:19 +00:00
|
|
|
psSetupTrayIcon();
|
|
|
|
} else {
|
|
|
|
LOG(("System tray is not available."));
|
|
|
|
}
|
|
|
|
}
|
2020-05-03 11:45:32 +00:00
|
|
|
|
2020-08-28 16:14:19 +00:00
|
|
|
void MainWindow::handleAppMenuOwnerChanged(
|
2020-05-03 11:45:32 +00:00
|
|
|
const QString &service,
|
|
|
|
const QString &oldOwner,
|
|
|
|
const QString &newOwner) {
|
|
|
|
if (oldOwner.isEmpty() && !newOwner.isEmpty()) {
|
|
|
|
AppMenuSupported = true;
|
|
|
|
LOG(("Using D-Bus global menu."));
|
|
|
|
} else if (!oldOwner.isEmpty() && newOwner.isEmpty()) {
|
|
|
|
AppMenuSupported = false;
|
|
|
|
LOG(("Not using D-Bus global menu."));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (AppMenuSupported && !_mainMenuPath.path().isEmpty()) {
|
|
|
|
RegisterAppMenu(winId(), _mainMenuPath);
|
|
|
|
} else {
|
|
|
|
UnregisterAppMenu(winId());
|
|
|
|
}
|
|
|
|
}
|
2020-08-08 12:07:13 +00:00
|
|
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-01-31 06:34:37 +00:00
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
void MainWindow::psSetupTrayIcon() {
|
2020-03-03 01:24:13 +00:00
|
|
|
const auto counter = Core::App().unreadBadge();
|
|
|
|
const auto muted = Core::App().unreadBadgeMuted();
|
|
|
|
|
2020-03-10 10:17:19 +00:00
|
|
|
if (SNIAvailable) {
|
2020-08-08 12:07:13 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-01-31 06:34:37 +00:00
|
|
|
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-03-17 19:13:11 +00:00
|
|
|
setSNITrayIcon(counter, muted);
|
2020-01-31 06:34:37 +00:00
|
|
|
|
|
|
|
attachToSNITrayIcon();
|
|
|
|
}
|
2016-11-11 07:51:53 +00:00
|
|
|
updateIconCounters();
|
2020-08-08 12:07:13 +00:00
|
|
|
#endif // !DESKTOP_APP_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."));
|
2016-06-16 12:59:54 +00:00
|
|
|
if (!trayIcon) {
|
|
|
|
trayIcon = new QSystemTrayIcon(this);
|
2020-03-03 01:24:13 +00:00
|
|
|
trayIcon->setIcon(TrayIconGen(counter, muted));
|
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) {
|
2020-07-22 12:10:17 +00:00
|
|
|
if (!Platform::TrayIconSupported()) {
|
|
|
|
return;
|
|
|
|
} else if (mode == dbiwmWindowOnly) {
|
2020-08-08 12:07:13 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-03-10 10:17:19 +00:00
|
|
|
if (_sniTrayIcon) {
|
|
|
|
_sniTrayIcon->setContextMenu(0);
|
|
|
|
_sniTrayIcon->deleteLater();
|
|
|
|
}
|
|
|
|
_sniTrayIcon = nullptr;
|
2020-08-08 12:07:13 +00:00
|
|
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-03-10 10:17:19 +00:00
|
|
|
|
|
|
|
if (trayIcon) {
|
|
|
|
trayIcon->setContextMenu(0);
|
|
|
|
trayIcon->deleteLater();
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
2020-03-10 10:17:19 +00:00
|
|
|
trayIcon = nullptr;
|
2016-06-16 12:59:54 +00:00
|
|
|
} 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() {
|
2020-03-03 01:24:13 +00:00
|
|
|
const auto counter = Core::App().unreadBadge();
|
|
|
|
const auto muted = Core::App().unreadBadgeMuted();
|
|
|
|
|
2017-05-12 15:27:19 +00:00
|
|
|
updateWindowIcon();
|
2016-06-16 12:59:54 +00:00
|
|
|
|
2020-08-08 12:07:13 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-02-20 03:00:26 +00:00
|
|
|
if (UseUnityCounter()) {
|
|
|
|
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
|
|
|
|
2020-03-10 10:17:19 +00:00
|
|
|
if (_sniTrayIcon) {
|
|
|
|
setSNITrayIcon(counter, muted);
|
|
|
|
}
|
2020-08-08 12:07:13 +00:00
|
|
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-03-10 10:17:19 +00:00
|
|
|
|
|
|
|
if (trayIcon && IsIconRegenerationNeeded(counter, muted)) {
|
2020-03-03 01:24:13 +00:00
|
|
|
trayIcon->setIcon(TrayIconGen(counter, muted));
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-25 04:43:19 +00:00
|
|
|
void MainWindow::updateWaylandDecorationColors() {
|
2020-08-04 05:32:04 +00:00
|
|
|
windowHandle()->setProperty(
|
|
|
|
"__material_decoration_backgroundColor",
|
|
|
|
st::titleBgActive->c);
|
|
|
|
|
|
|
|
windowHandle()->setProperty(
|
|
|
|
"__material_decoration_foregroundColor",
|
|
|
|
st::titleFgActive->c);
|
|
|
|
|
|
|
|
windowHandle()->setProperty(
|
|
|
|
"__material_decoration_backgroundInactiveColor",
|
|
|
|
st::titleBg->c);
|
|
|
|
windowHandle()->setProperty(
|
|
|
|
"__material_decoration_foregroundInactiveColor",
|
|
|
|
st::titleFg->c);
|
2020-05-02 10:00:13 +00:00
|
|
|
|
|
|
|
// Trigger a QtWayland client-side decoration update
|
|
|
|
windowHandle()->resize(windowHandle()->size());
|
2020-04-25 04:43:19 +00:00
|
|
|
}
|
|
|
|
|
2016-06-16 17:20:58 +00:00
|
|
|
void MainWindow::LibsLoaded() {
|
2020-08-08 12:07:13 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-01-31 06:34:37 +00:00
|
|
|
qDBusRegisterMetaType<ToolTip>();
|
|
|
|
qDBusRegisterMetaType<IconPixmap>();
|
|
|
|
qDBusRegisterMetaType<IconPixmapList>();
|
2020-08-08 12:07:13 +00:00
|
|
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-08-01 12:33:45 +00:00
|
|
|
|
|
|
|
if (!qEnvironmentVariableIsSet(kDisableTrayCounter.utf8())) {
|
2020-08-16 21:07:33 +00:00
|
|
|
g_message(
|
2020-08-01 12:33:45 +00:00
|
|
|
"You can disable tray icon counter with %s "
|
|
|
|
"and make it look better if it is monochrome.",
|
|
|
|
kDisableTrayCounter.utf8().constData());
|
|
|
|
}
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
|
|
|
|
2020-02-12 08:09:17 +00:00
|
|
|
void MainWindow::initTrayMenuHook() {
|
2020-03-10 10:17:19 +00:00
|
|
|
_trayIconMenuXEmbed = new Ui::PopupMenu(nullptr, trayIconMenu);
|
|
|
|
_trayIconMenuXEmbed->deleteOnHide(false);
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
|
|
|
|
2020-08-08 12:07:13 +00:00
|
|
|
#ifdef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-03-14 12:13:33 +00:00
|
|
|
|
|
|
|
void MainWindow::createGlobalMenu() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::updateGlobalMenuHook() {
|
|
|
|
}
|
|
|
|
|
2020-09-18 09:09:05 +00:00
|
|
|
void MainWindow::handleVisibleChangedHook(bool visible) {
|
|
|
|
}
|
|
|
|
|
2020-08-08 12:07:13 +00:00
|
|
|
#else // DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-03-14 12:13:33 +00:00
|
|
|
|
2020-03-04 05:45:44 +00:00
|
|
|
void MainWindow::createGlobalMenu() {
|
|
|
|
psMainMenu = new QMenu(this);
|
|
|
|
|
|
|
|
auto file = psMainMenu->addMenu(tr::lng_mac_menu_file(tr::now));
|
|
|
|
|
2020-06-16 09:40:43 +00:00
|
|
|
psLogout = file->addAction(tr::lng_mac_menu_logout(tr::now));
|
|
|
|
connect(psLogout, &QAction::triggered, psLogout, [] {
|
|
|
|
if (App::wnd()) App::wnd()->showLogoutConfirmation();
|
|
|
|
});
|
2020-03-04 05:45:44 +00:00
|
|
|
|
|
|
|
auto quit = file->addAction(
|
|
|
|
tr::lng_mac_menu_quit_telegram(tr::now, lt_telegram, qsl("Telegram")),
|
|
|
|
App::wnd(),
|
2020-08-28 16:14:19 +00:00
|
|
|
[=] { App::wnd()->quitFromTray(); },
|
2020-03-04 05:45:44 +00:00
|
|
|
QKeySequence::Quit);
|
|
|
|
|
|
|
|
quit->setMenuRole(QAction::QuitRole);
|
|
|
|
|
|
|
|
auto edit = psMainMenu->addMenu(tr::lng_mac_menu_edit(tr::now));
|
|
|
|
|
|
|
|
psUndo = edit->addAction(
|
|
|
|
tr::lng_linux_menu_undo(tr::now),
|
|
|
|
this,
|
2020-08-28 16:14:19 +00:00
|
|
|
[=] { psLinuxUndo(); },
|
2020-03-04 05:45:44 +00:00
|
|
|
QKeySequence::Undo);
|
|
|
|
|
|
|
|
psRedo = edit->addAction(
|
|
|
|
tr::lng_linux_menu_redo(tr::now),
|
|
|
|
this,
|
2020-08-28 16:14:19 +00:00
|
|
|
[=] { psLinuxRedo(); },
|
2020-03-04 05:45:44 +00:00
|
|
|
QKeySequence::Redo);
|
|
|
|
|
|
|
|
edit->addSeparator();
|
|
|
|
|
|
|
|
psCut = edit->addAction(
|
|
|
|
tr::lng_mac_menu_cut(tr::now),
|
|
|
|
this,
|
2020-08-28 16:14:19 +00:00
|
|
|
[=] { psLinuxCut(); },
|
2020-03-04 05:45:44 +00:00
|
|
|
QKeySequence::Cut);
|
|
|
|
psCopy = edit->addAction(
|
|
|
|
tr::lng_mac_menu_copy(tr::now),
|
|
|
|
this,
|
2020-08-28 16:14:19 +00:00
|
|
|
[=] { psLinuxCopy(); },
|
2020-03-04 05:45:44 +00:00
|
|
|
QKeySequence::Copy);
|
|
|
|
|
|
|
|
psPaste = edit->addAction(
|
|
|
|
tr::lng_mac_menu_paste(tr::now),
|
|
|
|
this,
|
2020-08-28 16:14:19 +00:00
|
|
|
[=] { psLinuxPaste(); },
|
2020-03-04 05:45:44 +00:00
|
|
|
QKeySequence::Paste);
|
|
|
|
|
|
|
|
psDelete = edit->addAction(
|
|
|
|
tr::lng_mac_menu_delete(tr::now),
|
|
|
|
this,
|
2020-08-28 16:14:19 +00:00
|
|
|
[=] { psLinuxDelete(); },
|
2020-03-04 05:45:44 +00:00
|
|
|
QKeySequence(Qt::ControlModifier | Qt::Key_Backspace));
|
|
|
|
|
|
|
|
edit->addSeparator();
|
|
|
|
|
|
|
|
psBold = edit->addAction(
|
|
|
|
tr::lng_menu_formatting_bold(tr::now),
|
|
|
|
this,
|
2020-08-28 16:14:19 +00:00
|
|
|
[=] { psLinuxBold(); },
|
2020-03-04 05:45:44 +00:00
|
|
|
QKeySequence::Bold);
|
|
|
|
|
|
|
|
psItalic = edit->addAction(
|
|
|
|
tr::lng_menu_formatting_italic(tr::now),
|
|
|
|
this,
|
2020-08-28 16:14:19 +00:00
|
|
|
[=] { psLinuxItalic(); },
|
2020-03-04 05:45:44 +00:00
|
|
|
QKeySequence::Italic);
|
|
|
|
|
|
|
|
psUnderline = edit->addAction(
|
|
|
|
tr::lng_menu_formatting_underline(tr::now),
|
|
|
|
this,
|
2020-08-28 16:14:19 +00:00
|
|
|
[=] { psLinuxUnderline(); },
|
2020-03-04 05:45:44 +00:00
|
|
|
QKeySequence::Underline);
|
|
|
|
|
|
|
|
psStrikeOut = edit->addAction(
|
|
|
|
tr::lng_menu_formatting_strike_out(tr::now),
|
|
|
|
this,
|
2020-08-28 16:14:19 +00:00
|
|
|
[=] { psLinuxStrikeOut(); },
|
2020-03-04 05:45:44 +00:00
|
|
|
Ui::kStrikeOutSequence);
|
|
|
|
|
|
|
|
psMonospace = edit->addAction(
|
|
|
|
tr::lng_menu_formatting_monospace(tr::now),
|
|
|
|
this,
|
2020-08-28 16:14:19 +00:00
|
|
|
[=] { psLinuxMonospace(); },
|
2020-03-04 05:45:44 +00:00
|
|
|
Ui::kMonospaceSequence);
|
|
|
|
|
|
|
|
psClearFormat = edit->addAction(
|
|
|
|
tr::lng_menu_formatting_clear(tr::now),
|
|
|
|
this,
|
2020-08-28 16:14:19 +00:00
|
|
|
[=] { psLinuxClearFormat(); },
|
2020-03-04 05:45:44 +00:00
|
|
|
Ui::kClearFormatSequence);
|
|
|
|
|
|
|
|
edit->addSeparator();
|
|
|
|
|
|
|
|
psSelectAll = edit->addAction(
|
|
|
|
tr::lng_mac_menu_select_all(tr::now),
|
2020-08-28 16:14:19 +00:00
|
|
|
this, [=] { psLinuxSelectAll(); },
|
2020-03-04 05:45:44 +00:00
|
|
|
QKeySequence::SelectAll);
|
|
|
|
|
|
|
|
edit->addSeparator();
|
|
|
|
|
|
|
|
auto prefs = edit->addAction(
|
|
|
|
tr::lng_mac_menu_preferences(tr::now),
|
|
|
|
App::wnd(),
|
2020-08-28 16:14:19 +00:00
|
|
|
[=] { App::wnd()->showSettings(); },
|
2020-03-04 05:45:44 +00:00
|
|
|
QKeySequence(Qt::ControlModifier | Qt::Key_Comma));
|
|
|
|
|
|
|
|
prefs->setMenuRole(QAction::PreferencesRole);
|
|
|
|
|
|
|
|
auto tools = psMainMenu->addMenu(tr::lng_linux_menu_tools(tr::now));
|
|
|
|
|
|
|
|
psContacts = tools->addAction(
|
|
|
|
tr::lng_mac_menu_contacts(tr::now),
|
|
|
|
crl::guard(this, [=] {
|
|
|
|
if (isHidden()) {
|
|
|
|
App::wnd()->showFromTray();
|
|
|
|
}
|
|
|
|
|
2020-06-26 07:51:05 +00:00
|
|
|
if (!sessionController()) {
|
2020-03-04 05:45:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ui::show(
|
|
|
|
Box<PeerListBox>(std::make_unique<ContactsBoxController>(
|
|
|
|
sessionController()),
|
|
|
|
[](not_null<PeerListBox*> box) {
|
|
|
|
box->addButton(tr::lng_close(), [box] {
|
|
|
|
box->closeBox();
|
|
|
|
});
|
|
|
|
|
|
|
|
box->addLeftButton(tr::lng_profile_add_contact(), [] {
|
|
|
|
App::wnd()->onShowAddContact();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
|
|
|
|
psAddContact = tools->addAction(
|
|
|
|
tr::lng_mac_menu_add_contact(tr::now),
|
|
|
|
App::wnd(),
|
2020-08-28 16:14:19 +00:00
|
|
|
[=] { App::wnd()->onShowAddContact(); });
|
2020-03-04 05:45:44 +00:00
|
|
|
|
|
|
|
tools->addSeparator();
|
|
|
|
|
|
|
|
psNewGroup = tools->addAction(
|
|
|
|
tr::lng_mac_menu_new_group(tr::now),
|
|
|
|
App::wnd(),
|
2020-08-28 16:14:19 +00:00
|
|
|
[=] { App::wnd()->onShowNewGroup(); });
|
2020-03-04 05:45:44 +00:00
|
|
|
|
|
|
|
psNewChannel = tools->addAction(
|
|
|
|
tr::lng_mac_menu_new_channel(tr::now),
|
|
|
|
App::wnd(),
|
2020-08-28 16:14:19 +00:00
|
|
|
[=] { App::wnd()->onShowNewChannel(); });
|
2020-03-04 05:45:44 +00:00
|
|
|
|
|
|
|
auto help = psMainMenu->addMenu(tr::lng_linux_menu_help(tr::now));
|
|
|
|
|
|
|
|
auto about = help->addAction(
|
|
|
|
tr::lng_mac_menu_about_telegram(
|
|
|
|
tr::now,
|
|
|
|
lt_telegram,
|
|
|
|
qsl("Telegram")),
|
|
|
|
[] {
|
|
|
|
if (App::wnd() && App::wnd()->isHidden()) {
|
|
|
|
App::wnd()->showFromTray();
|
|
|
|
}
|
|
|
|
|
|
|
|
Ui::show(Box<AboutBox>());
|
|
|
|
});
|
|
|
|
|
|
|
|
about->setMenuRole(QAction::AboutQtRole);
|
|
|
|
|
|
|
|
_mainMenuPath.setPath(qsl("/MenuBar"));
|
|
|
|
|
|
|
|
_mainMenuExporter = new DBusMenuExporter(
|
|
|
|
_mainMenuPath.path(),
|
|
|
|
psMainMenu);
|
|
|
|
|
2020-05-03 11:45:32 +00:00
|
|
|
if (AppMenuSupported) {
|
|
|
|
RegisterAppMenu(winId(), _mainMenuPath);
|
|
|
|
}
|
2020-03-04 05:45:44 +00:00
|
|
|
|
|
|
|
updateGlobalMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::psLinuxUndo() {
|
|
|
|
SendKeySequence(Qt::Key_Z, Qt::ControlModifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::psLinuxRedo() {
|
|
|
|
SendKeySequence(Qt::Key_Z, Qt::ControlModifier | Qt::ShiftModifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::psLinuxCut() {
|
|
|
|
SendKeySequence(Qt::Key_X, Qt::ControlModifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::psLinuxCopy() {
|
|
|
|
SendKeySequence(Qt::Key_C, Qt::ControlModifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::psLinuxPaste() {
|
|
|
|
SendKeySequence(Qt::Key_V, Qt::ControlModifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::psLinuxDelete() {
|
|
|
|
SendKeySequence(Qt::Key_Delete);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::psLinuxSelectAll() {
|
|
|
|
SendKeySequence(Qt::Key_A, Qt::ControlModifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::psLinuxBold() {
|
|
|
|
SendKeySequence(Qt::Key_B, Qt::ControlModifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::psLinuxItalic() {
|
|
|
|
SendKeySequence(Qt::Key_I, Qt::ControlModifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::psLinuxUnderline() {
|
|
|
|
SendKeySequence(Qt::Key_U, Qt::ControlModifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::psLinuxStrikeOut() {
|
|
|
|
SendKeySequence(Qt::Key_X, Qt::ControlModifier | Qt::ShiftModifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::psLinuxMonospace() {
|
|
|
|
SendKeySequence(Qt::Key_M, Qt::ControlModifier | Qt::ShiftModifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::psLinuxClearFormat() {
|
|
|
|
SendKeySequence(Qt::Key_N, Qt::ControlModifier | Qt::ShiftModifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::updateGlobalMenuHook() {
|
2020-05-03 11:45:32 +00:00
|
|
|
if (!App::wnd() || !positionInited()) return;
|
2020-03-04 05:45:44 +00:00
|
|
|
|
|
|
|
const auto focused = QApplication::focusWidget();
|
|
|
|
auto canUndo = false;
|
|
|
|
auto canRedo = false;
|
|
|
|
auto canCut = false;
|
|
|
|
auto canCopy = false;
|
|
|
|
auto canPaste = false;
|
|
|
|
auto canDelete = false;
|
|
|
|
auto canSelectAll = false;
|
|
|
|
const auto clipboardHasText = QGuiApplication::clipboard()
|
|
|
|
->ownsClipboard();
|
|
|
|
auto markdownEnabled = false;
|
|
|
|
if (const auto edit = qobject_cast<QLineEdit*>(focused)) {
|
|
|
|
canCut = canCopy = canDelete = edit->hasSelectedText();
|
|
|
|
canSelectAll = !edit->text().isEmpty();
|
|
|
|
canUndo = edit->isUndoAvailable();
|
|
|
|
canRedo = edit->isRedoAvailable();
|
|
|
|
canPaste = clipboardHasText;
|
|
|
|
} else if (const auto edit = qobject_cast<QTextEdit*>(focused)) {
|
|
|
|
canCut = canCopy = canDelete = edit->textCursor().hasSelection();
|
|
|
|
canSelectAll = !edit->document()->isEmpty();
|
|
|
|
canUndo = edit->document()->isUndoAvailable();
|
|
|
|
canRedo = edit->document()->isRedoAvailable();
|
|
|
|
canPaste = clipboardHasText;
|
|
|
|
if (canCopy) {
|
|
|
|
if (const auto inputField = qobject_cast<Ui::InputField*>(
|
|
|
|
focused->parentWidget())) {
|
|
|
|
markdownEnabled = inputField->isMarkdownEnabled();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (const auto list = qobject_cast<HistoryInner*>(focused)) {
|
|
|
|
canCopy = list->canCopySelected();
|
|
|
|
canDelete = list->canDeleteSelected();
|
|
|
|
}
|
2020-06-17 09:36:25 +00:00
|
|
|
App::wnd()->updateIsActive();
|
2020-06-26 07:51:05 +00:00
|
|
|
const auto logged = (sessionController() != nullptr);
|
2020-06-24 07:56:16 +00:00
|
|
|
const auto inactive = !logged || controller().locked();
|
2020-03-04 05:45:44 +00:00
|
|
|
const auto support = logged && account().session().supportMode();
|
2020-06-24 07:56:16 +00:00
|
|
|
ForceDisabled(psLogout, !logged && !Core::App().passcodeLocked());
|
2020-03-04 05:45:44 +00:00
|
|
|
ForceDisabled(psUndo, !canUndo);
|
|
|
|
ForceDisabled(psRedo, !canRedo);
|
|
|
|
ForceDisabled(psCut, !canCut);
|
|
|
|
ForceDisabled(psCopy, !canCopy);
|
|
|
|
ForceDisabled(psPaste, !canPaste);
|
|
|
|
ForceDisabled(psDelete, !canDelete);
|
|
|
|
ForceDisabled(psSelectAll, !canSelectAll);
|
|
|
|
ForceDisabled(psContacts, inactive || support);
|
|
|
|
ForceDisabled(psAddContact, inactive);
|
|
|
|
ForceDisabled(psNewGroup, inactive || support);
|
|
|
|
ForceDisabled(psNewChannel, inactive || support);
|
|
|
|
|
|
|
|
ForceDisabled(psBold, !markdownEnabled);
|
|
|
|
ForceDisabled(psItalic, !markdownEnabled);
|
|
|
|
ForceDisabled(psUnderline, !markdownEnabled);
|
|
|
|
ForceDisabled(psStrikeOut, !markdownEnabled);
|
|
|
|
ForceDisabled(psMonospace, !markdownEnabled);
|
|
|
|
ForceDisabled(psClearFormat, !markdownEnabled);
|
|
|
|
}
|
|
|
|
|
2020-09-18 09:09:05 +00:00
|
|
|
void MainWindow::handleVisibleChangedHook(bool visible) {
|
2020-05-03 11:45:32 +00:00
|
|
|
if (AppMenuSupported && !_mainMenuPath.path().isEmpty()) {
|
2020-03-04 05:45:44 +00:00
|
|
|
if (visible) {
|
|
|
|
RegisterAppMenu(winId(), _mainMenuPath);
|
|
|
|
} else {
|
|
|
|
UnregisterAppMenu(winId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-08 12:07:13 +00:00
|
|
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-03-14 12:13:33 +00:00
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
MainWindow::~MainWindow() {
|
2020-08-08 12:07:13 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-01-31 06:34:37 +00:00
|
|
|
delete _sniTrayIcon;
|
2020-03-04 05:45:44 +00:00
|
|
|
|
2020-05-03 11:45:32 +00:00
|
|
|
if (AppMenuSupported) {
|
2020-03-04 05:45:44 +00:00
|
|
|
UnregisterAppMenu(winId());
|
|
|
|
}
|
2020-05-03 11:45:32 +00:00
|
|
|
|
|
|
|
delete _mainMenuExporter;
|
|
|
|
delete psMainMenu;
|
2020-08-08 12:07:13 +00:00
|
|
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-01-31 06:34:37 +00:00
|
|
|
|
|
|
|
delete _trayIconMenuXEmbed;
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Platform
|