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) |
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/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 | |
39 | KDebugDialog::KDebugDialog(const AreaMap& areaMap, QWidget* parent) |
40 | : KAbstractDebugDialog(parent) |
41 | { |
42 | setCaption(i18n("Debug Settings" )); |
43 | setButtons(None); |
44 | |
45 | setupUi(mainWidget()); |
46 | mainWidget()->layout()->setContentsMargins(0, 0, 0, 0); |
47 | |
48 | // Debug area tree |
49 | m_incrSearch->searchLine()->addTreeWidget(m_areaWidget); |
50 | |
51 | for( QMap<QString,QString>::const_iterator it = areaMap.begin(); it != areaMap.end(); ++it ) { |
52 | QTreeWidgetItem* item = new QTreeWidgetItem(m_areaWidget, QStringList() << it.value()); |
53 | item->setData(0, Qt::UserRole, it.key().simplified()); |
54 | } |
55 | |
56 | QStringList destList; |
57 | destList.append( i18n("File" ) ); |
58 | destList.append( i18n("Message Box" ) ); |
59 | destList.append( i18n("Shell" ) ); |
60 | destList.append( i18n("Syslog" ) ); |
61 | destList.append( i18n("None" ) ); |
62 | |
63 | // |
64 | // Upper left frame |
65 | // |
66 | connect(pInfoCombo, SIGNAL(activated(int)), |
67 | this, SLOT(slotDestinationChanged())); |
68 | pInfoCombo->addItems( destList ); |
69 | |
70 | // |
71 | // Upper right frame |
72 | // |
73 | connect(pWarnCombo, SIGNAL(activated(int)), |
74 | this, SLOT(slotDestinationChanged())); |
75 | pWarnCombo->addItems( destList ); |
76 | |
77 | // |
78 | // Lower left frame |
79 | // |
80 | connect(pErrorCombo, SIGNAL(activated(int)), |
81 | this, SLOT(slotDestinationChanged())); |
82 | pErrorCombo->addItems( destList ); |
83 | |
84 | // |
85 | // Lower right frame |
86 | // |
87 | connect(pFatalCombo, SIGNAL(activated(int)), |
88 | this, SLOT(slotDestinationChanged())); |
89 | pFatalCombo->addItems( destList ); |
90 | |
91 | // Hack! |
92 | m_disableAll = m_disableAll2; |
93 | connect(m_disableAll, SIGNAL(toggled(bool)), this, SLOT(disableAllClicked())); |
94 | |
95 | showButtonSeparator(true); |
96 | buildButtons(); |
97 | |
98 | connect( m_areaWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), |
99 | SLOT(slotDebugAreaChanged(QTreeWidgetItem*)) ); |
100 | |
101 | // Get initial values |
102 | showArea(QString("0" )); |
103 | |
104 | load(); |
105 | |
106 | resize(600, height()); |
107 | } |
108 | |
109 | KDebugDialog::~KDebugDialog() |
110 | { |
111 | } |
112 | |
113 | void KDebugDialog::slotDebugAreaChanged(QTreeWidgetItem* item) |
114 | { |
115 | // Save settings from previous page |
116 | save(); |
117 | |
118 | const QString areaName = item->data(0, Qt::UserRole).toString(); |
119 | showArea(areaName); |
120 | } |
121 | |
122 | void KDebugDialog::showArea(const QString& areaName) |
123 | { |
124 | /* Fill dialog fields with values from config data */ |
125 | mCurrentDebugArea = areaName; |
126 | KConfigGroup group = pConfig->group(areaName); |
127 | pInfoCombo->setCurrentIndex( group.readEntry( "InfoOutput" , 2 ) ); |
128 | pInfoFile->setText( group.readPathEntry( "InfoFilename" ,"kdebug.dbg" ) ); |
129 | //pInfoShow->setText( group.readEntry( "InfoShow" ) ); |
130 | pWarnCombo->setCurrentIndex( group.readEntry( "WarnOutput" , 2 ) ); |
131 | pWarnFile->setText( group.readPathEntry( "WarnFilename" ,"kdebug.dbg" ) ); |
132 | //pWarnShow->setText( group.readEntry( "WarnShow" ) ); |
133 | pErrorCombo->setCurrentIndex( group.readEntry( "ErrorOutput" , 2 ) ); |
134 | pErrorFile->setText( group.readPathEntry( "ErrorFilename" ,"kdebug.dbg" ) ); |
135 | //pErrorShow->setText( group.readEntry( "ErrorShow" ) ); |
136 | pFatalCombo->setCurrentIndex( group.readEntry( "FatalOutput" , 2 ) ); |
137 | pFatalFile->setText( group.readPathEntry("FatalFilename" ,"kdebug.dbg" ) ); |
138 | //pFatalShow->setText( group.readEntry( "FatalShow" ) ); |
139 | pAbortFatal->setChecked( group.readEntry( "AbortFatal" , 1 ) ); |
140 | slotDestinationChanged(); |
141 | } |
142 | |
143 | void KDebugDialog::doSave() |
144 | { |
145 | KConfigGroup group = pConfig->group( mCurrentDebugArea ); // Group name = debug area code |
146 | group.writeEntry( "InfoOutput" , pInfoCombo->currentIndex() ); |
147 | group.writePathEntry( "InfoFilename" , pInfoFile->text() ); |
148 | //group.writeEntry( "InfoShow", pInfoShow->text() ); |
149 | group.writeEntry( "WarnOutput" , pWarnCombo->currentIndex() ); |
150 | group.writePathEntry( "WarnFilename" , pWarnFile->text() ); |
151 | //group.writeEntry( "WarnShow", pWarnShow->text() ); |
152 | group.writeEntry( "ErrorOutput" , pErrorCombo->currentIndex() ); |
153 | group.writePathEntry( "ErrorFilename" , pErrorFile->text() ); |
154 | //group.writeEntry( "ErrorShow", pErrorShow->text() ); |
155 | group.writeEntry( "FatalOutput" , pFatalCombo->currentIndex() ); |
156 | group.writePathEntry( "FatalFilename" , pFatalFile->text() ); |
157 | //group.writeEntry( "FatalShow", pFatalShow->text() ); |
158 | group.writeEntry( "AbortFatal" , pAbortFatal->isChecked() ); |
159 | |
160 | QDBusMessage msg = QDBusMessage::createSignal("/" , "org.kde.KDebug" , "configChanged" ); |
161 | if (!QDBusConnection::sessionBus().send(msg)) |
162 | { |
163 | kError() << "Unable to send D-BUS message" << endl; |
164 | } |
165 | } |
166 | |
167 | void KDebugDialog::slotDestinationChanged() |
168 | { |
169 | pInfoFile->setEnabled(pInfoCombo->currentIndex() == 0); |
170 | pWarnFile->setEnabled(pWarnCombo->currentIndex() == 0); |
171 | pErrorFile->setEnabled(pErrorCombo->currentIndex() == 0); |
172 | pFatalFile->setEnabled(pFatalCombo->currentIndex() == 0); |
173 | } |
174 | |
175 | void KDebugDialog::disableAllClicked() |
176 | { |
177 | kDebug(); |
178 | bool enabled = !m_disableAll->isChecked(); |
179 | m_areaWidget->setEnabled(enabled); |
180 | pInfoGroup->setEnabled(enabled); |
181 | pWarnGroup->setEnabled(enabled); |
182 | pErrorGroup->setEnabled(enabled); |
183 | pFatalGroup->setEnabled(enabled); |
184 | pAbortFatal->setEnabled(enabled); |
185 | } |
186 | |
187 | #include "kdebugdialog.moc" |
188 | |