Commit 600baf72 authored by Alexander Volkov's avatar Alexander Volkov
Browse files

qdbusviewer: Extract MainWindow class


This refactoring is a preparation for saving/restoring window settings.

Change-Id: I22b4c4947437e90f986390a4dd7c14d50a0f02d6
Reviewed-by: default avatarOswald Buddenhagen <oswald.buddenhagen@digia.com>
Reviewed-by: default avatarFriedemann Kleint <Friedemann.Kleint@digia.com>
Showing with 174 additions and 54 deletions
...@@ -40,62 +40,29 @@ ...@@ -40,62 +40,29 @@
****************************************************************************/ ****************************************************************************/
#include <QtWidgets/qapplication.h> #include <QtWidgets/qapplication.h>
#include <QtWidgets/qmainwindow.h>
#include <QtWidgets/qtabwidget.h> #include "mainwindow.h"
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QMenu>
#include <QtWidgets/QAction>
#include <QtDBus/qdbusconnection.h>
#include "qdbusviewer.h"
#include <stdio.h> #include <stdio.h>
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication app(argc, argv); QApplication app(argc, argv);
QMainWindow mw; MainWindow mw;
#ifndef Q_OS_MAC #ifndef Q_OS_MAC
app.setWindowIcon(QIcon(QLatin1String(":/qt-project.org/qdbusviewer/images/qdbusviewer.png"))); app.setWindowIcon(QIcon(QLatin1String(":/qt-project.org/qdbusviewer/images/qdbusviewer.png")));
#else #else
mw.setWindowTitle(qApp->translate("QtDBusViewer", "Qt D-Bus Viewer")); mw.setWindowTitle(qApp->translate("QtDBusViewer", "Qt D-Bus Viewer"));
#endif #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(); QStringList args = app.arguments();
while (args.count()) { while (args.count()) {
QString arg = args.takeFirst(); QString arg = args.takeFirst();
if (arg == QLatin1String("--bus")) { if (arg == QLatin1String("--bus"))
QDBusConnection connection = QDBusConnection::connectToBus(args.takeFirst(), "QDBusViewer"); mw.addCustomBusTab(args.takeFirst());
if (connection.isConnected()) {
QDBusViewer *customBusViewer = new QDBusViewer(connection);
mainWidget->addTab(customBusViewer, QObject::tr("Custom Bus"));
}
}
} }
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(); mw.show();
return app.exec(); return app.exec();
} }
/****************************************************************************
**
** 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();
}
/****************************************************************************
**
** 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
...@@ -495,19 +495,6 @@ void QDBusViewer::refreshChildren() ...@@ -495,19 +495,6 @@ void QDBusViewer::refreshChildren()
model->refresh(tree->currentIndex()); 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) void QDBusViewer::anchorClicked(const QUrl &url)
{ {
if (url.scheme() != QLatin1String("qdbus")) if (url.scheme() != QLatin1String("qdbus"))
......
...@@ -69,7 +69,6 @@ public: ...@@ -69,7 +69,6 @@ public:
public slots: public slots:
void refresh(); void refresh();
void about();
private slots: private slots:
void serviceChanged(const QModelIndex &index); void serviceChanged(const QModelIndex &index);
......
HEADERS = qdbusviewer.h \ HEADERS = qdbusviewer.h \
qdbusmodel.h \ qdbusmodel.h \
propertydialog.h \ propertydialog.h \
logviewer.h logviewer.h \
mainwindow.h
SOURCES = qdbusviewer.cpp \ SOURCES = qdbusviewer.cpp \
qdbusmodel.cpp \ qdbusmodel.cpp \
propertydialog.cpp \ propertydialog.cpp \
logviewer.cpp \ logviewer.cpp \
main.cpp mainwindow.cpp \
main.cpp \
RESOURCES += qdbusviewer.qrc RESOURCES += qdbusviewer.qrc
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment