~ubuntu-branches/ubuntu/karmic/kdepim/karmic-backports

« back to all changes in this revision

Viewing changes to akonadi/akonadiconsole/debugwidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christian Mangold
  • Date: 2009-07-10 06:34:50 UTC
  • mfrom: (1.1.40 upstream)
  • Revision ID: james.westby@ubuntu.com-20090710063450-neojgew2fh0n3y0u
Tags: 4:4.2.96-0ubuntu1
* New upstream release
* Bump kde build-deps to 4.2.96

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    This file is part of Akonadi.
3
 
 
4
 
    Copyright (c) 2006 Tobias Koenig <tokoe@kde.org>
5
 
 
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.
10
 
 
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.
15
 
 
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,
19
 
    USA.
20
 
*/
21
 
 
22
 
#include "debugwidget.h"
23
 
 
24
 
#include "tracernotificationinterface.h"
25
 
#include "connectionpage.h"
26
 
 
27
 
#include <akonadi/control.h>
28
 
 
29
 
#include <KLocale>
30
 
 
31
 
#include <QtGui/QPushButton>
32
 
#include <QtGui/QSplitter>
33
 
#include <QtGui/QTabWidget>
34
 
#include <QtGui/QTextEdit>
35
 
#include <QtGui/QVBoxLayout>
36
 
#include <QtGui/QCheckBox>
37
 
 
38
 
using org::freedesktop::Akonadi::DebugInterface;
39
 
 
40
 
DebugWidget::DebugWidget( QWidget *parent )
41
 
  : QWidget( parent )
42
 
{
43
 
  QVBoxLayout *layout = new QVBoxLayout( this );
44
 
 
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 );
50
 
 
51
 
  QSplitter *splitter = new QSplitter( Qt::Vertical, this );
52
 
  splitter->setObjectName( "debugSplitter" );
53
 
  layout->addWidget( splitter );
54
 
 
55
 
  mConnectionPages = new QTabWidget( splitter );
56
 
 
57
 
  mGeneralView = new QTextEdit( splitter );
58
 
  mGeneralView->setReadOnly( true );
59
 
 
60
 
  ConnectionPage *page = new ConnectionPage( "All" );
61
 
  page->showAllConnections( true );
62
 
  mConnectionPages->addTab( page, "All" );
63
 
 
64
 
  org::freedesktop::Akonadi::TracerNotification *iface = new org::freedesktop::Akonadi::TracerNotification( QString(), "/tracing/notifications", QDBusConnection::sessionBus(), this );
65
 
 
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& ) ) );
76
 
 
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& ) ) );
82
 
 
83
 
  QHBoxLayout *buttonLayout = new QHBoxLayout;
84
 
  layout->addLayout( buttonLayout );
85
 
 
86
 
  QPushButton *clearAllButton = new QPushButton( "Clear All", this );
87
 
  QPushButton *clearGeneralButton = new QPushButton( "Clear General", this );
88
 
 
89
 
  buttonLayout->addWidget( clearAllButton );
90
 
  buttonLayout->addWidget( clearGeneralButton );
91
 
 
92
 
  connect( clearAllButton, SIGNAL( clicked() ), page, SLOT( clear() ) );
93
 
  connect( clearGeneralButton, SIGNAL( clicked() ), mGeneralView, SLOT( clear() ) );
94
 
 
95
 
  Akonadi::Control::widgetNeedsAkonadi( this );
96
 
}
97
 
 
98
 
void DebugWidget::connectionStarted( const QString &identifier, const QString &msg )
99
 
{
100
 
  Q_UNUSED( msg );
101
 
  if ( mPageHash.contains( identifier ) )
102
 
    return;
103
 
 
104
 
  ConnectionPage *page = new ConnectionPage( identifier );
105
 
  mConnectionPages->addTab( page, identifier );
106
 
 
107
 
  mPageHash.insert( identifier, page );
108
 
}
109
 
 
110
 
void DebugWidget::connectionEnded( const QString &identifier, const QString& )
111
 
{
112
 
  if ( !mPageHash.contains( identifier ) )
113
 
    return;
114
 
 
115
 
  QWidget *widget = mPageHash[ identifier ];
116
 
 
117
 
  mConnectionPages->removeTab( mConnectionPages->indexOf( widget ) );
118
 
 
119
 
  mPageHash.remove( identifier );
120
 
  delete widget;
121
 
}
122
 
 
123
 
void DebugWidget::signalEmitted( const QString &signalName, const QString &msg )
124
 
{
125
 
  mGeneralView->append( QString( "<font color=\"green\">%1 ( %2 )</font>" ).arg( signalName, msg ) );
126
 
}
127
 
 
128
 
void DebugWidget::warningEmitted( const QString &componentName, const QString &msg )
129
 
{
130
 
  mGeneralView->append( QString( "<font color=\"blue\">%1: %2</font>" ).arg( componentName, msg ) );
131
 
}
132
 
 
133
 
void DebugWidget::errorEmitted( const QString &componentName, const QString &msg )
134
 
{
135
 
  mGeneralView->append( QString( "<font color=\"red\">%1: %2</font>" ).arg( componentName, msg ) );
136
 
}
137
 
 
138
 
void DebugWidget::enableDebugger(bool enable)
139
 
{
140
 
  mDebugInterface->setTracer( enable ? QLatin1String( "dbus" ) : QLatin1String( "null" ) );
141
 
}
142
 
 
143
 
#include "debugwidget.moc"