File: patchoptiondialog.cpp

package info (click to toggle)
cervisia 4:17.08.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 7,548 kB
  • sloc: cpp: 14,364; xml: 393; makefile: 3; sh: 3
file content (166 lines) | stat: -rw-r--r-- 5,099 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
 *  Copyright (C) 2004 Christian Loose <christian.loose@kdemail.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include "patchoptiondialog.h"

using Cervisia::PatchOptionDialog;

#include <KHelpClient>
#include <KConfigGroup>
#include <KLocalizedString>

#include <qcheckbox.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qradiobutton.h>
#include <qgroupbox.h>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QButtonGroup>
#include <QSpinBox>
#include <QDialogButtonBox>
#include <QPushButton>


PatchOptionDialog::PatchOptionDialog(QWidget* parent)
    : QDialog(parent)
{
    setModal(false);

    QVBoxLayout *mainLayout = new QVBoxLayout;
    setLayout(mainLayout);

    QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help);
    QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
    okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
    connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
    connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
    connect(buttonBox, &QDialogButtonBox::helpRequested, this, &PatchOptionDialog::slotHelp);

    { // format
      m_formatBtnGroup = new QButtonGroup(this);

      connect(m_formatBtnGroup, SIGNAL(buttonClicked(int)),
              this,             SLOT(formatChanged(int)));

      m_formatBtnGroup->addButton(new QRadioButton(i18n("Context")), 0);
      m_formatBtnGroup->addButton(new QRadioButton(i18n("Normal")), 1);
      QRadioButton* unifiedFormatBtn = new QRadioButton(i18n("Unified"));
      unifiedFormatBtn->setChecked(true);
      m_formatBtnGroup->addButton(unifiedFormatBtn, 2);

      QGroupBox *box = new QGroupBox(i18n("Output Format"));
      mainLayout->addWidget(box);
      QVBoxLayout *v = new QVBoxLayout(box);
      v->addWidget(m_formatBtnGroup->button(0));
      v->addWidget(m_formatBtnGroup->button(1));
      v->addWidget(m_formatBtnGroup->button(2));

      mainLayout->addWidget(box);
    }

    QLabel* contextLinesLbl = new QLabel(i18n("&Number of context lines:"));
    m_contextLines = new QSpinBox;
    m_contextLines->setValue(3);
    mainLayout->addWidget(m_contextLines);
    m_contextLines->setRange(2, 65535);
    contextLinesLbl->setBuddy(m_contextLines);

    QBoxLayout* contextLinesLayout = new QHBoxLayout();
    mainLayout->addLayout(contextLinesLayout);
    contextLinesLayout->addWidget(contextLinesLbl);
    contextLinesLayout->addWidget(m_contextLines);

    { // ignore options
      QButtonGroup *group = new QButtonGroup(this);
      group->setExclusive(false);

      m_blankLineChk   = new QCheckBox(i18n("Ignore added or removed empty lines"));
      m_spaceChangeChk = new QCheckBox(i18n("Ignore changes in the amount of whitespace"));
      m_allSpaceChk    = new QCheckBox(i18n("Ignore all whitespace"));
      m_caseChangesChk = new QCheckBox(i18n("Ignore changes in case"));

      group->addButton(m_blankLineChk);
      group->addButton(m_spaceChangeChk);
      group->addButton(m_allSpaceChk);
      group->addButton(m_caseChangesChk);

      QGroupBox *box = new QGroupBox(i18n("Ignore Options"));
      mainLayout->addWidget(box);
      QVBoxLayout *v = new QVBoxLayout(box);
      v->addWidget(m_blankLineChk);
      v->addWidget(m_spaceChangeChk);
      v->addWidget(m_allSpaceChk);
      v->addWidget(m_caseChangesChk);

      mainLayout->addWidget(box);
    }

    mainLayout->addWidget(buttonBox);
}


PatchOptionDialog::~PatchOptionDialog()
{
}

void PatchOptionDialog::slotHelp()
{
  KHelpClient::invokeHelp(QLatin1String("creatingpatches"));
}


QString PatchOptionDialog::diffOptions() const
{
    QString options;

    if( m_blankLineChk->isChecked() )
        options += " -B ";

    if( m_spaceChangeChk->isChecked() )
        options += " -b ";

    if( m_allSpaceChk->isChecked() )
        options += " -w ";

    if( m_caseChangesChk->isChecked() )
        options += " -i ";

    return options;
}


QString PatchOptionDialog::formatOption() const
{
    switch( m_formatBtnGroup->checkedId() )
    {
        case 0: return "-C " + QString::number(m_contextLines->value());
        case 1: return "";
        case 2: return "-U " + QString::number(m_contextLines->value());
    }

    return "";
}


void PatchOptionDialog::formatChanged(int buttonId)
{
    bool enabled = ( buttonId == 0 || buttonId == 2 );
    m_contextLines->setEnabled(enabled);
}