editing linux sources
This commit is contained in:
parent
39de79d3cd
commit
a261ab4f0c
3 changed files with 41 additions and 48 deletions
|
|
@ -6,8 +6,10 @@
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
#include "leakdetector.h"
|
#include "leakdetector.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include "defines.h"
|
||||||
|
|
||||||
#include <QtDBus/QtDBus>
|
#include <QtDBus/QtDBus>
|
||||||
|
#include <QDesktopServices>
|
||||||
|
|
||||||
constexpr const char* DBUS_ITEM = "org.freedesktop.Notifications";
|
constexpr const char* DBUS_ITEM = "org.freedesktop.Notifications";
|
||||||
constexpr const char* DBUS_PATH = "/org/freedesktop/Notifications";
|
constexpr const char* DBUS_PATH = "/org/freedesktop/Notifications";
|
||||||
|
|
@ -38,11 +40,30 @@ bool LinuxSystemTrayNotificationHandler::requiredCustomImpl() {
|
||||||
LinuxSystemTrayNotificationHandler::LinuxSystemTrayNotificationHandler(
|
LinuxSystemTrayNotificationHandler::LinuxSystemTrayNotificationHandler(
|
||||||
QObject* parent)
|
QObject* parent)
|
||||||
: SystemTrayNotificationHandler(parent) {
|
: SystemTrayNotificationHandler(parent) {
|
||||||
MVPN_COUNT_CTOR(LinuxSystemTrayNotificationHandler);
|
|
||||||
|
|
||||||
QDBusConnection::sessionBus().connect(DBUS_ITEM, DBUS_PATH, DBUS_INTERFACE,
|
m_systemTrayIcon.show();
|
||||||
"ActionInvoked", this,
|
connect(&m_systemTrayIcon, &QSystemTrayIcon::activated, this);
|
||||||
SLOT(actionInvoked(uint, QString)));
|
|
||||||
|
|
||||||
|
m_menu.addAction(QIcon(":/images/tray/application.png"), tr("Show") + " " + APPLICATION_NAME, this, [this](){
|
||||||
|
emit raiseRequested();
|
||||||
|
});
|
||||||
|
m_menu.addSeparator();
|
||||||
|
m_trayActionConnect = m_menu.addAction(tr("Connect"), this, [this](){ emit connectRequested(); });
|
||||||
|
m_trayActionDisconnect = m_menu.addAction(tr("Disconnect"), this, [this](){ emit disconnectRequested(); });
|
||||||
|
|
||||||
|
m_menu.addSeparator();
|
||||||
|
|
||||||
|
m_menu.addAction(QIcon(":/images/tray/link.png"), tr("Visit Website"), [&](){
|
||||||
|
QDesktopServices::openUrl(QUrl("https://amnezia.org"));
|
||||||
|
});
|
||||||
|
|
||||||
|
m_menu.addAction(QIcon(":/images/tray/cancel.png"), tr("Quit") + " " + APPLICATION_NAME, this, [&](){
|
||||||
|
qApp->quit();
|
||||||
|
});
|
||||||
|
|
||||||
|
m_systemTrayIcon.setContextMenu(&m_menu);
|
||||||
|
setTrayState(VpnProtocol::Disconnected);
|
||||||
}
|
}
|
||||||
|
|
||||||
LinuxSystemTrayNotificationHandler::~LinuxSystemTrayNotificationHandler() {
|
LinuxSystemTrayNotificationHandler::~LinuxSystemTrayNotificationHandler() {
|
||||||
|
|
@ -53,50 +74,8 @@ void LinuxSystemTrayNotificationHandler::notify(Message type,
|
||||||
const QString& title,
|
const QString& title,
|
||||||
const QString& message,
|
const QString& message,
|
||||||
int timerMsec) {
|
int timerMsec) {
|
||||||
QString actionMessage;
|
|
||||||
switch (type) {
|
|
||||||
case None:
|
|
||||||
return SystemTrayNotificationHandler::notify(type, title, message,
|
|
||||||
timerMsec);
|
|
||||||
|
|
||||||
case UnsecuredNetwork:
|
|
||||||
actionMessage = qtTrId("vpn.toggle.on");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CaptivePortalBlock:
|
|
||||||
actionMessage = qtTrId("vpn.toggle.off");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CaptivePortalUnblock:
|
|
||||||
actionMessage = qtTrId("vpn.toggle.on");
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
Q_ASSERT(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_lastMessage = type;
|
|
||||||
emit notificationShown(title, message);
|
|
||||||
|
|
||||||
QDBusInterface n(DBUS_ITEM, DBUS_PATH, DBUS_INTERFACE,
|
|
||||||
QDBusConnection::sessionBus());
|
|
||||||
if (!n.isValid()) {
|
|
||||||
qWarning("Failed to connect to the notification manager via system dbus");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t replacesId = 0; // Don't replace.
|
|
||||||
const char* appIcon = MVPN_ICON_PATH;
|
|
||||||
QStringList actions{ACTION_ID, actionMessage};
|
|
||||||
QMap<QString, QVariant> hints;
|
|
||||||
|
|
||||||
QDBusReply<uint> reply = n.call("Notify", "Mozilla VPN", replacesId, appIcon,
|
|
||||||
title, message, actions, hints, timerMsec);
|
|
||||||
if (!reply.isValid()) {
|
|
||||||
logger.warning() << "Failed to show the notification";
|
|
||||||
}
|
|
||||||
|
|
||||||
m_lastNotificationId = reply;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LinuxSystemTrayNotificationHandler::actionInvoked(uint actionId,
|
void LinuxSystemTrayNotificationHandler::actionInvoked(uint actionId,
|
||||||
|
|
|
||||||
|
|
@ -23,11 +23,25 @@ class LinuxSystemTrayNotificationHandler final
|
||||||
private:
|
private:
|
||||||
void notify(Message type, const QString& title, const QString& message,
|
void notify(Message type, const QString& title, const QString& message,
|
||||||
int timerMsec) override;
|
int timerMsec) override;
|
||||||
|
void setTrayState(VpnProtocol::VpnConnectionState state);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void actionInvoked(uint actionId, QString action);
|
void actionInvoked(uint actionId, QString action);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QMenu m_menu;
|
||||||
|
QSystemTrayIcon m_systemTrayIcon;
|
||||||
|
|
||||||
|
QAction* m_trayActionConnect = nullptr;
|
||||||
|
QAction* m_trayActionDisconnect = nullptr;
|
||||||
|
QAction* m_preferencesAction = nullptr;
|
||||||
|
QAction* m_statusLabel = nullptr;
|
||||||
|
QAction* m_separator = nullptr;
|
||||||
|
|
||||||
|
const QString ConnectedTrayIconName = "active.png";
|
||||||
|
const QString DisconnectedTrayIconName = "default.png";
|
||||||
|
const QString ErrorTrayIconName = "error.png";
|
||||||
|
|
||||||
uint m_lastNotificationId = 0;
|
uint m_lastNotificationId = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
#else
|
#else
|
||||||
|
|
||||||
# if defined(Q_OS_LINUX)
|
# if defined(Q_OS_LINUX)
|
||||||
# include "linuxsystemtraynotificationhandler.h"
|
# include "platforms/linux/linuxsystemtraynotificationhandler.h"
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
# include "systemtray_notificationhandler.h"
|
# include "systemtray_notificationhandler.h"
|
||||||
|
|
@ -27,7 +27,7 @@ NotificationHandler* NotificationHandler::create(QObject* parent) {
|
||||||
#else
|
#else
|
||||||
|
|
||||||
# if defined(Q_OS_LINUX)
|
# if defined(Q_OS_LINUX)
|
||||||
if (LinuxSystemTrayNotificationHandler::requiredCustomImpl() == true) {
|
if (LinuxSystemTrayNotificationHandler::requiredCustomImpl()) {
|
||||||
return new LinuxSystemTrayNotificationHandler(parent);
|
return new LinuxSystemTrayNotificationHandler(parent);
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue