1
0
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:
agilob 2015-08-29 13:10:17 +01:00 committed by tux3
parent b69f8425c6
commit 521b55f776
3 changed files with 40 additions and 42 deletions

View File

@ -26,8 +26,9 @@
#include <QDebug>
#include "src/persistence/settings.h"
SystemTrayIcon::SystemTrayIcon()
SystemTrayIcon::SystemTrayIcon(Widget *parent)
{
this->parent = parent;
QString desktop = getenv("XDG_CURRENT_DESKTOP");
if (desktop.isEmpty())
desktop = getenv("DESKTOP_SESSION");
@ -88,28 +89,12 @@ SystemTrayIcon::SystemTrayIcon()
g_signal_connect(gtkIcon, "button-release-event", G_CALLBACK(callbackButtonClick), this);
}
#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";
backendType = SystrayBackendType::StatusNotifier;
gtk_init(nullptr, nullptr);
snMenu = gtk_menu_new();
// 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";
qDebug() << "Using the Qt backend";
qtIcon = new QSystemTrayIcon;
backendType = SystrayBackendType::Qt;
connect(qtIcon, &QSystemTrayIcon::activated, this, &SystemTrayIcon::activated);
}
else
{

View File

@ -22,6 +22,7 @@
#define SYSTEMTRAYICON_H
#include "systemtrayicon_private.h"
#include "widget.h"
#include <QObject>
class QSystemTrayIcon;
@ -31,7 +32,7 @@ class SystemTrayIcon : public QObject
{
Q_OBJECT
public:
SystemTrayIcon();
SystemTrayIcon(Widget *parent);
~SystemTrayIcon();
void setContextMenu(QMenu* menu);
void show();
@ -48,6 +49,8 @@ private:
private:
SystrayBackendType backendType;
QSystemTrayIcon* qtIcon;
Widget *parent;
#ifdef ENABLE_SYSTRAY_UNITY_BACKEND
AppIndicator *unityIndicator;
GtkWidget *unityMenu;

View File

@ -71,6 +71,7 @@
#include <QList>
#include <QDesktopServices>
#include <QProcess>
#include <QSvgRenderer>
#include <QWindow>
#include <tox/tox.h>
@ -119,14 +120,16 @@ void Widget::init()
offlineMsgTimer->start(15000);
statusOnline = new QAction(this);
statusOnline->setIcon(getStatusIcon(Status::Online, 10, 10));
connect(statusOnline, SIGNAL(triggered()), this, SLOT(setStatusOnline()));
statusOnline->setIcon(getStatusIcon(Status::Online, 50, 50));
connect(statusOnline, &QAction::triggered, this, &Widget::setStatusOnline);
statusAway = new QAction(this);
statusAway->setIcon(getStatusIcon(Status::Away, 10, 10));
connect(statusAway, SIGNAL(triggered()), this, SLOT(setStatusAway()));
statusAway->setIcon(getStatusIcon(Status::Away, 50, 50));
connect(statusAway, &QAction::triggered, this, &Widget::setStatusAway);
statusBusy = new QAction(this);
statusBusy->setIcon(getStatusIcon(Status::Busy, 10, 10));
connect(statusBusy, SIGNAL(triggered()), this, SLOT(setStatusBusy()));
statusBusy->setIcon(getStatusIcon(Status::Busy, 50, 50));
connect(statusBusy, &QAction::triggered, this, &Widget::setStatusBusy);
layout()->setContentsMargins(0, 0, 0, 0);
ui->friendList->setStyleSheet(Style::resolve(Style::getStylesheet(":ui/friendList/friendList.css")));
@ -412,7 +415,16 @@ void Widget::updateIcons()
if (ico.isNull())
{
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);
@ -1682,12 +1694,14 @@ void Widget::onTryCreateTrayIcon()
{
if (QSystemTrayIcon::isSystemTrayAvailable())
{
icon = new SystemTrayIcon;
icon = new SystemTrayIcon(this);
updateIcons();
trayMenu = new QMenu;
actionQuit = new QAction(tr("&Quit"), this);
connect(actionQuit, SIGNAL(triggered()), qApp, SLOT(quit()));
trayMenu = new QMenu(this);
QStyle *style = qApp->style();
actionQuit = new QAction(tr("&Exit"), this);
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(statusAway);
@ -1696,8 +1710,7 @@ void Widget::onTryCreateTrayIcon()
trayMenu->addAction(actionQuit);
icon->setContextMenu(trayMenu);
connect(icon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
this, SLOT(onIconClick(QSystemTrayIcon::ActivationReason)));
connect(icon, &SystemTrayIcon::activated, this, &Widget::onIconClick);
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 getStatusIconPixmap(status, w, h);
else
return QIcon(getStatusIconPath(status));
return QIcon(getStatusIconPath(status));
}
QPixmap Widget::getStatusIconPixmap(Status status, uint32_t w, uint32_t h)