indicator: open Configure menu on double click

This commit is contained in:
Piyush Aggarwal 2020-11-14 13:54:21 +05:30
parent d773959a5d
commit e7c3c4fb7b

View file

@ -7,6 +7,7 @@
#include <QApplication>
#include <QProcess>
#include <QThread>
#include <QPointer>
#ifdef QSYSTRAY
#include <QSystemTrayIcon>
@ -56,15 +57,22 @@ int main(int argc, char** argv)
model.setDisplayFilter(DevicesModel::Reachable | DevicesModel::Paired);
QMenu* menu = new QMenu;
QPointer<KCMultiDialog> dialog;
DaemonDbusInterface iface;
auto refreshMenu = [&iface, &model, &menu, &helper]() {
auto refreshMenu = [&iface, &model, &menu, &helper, &dialog]() {
menu->clear();
auto configure = menu->addAction(QIcon::fromTheme(QStringLiteral("configure")), i18n("Configure..."));
QObject::connect(configure, &QAction::triggered, configure, [](){
KCMultiDialog* dialog = new KCMultiDialog;
dialog->addModule(QStringLiteral("kcm_kdeconnect"));
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->show();
QObject::connect(configure, &QAction::triggered, configure, [&dialog]() {
if (dialog == nullptr) {
dialog = new KCMultiDialog;
dialog->addModule(QStringLiteral("kcm_kdeconnect"));
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->show();
} else {
dialog->activateWindow();
}
});
for (int i=0, count = model.rowCount(); i<count; ++i) {
DeviceDbusInterface* device = model.getDevice(i);
@ -125,6 +133,11 @@ int main(int argc, char** argv)
QObject::connect(&model, &DevicesModel::rowsChanged, &model, [&systray, &model]() {
systray.setToolTip(i18np("%1 device connected", "%1 devices connected", model.rowCount()));
});
QObject::connect(&systray, &QSystemTrayIcon::activated, [&iface](QSystemTrayIcon::ActivationReason reason) {
if (reason == QSystemTrayIcon::DoubleClick) {
iface.openConfiguration();
}
});
systray.setContextMenu(menu);
#else