1 | /****************************************************************************
|
---|
2 | ** ui.h extension file, included from the uic-generated form implementation.
|
---|
3 | **
|
---|
4 | ** If you wish to add, delete or rename functions or slots use
|
---|
5 | ** Qt Designer which will update this file, preserving your code. Create an
|
---|
6 | ** init() function in place of a constructor, and a destroy() function in
|
---|
7 | ** place of a destructor.
|
---|
8 | *****************************************************************************/
|
---|
9 |
|
---|
10 | #include <qapplication.h>
|
---|
11 | #include <qcursor.h>
|
---|
12 | #include <qeventloop.h>
|
---|
13 | #include <qfile.h>
|
---|
14 | #include <qfiledialog.h>
|
---|
15 | #include <qfileinfo.h>
|
---|
16 | #include <qlineedit.h>
|
---|
17 | #include <qmessagebox.h>
|
---|
18 | #include <qpushbutton.h>
|
---|
19 | #include <qtimer.h>
|
---|
20 |
|
---|
21 |
|
---|
22 | void Distributor::init()
|
---|
23 | {
|
---|
24 | timer = new QTimer( this );
|
---|
25 | connect( timer, SIGNAL(timeout()), SLOT(checkLibData()) );
|
---|
26 |
|
---|
27 | cancelButton()->setAutoDefault( FALSE );
|
---|
28 | backButton()->setAutoDefault( FALSE );
|
---|
29 |
|
---|
30 | setNextEnabled( selectLibrary, FALSE );
|
---|
31 |
|
---|
32 | setHelpEnabled( selectLibrary, FALSE );
|
---|
33 | setHelpEnabled( modifyPaths, FALSE );
|
---|
34 | setHelpEnabled( verifyMods, FALSE );
|
---|
35 |
|
---|
36 | setFinishEnabled( verifyMods, TRUE );
|
---|
37 | }
|
---|
38 |
|
---|
39 | void Distributor::showPage( QWidget *page )
|
---|
40 | {
|
---|
41 | if ( page == selectLibrary ) {
|
---|
42 | nextButton()->setDefault( TRUE );
|
---|
43 | libFilename->setFocus();
|
---|
44 | } else if ( page == modifyPaths ) {
|
---|
45 | nextButton()->setDefault( TRUE );
|
---|
46 | prefixPath->selectAll();
|
---|
47 | prefixPath->setFocus();
|
---|
48 | } else if ( page == verifyMods ) {
|
---|
49 | finishButton()->setDefault( TRUE );
|
---|
50 | finishButton()->setFocus();
|
---|
51 |
|
---|
52 | QString labeltext =
|
---|
53 | tr("<p><b>Current Library File:</b> %1</p>"
|
---|
54 | "<table border=0>"
|
---|
55 | "<tr><td><b>New Installation Prefix:</b></td><td>%2</td></tr>"
|
---|
56 | "<tr><td></td><td></td></tr>"
|
---|
57 | "<tr><td><b>Binaries Path:</b></td><td>%3</td></tr>"
|
---|
58 | "<tr><td><b>Documentation Path:</b></td><td>%4</td></tr>"
|
---|
59 | "<tr><td><b>Headers Path:</b></td><td>%5</td></tr>"
|
---|
60 | "<tr><td><b>Libraries Path:</b></td><td>%6</td></tr>"
|
---|
61 | "<tr><td><b>Plugins Path:</b></td><td>%7</td></tr>"
|
---|
62 | "<tr><td><b>Data Path:</b></td><td>%8</td></tr>"
|
---|
63 | "</table>"
|
---|
64 | "<p>Please verify that these options are correct. Press the "
|
---|
65 | "<i>Finish</i> button to apply these modifications to the Qt "
|
---|
66 | "library. Use the <i>Back</i> button to make corrections. Use "
|
---|
67 | "the <i>Cancel</i> button to abort.</p>")
|
---|
68 | .arg( libFilename->text() )
|
---|
69 | .arg( prefixPath->text() )
|
---|
70 | .arg( binPath->text() )
|
---|
71 | .arg( docPath->text() )
|
---|
72 | .arg( hdrPath->text() )
|
---|
73 | .arg( libPath->text() )
|
---|
74 | .arg( plgPath->text() )
|
---|
75 | .arg( datPath->text() );
|
---|
76 | textLabel4->setText( labeltext );
|
---|
77 | }
|
---|
78 |
|
---|
79 | QWizard::showPage( page );
|
---|
80 | }
|
---|
81 |
|
---|
82 | void Distributor::checkLibFilename( const QString &filename )
|
---|
83 | {
|
---|
84 | setNextEnabled( selectLibrary, FALSE );
|
---|
85 |
|
---|
86 | QFileInfo fileinfo( filename );
|
---|
87 | if ( ! filename.isEmpty() && fileinfo.exists() &&
|
---|
88 | fileinfo.isReadable() && fileinfo.isWritable() &&
|
---|
89 | fileinfo.isFile() && !fileinfo.isSymLink() )
|
---|
90 | timer->start( 500, TRUE );
|
---|
91 | }
|
---|
92 |
|
---|
93 | void Distributor::browseLibFilename()
|
---|
94 | {
|
---|
95 | QString filename =
|
---|
96 | QFileDialog::getOpenFileName( QString::null, QString::null, this );
|
---|
97 | libFilename->setText( filename );
|
---|
98 | }
|
---|
99 |
|
---|
100 | static char *find_pattern( char *h, const char *n, ulong hlen )
|
---|
101 | {
|
---|
102 | if ( ! h || ! n || hlen == 0 )
|
---|
103 | return 0;
|
---|
104 |
|
---|
105 | #ifdef Q_OS_UNIX
|
---|
106 | size_t nlen;
|
---|
107 | #else
|
---|
108 | ulong nlen;
|
---|
109 | #endif
|
---|
110 |
|
---|
111 | char nc = *n++;
|
---|
112 | nlen = strlen( n );
|
---|
113 | char hc;
|
---|
114 |
|
---|
115 | do {
|
---|
116 | do {
|
---|
117 | hc = *h++;
|
---|
118 | if ( hlen-- < 1 )
|
---|
119 | return 0;
|
---|
120 | } while ( hc != nc );
|
---|
121 |
|
---|
122 | if ( nlen > hlen )
|
---|
123 | return 0;
|
---|
124 | } while ( qstrncmp( h, n, nlen ) != 0 );
|
---|
125 | return h + nlen;
|
---|
126 | }
|
---|
127 |
|
---|
128 | void Distributor::checkLibData()
|
---|
129 | {
|
---|
130 | struct step {
|
---|
131 | const char *key;
|
---|
132 | QCString value;
|
---|
133 | bool done;
|
---|
134 | } steps[7];
|
---|
135 |
|
---|
136 | steps[0].key = "qt_nstpath=";
|
---|
137 | steps[0].done = FALSE;
|
---|
138 |
|
---|
139 | steps[1].key = "qt_binpath=";
|
---|
140 | steps[1].done = FALSE;
|
---|
141 |
|
---|
142 | steps[2].key = "qt_docpath=";
|
---|
143 | steps[2].done = FALSE;
|
---|
144 |
|
---|
145 | steps[3].key = "qt_hdrpath=";
|
---|
146 | steps[3].done = FALSE;
|
---|
147 |
|
---|
148 | steps[4].key = "qt_libpath=";
|
---|
149 | steps[4].done = FALSE;
|
---|
150 |
|
---|
151 | steps[5].key = "qt_plgpath=";
|
---|
152 | steps[5].done = FALSE;
|
---|
153 |
|
---|
154 | steps[6].key = "qt_datpath=";
|
---|
155 | steps[6].done = FALSE;
|
---|
156 |
|
---|
157 | uint completed = 0;
|
---|
158 | uint total_steps = sizeof(steps) / sizeof(step);
|
---|
159 |
|
---|
160 | QFile file( libFilename->text() );
|
---|
161 | if ( file.open( IO_ReadOnly ) ) {
|
---|
162 | QApplication::setOverrideCursor( WaitCursor );
|
---|
163 |
|
---|
164 | // instead of reading in the entire file, do the search in chunks
|
---|
165 | char data[60000];
|
---|
166 | ulong offset = 0;
|
---|
167 |
|
---|
168 | while ( ! file.atEnd() && completed < total_steps ) {
|
---|
169 | QApplication::eventLoop()->processEvents( QEventLoop::ExcludeUserInput );
|
---|
170 |
|
---|
171 | ulong len = file.readBlock( data, sizeof(data) );
|
---|
172 | if ( len < 267 ) {
|
---|
173 | // not enough room to make any modifications... stop
|
---|
174 | break;
|
---|
175 | }
|
---|
176 |
|
---|
177 | for ( uint x = 0; x < total_steps; ++x ) {
|
---|
178 | if ( steps[x].done ) continue;
|
---|
179 |
|
---|
180 | char *s = find_pattern( data, steps[x].key, len );
|
---|
181 | if ( s ) {
|
---|
182 | ulong where = s - data;
|
---|
183 | if ( len - where < 256 ) {
|
---|
184 | // not enough space left to write the full
|
---|
185 | // path... move the file pointer back to just
|
---|
186 | // before the pattern and continue
|
---|
187 | offset += where - 11;
|
---|
188 | file.at( offset );
|
---|
189 | len = file.readBlock( data, sizeof(data) );
|
---|
190 | --x; // retry the current step
|
---|
191 | continue;
|
---|
192 | }
|
---|
193 |
|
---|
194 | steps[x].value = s;
|
---|
195 | steps[x].done = TRUE;
|
---|
196 |
|
---|
197 | ++completed;
|
---|
198 | }
|
---|
199 | }
|
---|
200 |
|
---|
201 | // move to the new read position
|
---|
202 | offset += len - 11;
|
---|
203 | file.at( offset );
|
---|
204 | }
|
---|
205 |
|
---|
206 | file.close();
|
---|
207 |
|
---|
208 | QApplication::restoreOverrideCursor();
|
---|
209 | }
|
---|
210 |
|
---|
211 | if ( completed == total_steps ) {
|
---|
212 | setNextEnabled( selectLibrary, TRUE );
|
---|
213 |
|
---|
214 | QString prefix = QFile::decodeName( steps[0].value );
|
---|
215 | prefixPath->setText( prefix );
|
---|
216 |
|
---|
217 | QString def_bin = prefix + QString::fromLatin1( "/bin" );
|
---|
218 | QString def_doc = prefix + QString::fromLatin1( "/doc" );
|
---|
219 | QString def_hdr = prefix + QString::fromLatin1( "/include" );
|
---|
220 | QString def_lib = prefix + QString::fromLatin1( "/lib" );
|
---|
221 | QString def_plg = prefix + QString::fromLatin1( "/plugins" );
|
---|
222 | QString def_dat = prefix;
|
---|
223 |
|
---|
224 | QString bin = QFile::decodeName( steps[1].value );
|
---|
225 | QString doc = QFile::decodeName( steps[2].value );
|
---|
226 | QString hdr = QFile::decodeName( steps[3].value );
|
---|
227 | QString lib = QFile::decodeName( steps[4].value );
|
---|
228 | QString plg = QFile::decodeName( steps[5].value );
|
---|
229 | QString dat = QFile::decodeName( steps[6].value );
|
---|
230 |
|
---|
231 | autoSet->setChecked( def_bin == bin &&
|
---|
232 | def_doc == doc &&
|
---|
233 | def_hdr == hdr &&
|
---|
234 | def_lib == lib &&
|
---|
235 | def_plg == plg &&
|
---|
236 | def_dat == dat );
|
---|
237 |
|
---|
238 | if ( ! autoSet->isChecked() ) {
|
---|
239 | binPath->setText( bin );
|
---|
240 | docPath->setText( doc );
|
---|
241 | hdrPath->setText( hdr );
|
---|
242 | libPath->setText( lib );
|
---|
243 | plgPath->setText( plg );
|
---|
244 | datPath->setText( dat );
|
---|
245 | }
|
---|
246 | }
|
---|
247 | }
|
---|
248 |
|
---|
249 | void Distributor::checkInstallationPrefix( const QString &prefix )
|
---|
250 | {
|
---|
251 | if ( autoSet->isChecked() ) {
|
---|
252 | binPath->setText( prefix + QString::fromLatin1( "/bin" ) );
|
---|
253 | docPath->setText( prefix + QString::fromLatin1( "/doc" ) );
|
---|
254 | hdrPath->setText( prefix + QString::fromLatin1( "/include" ) );
|
---|
255 | libPath->setText( prefix + QString::fromLatin1( "/lib" ) );
|
---|
256 | plgPath->setText( prefix + QString::fromLatin1( "/plugins" ) );
|
---|
257 | datPath->setText( prefix );
|
---|
258 | }
|
---|
259 | }
|
---|
260 |
|
---|
261 | void Distributor::browseInstallationPrefix()
|
---|
262 | {
|
---|
263 | QString prefix =
|
---|
264 | QFileDialog::getOpenFileName( QString::null, QString::null, this );
|
---|
265 | prefixPath->setText( prefix );
|
---|
266 | }
|
---|
267 |
|
---|
268 |
|
---|
269 | void Distributor::toggleAutoSet( bool autoset )
|
---|
270 | {
|
---|
271 | if ( autoset ) checkInstallationPrefix( prefixPath->text() );
|
---|
272 | }
|
---|
273 |
|
---|
274 | void Distributor::accept()
|
---|
275 | {
|
---|
276 | struct step {
|
---|
277 | const char *key;
|
---|
278 | QCString value;
|
---|
279 | bool done;
|
---|
280 | } steps[7];
|
---|
281 |
|
---|
282 | steps[0].key = "qt_nstpath=";
|
---|
283 | steps[0].value = QFile::encodeName( prefixPath->text() );
|
---|
284 | steps[0].done = FALSE;
|
---|
285 |
|
---|
286 | steps[1].key = "qt_binpath=";
|
---|
287 | steps[1].value = QFile::encodeName( binPath->text() );
|
---|
288 | steps[1].done = FALSE;
|
---|
289 |
|
---|
290 | steps[2].key = "qt_docpath=";
|
---|
291 | steps[2].value = QFile::encodeName( docPath->text() );
|
---|
292 | steps[2].done = FALSE;
|
---|
293 |
|
---|
294 | steps[3].key = "qt_hdrpath=";
|
---|
295 | steps[3].value = QFile::encodeName( hdrPath->text() );
|
---|
296 | steps[3].done = FALSE;
|
---|
297 |
|
---|
298 | steps[4].key = "qt_libpath=";
|
---|
299 | steps[4].value = QFile::encodeName( libPath->text() );
|
---|
300 | steps[4].done = FALSE;
|
---|
301 |
|
---|
302 | steps[5].key = "qt_plgpath=";
|
---|
303 | steps[5].value = QFile::encodeName( plgPath->text() );
|
---|
304 | steps[5].done = FALSE;
|
---|
305 |
|
---|
306 | steps[6].key = "qt_datpath=";
|
---|
307 | steps[6].value = QFile::encodeName( datPath->text() );
|
---|
308 | steps[6].done = FALSE;
|
---|
309 |
|
---|
310 | uint completed = 0;
|
---|
311 | uint total_steps = sizeof(steps) / sizeof(step);
|
---|
312 |
|
---|
313 | QFile file( libFilename->text() );
|
---|
314 | if ( file.open( IO_ReadWrite ) ) {
|
---|
315 | QApplication::setOverrideCursor( WaitCursor );
|
---|
316 |
|
---|
317 | // instead of reading in the entire file, do the search in chunks
|
---|
318 | char data[60000];
|
---|
319 | ulong offset = 0;
|
---|
320 |
|
---|
321 | while ( ! file.atEnd() && completed < total_steps ) {
|
---|
322 | QApplication::eventLoop()->processEvents( QEventLoop::ExcludeUserInput );
|
---|
323 |
|
---|
324 | ulong len = file.readBlock( data, sizeof(data) );
|
---|
325 | if ( len < 267 ) {
|
---|
326 | // not enough room to make any modifications... stop
|
---|
327 | break;
|
---|
328 | }
|
---|
329 |
|
---|
330 | uint completed_save = completed;
|
---|
331 | for ( uint x = 0; x < total_steps; ++x ) {
|
---|
332 | if ( steps[x].done ) continue;
|
---|
333 |
|
---|
334 | char *s = find_pattern( data, steps[x].key, len );
|
---|
335 | if ( s ) {
|
---|
336 | ulong where = s - data;
|
---|
337 | if ( len - where < 256 ) {
|
---|
338 | // not enough space left to write the full
|
---|
339 | // path... move the file pointer back to just
|
---|
340 | // before the pattern and continue
|
---|
341 | offset += where - 11;
|
---|
342 | file.at( offset );
|
---|
343 | len = file.readBlock( data, sizeof(data) );
|
---|
344 | --x; // retry the current step
|
---|
345 | continue;
|
---|
346 | }
|
---|
347 |
|
---|
348 | qstrcpy( s, steps[x].value );
|
---|
349 | steps[x].done = TRUE;
|
---|
350 |
|
---|
351 | ++completed;
|
---|
352 | }
|
---|
353 | }
|
---|
354 |
|
---|
355 | if ( completed != completed_save ) {
|
---|
356 | // something changed... move file pointer back to
|
---|
357 | // where the data was read and write the new data
|
---|
358 | file.at( offset );
|
---|
359 | file.writeBlock( data, len );
|
---|
360 | }
|
---|
361 |
|
---|
362 | // move to the new read position
|
---|
363 | offset += len - 11;
|
---|
364 | file.at( offset );
|
---|
365 | }
|
---|
366 |
|
---|
367 | file.close();
|
---|
368 |
|
---|
369 | QApplication::restoreOverrideCursor();
|
---|
370 | }
|
---|
371 |
|
---|
372 | if ( completed != total_steps ) {
|
---|
373 | QMessageBox::information( this,
|
---|
374 | tr("Qt Distribution Wizard"),
|
---|
375 | tr("<p><h3>Modifications failed.</h3></p>"
|
---|
376 | "<p>Please make sure that you have permission "
|
---|
377 | "to write the selected file, and that the library "
|
---|
378 | "is properly built.</p>") );
|
---|
379 | return;
|
---|
380 | }
|
---|
381 |
|
---|
382 | QWizard::accept();
|
---|
383 | }
|
---|