170 changes: 85 additions & 85 deletions src/core/qgsapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@
#include <ogr_api.h>
#include <cpl_conv.h> // for setting gdal options

QObject * QgsApplication::mFileOpenEventReceiver;
QStringList QgsApplication::mFileOpenEventList;
QString QgsApplication::mPrefixPath;
QString QgsApplication::mPluginPath;
QString QgsApplication::mPkgDataPath;
QString QgsApplication::mLibraryPath;
QString QgsApplication::mLibexecPath;
QString QgsApplication::mThemeName;
QStringList QgsApplication::mDefaultSvgPaths;
QString QgsApplication::mConfigPath = QDir::homePath() + QString( "/.qgis/" );
bool QgsApplication::mRunningFromBuildDir = false;
QString QgsApplication::mBuildSourcePath;
QString QgsApplication::mBuildOutputPath;
QStringList QgsApplication::mGdalSkipList;
QObject * ABISYM( QgsApplication::mFileOpenEventReceiver );
QStringList ABISYM( QgsApplication::mFileOpenEventList );
QString ABISYM( QgsApplication::mPrefixPath );
QString ABISYM( QgsApplication::mPluginPath );
QString ABISYM( QgsApplication::mPkgDataPath );
QString ABISYM( QgsApplication::mLibraryPath );
QString ABISYM( QgsApplication::mLibexecPath );
QString ABISYM( QgsApplication::mThemeName );
QStringList ABISYM( QgsApplication::mDefaultSvgPaths );
QString ABISYM( QgsApplication::mConfigPath ) = QDir::homePath() + QString( "/.qgis/" );
bool ABISYM( QgsApplication::mRunningFromBuildDir ) = false;
QString ABISYM( QgsApplication::mBuildSourcePath );
QString ABISYM( QgsApplication::mBuildOutputPath );
QStringList ABISYM( QgsApplication::mGdalSkipList );

/*!
\class QgsApplication
Expand Down Expand Up @@ -82,27 +82,27 @@ void QgsApplication::init( QString customConfigPath )
QFile f( applicationDirPath() + "/source_path.txt" );
if ( f.open( QIODevice::ReadOnly ) )
{
mRunningFromBuildDir = true;
mBuildSourcePath = f.readAll();
ABISYM( mRunningFromBuildDir ) = true;
ABISYM( mBuildSourcePath ) = f.readAll();
#if defined(Q_WS_MACX) || defined(Q_WS_WIN32) || defined(WIN32)
mBuildOutputPath = applicationDirPath();
ABISYM( mBuildOutputPath ) = applicationDirPath();
#else
mBuildOutputPath = applicationDirPath() + "/.."; // on linux
ABISYM( mBuildOutputPath ) = applicationDirPath() + "/.."; // on linux
#endif
qDebug( "Running from build directory!" );
qDebug( "- source directory: %s", mBuildSourcePath.toAscii().data() );
qDebug( "- output directory of the build: %s", mBuildOutputPath.toAscii().data() );
qDebug( "- source directory: %s", ABISYM( mBuildSourcePath ).toAscii().data() );
qDebug( "- output directory of the build: %s", ABISYM( mBuildOutputPath ).toAscii().data() );
}
}

if ( mRunningFromBuildDir )
if ( ABISYM( mRunningFromBuildDir ) )
{
// we run from source directory - not installed to destination (specified prefix)
mPrefixPath = QString(); // set invalid path
setPluginPath( mBuildOutputPath + "/" + QString( QGIS_PLUGIN_SUBDIR ) );
setPkgDataPath( mBuildSourcePath ); // directly source path - used for: doc, resources, svg
mLibraryPath = mBuildOutputPath + "/" + QGIS_LIB_SUBDIR + "/";
mLibexecPath = mBuildOutputPath + "/" + QGIS_LIBEXEC_SUBDIR + "/";
ABISYM( mPrefixPath ) = QString(); // set invalid path
setPluginPath( ABISYM( mBuildOutputPath ) + "/" + QString( QGIS_PLUGIN_SUBDIR ) );
setPkgDataPath( ABISYM( mBuildSourcePath ) ); // directly source path - used for: doc, resources, svg
ABISYM( mLibraryPath ) = ABISYM( mBuildOutputPath ) + "/" + QGIS_LIB_SUBDIR + "/";
ABISYM( mLibexecPath ) = ABISYM( mBuildOutputPath ) + "/" + QGIS_LIBEXEC_SUBDIR + "/";
}
else
{
Expand All @@ -118,10 +118,10 @@ void QgsApplication::init( QString customConfigPath )

if ( !customConfigPath.isEmpty() )
{
mConfigPath = customConfigPath + "/"; // make sure trailing slash is included
ABISYM( mConfigPath ) = customConfigPath + "/"; // make sure trailing slash is included
}

mDefaultSvgPaths << qgisSettingsDirPath() + QString( "svg/" );
ABISYM( mDefaultSvgPaths ) << qgisSettingsDirPath() + QString( "svg/" );

// set a working directory up for gdal to write .aux.xml files into
// for cases where the raster dir is read only to the user
Expand Down Expand Up @@ -154,17 +154,17 @@ bool QgsApplication::event( QEvent * event )
if ( event->type() == QEvent::FileOpen )
{
// handle FileOpen event (double clicking a file icon in Mac OS X Finder)
if ( mFileOpenEventReceiver )
if ( ABISYM( mFileOpenEventReceiver ) )
{
// Forward event to main window.
done = notify( mFileOpenEventReceiver, event );
done = notify( ABISYM( mFileOpenEventReceiver ), event );
}
else
{
// Store filename because receiver has not registered yet.
// If QGIS has been launched by double clicking a file icon, FileOpen will be
// the first event; the main window is not yet ready to handle the event.
mFileOpenEventList.append( static_cast<QFileOpenEvent *>( event )->file() );
ABISYM( mFileOpenEventList ).append( static_cast<QFileOpenEvent *>( event )->file() );
done = true;
}
}
Expand Down Expand Up @@ -209,81 +209,81 @@ bool QgsApplication::notify( QObject * receiver, QEvent * event )
void QgsApplication::setFileOpenEventReceiver( QObject * receiver )
{
// Set receiver for FileOpen events
mFileOpenEventReceiver = receiver;
ABISYM( mFileOpenEventReceiver ) = receiver;
// Propagate any events collected before the receiver has registered.
if ( mFileOpenEventList.count() > 0 )
if ( ABISYM( mFileOpenEventList ).count() > 0 )
{
QStringListIterator i( mFileOpenEventList );
QStringListIterator i( ABISYM( mFileOpenEventList ) );
while ( i.hasNext() )
{
QFileOpenEvent foe( i.next() );
QgsApplication::sendEvent( mFileOpenEventReceiver, &foe );
QgsApplication::sendEvent( ABISYM( mFileOpenEventReceiver ), &foe );
}
mFileOpenEventList.clear();
ABISYM( mFileOpenEventList ).clear();
}
}

void QgsApplication::setPrefixPath( const QString thePrefixPath, bool useDefaultPaths )
{
mPrefixPath = thePrefixPath;
ABISYM( mPrefixPath ) = thePrefixPath;
#if defined(_MSC_VER)
if ( mPrefixPath.endsWith( "/bin" ) )
if ( ABISYM( mPrefixPath ).endsWith( "/bin" ) )
{
mPrefixPath.chop( 4 );
ABISYM( mPrefixPath ).chop( 4 );
}
#endif
if ( useDefaultPaths )
{
setPluginPath( mPrefixPath + "/" + QString( QGIS_PLUGIN_SUBDIR ) );
setPkgDataPath( mPrefixPath + "/" + QString( QGIS_DATA_SUBDIR ) );
setPluginPath( ABISYM( mPrefixPath ) + "/" + QString( QGIS_PLUGIN_SUBDIR ) );
setPkgDataPath( ABISYM( mPrefixPath ) + "/" + QString( QGIS_DATA_SUBDIR ) );
}
mLibraryPath = mPrefixPath + "/" + QGIS_LIB_SUBDIR + "/";
mLibexecPath = mPrefixPath + "/" + QGIS_LIBEXEC_SUBDIR + "/";
ABISYM( mLibraryPath ) = ABISYM( mPrefixPath ) + "/" + QGIS_LIB_SUBDIR + "/";
ABISYM( mLibexecPath ) = ABISYM( mPrefixPath ) + "/" + QGIS_LIBEXEC_SUBDIR + "/";
}

void QgsApplication::setPluginPath( const QString thePluginPath )
{
mPluginPath = thePluginPath;
ABISYM( mPluginPath ) = thePluginPath;
}

void QgsApplication::setPkgDataPath( const QString thePkgDataPath )
{
mPkgDataPath = thePkgDataPath;
QString mySvgPath = thePkgDataPath + ( mRunningFromBuildDir ? "/images/svg/" : "/svg/" );
ABISYM( mPkgDataPath ) = thePkgDataPath;
QString mySvgPath = thePkgDataPath + ( ABISYM( mRunningFromBuildDir ) ? "/images/svg/" : "/svg/" );
// avoid duplicate entries
if ( !mDefaultSvgPaths.contains( mySvgPath ) )
mDefaultSvgPaths << mySvgPath;
if ( !ABISYM( mDefaultSvgPaths ).contains( mySvgPath ) )
ABISYM( mDefaultSvgPaths ) << mySvgPath;
}

void QgsApplication::setDefaultSvgPaths( const QStringList& pathList )
{
mDefaultSvgPaths = pathList;
ABISYM( mDefaultSvgPaths ) = pathList;
}

const QString QgsApplication::prefixPath()
{
if ( mRunningFromBuildDir )
if ( ABISYM( mRunningFromBuildDir ) )
{
qWarning( "!!! prefix path was requested, but it is not valid - we do not run from installed path !!!" );
}

return mPrefixPath;
return ABISYM( mPrefixPath );
}
const QString QgsApplication::pluginPath()
{
return mPluginPath;
return ABISYM( mPluginPath );
}
const QString QgsApplication::pkgDataPath()
{
return mPkgDataPath;
return ABISYM( mPkgDataPath );
}
const QString QgsApplication::defaultThemePath()
{
return ":/images/themes/default/";
}
const QString QgsApplication::activeThemePath()
{
return ":/images/themes/" + mThemeName + "/";
return ":/images/themes/" + themeName() + "/";
}


Expand All @@ -307,48 +307,48 @@ void QgsApplication::setThemeName( const QString theThemeName )
//check it exists and if not roll back to default theme
if ( QFile::exists( myPath ) )
{
mThemeName = theThemeName;
ABISYM( mThemeName ) = theThemeName;
}
else
{
mThemeName = "default";
ABISYM( mThemeName ) = "default";
}
}
/*!
* Get the active theme name
*/
const QString QgsApplication::themeName()
{
return mThemeName;
return ABISYM( mThemeName );
}
/*!
Returns the path to the authors file.
*/
const QString QgsApplication::authorsFilePath()
{
return mPkgDataPath + QString( "/doc/AUTHORS" );
return ABISYM( mPkgDataPath ) + QString( "/doc/AUTHORS" );
}
/*!
Returns the path to the contributors file.
*/
const QString QgsApplication::contributorsFilePath()
{
return mPkgDataPath + QString( "/doc/CONTRIBUTORS" );
return ABISYM( mPkgDataPath ) + QString( "/doc/CONTRIBUTORS" );
}
/*!
Returns the path to the sponsors file.
*/
const QString QgsApplication::sponsorsFilePath()
{
return mPkgDataPath + QString( "/doc/SPONSORS" );
return ABISYM( mPkgDataPath ) + QString( "/doc/SPONSORS" );
}

/*!
Returns the path to the donors file.
*/
const QString QgsApplication::donorsFilePath()
{
return mPkgDataPath + QString( "/doc/DONORS" );
return ABISYM( mPkgDataPath ) + QString( "/doc/DONORS" );
}

/*!
Expand All @@ -357,7 +357,7 @@ const QString QgsApplication::donorsFilePath()
*/
const QString QgsApplication::translatorsFilePath()
{
return mPkgDataPath + QString( "/doc/TRANSLATORS" );
return ABISYM( mPkgDataPath ) + QString( "/doc/TRANSLATORS" );
}

const QString QgsApplication::developerPath()
Expand All @@ -384,26 +384,26 @@ const QString QgsApplication::helpAppPath()
*/
const QString QgsApplication::i18nPath()
{
if ( mRunningFromBuildDir )
return mBuildOutputPath + QString( "/i18n" );
if ( ABISYM( mRunningFromBuildDir ) )
return ABISYM( mBuildOutputPath ) + QString( "/i18n" );
else
return mPkgDataPath + QString( "/i18n/" );
return ABISYM( mPkgDataPath ) + QString( "/i18n/" );
}

/*!
Returns the path to the master qgis.db file.
*/
const QString QgsApplication::qgisMasterDbFilePath()
{
return mPkgDataPath + QString( "/resources/qgis.db" );
return ABISYM( mPkgDataPath ) + QString( "/resources/qgis.db" );
}

/*!
Returns the path to the settings directory in user's home dir
*/
const QString QgsApplication::qgisSettingsDirPath()
{
return mConfigPath;
return ABISYM( mConfigPath );
}

/*!
Expand All @@ -427,14 +427,14 @@ const QString QgsApplication::splashPath()
*/
const QString QgsApplication::iconsPath()
{
return mPkgDataPath + QString( "/images/icons/" );
return ABISYM( mPkgDataPath ) + QString( "/images/icons/" );
}
/*!
Returns the path to the srs.db file.
*/
const QString QgsApplication::srsDbFilePath()
{
return mPkgDataPath + QString( "/resources/srs.db" );
return ABISYM( mPkgDataPath ) + QString( "/resources/srs.db" );
}

/*!
Expand All @@ -452,7 +452,7 @@ const QStringList QgsApplication::svgPaths()
myPathList = myPaths.split( "|" );
}

myPathList << mDefaultSvgPaths;
myPathList << ABISYM( mDefaultSvgPaths );
return myPathList;
}

Expand All @@ -461,8 +461,8 @@ const QStringList QgsApplication::svgPaths()
*/
const QString QgsApplication::svgPath()
{
QString svgSubDir( mRunningFromBuildDir ? "/images/svg/" : "/svg/" );
return mPkgDataPath + svgSubDir;
QString svgSubDir( ABISYM( mRunningFromBuildDir ) ? "/images/svg/" : "/svg/" );
return ABISYM( mPkgDataPath ) + svgSubDir;
}

const QString QgsApplication::userStyleV2Path()
Expand All @@ -472,17 +472,17 @@ const QString QgsApplication::userStyleV2Path()

const QString QgsApplication::defaultStyleV2Path()
{
return mPkgDataPath + QString( "/resources/symbology-ng-style.xml" );
return ABISYM( mPkgDataPath ) + QString( "/resources/symbology-ng-style.xml" );
}

const QString QgsApplication::libraryPath()
{
return mLibraryPath;
return ABISYM( mLibraryPath );
}

const QString QgsApplication::libexecPath()
{
return mLibexecPath;
return ABISYM( mLibexecPath );
}

QgsApplication::endian_t QgsApplication::endian()
Expand Down Expand Up @@ -516,9 +516,9 @@ QString QgsApplication::showSettings()
"Default Theme Path:\t%6\n"
"SVG Search Paths:\t%7\n"
"User DB Path:\t%8\n" )
.arg( mPrefixPath )
.arg( mPluginPath )
.arg( mPkgDataPath )
.arg( prefixPath() )
.arg( pluginPath() )
.arg( pkgDataPath() )
.arg( themeName() )
.arg( activeThemePath() )
.arg( defaultThemePath() )
Expand Down Expand Up @@ -738,32 +738,32 @@ QString QgsApplication::relativePathToAbsolutePath( QString rpath, QString targe

void QgsApplication::skipGdalDriver( QString theDriver )
{
if ( mGdalSkipList.contains( theDriver ) || theDriver.isEmpty() )
if ( ABISYM( mGdalSkipList ).contains( theDriver ) || theDriver.isEmpty() )
{
return;
}
mGdalSkipList << theDriver;
ABISYM( mGdalSkipList ) << theDriver;
applyGdalSkippedDrivers();
}

void QgsApplication::restoreGdalDriver( QString theDriver )
{
if ( !mGdalSkipList.contains( theDriver ) )
if ( !ABISYM( mGdalSkipList ).contains( theDriver ) )
{
return;
}
int myPos = mGdalSkipList.indexOf( theDriver );
int myPos = ABISYM( mGdalSkipList ).indexOf( theDriver );
if ( myPos >= 0 )
{
mGdalSkipList.removeAt( myPos );
ABISYM( mGdalSkipList ).removeAt( myPos );
}
applyGdalSkippedDrivers();
}

void QgsApplication::applyGdalSkippedDrivers()
{
mGdalSkipList.removeDuplicates();
QString myDriverList = mGdalSkipList.join( " " );
ABISYM( mGdalSkipList ).removeDuplicates();
QString myDriverList = ABISYM( mGdalSkipList ).join( " " );
QgsDebugMsg( "Gdal Skipped driver list set to:" );
QgsDebugMsg( myDriverList );
CPLSetConfigOption( "GDAL_SKIP", myDriverList.toUtf8() );
Expand Down
38 changes: 20 additions & 18 deletions src/core/qgsapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include <qgis.h>

#define ABISYM(x) x ## VERSION_INT

/** \ingroup core
* Extends QApplication to provide access to QGIS specific resources such
* as theme paths, database paths etc.
Expand Down Expand Up @@ -219,13 +221,13 @@ class CORE_EXPORT QgsApplication: public QApplication

/** Indicates whether running from build directory (not installed)
@note added in 2.0 */
static bool isRunningFromBuildDir() { return mRunningFromBuildDir; }
static bool isRunningFromBuildDir() { return ABISYM( mRunningFromBuildDir ); }
/** Returns path to the source directory. Valid only when running from build directory
@note added in 2.0 */
static QString buildSourcePath() { return mBuildSourcePath; }
static QString buildSourcePath() { return ABISYM( mBuildSourcePath ); }
/** Returns path to the build output directory. Valid only when running from build directory
@note added in 2.0 */
static QString buildOutputPath() { return mBuildOutputPath; }
static QString buildOutputPath() { return ABISYM( mBuildOutputPath ); }

/** Sets the GDAL_SKIP environment variable to include the specified driver
* and then calls GDALDriverManager::AutoSkipDrivers() to unregister it. The
Expand All @@ -245,7 +247,7 @@ class CORE_EXPORT QgsApplication: public QApplication
* GDAL_SKIP environment variable)
* @note added in 2.0
*/
static QStringList skippedGdalDrivers( ) { return mGdalSkipList; };
static QStringList skippedGdalDrivers( ) { return ABISYM( mGdalSkipList ); };

/** Apply the skipped drivers list to gdal
* @see skipGdalDriver
Expand All @@ -258,29 +260,29 @@ class CORE_EXPORT QgsApplication: public QApplication
void preNotify( QObject * receiver, QEvent * event, bool * done );

private:
static QObject* mFileOpenEventReceiver;
static QStringList mFileOpenEventList;
static QObject* ABISYM( mFileOpenEventReceiver );
static QStringList ABISYM( mFileOpenEventList );

static QString mPrefixPath;
static QString mPluginPath;
static QString mPkgDataPath;
static QString mLibraryPath;
static QString mLibexecPath;
static QString mThemeName;
static QStringList mDefaultSvgPaths;
static QString ABISYM( mPrefixPath );
static QString ABISYM( mPluginPath );
static QString ABISYM( mPkgDataPath );
static QString ABISYM( mLibraryPath );
static QString ABISYM( mLibexecPath );
static QString ABISYM( mThemeName );
static QStringList ABISYM( mDefaultSvgPaths );

static QString mConfigPath;
static QString ABISYM( mConfigPath );

/** true when running from build directory, i.e. without 'make install' */
static bool mRunningFromBuildDir;
static bool ABISYM( mRunningFromBuildDir );
/** path to the source directory. valid only when running from build directory. */
static QString mBuildSourcePath;
static QString ABISYM( mBuildSourcePath );
/** path to the output directory of the build. valid only when running from build directory */
static QString mBuildOutputPath;
static QString ABISYM( mBuildOutputPath );
/** List of gdal drivers to be skipped. Uses GDAL_SKIP to exclude them.
* @see skipGdalDriver, restoreGdalDriver
* @note added in 2.0 */
static QStringList mGdalSkipList;
static QStringList ABISYM( mGdalSkipList );
};

#endif
6 changes: 3 additions & 3 deletions src/core/qgslogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,20 @@ void QgsLogger::debug( const QString& var, double val, int debuglevel, const cha

void QgsLogger::warning( const QString& msg )
{
qWarning( "%s", msg.toLocal8Bit().constData() );
logMessageToFile( msg );
qWarning( "%s", msg.toLocal8Bit().constData() );
}

void QgsLogger::critical( const QString& msg )
{
qCritical( "%s", msg.toLocal8Bit().constData() );
logMessageToFile( msg );
qCritical( "%s", msg.toLocal8Bit().constData() );
}

void QgsLogger::fatal( const QString& msg )
{
qFatal( "%s", msg.toLocal8Bit().constData() );
logMessageToFile( msg );
qFatal( "%s", msg.toLocal8Bit().constData() );
}

int QgsLogger::debugLevel()
Expand Down