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
|
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you wish to add, delete or rename functions or slots use
** Qt Designer which will update this file, preserving your code. Create an
** init() function in place of a constructor, and a destroy() function in
** place of a destructor.
*****************************************************************************/
#include <qapplication.h>
#include <qcursor.h>
#include <qeventloop.h>
#include <qfile.h>
#include <qfiledialog.h>
#include <qfileinfo.h>
#include <qlineedit.h>
#include <qmessagebox.h>
#include <qpushbutton.h>
#include <qtimer.h>
void Distributor::init()
{
timer = new QTimer( this );
connect( timer, SIGNAL(timeout()), SLOT(checkLibData()) );
cancelButton()->setAutoDefault( FALSE );
backButton()->setAutoDefault( FALSE );
setNextEnabled( selectLibrary, FALSE );
setHelpEnabled( selectLibrary, FALSE );
setHelpEnabled( modifyPaths, FALSE );
setHelpEnabled( verifyMods, FALSE );
setFinishEnabled( verifyMods, TRUE );
}
void Distributor::showPage( QWidget *page )
{
if ( page == selectLibrary ) {
nextButton()->setDefault( TRUE );
libFilename->setFocus();
} else if ( page == modifyPaths ) {
nextButton()->setDefault( TRUE );
prefixPath->selectAll();
prefixPath->setFocus();
} else if ( page == verifyMods ) {
finishButton()->setDefault( TRUE );
finishButton()->setFocus();
QString labeltext =
tr("<p><b>Current Library File:</b> %1</p>"
"<table border=0>"
"<tr><td><b>New Installation Prefix:</b></td><td>%2</td></tr>"
"<tr><td></td><td></td></tr>"
"<tr><td><b>Binaries Path:</b></td><td>%3</td></tr>"
"<tr><td><b>Documentation Path:</b></td><td>%4</td></tr>"
"<tr><td><b>Headers Path:</b></td><td>%5</td></tr>"
"<tr><td><b>Libraries Path:</b></td><td>%6</td></tr>"
"<tr><td><b>Plugins Path:</b></td><td>%7</td></tr>"
"<tr><td><b>Data Path:</b></td><td>%8</td></tr>"
"</table>"
"<p>Please verify that these options are correct. Press the "
"<i>Finish</i> button to apply these modifications to the Qt "
"library. Use the <i>Back</i> button to make corrections. Use "
"the <i>Cancel</i> button to abort.</p>")
.arg( libFilename->text() )
.arg( prefixPath->text() )
.arg( binPath->text() )
.arg( docPath->text() )
.arg( hdrPath->text() )
.arg( libPath->text() )
.arg( plgPath->text() )
.arg( datPath->text() );
textLabel4->setText( labeltext );
}
QWizard::showPage( page );
}
void Distributor::checkLibFilename( const QString &filename )
{
setNextEnabled( selectLibrary, FALSE );
QFileInfo fileinfo( filename );
if ( ! filename.isEmpty() && fileinfo.exists() &&
fileinfo.isReadable() && fileinfo.isWritable() &&
fileinfo.isFile() && !fileinfo.isSymLink() )
timer->start( 500, TRUE );
}
void Distributor::browseLibFilename()
{
QString filename =
QFileDialog::getOpenFileName( QString::null, QString::null, this );
libFilename->setText( filename );
}
static char *find_pattern( char *h, const char *n, ulong hlen )
{
if ( ! h || ! n || hlen == 0 )
return 0;
#ifdef Q_OS_UNIX
size_t nlen;
#else
ulong nlen;
#endif
char nc = *n++;
nlen = strlen( n );
char hc;
do {
do {
hc = *h++;
if ( hlen-- < 1 )
return 0;
} while ( hc != nc );
if ( nlen > hlen )
return 0;
} while ( qstrncmp( h, n, nlen ) != 0 );
return h + nlen;
}
void Distributor::checkLibData()
{
struct step {
const char *key;
QCString value;
bool done;
} steps[7];
steps[0].key = "qt_nstpath=";
steps[0].done = FALSE;
steps[1].key = "qt_binpath=";
steps[1].done = FALSE;
steps[2].key = "qt_docpath=";
steps[2].done = FALSE;
steps[3].key = "qt_hdrpath=";
steps[3].done = FALSE;
steps[4].key = "qt_libpath=";
steps[4].done = FALSE;
steps[5].key = "qt_plgpath=";
steps[5].done = FALSE;
steps[6].key = "qt_datpath=";
steps[6].done = FALSE;
uint completed = 0;
uint total_steps = sizeof(steps) / sizeof(step);
QFile file( libFilename->text() );
if ( file.open( IO_ReadOnly ) ) {
QApplication::setOverrideCursor( WaitCursor );
// instead of reading in the entire file, do the search in chunks
char data[60000];
ulong offset = 0;
while ( ! file.atEnd() && completed < total_steps ) {
QApplication::eventLoop()->processEvents( QEventLoop::ExcludeUserInput );
ulong len = file.readBlock( data, sizeof(data) );
if ( len < 267 ) {
// not enough room to make any modifications... stop
break;
}
for ( uint x = 0; x < total_steps; ++x ) {
if ( steps[x].done ) continue;
char *s = find_pattern( data, steps[x].key, len );
if ( s ) {
ulong where = s - data;
if ( len - where < 256 ) {
// not enough space left to write the full
// path... move the file pointer back to just
// before the pattern and continue
offset += where - 11;
file.at( offset );
len = file.readBlock( data, sizeof(data) );
--x; // retry the current step
continue;
}
steps[x].value = s;
steps[x].done = TRUE;
++completed;
}
}
// move to the new read position
offset += len - 11;
file.at( offset );
}
file.close();
QApplication::restoreOverrideCursor();
}
if ( completed == total_steps ) {
setNextEnabled( selectLibrary, TRUE );
QString prefix = QFile::decodeName( steps[0].value );
prefixPath->setText( prefix );
QString def_bin = prefix + QString::fromLatin1( "/bin" );
QString def_doc = prefix + QString::fromLatin1( "/doc" );
QString def_hdr = prefix + QString::fromLatin1( "/include" );
QString def_lib = prefix + QString::fromLatin1( "/lib" );
QString def_plg = prefix + QString::fromLatin1( "/plugins" );
QString def_dat = prefix;
QString bin = QFile::decodeName( steps[1].value );
QString doc = QFile::decodeName( steps[2].value );
QString hdr = QFile::decodeName( steps[3].value );
QString lib = QFile::decodeName( steps[4].value );
QString plg = QFile::decodeName( steps[5].value );
QString dat = QFile::decodeName( steps[6].value );
autoSet->setChecked( def_bin == bin &&
def_doc == doc &&
def_hdr == hdr &&
def_lib == lib &&
def_plg == plg &&
def_dat == dat );
if ( ! autoSet->isChecked() ) {
binPath->setText( bin );
docPath->setText( doc );
hdrPath->setText( hdr );
libPath->setText( lib );
plgPath->setText( plg );
datPath->setText( dat );
}
}
}
void Distributor::checkInstallationPrefix( const QString &prefix )
{
if ( autoSet->isChecked() ) {
binPath->setText( prefix + QString::fromLatin1( "/bin" ) );
docPath->setText( prefix + QString::fromLatin1( "/doc" ) );
hdrPath->setText( prefix + QString::fromLatin1( "/include" ) );
libPath->setText( prefix + QString::fromLatin1( "/lib" ) );
plgPath->setText( prefix + QString::fromLatin1( "/plugins" ) );
datPath->setText( prefix );
}
}
void Distributor::browseInstallationPrefix()
{
QString prefix =
QFileDialog::getOpenFileName( QString::null, QString::null, this );
prefixPath->setText( prefix );
}
void Distributor::toggleAutoSet( bool autoset )
{
if ( autoset ) checkInstallationPrefix( prefixPath->text() );
}
void Distributor::accept()
{
struct step {
const char *key;
QCString value;
bool done;
} steps[7];
steps[0].key = "qt_nstpath=";
steps[0].value = QFile::encodeName( prefixPath->text() );
steps[0].done = FALSE;
steps[1].key = "qt_binpath=";
steps[1].value = QFile::encodeName( binPath->text() );
steps[1].done = FALSE;
steps[2].key = "qt_docpath=";
steps[2].value = QFile::encodeName( docPath->text() );
steps[2].done = FALSE;
steps[3].key = "qt_hdrpath=";
steps[3].value = QFile::encodeName( hdrPath->text() );
steps[3].done = FALSE;
steps[4].key = "qt_libpath=";
steps[4].value = QFile::encodeName( libPath->text() );
steps[4].done = FALSE;
steps[5].key = "qt_plgpath=";
steps[5].value = QFile::encodeName( plgPath->text() );
steps[5].done = FALSE;
steps[6].key = "qt_datpath=";
steps[6].value = QFile::encodeName( datPath->text() );
steps[6].done = FALSE;
uint completed = 0;
uint total_steps = sizeof(steps) / sizeof(step);
QFile file( libFilename->text() );
if ( file.open( IO_ReadWrite ) ) {
QApplication::setOverrideCursor( WaitCursor );
// instead of reading in the entire file, do the search in chunks
char data[60000];
ulong offset = 0;
while ( ! file.atEnd() && completed < total_steps ) {
QApplication::eventLoop()->processEvents( QEventLoop::ExcludeUserInput );
ulong len = file.readBlock( data, sizeof(data) );
if ( len < 267 ) {
// not enough room to make any modifications... stop
break;
}
uint completed_save = completed;
for ( uint x = 0; x < total_steps; ++x ) {
if ( steps[x].done ) continue;
char *s = find_pattern( data, steps[x].key, len );
if ( s ) {
ulong where = s - data;
if ( len - where < 256 ) {
// not enough space left to write the full
// path... move the file pointer back to just
// before the pattern and continue
offset += where - 11;
file.at( offset );
len = file.readBlock( data, sizeof(data) );
--x; // retry the current step
continue;
}
qstrcpy( s, steps[x].value );
steps[x].done = TRUE;
++completed;
}
}
if ( completed != completed_save ) {
// something changed... move file pointer back to
// where the data was read and write the new data
file.at( offset );
file.writeBlock( data, len );
}
// move to the new read position
offset += len - 11;
file.at( offset );
}
file.close();
QApplication::restoreOverrideCursor();
}
if ( completed != total_steps ) {
QMessageBox::information( this,
tr("Qt Distribution Wizard"),
tr("<p><h3>Modifications failed.</h3></p>"
"<p>Please make sure that you have permission "
"to write the selected file, and that the library "
"is properly built.</p>") );
return;
}
QWizard::accept();
}
|