Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

main.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Tim Sutton   *
00003  *   tim@linfiniti.com   *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 
00022 #ifdef HAVE_CONFIG_H
00023 #include <config.h>
00024 #endif
00025 
00026 #include "omgmainwindow.h"
00027 #include "omgtermsandconditions.h"
00028 #include "omgui.h"
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 //qt includes
00032 #include <QApplication>
00033 #include <QBitmap>
00034 #include <QDir>
00035 #include <QPixmap>
00036 #include <QPlastiqueStyle>
00037 #include <QSettings>
00038 #include <QString>
00039 #include <QStyle>
00040 #include <QSettings>
00041 #include <QTextCodec>
00042 #include <QLocale>
00043 #include <QTranslator>
00044 #include <QImageReader>
00045 
00046 #include <cpl_conv.h> // for setting gdal options
00047 
00048 
00049 #ifdef WITH_QGIS
00050 //
00051 // QGIS Includes
00052 //
00053 #include <qgsapplication.h>
00054 #endif
00055 
00056 #if STATIC_BUILD
00057  #include <QtCore/QtPlugin>
00058  Q_IMPORT_PLUGIN(qjpeg)
00059  Q_IMPORT_PLUGIN(qsvg)
00060 #endif
00061 
00062 #ifdef Q_OS_MACX
00063 //for getting app bundle path
00064 #include <ApplicationServices/ApplicationServices.h>
00065 #endif
00066 //std includes
00067 
00068 int main(int argc, char *argv[])
00069 {
00070 #ifdef WITH_QGIS
00071   QgsApplication myApp(argc,argv,true);
00072 
00073 #else
00074   QApplication  myApp(argc,argv);
00075 #endif
00076 
00077   //NOTE: make sure these lines stay after myApp init above
00078   QCoreApplication::setOrganizationName("openModeller");
00079   QCoreApplication::setOrganizationDomain("openmodeller.sf.net");
00080   QCoreApplication::setApplicationName("OpenModellerGui");
00081 
00082   // For non static builds on mac and win
00083   // we need to be sure we can find the qt image
00084   // plugins. In mac be sure to look in the
00085   // application bundle...
00086 #ifdef Q_WS_WIN
00087   QApplication::addLibraryPath( QApplication::applicationDirPath() 
00088       + QDir::separator() + "plugins" );
00089 #endif
00090 #ifdef Q_OS_MACX
00091   qDebug("Adding qt image plugins to plugin search path...");
00092   CFURLRef myBundleRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
00093   CFStringRef myMacPath = CFURLCopyFileSystemPath(myBundleRef, kCFURLPOSIXPathStyle);
00094   const char *mypPathPtr = CFStringGetCStringPtr(myMacPath,CFStringGetSystemEncoding());
00095   CFRelease(myBundleRef);
00096   CFRelease(myMacPath);
00097   QString myPath(mypPathPtr);
00098   // if we are not in a bundle assume that the app is built
00099   // as a non bundle app and that image plugins will be
00100   // in system Qt frameworks. If the app is a bundle
00101   // lets try to set the qt plugin search path...
00102   if (myPath.contains(".app"))
00103   {
00104     QString myPluginPath = myPath + "/Contents/plugins";
00105     QApplication::addLibraryPath( myPluginPath );
00106     qDebug( "Added %s to plugin search path", qPrintable( myPluginPath ) );
00107     //
00108     // Set the search path for Gdal CSV data files
00109     //
00110     QString myGdalDataPath = myPath + "/Contents/MacOS/share";
00111     CPLSetConfigOption("GDAL_DATA", myGdalDataPath.toLocal8Bit()); 
00112     // verify ...
00113     if( CPLGetConfigOption("GDAL_DATA",NULL) != NULL )
00114     {
00115       myGdalDataPath = QString(CPLGetConfigOption("GDAL_DATA",NULL));
00116       qDebug("GDAL_DATA set to :" + myGdalDataPath.toLocal8Bit());
00117     }
00118     else
00119     {
00120       qDebug("Warning GDAL_DATA is not set and thus projections");
00121       qDebug("may not work properly...");
00122     }
00123   }
00124 #endif
00125 
00126 
00127 
00128   //
00129   // QGis plugin paths
00130   //
00131 #ifdef Q_WS_WIN
00132   myApp.setPluginPath(myApp.applicationDirPath() + QDir::separator() + 
00133       "lib" + QDir::separator() + "qgis");
00134   myApp.setPkgDataPath(myApp.applicationDirPath() + QDir::separator() + 
00135       "share" + QDir::separator() + "qgis");
00136   //qDebug("plugin path:" + myApp.pluginPath().toLocal8Bit());
00137 #endif
00138   qDebug("srs path:" + myApp.srsDbFilePath().toLocal8Bit());
00139 
00140   QImageReader::supportedImageFormats(); // will check for qt image plugins
00141 #ifdef Q_WS_WIN
00142   //for windows lets use plastique syle!
00143   QApplication::setStyle(new QPlastiqueStyle);
00144 #endif
00145   //make the library search path include the application dir on windows
00146   //this is so the plugins can find the dlls they are linked to at run time
00147   QApplication::addLibraryPath(QApplication::applicationDirPath());
00148 
00149   //
00150   // Set up the stylesheet
00151   // gradieted colour for header views
00152   //QString myStyle = "QHeaderView::section { background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #616161, stop: 0.5 #505050, stop: 0.6 #434343, stop:1 #656565); color: white; padding-left: 4px; border: 1px solid #6c6c6c; }";
00153   //myApp.setStyleSheet(myStyle);
00154 
00155   //
00156   // Set up translations
00157   //
00158   QSettings mySettings;
00159   QString mySystemLocale = QLocale::languageToString(QLocale::system().language());
00160   QString myUserLocale = mySettings.value("locale/userLocale", "").toString();
00161   bool myLocaleOverrideFlag = mySettings.value("locale/overrideFlag",false).toBool();
00162   QString myI18nPath = Omgui::i18nPath();
00163   QString myLocale;
00164   if (!myLocaleOverrideFlag || myUserLocale.isEmpty())
00165   {
00166     myLocale = QTextCodec::locale();
00167   }
00168   else
00169   {
00170     myLocale = myUserLocale;
00171   }
00172   //qDebug( "Setting translation to "
00173   //+ myI18nPath.toLocal8Bit()  + "/openModellerDesktop_" +
00174   //myLocale.toLocal8Bit());
00175 
00176   /* Translation file for Qt.
00177    * The strings from the QMenuBar context section are used by Qt/Mac to shift
00178    * the About, Preferences and Quit items to the Mac Application menu.
00179    * These items must be translated identically in both qt_ and qgis_ files.
00180    */
00181   QTranslator myQtTranslator(0);
00182   if (myQtTranslator.load(QString("qt_") + myLocale, myI18nPath))
00183   {
00184     myApp.installTranslator(&myQtTranslator);
00185     //qDebug("openModellerDesktop_" + myLocale.toLocal8Bit() + " locale loaded for Qt");
00186   }
00187 
00188   /* Translation file for openModeller Desktop.
00189   */
00190   QTranslator myOmgTranslator(0);
00191   if (myOmgTranslator.load(QString("openModellerDesktop_") + myLocale, myI18nPath))
00192   {
00193     myApp.installTranslator(&myOmgTranslator);
00194     //qDebug("openModellerDesktop_" + myLocale.toLocal8Bit() + " locale loaded for openModeller");
00195   }
00196 
00197   //
00198   // Now set up the main window and lauch the app
00199   //
00200   OmgMainWindow * mypOmg = new OmgMainWindow();
00201   if (mySettings.value("licensing/termsAgreedFlag",false).toBool()!=true)
00202   {
00203     OmgTermsAndConditions myTerms;
00204     if (myTerms.exec()!=QDialog::Accepted)
00205     {
00206       return false;
00207     }
00208   }
00209   mypOmg->show();
00210   // note if the widget does not inherit qdialog
00211   // (as in the case of our main window)
00212   // you must call app exec!
00213   return myApp.exec();
00214 
00215 }
00216 

Generated on Mon Apr 28 15:06:38 2008 for openModellerDesktop by  doxygen 1.4.1-20050210