summaryrefslogtreecommitdiffstats
path: root/src/qdbus
diff options
context:
space:
mode:
authorAlexander Volkov <a.volkov@rusbitech.ru>2014-09-19 16:22:53 +0400
committerAlexander Volkov <a.volkov@rusbitech.ru>2014-09-24 09:51:14 +0200
commit600baf72fa2d100f0ec5e2861f3594b38ff6a2a2 (patch)
treed41360c8ce040f8dd9656b8c32014c3ddceae5ce /src/qdbus
parenta8fd7c7b0a89e063d62cf130c5044d5b5d23f467 (diff)
qdbusviewer: Extract MainWindow class
This refactoring is a preparation for saving/restoring window settings. Change-Id: I22b4c4947437e90f986390a4dd7c14d50a0f02d6 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Diffstat (limited to 'src/qdbus')
-rw-r--r--src/qdbus/qdbusviewer/main.cpp43
-rw-r--r--src/qdbus/qdbusviewer/mainwindow.cpp101
-rw-r--r--src/qdbus/qdbusviewer/mainwindow.h64
-rw-r--r--src/qdbus/qdbusviewer/qdbusviewer.cpp13
-rw-r--r--src/qdbus/qdbusviewer/qdbusviewer.h1
-rw-r--r--src/qdbus/qdbusviewer/qdbusviewer.pro6
6 files changed, 174 insertions, 54 deletions
diff --git a/src/qdbus/qdbusviewer/main.cpp b/src/qdbus/qdbusviewer/main.cpp
index f539230be..54e49d4cb 100644
--- a/src/qdbus/qdbusviewer/main.cpp
+++ b/src/qdbus/qdbusviewer/main.cpp
@@ -40,62 +40,29 @@
****************************************************************************/
#include <QtWidgets/qapplication.h>
-#include <QtWidgets/qmainwindow.h>
-#include <QtWidgets/qtabwidget.h>
-#include <QtWidgets/QMenuBar>
-#include <QtWidgets/QMenu>
-#include <QtWidgets/QAction>
-#include <QtDBus/qdbusconnection.h>
-#include "qdbusviewer.h"
+
+#include "mainwindow.h"
#include <stdio.h>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
- QMainWindow mw;
+ MainWindow mw;
#ifndef Q_OS_MAC
app.setWindowIcon(QIcon(QLatin1String(":/qt-project.org/qdbusviewer/images/qdbusviewer.png")));
#else
mw.setWindowTitle(qApp->translate("QtDBusViewer", "Qt D-Bus Viewer"));
#endif
-
- QTabWidget *mainWidget = new QTabWidget;
- mw.setCentralWidget(mainWidget);
- QDBusViewer *sessionBusViewer = new QDBusViewer(QDBusConnection::sessionBus());
- QDBusViewer *systemBusViewer = new QDBusViewer(QDBusConnection::systemBus());
- mainWidget->addTab(sessionBusViewer, QObject::tr("Session Bus"));
- mainWidget->addTab(systemBusViewer, QObject::tr("System Bus"));
-
QStringList args = app.arguments();
while (args.count()) {
QString arg = args.takeFirst();
- if (arg == QLatin1String("--bus")) {
- QDBusConnection connection = QDBusConnection::connectToBus(args.takeFirst(), "QDBusViewer");
- if (connection.isConnected()) {
- QDBusViewer *customBusViewer = new QDBusViewer(connection);
- mainWidget->addTab(customBusViewer, QObject::tr("Custom Bus"));
- }
- }
+ if (arg == QLatin1String("--bus"))
+ mw.addCustomBusTab(args.takeFirst());
}
- QMenu *fileMenu = mw.menuBar()->addMenu(QObject::tr("&File"));
- QAction *quitAction = fileMenu->addAction(QObject::tr("&Quit"), &mw, SLOT(close()));
- quitAction->setShortcut(QKeySequence::Quit);
- quitAction->setMenuRole(QAction::QuitRole);
-
- QMenu *helpMenu = mw.menuBar()->addMenu(QObject::tr("&Help"));
- QAction *aboutAction = helpMenu->addAction(QObject::tr("&About"));
- aboutAction->setMenuRole(QAction::AboutRole);
- QObject::connect(aboutAction, SIGNAL(triggered()), sessionBusViewer, SLOT(about()));
-
- QAction *aboutQtAction = helpMenu->addAction(QObject::tr("About &Qt"));
- aboutQtAction->setMenuRole(QAction::AboutQtRole);
- QObject::connect(aboutQtAction, SIGNAL(triggered()), &app, SLOT(aboutQt()));
-
mw.show();
return app.exec();
}
-
diff --git a/src/qdbus/qdbusviewer/mainwindow.cpp b/src/qdbus/qdbusviewer/mainwindow.cpp
new file mode 100644
index 000000000..723d5637f
--- /dev/null
+++ b/src/qdbus/qdbusviewer/mainwindow.cpp
@@ -0,0 +1,101 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the tools applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mainwindow.h"
+
+#include "qdbusviewer.h"
+
+#include <QtWidgets/QApplication>
+#include <QtWidgets/QTabWidget>
+#include <QtWidgets/QMenuBar>
+#include <QtWidgets/QMenu>
+#include <QtWidgets/QAction>
+#include <QtWidgets/QMessageBox>
+
+#include <QtDBus/QDBusConnection>
+
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent)
+{
+ QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
+ QAction *quitAction = fileMenu->addAction(tr("&Quit"), this, SLOT(close()));
+ quitAction->setShortcut(QKeySequence::Quit);
+ quitAction->setMenuRole(QAction::QuitRole);
+
+ QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
+ QAction *aboutAction = helpMenu->addAction(tr("&About"));
+ aboutAction->setMenuRole(QAction::AboutRole);
+ QObject::connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
+
+ QAction *aboutQtAction = helpMenu->addAction(tr("About &Qt"));
+ aboutQtAction->setMenuRole(QAction::AboutQtRole);
+ QObject::connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+
+ tabWidget = new QTabWidget;
+ setCentralWidget(tabWidget);
+
+ QDBusViewer *sessionBusViewer = new QDBusViewer(QDBusConnection::sessionBus());
+ QDBusViewer *systemBusViewer = new QDBusViewer(QDBusConnection::systemBus());
+ tabWidget->addTab(sessionBusViewer, tr("Session Bus"));
+ tabWidget->addTab(systemBusViewer, tr("System Bus"));
+}
+
+void MainWindow::addCustomBusTab(const QString &busAddress)
+{
+ QDBusConnection connection = QDBusConnection::connectToBus(busAddress, "QDBusViewer");
+ if (connection.isConnected()) {
+ QDBusViewer *customBusViewer = new QDBusViewer(connection);
+ tabWidget->addTab(customBusViewer, tr("Custom Bus"));
+ }
+}
+
+void MainWindow::about()
+{
+ QMessageBox box(this);
+
+ box.setText(QString::fromLatin1("<center><img src=\":/qt-project.org/qdbusviewer/images/qdbusviewer-128.png\">"
+ "<h3>%1</h3>"
+ "<p>Version %2</p></center>"
+ "<p>Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).</p>")
+ .arg(tr("D-Bus Viewer")).arg(QLatin1String(QT_VERSION_STR)));
+ box.setWindowTitle(tr("D-Bus Viewer"));
+ box.exec();
+}
diff --git a/src/qdbus/qdbusviewer/mainwindow.h b/src/qdbus/qdbusviewer/mainwindow.h
new file mode 100644
index 000000000..d1802f457
--- /dev/null
+++ b/src/qdbus/qdbusviewer/mainwindow.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the tools applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+QT_FORWARD_DECLARE_CLASS(QTabWidget)
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+public:
+ explicit MainWindow(QWidget *parent = 0);
+
+ void addCustomBusTab(const QString &bus);
+
+private slots:
+ void about();
+
+private:
+ QTabWidget *tabWidget;
+};
+
+#endif // MAINWINDOW_H
diff --git a/src/qdbus/qdbusviewer/qdbusviewer.cpp b/src/qdbus/qdbusviewer/qdbusviewer.cpp
index ac0c141b4..cb98c578a 100644
--- a/src/qdbus/qdbusviewer/qdbusviewer.cpp
+++ b/src/qdbus/qdbusviewer/qdbusviewer.cpp
@@ -495,19 +495,6 @@ void QDBusViewer::refreshChildren()
model->refresh(tree->currentIndex());
}
-void QDBusViewer::about()
-{
- QMessageBox box(this);
-
- box.setText(QString::fromLatin1("<center><img src=\":/qt-project.org/qdbusviewer/images/qdbusviewer-128.png\">"
- "<h3>%1</h3>"
- "<p>Version %2</p></center>"
- "<p>Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).</p>")
- .arg(tr("D-Bus Viewer")).arg(QLatin1String(QT_VERSION_STR)));
- box.setWindowTitle(tr("D-Bus Viewer"));
- box.exec();
-}
-
void QDBusViewer::anchorClicked(const QUrl &url)
{
if (url.scheme() != QLatin1String("qdbus"))
diff --git a/src/qdbus/qdbusviewer/qdbusviewer.h b/src/qdbus/qdbusviewer/qdbusviewer.h
index 92523cce3..7a9feba28 100644
--- a/src/qdbus/qdbusviewer/qdbusviewer.h
+++ b/src/qdbus/qdbusviewer/qdbusviewer.h
@@ -69,7 +69,6 @@ public:
public slots:
void refresh();
- void about();
private slots:
void serviceChanged(const QModelIndex &index);
diff --git a/src/qdbus/qdbusviewer/qdbusviewer.pro b/src/qdbus/qdbusviewer/qdbusviewer.pro
index 1cd2f8f4d..a653f9f46 100644
--- a/src/qdbus/qdbusviewer/qdbusviewer.pro
+++ b/src/qdbus/qdbusviewer/qdbusviewer.pro
@@ -1,13 +1,15 @@
HEADERS = qdbusviewer.h \
qdbusmodel.h \
propertydialog.h \
- logviewer.h
+ logviewer.h \
+ mainwindow.h
SOURCES = qdbusviewer.cpp \
qdbusmodel.cpp \
propertydialog.cpp \
logviewer.cpp \
- main.cpp
+ mainwindow.cpp \
+ main.cpp \
RESOURCES += qdbusviewer.qrc