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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/examples/distributor/distributor.doc:1 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>TQt Distribution Example</title>
<style type="text/css"><!--
fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
<a href="index.html">
<font color="#004faf">Home</font></a>
| <a href="classes.html">
<font color="#004faf">All Classes</font></a>
| <a href="mainclasses.html">
<font color="#004faf">Main Classes</font></a>
| <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
| <a href="groups.html">
<font color="#004faf">Grouped Classes</font></a>
| <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>TQt Distribution Example</h1>
<p> This example program modifies the hard-coded paths that are
compiled into the TQt library.
<p> When distributing the TQt library, the final installation prefix is
very rarely the same as the prefix used when doing development.
You can use the code from this example to modify the following
hard-coded paths in TQt library:
<p> <ul>
<p> <li> Prefix - Normally, all other paths are relative to the <em>Prefix</em>.
<p> <li> Binaries - Location of binaries distributed with TQt (for
example, <em>TQt Assistant</em>).
<p> <li> Documentation - Location of the TQt documentation.
<p> <li> Headers - Location of the TQt headers.
<p> <li> Libraries - Location of addition libraries distributed with TQt
(for example, the <em>tqui</em> library).
<p> <li> Plugins - Location of the TQt plugins.
<p> <li> Data - Location of applicaton specific data for all programs
distributed with TQt.
<p> </ul>
<p> <hr>
<p> Implementation:
<p> <pre>/****************************************************************************
** ui.h extension file, included from the tquic-generated form implementation.
**
** If you wish to add, delete or rename functions or slots use
** TQt 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 <<a href="qapplication-h.html">ntqapplication.h</a>>
#include <<a href="tqcursor-h.html">tqcursor.h</a>>
#include <<a href="tqeventloop-h.html">tqeventloop.h</a>>
#include <<a href="tqfile-h.html">tqfile.h</a>>
#include <<a href="tqfiledialog-h.html">tqfiledialog.h</a>>
#include <<a href="tqfileinfo-h.html">tqfileinfo.h</a>>
#include <<a href="tqlineedit-h.html">tqlineedit.h</a>>
#include <<a href="tqmessagebox-h.html">tqmessagebox.h</a>>
#include <<a href="tqpushbutton-h.html">tqpushbutton.h</a>>
#include <<a href="tqtimer-h.html">tqtimer.h</a>>
void Distributor::init()
{
timer = new <a href="tqtimer.html">TQTimer</a>( this );
<a name="x2672"></a> connect( timer, TQ_SIGNAL(<a href="tqtimer.html#timeout">timeout</a>()), TQ_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( <a href="tqwidget.html">TQWidget</a> *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();
<a href="tqstring.html">TQString</a> 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 TQt "
"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 );
}
<a name="x2673"></a> TQWizard::<a href="tqwizard.html#showPage">showPage</a>( page );
}
void Distributor::checkLibFilename( const <a href="tqstring.html">TQString</a> &filename )
{
setNextEnabled( selectLibrary, FALSE );
<a href="tqfileinfo.html">TQFileInfo</a> fileinfo( filename );
<a name="x2661"></a> if ( ! filename.<a href="tqstring.html#isEmpty">isEmpty</a>() && fileinfo.<a href="tqfileinfo.html#exists">exists</a>() &&
<a name="x2665"></a><a name="x2663"></a> fileinfo.<a href="tqfileinfo.html#isReadable">isReadable</a>() && fileinfo.<a href="tqfileinfo.html#isWritable">isWritable</a>() &&
<a name="x2664"></a><a name="x2662"></a> fileinfo.<a href="tqfileinfo.html#isFile">isFile</a>() && !fileinfo.<a href="tqfileinfo.html#isSymLink">isSymLink</a>() )
<a name="x2671"></a> timer-><a href="tqtimer.html#start">start</a>( 500, TRUE );
}
void Distributor::browseLibFilename()
{
<a href="tqstring.html">TQString</a> filename =
<a name="x2660"></a> TQFileDialog::<a href="tqfiledialog.html#getOpenFileName">getOpenFileName</a>( <a href="tqstring.html#TQString-null">TQString::null</a>, TQString::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 ( <a href="tqcstring.html#qstrncmp">tqstrncmp</a>( h, n, nlen ) != 0 );
return h + nlen;
}
void Distributor::checkLibData()
{
struct step {
const char *key;
<a href="tqcstring.html">TQCString</a> 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);
<a href="tqfile.html">TQFile</a> file( libFilename->text() );
<a name="x2659"></a> if ( file.<a href="tqfile.html#open">open</a>( <a href="tqfile.html#open">IO_ReadOnly</a> ) ) {
<a name="x2653"></a> TQApplication::<a href="ntqapplication.html#setOverrideCursor">setOverrideCursor</a>( WaitCursor );
// instead of reading in the entire file, do the search in chunks
char data[60000];
ulong offset = 0;
<a name="x2655"></a> while ( ! file.<a href="tqfile.html#atEnd">atEnd</a>() && completed < total_steps ) {
<a name="x2651"></a> TQApplication::<a href="ntqapplication.html#eventLoop">eventLoop</a>()->processEvents( TQEventLoop::ExcludeUserInput );
<a name="x2667"></a> ulong len = file.<a href="tqiodevice.html#readBlock">readBlock</a>( 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;
<a name="x2666"></a> file.<a href="tqiodevice.html#at">at</a>( offset );
len = file.<a href="tqiodevice.html#readBlock">readBlock</a>( 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.<a href="tqiodevice.html#at">at</a>( offset );
}
<a name="x2656"></a> file.<a href="tqfile.html#close">close</a>();
<a name="x2652"></a> TQApplication::<a href="ntqapplication.html#restoreOverrideCursor">restoreOverrideCursor</a>();
}
if ( completed == total_steps ) {
setNextEnabled( selectLibrary, TRUE );
<a name="x2657"></a> <a href="tqstring.html">TQString</a> prefix = TQFile::<a href="tqfile.html#decodeName">decodeName</a>( steps[0].value );
prefixPath->setText( prefix );
<a href="tqstring.html">TQString</a> def_bin = prefix + TQString::fromLatin1( "/bin" );
<a href="tqstring.html">TQString</a> def_doc = prefix + TQString::fromLatin1( "/doc" );
<a href="tqstring.html">TQString</a> def_hdr = prefix + TQString::fromLatin1( "/include" );
<a href="tqstring.html">TQString</a> def_lib = prefix + TQString::fromLatin1( "/lib" );
<a href="tqstring.html">TQString</a> def_plg = prefix + TQString::fromLatin1( "/plugins" );
<a href="tqstring.html">TQString</a> def_dat = prefix;
<a href="tqstring.html">TQString</a> bin = TQFile::<a href="tqfile.html#decodeName">decodeName</a>( steps[1].value );
<a href="tqstring.html">TQString</a> doc = TQFile::<a href="tqfile.html#decodeName">decodeName</a>( steps[2].value );
<a href="tqstring.html">TQString</a> hdr = TQFile::<a href="tqfile.html#decodeName">decodeName</a>( steps[3].value );
<a href="tqstring.html">TQString</a> lib = TQFile::<a href="tqfile.html#decodeName">decodeName</a>( steps[4].value );
<a href="tqstring.html">TQString</a> plg = TQFile::<a href="tqfile.html#decodeName">decodeName</a>( steps[5].value );
<a href="tqstring.html">TQString</a> dat = TQFile::<a href="tqfile.html#decodeName">decodeName</a>( 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 <a href="tqstring.html">TQString</a> &prefix )
{
if ( autoSet->isChecked() ) {
binPath->setText( prefix + TQString::fromLatin1( "/bin" ) );
docPath->setText( prefix + TQString::fromLatin1( "/doc" ) );
hdrPath->setText( prefix + TQString::fromLatin1( "/include" ) );
libPath->setText( prefix + TQString::fromLatin1( "/lib" ) );
plgPath->setText( prefix + TQString::fromLatin1( "/plugins" ) );
datPath->setText( prefix );
}
}
void Distributor::browseInstallationPrefix()
{
<a href="tqstring.html">TQString</a> prefix =
TQFileDialog::<a href="tqfiledialog.html#getOpenFileName">getOpenFileName</a>( TQString::null, TQString::null, this );
prefixPath->setText( prefix );
}
void Distributor::toggleAutoSet( bool autoset )
{
if ( autoset ) checkInstallationPrefix( prefixPath->text() );
}
void Distributor::accept()
{
struct step {
const char *key;
<a href="tqcstring.html">TQCString</a> value;
bool done;
} steps[7];
steps[0].key = "qt_nstpath=";
<a name="x2658"></a> steps[0].value = TQFile::<a href="tqfile.html#encodeName">encodeName</a>( prefixPath->text() );
steps[0].done = FALSE;
steps[1].key = "qt_binpath=";
steps[1].value = TQFile::<a href="tqfile.html#encodeName">encodeName</a>( binPath->text() );
steps[1].done = FALSE;
steps[2].key = "qt_docpath=";
steps[2].value = TQFile::<a href="tqfile.html#encodeName">encodeName</a>( docPath->text() );
steps[2].done = FALSE;
steps[3].key = "qt_hdrpath=";
steps[3].value = TQFile::<a href="tqfile.html#encodeName">encodeName</a>( hdrPath->text() );
steps[3].done = FALSE;
steps[4].key = "qt_libpath=";
steps[4].value = TQFile::<a href="tqfile.html#encodeName">encodeName</a>( libPath->text() );
steps[4].done = FALSE;
steps[5].key = "qt_plgpath=";
steps[5].value = TQFile::<a href="tqfile.html#encodeName">encodeName</a>( plgPath->text() );
steps[5].done = FALSE;
steps[6].key = "qt_datpath=";
steps[6].value = TQFile::<a href="tqfile.html#encodeName">encodeName</a>( datPath->text() );
steps[6].done = FALSE;
uint completed = 0;
uint total_steps = sizeof(steps) / sizeof(step);
<a href="tqfile.html">TQFile</a> file( libFilename->text() );
if ( file.<a href="tqfile.html#open">open</a>( <a href="tqfile.html#open">IO_ReadWrite</a> ) ) {
TQApplication::<a href="ntqapplication.html#setOverrideCursor">setOverrideCursor</a>( WaitCursor );
// instead of reading in the entire file, do the search in chunks
char data[60000];
ulong offset = 0;
while ( ! file.<a href="tqfile.html#atEnd">atEnd</a>() && completed < total_steps ) {
TQApplication::<a href="ntqapplication.html#eventLoop">eventLoop</a>()->processEvents( TQEventLoop::ExcludeUserInput );
ulong len = file.<a href="tqiodevice.html#readBlock">readBlock</a>( 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.<a href="tqiodevice.html#at">at</a>( offset );
len = file.<a href="tqiodevice.html#readBlock">readBlock</a>( data, sizeof(data) );
--x; // retry the current step
continue;
}
<a href="tqcstring.html#qstrcpy">qstrcpy</a>( 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.<a href="tqiodevice.html#at">at</a>( offset );
<a name="x2668"></a> file.<a href="tqiodevice.html#writeBlock">writeBlock</a>( data, len );
}
// move to the new read position
offset += len - 11;
file.<a href="tqiodevice.html#at">at</a>( offset );
}
file.<a href="tqfile.html#close">close</a>();
TQApplication::<a href="ntqapplication.html#restoreOverrideCursor">restoreOverrideCursor</a>();
}
if ( completed != total_steps ) {
TQMessageBox::<a href="tqmessagebox.html#information">information</a>( this,
tr("TQt 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;
}
<a name="x2654"></a> TQWizard::<a href="tqdialog.html#accept">accept</a>();
}
</pre>
<p>See also <a href="examples.html">Examples</a>.
<!-- eof -->
<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright © 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>TQt 3.3.8</div>
</table></div></address></body>
</html>
|