25 #include <QFileOpenEvent>
26 #include <QMessageBox>
34 #include <netinet/in.h>
39 #include "qgsconfig.h"
46 QObject *
ABISYM( QgsApplication::mFileOpenEventReceiver );
47 QStringList
ABISYM( QgsApplication::mFileOpenEventList );
48 QString
ABISYM( QgsApplication::mPrefixPath );
49 QString
ABISYM( QgsApplication::mPluginPath );
50 QString
ABISYM( QgsApplication::mPkgDataPath );
51 QString
ABISYM( QgsApplication::mLibraryPath );
52 QString
ABISYM( QgsApplication::mLibexecPath );
53 QString
ABISYM( QgsApplication::mThemeName );
54 QStringList
ABISYM( QgsApplication::mDefaultSvgPaths );
55 QMap<QString, QString>
ABISYM( QgsApplication::mSystemEnvVars );
56 QString
ABISYM( QgsApplication::mConfigPath );
57 bool ABISYM( QgsApplication::mRunningFromBuildDir ) =
false;
58 QString
ABISYM( QgsApplication::mBuildSourcePath );
60 QString
ABISYM( QgsApplication::mCfgIntDir );
62 QString
ABISYM( QgsApplication::mBuildOutputPath );
63 QStringList
ABISYM( QgsApplication::mGdalSkipList );
79 : QApplication( argc, argv, GUIenabled )
81 init( customConfigPath );
86 if ( customConfigPath.isEmpty() )
88 customConfigPath = QDir::homePath() + QString(
"/.qgis%1/" ).arg( 2 );
91 qRegisterMetaType<QgsGeometry::Error>(
"QgsGeometry::Error" );
93 QString
prefixPath( getenv(
"QGIS_PREFIX_PATH" ) ? getenv(
"QGIS_PREFIX_PATH" ) : applicationDirPath() );
98 foreach ( QString path, QStringList() <<
"" <<
"/.." <<
"/bin" <<
"/../../.." )
100 f.setFileName( prefixPath + path +
"/qgisbuildpath.txt" );
104 if ( f.exists() && f.open( QIODevice::ReadOnly ) )
106 ABISYM( mRunningFromBuildDir ) =
true;
107 ABISYM( mBuildSourcePath ) = f.readLine().trimmed();
108 ABISYM( mBuildOutputPath ) = f.readLine().trimmed();
109 qDebug(
"Running from build directory!" );
110 qDebug(
"- source directory: %s",
ABISYM( mBuildSourcePath ).toUtf8().data() );
111 qDebug(
"- output directory of the build: %s",
ABISYM( mBuildOutputPath ).toUtf8().data() );
113 ABISYM( mCfgIntDir ) = prefixPath.split(
"/", QString::SkipEmptyParts ).last();
114 qDebug(
"- cfg: %s",
ABISYM( mCfgIntDir ).toUtf8().data() );
118 if (
ABISYM( mRunningFromBuildDir ) )
121 ABISYM( mPrefixPath ) = QString();
122 #if defined(_MSC_VER) && !defined(USING_NMAKE)
128 ABISYM( mLibraryPath ) =
ABISYM( mBuildOutputPath ) +
"/" + QGIS_LIB_SUBDIR +
"/";
129 #if defined(_MSC_VER) && !defined(USING_NMAKE)
130 ABISYM( mLibexecPath ) =
ABISYM( mBuildOutputPath ) +
"/" + QGIS_LIBEXEC_SUBDIR +
"/" +
ABISYM( mCfgIntDir ) +
"/";
132 ABISYM( mLibexecPath ) =
ABISYM( mBuildOutputPath ) +
"/" + QGIS_LIBEXEC_SUBDIR +
"/";
137 char *prefixPath = getenv(
"QGIS_PREFIX_PATH" );
140 #if defined(Q_WS_MACX) || defined(Q_WS_WIN32) || defined(WIN32)
143 QDir myDir( applicationDirPath() );
145 QString myPrefix = myDir.absolutePath();
155 if ( !customConfigPath.isEmpty() )
157 ABISYM( mConfigPath ) = customConfigPath +
"/";
163 QMap<QString, QString> systemEnvVarMap;
164 foreach (
const QString &varStr, QProcess::systemEnvironment() )
166 int pos = varStr.indexOf( QLatin1Char(
'=' ) );
169 QString varStrName = varStr.left( pos );
170 QString varStrValue = varStr.mid( pos + 1 );
171 systemEnvVarMap.insert( varStrName, varStrValue );
173 ABISYM( mSystemEnvVars ) = systemEnvVarMap;
184 if ( event->type() == QEvent::FileOpen )
187 if (
ABISYM( mFileOpenEventReceiver ) )
190 done =
notify(
ABISYM( mFileOpenEventReceiver ), event );
197 ABISYM( mFileOpenEventList ).append( static_cast<QFileOpenEvent *>( event )->
file() );
213 if ( thread() == receiver->thread() )
214 emit
preNotify( receiver, event, &done );
227 QMessageBox::critical( activeWindow(),
tr(
"Exception" ), e.
what() );
229 catch ( std::exception & e )
231 QMessageBox::critical( activeWindow(),
tr(
"Exception" ), e.what() );
235 QMessageBox::critical( activeWindow(),
tr(
"Exception" ),
tr(
"unknown exception" ) );
244 ABISYM( mFileOpenEventReceiver ) = receiver;
246 if (
ABISYM( mFileOpenEventList ).count() > 0 )
248 QStringListIterator i(
ABISYM( mFileOpenEventList ) );
249 while ( i.hasNext() )
251 QFileOpenEvent foe( i.next() );
252 QgsApplication::sendEvent(
ABISYM( mFileOpenEventReceiver ), &foe );
254 ABISYM( mFileOpenEventList ).clear();
260 ABISYM( mPrefixPath ) = thePrefixPath;
261 #if defined(_MSC_VER)
262 if (
ABISYM( mPrefixPath ).endsWith(
"/bin" ) )
264 ABISYM( mPrefixPath ).chop( 4 );
267 if ( useDefaultPaths && !
ABISYM( mRunningFromBuildDir ) )
272 ABISYM( mLibraryPath ) =
ABISYM( mPrefixPath ) +
"/" + QGIS_LIB_SUBDIR +
"/";
273 ABISYM( mLibexecPath ) =
ABISYM( mPrefixPath ) +
"/" + QGIS_LIBEXEC_SUBDIR +
"/";
278 ABISYM( mPluginPath ) = thePluginPath;
283 ABISYM( mPkgDataPath ) = thePkgDataPath;
284 QString mySvgPath = thePkgDataPath + (
ABISYM( mRunningFromBuildDir ) ?
"/images/svg/" :
"/svg/" );
286 if ( !
ABISYM( mDefaultSvgPaths ).contains( mySvgPath ) )
287 ABISYM( mDefaultSvgPaths ) << mySvgPath;
292 ABISYM( mDefaultSvgPaths ) = pathList;
297 if (
ABISYM( mRunningFromBuildDir ) )
299 qWarning(
"!!! prefix path was requested, but it is not valid - we do not run from installed path !!!" );
302 return ABISYM( mPrefixPath );
306 return ABISYM( mPluginPath );
310 return ABISYM( mPkgDataPath );
314 return ":/images/themes/default/";
318 return ":/images/themes/" +
themeName() +
"/";
326 if ( QFile::exists( path + iconFile ) )
327 return path + iconFile;
335 QString myPreferredPath =
activeThemePath() + QDir::separator() + theName;
337 if ( QFile::exists( myPreferredPath ) )
339 return QIcon( myPreferredPath );
341 else if ( QFile::exists( myDefaultPath ) )
345 return QIcon( myDefaultPath );
356 QString myPreferredPath =
activeThemePath() + QDir::separator() + theName;
358 if ( QFile::exists( myPreferredPath ) )
360 return QPixmap( myPreferredPath );
366 return QPixmap( myDefaultPath );
375 QString myPath =
":/images/themes/" + theThemeName +
"/";
377 if ( QFile::exists( myPath ) )
379 ABISYM( mThemeName ) = theThemeName;
383 ABISYM( mThemeName ) =
"default";
391 return ABISYM( mThemeName );
398 return ABISYM( mPkgDataPath ) + QString(
"/doc/AUTHORS" );
405 return ABISYM( mPkgDataPath ) + QString(
"/doc/CONTRIBUTORS" );
412 return ABISYM( mPkgDataPath ) + QString(
"/doc/SPONSORS" );
420 return ABISYM( mPkgDataPath ) + QString(
"/doc/DONORS" );
429 return ABISYM( mPkgDataPath ) + QString(
"/doc/TRANSLATORS" );
437 return ABISYM( mPkgDataPath ) + QString(
"/doc/LICENCE" );
447 helpAppPath = applicationDirPath() +
"/bin/qgis_help.app/Contents/MacOS";
451 helpAppPath +=
"/qgis_help";
453 helpAppPath +=
".exe";
462 if (
ABISYM( mRunningFromBuildDir ) )
463 return ABISYM( mBuildOutputPath ) + QString(
"/i18n" );
465 return ABISYM( mPkgDataPath ) + QString(
"/i18n/" );
473 return ABISYM( mPkgDataPath ) + QString(
"/resources/qgis.db" );
481 return ABISYM( mConfigPath );
497 return QString(
":/images/splash/" );
505 return ABISYM( mPkgDataPath ) + QString(
"/images/icons/" );
512 if (
ABISYM( mRunningFromBuildDir ) )
514 QString tempCopy = QDir::tempPath() +
"/srs.db";
516 if ( !QFile( tempCopy ).exists() )
518 QFile f(
ABISYM( mPkgDataPath ) +
"/resources/srs.db" );
519 if ( !f.copy( tempCopy ) )
521 qFatal(
"Could not create temporary copy" );
529 return ABISYM( mPkgDataPath ) + QString(
"/resources/srs.db" );
541 QStringList myPathList;
542 QString myPaths = settings.value(
"svg/searchPathsForSVG",
"" ).toString();
543 if ( !myPaths.isEmpty() )
545 myPathList = myPaths.split(
"|" );
548 myPathList <<
ABISYM( mDefaultSvgPaths );
559 return ABISYM( mPkgDataPath ) + QString(
"/resources/symbology-ng-style.db" );
564 return ABISYM( mLibraryPath );
569 return ABISYM( mLibexecPath );
574 return ( htonl( 1 ) == 1 ) ?
XDR :
NDR ;
594 QString myEnvironmentVar( getenv(
"QGIS_PREFIX_PATH" ) );
595 QString myState =
tr(
"Application state:\n"
596 "QGIS_PREFIX_PATH env var:\t\t%1\n"
598 "Plugin Path:\t\t%3\n"
599 "Package Data Path:\t%4\n"
600 "Active Theme Name:\t%5\n"
601 "Active Theme Path:\t%6\n"
602 "Default Theme Path:\t%7\n"
603 "SVG Search Paths:\t%8\n"
604 "User DB Path:\t%9\n" )
605 .arg( myEnvironmentVar )
612 .arg(
svgPaths().join(
tr(
"\n\t\t",
"match indentation of application state" ) ) )
624 QColor myColor1( Qt::lightGray );
625 QColor myColor2 = myColor1;
626 myColor2 = myColor2.lighter( 110 );
628 myStyle =
"p.glossy{ background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, "
629 " stop: 0 " + myColor1.name() +
","
630 " stop: 0.1 " + myColor2.name() +
","
631 " stop: 0.5 " + myColor1.name() +
","
632 " stop: 0.9 " + myColor2.name() +
","
633 " stop: 1 " + myColor1.name() +
");"
635 " padding-left: 4px;"
636 " padding-top: 20px;"
637 " padding-bottom: 8px;"
638 " border: 1px solid #6c6c6c;"
640 "p.subheaderglossy{ background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, "
641 " stop: 0 " + myColor1.name() +
","
642 " stop: 0.1 " + myColor2.name() +
","
643 " stop: 0.5 " + myColor1.name() +
","
644 " stop: 0.9 " + myColor2.name() +
","
645 " stop: 1 " + myColor1.name() +
");"
646 " font-weight: bold;"
647 " font-size: medium;"
648 " line-height: 1.1em;"
651 " padding-left: 4px;"
652 " padding-right: 4px;"
653 " padding-top: 20px;"
654 " padding-bottom: 8px;"
655 " border: 1px solid #6c6c6c;"
657 "th.glossy{ background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, "
658 " stop: 0 " + myColor1.name() +
","
659 " stop: 0.1 " + myColor2.name() +
","
660 " stop: 0.5 " + myColor1.name() +
","
661 " stop: 0.9 " + myColor2.name() +
","
662 " stop: 1 " + myColor1.name() +
");"
664 " border: 1px solid #6c6c6c;"
666 ".overview{ font: 1.82em; font-weight: bold;}"
667 "body{ background: white;"
669 " font-family: arial,sans-serif;"
671 "h1{ background-color: #F6F6F6;"
673 " font-size: x-large; "
674 " font-weight: normal;"
675 " font-family: luxi serif, georgia, times new roman, times, serif;"
677 " padding: 0.75em 0 0;"
681 "h2{ background-color: #F6F6F6;"
683 " font-size: medium; "
684 " font-weight: normal;"
685 " font-family: luxi serif, georgia, times new roman, times, serif;"
687 " padding: 0.75em 0 0;"
689 " line-height: 1.1em;"
691 "h3{ background-color: #F6F6F6;"
693 " font-family: luxi serif, georgia, times new roman, times, serif;"
694 " font-weight: bold;"
696 " text-align: right;"
697 " border-bottom: 5px solid #DCEB5C;"
699 "h4{ background-color: #F6F6F6;"
701 " font-family: luxi serif, georgia, times new roman, times, serif;"
702 " font-weight: bold;"
703 " font-size: medium;"
704 " text-align: right;"
706 "h5{ background-color: #F6F6F6;"
708 " font-family: luxi serif, georgia, times new roman, times, serif;"
709 " font-weight: bold;"
711 " text-align: right;"
714 " font-family: arial,sans-serif;"
717 "label{ background-color: #FFFFCC;"
718 " border: 1px solid black;"
720 " padding: 0px 3px; "
728 if ( 0 >= OGRGetDriverCount() )
736 #if defined( Q_OS_WIN )
737 const Qt::CaseSensitivity cs = Qt::CaseInsensitive;
739 aPath.replace(
"\\",
"/" );
740 if ( aPath.startsWith(
"//" ) )
743 aPath =
"\\\\" + aPath.mid( 2 );
746 targetPath.replace(
"\\",
"/" );
747 if ( targetPath.startsWith(
"//" ) )
750 targetPath =
"\\\\" + targetPath.mid( 2 );
753 const Qt::CaseSensitivity cs = Qt::CaseSensitive;
756 QStringList targetElems = targetPath.split(
"/", QString::SkipEmptyParts );
757 QStringList aPathElems = aPath.split(
"/", QString::SkipEmptyParts );
759 targetElems.removeAll(
"." );
760 aPathElems.removeAll(
"." );
764 while ( aPathElems.size() > 0 &&
765 targetElems.size() > 0 &&
766 aPathElems[0].compare( targetElems[0], cs ) == 0 )
768 aPathElems.removeFirst();
769 targetElems.removeFirst();
779 if ( targetElems.size() > 0 )
782 for (
int i = 0; i < targetElems.size(); i++ )
784 aPathElems.insert( 0,
".." );
791 aPathElems.insert( 0,
"." );
794 return aPathElems.join(
"/" );
800 if ( !rpath.startsWith(
"./" ) && !rpath.startsWith(
"../" ) )
805 #if defined(Q_OS_WIN)
806 rpath.replace(
"\\",
"/" );
807 targetPath.replace(
"\\",
"/" );
809 bool uncPath = targetPath.startsWith(
"//" );
812 QStringList srcElems = rpath.split(
"/", QString::SkipEmptyParts );
813 QStringList targetElems = targetPath.split(
"/", QString::SkipEmptyParts );
815 #if defined(Q_OS_WIN)
818 targetElems.insert( 0,
"" );
819 targetElems.insert( 0,
"" );
824 targetElems << srcElems;
825 targetElems.removeAll(
"." );
829 while (( pos = targetElems.indexOf(
".." ) ) > 0 )
832 targetElems.removeAt( pos - 1 );
833 targetElems.removeAt( pos - 1 );
836 #if !defined(Q_OS_WIN)
838 targetElems.prepend(
"" );
841 return targetElems.join(
"/" );
846 if (
ABISYM( mGdalSkipList ).contains( theDriver ) || theDriver.isEmpty() )
850 ABISYM( mGdalSkipList ) << theDriver;
856 if ( !
ABISYM( mGdalSkipList ).contains( theDriver ) )
860 int myPos =
ABISYM( mGdalSkipList ).indexOf( theDriver );
863 ABISYM( mGdalSkipList ).removeAt( myPos );
870 ABISYM( mGdalSkipList ).removeDuplicates();
871 QString myDriverList =
ABISYM( mGdalSkipList ).join(
" " );
874 CPLSetConfigOption(
"GDAL_SKIP", myDriverList.toUtf8() );
884 QDir myDir( myPamPath );
885 if ( !myDir.exists() )
887 myDir.mkpath( myPamPath );
890 #if defined(Q_WS_WIN32) || defined(WIN32)
891 CPLSetConfigOption(
"GDAL_PAM_PROXY_DIR", myPamPath.toUtf8() );
895 int myChangeFlag = 0;
896 setenv(
"GDAL_PAM_PROXY_DIR", myPamPath.toUtf8(), myChangeFlag );
903 if ( !qgisPrivateDbFile.exists() )
907 QFile masterFile( qgisMasterDbFileName );
913 bool isDbFileCopied = masterFile.copy( qgisPrivateDbFile.fileName() );
915 if ( !isDbFileCopied )
919 *errorMessage =
tr(
"[ERROR] Can not make qgis.db private copy" );
932 *errorMessage =
tr(
"Could not open qgis.db" );
938 int res = sqlite3_exec( db,
"SELECT epsg FROM tbl_srs LIMIT 0", 0, 0, &errmsg );
939 if ( res == SQLITE_OK )
942 if ( sqlite3_exec( db,
943 "ALTER TABLE tbl_srs RENAME TO tbl_srs_bak;"
944 "CREATE TABLE tbl_srs ("
945 "srs_id INTEGER PRIMARY KEY,"
946 "description text NOT NULL,"
947 "projection_acronym text NOT NULL,"
948 "ellipsoid_acronym NOT NULL,"
949 "parameters text NOT NULL,"
953 "is_geo integer NOT NULL,"
954 "deprecated boolean);"
955 "CREATE INDEX idx_srsauthid on tbl_srs(auth_name,auth_id);"
956 "INSERT INTO tbl_srs(srs_id,description,projection_acronym,ellipsoid_acronym,parameters,srid,auth_name,auth_id,is_geo,deprecated) SELECT srs_id,description,projection_acronym,ellipsoid_acronym,parameters,srid,'','',is_geo,0 FROM tbl_srs_bak;"
957 "DROP TABLE tbl_srs_bak", 0, 0, &errmsg ) != SQLITE_OK
962 *errorMessage =
tr(
"Migration of private qgis.db failed.\n%1" ).arg( QString::fromUtf8( errmsg ) );
964 sqlite3_free( errmsg );
971 sqlite3_free( errmsg );
974 if ( sqlite3_exec( db,
"DROP VIEW vw_srs", 0, 0, &errmsg ) != SQLITE_OK )
976 QgsDebugMsg( QString(
"vw_srs didn't exists in private qgis.db: %1" ).arg( errmsg ) );
979 if ( sqlite3_exec( db,
980 "CREATE VIEW vw_srs AS"
982 " a.description AS description"
983 ",a.srs_id AS srs_id"
984 ",a.is_geo AS is_geo"
985 ",coalesce(b.name,a.projection_acronym) AS name"
986 ",a.parameters AS parameters"
987 ",a.auth_name AS auth_name"
988 ",a.auth_id AS auth_id"
989 ",a.deprecated AS deprecated"
991 " LEFT OUTER JOIN tbl_projection b ON a.projection_acronym=b.acronym"
992 " ORDER BY coalesce(b.name,a.projection_acronym),a.description", 0, 0, &errmsg ) != SQLITE_OK
997 *errorMessage =
tr(
"Update of view in private qgis.db failed.\n%1" ).arg( QString::fromUtf8( errmsg ) );
999 sqlite3_free( errmsg );
1000 sqlite3_close( db );
1004 sqlite3_close( db );