src/app/qgsabout.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           qgsabout.cpp  -  description
00003                              -------------------
00004     begin                : Sat Aug 10 2002
00005     copyright            : (C) 2002 by Gary E.Sherman
00006     email                : sherman at mrcc.com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 /* $Id: qgsabout.cpp 9138 2008-08-23 21:37:31Z jef $ */
00018 
00019 #include "qgsabout.h"
00020 #include "qgsapplication.h"
00021 #include "qgsproviderregistry.h"
00022 #include "qgslogger.h"
00023 #include <QDesktopServices>
00024 #include <QFile>
00025 #include <QTextStream>
00026 #include <QImageReader>
00027 #include <QSqlDatabase>
00028 
00029 /* Uncomment this block to use preloaded images
00030 #include <map>
00031 #include "qgslogger.h"
00032 std::map<QString, QPixmap> mugs;
00033 */
00034 
00035 QgsAbout::QgsAbout()
00036     : QDialog( NULL, Qt::WindowSystemMenuHint )  // Modeless dialog with close button only
00037 {
00038   setupUi( this );
00039   init();
00040 }
00041 
00042 QgsAbout::~QgsAbout()
00043 {
00044 }
00045 
00046 void QgsAbout::init()
00047 {
00048   setPluginInfo();
00049 
00050   // set the 60x60 icon pixmap
00051   QPixmap icon( QgsApplication::iconsPath() + "qgis-icon-60x60.png" );
00052   qgisIcon->setPixmap( icon );
00053 
00054   //read the authors file to populate the contributors list
00055   QStringList lines;
00056 
00057   QFile file( QgsApplication::authorsFilePath() );
00058 #ifdef QGISDEBUG
00059   printf(( "Reading authors file " + file.fileName() +
00060            ".............................................\n" ).toLocal8Bit().constData() );
00061 #endif
00062   if ( file.open( QIODevice::ReadOnly ) )
00063   {
00064     QTextStream stream( &file );
00065     // Always use UTF-8
00066     stream.setCodec( "UTF-8" );
00067     QString line;
00068 #ifdef QGISDEBUG
00069     int i = 1;
00070 #endif
00071 
00072     while ( !stream.atEnd() )
00073     {
00074       line = stream.readLine(); // line of text excluding '\n'
00075       //ignore the line if it starts with a hash....
00076       if ( line.left( 1 ) == "#" ) continue;
00077 #ifdef QGISDEBUG
00078       printf( "Contributor: %3d: %s\n", i++, line.toLocal8Bit().constData() );
00079 #endif
00080       QStringList myTokens = line.split( "\t", QString::SkipEmptyParts );
00081       //printf ("Added contributor name to listbox: %s ",myTokens[0]);
00082       lines += myTokens[0];
00083 
00084       // add the image to the map
00085       /* Uncomment this block to preload the images (takes time at initial startup)
00086       QString authorName = myTokens[0].replace(" ","_");
00087 
00088       QString myString =QString(appPath + "/images/developers/") + authorName + QString(".jpg");
00089       printf ("Loading mug: %s\n", myString.toLocal8Bit().constData());
00090       QPixmap *pixmap = new QPixmap(myString);
00091       mugs[myTokens[0]] = *pixmap;
00092       */
00093     }
00094     file.close();
00095     listBox1->clear();
00096     listBox1->insertItems( 0, lines );
00097 
00098     // Load in the image for the first author
00099     if ( listBox1->count() > 0 )
00100       listBox1->setCurrentRow( 0 );
00101   }
00102 
00103   // read the SPONSORS file and populate the text widget
00104   QFile sponsorFile( QgsApplication::sponsorsFilePath() );
00105 #ifdef QGISDEBUG
00106   printf(( "Reading sponsors file " + sponsorFile.fileName() +
00107            ".............................................\n" ).toLocal8Bit().constData() );
00108 #endif
00109   if ( sponsorFile.open( QIODevice::ReadOnly ) )
00110   {
00111     QString sponsorHTML = ""
00112                           + tr( "<p>The following have sponsored QGIS by contributing "
00113                                 "money to fund development and other project costs</p>" )
00114                           + "<hr>"
00115                           "<table width='100%'>"
00116                           "<tr><th>" + tr( "Name" ) + "</th>"
00117                           "<th>" + tr( "Website" ) + "</th></tr>";
00118     QString website;
00119     QTextStream sponsorStream( &sponsorFile );
00120     // Always use UTF-8
00121     sponsorStream.setCodec( "UTF-8" );
00122     QString sline;
00123     while ( !sponsorStream.atEnd() )
00124     {
00125       sline = sponsorStream.readLine(); // line of text excluding '\n'
00126       //ignore the line if it starts with a hash....
00127       if ( sline.left( 1 ) == "#" ) continue;
00128       QStringList myTokens = sline.split( "|", QString::SkipEmptyParts );
00129       if ( myTokens.size() > 1 )
00130       {
00131         website = myTokens[1];
00132       }
00133       else
00134       {
00135         website = "&nbsp;";
00136       }
00137       sponsorHTML += "<tr>";
00138       sponsorHTML += "<td>" + myTokens[0] + "</td><td>" + website + "</td>";
00139       // close the row
00140       sponsorHTML += "</tr>";
00141     }
00142     sponsorHTML += "</table>";
00143 
00144     QString myStyle = QgsApplication::reportStyleSheet();
00145     txtSponsors->clear();
00146     txtSponsors->document()->setDefaultStyleSheet( myStyle );
00147     txtSponsors->setHtml( sponsorHTML );
00148     QgsDebugMsg( QString( "sponsorHTML:%1" ).arg( sponsorHTML.toAscii().constData() ) );
00149     QgsDebugMsg( QString( "txtSponsors:%1" ).arg( txtSponsors->toHtml().toAscii().constData() ) );
00150   }
00151 }
00152 
00153 void QgsAbout::setVersion( QString v )
00154 {
00155   lblVersion->setText( v );
00156 }
00157 
00158 void QgsAbout::setWhatsNew( QString txt )
00159 {
00160   QString myStyle = QgsApplication::reportStyleSheet();
00161   txtWhatsNew->clear();
00162   txtWhatsNew->document()->setDefaultStyleSheet( myStyle );
00163   txtWhatsNew->setHtml( txt );
00164 }
00165 
00166 void QgsAbout::setPluginInfo()
00167 {
00168   QString myString;
00169   //provide info about the plugins available
00170   myString += "<b>" + tr( "Available QGIS Data Provider Plugins" ) + "</b><br>";
00171   myString += QgsProviderRegistry::instance()->pluginList( true );
00172   //qt database plugins
00173   myString += "<b>" + tr( "Available Qt Database Plugins" ) + "</b><br>";
00174   myString += "<ol>\n<li>\n";
00175   QStringList myDbDriverList = QSqlDatabase::drivers();
00176   myString += myDbDriverList.join( "</li>\n<li>" );
00177   myString += "</li>\n</ol>\n";
00178   //qt image plugins
00179   myString += "<b>" + tr( "Available Qt Image Plugins" ) + "</b><br>";
00180   myString += "<ol>\n<li>\n";
00181   QList<QByteArray> myImageFormats = QImageReader::supportedImageFormats();
00182   QList<QByteArray>::const_iterator myIterator = myImageFormats.begin();
00183   while ( myIterator != myImageFormats.end() )
00184   {
00185     QString myFormat = ( *myIterator ).data();
00186     myString += myFormat + "</li>\n<li>";
00187     ++myIterator;
00188   }
00189   myString += "</li>\n</ol>\n";
00190 
00191   QString myStyle = QgsApplication::reportStyleSheet();
00192   txtBrowserPlugins->clear();
00193   txtBrowserPlugins->document()->setDefaultStyleSheet( myStyle );
00194   txtBrowserPlugins->setText( myString );
00195 }
00196 
00197 void QgsAbout::on_buttonCancel_clicked()
00198 {
00199   reject();
00200 }
00201 
00202 void QgsAbout::on_listBox1_currentItemChanged( QListWidgetItem *theItem )
00203 {
00204   //replace spaces in author name
00205 #ifdef QGISDEBUG
00206   printf( "Loading mug: " );
00207 #endif
00208   QString myString = listBox1->currentItem()->text();
00209   myString = myString.replace( " ", "_" );
00210   myString = QgsAbout::fileSystemSafe( myString );
00211 #ifdef QGISDEBUG
00212   printf( "Loading mug: %s", myString.toLocal8Bit().constData() );
00213 #endif
00214   myString = QgsApplication::developerPath() + myString + QString( ".jpg" );
00215 #ifdef QGISDEBUG
00216   printf( "Loading mug: %s\n", myString.toLocal8Bit().constData() );
00217 #endif
00218 
00219   /* Uncomment this block to use preloaded images
00220   pixAuthorMug->setPixmap(mugs[myString]);
00221   */
00222 }
00223 
00224 void QgsAbout::on_btnQgisUser_clicked()
00225 {
00226   // find a browser
00227   QString url = "http://lists.osgeo.org/mailman/listinfo/qgis-user";
00228   openUrl( url );
00229 }
00230 
00231 void QgsAbout::on_btnQgisHome_clicked()
00232 {
00233   openUrl( "http://qgis.org" );
00234 }
00235 
00236 void QgsAbout::openUrl( QString url )
00237 {
00238   //use the users default browser
00239   QDesktopServices::openUrl( url );
00240 }
00241 
00242 /*
00243  * The function below makes a name safe for using in most file system
00244  * Step 1: Code QString as UTF-8
00245  * Step 2: Replace all bytes of the UTF-8 above 0x7f with the hexcode in lower case.
00246  * Step 2: Replace all non [a-z][a-Z][0-9] with underscore (backward compatibility)
00247  */
00248 QString QgsAbout::fileSystemSafe( QString fileName )
00249 {
00250   QString result;
00251   QByteArray utf8 = fileName.toUtf8();
00252 
00253   for ( int i = 0; i < utf8.size(); i++ )
00254   {
00255     uchar c = utf8[i];
00256 
00257     if ( c > 0x7f )
00258     {
00259       result = result + QString( "%1" ).arg( c, 2, 16, QChar( '0' ) );
00260     }
00261     else
00262     {
00263       result = result + QString( c );
00264     }
00265   }
00266   result.replace( QRegExp( "[^a-z0-9A-Z]" ), "_" );
00267   QgsDebugMsg( result );
00268 
00269   return result;
00270 }

Generated on Tue Oct 28 16:51:25 2008 for Quantum GIS API Documentation by  doxygen 1.5.1