KDELibs4Support

kdebugdialog.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 1997 Matthias Kalle Dalheimer ([email protected])
3  Copyright (C) 1999 David Faure ([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 "kdebugdialog.h"
22 
23 #include <QLayout>
24 #include <QLineEdit>
25 #include <QComboBox>
26 #include <QLabel>
27 #include <QGroupBox>
28 #include <QCheckBox>
29 #include <QPushButton>
30 #include <QtDBus>
31 
32 #include <kdebug.h>
33 #include <kglobal.h>
34 #include <klocale.h>
35 #include <kdialog.h>
36 #include <kconfig.h>
37 #include <kseparator.h>
38 #include "ktreewidgetsearchline.h"
39 
40 KDebugDialog::KDebugDialog(const AreaMap& areaMap, QWidget* parent)
41  : KAbstractDebugDialog(parent)
42 {
43  setCaption(i18n("Debug Settings"));
44  setButtons(None);
45 
46  setupUi(mainWidget());
47  mainWidget()->layout()->setContentsMargins(0, 0, 0, 0);
48 
49  // Debug area tree
50  m_incrSearch->searchLine()->addTreeWidget(m_areaWidget);
51 
52  for( QMap<QString,QString>::const_iterator it = areaMap.begin(); it != areaMap.end(); ++it ) {
53  QTreeWidgetItem* item = new QTreeWidgetItem(m_areaWidget, QStringList() << it.value());
54  item->setData(0, Qt::UserRole, it.key().simplified());
55  }
56 
57  QStringList destList;
58  destList.append( i18n("File") );
59  destList.append( i18n("Message Box") );
60  destList.append( i18n("Shell") );
61  destList.append( i18n("Syslog") );
62  destList.append( i18n("None") );
63 
64  //
65  // Upper left frame
66  //
67  connect(pInfoCombo, SIGNAL(activated(int)),
68  this, SLOT(slotDestinationChanged()));
69  pInfoCombo->addItems( destList );
70 
71  //
72  // Upper right frame
73  //
74  connect(pWarnCombo, SIGNAL(activated(int)),
75  this, SLOT(slotDestinationChanged()));
76  pWarnCombo->addItems( destList );
77 
78  //
79  // Lower left frame
80  //
81  connect(pErrorCombo, SIGNAL(activated(int)),
82  this, SLOT(slotDestinationChanged()));
83  pErrorCombo->addItems( destList );
84 
85  //
86  // Lower right frame
87  //
88  connect(pFatalCombo, SIGNAL(activated(int)),
89  this, SLOT(slotDestinationChanged()));
90  pFatalCombo->addItems( destList );
91 
92  // Hack!
93  m_disableAll = m_disableAll2;
94  connect(m_disableAll, SIGNAL(toggled(bool)), this, SLOT(disableAllClicked()));
95 
96  showButtonSeparator(true);
97  buildButtons();
98 
99  connect( m_areaWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
100  SLOT(slotDebugAreaChanged(QTreeWidgetItem*)) );
101 
102  // Get initial values
103  showArea(QString("0"));
104 
105  load();
106 
107  resize(600, height());
108 }
109 
110 KDebugDialog::~KDebugDialog()
111 {
112 }
113 
114 void KDebugDialog::slotDebugAreaChanged(QTreeWidgetItem* item)
115 {
116  // Save settings from previous page
117  save();
118 
119  const QString areaName = item->data(0, Qt::UserRole).toString();
120  showArea(areaName);
121 }
122 
123 void KDebugDialog::showArea(const QString& areaName)
124 {
125  /* Fill dialog fields with values from config data */
126  mCurrentDebugArea = areaName;
127  KConfigGroup group = pConfig->group(areaName);
128  pInfoCombo->setCurrentIndex( group.readEntry( "InfoOutput", 2 ) );
129  pInfoFile->setText( group.readPathEntry( "InfoFilename","kdebug.dbg" ) );
130  //pInfoShow->setText( group.readEntry( "InfoShow" ) );
131  pWarnCombo->setCurrentIndex( group.readEntry( "WarnOutput", 2 ) );
132  pWarnFile->setText( group.readPathEntry( "WarnFilename","kdebug.dbg" ) );
133  //pWarnShow->setText( group.readEntry( "WarnShow" ) );
134  pErrorCombo->setCurrentIndex( group.readEntry( "ErrorOutput", 2 ) );
135  pErrorFile->setText( group.readPathEntry( "ErrorFilename","kdebug.dbg") );
136  //pErrorShow->setText( group.readEntry( "ErrorShow" ) );
137  pFatalCombo->setCurrentIndex( group.readEntry( "FatalOutput", 2 ) );
138  pFatalFile->setText( group.readPathEntry("FatalFilename","kdebug.dbg") );
139  //pFatalShow->setText( group.readEntry( "FatalShow" ) );
140  pAbortFatal->setChecked( group.readEntry( "AbortFatal", 1 ) );
141  slotDestinationChanged();
142 }
143 
144 void KDebugDialog::doSave()
145 {
146  KConfigGroup group = pConfig->group( mCurrentDebugArea ); // Group name = debug area code
147  group.writeEntry( "InfoOutput", pInfoCombo->currentIndex() );
148  group.writePathEntry( "InfoFilename", pInfoFile->text() );
149  //group.writeEntry( "InfoShow", pInfoShow->text() );
150  group.writeEntry( "WarnOutput", pWarnCombo->currentIndex() );
151  group.writePathEntry( "WarnFilename", pWarnFile->text() );
152  //group.writeEntry( "WarnShow", pWarnShow->text() );
153  group.writeEntry( "ErrorOutput", pErrorCombo->currentIndex() );
154  group.writePathEntry( "ErrorFilename", pErrorFile->text() );
155  //group.writeEntry( "ErrorShow", pErrorShow->text() );
156  group.writeEntry( "FatalOutput", pFatalCombo->currentIndex() );
157  group.writePathEntry( "FatalFilename", pFatalFile->text() );
158  //group.writeEntry( "FatalShow", pFatalShow->text() );
159  group.writeEntry( "AbortFatal", pAbortFatal->isChecked() );
160 
161  QDBusMessage msg = QDBusMessage::createSignal("/", "org.kde.KDebug", "configChanged");
162  if (!QDBusConnection::sessionBus().send(msg))
163  {
164  kError() << "Unable to send D-BUS message" << endl;
165  }
166 }
167 
168 void KDebugDialog::slotDestinationChanged()
169 {
170  pInfoFile->setEnabled(pInfoCombo->currentIndex() == 0);
171  pWarnFile->setEnabled(pWarnCombo->currentIndex() == 0);
172  pErrorFile->setEnabled(pErrorCombo->currentIndex() == 0);
173  pFatalFile->setEnabled(pFatalCombo->currentIndex() == 0);
174 }
175 
176 void KDebugDialog::disableAllClicked()
177 {
178  kDebug();
179  bool enabled = !m_disableAll->isChecked();
180  m_areaWidget->setEnabled(enabled);
181  pInfoGroup->setEnabled(enabled);
182  pWarnGroup->setEnabled(enabled);
183  pErrorGroup->setEnabled(enabled);
184  pFatalGroup->setEnabled(enabled);
185  pAbortFatal->setEnabled(enabled);
186 }
187 
QString readPathEntry(const QString &pKey, const QString &aDefault) const
void writePathEntry(const QString &pKey, const QString &path, WriteConfigFlags pFlags=Normal)
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
KDEGAMES_EXPORT QAction * load(const QObject *recvr, const char *slot, QObject *parent)
void append(const T &value)
QDBusMessage createSignal(const QString &path, const QString &interface, const QString &name)
UserRole
const QList< QKeySequence > & save()
QMap::iterator begin()
QString i18n(const char *text, const TYPE &arg...)
QString toString() const const
T readEntry(const QString &key, const T &aDefault) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jul 13 2020 22:58:30 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.