From 4f3ab62f472500203ce08e7e6cb1558a96e6717d Mon Sep 17 00:00:00 2001 From: gsherman Date: Mon, 14 Feb 2005 18:30:42 +0000 Subject: [PATCH] Added ability to pass a .qgs project file as an argument without using the --project switch. This is necessary to allow using QGIS to open .qgs files in a desktop environment where a mime type has been established. The --project switch still works, but QGIS will now load .qgs, .shp, and .tif files specified on the command line. git-svn-id: http://svn.osgeo.org/qgis/trunk@2801 c8812cc2-4d05-0410-92ff-de0c093fc19c --- src/main.cpp | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b9c26e578a3..f2cfbf0068f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -245,6 +245,25 @@ int main(int argc, char *argv[]) a.setMainWidget(qgis); + ///////////////////////////////////////////////////////////////////// + // If no --project was specified, parse the args to look for a // + // .qgs file and set myProjectFileName to it. This allows loading // + // of a project file by clicking on it in various desktop managers // + // where an appropriate mime-type has been set up. // + ///////////////////////////////////////////////////////////////////// + if(myProjectFileName.isEmpty()) + { + // check for a .qgs + for(int i = 0; i < argc; i++) + { + QString arg = argv[i]; + if(arg.contains(".qgs")) + { + myProjectFileName = argv[i]; + break; + } + } + } ///////////////////////////////////////////////////////////////////// // Load a project file if one was specified @@ -284,22 +303,27 @@ int main(int argc, char *argv[]) for ( QStringList::Iterator myIterator = myFileList->begin(); myIterator != myFileList->end(); ++myIterator ) { + #ifdef QGISDEBUG std::cout << "Trying to load file : " << *myIterator << std::endl; #endif QString myLayerName = *myIterator; - // try to add all these layers - any unsupported file types will - // be rejected automatically - // The funky bool ok is so this can be debugged a bit easier... + // don't load anything with a .qgs extension - these are project files + if(!myLayerName.contains(".qgs")) + { + // try to add all these layers - any unsupported file types will + // be rejected automatically + // The funky bool ok is so this can be debugged a bit easier... - //nope - try and load it as raster - bool ok = qgis->addRasterLayer(QFileInfo(myLayerName), false); - if(!ok){ - //nope - try and load it as a shape/ogr - ok = qgis->addLayer(QFileInfo(myLayerName)); - //we have no idea what this layer is... + //nope - try and load it as raster + bool ok = qgis->addRasterLayer(QFileInfo(myLayerName), false); if(!ok){ - std::cout << "Unable to load " << myLayerName << std::endl; + //nope - try and load it as a shape/ogr + ok = qgis->addLayer(QFileInfo(myLayerName)); + //we have no idea what this layer is... + if(!ok){ + std::cout << "Unable to load " << myLayerName << std::endl; + } } } }