8#include <QtWidgets/QApplication>
9#include <QtWidgets/QTabWidget>
10#include <QtWidgets/QMenuBar>
11#include <QtWidgets/QMenu>
12#include <QtGui/QAction>
13#include <QtWidgets/QMessageBox>
15#include <QtDBus/QDBusConnection>
16#include <QtCore/QSettings>
18using namespace Qt::StringLiterals;
22 , systemBusViewer(
nullptr)
24 QMenu *fileMenu = menuBar()->addMenu(tr(
"&File"));
25 QAction *quitAction = fileMenu->addAction(tr(
"&Quit"),
this, &QWidget::close);
26 quitAction->setShortcut(QKeySequence::Quit);
27 quitAction->setMenuRole(QAction::QuitRole);
29 QMenu *helpMenu = menuBar()->addMenu(tr(
"&Help"));
30 QAction *aboutAction = helpMenu->addAction(tr(
"&About"));
31 aboutAction->setMenuRole(QAction::AboutRole);
32 QObject::connect(aboutAction, &QAction::triggered,
this, &MainWindow::about);
34 QAction *aboutQtAction = helpMenu->addAction(tr(
"About &Qt"));
35 aboutQtAction->setMenuRole(QAction::AboutQtRole);
36 QObject::connect(aboutQtAction, &QAction::triggered, qApp, &QApplication::aboutQt);
38 tabWidget =
new QTabWidget;
39 setCentralWidget(tabWidget);
41 sessionBusViewer =
new QDBusViewer(QDBusConnection::sessionBus());
42 tabWidget->addTab(sessionBusViewer, tr(
"Session Bus"));
44 QDBusConnection connection = QDBusConnection::systemBus();
45 if (connection.isConnected()) {
47 tabWidget->addTab(systemBusViewer, tr(
"System Bus"));
60 QDBusConnection connection = QDBusConnection::connectToBus(busAddress,
"QDBusViewer");
61 if (connection.isConnected()) {
63 tabWidget->addTab(customBusViewer, tr(
"Custom Bus"));
69 QMessageBox box(
this);
71 box.setText(tr(
"<center><img src=\":/qt-project.org/qdbusviewer/images/qdbusviewer-128.png\">"
73 "<p>Version %2</p></center>"
74 "<p>Copyright (C) The Qt Company Ltd. and other contributors.</p>")
75 .arg(tr(
"D-Bus Viewer"), QLatin1String(QT_VERSION_STR)));
76 box.setWindowTitle(tr(
"D-Bus Viewer"));
82 return u"WindowGeometry"_s;
87 return u"SessionTab"_s;
92 return u"SystemTab"_s;
99 settings.setValue(windowGeometryKey(), saveGeometry());
101 settings.beginGroup(sessionTabGroup());
102 sessionBusViewer->saveState(&settings);
105 if (systemBusViewer) {
106 settings.beginGroup(systemTabGroup());
107 systemBusViewer->saveState(&settings);
116 restoreGeometry(settings.value(windowGeometryKey()).toByteArray());
118 settings.beginGroup(sessionTabGroup());
119 sessionBusViewer->restoreState(&settings);
122 if (systemBusViewer) {
123 settings.beginGroup(systemTabGroup());
124 systemBusViewer->restoreState(&settings);
void addCustomBusTab(const QString &bus)
MainWindow(QWidget *parent=nullptr)
static QString sessionTabGroup()
static QString systemTabGroup()
static QString windowGeometryKey()