applied translation-funcation to SystemTray

This commit is contained in:
ronoaer 2023-10-06 13:43:32 +08:00
parent 1eafa9a38a
commit 1357c4a309
5 changed files with 23 additions and 6 deletions

View file

@ -139,6 +139,7 @@ void AmneziaApplication::init()
&ConnectionController::openConnection);
connect(m_notificationHandler.get(), &NotificationHandler::disconnectRequested, m_connectionController.get(),
&ConnectionController::closeConnection);
connect(this, &AmneziaApplication::translationsUpdated, m_notificationHandler.get(), &NotificationHandler::onTranslationsUpdated);
m_engine->load(url);
m_systemController->setQmlRoot(m_engine->rootObjects().value(0));

View file

@ -88,6 +88,10 @@ void NotificationHandler::setConnectionState(Vpn::ConnectionState state)
}
}
void NotificationHandler::onTranslationsUpdated()
{
}
void NotificationHandler::unsecuredNetworkNotification(const QString& networkName) {
qDebug() << "Unsecured network notification shown";

View file

@ -32,6 +32,7 @@ public:
public slots:
virtual void setConnectionState(Vpn::ConnectionState state);
virtual void onTranslationsUpdated();
signals:
void notificationShown(const QString& title, const QString& message);

View file

@ -17,7 +17,6 @@
#include "version.h"
SystemTrayNotificationHandler::SystemTrayNotificationHandler(QObject* parent) :
NotificationHandler(parent),
m_systemTrayIcon(parent)
@ -26,8 +25,7 @@ SystemTrayNotificationHandler::SystemTrayNotificationHandler(QObject* parent) :
m_systemTrayIcon.show();
connect(&m_systemTrayIcon, &QSystemTrayIcon::activated, this, &SystemTrayNotificationHandler::onTrayActivated);
m_menu.addAction(QIcon(":/images/tray/application.png"), tr("Show") + " " + APPLICATION_NAME, this, [this](){
m_trayActionShow = m_menu.addAction(QIcon(":/images/tray/application.png"), tr("Show") + " " + APPLICATION_NAME, this, [this](){
emit raiseRequested();
});
m_menu.addSeparator();
@ -36,11 +34,11 @@ SystemTrayNotificationHandler::SystemTrayNotificationHandler(QObject* parent) :
m_menu.addSeparator();
m_menu.addAction(QIcon(":/images/tray/link.png"), tr("Visit Website"), [&](){
m_trayActionVisitWebSite = 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, [&](){
m_trayActionQuit = m_menu.addAction(QIcon(":/images/tray/cancel.png"), tr("Quit") + " " + APPLICATION_NAME, this, [&](){
qApp->quit();
});
@ -57,6 +55,15 @@ void SystemTrayNotificationHandler::setConnectionState(Vpn::ConnectionState stat
NotificationHandler::setConnectionState(state);
}
void SystemTrayNotificationHandler::onTranslationsUpdated()
{
m_trayActionShow->setText(tr("Show") + " " + APPLICATION_NAME);
m_trayActionConnect->setText(tr("Connect"));
m_trayActionDisconnect->setText(tr("Disconnect"));
m_trayActionVisitWebSite->setText(tr("Visit Website"));
m_trayActionQuit->setText(tr("Quit")+ " " + APPLICATION_NAME);
}
void SystemTrayNotificationHandler::setTrayIcon(const QString &iconPath)
{
QIcon trayIconMask(QPixmap(iconPath).scaled(128,128));

View file

@ -19,6 +19,8 @@ public:
void setConnectionState(Vpn::ConnectionState state) override;
void onTranslationsUpdated() override;
protected:
virtual void notify(Message type, const QString& title,
const QString& message, int timerMsec) override;
@ -35,9 +37,11 @@ private:
QMenu m_menu;
QSystemTrayIcon m_systemTrayIcon;
QAction* m_trayActionShow = nullptr;
QAction* m_trayActionConnect = nullptr;
QAction* m_trayActionDisconnect = nullptr;
QAction* m_preferencesAction = nullptr;
QAction* m_trayActionVisitWebSite = nullptr;
QAction* m_trayActionQuit = nullptr;
QAction* m_statusLabel = nullptr;
QAction* m_separator = nullptr;