File indexing completed on 2024-05-05 04:39:52

0001 /*
0002     SPDX-FileCopyrightText: 2006 Vladimir Prus <ghost@cs.msu.su>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "debuggertracingdialog.h"
0008 #include "breakpoint.h"
0009 
0010 #include <KEditListBox>
0011 #include <KMessageBox>
0012 
0013 /* WARNING: this code was not yet ported to KDevelop4 and is unused, but is 
0014    intended to be ported.  */
0015 
0016 using namespace KDevMI::GDB;
0017 
0018 DebuggerTracingDialog
0019 ::DebuggerTracingDialog(Breakpoint* bp,
0020                         QWidget* parent)
0021 : QDialog(parent), bp_(bp)
0022 {
0023     setupUi(this);
0024 
0025     expressions->setButtons(KEditListBox::Add | KEditListBox::Remove);
0026 
0027     connect(enable, SIGNAL(stateChanged(int)),
0028             this, SLOT(enableOrDisable(int)));
0029 
0030     connect(enableCustomFormat, SIGNAL(stateChanged(int)),
0031             this, SLOT(enableOrDisableCustomFormat(int)));
0032 
0033     enable->setChecked(bp_->tracingEnabled());
0034     expressions->setItems(bp_->tracedExpressions());
0035     enableCustomFormat->setChecked(bp_->traceFormatStringEnabled());
0036     customFormat->setText(bp_->traceFormatString());
0037 
0038     enableOrDisable(enable->isChecked());
0039 
0040     // Go away if the breakpoint does
0041     connect(bp_, SIGNAL(destroyed(QObject*)), this, SLOT(reject()));
0042 }
0043 
0044 void DebuggerTracingDialog::enableOrDisable(int state)
0045 {
0046     bool enable = (state == Qt::Checked);
0047 
0048     expressionsLabel->setEnabled(enable);
0049     expressions->setEnabled(enable);
0050     enableCustomFormat->setEnabled(enable);
0051     customFormat->setEnabled(enable && enableCustomFormat->isChecked());
0052 }
0053 
0054 void DebuggerTracingDialog::enableOrDisableCustomFormat(int state)
0055 {
0056     customFormat->setEnabled(state == Qt::Checked);
0057 }
0058 
0059 void DebuggerTracingDialog::accept()
0060 {
0061     // Check that if we use format string,
0062     // the number of expressions is not greater than the number of
0063     // format specifiers
0064     bool ok = true;
0065 
0066     if (enableCustomFormat->isChecked())
0067     {
0068         QString s = customFormat->text();
0069         int percent_count = 0;
0070         for (int i = 0; i < s.length(); ++i)
0071             if (s[i] == '%')
0072             {
0073                 if (i+1 < s.length())
0074                 {
0075                     if (s[i+1] != '%')
0076                     {
0077                         ++percent_count;
0078                     }
0079                     else
0080                     {
0081                         // Double %
0082                         ++i;
0083                     }
0084                 }
0085             }
0086 
0087         if (percent_count < expressions->items().count())
0088         {
0089             ok = false;
0090 
0091             KMessageBox::error(
0092                 this,
0093                 "<b>Not enough format specifiers</b>"
0094                 "<p>The number of format specifiers in the custom format "
0095                 "string is less than the number of expressions. Either remove "
0096                 "some expressions or edit the format string.",
0097                 "Not enough format specifiers");
0098         }
0099     }
0100 
0101     if (ok)
0102     {
0103         bp_->setTracingEnabled(enable->isChecked());
0104         bp_->setTracedExpressions(expressions->items());
0105         bp_->setTraceFormatStringEnabled(enableCustomFormat->isChecked());
0106         bp_->setTraceFormatString(customFormat->text());
0107         QDialog::accept();
0108     }
0109 }
0110 
0111 #include "moc_debuggertracingdialog.cpp"