1 /*
2 * Copyright (C) 2004 Christian Loose <christian.loose@kdemail.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19 #include "patchoptiondialog.h"
20
21 using Cervisia::PatchOptionDialog;
22
23 #include <KHelpClient>
24 #include <KConfigGroup>
25 #include <KLocalizedString>
26
27 #include <qcheckbox.h>
28 #include <qlabel.h>
29 #include <qlayout.h>
30 #include <qradiobutton.h>
31 #include <qgroupbox.h>
32 #include <QVBoxLayout>
33 #include <QHBoxLayout>
34 #include <QButtonGroup>
35 #include <QSpinBox>
36 #include <QDialogButtonBox>
37 #include <QPushButton>
38
39
PatchOptionDialog(QWidget * parent)40 PatchOptionDialog::PatchOptionDialog(QWidget* parent)
41 : QDialog(parent)
42 {
43 setModal(false);
44
45 QVBoxLayout *mainLayout = new QVBoxLayout;
46 setLayout(mainLayout);
47
48 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help);
49 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
50 okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
51 connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
52 connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
53 connect(buttonBox, &QDialogButtonBox::helpRequested, this, &PatchOptionDialog::slotHelp);
54
55 { // format
56 m_formatBtnGroup = new QButtonGroup(this);
57
58 connect(m_formatBtnGroup, SIGNAL(buttonClicked(int)),
59 this, SLOT(formatChanged(int)));
60
61 m_formatBtnGroup->addButton(new QRadioButton(i18n("Context")), 0);
62 m_formatBtnGroup->addButton(new QRadioButton(i18n("Normal")), 1);
63 QRadioButton* unifiedFormatBtn = new QRadioButton(i18n("Unified"));
64 unifiedFormatBtn->setChecked(true);
65 m_formatBtnGroup->addButton(unifiedFormatBtn, 2);
66
67 QGroupBox *box = new QGroupBox(i18n("Output Format"));
68 mainLayout->addWidget(box);
69 QVBoxLayout *v = new QVBoxLayout(box);
70 v->addWidget(m_formatBtnGroup->button(0));
71 v->addWidget(m_formatBtnGroup->button(1));
72 v->addWidget(m_formatBtnGroup->button(2));
73
74 mainLayout->addWidget(box);
75 }
76
77 QLabel* contextLinesLbl = new QLabel(i18n("&Number of context lines:"));
78 m_contextLines = new QSpinBox;
79 m_contextLines->setValue(3);
80 mainLayout->addWidget(m_contextLines);
81 m_contextLines->setRange(2, 65535);
82 contextLinesLbl->setBuddy(m_contextLines);
83
84 QBoxLayout* contextLinesLayout = new QHBoxLayout();
85 mainLayout->addLayout(contextLinesLayout);
86 contextLinesLayout->addWidget(contextLinesLbl);
87 contextLinesLayout->addWidget(m_contextLines);
88
89 { // ignore options
90 QButtonGroup *group = new QButtonGroup(this);
91 group->setExclusive(false);
92
93 m_blankLineChk = new QCheckBox(i18n("Ignore added or removed empty lines"));
94 m_spaceChangeChk = new QCheckBox(i18n("Ignore changes in the amount of whitespace"));
95 m_allSpaceChk = new QCheckBox(i18n("Ignore all whitespace"));
96 m_caseChangesChk = new QCheckBox(i18n("Ignore changes in case"));
97
98 group->addButton(m_blankLineChk);
99 group->addButton(m_spaceChangeChk);
100 group->addButton(m_allSpaceChk);
101 group->addButton(m_caseChangesChk);
102
103 QGroupBox *box = new QGroupBox(i18n("Ignore Options"));
104 mainLayout->addWidget(box);
105 QVBoxLayout *v = new QVBoxLayout(box);
106 v->addWidget(m_blankLineChk);
107 v->addWidget(m_spaceChangeChk);
108 v->addWidget(m_allSpaceChk);
109 v->addWidget(m_caseChangesChk);
110
111 mainLayout->addWidget(box);
112 }
113
114 mainLayout->addWidget(buttonBox);
115 }
116
117
~PatchOptionDialog()118 PatchOptionDialog::~PatchOptionDialog()
119 {
120 }
121
slotHelp()122 void PatchOptionDialog::slotHelp()
123 {
124 KHelpClient::invokeHelp(QLatin1String("creatingpatches"));
125 }
126
127
diffOptions() const128 QString PatchOptionDialog::diffOptions() const
129 {
130 QString options;
131
132 if( m_blankLineChk->isChecked() )
133 options += " -B ";
134
135 if( m_spaceChangeChk->isChecked() )
136 options += " -b ";
137
138 if( m_allSpaceChk->isChecked() )
139 options += " -w ";
140
141 if( m_caseChangesChk->isChecked() )
142 options += " -i ";
143
144 return options;
145 }
146
147
formatOption() const148 QString PatchOptionDialog::formatOption() const
149 {
150 switch( m_formatBtnGroup->checkedId() )
151 {
152 case 0: return "-C " + QString::number(m_contextLines->value());
153 case 1: return "";
154 case 2: return "-U " + QString::number(m_contextLines->value());
155 }
156
157 return "";
158 }
159
160
formatChanged(int buttonId)161 void PatchOptionDialog::formatChanged(int buttonId)
162 {
163 bool enabled = ( buttonId == 0 || buttonId == 2 );
164 m_contextLines->setEnabled(enabled);
165 }
166
167