File indexing completed on 2024-04-21 14:55:21
0001 /* This file is part of the KDE libraries 0002 Copyright (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org) 0003 Copyright (C) 1999 David Faure (faure@kde.org) 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License as published by the Free Software Foundation; either 0008 version 2 of the License, or (at your option) any later version. 0009 0010 This library is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this library; see the file COPYING.LIB. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #include "kdebugdialog.h" 0022 0023 #include <QDBusConnection> 0024 #include <QDBusMessage> 0025 #include <QLayout> 0026 #include <QLineEdit> 0027 #include <QComboBox> 0028 #include <QLabel> 0029 #include <QGroupBox> 0030 #include <QCheckBox> 0031 #include <QPushButton> 0032 0033 #include <kdebug.h> 0034 #include <kglobal.h> 0035 #include <klocale.h> 0036 #include <kdialog.h> 0037 #include <kconfig.h> 0038 #include <kseparator.h> 0039 #include "ktreewidgetsearchline.h" 0040 0041 KDebugDialog::KDebugDialog(const AreaMap& areaMap, QWidget* parent) 0042 : KAbstractDebugDialog(parent) 0043 { 0044 setCaption(i18n("Debug Settings")); 0045 setButtons(None); 0046 0047 setupUi(mainWidget()); 0048 mainWidget()->layout()->setContentsMargins(0, 0, 0, 0); 0049 0050 // Debug area tree 0051 m_incrSearch->searchLine()->addTreeWidget(m_areaWidget); 0052 0053 for( QMap<QString,QString>::const_iterator it = areaMap.begin(); it != areaMap.end(); ++it ) { 0054 QTreeWidgetItem* item = new QTreeWidgetItem(m_areaWidget, QStringList() << it.value()); 0055 item->setData(0, Qt::UserRole, it.key().simplified()); 0056 } 0057 0058 QStringList destList; 0059 destList.append( i18n("File") ); 0060 destList.append( i18n("Message Box") ); 0061 destList.append( i18n("Shell") ); 0062 destList.append( i18n("Syslog") ); 0063 destList.append( i18n("None") ); 0064 0065 // 0066 // Upper left frame 0067 // 0068 connect(pInfoCombo, SIGNAL(activated(int)), 0069 this, SLOT(slotDestinationChanged())); 0070 pInfoCombo->addItems( destList ); 0071 0072 // 0073 // Upper right frame 0074 // 0075 connect(pWarnCombo, SIGNAL(activated(int)), 0076 this, SLOT(slotDestinationChanged())); 0077 pWarnCombo->addItems( destList ); 0078 0079 // 0080 // Lower left frame 0081 // 0082 connect(pErrorCombo, SIGNAL(activated(int)), 0083 this, SLOT(slotDestinationChanged())); 0084 pErrorCombo->addItems( destList ); 0085 0086 // 0087 // Lower right frame 0088 // 0089 connect(pFatalCombo, SIGNAL(activated(int)), 0090 this, SLOT(slotDestinationChanged())); 0091 pFatalCombo->addItems( destList ); 0092 0093 // Hack! 0094 m_disableAll = m_disableAll2; 0095 connect(m_disableAll, SIGNAL(toggled(bool)), this, SLOT(disableAllClicked())); 0096 0097 showButtonSeparator(true); 0098 buildButtons(); 0099 0100 connect( m_areaWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), 0101 SLOT(slotDebugAreaChanged(QTreeWidgetItem*)) ); 0102 0103 // Get initial values 0104 showArea(QString("0")); 0105 0106 load(); 0107 0108 resize(600, height()); 0109 } 0110 0111 KDebugDialog::~KDebugDialog() 0112 { 0113 } 0114 0115 void KDebugDialog::slotDebugAreaChanged(QTreeWidgetItem* item) 0116 { 0117 // Save settings from previous page 0118 save(); 0119 0120 const QString areaName = item->data(0, Qt::UserRole).toString(); 0121 showArea(areaName); 0122 } 0123 0124 void KDebugDialog::showArea(const QString& areaName) 0125 { 0126 /* Fill dialog fields with values from config data */ 0127 mCurrentDebugArea = areaName; 0128 KConfigGroup group = pConfig->group(areaName); 0129 pInfoCombo->setCurrentIndex( group.readEntry( "InfoOutput", 2 ) ); 0130 pInfoFile->setText( group.readPathEntry( "InfoFilename","kdebug.dbg" ) ); 0131 //pInfoShow->setText( group.readEntry( "InfoShow" ) ); 0132 pWarnCombo->setCurrentIndex( group.readEntry( "WarnOutput", 2 ) ); 0133 pWarnFile->setText( group.readPathEntry( "WarnFilename","kdebug.dbg" ) ); 0134 //pWarnShow->setText( group.readEntry( "WarnShow" ) ); 0135 pErrorCombo->setCurrentIndex( group.readEntry( "ErrorOutput", 2 ) ); 0136 pErrorFile->setText( group.readPathEntry( "ErrorFilename","kdebug.dbg") ); 0137 //pErrorShow->setText( group.readEntry( "ErrorShow" ) ); 0138 pFatalCombo->setCurrentIndex( group.readEntry( "FatalOutput", 2 ) ); 0139 pFatalFile->setText( group.readPathEntry("FatalFilename","kdebug.dbg") ); 0140 //pFatalShow->setText( group.readEntry( "FatalShow" ) ); 0141 pAbortFatal->setChecked( group.readEntry( "AbortFatal", 1 ) ); 0142 slotDestinationChanged(); 0143 } 0144 0145 void KDebugDialog::doSave() 0146 { 0147 KConfigGroup group = pConfig->group( mCurrentDebugArea ); // Group name = debug area code 0148 group.writeEntry( "InfoOutput", pInfoCombo->currentIndex() ); 0149 group.writePathEntry( "InfoFilename", pInfoFile->text() ); 0150 //group.writeEntry( "InfoShow", pInfoShow->text() ); 0151 group.writeEntry( "WarnOutput", pWarnCombo->currentIndex() ); 0152 group.writePathEntry( "WarnFilename", pWarnFile->text() ); 0153 //group.writeEntry( "WarnShow", pWarnShow->text() ); 0154 group.writeEntry( "ErrorOutput", pErrorCombo->currentIndex() ); 0155 group.writePathEntry( "ErrorFilename", pErrorFile->text() ); 0156 //group.writeEntry( "ErrorShow", pErrorShow->text() ); 0157 group.writeEntry( "FatalOutput", pFatalCombo->currentIndex() ); 0158 group.writePathEntry( "FatalFilename", pFatalFile->text() ); 0159 //group.writeEntry( "FatalShow", pFatalShow->text() ); 0160 group.writeEntry( "AbortFatal", pAbortFatal->isChecked() ); 0161 0162 QDBusMessage msg = QDBusMessage::createSignal("/", "org.kde.KDebug", "configChanged"); 0163 if (!QDBusConnection::sessionBus().send(msg)) 0164 { 0165 kError() << "Unable to send D-BUS message" << endl; 0166 } 0167 } 0168 0169 void KDebugDialog::slotDestinationChanged() 0170 { 0171 pInfoFile->setEnabled(pInfoCombo->currentIndex() == 0); 0172 pWarnFile->setEnabled(pWarnCombo->currentIndex() == 0); 0173 pErrorFile->setEnabled(pErrorCombo->currentIndex() == 0); 0174 pFatalFile->setEnabled(pFatalCombo->currentIndex() == 0); 0175 } 0176 0177 void KDebugDialog::disableAllClicked() 0178 { 0179 kDebug(); 0180 bool enabled = !m_disableAll->isChecked(); 0181 m_areaWidget->setEnabled(enabled); 0182 pInfoGroup->setEnabled(enabled); 0183 pWarnGroup->setEnabled(enabled); 0184 pErrorGroup->setEnabled(enabled); 0185 pFatalGroup->setEnabled(enabled); 0186 pAbortFatal->setEnabled(enabled); 0187 } 0188 0189 #include "moc_kdebugdialog.cpp"