maked first build
This commit is contained in:
parent
a261ab4f0c
commit
e9f44ffcc6
3 changed files with 87 additions and 36 deletions
|
@ -22,19 +22,19 @@ Logger logger(LOG_LINUX, "LinuxSystemTrayNotificationHandler");
|
||||||
|
|
||||||
//static
|
//static
|
||||||
bool LinuxSystemTrayNotificationHandler::requiredCustomImpl() {
|
bool LinuxSystemTrayNotificationHandler::requiredCustomImpl() {
|
||||||
if (!QDBusConnection::sessionBus().isConnected()) {
|
//if (!QDBusConnection::sessionBus().isConnected()) {
|
||||||
return false;
|
// return false;
|
||||||
}
|
//}
|
||||||
|
|
||||||
QDBusConnectionInterface* interface =
|
//QDBusConnectionInterface* interface =
|
||||||
QDBusConnection::sessionBus().interface();
|
// QDBusConnection::sessionBus().interface();
|
||||||
if (!interface) {
|
//if (!interface) {
|
||||||
return false;
|
// return false;
|
||||||
}
|
//}
|
||||||
|
|
||||||
// This custom systemTrayHandler implementation is required only on Unity.
|
//// This custom systemTrayHandler implementation is required only on Unity.
|
||||||
QStringList registeredServices = interface->registeredServiceNames().value();
|
//QStringList registeredServices = interface->registeredServiceNames().value();
|
||||||
return registeredServices.contains("com.canonical.Unity");
|
//return registeredServices.contains("com.canonical.Unity");
|
||||||
}
|
}
|
||||||
|
|
||||||
LinuxSystemTrayNotificationHandler::LinuxSystemTrayNotificationHandler(
|
LinuxSystemTrayNotificationHandler::LinuxSystemTrayNotificationHandler(
|
||||||
|
@ -42,7 +42,7 @@ LinuxSystemTrayNotificationHandler::LinuxSystemTrayNotificationHandler(
|
||||||
: SystemTrayNotificationHandler(parent) {
|
: SystemTrayNotificationHandler(parent) {
|
||||||
|
|
||||||
m_systemTrayIcon.show();
|
m_systemTrayIcon.show();
|
||||||
connect(&m_systemTrayIcon, &QSystemTrayIcon::activated, this);
|
connect(&m_systemTrayIcon, &QSystemTrayIcon::activated, this, &LinuxSystemTrayNotificationHandler::onTrayActivated);
|
||||||
|
|
||||||
|
|
||||||
m_menu.addAction(QIcon(":/images/tray/application.png"), tr("Show") + " " + APPLICATION_NAME, this, [this](){
|
m_menu.addAction(QIcon(":/images/tray/application.png"), tr("Show") + " " + APPLICATION_NAME, this, [this](){
|
||||||
|
@ -66,6 +66,79 @@ LinuxSystemTrayNotificationHandler::LinuxSystemTrayNotificationHandler(
|
||||||
setTrayState(VpnProtocol::Disconnected);
|
setTrayState(VpnProtocol::Disconnected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LinuxSystemTrayNotificationHandler::setTrayState(VpnProtocol::VpnConnectionState state)
|
||||||
|
{
|
||||||
|
qDebug() << "SystemTrayNotificationHandler::setTrayState" << state;
|
||||||
|
QString resourcesPath = ":/images/tray/%1";
|
||||||
|
|
||||||
|
switch (state) {
|
||||||
|
case VpnProtocol::Disconnected:
|
||||||
|
setTrayIcon(QString(resourcesPath).arg(DisconnectedTrayIconName));
|
||||||
|
m_trayActionConnect->setEnabled(true);
|
||||||
|
m_trayActionDisconnect->setEnabled(false);
|
||||||
|
break;
|
||||||
|
case VpnProtocol::Preparing:
|
||||||
|
setTrayIcon(QString(resourcesPath).arg(DisconnectedTrayIconName));
|
||||||
|
m_trayActionConnect->setEnabled(false);
|
||||||
|
m_trayActionDisconnect->setEnabled(true);
|
||||||
|
break;
|
||||||
|
case VpnProtocol::Connecting:
|
||||||
|
setTrayIcon(QString(resourcesPath).arg(DisconnectedTrayIconName));
|
||||||
|
m_trayActionConnect->setEnabled(false);
|
||||||
|
m_trayActionDisconnect->setEnabled(true);
|
||||||
|
break;
|
||||||
|
case VpnProtocol::Connected:
|
||||||
|
setTrayIcon(QString(resourcesPath).arg(ConnectedTrayIconName));
|
||||||
|
m_trayActionConnect->setEnabled(false);
|
||||||
|
m_trayActionDisconnect->setEnabled(true);
|
||||||
|
break;
|
||||||
|
case VpnProtocol::Disconnecting:
|
||||||
|
setTrayIcon(QString(resourcesPath).arg(DisconnectedTrayIconName));
|
||||||
|
m_trayActionConnect->setEnabled(false);
|
||||||
|
m_trayActionDisconnect->setEnabled(true);
|
||||||
|
break;
|
||||||
|
case VpnProtocol::Reconnecting:
|
||||||
|
setTrayIcon(QString(resourcesPath).arg(DisconnectedTrayIconName));
|
||||||
|
m_trayActionConnect->setEnabled(false);
|
||||||
|
m_trayActionDisconnect->setEnabled(true);
|
||||||
|
break;
|
||||||
|
case VpnProtocol::Error:
|
||||||
|
setTrayIcon(QString(resourcesPath).arg(ErrorTrayIconName));
|
||||||
|
m_trayActionConnect->setEnabled(true);
|
||||||
|
m_trayActionDisconnect->setEnabled(false);
|
||||||
|
break;
|
||||||
|
case VpnProtocol::Unknown:
|
||||||
|
default:
|
||||||
|
m_trayActionConnect->setEnabled(false);
|
||||||
|
m_trayActionDisconnect->setEnabled(true);
|
||||||
|
setTrayIcon(QString(resourcesPath).arg(DisconnectedTrayIconName));
|
||||||
|
}
|
||||||
|
|
||||||
|
//#ifdef Q_OS_MAC
|
||||||
|
// // Get theme from current user (note, this app can be launched as root application and in this case this theme can be different from theme of real current user )
|
||||||
|
// bool darkTaskBar = MacOSFunctions::instance().isMenuBarUseDarkTheme();
|
||||||
|
// darkTaskBar = forceUseBrightIcons ? true : darkTaskBar;
|
||||||
|
// resourcesPath = ":/images_mac/tray_icon/%1";
|
||||||
|
// useIconName = useIconName.replace(".png", darkTaskBar ? "@2x.png" : " dark@2x.png");
|
||||||
|
//#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void LinuxSystemTrayNotificationHandler::setTrayIcon(const QString &iconPath)
|
||||||
|
{
|
||||||
|
QIcon trayIconMask(QPixmap(iconPath).scaled(128,128));
|
||||||
|
trayIconMask.setIsMask(true);
|
||||||
|
m_systemTrayIcon.setIcon(trayIconMask);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LinuxSystemTrayNotificationHandler::onTrayActivated(QSystemTrayIcon::ActivationReason reason)
|
||||||
|
{
|
||||||
|
#ifndef Q_OS_MAC
|
||||||
|
if(reason == QSystemTrayIcon::DoubleClick || reason == QSystemTrayIcon::Trigger) {
|
||||||
|
emit raiseRequested();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
LinuxSystemTrayNotificationHandler::~LinuxSystemTrayNotificationHandler() {
|
LinuxSystemTrayNotificationHandler::~LinuxSystemTrayNotificationHandler() {
|
||||||
MVPN_COUNT_DTOR(LinuxSystemTrayNotificationHandler);
|
MVPN_COUNT_DTOR(LinuxSystemTrayNotificationHandler);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,8 @@ class LinuxSystemTrayNotificationHandler final
|
||||||
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);
|
void setTrayState(VpnProtocol::VpnConnectionState state);
|
||||||
|
void setTrayIcon(const QString &iconPath);
|
||||||
|
void onTrayActivated(QSystemTrayIcon::ActivationReason reason);
|
||||||
private slots:
|
private slots:
|
||||||
void actionInvoked(uint actionId, QString action);
|
void actionInvoked(uint actionId, QString action);
|
||||||
|
|
||||||
|
|
|
@ -46,29 +46,6 @@ SystemTrayNotificationHandler::SystemTrayNotificationHandler(QObject* parent) :
|
||||||
|
|
||||||
m_systemTrayIcon.setContextMenu(&m_menu);
|
m_systemTrayIcon.setContextMenu(&m_menu);
|
||||||
setTrayState(VpnProtocol::Disconnected);
|
setTrayState(VpnProtocol::Disconnected);
|
||||||
|
|
||||||
|
|
||||||
// m_preferencesAction = m_menu.addAction("", vpn, &MozillaVPN::requestSettings);
|
|
||||||
|
|
||||||
// m_menu.addSeparator();
|
|
||||||
|
|
||||||
// m_quitAction = m_menu.addAction("", vpn->controller(), &Controller::quit);
|
|
||||||
// m_systemTrayIcon.setContextMenu(&m_menu);
|
|
||||||
|
|
||||||
// updateIcon(vpn->statusIcon()->iconString());
|
|
||||||
|
|
||||||
// connect(QmlEngineHolder::instance()->window(), &QWindow::visibleChanged, this,
|
|
||||||
// &SystemTrayNotificationHandler::updateContextMenu);
|
|
||||||
|
|
||||||
// connect(&m_systemTrayIcon, &QSystemTrayIcon::activated, this,
|
|
||||||
// &SystemTrayNotificationHandler::maybeActivated);
|
|
||||||
|
|
||||||
// connect(&m_systemTrayIcon, &QSystemTrayIcon::messageClicked, this,
|
|
||||||
// &SystemTrayNotificationHandler::messageClickHandle);
|
|
||||||
|
|
||||||
// retranslate();
|
|
||||||
|
|
||||||
// m_systemTrayIcon.show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SystemTrayNotificationHandler::~SystemTrayNotificationHandler() {
|
SystemTrayNotificationHandler::~SystemTrayNotificationHandler() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue