diff --git a/src/qdbus/qdbusviewer/main.cpp b/src/qdbus/qdbusviewer/main.cpp index f539230be7549484cc79136281ab55d402e120d9..54e49d4cbf24f687d20ccad4e1cab86cdc88e7fd 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 0000000000000000000000000000000000000000..723d5637f0cf62a09271260117bf6b204604b304 --- /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 0000000000000000000000000000000000000000..d1802f4571da3e25bab6de53e2bba6ecc092af02 --- /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 ac0c141b4799d27d979f00f4c7cc6b967ec0d87c..cb98c578a1644c9c04d5f9a676641a17224012c8 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 92523cce376620f2d6eba11bf910aa3ddfc6768e..7a9feba287e6175400f5413c61b289d4c08ddaca 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 1cd2f8f4d901ef009c73d6452f472443ab0934ba..a653f9f46463aa9d1c7bf17a725ddac9e559d16d 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