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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
|
/*
* khexedit - Versatile hex editor
* Copyright (C) 1999-2000 Espen Sand, [email protected]
*
* 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 <qcheckbox.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <qspinbox.h>
#include <kconfig.h>
#include <kglobalsettings.h>
#include <klocale.h>
#include <kmessagebox.h>
#include "listview.h"
#include "stringdialog.h"
#include <qpushbutton.h>
CStringDialog::CStringDialog( QWidget *parent, const char *name, bool modal )
: KDialogBase( Plain, i18n("Extract Strings"), Help|User1|Cancel, User1,
parent, name, modal, true, i18n("&Update") ),
mMaxLength(0), mBusy(false), mDirty(false)
{
setHelp( "khexedit/khexedit.html", QString::null );
QString text;
QVBoxLayout *topLayout = new QVBoxLayout( plainPage(), 0, spacingHint() );
QGridLayout *glay = new QGridLayout( 3, 3, spacingHint() );
topLayout->addLayout( glay );
glay->setColStretch( 1, 10 );
mLengthSpin = new QSpinBox( plainPage() );
mLengthSpin->setMinimumWidth( fontMetrics().maxWidth()*17 );
mLengthSpin->setRange( 1, 1000000 );
mLengthSpin->setValue( 4 );
glay->addMultiCellWidget( mLengthSpin, 0, 0, 1, 2 );
text = i18n("&Minimum length:");
QLabel *label = new QLabel( mLengthSpin, text, plainPage() );
glay->addWidget( label, 0, 0, AlignRight );
mFilter = new QLineEdit( plainPage() );
mFilter->setMinimumWidth( fontMetrics().maxWidth()*17 );
mFilter->setText("*");
glay->addWidget( mFilter, 1, 1 );
text = i18n("&Filter:");
label = new QLabel( mFilter, text, plainPage() );
glay->addWidget( label, 1, 0, AlignRight );
QPushButton *useButton = new QPushButton( plainPage(), "use" );
useButton->setText( i18n("&Use") );
useButton->setAutoDefault( false );
connect( useButton, SIGNAL(clicked()),this,SLOT(slotUser1()) );
glay->addWidget( useButton, 1, 2 );
QWidget *helper = new QWidget( plainPage() );
glay->addMultiCellWidget( helper, 2, 2, 1, 2 );
QHBoxLayout *hlay = new QHBoxLayout( helper, 0, spacingHint() );
text = i18n("&Ignore case");
mIgnoreCaseCheck = new QCheckBox( text, helper );
hlay->addWidget( mIgnoreCaseCheck );
text = i18n("Show offset as &decimal");
mOffsetDecimalCheck = new QCheckBox( text, helper );
hlay->addWidget( mOffsetDecimalCheck );
hlay->addStretch(10);
//
// Using listview as suggested by Dima Rogozin <[email protected]>
//
mStringList = new CListView( plainPage(), "stringList" );
mStringList->setFont( KGlobalSettings::fixedFont() );
mStringList->addColumn( i18n("Offset") );
mStringList->addColumn( i18n("String") );
mStringList->setAllColumnsShowFocus( true );
mStringList->setFrameStyle( QFrame::WinPanel + QFrame::Sunken );
connect( mStringList, SIGNAL(selectionChanged()),
SLOT(selectionChanged()));
topLayout->addWidget( mStringList, 10 );
hlay = new QHBoxLayout( topLayout );
text = i18n("Number of strings:");
label = new QLabel( text, plainPage() );
hlay->addWidget( label, AlignLeft );
mListSizeLabel = new QLabel( QString(), plainPage() );
mListSizeLabel->setFixedWidth( fontMetrics().maxWidth()*10 );
hlay->addWidget( mListSizeLabel, AlignLeft|AlignHCenter );
text = i18n("Displayed:");
label = new QLabel( text, plainPage() );
hlay->addWidget( label, AlignLeft );
mDisplaySizeLabel = new QLabel( QString(""), plainPage() );
mDisplaySizeLabel->setFixedWidth( fontMetrics().maxWidth()*10 );
hlay->addWidget( mDisplaySizeLabel, AlignLeft|AlignHCenter);
hlay->addStretch( 10 );
mDirtyLabel = new QLabel( plainPage() );
topLayout->addWidget( mDirtyLabel );
readConfiguration();
//
// The initial width of the columns are set in updateListInfo()
//
updateListInfo();
mStringList->setVisibleItem( 15 );
startTimer(100);
}
CStringDialog::~CStringDialog( void )
{
writeConfiguration();
}
void CStringDialog::showEvent( QShowEvent *e )
{
KDialogBase::showEvent(e);
mLengthSpin->setFocus();
}
void CStringDialog::readConfiguration( void )
{
KConfig &config = *kapp->config();
config.setGroup( "String Dialog" );
mLengthSpin->setValue( config.readNumEntry("MinimumLength", 4) );
mFilter->setText( config.readEntry("FilterText", "*") );
mIgnoreCaseCheck->setChecked( config.readBoolEntry("IgnoreCase", false) );
mOffsetDecimalCheck->setChecked(
config.readBoolEntry("OffsetAsDecimal", false ) );
}
void CStringDialog::writeConfiguration( void )
{
KConfig &config = *kapp->config();
config.setGroup( "String Dialog" );
config.writeEntry( "MinimumLength", mLengthSpin->value() );
config.writeEntry( "FilterText", mFilter->text() );
config.writeEntry( "IgnoreCase", mIgnoreCaseCheck->isChecked() );
config.writeEntry( "OffsetAsDecimal", mOffsetDecimalCheck->isChecked() );
config.sync();
}
void CStringDialog::slotUser1( void ) // Start
{
if( mBusy == true )
{
return;
}
mRegExp.setCaseSensitive( mIgnoreCaseCheck->isChecked() == false );
mRegExp.setWildcard( true );
if( mFilter->text().isEmpty() == true )
{
mRegExp.setPattern("*");
}
else
{
mRegExp.setPattern(mFilter->text());
}
if( mRegExp.isValid() == false )
{
QString msg = i18n(""
"The filter expression you have specified is illegal. "
"You must specify a valid regular expression.\n"
"Continue without filter?");
int reply = KMessageBox::warningContinueCancel( this, msg, i18n("Extract Strings"));
if( reply != KMessageBox::Continue )
{
return;
}
mRegExp.setPattern( "*");
}
mStringData.minLength = mLengthSpin->value();
mStringData.decimalOffset = mOffsetDecimalCheck->isChecked();
removeList();
mBusy = true;
emit collect();
mBusy = false;
}
void CStringDialog::startGoto( QListViewItem *item )
{
QString str_offset = item->text(0);
QString string = item->text(1);
uint offset;
if( stringData().decimalOffset == true )
{
// sscanf( str_offset.ascii(), "%u", &offset );
offset = str_offset.toInt();
}
else
{
uint val1,val2;
// #### Rewrite it do it doesn't need the .ascii() call
sscanf( str_offset.ascii(), "%X:%X", &val1, &val2 );
offset = (val1<<16) + val2;
}
uint size = string.length();
emit markText( offset, size, true );
}
void CStringDialog::setDirty( void )
{
if( mDirty == true )
{
return;
}
mDirtyLabel->setText(
i18n("Warning: Document has been modified since last update"));
mDirty = true;
}
void CStringDialog::setClean( void )
{
if( mDirty == false )
{
return;
}
mDirtyLabel->setText("");
mDirty = false;
}
void CStringDialog::selectionChanged()
{
killTimers();
startTimer( 200 );
}
void CStringDialog::timerEvent( QTimerEvent * )
{
killTimers();
QListViewItem *item = mStringList->currentItem();
if( item == 0 )
{
slotUser1();
return;
}
startGoto( item );
}
void CStringDialog::resizeEvent( QResizeEvent * )
{
setColumnWidth();
}
int CStringDialog::updateList( CProgress &p )
{
clearList();
enableList( false );
int offsetLen = stringData().offsetLen();
QPtrList<QString> &list = stringData().list();
for( const QString *str = list.first(); str != 0; str = list.next() )
{
appendListItem( *str, offsetLen );
mMaxLength = QMAX( mMaxLength, str->length() );
if( p.expired() == true )
{
int errCode = p.step( (float)list.at()/(float)list.count() );
if( errCode == Err_Stop )
{
p.finish();
return( Err_Success );
}
}
}
p.finish();
updateListInfo();
enableList( true );
return( Err_Success );
}
void CStringDialog::clearList( void )
{
if( mStringList->childCount() > 0 )
{
mStringList->clear();
mStringList->update();
}
mMaxLength = 0;
updateListInfo();
setClean();
}
void CStringDialog::removeList( void )
{
mStringData.clear();
clearList();
}
void CStringDialog::enableList( bool state )
{
mStringList->setEnabled( state );
if( state == true )
{
mStringList->update();
}
}
void CStringDialog::appendListItem( const QString &str, uint offsetLen )
{
if( mRegExp.search ( str, offsetLen ) != -1 )
{
new QListViewItem( mStringList, str.left(offsetLen), str.mid(offsetLen) );
}
}
void CStringDialog::updateListInfo( void )
{
mListSizeLabel->setText( QString("%1").arg(mStringData.count()) );
mDisplaySizeLabel->setText( QString("%1").arg(mStringList->childCount()) );
setColumnWidth();
}
void CStringDialog::setColumnWidth( void )
{
const QFontMetrics &fm = mStringList->fontMetrics();
if( mStringData.count() == 0 )
{
int w1 = fm.maxWidth() * (stringData().offsetLen() + 2);
int w2 = mStringList->viewport()->width() - w1;
mStringList->setColumnWidth( 0, w1 );
mStringList->setColumnWidth( 1, w2 );
}
else
{
int w1 = fm.maxWidth() * (stringData().offsetLen() + 2);
int w2 = fm.maxWidth() * mMaxLength - w1;
if( w2 < 0 )
{
w2 = mStringList->viewport()->width() - w1;
}
mStringList->setColumnWidth( 0, w1 );
mStringList->setColumnWidth( 1, w2 );
}
}
#include "stringdialog.moc"
|