2
This file is part of Akonadi.
4
Copyright (c) 2006 Tobias Koenig <tokoe@kde.org>
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22
#include "debugwidget.h"
24
#include "tracernotificationinterface.h"
25
#include "connectionpage.h"
27
#include <akonadi/control.h>
31
#include <QtGui/QPushButton>
32
#include <QtGui/QSplitter>
33
#include <QtGui/QTabWidget>
34
#include <QtGui/QTextEdit>
35
#include <QtGui/QVBoxLayout>
36
#include <QtGui/QCheckBox>
38
using org::freedesktop::Akonadi::DebugInterface;
40
DebugWidget::DebugWidget( QWidget *parent )
43
QVBoxLayout *layout = new QVBoxLayout( this );
45
mDebugInterface = new DebugInterface( "org.freedesktop.Akonadi", "/debug", QDBusConnection::sessionBus(), this );
46
QCheckBox *cb = new QCheckBox( i18n("Enable debugger"), this );
47
cb->setChecked( mDebugInterface->isValid() && mDebugInterface->tracer().value() == QLatin1String( "dbus" ) );
48
connect( cb, SIGNAL(toggled(bool)), SLOT(enableDebugger(bool)) );
49
layout->addWidget( cb );
51
QSplitter *splitter = new QSplitter( Qt::Vertical, this );
52
splitter->setObjectName( "debugSplitter" );
53
layout->addWidget( splitter );
55
mConnectionPages = new QTabWidget( splitter );
57
mGeneralView = new QTextEdit( splitter );
58
mGeneralView->setReadOnly( true );
60
ConnectionPage *page = new ConnectionPage( "All" );
61
page->showAllConnections( true );
62
mConnectionPages->addTab( page, "All" );
64
org::freedesktop::Akonadi::TracerNotification *iface = new org::freedesktop::Akonadi::TracerNotification( QString(), "/tracing/notifications", QDBusConnection::sessionBus(), this );
66
connect( iface, SIGNAL( connectionStarted( const QString&, const QString& ) ),
67
this, SLOT( connectionStarted( const QString&, const QString& ) ) );
68
connect( iface, SIGNAL( connectionEnded( const QString&, const QString& ) ),
69
this, SLOT( connectionEnded( const QString&, const QString& ) ) );
70
connect( iface, SIGNAL( signalEmitted( const QString&, const QString& ) ),
71
this, SLOT( signalEmitted( const QString&, const QString& ) ) );
72
connect( iface, SIGNAL( warningEmitted( const QString&, const QString& ) ),
73
this, SLOT( warningEmitted( const QString&, const QString& ) ) );
74
connect( iface, SIGNAL( errorEmitted( const QString&, const QString& ) ),
75
this, SLOT( errorEmitted( const QString&, const QString& ) ) );
77
// in case we started listening when the connection is already ongoing
78
connect( iface, SIGNAL( connectionDataInput( const QString&, const QString& ) ),
79
this, SLOT( connectionStarted( const QString&, const QString& ) ) );
80
connect( iface, SIGNAL( connectionDataOutput( const QString&, const QString& ) ),
81
this, SLOT( connectionStarted( const QString&, const QString& ) ) );
83
QHBoxLayout *buttonLayout = new QHBoxLayout;
84
layout->addLayout( buttonLayout );
86
QPushButton *clearAllButton = new QPushButton( "Clear All", this );
87
QPushButton *clearGeneralButton = new QPushButton( "Clear General", this );
89
buttonLayout->addWidget( clearAllButton );
90
buttonLayout->addWidget( clearGeneralButton );
92
connect( clearAllButton, SIGNAL( clicked() ), page, SLOT( clear() ) );
93
connect( clearGeneralButton, SIGNAL( clicked() ), mGeneralView, SLOT( clear() ) );
95
Akonadi::Control::widgetNeedsAkonadi( this );
98
void DebugWidget::connectionStarted( const QString &identifier, const QString &msg )
101
if ( mPageHash.contains( identifier ) )
104
ConnectionPage *page = new ConnectionPage( identifier );
105
mConnectionPages->addTab( page, identifier );
107
mPageHash.insert( identifier, page );
110
void DebugWidget::connectionEnded( const QString &identifier, const QString& )
112
if ( !mPageHash.contains( identifier ) )
115
QWidget *widget = mPageHash[ identifier ];
117
mConnectionPages->removeTab( mConnectionPages->indexOf( widget ) );
119
mPageHash.remove( identifier );
123
void DebugWidget::signalEmitted( const QString &signalName, const QString &msg )
125
mGeneralView->append( QString( "<font color=\"green\">%1 ( %2 )</font>" ).arg( signalName, msg ) );
128
void DebugWidget::warningEmitted( const QString &componentName, const QString &msg )
130
mGeneralView->append( QString( "<font color=\"blue\">%1: %2</font>" ).arg( componentName, msg ) );
133
void DebugWidget::errorEmitted( const QString &componentName, const QString &msg )
135
mGeneralView->append( QString( "<font color=\"red\">%1: %2</font>" ).arg( componentName, msg ) );
138
void DebugWidget::enableDebugger(bool enable)
140
mDebugInterface->setTracer( enable ? QLatin1String( "dbus" ) : QLatin1String( "null" ) );
143
#include "debugwidget.moc"