summaryrefslogtreecommitdiffstats
path: root/examples/applicationmanager/application-features/native
diff options
context:
space:
mode:
authorBernd Weimer <bernd.weimer@pelagicore.com>2019-09-20 16:01:22 +0200
committerBernd Weimer <bernd.weimer@pelagicore.com>2019-11-14 16:26:40 +0100
commit973a514b1a5ed706b024866c715dacdff68f70ab (patch)
treef8a91914afa4a774e902c2df8f38d2ace5443194 /examples/applicationmanager/application-features/native
parent8e46d6738c8335b9983fa365dfc684d4edb606c2 (diff)
Rename classes
Those classes are not restricted to QML, but provide general inter- process communication via DBus. They can be used from native applications, as well: - QmlApplicationInterface to DBusApplicationInterface - QmlApplicationInterfaceExtension to DBusApplicationInterfaceExtension - QmlNotification to DBusNotification Task-number: AUTOSUITE-1260 Change-Id: Iaff6251e61d62b7173e0e17a81863b4f653e8b5d Reviewed-by: Robert Griebl <robert.griebl@qt.io>
Diffstat (limited to 'examples/applicationmanager/application-features/native')
-rw-r--r--examples/applicationmanager/application-features/native/widgets/main.cpp42
1 files changed, 33 insertions, 9 deletions
diff --git a/examples/applicationmanager/application-features/native/widgets/main.cpp b/examples/applicationmanager/application-features/native/widgets/main.cpp
index 3403065f..4c1c0914 100644
--- a/examples/applicationmanager/application-features/native/widgets/main.cpp
+++ b/examples/applicationmanager/application-features/native/widgets/main.cpp
@@ -29,14 +29,18 @@
#include <QApplication>
#include <QPushButton>
#include <QDialog>
+#include <QVBoxLayout>
#include "launchermain.h"
#include "logging.h"
+#include "dbusapplicationinterface.h"
+#include "dbusnotification.h"
int main(int argc, char *argv[])
{
QtAM::Logging::initialize(argc, argv);
+ QtAM::Logging::setApplicationId("widgets");
QtAM::LauncherMain::initialize();
QApplication app(argc, argv);
@@ -44,19 +48,39 @@ int main(int argc, char *argv[])
launcher.registerWaylandExtensions();
launcher.loadConfiguration();
- launcher.setupDBusConnections();
launcher.setupLogging(false, launcher.loggingRules(), QString(), launcher.useAMConsoleLogger());
+ launcher.setupDBusConnections();
+
+ QWidget window;
+ QVBoxLayout layout(&window);
+
+ // Popup using application manager window property
+ QPushButton button1(QStringLiteral("Click to open/close a popup"));
+ button1.setStyleSheet(QStringLiteral("QPushButton { background-color : limegreen; font-size: 36px; }"));
+ layout.addWidget(&button1);
+
+ QDialog *popup1 = new QDialog(&window);
+ (new QPushButton(QStringLiteral("I'm a popup!"), popup1))->resize(340, 140);
+ popup1->setStyleSheet(QStringLiteral("QPushButton { background-color : limegreen; color : white; font-size: 24px; }"));
+ QObject::connect(&button1, &QPushButton::clicked, [&popup1, &launcher] () {
+ popup1->setVisible(!popup1->isVisible());
+ launcher.setWindowProperty(popup1->windowHandle(), "type", QStringLiteral("pop-up"));
+ });
- QPushButton window("I'm a top-level window!\nClick to open/close a popup.");
- QDialog *popup = new QDialog(&window);
- (new QPushButton("I'm a popup!", popup))->resize(300, 100);
+ // Notification
+ QPushButton button2(QStringLiteral("Click to open a notification"));
+ button2.setStyleSheet(QStringLiteral("QPushButton { background-color : darkgrey; font-size: 36px; }"));
+ layout.addWidget(&button2);
- window.setStyleSheet("QPushButton { background-color : lightgrey; font-size: 36px; }");
- popup->setStyleSheet("QPushButton { background-color : green; color : white; font-size: 24px; }");
+ QtAM::DBusNotification *notification = QtAM::DBusNotification::create(&app);
+ notification->setSummary(QStringLiteral("I'm a notification"));
+ QObject::connect(&button2, &QPushButton::clicked, notification, &QtAM::DBusNotification::show);
- QObject::connect(&window, &QPushButton::clicked, [&popup, &launcher] () {
- popup->setVisible(!popup->isVisible());
- launcher.setWindowProperty(popup->windowHandle(), "type", QVariant::fromValue(QStringLiteral("pop-up")));
+ // Application interface for handling quit
+ QtAM::DBusApplicationInterface iface(launcher.p2pDBusName(), launcher.notificationDBusName());
+ iface.initialize();
+ QObject::connect(&iface, &QtAM::DBusApplicationInterface::quit, [&iface] () {
+ iface.acknowledgeQuit();
});
app.processEvents();