Skip to content

Commit

Permalink
Replace all non-image hard-coded paths in src/ with calls to new QgsA…
Browse files Browse the repository at this point in the history
…pplication path accessor mathods. This minimizes platform-specific #ifdefs. Image paths still to be done.

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@4465 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
telwertowski committed Jan 4, 2006
1 parent 31e7393 commit 3e473c4
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 128 deletions.
22 changes: 4 additions & 18 deletions src/qgisapp.cpp
Expand Up @@ -82,6 +82,7 @@
#include "qgis.h"
#include "qgsabout.h"
#include "qgsacetaterectangle.h"
#include "qgsapplication.h"
#include "qgsbookmarkitem.h"
#include "qgsbookmarks.h"
#include "qgscomposer.h"
Expand Down Expand Up @@ -266,11 +267,7 @@ static void setTitleBarText_( QWidget & qgisApp )
// Create the plugin registry and load plugins
//
// Get pointer to the provider registry singleton
#if defined(WIN32) || defined(Q_OS_MACX)
QString plib = mAppDir + "/lib/qgis";
#else
QString plib = PLUGINPATH;
#endif
QString plib = QgsApplication::pluginPath();
// set the provider plugin path
mProviderRegistry = QgsProviderRegistry::instance(plib);
#ifdef QGISDEBUG
Expand Down Expand Up @@ -319,11 +316,7 @@ QgisApp::~QgisApp()
void QgisApp::readSettings()
{
// get the application dir
#if defined(WIN32) || defined(Q_OS_MACX)
mAppDir = qApp->applicationDirPath();
#else
mAppDir = PREFIX;
#endif
mAppDir = QgsApplication::prefixPath();

QSettings settings;
// get the users theme preference from the settings
Expand Down Expand Up @@ -764,9 +757,6 @@ void QgisApp::createStatusBar()
// Add a panel to the status bar for the scale, coords and progress
// And also rendering suppression checkbox
//
#if defined(WIN32) || defined(Q_OS_MACX)
QString PKGDATAPATH = qApp->applicationDirPath() + "/share/qgis";
#endif
mProgressBar = new QProgressBar(statusBar());
mProgressBar->setMaximumWidth(100);
QWhatsThis::add(mProgressBar, tr("Progress bar that displays the status of rendering layers and other time-intensive operations"));
Expand Down Expand Up @@ -1067,11 +1057,7 @@ void QgisApp::createDB()
if (!qgisPrivateDbFile.exists())
{
// if it doesnt exist we copy it in from the global resources dir
#if defined(Q_OS_MACX) || defined(WIN32)
QString PKGDATAPATH(qApp->applicationDirPath() + "/share/qgis");
#endif
QString qgisMasterDbFileName = PKGDATAPATH;
qgisMasterDbFileName += "/resources/qgis.db";
QString qgisMasterDbFileName = QgsApplication::qgisMasterDbFilePath();

// Must be sure there is destination directory ~/.qgis
// @todo XXX REPLACE with recursive dir creator, but first define QgsDir class and
Expand Down
17 changes: 3 additions & 14 deletions src/qgsabout.cpp
Expand Up @@ -17,6 +17,7 @@
/* $Id:$ */

#include "qgsabout.h"
#include "qgsapplication.h"
#ifdef Q_OS_MACX
#include <ApplicationServices/ApplicationServices.h>
#else
Expand Down Expand Up @@ -49,13 +50,7 @@ void QgsAbout::init()
//read the authors file to populate the contributors list
QStringList lines;

#if defined(Q_OS_MACX) || defined(WIN32)
QString appPath = QCoreApplication::applicationDirPath() + "/share/qgis";
#else
QString appPath = QString(PKGDATAPATH);
#endif

QFile file(appPath + "/doc/AUTHORS" );
QFile file(QgsApplication::authorsFilePath());
#ifdef QGISDEBUG
printf (("Reading authors file " + file.name() +
".............................................\n").toLocal8Bit().data());
Expand Down Expand Up @@ -123,18 +118,12 @@ void QgsAbout::on_listBox1_currentChanged(Q3ListBoxItem *theItem)
#ifdef QGISDEBUG
printf ("Loading mug: ");
#endif
#if defined(Q_OS_MACX) || defined(WIN32)
QString appPath = qApp->applicationDirPath() + "/share/qgis";
#else
QString appPath = QString(PKGDATAPATH);
#endif

QString myString = listBox1->currentText();
myString = myString.replace(" ","_");
#ifdef QGISDEBUG
printf ("Loading mug: %s", (const char *)myString.toLocal8Bit().data());
#endif
myString =QString(appPath + "/images/developers/") + myString + QString(".jpg");
myString = QgsApplication::developerPath() + myString + QString(".jpg");
#ifdef QGISDEBUG
printf ("Loading mug: %s\n", (const char *)myString.toLocal8Bit().data());
#endif
Expand Down
73 changes: 67 additions & 6 deletions src/qgsapplication.cpp
Expand Up @@ -16,7 +16,10 @@

#include "qgsapplication.h"

QString QgsApplication::mPrefixPath;
QString QgsApplication::mPluginPath;
QString QgsApplication::mPkgDataPath;
QString QgsApplication::mThemePath;

/*!
\class QgsApplication
Expand All @@ -35,35 +38,93 @@ QgsApplication::QgsApplication(int & argc, char ** argv, bool GUIenabled)
: QApplication(argc, argv, GUIenabled)
{
#if defined(Q_WS_MACX) || defined(Q_WS_WIN32)
mPkgDataPath = QCoreApplication::applicationDirPath() + QString("/share/qgis");
mPrefixPath = applicationDirPath();
mPluginPath = mPrefixPath + QString("/lib/qgis");
mPkgDataPath = mPrefixPath + QString("/share/qgis");
#else
mPrefixPath = PREFIX;
mPluginPath = PLUGINPATH;
mPkgDataPath = PKGDATAPATH;
#endif
mThemePath = mPkgDataPath + QString("/themes/default/");
}

QgsApplication::~QgsApplication()
{}

/*!
Returns the path to the translation files.
Set the theme path to the specified theme.
*/
void QgsApplication::selectTheme(const QString& theThemeName)
{
mThemePath = mPkgDataPath + QString("/themes/") + theThemeName + QString("/");
}

/*!
Returns the path to the authors file.
*/
const QString QgsApplication::authorsFilePath()
{
return mPkgDataPath + QString("/doc/AUTHORS");
}

/*!
Returns the path to the developer image directory.
*/
const QString QgsApplication::developerPath()
{
return mPkgDataPath + QString("/images/developers/");
}

/*!
Returns the path to the help application.
*/
const QString QgsApplication::helpAppPath()
{
QString helpAppPath = applicationDirPath();
#ifdef Q_OS_MACX
helpAppPath += "/bin/qgis_help.app/Contents/MacOS";
#endif
helpAppPath += "/qgis_help";
return helpAppPath;
}

/*!
Returns the path to the translation directory.
*/
const QString QgsApplication::i18nPath()
{
return mPkgDataPath + QString("/i18n/");
}

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

/*!
Returns the path to the splash screen image directory.
*/
const QString QgsApplication::splashPath()
{
return mPkgDataPath + QString("/images/splash/");
}

/*!
Returns the path to the theme images.
Returns the path to the srs.db file.
*/
const QString QgsApplication::srsDbFilePath()
{
return mPkgDataPath + QString("/resources/srs.db");
}

/*!
Returns the path to the svg directory.
*/
const QString QgsApplication::themePath()
const QString QgsApplication::svgPath()
{
return mPkgDataPath + QString("/themes/");
return mPkgDataPath + QString("/svg/");
}
40 changes: 35 additions & 5 deletions src/qgsapplication.h
Expand Up @@ -24,20 +24,50 @@ class QgsApplication: public QApplication
QgsApplication(int & argc, char ** argv, bool GUIenabled);
virtual ~QgsApplication();

//! Returns the path to the translation files.
//! Set the theme path to the specified theme.
static void selectTheme(const QString& theThemeName);

//! Returns the path to the authors file.
static const QString authorsFilePath();

//! Returns the path to the developer image directory.
static const QString developerPath();

//! Returns the path to the help application.
static const QString helpAppPath();

//! Returns the path to the translation directory.
static const QString i18nPath();

//! Returns the path to the splash screen images.
//! Returns the path to the master qgis.db file.
static const QString qgisMasterDbFilePath();

//! Returns the path to the splash screen image directory.
static const QString splashPath();

//! Returns the path to the theme images.
static const QString themePath();
//! Returns the path to the srs.db file.
static const QString srsDbFilePath();

//! Returns the common root of all data path.
//! Returns the path to the svg directory.
static const QString svgPath();

//! Returns the path to the application prefix directory.
static const QString& prefixPath() { return mPrefixPath; }

//! Returns the path to the application plugin directory.
static const QString& pluginPath() { return mPluginPath; }

//! Returns the common root path of all application data directories.
static const QString& pkgDataPath() { return mPkgDataPath; }

//! Returns the path to the current theme directory.
static const QString& themePath() { return mThemePath; }

private:
static QString mPrefixPath;
static QString mPluginPath;
static QString mPkgDataPath;
static QString mThemePath;
};

#endif
10 changes: 3 additions & 7 deletions src/qgsbookmarks.cpp
Expand Up @@ -17,6 +17,7 @@
/* $Id$ */
#include "qgsbookmarks.h"
#include "qgisapp.h"
#include "qgsapplication.h"
#include "qgscontexthelp.h"
#include "qgsmapcanvas.h"

Expand Down Expand Up @@ -287,13 +288,8 @@ bool QgsBookmarks::createDatabase()
#endif
//now make sure the users .qgis dir exists
makeDir(myUserQGisDir);
// Get the package data path and set the full path name to the sqlite3 spatial reference
// database.
#if defined(Q_OS_MACX) || defined(WIN32)
QString PKGDATAPATH = qApp->applicationDirPath() + "/share/qgis";
#endif
QString myMasterDatabaseFileName = PKGDATAPATH;
myMasterDatabaseFileName += "/resources/qgis.db";
// Get the full path name to the sqlite3 spatial reference database.
QString myMasterDatabaseFileName = QgsApplication::qgisMasterDbFilePath();
//now copy the master file into the users .qgis dir
std::ifstream myInputStream(myMasterDatabaseFileName.toLocal8Bit().data() );

Expand Down
11 changes: 3 additions & 8 deletions src/qgscontexthelp.cpp
Expand Up @@ -21,8 +21,8 @@
#include <qdir.h>
#include <q3process.h>
#include <q3socket.h>
#include <qapplication.h>
#include "qgscontexthelp.h"
#include "qgsapplication.h"
//Added by qt3to4:
#include <QTextStream>

Expand Down Expand Up @@ -71,13 +71,8 @@ QgsContextHelp::~QgsContextHelp()

Q3Process *QgsContextHelp::start(int contextId)
{
// Assume minimum Qt 3.2 version and use the API to get the path
// path to the help viewer
QString helpPath = qApp->applicationDirPath();
#ifdef Q_OS_MACX
helpPath += "/bin/qgis_help.app/Contents/MacOS";
#endif
helpPath += "/qgis_help";
// Get the path to the help viewer
QString helpPath = QgsApplication::helpAppPath();
#ifdef QGISDEBUG
std::cout << "Help path is " << helpPath.toLocal8Bit().data() << std::endl;
#endif
Expand Down
10 changes: 3 additions & 7 deletions src/qgscustomprojectiondialog.cpp
Expand Up @@ -13,6 +13,7 @@

//qgis includes
#include "qgis.h" //<--magick numbers
#include "qgsapplication.h"

//qt includes
#include <QDir>
Expand Down Expand Up @@ -56,13 +57,8 @@ QgsCustomProjectionDialog::QgsCustomProjectionDialog( QWidget* parent , const ch
myUserQGisDir.setPath(myPath);
//now make sure the users .qgis dir exists
makeDir(myUserQGisDir);
// Get the package data path and set the full path name to the sqlite3 spatial reference
// database.
#if defined(Q_OS_MACX) || defined(WIN32)
QString PKGDATAPATH = qApp->applicationDirPath() + "/share/qgis";
#endif
QString myMasterDatabaseFileName = PKGDATAPATH;
myMasterDatabaseFileName += "/resources/qgis.db";
// Get the full path name to the sqlite3 spatial reference database.
QString myMasterDatabaseFileName = QgsApplication::qgisMasterDbFilePath();
//now copy the master file into the users .qgis dir
std::ifstream myInputStream(myMasterDatabaseFileName.toLocal8Bit().data() );

Expand Down
15 changes: 5 additions & 10 deletions src/qgsmarkercatalogue.cpp
Expand Up @@ -16,7 +16,6 @@
#include <cmath>
#include <iostream>

#include <qapplication.h>
#include <qpainter.h>
#include <qpixmap.h>
#include <qimage.h>
Expand All @@ -27,6 +26,7 @@
#include <q3pointarray.h>
#include <qdir.h>

#include "qgsapplication.h"
#include "qgssvgcache.h"
#include "qgsmarkercatalogue.h"

Expand All @@ -44,28 +44,23 @@ QgsMarkerCatalogue::QgsMarkerCatalogue()
mList.append ( "hard:cross2" );

// SVG
QString appdir;
#if defined(WIN32) || defined(Q_OS_MACX)
appdir = qApp->applicationDirPath();
#else
appdir = PREFIX;
#endif
QString svgPath = QgsApplication::svgPath();

// TODO recursiv ?
QDir dir ( appdir + "/share/qgis/svg/" );
QDir dir ( svgPath );

QStringList dl = dir.entryList(QDir::Dirs);

for ( QStringList::iterator it = dl.begin(); it != dl.end(); ++it ) {
if ( *it == "." || *it == ".." ) continue;

QDir dir2 ( appdir + "/share/qgis/svg/" + *it );
QDir dir2 ( svgPath + *it );

QStringList dl2 = dir2.entryList("*.svg",QDir::Files);

for ( QStringList::iterator it2 = dl2.begin(); it2 != dl2.end(); ++it2 ) {
// TODO test if it is correct SVG
mList.append ( "svg:" + appdir + "/share/qgis/svg/" + *it + "/" + *it2 );
mList.append ( "svg:" + svgPath + *it + "/" + *it2 );
}
}
}
Expand Down

0 comments on commit 3e473c4

Please sign in to comment.