You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tqt3/doc/html/distributor-example.html

450 lines
19 KiB

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<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&nbsp;Classes</font></a>
| <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
| <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
| <a href="groups.html">
<font color="#004faf">Grouped&nbsp;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 &lt;<a href="tqapplication-h.html">tqapplication.h</a>&gt;
#include &lt;<a href="tqcursor-h.html">tqcursor.h</a>&gt;
#include &lt;<a href="tqeventloop-h.html">tqeventloop.h</a>&gt;
#include &lt;<a href="tqfile-h.html">tqfile.h</a>&gt;
#include &lt;<a href="tqfiledialog-h.html">tqfiledialog.h</a>&gt;
#include &lt;<a href="tqfileinfo-h.html">tqfileinfo.h</a>&gt;
#include &lt;<a href="tqlineedit-h.html">tqlineedit.h</a>&gt;
#include &lt;<a href="tqmessagebox-h.html">tqmessagebox.h</a>&gt;
#include &lt;<a href="tqpushbutton-h.html">tqpushbutton.h</a>&gt;
#include &lt;<a href="tqtimer-h.html">tqtimer.h</a>&gt;
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()-&gt;setAutoDefault( FALSE );
backButton()-&gt;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()-&gt;setDefault( TRUE );
libFilename-&gt;setFocus();
} else if ( page == modifyPaths ) {
nextButton()-&gt;setDefault( TRUE );
prefixPath-&gt;selectAll();
prefixPath-&gt;setFocus();
} else if ( page == verifyMods ) {
finishButton()-&gt;setDefault( TRUE );
finishButton()-&gt;setFocus();
<a href="tqstring.html">TQString</a> labeltext =
tr("&lt;p&gt;&lt;b&gt;Current Library File:&lt;/b&gt; %1&lt;/p&gt;"
"&lt;table border=0&gt;"
"&lt;tr&gt;&lt;td&gt;&lt;b&gt;New Installation Prefix:&lt;/b&gt;&lt;/td&gt;&lt;td&gt;%2&lt;/td&gt;&lt;/tr&gt;"
"&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;"
"&lt;tr&gt;&lt;td&gt;&lt;b&gt;Binaries Path:&lt;/b&gt;&lt;/td&gt;&lt;td&gt;%3&lt;/td&gt;&lt;/tr&gt;"
"&lt;tr&gt;&lt;td&gt;&lt;b&gt;Documentation Path:&lt;/b&gt;&lt;/td&gt;&lt;td&gt;%4&lt;/td&gt;&lt;/tr&gt;"
"&lt;tr&gt;&lt;td&gt;&lt;b&gt;Headers Path:&lt;/b&gt;&lt;/td&gt;&lt;td&gt;%5&lt;/td&gt;&lt;/tr&gt;"
"&lt;tr&gt;&lt;td&gt;&lt;b&gt;Libraries Path:&lt;/b&gt;&lt;/td&gt;&lt;td&gt;%6&lt;/td&gt;&lt;/tr&gt;"
"&lt;tr&gt;&lt;td&gt;&lt;b&gt;Plugins Path:&lt;/b&gt;&lt;/td&gt;&lt;td&gt;%7&lt;/td&gt;&lt;/tr&gt;"
"&lt;tr&gt;&lt;td&gt;&lt;b&gt;Data Path:&lt;/b&gt;&lt;/td&gt;&lt;td&gt;%8&lt;/td&gt;&lt;/tr&gt;"
"&lt;/table&gt;"
"&lt;p&gt;Please verify that these options are correct. Press the "
"&lt;i&gt;Finish&lt;/i&gt; button to apply these modifications to the TQt "
"library. Use the &lt;i&gt;Back&lt;/i&gt; button to make corrections. Use "
"the &lt;i&gt;Cancel&lt;/i&gt; button to abort.&lt;/p&gt;")
.arg( libFilename-&gt;text() )
.arg( prefixPath-&gt;text() )
.arg( binPath-&gt;text() )
.arg( docPath-&gt;text() )
.arg( hdrPath-&gt;text() )
.arg( libPath-&gt;text() )
.arg( plgPath-&gt;text() )
.arg( datPath-&gt;text() );
textLabel4-&gt;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> &amp;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>() &amp;&amp; fileinfo.<a href="tqfileinfo.html#exists">exists</a>() &amp;&amp;
<a name="x2665"></a><a name="x2663"></a> fileinfo.<a href="tqfileinfo.html#isReadable">isReadable</a>() &amp;&amp; fileinfo.<a href="tqfileinfo.html#isWritable">isWritable</a>() &amp;&amp;
<a name="x2664"></a><a name="x2662"></a> fileinfo.<a href="tqfileinfo.html#isFile">isFile</a>() &amp;&amp; !fileinfo.<a href="tqfileinfo.html#isSymLink">isSymLink</a>() )
<a name="x2671"></a> timer-&gt;<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-&gt;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-- &lt; 1 )
return 0;
} while ( hc != nc );
if ( nlen &gt; 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-&gt;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="tqapplication.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>() &amp;&amp; completed &lt; total_steps ) {
<a name="x2651"></a> TQApplication::<a href="tqapplication.html#eventLoop">eventLoop</a>()-&gt;processEvents( TQEventLoop::ExcludeUserInput );
<a name="x2667"></a> ulong len = file.<a href="tqiodevice.html#readBlock">readBlock</a>( data, sizeof(data) );
if ( len &lt; 267 ) {
// not enough room to make any modifications... stop
break;
}
for ( uint x = 0; x &lt; 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 &lt; 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="tqapplication.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-&gt;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-&gt;setChecked( def_bin == bin &amp;&amp;
def_doc == doc &amp;&amp;
def_hdr == hdr &amp;&amp;
def_lib == lib &amp;&amp;
def_plg == plg &amp;&amp;
def_dat == dat );
if ( ! autoSet-&gt;isChecked() ) {
binPath-&gt;setText( bin );
docPath-&gt;setText( doc );
hdrPath-&gt;setText( hdr );
libPath-&gt;setText( lib );
plgPath-&gt;setText( plg );
datPath-&gt;setText( dat );
}
}
}
void Distributor::checkInstallationPrefix( const <a href="tqstring.html">TQString</a> &amp;prefix )
{
if ( autoSet-&gt;isChecked() ) {
binPath-&gt;setText( prefix + TQString::fromLatin1( "/bin" ) );
docPath-&gt;setText( prefix + TQString::fromLatin1( "/doc" ) );
hdrPath-&gt;setText( prefix + TQString::fromLatin1( "/include" ) );
libPath-&gt;setText( prefix + TQString::fromLatin1( "/lib" ) );
plgPath-&gt;setText( prefix + TQString::fromLatin1( "/plugins" ) );
datPath-&gt;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-&gt;setText( prefix );
}
void Distributor::toggleAutoSet( bool autoset )
{
if ( autoset ) checkInstallationPrefix( prefixPath-&gt;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-&gt;text() );
steps[0].done = FALSE;
steps[1].key = "qt_binpath=";
steps[1].value = TQFile::<a href="tqfile.html#encodeName">encodeName</a>( binPath-&gt;text() );
steps[1].done = FALSE;
steps[2].key = "qt_docpath=";
steps[2].value = TQFile::<a href="tqfile.html#encodeName">encodeName</a>( docPath-&gt;text() );
steps[2].done = FALSE;
steps[3].key = "qt_hdrpath=";
steps[3].value = TQFile::<a href="tqfile.html#encodeName">encodeName</a>( hdrPath-&gt;text() );
steps[3].done = FALSE;
steps[4].key = "qt_libpath=";
steps[4].value = TQFile::<a href="tqfile.html#encodeName">encodeName</a>( libPath-&gt;text() );
steps[4].done = FALSE;
steps[5].key = "qt_plgpath=";
steps[5].value = TQFile::<a href="tqfile.html#encodeName">encodeName</a>( plgPath-&gt;text() );
steps[5].done = FALSE;
steps[6].key = "qt_datpath=";
steps[6].value = TQFile::<a href="tqfile.html#encodeName">encodeName</a>( datPath-&gt;text() );
steps[6].done = FALSE;
uint completed = 0;
uint total_steps = sizeof(steps) / sizeof(step);
<a href="tqfile.html">TQFile</a> file( libFilename-&gt;text() );
if ( file.<a href="tqfile.html#open">open</a>( <a href="tqfile.html#open">IO_ReadWrite</a> ) ) {
TQApplication::<a href="tqapplication.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>() &amp;&amp; completed &lt; total_steps ) {
TQApplication::<a href="tqapplication.html#eventLoop">eventLoop</a>()-&gt;processEvents( TQEventLoop::ExcludeUserInput );
ulong len = file.<a href="tqiodevice.html#readBlock">readBlock</a>( data, sizeof(data) );
if ( len &lt; 267 ) {
// not enough room to make any modifications... stop
break;
}
uint completed_save = completed;
for ( uint x = 0; x &lt; 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 &lt; 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="tqapplication.html#restoreOverrideCursor">restoreOverrideCursor</a>();
}
if ( completed != total_steps ) {
TQMessageBox::<a href="tqmessagebox.html#information">information</a>( this,
tr("TQt Distribution Wizard"),
tr("&lt;p&gt;&lt;h3&gt;Modifications failed.&lt;/h3&gt;&lt;/p&gt;"
"&lt;p&gt;Please make sure that you have permission "
"to write the selected file, and that the library "
"is properly built.&lt;/p&gt;") );
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 &copy; 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>