Add optional system tray support to KDE GUI
This commit is contained in:
parent
f36a782632
commit
db8414f815
|
|
@ -103,6 +103,13 @@ Dialog {
|
|||
font.pixelSize: Qt.application.font.pixelSize * 0.85
|
||||
}
|
||||
|
||||
CheckBox {
|
||||
text: "Keep Ollie running in the system tray when closed"
|
||||
checked: theme.closeToTray
|
||||
onToggled: theme.closeToTray = checked
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
Layout.fillWidth: true
|
||||
height: 1
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
// ollie-gui-9p: minimal Qt GUI using 9P for all communication.
|
||||
// Uses ollie-9p subprocess for 9P transport.
|
||||
#include <QApplication>
|
||||
#include <QIcon>
|
||||
#include <QMenu>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QAction>
|
||||
#include <QQuickWindow>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlContext>
|
||||
#include <QQuickStyle>
|
||||
|
|
@ -48,5 +53,40 @@ const QUrl url(QStringLiteral("qrc:/main.qml"));
|
|||
if (engine.rootObjects().isEmpty())
|
||||
return -1;
|
||||
|
||||
auto *window = qobject_cast<QQuickWindow *>(engine.rootObjects().constFirst());
|
||||
QIcon trayIconImage = QIcon::fromTheme("ollie");
|
||||
if (trayIconImage.isNull()) {
|
||||
trayIconImage.addFile(":/ollie.svg");
|
||||
trayIconImage.addFile(":/gui/ollie.svg");
|
||||
}
|
||||
auto *trayIcon = new QSystemTrayIcon(trayIconImage, &app);
|
||||
auto *trayMenu = new QMenu;
|
||||
auto *showAction = trayMenu->addAction("Show Ollie");
|
||||
trayMenu->addSeparator();
|
||||
auto *quitAction = trayMenu->addAction("Quit");
|
||||
trayIcon->setContextMenu(trayMenu);
|
||||
trayIcon->setToolTip("Ollie");
|
||||
|
||||
engine.rootContext()->setContextProperty("trayIcon", trayIcon);
|
||||
|
||||
QObject::connect(showAction, &QAction::triggered, [window, trayIcon]() {
|
||||
window->show();
|
||||
window->raise();
|
||||
window->requestActivate();
|
||||
trayIcon->show();
|
||||
});
|
||||
QObject::connect(quitAction, &QAction::triggered, [window, &app]() {
|
||||
window->setProperty("quitting", true);
|
||||
app.quit();
|
||||
});
|
||||
QObject::connect(trayIcon, &QSystemTrayIcon::activated,
|
||||
[showAction](QSystemTrayIcon::ActivationReason reason) {
|
||||
if (reason == QSystemTrayIcon::Trigger)
|
||||
showAction->trigger();
|
||||
});
|
||||
QObject::connect(theme, &ThemeManager::closeToTrayChanged,
|
||||
[theme, trayIcon]() { trayIcon->setVisible(theme->closeToTray()); });
|
||||
trayIcon->setVisible(theme->closeToTray());
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,8 +79,15 @@ ApplicationWindow {
|
|||
}
|
||||
|
||||
property bool sidebarVisible: true
|
||||
property bool quitting: false
|
||||
|
||||
// --- Rename Error Dialog ---
|
||||
onClosing: function(close) {
|
||||
if (!quitting && theme.closeToTray) {
|
||||
close.accepted = false
|
||||
root.hide()
|
||||
trayIcon.show()
|
||||
}
|
||||
}
|
||||
Dialog {
|
||||
id: renameErrorDialog
|
||||
title: "Rename Failed"
|
||||
|
|
|
|||
|
|
@ -8,5 +8,6 @@
|
|||
<file>ChatBlockDelegate.qml</file>
|
||||
<file>SessionTree.qml</file>
|
||||
<file>ChatPane.qml</file>
|
||||
<file>ollie.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
|
|||
Loading…
Reference in New Issue