Skip to content
Permalink
Browse files

add QgsApplication::upgradeConfig to upgrade any configs that changed…

… from 1.8

use different keys for scanItemsInBrowser and scanZipInBrowser in qgis-1.9 because new storage type (string vs. int) causes conflicts with 1.8
  • Loading branch information
etiennesky committed Nov 6, 2012
1 parent 038acbc commit b754f0771fab4b3cd0f0a36e6039a09a037583d5
@@ -2546,7 +2546,7 @@ bool QgisApp::askUserForZipItemLayers( QString path )
QgsDebugMsg( "askUserForZipItemLayers( " + path + ")" );

// if scanZipBrowser == no: skip to the next file
if ( settings.value( "/qgis/scanZipInBrowser", "basic" ).toString() == "no" )
if ( settings.value( "/qgis/scanZipInBrowser2", "basic" ).toString() == "no" )
{
return false;
}
@@ -228,7 +228,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
cmbScanItemsInBrowser->clear();
cmbScanItemsInBrowser->addItem( tr( "Check file contents" ), "contents" ); // 0
cmbScanItemsInBrowser->addItem( tr( "Check extension" ), "extension" ); // 1
int index = cmbScanItemsInBrowser->findData( settings.value( "/qgis/scanItemsInBrowser", "" ) );
int index = cmbScanItemsInBrowser->findData( settings.value( "/qgis/scanItemsInBrowser2", "" ) );
if ( index == -1 ) index = 1;
cmbScanItemsInBrowser->setCurrentIndex( index );

@@ -238,7 +238,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
// cmbScanZipInBrowser->addItem( tr( "Passthru" ) ); // 1 - removed
cmbScanZipInBrowser->addItem( tr( "Basic scan" ), QVariant( "basic" ) );
cmbScanZipInBrowser->addItem( tr( "Full scan" ), QVariant( "full" ) );
index = cmbScanZipInBrowser->findData( settings.value( "/qgis/scanZipInBrowser", "" ) );
index = cmbScanZipInBrowser->findData( settings.value( "/qgis/scanZipInBrowser2", "" ) );
if ( index == -1 ) index = 1;
cmbScanZipInBrowser->setCurrentIndex( index );

@@ -881,9 +881,9 @@ void QgsOptions::saveOptions()
settings.setValue( "/qgis/attributeTableBehaviour", cmbAttrTableBehaviour->currentIndex() );
settings.setValue( "/qgis/attributeTableRowCache", spinBoxAttrTableRowCache->value() );
settings.setValue( "/qgis/promptForRasterSublayers", cmbPromptRasterSublayers->currentIndex() );
settings.setValue( "/qgis/scanItemsInBrowser",
settings.setValue( "/qgis/scanItemsInBrowser2",
cmbScanItemsInBrowser->itemData( cmbScanItemsInBrowser->currentIndex() ).toString() );
settings.setValue( "/qgis/scanZipInBrowser",
settings.setValue( "/qgis/scanZipInBrowser2",
cmbScanZipInBrowser->itemData( cmbScanZipInBrowser->currentIndex() ).toString() );
settings.setValue( "/qgis/ignoreShapeEncoding", cbxIgnoreShapeEncoding->isChecked() );
settings.setValue( "/qgis/dockIdentifyResults", cbxIdentifyResultsDocked->isChecked() );
@@ -583,6 +583,9 @@ void QgsApplication::initQgis()

// create map layer registry if doesn't exist
QgsMapLayerRegistry::instance();

// upgrade config options from older version
upgradeConfig();
}

void QgsApplication::exitQgis()
@@ -858,3 +861,87 @@ void QgsApplication::applyGdalSkippedDrivers()
CPLSetConfigOption( "GDAL_SKIP", myDriverList.toUtf8() );
GDALAllRegister(); //to update driver list and skip missing ones
}

void QgsApplication::upgradeConfig()
{
QSettings settings;

/* Due to changes in settings storage types for "scan items" and "scan zip" settings,
qgis-1.8 and qgis-1.9 have conficting values, so the keys have been renamed
Here we do a 1-time check to copy old setting to new setting
*/

// use a special settings key so we only check once
if ( ! settings.value( "/qgis/scanInBrowserUpgradeChecked", false ).toBool() )
{
QVariant v;
int i;
QString s;
bool ok;

// check if new setting is empty
if ( settings.value( "/qgis/scanItemsInBrowser2" ).isNull() )
{
v = settings.value( "/qgis/scanItemsInBrowser" );
i = v.toInt( &ok );
// check if value was defined in qgis-1.8 (as int)
if ( ! v.isNull() && ok )
{
// convert old setting to new setting
switch ( i )
{
case 0:
s = "contents";
break;
case 1:
s = "extension";
break;
default:
s = "";
break;
}
settings.setValue( "/qgis/scanItemsInBrowser2", s );
}
// check if value was defined in qgis-1.9 (as QString)
else if ( ! v.isNull() && !v.toString().isEmpty() )
{
s = v.toString();
settings.setValue( "/qgis/scanItemsInBrowser2", s );
}
}

if ( settings.value( "/qgis/scanZipInBrowser2" ).isNull() )
{
v = settings.value( "/qgis/scanZipInBrowser" );
i = v.toInt( & ok );
if ( ! v.isNull() && ok )
{
switch ( i )
{
case 0:
s = "No";
break;
case 1: // passthru removed, use basic instead
case 2:
s = "basic";
break;
case 3:
s = "full";
break;
default:
s = "";
break;
}
settings.setValue( "/qgis/scanZipInBrowser2", s );
}
else if ( ! v.isNull() && !v.toString().isEmpty() )
{
s = v.toString();
settings.setValue( "/qgis/scanZipInBrowser2", s );
}
}

settings.setValue( "/qgis/scanInBrowserUpgradeChecked", true );
}
}

@@ -270,6 +270,10 @@ class CORE_EXPORT QgsApplication: public QApplication
* @note added in 2.0 */
static void applyGdalSkippedDrivers();

/** upgrades config options from older version, called by initQGis
* @note added in 2.0 */
static void upgradeConfig();

signals:
//! @note not available in python bindings
void preNotify( QObject * receiver, QEvent * event, bool * done );
@@ -474,7 +474,7 @@ QVector<QgsDataItem*> QgsDirectoryItem::createChildren( )

QString vsiPrefix = QgsZipItem::vsiPrefix( path );
// vsizip support was added to GDAL/OGR 1.6 but GDAL_VERSION_NUM not available here
if (( settings.value( "/qgis/scanZipInBrowser", QVariant( "basic" ) ).toString() != "no" ) &&
if (( settings.value( "/qgis/scanZipInBrowser2", QVariant( "basic" ) ).toString() != "no" ) &&
( vsiPrefix == "/vsizip/" || vsiPrefix == "/vsitar/" ) )
{
QgsDataItem * item = QgsZipItem::itemFromPath( this, path, name );
@@ -857,7 +857,7 @@ QVector<QgsDataItem*> QgsZipItem::createChildren( )
QString tmpPath;
QString childPath;
QSettings settings;
QString scanZipSetting = settings.value( "/qgis/scanZipInBrowser", "basic" ).toString();
QString scanZipSetting = settings.value( "/qgis/scanZipInBrowser2", "basic" ).toString();

mZipFileList.clear();

@@ -955,7 +955,7 @@ QString QgsZipItem::vsiPrefix( QString path )
QgsDataItem* QgsZipItem::itemFromPath( QgsDataItem* parent, QString path, QString name )
{
QSettings settings;
QString scanZipSetting = settings.value( "/qgis/scanZipInBrowser", "basic" ).toString();
QString scanZipSetting = settings.value( "/qgis/scanZipInBrowser2", "basic" ).toString();
QString vsiPath = path;
int zipFileCount = 0;
QStringList zipFileList;
@@ -1059,7 +1059,7 @@ const QStringList & QgsZipItem::getZipFileList()

QString tmpPath;
QSettings settings;
QString scanZipSetting = settings.value( "/qgis/scanZipInBrowser", "basic" ).toString();
QString scanZipSetting = settings.value( "/qgis/scanZipInBrowser2", "basic" ).toString();

QgsDebugMsgLevel( QString( "path = %1 name= %2 scanZipSetting= %3 vsiPrefix= %4" ).arg( path() ).arg( name() ).arg( scanZipSetting ).arg( mVsiPrefix ), 3 );

@@ -144,7 +144,7 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )

// zip settings + info
QSettings settings;
QString scanZipSetting = settings.value( "/qgis/scanZipInBrowser", "basic" ).toString();
QString scanZipSetting = settings.value( "/qgis/scanZipInBrowser2", "basic" ).toString();
QString vsiPrefix = QgsZipItem::vsiPrefix( thePath );
bool is_vsizip = ( vsiPrefix == "/vsizip/" );
bool is_vsigzip = ( vsiPrefix == "/vsigzip/" );
@@ -217,7 +217,7 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
// not zipfile and scan items == "Check extension"
if ((( is_vsizip || is_vsitar ) && scanZipSetting == "basic" ) ||
( !is_vsizip && !is_vsitar &&
( settings.value( "/qgis/scanItemsInBrowser",
( settings.value( "/qgis/scanItemsInBrowser2",
"extension" ).toString() == "extension" ) ) )
{
// if this is a VRT file make sure it is raster VRT to avoid duplicates
@@ -1897,7 +1897,7 @@ void buildSupportedRasterFileFilterAndExtensions( QString & theFileFiltersString
// VSIFileHandler (see qgsogrprovider.cpp)
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1600
QSettings settings;
if ( settings.value( "/qgis/scanZipInBrowser", "basic" ).toString() != "no" )
if ( settings.value( "/qgis/scanZipInBrowser2", "basic" ).toString() != "no" )
{
QString glob = "*.zip";
glob += " *.gz";
@@ -239,7 +239,7 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )

// zip settings + info
QSettings settings;
QString scanZipSetting = settings.value( "/qgis/scanZipInBrowser", "basic" ).toString();
QString scanZipSetting = settings.value( "/qgis/scanZipInBrowser2", "basic" ).toString();
QString vsiPrefix = QgsZipItem::vsiPrefix( thePath );
bool is_vsizip = ( vsiPrefix == "/vsizip/" );
bool is_vsigzip = ( vsiPrefix == "/vsigzip/" );
@@ -318,7 +318,7 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
// not zipfile and scan items == "Check extension"
if ((( is_vsizip || is_vsitar ) && scanZipSetting == "basic" ) ||
( !is_vsizip && !is_vsitar &&
( settings.value( "/qgis/scanItemsInBrowser",
( settings.value( "/qgis/scanItemsInBrowser2",
"extension" ).toString() == "extension" ) ) )
{
// if this is a VRT file make sure it is vector VRT to avoid duplicates
@@ -1790,7 +1790,7 @@ QString createFilters( QString type )
// This does not work for some file types, see VSIFileHandler doc.
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1600
QSettings settings;
if ( settings.value( "/qgis/scanZipInBrowser", "basic" ).toString() != "no" )
if ( settings.value( "/qgis/scanZipInBrowser2", "basic" ).toString() != "no" )
{
myFileFilters += createFileFilter_( QObject::tr( "GDAL/OGR VSIFileHandler" ), "*.zip *.gz *.tar *.tar.gz *.tgz" );
myExtensions << "zip" << "gz" << "tar" << "tar.gz" << "tgz";
@@ -62,7 +62,7 @@ void TestQgsDataItem::initTestCase()
QCoreApplication::setApplicationName( "QGIS-TEST" );
// save current scanItemsSetting value
QSettings settings;
mScanItemsSetting = settings.value( "/qgis/scanItemsInBrowser", 0 ).toInt();
mScanItemsSetting = settings.value( "/qgis/scanItemsInBrowser2", 0 ).toInt();

This comment has been minimized.

Copy link
@brushtyler

brushtyler Nov 6, 2012

Contributor

is 0 the correct default value for scanItemsInBrowser2?

This comment has been minimized.

Copy link
@etiennesky

etiennesky Nov 6, 2012

Author Contributor

no this is a mistake


//create a directory item that will be used in all tests...
mDirItem = new QgsDirectoryItem( 0, "Test", TEST_DATA_DIR );
@@ -72,7 +72,7 @@ void TestQgsDataItem::cleanupTestCase()
{
// restore scanItemsSetting
QSettings settings;
settings.setValue( "/qgis/scanItemsInBrowser", mScanItemsSetting );
settings.setValue( "/qgis/scanItemsInBrowser2", mScanItemsSetting );
if ( mDirItem )
delete mDirItem;
}
@@ -96,7 +96,7 @@ void TestQgsDataItem::testDirItemChildren()
QSettings settings;
for ( int iSetting = 0 ; iSetting <= 1 ; iSetting++ )
{
settings.setValue( "/qgis/scanItemsInBrowser", iSetting );
settings.setValue( "/qgis/scanItemsInBrowser2", iSetting );
QgsDirectoryItem* dirItem = new QgsDirectoryItem( 0, "Test", TEST_DATA_DIR );
QVERIFY( isValidDirItem( dirItem ) );

5 comments on commit b754f07

@brushtyler

This comment has been minimized.

Copy link
Contributor

@brushtyler brushtyler replied Nov 6, 2012

Hi Etienne,
since we have broken APIs and the next release will be QGis 2.0, IMHO it isn't worth to convert the 1.8 settings values to 1.9/2.0 ones if they need a so twisted conversion (it's some code we will need to maintain).

I'd just replace scanZipInBrowser with scanZipInBrowser2.

@etiennesky

This comment has been minimized.

Copy link
Contributor Author

@etiennesky etiennesky replied Nov 6, 2012

Hi,

I justs didn't want things to break for current users, but uf you think it's not worth it I can remove that and fix the default above

@brushtyler

This comment has been minimized.

Copy link
Contributor

@brushtyler brushtyler replied Nov 7, 2012

I justs didn't want things to break for current users, but uf you think it's not worth it I can remove that

It would be worth for critical tasks that makes master unusable, but IMO a such minor break could occur in the development version, especially if the next release will be 2.0.

@etiennesky

This comment has been minimized.

Copy link
Contributor Author

@etiennesky etiennesky replied Nov 7, 2012

ok, thanks for your input

@etiennesky

This comment has been minimized.

Copy link
Contributor Author

@etiennesky etiennesky replied Nov 15, 2012

FYI I fixed this in 565d2eb..7d0d5d3 - thanks

Please sign in to comment.
You can’t perform that action at this time.