From bd0f3345a938b35ce6a12f6150373b0955b8dd12 Mon Sep 17 00:00:00 2001
From: Timothy Pearson
Date: Sun, 10 Jul 2011 15:24:15 -0500
Subject: Add Qt3 development HEAD version
---
examples/distributor/distributor.doc | 41 ++++
examples/distributor/distributor.pro | 10 +
examples/distributor/distributor.ui | 427 ++++++++++++++++++++++++++++++++++
examples/distributor/distributor.ui.h | 383 ++++++++++++++++++++++++++++++
examples/distributor/main.cpp | 11 +
5 files changed, 872 insertions(+)
create mode 100644 examples/distributor/distributor.doc
create mode 100644 examples/distributor/distributor.pro
create mode 100644 examples/distributor/distributor.ui
create mode 100644 examples/distributor/distributor.ui.h
create mode 100644 examples/distributor/main.cpp
(limited to 'examples/distributor')
diff --git a/examples/distributor/distributor.doc b/examples/distributor/distributor.doc
new file mode 100644
index 0000000..4884c21
--- /dev/null
+++ b/examples/distributor/distributor.doc
@@ -0,0 +1,41 @@
+/*! \page distributor-example.html
+ \ingroup examples
+
+ \title Qt Distribution Example
+
+ This example program modifies the hard-coded paths that are
+ compiled into the Qt library.
+
+ When distributing the Qt 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 Qt library:
+
+ \list
+
+ \i Prefix - Normally, all other paths are relative to the \e
+ Prefix.
+
+ \i Binaries - Location of binaries distributed with Qt (for
+ example, \e{Qt Assistant}).
+
+ \i Documentation - Location of the Qt documentation.
+
+ \i Headers - Location of the Qt headers.
+
+ \i Libraries - Location of addition libraries distributed with Qt
+ (for example, the \e qui library).
+
+ \i Plugins - Location of the Qt plugins.
+
+ \i Data - Location of applicaton specific data for all programs
+ distributed with Qt.
+
+ \endlist
+
+
+
+ Implementation:
+
+ \include distributor/distributor.ui.h
+*/
diff --git a/examples/distributor/distributor.pro b/examples/distributor/distributor.pro
new file mode 100644
index 0000000..81d0ec5
--- /dev/null
+++ b/examples/distributor/distributor.pro
@@ -0,0 +1,10 @@
+TEMPLATE = app
+LANGUAGE = C++
+TARGET = distributor
+
+CONFIG += qt warn_on
+
+REQUIRES = full-config
+
+SOURCES += main.cpp
+FORMS = distributor.ui
diff --git a/examples/distributor/distributor.ui b/examples/distributor/distributor.ui
new file mode 100644
index 0000000..64f6f0c
--- /dev/null
+++ b/examples/distributor/distributor.ui
@@ -0,0 +1,427 @@
+
+Distributor
+
+
+ Distributor
+
+
+
+ 0
+ 0
+ 522
+ 422
+
+
+
+ Qt Distribution Wizard
+
+
+
+ selectLibrary
+
+
+ <b>Select Qt Library File</b>
+
+
+
+ unnamed
+
+
+
+ spacer2
+
+
+ Vertical
+
+
+ Expanding
+
+
+
+ 20
+ 40
+
+
+
+
+
+ libFilename
+
+
+ LineEditPanel
+
+
+ Sunken
+
+
+
+
+ libBrowseButton
+
+
+ &Browse...
+
+
+
+
+ textLabel1
+
+
+ <p>Enter the filename of the Qt library to modify, or use the <i>Browse</i> button to browse for the library.</p>
+<p>This wizard will allow you to modify the installation paths stored in the library.</p>
+
+
+
+
+
+
+ modifyPaths
+
+
+ <b>Modify Installation Paths</b>
+
+
+
+ unnamed
+
+
+
+ spacer2_2
+
+
+ Vertical
+
+
+ Expanding
+
+
+
+ 20
+ 40
+
+
+
+
+
+ prefixBuddy
+
+
+ Installation &Prefix
+
+
+ prefixPath
+
+
+
+
+ libPath
+
+
+ false
+
+
+ 255
+
+
+
+
+ prefixPath
+
+
+ 255
+
+
+
+
+ plgPath
+
+
+ false
+
+
+ 255
+
+
+
+
+ prefixBrowseButton
+
+
+ &Browse...
+
+
+
+
+ datPath
+
+
+ false
+
+
+ 255
+
+
+
+
+ textLabel2
+
+
+ <p>Enter the new <i>Installation Prefix</i> for the selected Qt library, or use the <i>Browse</i> button to browse for the desired directory.</p>
+<p>Use the <i>Next</i> button to review your choices and perform the modification.</p>
+
+
+
+
+ line1
+
+
+ HLine
+
+
+ Sunken
+
+
+ Horizontal
+
+
+
+
+ docPath
+
+
+ false
+
+
+ 255
+
+
+
+
+ hdrPath
+
+
+ false
+
+
+ 255
+
+
+
+
+ textLabel3
+
+
+ <p>The various paths below are set automatically according to the chosen <i>Installation Prefix</i>. Uncheck the <i>Set paths from Installation Prefix</i> box to enter custom values.</p>
+
+
+
+
+ binPath
+
+
+ false
+
+
+ 255
+
+
+
+
+ autoSet
+
+
+ Set paths from Installation Prefix
+
+
+ true
+
+
+
+
+ docBuddy
+
+
+ Documentation
+
+
+
+
+ datBuddy
+
+
+ Data
+
+
+
+
+ hdrBuddy
+
+
+ Headers
+
+
+
+
+ libBuddy
+
+
+ Libraries
+
+
+
+
+ plgBuddy
+
+
+ Plugins
+
+
+
+
+ binBuddy
+
+
+ Binaries
+
+
+
+
+
+
+ verifyMods
+
+
+ <b>Verify Modifications</b>
+
+
+
+ unnamed
+
+
+
+ textLabel4
+
+
+ <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 Qt library. Use the <i>Back</i> button to make corrections. Use the <i>Cancel</i> button to abort.</p>
+
+
+ WordBreak|AlignTop
+
+
+
+
+
+
+
+ autoSet
+ toggled(bool)
+ binPath
+ setDisabled(bool)
+
+
+ autoSet
+ toggled(bool)
+ docPath
+ setDisabled(bool)
+
+
+ autoSet
+ toggled(bool)
+ hdrPath
+ setDisabled(bool)
+
+
+ autoSet
+ toggled(bool)
+ libPath
+ setDisabled(bool)
+
+
+ autoSet
+ toggled(bool)
+ plgPath
+ setDisabled(bool)
+
+
+ autoSet
+ toggled(bool)
+ datPath
+ setDisabled(bool)
+
+
+ libFilename
+ textChanged(const QString&)
+ Distributor
+ checkLibFilename(const QString&)
+
+
+ libBrowseButton
+ clicked()
+ Distributor
+ browseLibFilename()
+
+
+ prefixPath
+ textChanged(const QString&)
+ Distributor
+ checkInstallationPrefix(const QString&)
+
+
+ prefixBrowseButton
+ clicked()
+ Distributor
+ browseInstallationPrefix()
+
+
+ autoSet
+ toggled(bool)
+ Distributor
+ toggleAutoSet(bool)
+
+
+
+ libFilename
+ libBrowseButton
+ prefixPath
+ prefixBrowseButton
+ autoSet
+ binPath
+ docPath
+ hdrPath
+ libPath
+ plgPath
+ datPath
+
+
+ distributor.ui.h
+
+
+ QTimer *timer;
+
+
+ checkLibFilename( const QString & filename )
+ browseLibFilename()
+ checkLibData()
+ checkInstallationPrefix( const QString &filename )
+ browseInstallationPrefix()
+ toggleAutoSet( bool autoset )
+ accept()
+
+
+ init()
+ showPage( QWidget * page )
+
+
+
+
diff --git a/examples/distributor/distributor.ui.h b/examples/distributor/distributor.ui.h
new file mode 100644
index 0000000..e0c2d54
--- /dev/null
+++ b/examples/distributor/distributor.ui.h
@@ -0,0 +1,383 @@
+/****************************************************************************
+** ui.h extension file, included from the uic-generated form implementation.
+**
+** If you wish to add, delete or rename functions or slots use
+** Qt 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
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+
+void Distributor::init()
+{
+ timer = new QTimer( this );
+ connect( timer, SIGNAL(timeout()), 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( QWidget *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();
+
+ QString labeltext =
+ tr("Current Library File: %1
"
+ ""
+ "New Installation Prefix: | %2 |
"
+ " | |
"
+ "Binaries Path: | %3 |
"
+ "Documentation Path: | %4 |
"
+ "Headers Path: | %5 |
"
+ "Libraries Path: | %6 |
"
+ "Plugins Path: | %7 |
"
+ "Data Path: | %8 |
"
+ "
"
+ "Please verify that these options are correct. Press the "
+ "Finish button to apply these modifications to the Qt "
+ "library. Use the Back button to make corrections. Use "
+ "the Cancel button to abort.
")
+ .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 );
+ }
+
+ QWizard::showPage( page );
+}
+
+void Distributor::checkLibFilename( const QString &filename )
+{
+ setNextEnabled( selectLibrary, FALSE );
+
+ QFileInfo fileinfo( filename );
+ if ( ! filename.isEmpty() && fileinfo.exists() &&
+ fileinfo.isReadable() && fileinfo.isWritable() &&
+ fileinfo.isFile() && !fileinfo.isSymLink() )
+ timer->start( 500, TRUE );
+}
+
+void Distributor::browseLibFilename()
+{
+ QString filename =
+ QFileDialog::getOpenFileName( QString::null, QString::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 ( qstrncmp( h, n, nlen ) != 0 );
+ return h + nlen;
+}
+
+void Distributor::checkLibData()
+{
+ struct step {
+ const char *key;
+ QCString 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);
+
+ QFile file( libFilename->text() );
+ if ( file.open( IO_ReadOnly ) ) {
+ QApplication::setOverrideCursor( WaitCursor );
+
+ // instead of reading in the entire file, do the search in chunks
+ char data[60000];
+ ulong offset = 0;
+
+ while ( ! file.atEnd() && completed < total_steps ) {
+ QApplication::eventLoop()->processEvents( QEventLoop::ExcludeUserInput );
+
+ ulong len = file.readBlock( 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;
+ file.at( offset );
+ len = file.readBlock( 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.at( offset );
+ }
+
+ file.close();
+
+ QApplication::restoreOverrideCursor();
+ }
+
+ if ( completed == total_steps ) {
+ setNextEnabled( selectLibrary, TRUE );
+
+ QString prefix = QFile::decodeName( steps[0].value );
+ prefixPath->setText( prefix );
+
+ QString def_bin = prefix + QString::fromLatin1( "/bin" );
+ QString def_doc = prefix + QString::fromLatin1( "/doc" );
+ QString def_hdr = prefix + QString::fromLatin1( "/include" );
+ QString def_lib = prefix + QString::fromLatin1( "/lib" );
+ QString def_plg = prefix + QString::fromLatin1( "/plugins" );
+ QString def_dat = prefix;
+
+ QString bin = QFile::decodeName( steps[1].value );
+ QString doc = QFile::decodeName( steps[2].value );
+ QString hdr = QFile::decodeName( steps[3].value );
+ QString lib = QFile::decodeName( steps[4].value );
+ QString plg = QFile::decodeName( steps[5].value );
+ QString dat = QFile::decodeName( 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 QString &prefix )
+{
+ if ( autoSet->isChecked() ) {
+ binPath->setText( prefix + QString::fromLatin1( "/bin" ) );
+ docPath->setText( prefix + QString::fromLatin1( "/doc" ) );
+ hdrPath->setText( prefix + QString::fromLatin1( "/include" ) );
+ libPath->setText( prefix + QString::fromLatin1( "/lib" ) );
+ plgPath->setText( prefix + QString::fromLatin1( "/plugins" ) );
+ datPath->setText( prefix );
+ }
+}
+
+void Distributor::browseInstallationPrefix()
+{
+ QString prefix =
+ QFileDialog::getOpenFileName( QString::null, QString::null, this );
+ prefixPath->setText( prefix );
+}
+
+
+void Distributor::toggleAutoSet( bool autoset )
+{
+ if ( autoset ) checkInstallationPrefix( prefixPath->text() );
+}
+
+void Distributor::accept()
+{
+ struct step {
+ const char *key;
+ QCString value;
+ bool done;
+ } steps[7];
+
+ steps[0].key = "qt_nstpath=";
+ steps[0].value = QFile::encodeName( prefixPath->text() );
+ steps[0].done = FALSE;
+
+ steps[1].key = "qt_binpath=";
+ steps[1].value = QFile::encodeName( binPath->text() );
+ steps[1].done = FALSE;
+
+ steps[2].key = "qt_docpath=";
+ steps[2].value = QFile::encodeName( docPath->text() );
+ steps[2].done = FALSE;
+
+ steps[3].key = "qt_hdrpath=";
+ steps[3].value = QFile::encodeName( hdrPath->text() );
+ steps[3].done = FALSE;
+
+ steps[4].key = "qt_libpath=";
+ steps[4].value = QFile::encodeName( libPath->text() );
+ steps[4].done = FALSE;
+
+ steps[5].key = "qt_plgpath=";
+ steps[5].value = QFile::encodeName( plgPath->text() );
+ steps[5].done = FALSE;
+
+ steps[6].key = "qt_datpath=";
+ steps[6].value = QFile::encodeName( datPath->text() );
+ steps[6].done = FALSE;
+
+ uint completed = 0;
+ uint total_steps = sizeof(steps) / sizeof(step);
+
+ QFile file( libFilename->text() );
+ if ( file.open( IO_ReadWrite ) ) {
+ QApplication::setOverrideCursor( WaitCursor );
+
+ // instead of reading in the entire file, do the search in chunks
+ char data[60000];
+ ulong offset = 0;
+
+ while ( ! file.atEnd() && completed < total_steps ) {
+ QApplication::eventLoop()->processEvents( QEventLoop::ExcludeUserInput );
+
+ ulong len = file.readBlock( 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.at( offset );
+ len = file.readBlock( data, sizeof(data) );
+ --x; // retry the current step
+ continue;
+ }
+
+ qstrcpy( 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.at( offset );
+ file.writeBlock( data, len );
+ }
+
+ // move to the new read position
+ offset += len - 11;
+ file.at( offset );
+ }
+
+ file.close();
+
+ QApplication::restoreOverrideCursor();
+ }
+
+ if ( completed != total_steps ) {
+ QMessageBox::information( this,
+ tr("Qt Distribution Wizard"),
+ tr("Modifications failed.
"
+ "Please make sure that you have permission "
+ "to write the selected file, and that the library "
+ "is properly built.
") );
+ return;
+ }
+
+ QWizard::accept();
+}
diff --git a/examples/distributor/main.cpp b/examples/distributor/main.cpp
new file mode 100644
index 0000000..cded77d
--- /dev/null
+++ b/examples/distributor/main.cpp
@@ -0,0 +1,11 @@
+#include
+#include "distributor.h"
+
+int main( int argc, char ** argv )
+{
+ QApplication a( argc, argv );
+ Distributor w;
+ w.show();
+ a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
+ return a.exec();
+}
--
cgit v1.2.1