1 /* This file is part of the KDE libraries
2 Copyright (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org)
3 Copyright (C) 1999 David Faure (faure@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.
27 #include <QPushButton>
28 #include <QtDBus/QtDBus>
34 #include <kseparator.h>
35 #include <kapplication.h>
37 #include "kdebugdialog.h"
39 KDebugDialog::KDebugDialog( QStringList areaList
, QWidget
*parent
, const char *name
, bool modal
)
40 : KAbstractDebugDialog( parent
, name
, modal
)
42 setCaption(i18n("Debug Settings"));
44 QWidget
* mainWidget
= new QWidget( this );
45 QVBoxLayout
*topLayout
= new QVBoxLayout( mainWidget
);
46 topLayout
->setMargin( KDialog::marginHint() );
47 topLayout
->setSpacing( KDialog::spacingHint() );
48 setLayout( topLayout
);
50 QLabel
* tmpLabel
= new QLabel( i18n("Debug area:"), this );
51 tmpLabel
->setFixedHeight( fontMetrics().lineSpacing() );
52 topLayout
->addWidget( tmpLabel
);
54 // Build combo of debug areas
55 pDebugAreas
= new QComboBox( this );
56 pDebugAreas
->setEditable( false );
57 pDebugAreas
->setFixedHeight( pDebugAreas
->sizeHint().height() );
58 pDebugAreas
->addItems( areaList
);
59 topLayout
->addWidget( pDebugAreas
);
61 QGridLayout
*gbox
= new QGridLayout();
62 gbox
->setMargin( KDialog::marginHint() );
63 topLayout
->addLayout( gbox
);
66 destList
.append( i18n("File") );
67 destList
.append( i18n("Message Box") );
68 destList
.append( i18n("Shell") );
69 destList
.append( i18n("Syslog") );
70 destList
.append( i18n("None") );
75 pInfoGroup
= new QGroupBox( i18n("Information"), this );
76 gbox
->addWidget( pInfoGroup
, 0, 0 );
77 QVBoxLayout
*vbox
= new QVBoxLayout( pInfoGroup
);
78 vbox
->setSpacing( KDialog::spacingHint() );
79 vbox
->addSpacing( fontMetrics().lineSpacing() );
80 pInfoLabel1
= new QLabel( i18n("Output to:"), pInfoGroup
);
81 vbox
->addWidget( pInfoLabel1
);
82 pInfoCombo
= new QComboBox( pInfoGroup
);
83 pInfoCombo
->setEditable( false );
84 connect(pInfoCombo
, SIGNAL(activated(int)),
85 this, SLOT(slotDestinationChanged(int)));
86 vbox
->addWidget( pInfoCombo
);
87 pInfoCombo
->addItems( destList
);
88 pInfoLabel2
= new QLabel( i18n("Filename:"), pInfoGroup
);
89 vbox
->addWidget( pInfoLabel2
);
90 pInfoFile
= new QLineEdit( pInfoGroup
);
91 vbox
->addWidget( pInfoFile
);
93 pInfoLabel3 = new QLabel( i18n("Show only area(s):"), pInfoGroup );
94 vbox->addWidget( pInfoLabel3 );
95 pInfoShow = new QLineEdit( pInfoGroup );
96 vbox->addWidget( pInfoShow );
102 pWarnGroup
= new QGroupBox( i18n("Warning"), this );
103 gbox
->addWidget( pWarnGroup
, 0, 1 );
104 vbox
= new QVBoxLayout( pWarnGroup
);
105 vbox
->setSpacing( KDialog::spacingHint() );
106 vbox
->addSpacing( fontMetrics().lineSpacing() );
107 pWarnLabel1
= new QLabel( i18n("Output to:"), pWarnGroup
);
108 vbox
->addWidget( pWarnLabel1
);
109 pWarnCombo
= new QComboBox( pWarnGroup
);
110 pWarnCombo
->setEditable( false );
111 connect(pWarnCombo
, SIGNAL(activated(int)),
112 this, SLOT(slotDestinationChanged(int)));
113 vbox
->addWidget( pWarnCombo
);
114 pWarnCombo
->addItems( destList
);
115 pWarnLabel2
= new QLabel( i18n("Filename:"), pWarnGroup
);
116 vbox
->addWidget( pWarnLabel2
);
117 pWarnFile
= new QLineEdit( pWarnGroup
);
118 vbox
->addWidget( pWarnFile
);
120 pWarnLabel3 = new QLabel( i18n("Show only area(s):"), pWarnGroup );
121 vbox->addWidget( pWarnLabel3 );
122 pWarnShow = new QLineEdit( pWarnGroup );
123 vbox->addWidget( pWarnShow );
129 pErrorGroup
= new QGroupBox( i18n("Error"), this );
130 gbox
->addWidget( pErrorGroup
, 1, 0 );
131 vbox
= new QVBoxLayout( pErrorGroup
);
132 vbox
->setSpacing( KDialog::spacingHint() );
133 vbox
->addSpacing( fontMetrics().lineSpacing() );
134 pErrorLabel1
= new QLabel( i18n("Output to:"), pErrorGroup
);
135 vbox
->addWidget( pErrorLabel1
);
136 pErrorCombo
= new QComboBox( pErrorGroup
);
137 pErrorCombo
->setEditable( false );
138 connect(pErrorCombo
, SIGNAL(activated(int)),
139 this, SLOT(slotDestinationChanged(int)));
140 vbox
->addWidget( pErrorCombo
);
141 pErrorCombo
->addItems( destList
);
142 pErrorLabel2
= new QLabel( i18n("Filename:"), pErrorGroup
);
143 vbox
->addWidget( pErrorLabel2
);
144 pErrorFile
= new QLineEdit( pErrorGroup
);
145 vbox
->addWidget( pErrorFile
);
147 pErrorLabel3 = new QLabel( i18n("Show only area(s):"), pErrorGroup );
148 vbox->addWidget( pErrorLabel3 );
149 pErrorShow = new QLineEdit( pErrorGroup );
150 vbox->addWidget( pErrorShow );
156 pFatalGroup
= new QGroupBox( i18n("Fatal Error"), this );
157 gbox
->addWidget( pFatalGroup
, 1, 1 );
158 vbox
= new QVBoxLayout( pFatalGroup
);
159 vbox
->setSpacing( KDialog::spacingHint() );
160 vbox
->addSpacing( fontMetrics().lineSpacing() );
161 pFatalLabel1
= new QLabel( i18n("Output to:"), pFatalGroup
);
162 vbox
->addWidget( pFatalLabel1
);
163 pFatalCombo
= new QComboBox( pFatalGroup
);
164 pFatalCombo
->setEditable( false );
165 connect(pFatalCombo
, SIGNAL(activated(int)),
166 this, SLOT(slotDestinationChanged(int)));
167 vbox
->addWidget( pFatalCombo
);
168 pFatalCombo
->addItems( destList
);
169 pFatalLabel2
= new QLabel( i18n("Filename:"), pFatalGroup
);
170 vbox
->addWidget( pFatalLabel2
);
171 pFatalFile
= new QLineEdit( pFatalGroup
);
172 vbox
->addWidget( pFatalFile
);
174 pFatalLabel3 = new QLabel( i18n("Show only area(s):"), pFatalGroup );
175 vbox->addWidget( pFatalLabel3 );
176 pFatalShow = new QLineEdit( pFatalGroup );
177 vbox->addWidget( pFatalShow );
181 pAbortFatal
= new QCheckBox( i18n("Abort on fatal errors"), this );
182 topLayout
->addWidget(pAbortFatal
);
184 topLayout
->addStretch();
185 KSeparator
*hline
= new KSeparator( Qt::Horizontal
, this );
186 topLayout
->addWidget( hline
);
188 buildButtons( topLayout
);
190 connect( pDebugAreas
, SIGNAL( activated( const QString
&) ),
191 SLOT( slotDebugAreaChanged( const QString
& ) ) );
193 // Get initial values ("initial" is understood by the slot)
194 slotDebugAreaChanged( "0 initial" );
195 slotDestinationChanged(0);
197 resize( 300, height() );
198 setMainWidget( mainWidget
);
201 KDebugDialog::~KDebugDialog()
205 void KDebugDialog::slotDebugAreaChanged( const QString
& text
)
207 // Save settings from previous page
208 if ( text
!= "0 initial" ) // except on first call
211 QString data
= text
.simplified();
212 int space
= data
.indexOf(" ");
214 kError() << "No space:" << data
<< endl
;
217 unsigned long number
= data
.left(space
).toULong(&longOK
);
219 kError() << "The first part wasn't a number : " << data
<< endl
;
221 /* Fill dialog fields with values from config data */
222 mCurrentDebugArea
= number
;
223 KConfigGroup group
= pConfig
->group( QString::number( number
) ); // Group name = debug area code
224 pInfoCombo
->setCurrentIndex( group
.readEntry( "InfoOutput", 2 ) );
225 pInfoFile
->setText( group
.readPathEntry( "InfoFilename","kdebug.dbg" ) );
226 //pInfoShow->setText( group.readEntry( "InfoShow" ) );
227 pWarnCombo
->setCurrentIndex( group
.readEntry( "WarnOutput", 2 ) );
228 pWarnFile
->setText( group
.readPathEntry( "WarnFilename","kdebug.dbg" ) );
229 //pWarnShow->setText( group.readEntry( "WarnShow" ) );
230 pErrorCombo
->setCurrentIndex( group
.readEntry( "ErrorOutput", 2 ) );
231 pErrorFile
->setText( group
.readPathEntry( "ErrorFilename","kdebug.dbg") );
232 //pErrorShow->setText( group.readEntry( "ErrorShow" ) );
233 pFatalCombo
->setCurrentIndex( group
.readEntry( "FatalOutput", 2 ) );
234 pFatalFile
->setText( group
.readPathEntry("FatalFilename","kdebug.dbg") );
235 //pFatalShow->setText( group.readEntry( "FatalShow" ) );
236 pAbortFatal
->setChecked( group
.readEntry( "AbortFatal", 1 ) );
237 slotDestinationChanged(0);
240 void KDebugDialog::save()
242 KConfigGroup group
= pConfig
->group( QString::number( mCurrentDebugArea
) ); // Group name = debug area code
243 group
.writeEntry( "InfoOutput", pInfoCombo
->currentIndex() );
244 group
.writePathEntry( "InfoFilename", pInfoFile
->text() );
245 //group.writeEntry( "InfoShow", pInfoShow->text() );
246 group
.writeEntry( "WarnOutput", pWarnCombo
->currentIndex() );
247 group
.writePathEntry( "WarnFilename", pWarnFile
->text() );
248 //group.writeEntry( "WarnShow", pWarnShow->text() );
249 group
.writeEntry( "ErrorOutput", pErrorCombo
->currentIndex() );
250 group
.writePathEntry( "ErrorFilename", pErrorFile
->text() );
251 //group.writeEntry( "ErrorShow", pErrorShow->text() );
252 group
.writeEntry( "FatalOutput", pFatalCombo
->currentIndex() );
253 group
.writePathEntry( "FatalFilename", pFatalFile
->text() );
254 //group.writeEntry( "FatalShow", pFatalShow->text() );
255 group
.writeEntry( "AbortFatal", pAbortFatal
->isChecked() );
257 QDBusMessage msg
= QDBusMessage::createSignal("/", "org.kde.KDebug", "configChanged");
258 if (!QDBusConnection::sessionBus().send(msg
))
260 kError() << "Unable to send D-BUS message" << endl
;
264 void KDebugDialog::slotDestinationChanged(int) {
265 pInfoFile
->setEnabled(pInfoCombo
->currentIndex() == 0);
266 pWarnFile
->setEnabled(pWarnCombo
->currentIndex() == 0);
267 pErrorFile
->setEnabled(pErrorCombo
->currentIndex() == 0);
268 pFatalFile
->setEnabled(pFatalCombo
->currentIndex() == 0);
271 #include "kdebugdialog.moc"