File indexing completed on 2024-05-19 16:47:32

0001 // clang-format off
0002 /*
0003  * KDiff3 - Text Diff And Merge Tool
0004  *
0005  * SPDX-FileCopyrightText: 2002-2011 Joachim Eibl, joachim.eibl at gmx.de
0006  * SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 // clang-format on
0009 
0010 #include "smalldialogs.h"
0011 
0012 #include "diff.h"
0013 #include "FileNameLineEdit.h"
0014 #include "kdiff3.h"
0015 #include "options.h"
0016 #include "TypeUtils.h"
0017 #include "ui_opendialog.h"
0018 
0019 #include <QCheckBox>
0020 #include <QComboBox>
0021 #include <QDialogButtonBox>
0022 #include <QDir>
0023 #include <QDropEvent>
0024 #include <QFileDialog>
0025 #include <QLabel>
0026 #include <QLayout>
0027 #include <QLineEdit>
0028 #include <QMenu>
0029 #include <QMimeData>
0030 #include <QPushButton>
0031 #include <QToolTip>
0032 #include <QUrl>
0033 
0034 #include <KLocalizedString>
0035 
0036 // OpenDialog **************************************************************
0037 
0038 OpenDialog::OpenDialog(
0039     KDiff3App* pParent, const QString& n1, const QString& n2, const QString& n3,
0040     bool bMerge, const QString& outputName)
0041     : QDialog(pParent)
0042 {
0043     dialogUi.setupUi(this);
0044     setModal(true);
0045     //Abort if verticalLayout is not the immediate child of the dialog. This interferes with re-sizing.
0046     assert(dialogUi.virticalLayout->parent() == this);
0047 
0048     dialogUi.lineA->insertItems(0, gOptions->getRecentFilesA());
0049     dialogUi.lineA->setEditText(n1);
0050 
0051     QPushButton* button = dialogUi.fileSelectA;
0052     chk_connect_a(button, &QPushButton::clicked, this, &OpenDialog::selectFileA);
0053     QPushButton* button2 = dialogUi.folderSelectA;
0054     chk_connect_a(button2, &QPushButton::clicked, this, &OpenDialog::selectDirA);
0055     chk_connect_a(dialogUi.lineA, &QComboBox::editTextChanged, this, &OpenDialog::inputFilenameChanged);
0056 
0057     dialogUi.lineB->setEditable(true);
0058     dialogUi.lineB->insertItems(0, gOptions->getRecentFilesB());
0059     dialogUi.lineB->setEditText(n2);
0060 
0061     dialogUi.lineB->setMinimumWidth(200);
0062     button = dialogUi.fileSelectB;
0063     chk_connect_a(button, &QPushButton::clicked, this, &OpenDialog::selectFileB);
0064     button2 = dialogUi.folderSelectB;
0065     chk_connect_a(button2, &QPushButton::clicked, this, &OpenDialog::selectDirB);
0066     chk_connect_a(dialogUi.lineB, &QComboBox::editTextChanged, this, &OpenDialog::inputFilenameChanged);
0067 
0068     dialogUi.lineC->setEditable(true);
0069     dialogUi.lineC->insertItems(0, gOptions->getRecentFilesC());
0070     dialogUi.lineC->setEditText(n3);
0071     dialogUi.lineC->setMinimumWidth(200);
0072     button = dialogUi.fileSelectC;
0073     chk_connect_a(button, &QPushButton::clicked, this, &OpenDialog::selectFileC);
0074     button2 = dialogUi.folderSelectC;
0075     chk_connect_a(button2, &QPushButton::clicked, this, &OpenDialog::selectDirC);
0076     chk_connect_a(dialogUi.lineC, &QComboBox::editTextChanged, this, &OpenDialog::inputFilenameChanged);
0077 
0078     button = dialogUi.swapCopy;
0079 
0080     QMenu* m = new QMenu(this);
0081     m->addAction(i18n("Swap %1<->%2", QStringLiteral("A"), QStringLiteral("B")));
0082     m->addAction(i18n("Swap %1<->%2", QStringLiteral("B"), QStringLiteral("C")));
0083     m->addAction(i18n("Swap %1<->%2", QStringLiteral("C"), QStringLiteral("A")));
0084     m->addAction(i18n("Copy %1->Output", QStringLiteral("A")));
0085     m->addAction(i18n("Copy %1->Output", QStringLiteral("B")));
0086     m->addAction(i18n("Copy %1->Output", QStringLiteral("C")));
0087     m->addAction(i18n("Swap %1<->Output", QStringLiteral("A")));
0088     m->addAction(i18n("Swap %1<->Output", QStringLiteral("B")));
0089     m->addAction(i18n("Swap %1<->Output", QStringLiteral("C")));
0090     chk_connect_a(m, &QMenu::triggered, this, &OpenDialog::slotSwapCopyNames);
0091     button->setMenu(m);
0092 
0093     dialogUi.lineOut->insertItems(0, gOptions->getRecentOutputFiles());
0094     dialogUi.lineOut->setEditText(outputName);
0095 
0096     button = dialogUi.selectOutputFile;
0097     chk_connect_a(button, &QPushButton::clicked, this, &OpenDialog::selectOutputName);
0098     button2 = dialogUi.selectOutputFolder;
0099     chk_connect_a(button2, &QPushButton::clicked, this, &OpenDialog::selectOutputDir);
0100     chk_connect_a(dialogUi.mergeCheckBox, &QCheckBox::stateChanged, this, &OpenDialog::internalSlot);
0101     chk_connect_a(this, &OpenDialog::internalSignal, dialogUi.lineOut, &QComboBox::setEnabled);
0102     chk_connect_a(this, &OpenDialog::internalSignal, button, &QPushButton::setEnabled);
0103     chk_connect_a(this, &OpenDialog::internalSignal, button2, &QPushButton::setEnabled);
0104 
0105     dialogUi.mergeCheckBox->setChecked(bMerge);
0106 
0107     QDialogButtonBox *box = dialogUi.buttonBox;
0108     button = box->addButton(i18n("Configure..."), QDialogButtonBox::ActionRole);
0109     button->setIcon(QIcon::fromTheme("configure"));
0110     chk_connect_a(button, &QPushButton::clicked, pParent, &KDiff3App::slotConfigure);
0111     chk_connect_a(box, &QDialogButtonBox::accepted, this, &OpenDialog::accept);
0112     chk_connect_a(box, &QDialogButtonBox::rejected, this, &OpenDialog::reject);
0113 
0114     QSize sh = sizeHint();
0115     if(sh.height() > 10)
0116         setFixedHeight(sh.height());
0117     else
0118     {
0119         //This is likely a bug. It is also a recoverable condition. Assert for it in debug builds.
0120         assert(sh.isValid() && sh.height() > 10);
0121         setFixedHeight(262);
0122     }
0123     m_bInputFileNameChanged = false;
0124 
0125     /*
0126         QComboBox's default handling of Drag and Drop fails to clear existing text on drop.
0127         On some systems it may fail to do anything at all.
0128 
0129         This is not what we want. So manually replace the each QLineEdit object with a FileNameLineEdit.
0130         This makes behavior consitant with the main window.
0131 
0132         On windows this step also needed to bypasses Qt's quirky behavior when converting from QUrl
0133         to QString. Specifically % encoding is by handled differently on windows. This is explicitly documented
0134         as platform specific unspecified behavior. Not what we need.
0135     */
0136     dialogUi.lineA->setLineEdit(new FileNameLineEdit(dialogUi.lineA));
0137     dialogUi.lineB->setLineEdit(new FileNameLineEdit(dialogUi.lineB));
0138     dialogUi.lineC->setLineEdit(new FileNameLineEdit(dialogUi.lineC));
0139     dialogUi.lineOut->setLineEdit(new FileNameLineEdit(dialogUi.lineOut));
0140 }
0141 
0142 void OpenDialog::selectURL(QComboBox* pLine, bool bDir, qint32 i, bool bSave)
0143 {
0144     QString current = pLine->currentText();
0145     QUrl currentUrl;
0146 
0147     if(current.isEmpty() && i > 3)
0148     {
0149         current = dialogUi.lineC->currentText();
0150     }
0151     if(current.isEmpty())
0152     {
0153         current = dialogUi.lineB->currentText();
0154     }
0155     if(current.isEmpty())
0156     {
0157         current = dialogUi.lineA->currentText();
0158     }
0159 
0160     currentUrl = QUrl::fromUserInput(current, QString(), QUrl::AssumeLocalFile);
0161     QUrl newURL = bDir ? QFileDialog::getExistingDirectoryUrl(this, i18n("Open Folder"), currentUrl)
0162                        : bSave ? QFileDialog::getSaveFileUrl(this, i18n("Select Output File"), currentUrl)
0163                                : QFileDialog::getOpenFileUrl(this, i18n("Open File"), currentUrl);
0164     if(!newURL.isEmpty())
0165     {
0166         /*
0167             Since we are selecting a directory open in the parent directory
0168             not the one selected.
0169         */
0170         //QFileDialog::setStartDir( KIO::upUrl( newURL ) );
0171         pLine->setEditText(newURL.url());
0172     }
0173     // newURL won't be modified if nothing was selected.
0174 }
0175 
0176 void OpenDialog::selectFileA() { selectURL(dialogUi.lineA, false, 1, false); }
0177 void OpenDialog::selectFileB() { selectURL(dialogUi.lineB, false, 2, false); }
0178 void OpenDialog::selectFileC() { selectURL(dialogUi.lineC, false, 3, false); }
0179 void OpenDialog::selectOutputName() { selectURL(dialogUi.lineOut, false, 4, true); }
0180 void OpenDialog::selectDirA() { selectURL(dialogUi.lineA, true, 1, false); }
0181 void OpenDialog::selectDirB() { selectURL(dialogUi.lineB, true, 2, false); }
0182 void OpenDialog::selectDirC() { selectURL(dialogUi.lineC, true, 3, false); }
0183 void OpenDialog::selectOutputDir() { selectURL(dialogUi.lineOut, true, 4, true); }
0184 
0185 void OpenDialog::internalSlot(qint32 i)
0186 {
0187     Q_EMIT internalSignal(i != 0);
0188 }
0189 
0190 // Clear the output-filename when any input-filename changed,
0191 // because users forgot to change the output and accidentally overwrote it with
0192 // wrong data during a merge.
0193 void OpenDialog::inputFilenameChanged()
0194 {
0195     if(!m_bInputFileNameChanged)
0196     {
0197         m_bInputFileNameChanged = true;
0198         dialogUi.lineOut->clearEditText();
0199     }
0200 }
0201 
0202 void OpenDialog::fixCurrentText(QComboBox* pCB)
0203 {
0204     QString s = pCB->currentText();
0205     QtSizeType pos = s.indexOf('\n');
0206 
0207     if(pos >= 0)
0208         s = s.left(pos);
0209     pos = s.indexOf('\r');
0210     if(pos >= 0)
0211         s = s.left(pos);
0212 
0213     pCB->setEditText(s);
0214 }
0215 
0216 void OpenDialog::accept()
0217 {
0218     fixCurrentText(dialogUi.lineA);
0219     QString s = dialogUi.lineA->currentText();
0220     s = FileAccess::prettyAbsPath(QUrl::fromUserInput(s, QString(), QUrl::AssumeLocalFile));
0221     gOptions->getRecentFilesA().push_front(s);
0222 
0223     fixCurrentText(dialogUi.lineB);
0224     s = dialogUi.lineB->currentText();
0225     s = FileAccess::prettyAbsPath(QUrl::fromUserInput(s, QString(), QUrl::AssumeLocalFile));
0226     gOptions->getRecentFilesB().push_front(s);
0227 
0228     fixCurrentText(dialogUi.lineC);
0229     s = dialogUi.lineC->currentText();
0230     s = FileAccess::prettyAbsPath(QUrl::fromUserInput(s, QString(), QUrl::AssumeLocalFile));
0231     gOptions->getRecentFilesC().push_front(s);
0232 
0233     fixCurrentText(dialogUi.lineOut);
0234     s = dialogUi.lineOut->currentText();
0235     s = FileAccess::prettyAbsPath(QUrl::fromUserInput(s, QString(), QUrl::AssumeLocalFile));
0236     gOptions->getRecentOutputFiles().push_front(s);
0237 
0238     QDialog::accept();
0239 }
0240 
0241 void OpenDialog::slotSwapCopyNames(QAction* pAction) const // id selected in the popup menu
0242 {
0243     const QtSizeType id = pAction->parentWidget()->actions().indexOf(pAction);
0244     QComboBox* cb1 = nullptr;
0245     QComboBox* cb2 = nullptr;
0246 
0247     switch(id)
0248     {
0249         case swapAB:
0250             cb1 = dialogUi.lineA;
0251             cb2 = dialogUi.lineB;
0252             break;
0253         case swapBC:
0254             cb1 = dialogUi.lineB;
0255             cb2 = dialogUi.lineC;
0256             break;
0257         case swapCA:
0258             cb1 = dialogUi.lineC;
0259             cb2 = dialogUi.lineA;
0260             break;
0261         case copyAToOut:
0262             cb1 = dialogUi.lineA;
0263             cb2 = dialogUi.lineOut;
0264             break;
0265         case copyBToOut:
0266             cb1 = dialogUi.lineB;
0267             cb2 = dialogUi.lineOut;
0268             break;
0269         case copyCToOut:
0270             cb1 = dialogUi.lineC;
0271             cb2 = dialogUi.lineOut;
0272             break;
0273         case swapAOut:
0274             cb1 = dialogUi.lineA;
0275             cb2 = dialogUi.lineOut;
0276             break;
0277         case swapBOut:
0278             cb1 = dialogUi.lineB;
0279             cb2 = dialogUi.lineOut;
0280             break;
0281         case swapCOut:
0282             cb1 = dialogUi.lineC;
0283             cb2 = dialogUi.lineOut;
0284             break;
0285     }
0286 
0287     if(cb1 && cb2)
0288     {
0289         QString t1 = cb1->currentText();
0290         QString t2 = cb2->currentText();
0291         cb2->setEditText(t1);
0292         if(id <= swapCA || id >= swapAOut)
0293         {
0294             cb1->setEditText(t2);
0295         }
0296     }
0297 }
0298 
0299 // FindDialog *********************************************
0300 
0301 FindDialog::FindDialog(QWidget* pParent)
0302     : QDialog(pParent)
0303 {
0304     QGridLayout* layout = new QGridLayout(this);
0305     layout->setContentsMargins(5, 5, 5, 5);
0306     layout->setSpacing(5);
0307 
0308     qint32 line = 0;
0309     layout->addWidget(new QLabel(i18n("Search text:"), this), line, 0, 1, 2);
0310     ++line;
0311 
0312     m_pSearchString = new QLineEdit(this);
0313     layout->addWidget(m_pSearchString, line, 0, 1, 2);
0314     ++line;
0315 
0316     m_pCaseSensitive = new QCheckBox(i18n("Case sensitive"), this);
0317     layout->addWidget(m_pCaseSensitive, line, 1);
0318 
0319     m_pSearchInA = new QCheckBox(i18n("Search A"), this);
0320     layout->addWidget(m_pSearchInA, line, 0);
0321     m_pSearchInA->setChecked(true);
0322     ++line;
0323 
0324     m_pSearchInB = new QCheckBox(i18n("Search B"), this);
0325     layout->addWidget(m_pSearchInB, line, 0);
0326     m_pSearchInB->setChecked(true);
0327     ++line;
0328 
0329     m_pSearchInC = new QCheckBox(i18n("Search C"), this);
0330     layout->addWidget(m_pSearchInC, line, 0);
0331     m_pSearchInC->setChecked(true);
0332     ++line;
0333 
0334     m_pSearchInOutput = new QCheckBox(i18n("Search output"), this);
0335     layout->addWidget(m_pSearchInOutput, line, 0);
0336     m_pSearchInOutput->setChecked(true);
0337     ++line;
0338 
0339     QDialogButtonBox *box = new QDialogButtonBox(QDialogButtonBox::Cancel, this);
0340     layout->addWidget(box, line, 0, 1, 2);
0341     box->addButton(i18n("&Search"), QDialogButtonBox::AcceptRole);
0342     chk_connect_a(box, &QDialogButtonBox::accepted, this, &FindDialog::accept);
0343     chk_connect_a(box, &QDialogButtonBox::rejected, this, &FindDialog::reject);
0344 
0345     hide();
0346 }
0347 
0348 void FindDialog::restartFind()
0349 {
0350     currentLine = 0;
0351     currentPos = 0;
0352     currentWindow = eWindowIndex::A;
0353 }
0354 
0355 void FindDialog::setVisible(bool bVisible)
0356 {
0357     QDialog::setVisible(bVisible);
0358     m_pSearchString->selectAll();
0359     m_pSearchString->setFocus();
0360 }
0361 
0362 RegExpTester::RegExpTester(QWidget* pParent, const QString& autoMergeRegExpToolTip,
0363                            const QString& historyStartRegExpToolTip, const QString& historyEntryStartRegExpToolTip, const QString& historySortKeyOrderToolTip)
0364     : QDialog(pParent)
0365 {
0366     qint32 line = 0;
0367     setWindowTitle(i18n("Regular Expression Tester"));
0368     QGridLayout* pGrid = new QGridLayout(this);
0369     pGrid->setSpacing(5);
0370     pGrid->setContentsMargins(5, 5, 5, 5);
0371 
0372     QLabel* l = new QLabel(i18n("Auto merge regular expression:"), this);
0373     pGrid->addWidget(l, line, 0);
0374     l->setToolTip(autoMergeRegExpToolTip);
0375     m_pAutoMergeRegExpEdit = new QLineEdit(this);
0376     pGrid->addWidget(m_pAutoMergeRegExpEdit, line, 1);
0377     chk_connect_a(m_pAutoMergeRegExpEdit, &QLineEdit::textChanged, this, &RegExpTester::slotRecalc);
0378     ++line;
0379 
0380     l = new QLabel(i18n("Example auto merge line:"), this);
0381     pGrid->addWidget(l, line, 0);
0382     l->setToolTip(i18nc("Tool Tip", "To test auto merge, copy a line as used in your files."));
0383     m_pAutoMergeExampleEdit = new QLineEdit(this);
0384     pGrid->addWidget(m_pAutoMergeExampleEdit, line, 1);
0385     chk_connect_a(m_pAutoMergeExampleEdit, &QLineEdit::textChanged, this, &RegExpTester::slotRecalc);
0386     ++line;
0387 
0388     l = new QLabel(i18n("Match result:"), this);
0389     pGrid->addWidget(l, line, 0);
0390     m_pAutoMergeMatchResult = new QLineEdit(this);
0391     m_pAutoMergeMatchResult->setReadOnly(true);
0392     pGrid->addWidget(m_pAutoMergeMatchResult, line, 1);
0393     ++line;
0394 
0395     pGrid->addItem(new QSpacerItem(100, 20), line, 0);
0396     pGrid->setRowStretch(line, 5);
0397     ++line;
0398 
0399     l = new QLabel(i18n("History start regular expression:"), this);
0400     pGrid->addWidget(l, line, 0);
0401     l->setToolTip(historyStartRegExpToolTip);
0402     m_pHistoryStartRegExpEdit = new QLineEdit(this);
0403     pGrid->addWidget(m_pHistoryStartRegExpEdit, line, 1);
0404     chk_connect_a(m_pHistoryStartRegExpEdit, &QLineEdit::textChanged, this, &RegExpTester::slotRecalc);
0405     ++line;
0406 
0407     l = new QLabel(i18n("Example history start line (with leading comment):"), this);
0408     pGrid->addWidget(l, line, 0);
0409     l->setToolTip(i18nc("Tool Tip", "Copy a history start line as used in your files,\n"
0410                                     "including the leading comment."));
0411     m_pHistoryStartExampleEdit = new QLineEdit(this);
0412     pGrid->addWidget(m_pHistoryStartExampleEdit, line, 1);
0413     chk_connect_a(m_pHistoryStartExampleEdit, &QLineEdit::textChanged, this, &RegExpTester::slotRecalc);
0414     ++line;
0415 
0416     l = new QLabel(i18n("Match result:"), this);
0417     pGrid->addWidget(l, line, 0);
0418     m_pHistoryStartMatchResult = new QLineEdit(this);
0419     m_pHistoryStartMatchResult->setReadOnly(true);
0420     pGrid->addWidget(m_pHistoryStartMatchResult, line, 1);
0421     ++line;
0422 
0423     pGrid->addItem(new QSpacerItem(100, 20), line, 0);
0424     pGrid->setRowStretch(line, 5);
0425     ++line;
0426 
0427     l = new QLabel(i18n("History entry start regular expression:"), this);
0428     pGrid->addWidget(l, line, 0);
0429     l->setToolTip(historyEntryStartRegExpToolTip);
0430     m_pHistoryEntryStartRegExpEdit = new QLineEdit(this);
0431     pGrid->addWidget(m_pHistoryEntryStartRegExpEdit, line, 1);
0432     chk_connect_a(m_pHistoryEntryStartRegExpEdit, &QLineEdit::textChanged, this, &RegExpTester::slotRecalc);
0433     ++line;
0434 
0435     l = new QLabel(i18n("History sort key order:"), this);
0436     pGrid->addWidget(l, line, 0);
0437     l->setToolTip(historySortKeyOrderToolTip);
0438     m_pHistorySortKeyOrderEdit = new QLineEdit(this);
0439     pGrid->addWidget(m_pHistorySortKeyOrderEdit, line, 1);
0440     chk_connect_a(m_pHistorySortKeyOrderEdit, &QLineEdit::textChanged, this, &RegExpTester::slotRecalc);
0441     ++line;
0442 
0443     l = new QLabel(i18n("Example history entry start line (without leading comment):"), this);
0444     pGrid->addWidget(l, line, 0);
0445     l->setToolTip(i18nc("Tool Tip", "Copy a history entry start line as used in your files,\n"
0446                                     "but omit the leading comment."));
0447     m_pHistoryEntryStartExampleEdit = new QLineEdit(this);
0448     pGrid->addWidget(m_pHistoryEntryStartExampleEdit, line, 1);
0449     chk_connect_a(m_pHistoryEntryStartExampleEdit, &QLineEdit::textChanged, this, &RegExpTester::slotRecalc);
0450     ++line;
0451 
0452     l = new QLabel(i18n("Match result:"), this);
0453     pGrid->addWidget(l, line, 0);
0454     m_pHistoryEntryStartMatchResult = new QLineEdit(this);
0455     m_pHistoryEntryStartMatchResult->setReadOnly(true);
0456     pGrid->addWidget(m_pHistoryEntryStartMatchResult, line, 1);
0457     ++line;
0458 
0459     l = new QLabel(i18n("Sort key result:"), this);
0460     pGrid->addWidget(l, line, 0);
0461     m_pHistorySortKeyResult = new QLineEdit(this);
0462     m_pHistorySortKeyResult->setReadOnly(true);
0463     pGrid->addWidget(m_pHistorySortKeyResult, line, 1);
0464     ++line;
0465 
0466     QDialogButtonBox *box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
0467     pGrid->addWidget(box, line, 0, 1, 2);
0468     chk_connect_a(box, &QDialogButtonBox::accepted, this, &RegExpTester::accept);
0469     chk_connect_a(box, &QDialogButtonBox::rejected, this, &RegExpTester::reject);
0470 
0471     resize(800, sizeHint().height());
0472 }
0473 
0474 void RegExpTester::init(const QString& autoMergeRegExp, const QString& historyStartRegExp, const QString& historyEntryStartRegExp, const QString& historySortKeyOrder)
0475 {
0476     m_pAutoMergeRegExpEdit->setText(autoMergeRegExp);
0477     m_pHistoryStartRegExpEdit->setText(historyStartRegExp);
0478     m_pHistoryEntryStartRegExpEdit->setText(historyEntryStartRegExp);
0479     m_pHistorySortKeyOrderEdit->setText(historySortKeyOrder);
0480 }
0481 
0482 QString RegExpTester::autoMergeRegExp() const
0483 {
0484     return m_pAutoMergeRegExpEdit->text();
0485 }
0486 
0487 QString RegExpTester::historyStartRegExp() const
0488 {
0489     return m_pHistoryStartRegExpEdit->text();
0490 }
0491 
0492 QString RegExpTester::historyEntryStartRegExp() const
0493 {
0494     return m_pHistoryEntryStartRegExpEdit->text();
0495 }
0496 
0497 QString RegExpTester::historySortKeyOrder() const
0498 {
0499     return m_pHistorySortKeyOrderEdit->text();
0500 }
0501 
0502 void RegExpTester::slotRecalc()
0503 {
0504     const QRegularExpression autoMergeRegExp(m_pAutoMergeRegExpEdit->text());
0505     QRegularExpressionMatch match = autoMergeRegExp.match(m_pAutoMergeExampleEdit->text());
0506 
0507     if(match.hasMatch())
0508     {
0509         m_pAutoMergeMatchResult->setText(i18n("Match success."));
0510     }
0511     else
0512     {
0513         m_pAutoMergeMatchResult->setText(i18n("Match failed."));
0514     }
0515 
0516     const QRegularExpression historyStartRegExp(m_pHistoryStartRegExpEdit->text());
0517     match = historyStartRegExp.match(m_pHistoryStartExampleEdit->text());
0518 
0519     if(match.hasMatch())
0520     {
0521         m_pHistoryStartMatchResult->setText(i18n("Match success."));
0522     }
0523     else
0524     {
0525         m_pHistoryStartMatchResult->setText(i18n("Match failed."));
0526     }
0527 
0528     QStringList parenthesesGroups;
0529     bool bSuccess = findParenthesesGroups(m_pHistoryEntryStartRegExpEdit->text(), parenthesesGroups);
0530     if(!bSuccess)
0531     {
0532         m_pHistoryEntryStartMatchResult->setText(i18n("Opening and closing parentheses do not match in regular expression."));
0533         m_pHistorySortKeyResult->setText("");
0534         return;
0535     }
0536     const QRegularExpression historyEntryStartRegExp(m_pHistoryEntryStartRegExpEdit->text());
0537     const QString s = m_pHistoryEntryStartExampleEdit->text();
0538     match = historyEntryStartRegExp.match(s);
0539 
0540     if(match.hasMatch())
0541     {
0542         m_pHistoryEntryStartMatchResult->setText(i18n("Match success."));
0543         QString key = calcHistorySortKey(m_pHistorySortKeyOrderEdit->text(), match, parenthesesGroups);
0544         m_pHistorySortKeyResult->setText(key);
0545     }
0546     else
0547     {
0548         m_pHistoryEntryStartMatchResult->setText(i18n("Match failed."));
0549         m_pHistorySortKeyResult->setText("");
0550     }
0551 }
0552 
0553 //#include "smalldialogs.moc"