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
This commit is contained in:
gsherman 2005-02-14 18:30:42 +00:00
parent 00dcb49897
commit 4f3ab62f47

View File

@ -245,6 +245,25 @@ int main(int argc, char *argv[])
a.setMainWidget(qgis); 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 // Load a project file if one was specified
@ -284,10 +303,14 @@ int main(int argc, char *argv[])
for ( QStringList::Iterator myIterator = myFileList->begin(); myIterator != myFileList->end(); ++myIterator ) for ( QStringList::Iterator myIterator = myFileList->begin(); myIterator != myFileList->end(); ++myIterator )
{ {
#ifdef QGISDEBUG #ifdef QGISDEBUG
std::cout << "Trying to load file : " << *myIterator << std::endl; std::cout << "Trying to load file : " << *myIterator << std::endl;
#endif #endif
QString myLayerName = *myIterator; QString myLayerName = *myIterator;
// 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 // try to add all these layers - any unsupported file types will
// be rejected automatically // be rejected automatically
// The funky bool ok is so this can be debugged a bit easier... // The funky bool ok is so this can be debugged a bit easier...
@ -303,6 +326,7 @@ int main(int argc, char *argv[])
} }
} }
} }
}