joachim99@69
|
1 /***************************************************************************
|
joachim99@77
|
2 * Copyright (C) 2005-2007 by Joachim Eibl *
|
joachim99@69
|
3 * joachim.eibl at gmx.de *
|
joachim99@69
|
4 * *
|
joachim99@69
|
5 * This program is free software; you can redistribute it and/or modify *
|
joachim99@69
|
6 * it under the terms of the GNU General Public License as published by *
|
joachim99@69
|
7 * the Free Software Foundation; either version 2 of the License, or *
|
joachim99@69
|
8 * (at your option) any later version. *
|
joachim99@69
|
9 * *
|
joachim99@69
|
10 * This program is distributed in the hope that it will be useful, *
|
joachim99@69
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
joachim99@69
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
joachim99@69
|
13 * GNU General Public License for more details. *
|
joachim99@69
|
14 * *
|
joachim99@69
|
15 * You should have received a copy of the GNU General Public License *
|
joachim99@69
|
16 * along with this program; if not, write to the *
|
joachim99@69
|
17 * Free Software Foundation, Inc., *
|
joachim99@69
|
18 * 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. *
|
joachim99@69
|
19 ***************************************************************************/
|
joachim99@69
|
20
|
joachim99@69
|
21 #include "smalldialogs.h"
|
joachim99@69
|
22 #include "optiondialog.h"
|
joachim99@75
|
23 #include "diff.h"
|
joachim99@69
|
24
|
joachim99@75
|
25 #include <QComboBox>
|
joachim99@75
|
26 #include <QCheckBox>
|
joachim99@75
|
27 #include <QLineEdit>
|
joachim99@75
|
28 #include <QLabel>
|
joachim99@75
|
29 #include <QLayout>
|
joachim99@75
|
30 #include <QToolTip>
|
joachim99@75
|
31 #include <QUrl>
|
joachim99@75
|
32 #include <QDir>
|
joachim99@70
|
33 #include <QDropEvent>
|
joachim99@75
|
34 #include <QMenu>
|
joachim99@80
|
35 #include <QPushButton>
|
Chris@113
|
36 #include <QMimeData>
|
joachim99@69
|
37
|
joachim99@69
|
38 #include <kfiledialog.h>
|
joachim99@69
|
39 #include <klocale.h>
|
joachim99@69
|
40
|
joachim99@69
|
41 // OpenDialog **************************************************************
|
joachim99@69
|
42
|
joachim99@69
|
43 OpenDialog::OpenDialog(
|
joachim99@69
|
44 QWidget* pParent, const QString& n1, const QString& n2, const QString& n3,
|
joachim99@69
|
45 bool bMerge, const QString& outputName, const char* slotConfigure, OptionDialog* pOptions )
|
joachim99@75
|
46 : QDialog( pParent )
|
joachim99@69
|
47 {
|
joachim99@75
|
48 setObjectName("OpenDialog");
|
joachim99@75
|
49 setModal(true);
|
joachim99@69
|
50 m_pOptions = pOptions;
|
joachim99@69
|
51
|
joachim99@75
|
52 QVBoxLayout* v = new QVBoxLayout( this );
|
joachim99@75
|
53 v->setMargin(5);
|
joachim99@75
|
54 QGridLayout* h = new QGridLayout();
|
joachim99@75
|
55 v->addLayout(h);
|
joachim99@75
|
56 h->setSpacing( 5 );
|
joachim99@75
|
57 h->setColumnStretch( 1, 10 );
|
joachim99@69
|
58
|
joachim99@69
|
59 QLabel* label = new QLabel( i18n("A (Base):"), this );
|
joachim99@69
|
60
|
joachim99@75
|
61 m_pLineA = new QComboBox();
|
joachim99@75
|
62 m_pLineA->setEditable(true);
|
joachim99@75
|
63 m_pLineA->insertItems( 0, m_pOptions->m_recentAFiles );
|
joachim99@80
|
64 m_pLineA->setEditText( KUrl(n1).prettyUrl() );
|
joachim99@75
|
65 m_pLineA->setMinimumWidth( 200 );
|
joachim99@69
|
66 QPushButton * button = new QPushButton( i18n("File..."), this );
|
joachim99@69
|
67 connect( button, SIGNAL(clicked()), this, SLOT( selectFileA() ) );
|
joachim99@69
|
68 QPushButton * button2 = new QPushButton( i18n("Dir..."), this );
|
joachim99@69
|
69 connect( button2, SIGNAL(clicked()), this, SLOT( selectDirA() ) );
|
joachim99@75
|
70 connect( m_pLineA, SIGNAL(editTextChanged(const QString&)), this, SLOT(inputFilenameChanged() ) );
|
joachim99@69
|
71
|
joachim99@69
|
72 h->addWidget( label, 0, 0 );
|
joachim99@69
|
73 h->addWidget( m_pLineA, 0, 1 );
|
joachim99@69
|
74 h->addWidget( button, 0, 2 );
|
joachim99@69
|
75 h->addWidget( button2, 0, 3 );
|
joachim99@69
|
76
|
joachim99@69
|
77 label = new QLabel( "B:", this );
|
joachim99@75
|
78 m_pLineB = new QComboBox();
|
joachim99@75
|
79 m_pLineB->setEditable(true);
|
joachim99@75
|
80 m_pLineB->insertItems( 0, m_pOptions->m_recentBFiles );
|
joachim99@80
|
81 m_pLineB->setEditText( KUrl(n2).prettyUrl() );
|
joachim99@75
|
82 m_pLineB->setMinimumWidth( 200 );
|
joachim99@69
|
83 button = new QPushButton( i18n("File..."), this );
|
joachim99@69
|
84 connect( button, SIGNAL(clicked()), this, SLOT( selectFileB() ) );
|
joachim99@69
|
85 button2 = new QPushButton( i18n("Dir..."), this );
|
joachim99@69
|
86 connect( button2, SIGNAL(clicked()), this, SLOT( selectDirB() ) );
|
joachim99@75
|
87 connect( m_pLineB, SIGNAL(editTextChanged(const QString&)), this, SLOT(inputFilenameChanged() ) );
|
joachim99@69
|
88
|
joachim99@69
|
89 h->addWidget( label, 1, 0 );
|
joachim99@75
|
90 h->addWidget( m_pLineB, 1, 1 );
|
joachim99@69
|
91 h->addWidget( button, 1, 2 );
|
joachim99@69
|
92 h->addWidget( button2, 1, 3 );
|
joachim99@69
|
93
|
joachim99@69
|
94 label = new QLabel( i18n("C (Optional):"), this );
|
joachim99@75
|
95 m_pLineC= new QComboBox();
|
joachim99@75
|
96 m_pLineC->setEditable(true);
|
joachim99@75
|
97 m_pLineC->insertItems( 0, m_pOptions->m_recentCFiles );
|
joachim99@80
|
98 m_pLineC->setEditText( KUrl(n3).prettyUrl() );
|
joachim99@75
|
99 m_pLineC->setMinimumWidth( 200 );
|
joachim99@69
|
100 button = new QPushButton( i18n("File..."), this );
|
joachim99@69
|
101 connect( button, SIGNAL(clicked()), this, SLOT( selectFileC() ) );
|
joachim99@69
|
102 button2 = new QPushButton( i18n("Dir..."), this );
|
joachim99@69
|
103 connect( button2, SIGNAL(clicked()), this, SLOT( selectDirC() ) );
|
joachim99@75
|
104 connect( m_pLineC, SIGNAL(editTextChanged(const QString&)), this, SLOT(inputFilenameChanged() ) );
|
joachim99@69
|
105
|
joachim99@69
|
106 h->addWidget( label, 2, 0 );
|
joachim99@69
|
107 h->addWidget( m_pLineC, 2, 1 );
|
joachim99@69
|
108 h->addWidget( button, 2, 2 );
|
joachim99@69
|
109 h->addWidget( button2, 2, 3 );
|
joachim99@69
|
110
|
joachim99@69
|
111 m_pMerge = new QCheckBox( i18n("Merge"), this );
|
joachim99@69
|
112 h->addWidget( m_pMerge, 3, 0 );
|
joachim99@69
|
113
|
joachim99@75
|
114 QHBoxLayout* hl = new QHBoxLayout();
|
joachim99@69
|
115 h->addLayout( hl, 3, 1 );
|
joachim99@69
|
116 hl->addStretch(2);
|
joachim99@69
|
117 button = new QPushButton(i18n("Swap/Copy Names ..."), this);
|
joachim99@69
|
118 //button->setToggleButton(false);
|
joachim99@69
|
119 hl->addWidget( button );
|
joachim99@69
|
120
|
joachim99@75
|
121 QMenu* m = new QMenu(this);
|
joachim99@80
|
122 m->addAction( i18n("Swap %1<->%2", QString("A"),QString("B") ));
|
joachim99@80
|
123 m->addAction( i18n("Swap %1<->%2",QString("B"),QString("C") ));
|
joachim99@80
|
124 m->addAction( i18n("Swap %1<->%2",QString("C"),QString("A") ));
|
joachim99@80
|
125 m->addAction( i18n("Copy %1->Output",QString("A") ));
|
joachim99@80
|
126 m->addAction( i18n("Copy %1->Output",QString("B") ));
|
joachim99@80
|
127 m->addAction( i18n("Copy %1->Output",QString("C") ));
|
joachim99@80
|
128 m->addAction( i18n("Swap %1<->Output",QString("A") ));
|
joachim99@80
|
129 m->addAction( i18n("Swap %1<->Output",QString("B") ));
|
joachim99@80
|
130 m->addAction( i18n("Swap %1<->Output",QString("C") ));
|
joachim99@75
|
131 connect( m, SIGNAL(triggered(QAction*)), this, SLOT(slotSwapCopyNames(QAction*)));
|
joachim99@75
|
132 button->setMenu(m);
|
joachim99@69
|
133
|
joachim99@69
|
134
|
joachim99@69
|
135 hl->addStretch(2);
|
joachim99@69
|
136
|
joachim99@69
|
137 label = new QLabel( i18n("Output (optional):"), this );
|
joachim99@75
|
138 m_pLineOut = new QComboBox();
|
joachim99@75
|
139 m_pLineOut->setEditable(true);
|
joachim99@75
|
140 m_pLineOut->insertItems( 0, m_pOptions->m_recentOutputFiles );
|
joachim99@80
|
141 m_pLineOut->setEditText( KUrl(outputName).prettyUrl() );
|
joachim99@75
|
142 m_pLineOut->setMinimumWidth( 200 );
|
joachim99@69
|
143 button = new QPushButton( i18n("File..."), this );
|
joachim99@69
|
144 connect( button, SIGNAL(clicked()), this, SLOT( selectOutputName() ) );
|
joachim99@69
|
145 button2 = new QPushButton( i18n("Dir..."), this );
|
joachim99@69
|
146 connect( button2, SIGNAL(clicked()), this, SLOT( selectOutputDir() ) );
|
joachim99@69
|
147 connect( m_pMerge, SIGNAL(stateChanged(int)), this, SLOT(internalSlot(int)) );
|
joachim99@69
|
148 connect( this, SIGNAL(internalSignal(bool)), m_pLineOut, SLOT(setEnabled(bool)) );
|
joachim99@69
|
149 connect( this, SIGNAL(internalSignal(bool)), button, SLOT(setEnabled(bool)) );
|
joachim99@69
|
150 connect( this, SIGNAL(internalSignal(bool)), button2, SLOT(setEnabled(bool)) );
|
joachim99@69
|
151
|
joachim99@69
|
152 m_pMerge->setChecked( !bMerge );
|
joachim99@69
|
153 m_pMerge->setChecked( bMerge );
|
joachim99@69
|
154 // m_pLineOutput->setEnabled( bMerge );
|
joachim99@69
|
155
|
joachim99@69
|
156 // button->setEnabled( bMerge );
|
joachim99@69
|
157
|
joachim99@69
|
158 h->addWidget( label, 4, 0 );
|
joachim99@69
|
159 h->addWidget( m_pLineOut, 4, 1 );
|
joachim99@69
|
160 h->addWidget( button, 4, 2 );
|
joachim99@69
|
161 h->addWidget( button2, 4, 3 );
|
joachim99@69
|
162
|
joachim99@75
|
163 h->addItem(new QSpacerItem(200, 0), 0, 1);
|
joachim99@69
|
164
|
joachim99@75
|
165 QHBoxLayout* l = new QHBoxLayout();
|
joachim99@75
|
166 v->addLayout( l );
|
joachim99@75
|
167 l->setSpacing(5);
|
joachim99@69
|
168
|
joachim99@69
|
169 button = new QPushButton( i18n("Configure..."), this );
|
joachim99@69
|
170 connect( button, SIGNAL(clicked()), pParent, slotConfigure );
|
joachim99@69
|
171 l->addWidget( button, 1 );
|
joachim99@69
|
172
|
joachim99@69
|
173 l->addStretch(1);
|
joachim99@69
|
174
|
joachim99@69
|
175 button = new QPushButton( i18n("&OK"), this );
|
joachim99@69
|
176 button->setDefault( true );
|
joachim99@69
|
177 connect( button, SIGNAL(clicked()), this, SLOT( accept() ) );
|
joachim99@69
|
178 l->addWidget( button, 1 );
|
joachim99@69
|
179
|
joachim99@69
|
180 button = new QPushButton( i18n("&Cancel"), this );
|
joachim99@69
|
181 connect( button, SIGNAL(clicked()), this, SLOT( reject() ) );
|
joachim99@69
|
182 l->addWidget( button,1 );
|
joachim99@69
|
183
|
joachim99@69
|
184 QSize sh = sizeHint();
|
joachim99@69
|
185 setFixedHeight( sh.height() );
|
joachim99@69
|
186 m_bInputFileNameChanged = false;
|
joachim99@69
|
187
|
joachim99@69
|
188 #ifdef KREPLACEMENTS_H
|
joachim99@69
|
189 m_pLineA->lineEdit()->installEventFilter( this );
|
joachim99@69
|
190 m_pLineB->lineEdit()->installEventFilter( this );
|
joachim99@69
|
191 m_pLineC->lineEdit()->installEventFilter( this );
|
joachim99@69
|
192 m_pLineOut->lineEdit()->installEventFilter( this );
|
joachim99@69
|
193 #endif
|
joachim99@69
|
194 }
|
joachim99@69
|
195
|
joachim99@69
|
196 // Eventfilter: Only needed under Windows.
|
joachim99@69
|
197 // Without this, files dropped in the line edit have URL-encoding.
|
joachim99@69
|
198 // This eventfilter decodes the filenames as needed by KDiff3.
|
joachim99@69
|
199 bool OpenDialog::eventFilter(QObject* o, QEvent* e)
|
joachim99@69
|
200 {
|
joachim99@75
|
201 if ( e->type()==QEvent::DragEnter )
|
joachim99@75
|
202 {
|
joachim99@75
|
203 QDragEnterEvent* d = static_cast<QDragEnterEvent*>(e);
|
joachim99@75
|
204 d->setAccepted( d->mimeData()->hasUrls() );
|
joachim99@75
|
205 return true;
|
joachim99@75
|
206 }
|
joachim99@69
|
207 if (e->type()==QEvent::Drop)
|
joachim99@69
|
208 {
|
joachim99@69
|
209 QDropEvent* d = static_cast<QDropEvent*>(e);
|
joachim99@69
|
210
|
joachim99@75
|
211 if ( !d->mimeData()->hasUrls() )
|
joachim99@69
|
212 return false;
|
joachim99@69
|
213
|
joachim99@75
|
214 QList<QUrl> lst = d->mimeData()->urls();
|
joachim99@69
|
215
|
joachim99@69
|
216 if ( lst.count() > 0 )
|
joachim99@69
|
217 {
|
joachim99@75
|
218 static_cast<QLineEdit*>(o)->setText( QDir::toNativeSeparators( lst[0].toLocalFile() ) );
|
joachim99@69
|
219 static_cast<QLineEdit*>(o)->setFocus();
|
joachim99@69
|
220 }
|
joachim99@69
|
221
|
joachim99@69
|
222 return true;
|
joachim99@69
|
223 }
|
joachim99@69
|
224 return false;
|
joachim99@69
|
225 }
|
joachim99@69
|
226
|
joachim99@69
|
227
|
joachim99@69
|
228 void OpenDialog::selectURL( QComboBox* pLine, bool bDir, int i, bool bSave )
|
joachim99@69
|
229 {
|
joachim99@69
|
230 QString current = pLine->currentText();
|
joachim99@69
|
231 if (current.isEmpty() && i>3 ){ current = m_pLineC->currentText(); }
|
joachim99@69
|
232 if (current.isEmpty() ){ current = m_pLineB->currentText(); }
|
joachim99@69
|
233 if (current.isEmpty() ){ current = m_pLineA->currentText(); }
|
joachim99@80
|
234 KUrl newURL = bDir ? KFileDialog::getExistingDirectoryUrl( current, this)
|
joachim99@80
|
235 : bSave ? KFileDialog::getSaveUrl( current, 0, this)
|
joachim99@80
|
236 : KFileDialog::getOpenUrl( current, 0, this);
|
joachim99@69
|
237 if ( !newURL.isEmpty() )
|
joachim99@69
|
238 {
|
joachim99@69
|
239 pLine->setEditText( newURL.url() );
|
joachim99@69
|
240 }
|
joachim99@69
|
241 // newURL won't be modified if nothing was selected.
|
joachim99@69
|
242 }
|
joachim99@69
|
243
|
joachim99@69
|
244 void OpenDialog::selectFileA() { selectURL( m_pLineA, false, 1, false ); }
|
joachim99@69
|
245 void OpenDialog::selectFileB() { selectURL( m_pLineB, false, 2, false ); }
|
joachim99@69
|
246 void OpenDialog::selectFileC() { selectURL( m_pLineC, false, 3, false ); }
|
joachim99@69
|
247 void OpenDialog::selectOutputName(){ selectURL( m_pLineOut, false, 4, true ); }
|
joachim99@69
|
248 void OpenDialog::selectDirA() { selectURL( m_pLineA, true, 1, false ); }
|
joachim99@69
|
249 void OpenDialog::selectDirB() { selectURL( m_pLineB, true, 2, false ); }
|
joachim99@69
|
250 void OpenDialog::selectDirC() { selectURL( m_pLineC, true, 3, false ); }
|
joachim99@69
|
251 void OpenDialog::selectOutputDir() { selectURL( m_pLineOut, true, 4, true ); }
|
joachim99@69
|
252
|
joachim99@69
|
253 void OpenDialog::internalSlot(int i)
|
joachim99@69
|
254 {
|
joachim99@69
|
255 emit internalSignal(i!=0);
|
joachim99@69
|
256 }
|
joachim99@69
|
257
|
joachim99@69
|
258 // Clear the output-filename when any input-filename changed,
|
joachim99@69
|
259 // because users forgot to change the output and accidently overwrote it with
|
joachim99@69
|
260 // wrong data during a merge.
|
joachim99@69
|
261 void OpenDialog::inputFilenameChanged()
|
joachim99@69
|
262 {
|
joachim99@69
|
263 if(!m_bInputFileNameChanged)
|
joachim99@69
|
264 {
|
joachim99@69
|
265 m_bInputFileNameChanged=true;
|
joachim99@75
|
266 m_pLineOut->clearEditText();
|
joachim99@69
|
267 }
|
joachim99@69
|
268 }
|
joachim99@69
|
269
|
joachim99@75
|
270 static void fixCurrentText( QComboBox* pCB )
|
joachim99@75
|
271 {
|
joachim99@75
|
272 QString s = pCB->currentText();
|
joachim99@75
|
273
|
joachim99@75
|
274 int pos = s.indexOf( '\n' );
|
joachim99@75
|
275 if ( pos>=0 )
|
joachim99@75
|
276 s=s.left(pos);
|
joachim99@75
|
277 pos = s.indexOf( '\r' );
|
joachim99@75
|
278 if ( pos>=0 )
|
joachim99@75
|
279 s=s.left(pos);
|
joachim99@75
|
280
|
joachim99@75
|
281 pCB->setEditText( s );
|
joachim99@75
|
282 }
|
joachim99@75
|
283
|
joachim99@69
|
284 void OpenDialog::accept()
|
joachim99@69
|
285 {
|
joachim99@70
|
286 int maxNofRecentFiles = 10;
|
joachim99@75
|
287 fixCurrentText( m_pLineA );
|
joachim99@69
|
288
|
joachim99@69
|
289 QString s = m_pLineA->currentText();
|
joachim99@80
|
290 s = QUrl::fromLocalFile(s).toLocalFile();
|
joachim99@69
|
291 QStringList* sl = &m_pOptions->m_recentAFiles;
|
joachim99@69
|
292 // If an item exist, remove it from the list and reinsert it at the beginning.
|
joachim99@75
|
293 sl->removeAll(s);
|
joachim99@69
|
294 if ( !s.isEmpty() ) sl->prepend( s );
|
joachim99@70
|
295 if (sl->count()>maxNofRecentFiles) sl->erase( sl->begin()+maxNofRecentFiles, sl->end() );
|
joachim99@69
|
296
|
joachim99@75
|
297 fixCurrentText( m_pLineB );
|
joachim99@69
|
298 s = m_pLineB->currentText();
|
joachim99@80
|
299 s = QUrl::fromLocalFile(s).toLocalFile();
|
joachim99@69
|
300 sl = &m_pOptions->m_recentBFiles;
|
joachim99@75
|
301 sl->removeAll(s);
|
joachim99@69
|
302 if ( !s.isEmpty() ) sl->prepend( s );
|
joachim99@70
|
303 if (sl->count()>maxNofRecentFiles) sl->erase( sl->begin()+maxNofRecentFiles, sl->end() );
|
joachim99@69
|
304
|
joachim99@75
|
305 fixCurrentText( m_pLineC );
|
joachim99@69
|
306 s = m_pLineC->currentText();
|
joachim99@80
|
307 s = QUrl::fromLocalFile(s).toLocalFile();
|
joachim99@69
|
308 sl = &m_pOptions->m_recentCFiles;
|
joachim99@75
|
309 sl->removeAll(s);
|
joachim99@69
|
310 if ( !s.isEmpty() ) sl->prepend( s );
|
joachim99@70
|
311 if (sl->count()>maxNofRecentFiles) sl->erase( sl->begin()+maxNofRecentFiles, sl->end() );
|
joachim99@69
|
312
|
joachim99@75
|
313 fixCurrentText( m_pLineOut );
|
joachim99@69
|
314 s = m_pLineOut->currentText();
|
joachim99@80
|
315 s = QUrl::fromLocalFile(s).toLocalFile();
|
joachim99@69
|
316 sl = &m_pOptions->m_recentOutputFiles;
|
joachim99@75
|
317 sl->removeAll(s);
|
joachim99@69
|
318 if ( !s.isEmpty() ) sl->prepend( s );
|
joachim99@70
|
319 if (sl->count()>maxNofRecentFiles) sl->erase( sl->begin()+maxNofRecentFiles, sl->end() );
|
joachim99@69
|
320
|
joachim99@69
|
321 QDialog::accept();
|
joachim99@69
|
322 }
|
joachim99@69
|
323
|
joachim99@75
|
324 void OpenDialog::slotSwapCopyNames( QAction* pAction ) // id selected in the popup menu
|
joachim99@69
|
325 {
|
joachim99@75
|
326 int id = pAction->parentWidget()->actions().indexOf(pAction);
|
joachim99@69
|
327 QComboBox* cb1=0;
|
joachim99@69
|
328 QComboBox* cb2=0;
|
joachim99@69
|
329 switch(id)
|
joachim99@69
|
330 {
|
joachim99@69
|
331 case 0: cb1=m_pLineA; cb2=m_pLineB; break;
|
joachim99@69
|
332 case 1: cb1=m_pLineB; cb2=m_pLineC; break;
|
joachim99@69
|
333 case 2: cb1=m_pLineC; cb2=m_pLineA; break;
|
joachim99@69
|
334 case 3: cb1=m_pLineA; cb2=m_pLineOut; break;
|
joachim99@69
|
335 case 4: cb1=m_pLineB; cb2=m_pLineOut; break;
|
joachim99@69
|
336 case 5: cb1=m_pLineC; cb2=m_pLineOut; break;
|
joachim99@69
|
337 case 6: cb1=m_pLineA; cb2=m_pLineOut; break;
|
joachim99@69
|
338 case 7: cb1=m_pLineB; cb2=m_pLineOut; break;
|
joachim99@69
|
339 case 8: cb1=m_pLineC; cb2=m_pLineOut; break;
|
joachim99@69
|
340 }
|
joachim99@69
|
341 if ( cb1 && cb2 )
|
joachim99@69
|
342 {
|
joachim99@69
|
343 QString t1 = cb1->currentText();
|
joachim99@69
|
344 QString t2 = cb2->currentText();
|
joachim99@75
|
345 cb2->setEditText(t1);
|
joachim99@69
|
346 if ( id<=2 || id>=6 )
|
joachim99@69
|
347 {
|
joachim99@75
|
348 cb1->setEditText( t2 );
|
joachim99@69
|
349 }
|
joachim99@69
|
350 }
|
joachim99@69
|
351 }
|
joachim99@69
|
352
|
joachim99@69
|
353 // FindDialog *********************************************
|
joachim99@69
|
354
|
joachim99@69
|
355 FindDialog::FindDialog(QWidget* pParent)
|
joachim99@69
|
356 : QDialog( pParent )
|
joachim99@69
|
357 {
|
joachim99@75
|
358 QGridLayout* layout = new QGridLayout( this );
|
joachim99@69
|
359 layout->setMargin(5);
|
joachim99@69
|
360 layout->setSpacing(5);
|
joachim99@69
|
361
|
joachim99@69
|
362 int line=0;
|
joachim99@75
|
363 layout->addWidget( new QLabel(i18n("Search text:"),this), line, 0, 1, 2 );
|
joachim99@69
|
364 ++line;
|
joachim99@69
|
365
|
joachim99@69
|
366 m_pSearchString = new QLineEdit( this );
|
joachim99@75
|
367 layout->addWidget( m_pSearchString, line, 0, 1, 2 );
|
joachim99@69
|
368 ++line;
|
joachim99@69
|
369
|
joachim99@69
|
370 m_pCaseSensitive = new QCheckBox(i18n("Case sensitive"),this);
|
joachim99@69
|
371 layout->addWidget( m_pCaseSensitive, line, 1 );
|
joachim99@69
|
372
|
joachim99@69
|
373 m_pSearchInA = new QCheckBox(i18n("Search A"),this);
|
joachim99@69
|
374 layout->addWidget( m_pSearchInA, line, 0 );
|
joachim99@69
|
375 m_pSearchInA->setChecked( true );
|
joachim99@69
|
376 ++line;
|
joachim99@69
|
377
|
joachim99@69
|
378 m_pSearchInB = new QCheckBox(i18n("Search B"),this);
|
joachim99@69
|
379 layout->addWidget( m_pSearchInB, line, 0 );
|
joachim99@69
|
380 m_pSearchInB->setChecked( true );
|
joachim99@69
|
381 ++line;
|
joachim99@69
|
382
|
joachim99@69
|
383 m_pSearchInC = new QCheckBox(i18n("Search C"),this);
|
joachim99@69
|
384 layout->addWidget( m_pSearchInC, line, 0 );
|
joachim99@69
|
385 m_pSearchInC->setChecked( true );
|
joachim99@69
|
386 ++line;
|
joachim99@69
|
387
|
joachim99@69
|
388 m_pSearchInOutput = new QCheckBox(i18n("Search output"),this);
|
joachim99@69
|
389 layout->addWidget( m_pSearchInOutput, line, 0 );
|
joachim99@69
|
390 m_pSearchInOutput->setChecked( true );
|
joachim99@69
|
391 ++line;
|
joachim99@69
|
392
|
joachim99@69
|
393 QPushButton* pButton = new QPushButton( i18n("&Search"), this );
|
joachim99@69
|
394 layout->addWidget( pButton, line, 0 );
|
joachim99@69
|
395 connect( pButton, SIGNAL(clicked()), this, SLOT(accept()));
|
joachim99@69
|
396
|
joachim99@69
|
397 pButton = new QPushButton( i18n("&Cancel"), this );
|
joachim99@69
|
398 layout->addWidget( pButton, line, 1 );
|
joachim99@69
|
399 connect( pButton, SIGNAL(clicked()), this, SLOT(reject()));
|
joachim99@69
|
400
|
joachim99@69
|
401 hide();
|
joachim99@69
|
402 }
|
joachim99@69
|
403
|
joachim99@69
|
404
|
joachim99@69
|
405 RegExpTester::RegExpTester( QWidget* pParent, const QString& autoMergeRegExpToolTip,
|
joachim99@69
|
406 const QString& historyStartRegExpToolTip, const QString& historyEntryStartRegExpToolTip, const QString& historySortKeyOrderToolTip )
|
joachim99@69
|
407 : QDialog( pParent)
|
joachim99@69
|
408 {
|
joachim99@69
|
409 int line=0;
|
joachim99@75
|
410 setWindowTitle(i18n("Regular Expression Tester"));
|
joachim99@75
|
411 QGridLayout* pGrid = new QGridLayout( this );
|
joachim99@75
|
412 pGrid->setSpacing(5);
|
joachim99@75
|
413 pGrid->setMargin(5);
|
joachim99@69
|
414
|
joachim99@69
|
415 QLabel* l = new QLabel(i18n("Auto merge regular expression:"), this);
|
joachim99@69
|
416 pGrid->addWidget(l,line,0);
|
joachim99@75
|
417 l->setToolTip( autoMergeRegExpToolTip );
|
joachim99@69
|
418 m_pAutoMergeRegExpEdit = new QLineEdit(this);
|
joachim99@69
|
419 pGrid->addWidget(m_pAutoMergeRegExpEdit,line,1);
|
joachim99@98
|
420 connect( m_pAutoMergeRegExpEdit, SIGNAL(textChanged(const QString&)), this, SLOT(slotRecalc()));
|
joachim99@69
|
421 ++line;
|
joachim99@69
|
422
|
joachim99@69
|
423 l = new QLabel(i18n("Example auto merge line:"), this);
|
joachim99@98
|
424 pGrid->addWidget(l,line,0);
|
joachim99@75
|
425 l->setToolTip( i18n("For auto merge test copy a line as used in your files.") );
|
joachim99@69
|
426 m_pAutoMergeExampleEdit = new QLineEdit(this);
|
joachim99@69
|
427 pGrid->addWidget(m_pAutoMergeExampleEdit,line,1);
|
joachim99@98
|
428 connect( m_pAutoMergeExampleEdit, SIGNAL(textChanged(const QString&)), this, SLOT(slotRecalc()));
|
joachim99@69
|
429 ++line;
|
joachim99@69
|
430
|
joachim99@69
|
431 l = new QLabel(i18n("Match result:"), this);
|
joachim99@69
|
432 pGrid->addWidget(l,line,0);
|
joachim99@69
|
433 m_pAutoMergeMatchResult = new QLineEdit(this);
|
joachim99@69
|
434 m_pAutoMergeMatchResult->setReadOnly(true);
|
joachim99@69
|
435 pGrid->addWidget(m_pAutoMergeMatchResult,line,1);
|
joachim99@69
|
436 ++line;
|
joachim99@69
|
437
|
joachim99@69
|
438 pGrid->addItem( new QSpacerItem(100,20), line, 0 );
|
joachim99@69
|
439 pGrid->setRowStretch( line, 5);
|
joachim99@69
|
440 ++line;
|
joachim99@69
|
441
|
joachim99@69
|
442 l = new QLabel(i18n("History start regular expression:"), this);
|
joachim99@69
|
443 pGrid->addWidget(l,line,0);
|
joachim99@75
|
444 l->setToolTip( historyStartRegExpToolTip );
|
joachim99@69
|
445 m_pHistoryStartRegExpEdit = new QLineEdit(this);
|
joachim99@69
|
446 pGrid->addWidget(m_pHistoryStartRegExpEdit,line,1);
|
joachim99@98
|
447 connect( m_pHistoryStartRegExpEdit, SIGNAL(textChanged(const QString&)), this, SLOT(slotRecalc()));
|
joachim99@69
|
448 ++line;
|
joachim99@69
|
449
|
joachim99@69
|
450 l = new QLabel(i18n("Example history start line (with leading comment):"), this);
|
joachim99@98
|
451 pGrid->addWidget(l,line,0);
|
joachim99@75
|
452 l->setToolTip( i18n("Copy a history start line as used in your files,\n"
|
joachim99@69
|
453 "including the leading comment.") );
|
joachim99@69
|
454 m_pHistoryStartExampleEdit = new QLineEdit(this);
|
joachim99@69
|
455 pGrid->addWidget(m_pHistoryStartExampleEdit,line,1);
|
joachim99@98
|
456 connect( m_pHistoryStartExampleEdit, SIGNAL(textChanged(const QString&)), this, SLOT(slotRecalc()));
|
joachim99@69
|
457 ++line;
|
joachim99@69
|
458
|
joachim99@69
|
459 l = new QLabel(i18n("Match result:"), this);
|
joachim99@69
|
460 pGrid->addWidget(l,line,0);
|
joachim99@69
|
461 m_pHistoryStartMatchResult = new QLineEdit(this);
|
joachim99@69
|
462 m_pHistoryStartMatchResult->setReadOnly(true);
|
joachim99@69
|
463 pGrid->addWidget(m_pHistoryStartMatchResult,line,1);
|
joachim99@69
|
464 ++line;
|
joachim99@69
|
465
|
joachim99@69
|
466 pGrid->addItem( new QSpacerItem(100,20), line, 0 );
|
joachim99@69
|
467 pGrid->setRowStretch( line, 5);
|
joachim99@69
|
468 ++line;
|
joachim99@69
|
469
|
joachim99@69
|
470 l = new QLabel(i18n("History entry start regular expression:"), this);
|
joachim99@69
|
471 pGrid->addWidget(l,line,0);
|
joachim99@75
|
472 l->setToolTip( historyEntryStartRegExpToolTip );
|
joachim99@69
|
473 m_pHistoryEntryStartRegExpEdit = new QLineEdit(this);
|
joachim99@69
|
474 pGrid->addWidget(m_pHistoryEntryStartRegExpEdit,line,1);
|
joachim99@98
|
475 connect( m_pHistoryEntryStartRegExpEdit, SIGNAL(textChanged(const QString&)), this, SLOT(slotRecalc()));
|
joachim99@69
|
476 ++line;
|
joachim99@69
|
477
|
joachim99@69
|
478 l = new QLabel(i18n("History sort key order:"), this);
|
joachim99@69
|
479 pGrid->addWidget(l,line,0);
|
joachim99@75
|
480 l->setToolTip( historySortKeyOrderToolTip );
|
joachim99@69
|
481 m_pHistorySortKeyOrderEdit = new QLineEdit(this);
|
joachim99@69
|
482 pGrid->addWidget(m_pHistorySortKeyOrderEdit,line,1);
|
joachim99@98
|
483 connect( m_pHistorySortKeyOrderEdit, SIGNAL(textChanged(const QString&)), this, SLOT(slotRecalc()));
|
joachim99@69
|
484 ++line;
|
joachim99@69
|
485
|
joachim99@69
|
486 l = new QLabel(i18n("Example history entry start line (without leading comment):"), this);
|
joachim99@98
|
487 pGrid->addWidget(l,line,0);
|
joachim99@75
|
488 l->setToolTip( i18n("Copy a history entry start line as used in your files,\n"
|
joachim99@69
|
489 "but omit the leading comment.") );
|
joachim99@69
|
490 m_pHistoryEntryStartExampleEdit = new QLineEdit(this);
|
joachim99@69
|
491 pGrid->addWidget(m_pHistoryEntryStartExampleEdit,line,1);
|
joachim99@98
|
492 connect( m_pHistoryEntryStartExampleEdit, SIGNAL(textChanged(const QString&)), this, SLOT(slotRecalc()));
|
joachim99@69
|
493 ++line;
|
joachim99@69
|
494
|
joachim99@69
|
495 l = new QLabel(i18n("Match result:"), this);
|
joachim99@69
|
496 pGrid->addWidget(l,line,0);
|
joachim99@69
|
497 m_pHistoryEntryStartMatchResult = new QLineEdit(this);
|
joachim99@69
|
498 m_pHistoryEntryStartMatchResult->setReadOnly(true);
|
joachim99@69
|
499 pGrid->addWidget(m_pHistoryEntryStartMatchResult,line,1);
|
joachim99@69
|
500 ++line;
|
joachim99@69
|
501
|
joachim99@69
|
502 l = new QLabel(i18n("Sort key result:"), this);
|
joachim99@69
|
503 pGrid->addWidget(l,line,0);
|
joachim99@69
|
504 m_pHistorySortKeyResult = new QLineEdit(this);
|
joachim99@69
|
505 m_pHistorySortKeyResult->setReadOnly(true);
|
joachim99@69
|
506 pGrid->addWidget(m_pHistorySortKeyResult,line,1);
|
joachim99@69
|
507 ++line;
|
joachim99@69
|
508
|
joachim99@69
|
509 QPushButton* pButton = new QPushButton(i18n("OK"), this);
|
joachim99@69
|
510 pGrid->addWidget(pButton,line,0);
|
joachim99@69
|
511 connect( pButton, SIGNAL(clicked()), this, SLOT(accept()));
|
joachim99@69
|
512
|
joachim99@69
|
513 pButton = new QPushButton(i18n("Cancel"), this);
|
joachim99@69
|
514 pGrid->addWidget(pButton,line,1);
|
joachim99@69
|
515 connect( pButton, SIGNAL(clicked()), this, SLOT(reject()));
|
joachim99@69
|
516
|
joachim99@69
|
517 resize( 800, sizeHint().height() );
|
joachim99@69
|
518 }
|
joachim99@69
|
519
|
joachim99@69
|
520 void RegExpTester::init( const QString& autoMergeRegExp, const QString& historyStartRegExp, const QString& historyEntryStartRegExp, const QString historySortKeyOrder )
|
joachim99@69
|
521 {
|
joachim99@69
|
522 m_pAutoMergeRegExpEdit->setText( autoMergeRegExp );
|
joachim99@69
|
523 m_pHistoryStartRegExpEdit->setText( historyStartRegExp );
|
joachim99@69
|
524 m_pHistoryEntryStartRegExpEdit->setText( historyEntryStartRegExp );
|
joachim99@69
|
525 m_pHistorySortKeyOrderEdit->setText( historySortKeyOrder );
|
joachim99@69
|
526 }
|
joachim99@69
|
527
|
joachim99@69
|
528 QString RegExpTester::autoMergeRegExp()
|
joachim99@69
|
529 {
|
joachim99@69
|
530 return m_pAutoMergeRegExpEdit->text();
|
joachim99@69
|
531 }
|
joachim99@69
|
532
|
joachim99@69
|
533 QString RegExpTester::historyStartRegExp()
|
joachim99@69
|
534 {
|
joachim99@69
|
535 return m_pHistoryStartRegExpEdit->text();
|
joachim99@69
|
536 }
|
joachim99@69
|
537
|
joachim99@69
|
538 QString RegExpTester::historyEntryStartRegExp()
|
joachim99@69
|
539 {
|
joachim99@69
|
540 return m_pHistoryEntryStartRegExpEdit->text();
|
joachim99@69
|
541 }
|
joachim99@69
|
542
|
joachim99@69
|
543 QString RegExpTester::historySortKeyOrder()
|
joachim99@69
|
544 {
|
joachim99@69
|
545 return m_pHistorySortKeyOrderEdit->text();
|
joachim99@69
|
546 }
|
joachim99@69
|
547
|
joachim99@69
|
548 void RegExpTester::slotRecalc()
|
joachim99@69
|
549 {
|
joachim99@70
|
550 QRegExp autoMergeRegExp( m_pAutoMergeRegExpEdit->text() );
|
joachim99@69
|
551 if ( autoMergeRegExp.exactMatch( m_pAutoMergeExampleEdit->text() ) )
|
joachim99@69
|
552 {
|
joachim99@69
|
553 m_pAutoMergeMatchResult->setText( i18n("Match success.") );
|
joachim99@69
|
554 }
|
joachim99@69
|
555 else
|
joachim99@69
|
556 {
|
joachim99@69
|
557 m_pAutoMergeMatchResult->setText( i18n("Match failed.") );
|
joachim99@69
|
558 }
|
joachim99@69
|
559
|
joachim99@70
|
560 QRegExp historyStartRegExp( m_pHistoryStartRegExpEdit->text() );
|
joachim99@69
|
561 if ( historyStartRegExp.exactMatch( m_pHistoryStartExampleEdit->text() ) )
|
joachim99@69
|
562 {
|
joachim99@69
|
563 m_pHistoryStartMatchResult->setText( i18n("Match success.") );
|
joachim99@69
|
564 }
|
joachim99@69
|
565 else
|
joachim99@69
|
566 {
|
joachim99@69
|
567 m_pHistoryStartMatchResult->setText( i18n("Match failed.") );
|
joachim99@69
|
568 }
|
joachim99@69
|
569
|
joachim99@69
|
570
|
joachim99@69
|
571 QStringList parenthesesGroups;
|
joachim99@69
|
572 bool bSuccess = findParenthesesGroups( m_pHistoryEntryStartRegExpEdit->text(), parenthesesGroups );
|
joachim99@69
|
573 if ( ! bSuccess )
|
joachim99@69
|
574 {
|
joachim99@69
|
575 m_pHistoryEntryStartMatchResult->setText( i18n("Opening and closing parentheses don't match in regular expression.") );
|
joachim99@80
|
576 m_pHistorySortKeyResult->setText( "" );
|
joachim99@69
|
577 return;
|
joachim99@69
|
578 }
|
joachim99@70
|
579 QRegExp historyEntryStartRegExp( m_pHistoryEntryStartRegExpEdit->text() );
|
joachim99@69
|
580 QString s = m_pHistoryEntryStartExampleEdit->text();
|
joachim99@69
|
581
|
joachim99@69
|
582 if ( historyEntryStartRegExp.exactMatch( s ) )
|
joachim99@69
|
583 {
|
joachim99@69
|
584 m_pHistoryEntryStartMatchResult->setText( i18n("Match success.") );
|
joachim99@69
|
585 QString key = calcHistorySortKey( m_pHistorySortKeyOrderEdit->text(),historyEntryStartRegExp,parenthesesGroups);
|
joachim99@69
|
586 m_pHistorySortKeyResult->setText(key);
|
joachim99@69
|
587 }
|
joachim99@69
|
588 else
|
joachim99@69
|
589 {
|
joachim99@69
|
590 m_pHistoryEntryStartMatchResult->setText( i18n("Match failed.") );
|
joachim99@80
|
591 m_pHistorySortKeyResult->setText( "" );
|
joachim99@69
|
592 }
|
joachim99@69
|
593 }
|
joachim99@69
|
594
|
joachim99@70
|
595 //#include "smalldialogs.moc"
|