mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
use Qt backend of KDE5
commit fixes problem with usage of GTK3 fallback menu action used on KDE5, probably to a bug in status notifier - allows using Qt backend on KDE5 and other plasma related env. - icon in tray menu and tray icon are loaded from svg, their size is not limited to 50px now - plasma adds extra actionmenu to tray so quit was renamed to exit - exit action usues system-default icon for quit and system default keyboard shourtcut to close qtox
This commit is contained in:
parent
b69f8425c6
commit
521b55f776
|
@ -26,8 +26,9 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include "src/persistence/settings.h"
|
#include "src/persistence/settings.h"
|
||||||
|
|
||||||
SystemTrayIcon::SystemTrayIcon()
|
SystemTrayIcon::SystemTrayIcon(Widget *parent)
|
||||||
{
|
{
|
||||||
|
this->parent = parent;
|
||||||
QString desktop = getenv("XDG_CURRENT_DESKTOP");
|
QString desktop = getenv("XDG_CURRENT_DESKTOP");
|
||||||
if (desktop.isEmpty())
|
if (desktop.isEmpty())
|
||||||
desktop = getenv("DESKTOP_SESSION");
|
desktop = getenv("DESKTOP_SESSION");
|
||||||
|
@ -88,28 +89,12 @@ SystemTrayIcon::SystemTrayIcon()
|
||||||
g_signal_connect(gtkIcon, "button-release-event", G_CALLBACK(callbackButtonClick), this);
|
g_signal_connect(gtkIcon, "button-release-event", G_CALLBACK(callbackButtonClick), this);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_SYSTRAY_STATUSNOTIFIER_BACKEND
|
else if (desktop == "kde" && getenv("KDE_SESSION_VERSION") == QString("5"))
|
||||||
else if (desktop == "kde"
|
|
||||||
&& getenv("KDE_SESSION_VERSION") == QString("5"))
|
|
||||||
{
|
{
|
||||||
qDebug() << "Using Status Notifier backend";
|
qDebug() << "Using the Qt backend";
|
||||||
backendType = SystrayBackendType::StatusNotifier;
|
qtIcon = new QSystemTrayIcon;
|
||||||
gtk_init(nullptr, nullptr);
|
backendType = SystrayBackendType::Qt;
|
||||||
snMenu = gtk_menu_new();
|
connect(qtIcon, &QSystemTrayIcon::activated, this, &SystemTrayIcon::activated);
|
||||||
|
|
||||||
// No ':' needed in resource path!
|
|
||||||
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_resource("/img/icon.png", NULL);
|
|
||||||
statusNotifier = status_notifier_new_from_pixbuf("qtox",
|
|
||||||
STATUS_NOTIFIER_CATEGORY_APPLICATION_STATUS, pixbuf);
|
|
||||||
status_notifier_register(statusNotifier);
|
|
||||||
g_object_unref(pixbuf);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
else if (desktop == "kde"
|
|
||||||
&& getenv("KDE_SESSION_VERSION") == QString("5"))
|
|
||||||
{
|
|
||||||
backendType = SystrayBackendType::KDE5;
|
|
||||||
qWarning() << "Detected a KDE5 session, but we don't have Status Notifier support. Disabling the systray icon";
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#define SYSTEMTRAYICON_H
|
#define SYSTEMTRAYICON_H
|
||||||
|
|
||||||
#include "systemtrayicon_private.h"
|
#include "systemtrayicon_private.h"
|
||||||
|
#include "widget.h"
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
class QSystemTrayIcon;
|
class QSystemTrayIcon;
|
||||||
|
@ -31,7 +32,7 @@ class SystemTrayIcon : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
SystemTrayIcon();
|
SystemTrayIcon(Widget *parent);
|
||||||
~SystemTrayIcon();
|
~SystemTrayIcon();
|
||||||
void setContextMenu(QMenu* menu);
|
void setContextMenu(QMenu* menu);
|
||||||
void show();
|
void show();
|
||||||
|
@ -48,6 +49,8 @@ private:
|
||||||
private:
|
private:
|
||||||
SystrayBackendType backendType;
|
SystrayBackendType backendType;
|
||||||
QSystemTrayIcon* qtIcon;
|
QSystemTrayIcon* qtIcon;
|
||||||
|
Widget *parent;
|
||||||
|
|
||||||
#ifdef ENABLE_SYSTRAY_UNITY_BACKEND
|
#ifdef ENABLE_SYSTRAY_UNITY_BACKEND
|
||||||
AppIndicator *unityIndicator;
|
AppIndicator *unityIndicator;
|
||||||
GtkWidget *unityMenu;
|
GtkWidget *unityMenu;
|
||||||
|
|
|
@ -71,6 +71,7 @@
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
#include <QSvgRenderer>
|
||||||
#include <QWindow>
|
#include <QWindow>
|
||||||
#include <tox/tox.h>
|
#include <tox/tox.h>
|
||||||
|
|
||||||
|
@ -119,14 +120,16 @@ void Widget::init()
|
||||||
offlineMsgTimer->start(15000);
|
offlineMsgTimer->start(15000);
|
||||||
|
|
||||||
statusOnline = new QAction(this);
|
statusOnline = new QAction(this);
|
||||||
statusOnline->setIcon(getStatusIcon(Status::Online, 10, 10));
|
statusOnline->setIcon(getStatusIcon(Status::Online, 50, 50));
|
||||||
connect(statusOnline, SIGNAL(triggered()), this, SLOT(setStatusOnline()));
|
connect(statusOnline, &QAction::triggered, this, &Widget::setStatusOnline);
|
||||||
|
|
||||||
statusAway = new QAction(this);
|
statusAway = new QAction(this);
|
||||||
statusAway->setIcon(getStatusIcon(Status::Away, 10, 10));
|
statusAway->setIcon(getStatusIcon(Status::Away, 50, 50));
|
||||||
connect(statusAway, SIGNAL(triggered()), this, SLOT(setStatusAway()));
|
connect(statusAway, &QAction::triggered, this, &Widget::setStatusAway);
|
||||||
|
|
||||||
statusBusy = new QAction(this);
|
statusBusy = new QAction(this);
|
||||||
statusBusy->setIcon(getStatusIcon(Status::Busy, 10, 10));
|
statusBusy->setIcon(getStatusIcon(Status::Busy, 50, 50));
|
||||||
connect(statusBusy, SIGNAL(triggered()), this, SLOT(setStatusBusy()));
|
connect(statusBusy, &QAction::triggered, this, &Widget::setStatusBusy);
|
||||||
|
|
||||||
layout()->setContentsMargins(0, 0, 0, 0);
|
layout()->setContentsMargins(0, 0, 0, 0);
|
||||||
ui->friendList->setStyleSheet(Style::resolve(Style::getStylesheet(":ui/friendList/friendList.css")));
|
ui->friendList->setStyleSheet(Style::resolve(Style::getStylesheet(":ui/friendList/friendList.css")));
|
||||||
|
@ -412,7 +415,16 @@ void Widget::updateIcons()
|
||||||
if (ico.isNull())
|
if (ico.isNull())
|
||||||
{
|
{
|
||||||
QString color = Settings::getInstance().getLightTrayIcon() ? "light" : "dark";
|
QString color = Settings::getInstance().getLightTrayIcon() ? "light" : "dark";
|
||||||
ico = QIcon(":img/taskbar/" + color + "/taskbar_" + status + ".svg");
|
QString path = ":img/taskbar/" + color + "/taskbar_" + status + ".svg";
|
||||||
|
|
||||||
|
QSvgRenderer renderer(path);
|
||||||
|
|
||||||
|
// Prepare a QImage with desired characteritisc
|
||||||
|
QImage image(250, 250, QImage::Format_ARGB32_Premultiplied);
|
||||||
|
|
||||||
|
QPainter painter(&image);
|
||||||
|
renderer.render(&painter);
|
||||||
|
ico = QIcon(QPixmap::fromImage(image));
|
||||||
}
|
}
|
||||||
|
|
||||||
setWindowIcon(ico);
|
setWindowIcon(ico);
|
||||||
|
@ -1682,12 +1694,14 @@ void Widget::onTryCreateTrayIcon()
|
||||||
{
|
{
|
||||||
if (QSystemTrayIcon::isSystemTrayAvailable())
|
if (QSystemTrayIcon::isSystemTrayAvailable())
|
||||||
{
|
{
|
||||||
icon = new SystemTrayIcon;
|
icon = new SystemTrayIcon(this);
|
||||||
updateIcons();
|
updateIcons();
|
||||||
trayMenu = new QMenu;
|
trayMenu = new QMenu(this);
|
||||||
|
QStyle *style = qApp->style();
|
||||||
actionQuit = new QAction(tr("&Quit"), this);
|
actionQuit = new QAction(tr("&Exit"), this);
|
||||||
connect(actionQuit, SIGNAL(triggered()), qApp, SLOT(quit()));
|
actionQuit->setShortcut(QKeySequence::Quit); // system default quit shorcut
|
||||||
|
actionQuit->setIcon(style->standardIcon(QStyle::SP_DialogCloseButton)); // system default exit icon
|
||||||
|
connect(actionQuit, &QAction::triggered, qApp, &QApplication::quit);
|
||||||
|
|
||||||
trayMenu->addAction(statusOnline);
|
trayMenu->addAction(statusOnline);
|
||||||
trayMenu->addAction(statusAway);
|
trayMenu->addAction(statusAway);
|
||||||
|
@ -1696,8 +1710,7 @@ void Widget::onTryCreateTrayIcon()
|
||||||
trayMenu->addAction(actionQuit);
|
trayMenu->addAction(actionQuit);
|
||||||
icon->setContextMenu(trayMenu);
|
icon->setContextMenu(trayMenu);
|
||||||
|
|
||||||
connect(icon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
|
connect(icon, &SystemTrayIcon::activated, this, &Widget::onIconClick);
|
||||||
this, SLOT(onIconClick(QSystemTrayIcon::ActivationReason)));
|
|
||||||
|
|
||||||
if (Settings::getInstance().getShowSystemTray())
|
if (Settings::getInstance().getShowSystemTray())
|
||||||
{
|
{
|
||||||
|
@ -1909,12 +1922,9 @@ QString Widget::getStatusIconPath(Status status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline QIcon Widget::getStatusIcon(Status status, uint32_t w/*=0*/, uint32_t h/*=0*/)
|
inline QIcon Widget::getStatusIcon(Status status, uint32_t, uint32_t)
|
||||||
{
|
{
|
||||||
if (w > 0 && h > 0)
|
return QIcon(getStatusIconPath(status));
|
||||||
return getStatusIconPixmap(status, w, h);
|
|
||||||
else
|
|
||||||
return QIcon(getStatusIconPath(status));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap Widget::getStatusIconPixmap(Status status, uint32_t w, uint32_t h)
|
QPixmap Widget::getStatusIconPixmap(Status status, uint32_t w, uint32_t h)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user