Skip to content

Commit

Permalink
Local copy of user projection database now made in ~/.qgis/ if it doe…
Browse files Browse the repository at this point in the history
…s not already exist

git-svn-id: http://svn.osgeo.org/qgis/trunk@3127 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Apr 11, 2005
1 parent 8b61289 commit 6efa3f6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
50 changes: 32 additions & 18 deletions src/qgscustomprojectiondialog.cpp
Expand Up @@ -15,6 +15,7 @@
#include <iostream>
#include <cassert>
#include <sqlite3.h>
#include <fstream>

//qgis includes
#include "qgscsexception.h"
Expand All @@ -38,18 +39,19 @@
QgsCustomProjectionDialog::QgsCustomProjectionDialog( QWidget* parent , const char* name , WFlags fl )
: QgsCustomProjectionDialogBase( parent, "Projection Designer", fl )
{
QString myUserProjectionDb = QDir::homeDirPath () + "/.qgis/user_projections.db";
QString myQGisSettingsDir = QDir::homeDirPath () + "/.qgis/";
// first we look for ~/.qgis/user_projections.db
// if it doesnt exist we copy it in from the global resources dir
QFileInfo myFileInfo;
myFileInfo.setFile(myUserProjectionDb);
myFileInfo.setFile(myQGisSettingsDir+"user_projections.db");
if ( !myFileInfo.exists( ) )
{
// make sure the ~/.qgis dir exists first
QDir myUserQGisDir;
QString myPath = QDir::homeDirPath();
myPath += "/.qgis";
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.
Expand All @@ -58,30 +60,42 @@ QgsCustomProjectionDialog::QgsCustomProjectionDialog( QWidget* parent , const ch
#endif
QString myMasterDatabaseFileName = PKGDATAPATH;
myMasterDatabaseFileName += "/resources/user_projections.db";
//now make sure the users .qgis dir exists
//XXX make windows friendly too!!!
QUrlOperator *myUrlOperator = new QUrlOperator();
#ifdef QGISDEBUG
std::cout << "copying " << myMasterDatabaseFileName << " to " << myUserProjectionDb << std::endl;
#endif

myUrlOperator->copy ("file:/"+myMasterDatabaseFileName,
"file:/"+myUserProjectionDb,
false, false);
delete myUrlOperator;

//now copy the master file into the users .qgis dir
std::ifstream myInputStream(myMasterDatabaseFileName.latin1() );

if (! myInputStream)
{
std::cerr << "unable to open input file: "
<< myMasterDatabaseFileName << " --bailing out! \n";
//XXX Do better error handling
return ;
}

std::ofstream myOutputStream(QString(myQGisSettingsDir+"user_projections.db").latin1());

if (! myOutputStream)
{
std::cerr << "cannot open " << QString(myQGisSettingsDir+"user_projections.db").latin1() << " for output\n";
//XXX Do better error handling
return ;
}

char myChar;
while (myInputStream.get(myChar))
{
myOutputStream.put(myChar);
}

//
// Populate the projection combo
}
//
// Populate the projection combo
}


QgsCustomProjectionDialog::~QgsCustomProjectionDialog()
{
}



void QgsCustomProjectionDialog::pbnHelp_clicked()
{

Expand Down
2 changes: 1 addition & 1 deletion src/qgscustomprojectiondialog.h
Expand Up @@ -13,6 +13,7 @@
#define QGSCUSTOMPROJECTIONDIALOG_H

#include <qdir.h>
#include <qnetworkprotocol.h>
#include <qgscustomprojectiondialogbase.uic.h>

/**
Expand All @@ -34,7 +35,6 @@ public slots:
void pbnApply_clicked();
void pbnCancel_clicked();
void cboProjectionFamily_textChanged( const QString & );

};

#endif

0 comments on commit 6efa3f6

Please sign in to comment.