1 /* This file is part of the KDE libraries
2 Copyright (C) 2000 David Faure <faure@kde.org>
3 Copyright (C) 2005 Hamish Rodda <rodda@kde.org>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 #include "klistdebugdialog.h"
24 #include <kapplication.h>
27 #include <ktreewidgetsearchline.h>
29 #include <QtDBus/QtDBus>
31 #include <QTreeWidget>
32 #include <QPushButton>
34 KListDebugDialog::KListDebugDialog( QStringList areaList
, QWidget
*parent
, const char *name
, bool modal
)
35 : KAbstractDebugDialog( parent
, name
, modal
),
36 m_areaList( areaList
)
38 setCaption(i18n("Debug Settings"));
39 QWidget
* mainWidget
= new QWidget( this );
40 QVBoxLayout
*lay
= new QVBoxLayout( mainWidget
);
41 lay
->setMargin( KDialog::marginHint() );
42 lay
->setSpacing( KDialog::spacingHint() );
44 m_incrSearch
= new KTreeWidgetSearchLineWidget();
45 m_incrSearch
->searchLine()->setClearButtonShown(true);
46 lay
->addWidget( m_incrSearch
);
47 // connect( m_incrSearch, SIGNAL( textChanged( const QString& ) ),
48 // SLOT( filterCheckBoxes( const QString& ) ) );
50 //@TODO: Change back to QListWidget once Trolltech fixed the task: #214420
51 //See http://trolltech.com/developer/task-tracker/index_html?id=214420&method=entry
52 m_areaWidget
= new QTreeWidget();
53 m_areaWidget
->setHeaderHidden(true);
54 m_areaWidget
->setItemsExpandable(false);
55 m_areaWidget
->setRootIsDecorated(false);
56 m_areaWidget
->setUniformRowHeights(true);
57 lay
->addWidget(m_areaWidget
);
59 m_incrSearch
->searchLine()->addTreeWidget(m_areaWidget
);
63 QHBoxLayout
* selectButs
= new QHBoxLayout();
64 lay
->addLayout( selectButs
);
65 QPushButton
* all
= new QPushButton( i18n("&Select All"));
66 QPushButton
* none
= new QPushButton( i18n("&Deselect All"));
67 selectButs
->addWidget( all
);
68 selectButs
->addWidget( none
);
70 connect( all
, SIGNAL( clicked() ), this, SLOT( selectAll() ) );
71 connect( none
, SIGNAL( clicked() ), this, SLOT( deSelectAll() ) );
75 setMainWidget( mainWidget
);
76 setButtons( KDialog::NoDefault
);
79 void KListDebugDialog::generateCheckBoxes()
81 foreach (const QString
& area
, m_areaList
) {
82 QString data
= area
.simplified();
83 int space
= data
.indexOf(" ");
85 kError() << "No space:" << data
<< endl
;
87 QTreeWidgetItem
* item
= new QTreeWidgetItem(m_areaWidget
, QStringList() << data
);
88 item
->setData(0, Qt::UserRole
, data
.left(space
).toLatin1());
94 void KListDebugDialog::selectAll()
96 for (int i
= 0; i
< m_areaWidget
->topLevelItemCount(); ++i
) {
97 QTreeWidgetItem
* item
= m_areaWidget
->topLevelItem(i
);
98 if (!m_areaWidget
->isItemHidden(item
)) {
99 item
->setCheckState(0, Qt::Checked
);
104 void KListDebugDialog::deSelectAll()
106 for (int i
= 0; i
< m_areaWidget
->topLevelItemCount(); ++i
) {
107 QTreeWidgetItem
* item
= m_areaWidget
->topLevelItem(i
);
108 if (!m_areaWidget
->isItemHidden(item
)) {
109 item
->setCheckState(0, Qt::Unchecked
);
114 void KListDebugDialog::load()
116 for (int i
= 0; i
< m_areaWidget
->topLevelItemCount(); ++i
) {
117 QTreeWidgetItem
* item
= m_areaWidget
->topLevelItem(i
);
118 KConfigGroup group
= pConfig
->group( item
->data(0, Qt::UserRole
).toByteArray() ); // Group name = debug area code = cb's name
120 int setting
= group
.readEntry( "InfoOutput", 2 );
124 item
->setCheckState(0, Qt::Unchecked
);
127 item
->setCheckState(0, Qt::Checked
);
133 item
->setCheckState(0, Qt::PartiallyChecked
);
134 /////// Uses the triState capability of checkboxes
140 void KListDebugDialog::save()
142 for (int i
= 0; i
< m_areaWidget
->topLevelItemCount(); ++i
) {
143 QTreeWidgetItem
* item
= m_areaWidget
->topLevelItem(i
);
144 KConfigGroup group
= pConfig
->group( item
->data(0, Qt::UserRole
).toByteArray() ); // Group name = debug area code = cb's name
145 if (item
->checkState(0) != Qt::PartiallyChecked
)
147 int setting
= (item
->checkState(0) == Qt::Checked
) ? 2 : 4;
148 group
.writeEntry( "InfoOutput", setting
);
151 //sync done by main.cpp
153 // send DBus message to all clients
154 QDBusMessage msg
= QDBusMessage::createSignal("/", "org.kde.KDebug", "configChanged" );
155 if (!QDBusConnection::sessionBus().send(msg
))
157 kError() << "Unable to send D-BUS message" << endl
;
161 void KListDebugDialog::activateArea( QByteArray area
, bool activate
)
163 foreach(QTreeWidgetItem
* item
, m_areaWidget
->findItems(area
, Qt::MatchContains
)) {
164 item
->setCheckState( 0, activate
? Qt::Checked
: Qt::Unchecked
);
169 #include "klistdebugdialog.moc"