<!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 uic-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 = "qcursor-h.html" > ntqcursor.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 = "qmessagebox-h.html" > ntqmessagebox.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 = "ntqmessagebox.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 >