KDELibs4Support

klistdebugdialog.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2000 David Faure <[email protected]>
3  Copyright (C) 2005 Hamish Rodda <[email protected]>
4 
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.
9 
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.
14 
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.
19 */
20 
21 #include "klistdebugdialog.h"
22 
23 #include <kconfig.h>
24 #include <kdebug.h>
25 #include <klocale.h>
26 #include <ktreewidgetsearchline.h>
27 #include <ktreewidgetsearchlinewidget.h>
28 
29 #include <QtDBus>
30 #include <QLayout>
31 #include <QTreeWidget>
32 #include <QPushButton>
33 
34 KListDebugDialog::KListDebugDialog(const AreaMap& areaMap, QWidget *parent)
35  : KAbstractDebugDialog(parent)
36 {
37  setCaption(i18n("Debug Settings"));
38  QWidget* mainWidget = new QWidget( this );
39  QVBoxLayout *lay = new QVBoxLayout( mainWidget );
42 
43  m_incrSearch = new KTreeWidgetSearchLineWidget();
44  m_incrSearch->searchLine()->setClearButtonEnabled(true);
45  lay->addWidget( m_incrSearch );
46  // connect( m_incrSearch, SIGNAL(textChanged(QString)),
47  // SLOT(filterCheckBoxes(QString)) );
48 
49  //@TODO: Change back to QListWidget once Trolltech fixed the task: #214420
50  //See http://trolltech.com/developer/task-tracker/index_html?id=214420&method=entry
51  m_areaWidget = new QTreeWidget();
52  m_areaWidget->setHeaderHidden(true);
53  m_areaWidget->setItemsExpandable(false);
54  m_areaWidget->setRootIsDecorated(false);
55  m_areaWidget->setUniformRowHeights(true);
56  lay->addWidget(m_areaWidget);
57 
58  m_incrSearch->searchLine()->addTreeWidget(m_areaWidget);
59 
60  for( QMap<QString,QString>::const_iterator it = areaMap.begin(); it != areaMap.end(); ++it ) {
61  QTreeWidgetItem* item = new QTreeWidgetItem(m_areaWidget, QStringList() << it.value());
62  item->setData(0, Qt::UserRole, it.key().simplified());
63  }
64 
65  m_buttonContainer = new QWidget(mainWidget);
66  QHBoxLayout* selectButs = new QHBoxLayout(m_buttonContainer);
67  lay->addWidget(m_buttonContainer);
68  QPushButton* all = new QPushButton(i18n("&Select All"), m_buttonContainer);
69  QPushButton* none = new QPushButton(i18n("&Deselect All"), m_buttonContainer);
70  selectButs->addWidget( all );
71  selectButs->addWidget( none );
72 
73  connect( all, SIGNAL(clicked()), this, SLOT(selectAll()) );
74  connect( none, SIGNAL(clicked()), this, SLOT(deSelectAll()) );
75 
76  m_disableAll = new QCheckBox(mainWidget);
77  m_disableAll->setText(i18n("Disable all debug output"));
78  connect(m_disableAll, SIGNAL(toggled(bool)), this, SLOT(disableAllClicked()));
79  lay->addWidget(m_disableAll);
80 
81  load();
82 
83  buildButtons();
84  resize( 350, 400 );
85  setMainWidget( mainWidget );
86  m_incrSearch->searchLine()->setFocus();
87 }
88 
89 void KListDebugDialog::selectAll()
90 {
91  for (int i = 0; i < m_areaWidget->topLevelItemCount(); ++i) {
92  QTreeWidgetItem* item = m_areaWidget->topLevelItem(i);
93  if (!m_areaWidget->isItemHidden(item)) {
94  item->setCheckState(0, Qt::Checked);
95  }
96  }
97 }
98 
99 void KListDebugDialog::deSelectAll()
100 {
101  for (int i = 0; i < m_areaWidget->topLevelItemCount(); ++i) {
102  QTreeWidgetItem* item = m_areaWidget->topLevelItem(i);
103  if (!m_areaWidget->isItemHidden(item)) {
104  item->setCheckState(0, Qt::Unchecked);
105  }
106  }
107 }
108 
109 void KListDebugDialog::doLoad()
110 {
111  for (int i = 0; i < m_areaWidget->topLevelItemCount(); ++i) {
112  QTreeWidgetItem* item = m_areaWidget->topLevelItem(i);
113  KConfigGroup group = pConfig->group( item->data(0, Qt::UserRole).toByteArray() ); // Group name = debug area code = cb's name
114 
115  int setting = group.readEntry("InfoOutput", -1);
116 
117  switch (setting) {
118  case 4: // off
119  item->setCheckState(0, Qt::Unchecked);
120  break;
121  case -1: // default
122  case 2: //shell
123  item->setCheckState(0, Qt::Checked);
124  break;
125  case 3: //syslog
126  case 1: //msgbox
127  case 0: //file
128  default:
131  break;
132  }
133  }
134 }
135 
136 void KListDebugDialog::doSave()
137 {
138  for (int i = 0; i < m_areaWidget->topLevelItemCount(); ++i) {
139  QTreeWidgetItem* item = m_areaWidget->topLevelItem(i);
140  KConfigGroup group = pConfig->group( item->data(0, Qt::UserRole).toByteArray() ); // Group name = debug area code = cb's name
141  if (item->checkState(0) != Qt::PartiallyChecked)
142  {
143  int setting = (item->checkState(0) == Qt::Checked) ? 2 : 4;
144  group.writeEntry( "InfoOutput", setting );
145  }
146  }
147  //sync done by main.cpp
148 
149  // send DBus message to all clients
150  QDBusMessage msg = QDBusMessage::createSignal("/", "org.kde.KDebug", "configChanged" );
151  if (!QDBusConnection::sessionBus().send(msg))
152  {
153  kError() << "Unable to send D-BUS message" << endl;
154  }
155 }
156 
157 void KListDebugDialog::activateArea( const QByteArray& area, bool activate )
158 {
159  foreach(QTreeWidgetItem* item, m_areaWidget->findItems(area, Qt::MatchContains)) {
160  item->setCheckState( 0, activate ? Qt::Checked : Qt::Unchecked );
161  return;
162  }
163 }
164 
165 void KListDebugDialog::disableAllClicked()
166 {
167  bool allDisabled = m_disableAll->isChecked();
168  m_incrSearch->setEnabled(!allDisabled);
169  m_areaWidget->setEnabled(!allDisabled);
170  m_buttonContainer->setEnabled(!allDisabled);
171 }
172 
static int marginHint()
Returns the number of pixels that should be used between a dialog edge and the outermost widget(s) ac...
Definition: kdialog.cpp:459
QByteArray toByteArray() const const
Qt::CheckState checkState(int column) const const
MatchContains
Definition: netaccess.h:36
KConfigGroup group(const QByteArray &group)
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
virtual void setData(int column, int role, const QVariant &value)
QTextStream & endl(QTextStream &stream)
QDBusConnection sessionBus()
virtual QVariant data(int column, int role) const const
T value(int i) const const
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
static int spacingHint()
Returns the number of pixels that should be used between widgets inside a dialog according to the KDE...
Definition: kdialog.cpp:464
QDBusMessage createSignal(const QString &path, const QString &interface, const QString &name)
UserRole
QMap::iterator begin()
bool load()
QString i18n(const char *text, const TYPE &arg...)
void setCheckState(int column, Qt::CheckState state)
const QList< QKeySequence > & selectAll()
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setMargin(int margin)
T readEntry(const QString &key, const T &aDefault) const
void setSpacing(int spacing)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jul 3 2020 22:57:53 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.