summaryrefslogtreecommitdiffstats
path: root/doc/html/distributor-example.html
diff options
context:
space:
mode:
Diffstat (limited to 'doc/html/distributor-example.html')
-rw-r--r--doc/html/distributor-example.html450
1 files changed, 450 insertions, 0 deletions
diff --git a/doc/html/distributor-example.html b/doc/html/distributor-example.html
new file mode 100644
index 000000000..b7d034202
--- /dev/null
+++ b/doc/html/distributor-example.html
@@ -0,0 +1,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&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 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 &lt;<a href="qapplication-h.html">qapplication.h</a>&gt;
+#include &lt;<a href="qcursor-h.html">qcursor.h</a>&gt;
+#include &lt;<a href="qeventloop-h.html">qeventloop.h</a>&gt;
+#include &lt;<a href="qfile-h.html">qfile.h</a>&gt;
+#include &lt;<a href="qfiledialog-h.html">qfiledialog.h</a>&gt;
+#include &lt;<a href="qfileinfo-h.html">qfileinfo.h</a>&gt;
+#include &lt;<a href="qlineedit-h.html">qlineedit.h</a>&gt;
+#include &lt;<a href="qmessagebox-h.html">qmessagebox.h</a>&gt;
+#include &lt;<a href="qpushbutton-h.html">qpushbutton.h</a>&gt;
+#include &lt;<a href="qtimer-h.html">qtimer.h</a>&gt;
+
+
+void Distributor::init()
+{
+ timer = new <a href="qtimer.html">TQTimer</a>( this );
+<a name="x2672"></a> connect( timer, SIGNAL(<a href="qtimer.html#timeout">timeout</a>()), 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="qwidget.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="qstring.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="qwizard.html#showPage">showPage</a>( page );
+}
+
+void Distributor::checkLibFilename( const <a href="qstring.html">TQString</a> &amp;filename )
+{
+ setNextEnabled( selectLibrary, FALSE );
+
+ <a href="qfileinfo.html">TQFileInfo</a> fileinfo( filename );
+<a name="x2661"></a> if ( ! filename.<a href="qstring.html#isEmpty">isEmpty</a>() &amp;&amp; fileinfo.<a href="qfileinfo.html#exists">exists</a>() &amp;&amp;
+<a name="x2665"></a><a name="x2663"></a> fileinfo.<a href="qfileinfo.html#isReadable">isReadable</a>() &amp;&amp; fileinfo.<a href="qfileinfo.html#isWritable">isWritable</a>() &amp;&amp;
+<a name="x2664"></a><a name="x2662"></a> fileinfo.<a href="qfileinfo.html#isFile">isFile</a>() &amp;&amp; !fileinfo.<a href="qfileinfo.html#isSymLink">isSymLink</a>() )
+<a name="x2671"></a> timer-&gt;<a href="qtimer.html#start">start</a>( 500, TRUE );
+}
+
+void Distributor::browseLibFilename()
+{
+ <a href="qstring.html">TQString</a> filename =
+<a name="x2660"></a> TQFileDialog::<a href="qfiledialog.html#getOpenFileName">getOpenFileName</a>( <a href="qstring.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="qcstring.html#qstrncmp">qstrncmp</a>( h, n, nlen ) != 0 );
+ return h + nlen;
+}
+
+void Distributor::checkLibData()
+{
+ struct step {
+ const char *key;
+ <a href="qcstring.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="qfile.html">TQFile</a> file( libFilename-&gt;text() );
+<a name="x2659"></a> if ( file.<a href="qfile.html#open">open</a>( <a href="qfile.html#open">IO_ReadOnly</a> ) ) {
+<a name="x2653"></a> TQApplication::<a href="qapplication.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="qfile.html#atEnd">atEnd</a>() &amp;&amp; completed &lt; total_steps ) {
+<a name="x2651"></a> TQApplication::<a href="qapplication.html#eventLoop">eventLoop</a>()-&gt;processEvents( TQEventLoop::ExcludeUserInput );
+
+<a name="x2667"></a> ulong len = file.<a href="qiodevice.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="qiodevice.html#at">at</a>( offset );
+ len = file.<a href="qiodevice.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="qiodevice.html#at">at</a>( offset );
+ }
+
+<a name="x2656"></a> file.<a href="qfile.html#close">close</a>();
+
+<a name="x2652"></a> TQApplication::<a href="qapplication.html#restoreOverrideCursor">restoreOverrideCursor</a>();
+ }
+
+ if ( completed == total_steps ) {
+ setNextEnabled( selectLibrary, TRUE );
+
+<a name="x2657"></a> <a href="qstring.html">TQString</a> prefix = TQFile::<a href="qfile.html#decodeName">decodeName</a>( steps[0].value );
+ prefixPath-&gt;setText( prefix );
+
+ <a href="qstring.html">TQString</a> def_bin = prefix + TQString::fromLatin1( "/bin" );
+ <a href="qstring.html">TQString</a> def_doc = prefix + TQString::fromLatin1( "/doc" );
+ <a href="qstring.html">TQString</a> def_hdr = prefix + TQString::fromLatin1( "/include" );
+ <a href="qstring.html">TQString</a> def_lib = prefix + TQString::fromLatin1( "/lib" );
+ <a href="qstring.html">TQString</a> def_plg = prefix + TQString::fromLatin1( "/plugins" );
+ <a href="qstring.html">TQString</a> def_dat = prefix;
+
+ <a href="qstring.html">TQString</a> bin = TQFile::<a href="qfile.html#decodeName">decodeName</a>( steps[1].value );
+ <a href="qstring.html">TQString</a> doc = TQFile::<a href="qfile.html#decodeName">decodeName</a>( steps[2].value );
+ <a href="qstring.html">TQString</a> hdr = TQFile::<a href="qfile.html#decodeName">decodeName</a>( steps[3].value );
+ <a href="qstring.html">TQString</a> lib = TQFile::<a href="qfile.html#decodeName">decodeName</a>( steps[4].value );
+ <a href="qstring.html">TQString</a> plg = TQFile::<a href="qfile.html#decodeName">decodeName</a>( steps[5].value );
+ <a href="qstring.html">TQString</a> dat = TQFile::<a href="qfile.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="qstring.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="qstring.html">TQString</a> prefix =
+ TQFileDialog::<a href="qfiledialog.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="qcstring.html">TQCString</a> value;
+ bool done;
+ } steps[7];
+
+ steps[0].key = "qt_nstpath=";
+<a name="x2658"></a> steps[0].value = TQFile::<a href="qfile.html#encodeName">encodeName</a>( prefixPath-&gt;text() );
+ steps[0].done = FALSE;
+
+ steps[1].key = "qt_binpath=";
+ steps[1].value = TQFile::<a href="qfile.html#encodeName">encodeName</a>( binPath-&gt;text() );
+ steps[1].done = FALSE;
+
+ steps[2].key = "qt_docpath=";
+ steps[2].value = TQFile::<a href="qfile.html#encodeName">encodeName</a>( docPath-&gt;text() );
+ steps[2].done = FALSE;
+
+ steps[3].key = "qt_hdrpath=";
+ steps[3].value = TQFile::<a href="qfile.html#encodeName">encodeName</a>( hdrPath-&gt;text() );
+ steps[3].done = FALSE;
+
+ steps[4].key = "qt_libpath=";
+ steps[4].value = TQFile::<a href="qfile.html#encodeName">encodeName</a>( libPath-&gt;text() );
+ steps[4].done = FALSE;
+
+ steps[5].key = "qt_plgpath=";
+ steps[5].value = TQFile::<a href="qfile.html#encodeName">encodeName</a>( plgPath-&gt;text() );
+ steps[5].done = FALSE;
+
+ steps[6].key = "qt_datpath=";
+ steps[6].value = TQFile::<a href="qfile.html#encodeName">encodeName</a>( datPath-&gt;text() );
+ steps[6].done = FALSE;
+
+ uint completed = 0;
+ uint total_steps = sizeof(steps) / sizeof(step);
+
+ <a href="qfile.html">TQFile</a> file( libFilename-&gt;text() );
+ if ( file.<a href="qfile.html#open">open</a>( <a href="qfile.html#open">IO_ReadWrite</a> ) ) {
+ TQApplication::<a href="qapplication.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="qfile.html#atEnd">atEnd</a>() &amp;&amp; completed &lt; total_steps ) {
+ TQApplication::<a href="qapplication.html#eventLoop">eventLoop</a>()-&gt;processEvents( TQEventLoop::ExcludeUserInput );
+
+ ulong len = file.<a href="qiodevice.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="qiodevice.html#at">at</a>( offset );
+ len = file.<a href="qiodevice.html#readBlock">readBlock</a>( data, sizeof(data) );
+ --x; // retry the current step
+ continue;
+ }
+
+ <a href="qcstring.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="qiodevice.html#at">at</a>( offset );
+<a name="x2668"></a> file.<a href="qiodevice.html#writeBlock">writeBlock</a>( data, len );
+ }
+
+ // move to the new read position
+ offset += len - 11;
+ file.<a href="qiodevice.html#at">at</a>( offset );
+ }
+
+ file.<a href="qfile.html#close">close</a>();
+
+ TQApplication::<a href="qapplication.html#restoreOverrideCursor">restoreOverrideCursor</a>();
+ }
+
+ if ( completed != total_steps ) {
+ TQMessageBox::<a href="qmessagebox.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="qdialog.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>