[QGIS Commit] r11560 - in trunk/qgis/src: plugins/grass providers/grass

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat Sep 5 08:00:58 EDT 2009


Author: jef
Date: 2009-09-05 08:00:58 -0400 (Sat, 05 Sep 2009)
New Revision: 11560

Modified:
   trunk/qgis/src/plugins/grass/qgsgrassmodel.cpp
   trunk/qgis/src/plugins/grass/qgsgrassmodule.cpp
   trunk/qgis/src/plugins/grass/qgsgrassnewmapset.cpp
   trunk/qgis/src/plugins/grass/qgsgrassplugin.cpp
   trunk/qgis/src/plugins/grass/qgsgrassselect.cpp
   trunk/qgis/src/plugins/grass/qgsgrasstools.cpp
   trunk/qgis/src/providers/grass/provider.cpp
   trunk/qgis/src/providers/grass/qgsgrass.cpp
   trunk/qgis/src/providers/grass/qgsgrass.h
   trunk/qgis/src/providers/grass/qgsgrassprovider.cpp
Log:
apply #1878 (fixes #1900)

Modified: trunk/qgis/src/plugins/grass/qgsgrassmodel.cpp
===================================================================
--- trunk/qgis/src/plugins/grass/qgsgrassmodel.cpp	2009-09-05 11:55:02 UTC (rev 11559)
+++ trunk/qgis/src/plugins/grass/qgsgrassmodel.cpp	2009-09-05 12:00:58 UTC (rev 11560)
@@ -36,8 +36,7 @@
 class QgsGrassModelItem
 {
   public:
-    QgsGrassModelItem( QgsGrassModelItem *parent, int row, QString name,
-                       QString path, int type );
+    QgsGrassModelItem( QgsGrassModelItem *parent, int row, QString name, QString path, int type );
     QgsGrassModelItem();
     ~QgsGrassModelItem();
 
@@ -81,7 +80,7 @@
 
 QgsGrassModelItem::~QgsGrassModelItem()
 {
-  for ( int i = 0; i < mChildren.size();i++ )
+  for ( int i = 0; i < mChildren.size(); i++ )
   {
     delete mChildren[i];
   }
@@ -606,13 +605,13 @@
 
   // Add new items
 
-  for ( int i = 0; i < list.size();i++ )
+  for ( int i = 0; i < list.size(); i++ )
   {
     QString name = list.at( i );
 // QgsDebugMsg(QString("? add %1").arg(name));
 
     int insertAt = item->mChildren.size();
-    for ( int i = 0; i < item->mChildren.size();i++ )
+    for ( int i = 0; i < item->mChildren.size(); i++ )
     {
       if ( item->mChildren[i]->name() == name )
       {
@@ -897,7 +896,6 @@
       default:
         return mIconDirectory;
     }
-    return mIconDirectory;
   }
   return item->data( role );
 }

Modified: trunk/qgis/src/plugins/grass/qgsgrassmodule.cpp
===================================================================
--- trunk/qgis/src/plugins/grass/qgsgrassmodule.cpp	2009-09-05 11:55:02 UTC (rev 11559)
+++ trunk/qgis/src/plugins/grass/qgsgrassmodule.cpp	2009-09-05 12:00:58 UTC (rev 11560)
@@ -47,24 +47,9 @@
 
 #include <gdal.h>         // to collect version information
 
-#if defined(WIN32)
-#include <windows.h>
-static QString getShortPath( const QString &path )
-{
-  TCHAR buf[MAX_PATH];
-  GetShortPathName( path.toAscii().data(), buf, MAX_PATH );
-  return buf;
-}
-#endif
-
 bool QgsGrassModule::mExecPathInited = 0;
 QStringList QgsGrassModule::mExecPath;
 
-
-
-
-
-
 QString QgsGrassModule::findExec( QString file )
 {
   QgsDebugMsg( "called." );
@@ -78,7 +63,7 @@
 
 #ifdef WIN32
     mExecPath = path.split( ";" );
-    mExecPath.prepend( getShortPath( QgsApplication::applicationDirPath() ) );
+    mExecPath.prepend( QgsGrass::shortPath( QgsApplication::applicationDirPath() ) );
 #else
     mExecPath = path.split( ":" );
     mExecPath.prepend( QgsApplication::applicationDirPath() );
@@ -1392,7 +1377,7 @@
   {
     //line = QString::fromLocal8Bit( mProcess.readLineStdout().ascii() );
     QByteArray ba = mProcess.readLine();
-    line = QString::fromLocal8Bit( QString( ba ).toAscii() );
+    line = QString::fromUtf8( ba );
 
     // GRASS_INFO_PERCENT is catched here only because of bugs in GRASS,
     // normaly it should be printed to stderr
@@ -1426,7 +1411,7 @@
   {
     //line = QString::fromLocal8Bit( mProcess.readLineStderr().ascii() );
     QByteArray ba = mProcess.readLine();
-    line = QString::fromLocal8Bit( QString( ba ).toAscii() );
+    line = QString::fromUtf8( ba );
     //QgsDebugMsg(QString("line: '%1'").arg(line));
 
     if ( rxpercent.indexIn( line ) != -1 )

Modified: trunk/qgis/src/plugins/grass/qgsgrassnewmapset.cpp
===================================================================
--- trunk/qgis/src/plugins/grass/qgsgrassnewmapset.cpp	2009-09-05 11:55:02 UTC (rev 11559)
+++ trunk/qgis/src/plugins/grass/qgsgrassnewmapset.cpp	2009-09-05 12:00:58 UTC (rev 11560)
@@ -49,16 +49,6 @@
 QString temp4( GRASS_VERSION_RELEASE );
 #endif
 
-#if defined(WIN32)
-#include <windows.h>
-static QString getShortPath( const QString &path )
-{
-  TCHAR buf[MAX_PATH];
-  GetShortPathName( path.toAscii(), buf, MAX_PATH );
-  return buf;
-}
-#endif
-
 bool QgsGrassNewMapset::mRunning = false;
 
 QgsGrassNewMapset::QgsGrassNewMapset( QgisInterface *iface,
@@ -439,7 +429,7 @@
     int errcode;
     const char *oldlocale = setlocale( LC_NUMERIC, NULL );
     setlocale( LC_NUMERIC, "C" );
-    errcode = OSRImportFromProj4( hCRS, proj4.toAscii() );
+    errcode = OSRImportFromProj4( hCRS, proj4.toUtf8() );
     setlocale( LC_NUMERIC, oldlocale );
     if ( errcode != OGRERR_NONE )
     {
@@ -1261,24 +1251,27 @@
     //       database path
     QgsGrass::activeMode(); // because it calls private gsGrass::init()
 #if defined(WIN32)
-    G__setenv(( char * ) "GISDBASE", getShortPath( mDatabaseLineEdit->text() ).toAscii().data() );
+    G__setenv(( char * ) "GISDBASE", QgsGrass::shortPath( mDatabaseLineEdit->text() ).toUtf8().data() );
 #else
-    G__setenv(( char * ) "GISDBASE", mDatabaseLineEdit->text().toAscii().data() );
+    G__setenv(( char * ) "GISDBASE", mDatabaseLineEdit->text().toUtf8().data() );
 #endif
 
     int ret = 0;
 
-    QgsGrass::resetError();
-    if ( setjmp( QgsGrass::fatalErrorEnv() ) == 0 )
+    try
     {
-      ret = G_make_location( location.toAscii().data(), &mCellHead, mProjInfo, mProjUnits, stdout );
+      ret = G_make_location( location.toUtf8().data(), &mCellHead, mProjInfo, mProjUnits, stdout );
     }
-    QgsGrass::clearErrorEnv();
+    catch ( QgsGrass::Exception &e )
+    {
+      ret = -1;
+      Q_UNUSED( e );
+    }
 
-    if ( QgsGrass::getError() == QgsGrass::FATAL || ret != 0 )
+    if ( ret != 0 )
     {
       QMessageBox::warning( this, tr( "Create location" ),
-                            tr( "Cannot create new location: %1" ).arg( QgsGrass::getErrorMessage() ) );
+                            tr( "Cannot create new location: %1" ).arg( QgsGrass::errorMessage() ) );
       return;
     }
 

Modified: trunk/qgis/src/plugins/grass/qgsgrassplugin.cpp
===================================================================
--- trunk/qgis/src/plugins/grass/qgsgrassplugin.cpp	2009-09-05 11:55:02 UTC (rev 11559)
+++ trunk/qgis/src/plugins/grass/qgsgrassplugin.cpp	2009-09-05 12:00:58 UTC (rev 11560)
@@ -301,14 +301,13 @@
     QgsGrass::setLocation( sel->gisdbase, sel->location );
 
     /* Open vector */
-    QgsGrass::resetError();
-    Vect_set_open_level( 2 );
-    struct Map_info map;
-    int level = Vect_open_old_head( &map, sel->map.toAscii().data(),
-                                    sel->mapset.toAscii().data() );
+    try
+    {
+      Vect_set_open_level( 2 );
+      struct Map_info map;
+      int level = Vect_open_old_head( &map, sel->map.toUtf8().data(),
+                                      sel->mapset.toUtf8().data() );
 
-    if ( QgsGrass::getError() != QgsGrass::FATAL )
-    {
       if ( level >= 2 )
       {
         // Count layers
@@ -336,9 +335,9 @@
 
       Vect_close( &map );
     }
-    else
+    catch ( QgsGrass::Exception &e )
     {
-      QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot open GRASS vector:\n %1" ).arg( QgsGrass::getErrorMessage() ) );
+      QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot open GRASS vector:\n %1" ).arg( QString::fromUtf8( e.what() ) ) );
     }
 
     qGisInterface->addVectorLayer( uri, name, "grass" );
@@ -486,26 +485,29 @@
                        QgsGrass::getDefaultLocation(),
                        QgsGrass::getDefaultMapset() );
 
-  QgsGrass::resetError();
-  struct Map_info Map;
-  Vect_open_new( &Map, name.toAscii().data(), 0 );
-
-  if ( QgsGrass::getError() == QgsGrass::FATAL )
+  try
   {
-    QMessageBox::warning( 0, tr( "Warning" ),
-                          tr( "Cannot create new vector: %1" ).arg( QgsGrass::getErrorMessage() ) );
-    return;
-  }
+    struct Map_info Map;
+    Vect_open_new( &Map, name.toUtf8().data(), 0 );
 
 #if defined(GRASS_VERSION_MAJOR) && defined(GRASS_VERSION_MINOR) && \
   ( ( GRASS_VERSION_MAJOR == 6 && GRASS_VERSION_MINOR >= 4 ) || GRASS_VERSION_MAJOR > 6 )
-  Vect_build( &Map );
+    Vect_build( &Map );
 #else
-  Vect_build( &Map, stderr );
+    Vect_build( &Map, stderr );
 #endif
-  Vect_set_release_support( &Map );
-  Vect_close( &Map );
+    Vect_set_release_support( &Map );
+    Vect_close( &Map );
+  }
+  catch ( QgsGrass::Exception &e )
+  {
+    QMessageBox::warning( 0, tr( "Warning" ),
+                          tr( "Cannot create new vector: %1" ).arg( QString::fromUtf8( e.what() ) ) );
+    return;
+  }
 
+
+
   // Open in GRASS vector provider
 
   QString uri = QgsGrass::getDefaultGisdbase() + "/"

Modified: trunk/qgis/src/plugins/grass/qgsgrassselect.cpp
===================================================================
--- trunk/qgis/src/plugins/grass/qgsgrassselect.cpp	2009-09-05 11:55:02 UTC (rev 11559)
+++ trunk/qgis/src/plugins/grass/qgsgrassselect.cpp	2009-09-05 12:00:58 UTC (rev 11560)
@@ -346,7 +346,7 @@
 
   QStringList layers = vectorLayers( egisdbase->text(),
                                      elocation->currentText(), emapset->currentText(),
-                                     emap->currentText().toAscii() );
+                                     emap->currentText().toUtf8() );
 
   int idx = 0;
   int sel = -1;
@@ -410,15 +410,15 @@
   // Call to setjmp() returns 0 first time. In case of fatal error,
   // our error routine uses longjmp() to come back to this context,
   // this time setjmp() will return non-zero value and we can continue...
-  if ( setjmp( QgsGrass::fatalErrorEnv() ) == 0 )
+
+  try
   {
-    level = Vect_open_old_head( &map, ( char * ) mapName.toAscii().data(), ( char * ) mapset.toAscii().data() );
+    level = Vect_open_old_head( &map, ( char * ) mapName.toUtf8().data(), ( char * ) mapset.toUtf8().data() );
   }
-  QgsGrass::clearErrorEnv();
-
-  if ( QgsGrass::getError() == QgsGrass::FATAL )
+  catch ( QgsGrass::Exception &e )
   {
-    QgsDebugMsg( QString( "Cannot open GRASS vector: %1" ).arg( QgsGrass::getErrorMessage() ) );
+    Q_UNUSED( e );
+    QgsDebugMsg( QString( "Cannot open GRASS vector: %1" ).arg( e.what() ) );
     return list;
   }
 

Modified: trunk/qgis/src/plugins/grass/qgsgrasstools.cpp
===================================================================
--- trunk/qgis/src/plugins/grass/qgsgrasstools.cpp	2009-09-05 11:55:02 UTC (rev 11559)
+++ trunk/qgis/src/plugins/grass/qgsgrasstools.cpp	2009-09-05 12:00:58 UTC (rev 11560)
@@ -43,17 +43,6 @@
 #include <QStandardItem>
 
 
-#if defined(WIN32)
-#include <windows.h>
-static QString getShortPath( const QString &path )
-{
-  TCHAR buf[MAX_PATH];
-  GetShortPathName( path.toAscii(), buf, MAX_PATH );
-  return buf;
-}
-#endif
-
-
 QgsGrassTools::QgsGrassTools( QgisInterface *iface,
                               QWidget * parent, const char * name, Qt::WFlags f )
     : QDialog( parent, f ), QgsGrassToolsBase()
@@ -360,7 +349,7 @@
 QString QgsGrassTools::appDir( void )
 {
 #if defined(WIN32)
-  return getShortPath( QgsApplication::applicationDirPath() );
+  return QgsGrass::shortPath( QgsApplication::applicationDirPath() );
 #else
   return QgsApplication::applicationDirPath();
 #endif

Modified: trunk/qgis/src/providers/grass/provider.cpp
===================================================================
--- trunk/qgis/src/providers/grass/provider.cpp	2009-09-05 11:55:02 UTC (rev 11559)
+++ trunk/qgis/src/providers/grass/provider.cpp	2009-09-05 12:00:58 UTC (rev 11560)
@@ -14,7 +14,6 @@
  *                                                                         *
  ***************************************************************************/
 #include <string.h>
-#include <iostream>
 #include <vector>
 #include <cfloat>
 

Modified: trunk/qgis/src/providers/grass/qgsgrass.cpp
===================================================================
--- trunk/qgis/src/providers/grass/qgsgrass.cpp	2009-09-05 11:55:02 UTC (rev 11559)
+++ trunk/qgis/src/providers/grass/qgsgrass.cpp	2009-09-05 12:00:58 UTC (rev 11560)
@@ -26,6 +26,8 @@
 #include <QSettings>
 #include <QTextStream>
 
+#include <QTextCodec>
+
 extern "C"
 {
 #ifndef _MSC_VER
@@ -37,11 +39,12 @@
 
 #if defined(WIN32)
 #include <windows.h>
-static QString getShortPath( const QString &path )
+QString GRASS_EXPORT QgsGrass::shortPath( const QString &path )
 {
   TCHAR buf[MAX_PATH];
-  GetShortPathName( path.toAscii(), buf, MAX_PATH );
-  return buf;
+  GetShortPathName( path.toUtf8().constData(), buf, MAX_PATH );
+  QString res = QString::fromUtf8( buf );
+  return res;
 }
 #endif
 
@@ -54,7 +57,8 @@
   // Set error function
   G_set_error_routine( &error_routine );
 
-  if ( initialized ) return;
+  if ( initialized )
+    return;
 
   QSettings settings;
 
@@ -91,7 +95,7 @@
   // This value should always take precedence.
 #if WIN32
   QString gisBase = getenv( "WINGISBASE" ) ? getenv( "WINGISBASE" ) : getenv( "GISBASE" );
-  gisBase = getShortPath( gisBase );
+  gisBase = shortPath( gisBase );
 #else
   QString gisBase = getenv( "GISBASE" );
 #endif
@@ -110,7 +114,7 @@
 
 #ifdef WIN32
     // Use the applicationDirPath()/grass
-    gisBase = getShortPath( QCoreApplication::applicationDirPath() + "/grass" );
+    gisBase = shortPath( QCoreApplication::applicationDirPath() + "/grass" );
     QgsDebugMsg( QString( "GRASS gisBase = %1" ).arg( gisBase ) );
 #else
     // Use the location specified --with-grass during configure
@@ -150,7 +154,7 @@
       break;
     }
 #if defined(WIN32)
-    gisBase = getShortPath( gisBase );
+    gisBase = shortPath( gisBase );
 #endif
   }
 
@@ -170,7 +174,7 @@
   QString gisBaseEnv = "GISBASE=" + gisBase;
   /* _Correct_ putenv() implementation is not making copy! */
   char *gisBaseEnvChar = new char[gisBaseEnv.length()+1];
-  strcpy( gisBaseEnvChar, gisBaseEnv.toAscii().constData() );
+  strcpy( gisBaseEnvChar, gisBaseEnv.toUtf8().constData() );
   putenv( gisBaseEnvChar );
 
   // Add path to GRASS modules
@@ -190,11 +194,11 @@
 #ifdef WIN32
   // It seems that QgsApplication::prefixPath()
   // is not initialized at this point
-  path.append( sep + getShortPath( QCoreApplication::applicationDirPath() ) );
+  path.append( sep + shortPath( QCoreApplication::applicationDirPath() ) );
 
   // Add path to MSYS bin
   // Warning: MSYS sh.exe will translate this path to '/bin'
-  path.append( sep + getShortPath( QCoreApplication::applicationDirPath() + "/msys/bin/" ) );
+  path.append( sep + shortPath( QCoreApplication::applicationDirPath() + "/msys/bin/" ) );
 #endif
 
   QString p = getenv( "PATH" );
@@ -202,7 +206,7 @@
 
   QgsDebugMsg( QString( "set PATH: %1" ).arg( path ) );
   char *pathEnvChar = new char[path.length()+1];
-  strcpy( pathEnvChar, path.toAscii().constData() );
+  strcpy( pathEnvChar, path.toUtf8().constData() );
   putenv( pathEnvChar );
 
   // Set PYTHONPATH
@@ -211,7 +215,7 @@
   pythonpath.append( sep + pp );
   QgsDebugMsg( QString( "set PYTHONPATH: %1" ).arg( pythonpath ) );
   char *pythonpathEnvChar = new char[pythonpath.length()+1];
-  strcpy( pythonpathEnvChar, pythonpath.toAscii().constData() );
+  strcpy( pythonpathEnvChar, pythonpath.toUtf8().constData() );
   putenv( pythonpathEnvChar );
 
   // Set GRASS_PAGER if not set, it is necessary for some
@@ -253,7 +257,7 @@
     {
       pager.prepend( "GRASS_PAGER=" );
       char *pagerEnvChar = new char[pager.length()+1];
-      strcpy( pagerEnvChar, pager.toAscii().constData() );
+      strcpy( pagerEnvChar, pager.toUtf8().constData() );
       putenv( pagerEnvChar );
     }
   }
@@ -278,7 +282,7 @@
   /*
   if ( QgsGrass::versionMajor() > 6 || QgsGrass::versionMinor() > 0 )
   {
-  if ( G_is_gisbase( gisBase.toLocal8Bit().constData() ) ) return TRUE;
+  if ( G_is_gisbase( gisBase.toUtf8().constData() ) ) return TRUE;
   }
   else
   {
@@ -319,12 +323,12 @@
   init();
 
   // Set principal GRASS variables (in memory)
-#if defined(WIN32)
-  G__setenv(( char * ) "GISDBASE", getShortPath( gisdbase ).toAscii().data() );
-#else
-  G__setenv(( char * ) "GISDBASE", gisdbase.toAscii().data() );
-#endif
-  G__setenv(( char * ) "LOCATION_NAME", location.toAscii().data() );
+// #if defined(WIN32)
+//  G__setenv(( char * ) "GISDBASE", shortPath( gisdbase ).toLocal8Bit().data() );
+//#else
+  G__setenv(( char * ) "GISDBASE", gisdbase.toAscii().constData() );
+//#endif
+  G__setenv(( char * ) "LOCATION_NAME", location.toAscii().constData() );
   G__setenv(( char * ) "MAPSET", ( char * ) "PERMANENT" ); // PERMANENT must always exist
 
   // Add all available mapsets to search path
@@ -338,13 +342,13 @@
   init();
 
   // Set principal GRASS variables (in memory)
-#if defined(WIN32)
-  G__setenv(( char * ) "GISDBASE", getShortPath( gisdbase ).toAscii().data() );
-#else
-  G__setenv(( char * ) "GISDBASE", gisdbase.toAscii().data() );
-#endif
-  G__setenv(( char * ) "LOCATION_NAME", location.toAscii().data() );
-  G__setenv(( char * ) "MAPSET", mapset.toAscii().data() );
+// #if defined(WIN32)
+//  G__setenv(( char * ) "GISDBASE", shortPath( gisdbase ).toUtf8().data() );
+// #else
+  G__setenv(( char * ) "GISDBASE", gisdbase.toUtf8().data() );
+// #endif
+  G__setenv(( char * ) "LOCATION_NAME", location.toUtf8().data() );
+  G__setenv(( char * ) "MAPSET", mapset.toUtf8().data() );
 
   // Add all available mapsets to search path
   char **ms = G_available_mapsets();
@@ -355,7 +359,7 @@
 
 bool QgsGrass::active = 0;
 
-QgsGrass::GERROR QgsGrass::error = QgsGrass::OK;
+QgsGrass::GERROR QgsGrass::lastError = QgsGrass::OK;
 
 QString QgsGrass::error_message;
 
@@ -367,9 +371,6 @@
 QString QgsGrass::mGisrc;
 QString QgsGrass::mTmp;
 
-jmp_buf QgsGrass::mFatalErrorEnv;
-bool QgsGrass::mFatalErrorEnvActive = false;
-
 int QgsGrass::error_routine( char *msg, int fatal )
 {
   return error_routine(( const char* ) msg, fatal );
@@ -383,57 +384,35 @@
 
   if ( fatal )
   {
-    error = FATAL;
     // we have to do a long jump here, otherwise GRASS >= 6.3 will kill our process
-    if ( mFatalErrorEnvActive )
-      longjmp( mFatalErrorEnv, 1 );
-    else
-    {
-      QMessageBox::warning( 0, QObject::tr( "Uncatched fatal GRASS error" ), msg );
-      abort();
-    }
+    throw QgsGrass::Exception( msg );
   }
   else
-    error = WARNING;
+    lastError = WARNING;
 
   return 1;
 }
 
 void GRASS_EXPORT QgsGrass::resetError( void )
 {
-  error = OK;
+  lastError = OK;
 }
 
-int GRASS_EXPORT QgsGrass::getError( void )
+int GRASS_EXPORT QgsGrass::error( void )
 {
-  return error;
+  return lastError;
 }
 
-QString GRASS_EXPORT QgsGrass::getErrorMessage( void )
+QString GRASS_EXPORT QgsGrass::errorMessage( void )
 {
   return error_message;
 }
 
-jmp_buf GRASS_EXPORT &QgsGrass::fatalErrorEnv()
-{
-  if ( mFatalErrorEnvActive )
-    QgsDebugMsg( "fatal error environment already active." );
-  mFatalErrorEnvActive = true;
-  return mFatalErrorEnv;
-}
-
-void GRASS_EXPORT QgsGrass::clearErrorEnv()
-{
-  if ( !mFatalErrorEnvActive )
-    QgsDebugMsg( "fatal error environment already deactive." );
-  mFatalErrorEnvActive = false;
-}
-
 QString GRASS_EXPORT QgsGrass::openMapset( QString gisdbase, QString location, QString mapset )
 {
-  QgsDebugMsg( QString( "gisdbase = %1" ).arg( gisdbase.toLocal8Bit().constData() ) );
-  QgsDebugMsg( QString( "location = %1" ).arg( location.toLocal8Bit().constData() ) );
-  QgsDebugMsg( QString( "mapset = %1" ).arg( mapset.toLocal8Bit().constData() ) );
+  QgsDebugMsg( QString( "gisdbase = %1" ).arg( gisdbase.toUtf8().constData() ) );
+  QgsDebugMsg( QString( "location = %1" ).arg( location.toUtf8().constData() ) );
+  QgsDebugMsg( QString( "mapset = %1" ).arg( mapset.toUtf8().constData() ) );
 
   QString mapsetPath = gisdbase + "/" + location + "/" + mapset;
 
@@ -460,7 +439,7 @@
 #else
   int pid = GetCurrentProcessId();
 #endif
-  lockFile.write( QString( "%1" ).arg( pid ).toLocal8Bit() );
+  lockFile.write( QString( "%1" ).arg( pid ).toUtf8() );
   lockFile.close();
 #else
   QProcess *process = new QProcess();
@@ -516,8 +495,8 @@
   QString globalGisrc =  QDir::home().path() + "/.grassrc6";
   mGisrc = mTmp + "/gisrc";
 
-  QgsDebugMsg( QString( "globalGisrc = %1" ).arg( globalGisrc.toLocal8Bit().constData() ) );
-  QgsDebugMsg( QString( "mGisrc = %1" ).arg( mGisrc.toLocal8Bit().constData() ) );
+  QgsDebugMsg( QString( "globalGisrc = %1" ).arg( globalGisrc ) );
+  QgsDebugMsg( QString( "mGisrc = %1" ).arg( mGisrc ) );
 
   QFile out( mGisrc );
   if ( !out.open( QIODevice::WriteOnly ) )
@@ -558,19 +537,19 @@
 
   /* _Correct_ putenv() implementation is not making copy! */
   QString gisrcEnv = "GISRC=" + mGisrc;
-  char *gisrcEnvChar = new char[gisrcEnv.length()+1];
-  strcpy( gisrcEnvChar, gisrcEnv.toAscii().constData() );
+  char *gisrcEnvChar = new char[gisrcEnv.toUtf8().length()+1];
+  strcpy( gisrcEnvChar, gisrcEnv.toLocal8Bit().constData() );
   putenv( gisrcEnvChar );
 
   // Reinitialize GRASS
-  G__setenv(( char * ) "GISRC", gisrcEnv.toAscii().data() );
+  G__setenv(( char * ) "GISRC", gisrcEnv.toUtf8().data() );
 #if defined(WIN32)
-  G__setenv(( char * ) "GISDBASE", getShortPath( gisdbase ).toAscii().data() );
+  G__setenv(( char * ) "GISDBASE", shortPath( gisdbase ).toLocal8Bit().data() );
 #else
-  G__setenv(( char * ) "GISDBASE", gisdbase.toAscii().data() );
+  G__setenv(( char * ) "GISDBASE", gisdbase.toUtf8().data() );
 #endif
-  G__setenv(( char * ) "LOCATION_NAME", location.toAscii().data() );
-  G__setenv(( char * ) "MAPSET", mapset.toAscii().data() );
+  G__setenv(( char * ) "LOCATION_NAME", location.toLocal8Bit().data() );
+  G__setenv(( char * ) "MAPSET", mapset.toLocal8Bit().data() );
   defaultGisdbase = gisdbase;
   defaultLocation = location;
   defaultMapset = mapset;
@@ -627,13 +606,13 @@
         dir.remove( dir[i] );
         if ( dir.remove( dir[i] ) )
         {
-          QgsDebugMsg( QString( "Cannot remove temporary file %1" ).arg( dir[i].toLocal8Bit().constData() ) );
+          QgsDebugMsg( QString( "Cannot remove temporary file %1" ).arg( dir[i] ) );
         }
       }
 
       if ( !dir.rmdir( mTmp ) )
       {
-        QgsDebugMsg( QString( "Cannot remove temporary directory %1" ).arg( mTmp.toLocal8Bit().constData() ) );
+        QgsDebugMsg( QString( "Cannot remove temporary directory %1" ).arg( mTmp ) );
       }
     }
   }
@@ -710,9 +689,9 @@
   QStringList list;
 
   char **glist = G_list( G_ELEMENT_VECTOR,
-  gisbase.toLocal8Bit().constData(),
-  locationName.toLocal8Bit().constData(),
-  mapsetName.toLocal8Bit().constData() );
+  gisbase.toUtf8().constData(),
+  locationName.toUtf8().constData(),
+  mapsetName.toUtf8().constData() );
 
   int i = 0;
 
@@ -772,9 +751,9 @@
   QStringList list;
 
   char **glist = G_list( G_ELEMENT_RASTER,
-  gisbase.toLocal8Bit().constData(),
-  locationName.toLocal8Bit().constData(),
-  mapsetName.toLocal8Bit().constData() );
+  gisbase.toUtf8().constData(),
+  locationName.toUtf8().constData(),
+  mapsetName.toUtf8().constData() );
 
   int i = 0;
 
@@ -882,7 +861,7 @@
 {
   QgsGrass::setLocation( gisbase, location );
 
-  if ( G__get_window( window, ( char * ) "", ( char * ) "WIND", mapset.toLocal8Bit().data() ) )
+  if ( G__get_window( window, ( char * ) "", ( char * ) "WIND", mapset.toUtf8().data() ) )
   {
     return false;
   }
@@ -963,8 +942,8 @@
   if ( type == Raster )
   {
 
-    if ( G_get_cellhd( map.toLocal8Bit().data(),
-                       mapset.toLocal8Bit().data(), window ) < 0 )
+    if ( G_get_cellhd( map.toUtf8().data(),
+                       mapset.toUtf8().data(), window ) < 0 )
     {
       QMessageBox::warning( 0, QObject::tr( "Warning" ),
                             QObject::tr( "Cannot read raster map region" ) );
@@ -979,7 +958,7 @@
     struct Map_info Map;
 
     int level = Vect_open_old_head( &Map,
-                                    map.toLocal8Bit().data(), mapset.toLocal8Bit().data() );
+                                    map.toUtf8().data(), mapset.toUtf8().data() );
 
     if ( level < 2 )
     {
@@ -1016,8 +995,8 @@
   else if ( type == Region )
   {
     if ( G__get_window( window, ( char * ) "windows",
-                        map.toLocal8Bit().data(),
-                        mapset.toLocal8Bit().data() ) != NULL )
+                        map.toUtf8().data(),
+                        mapset.toUtf8().data() ) != NULL )
     {
       QMessageBox::warning( 0, QObject::tr( "Warning" ),
                             QObject::tr( "Cannot read region" ) );
@@ -1070,7 +1049,7 @@
   /*
   if ( QgsGrass::versionMajor() > 6 || QgsGrass::versionMinor() > 0 )
   {
-  if ( G_is_mapset( path.toLocal8Bit().constData() ) ) return true;
+  if ( G_is_mapset( path.toUtf8().constData() ) ) return true;
   }
   else
   {

Modified: trunk/qgis/src/providers/grass/qgsgrass.h
===================================================================
--- trunk/qgis/src/providers/grass/qgsgrass.h	2009-09-05 11:55:02 UTC (rev 11559)
+++ trunk/qgis/src/providers/grass/qgsgrass.h	2009-09-05 12:00:58 UTC (rev 11560)
@@ -23,16 +23,20 @@
 #include <grass/form.h>
 }
 
+#include <stdexcept>
 #include <QString>
-#include <setjmp.h>
 
 /*!
    Methods for C library initialization and error handling.
 */
 class QgsGrass
 {
-
   public:
+    struct Exception : public std::runtime_error
+    {
+      Exception( const std::string &msg ) : std::runtime_error( msg ) {}
+    };
+
     //! Get info about the mode
     /*! QgsGrass may be running in active or passive mode.
      *  Active mode means that GISRC is set up and GISRC file is available,
@@ -64,10 +68,9 @@
     */
     static GRASS_EXPORT void setMapset( QString gisdbase, QString location, QString mapset );
 
-    //! Error codes returned by GetError()
+    //! Error codes returned by error()
     enum GERROR { OK, /*!< OK. No error. */
-                  WARNING, /*!< Warning, non fatal error. Should be printed by application. */
-                  FATAL /*!< Fatal error. Function faild. */
+                  WARNING /*!< Warning, non fatal error. Should be printed by application. */
               };
 
     //! Map type
@@ -77,10 +80,10 @@
     static GRASS_EXPORT void resetError( void );  // reset error status
 
     //! Check if any error occured in lately called functions. Returns value from ERROR.
-    static GRASS_EXPORT int getError( void );
+    static GRASS_EXPORT int error( void );
 
     //! Get last error message
-    static GRASS_EXPORT QString getErrorMessage( void );
+    static GRASS_EXPORT QString errorMessage( void );
 
     /** \brief Open existing GRASS mapset
      * \return NULL string or error message
@@ -160,10 +163,10 @@
     static GRASS_EXPORT int versionRelease();
     static GRASS_EXPORT QString versionString();
 
-    static GRASS_EXPORT jmp_buf& fatalErrorEnv();
-    static GRASS_EXPORT void clearErrorEnv();
+#if defined(WIN32)
+    static GRASS_EXPORT QString shortPath( const QString &path );
+#endif
 
-
   private:
     static int initialized; // Set to 1 after initialization
     static bool active; // is active mode
@@ -172,7 +175,7 @@
     static QString defaultMapset;
 
     /* last error in GRASS libraries */
-    static GERROR error;         // static, because used in constructor
+    static GERROR lastError;         // static, because used in constructor
     static QString error_message;
 
     // G_set_error_routine has two versions of the function's first argument it expects:
@@ -188,10 +191,6 @@
     static QString mGisrc;
     // Temporary directory where GISRC and sockets are stored
     static QString mTmp;
-
-    // Context saved before a call to routine that can produce a fatal error
-    static jmp_buf mFatalErrorEnv;
-    static bool mFatalErrorEnvActive;
 };
 
 #endif // QGSGRASS_H

Modified: trunk/qgis/src/providers/grass/qgsgrassprovider.cpp
===================================================================
--- trunk/qgis/src/providers/grass/qgsgrassprovider.cpp	2009-09-05 11:55:02 UTC (rev 11559)
+++ trunk/qgis/src/providers/grass/qgsgrassprovider.cpp	2009-09-05 12:00:58 UTC (rev 11560)
@@ -218,7 +218,8 @@
 
   mValid = false;
 
-  if ( ! mMaps[mLayers[mLayerId].mapId].valid ) return;
+  if ( !mMaps[mLayers[mLayerId].mapId].valid )
+    return;
 
   // Getting the total number of features in the layer
   // It may happen that the field disappeares from the map (deleted features, new map without that field)
@@ -300,7 +301,8 @@
   if ( isEdited() || isFrozen() || !mValid )
     return false;
 
-  if ( mCidxFieldIndex < 0 ) return false; // No features, no features in this layer
+  if ( mCidxFieldIndex < 0 || mNextCidx >= mCidxFieldNumCats )
+    return false; // No features, no features in this layer
 
   // Get next line/area id
   int found = 0;
@@ -309,12 +311,17 @@
     Vect_cidx_get_cat_by_index( mMap, mCidxFieldIndex, mNextCidx++, &cat, &type, &id );
     // Warning: selection array is only of type line/area of current layer -> check type first
 
-    if ( !( type & mGrassType ) ) continue;
-    if ( !mSelection[id] ) continue;
+    if ( !( type & mGrassType ) )
+      continue;
+
+    if ( !mSelection[id] )
+      continue;
+
     found = 1;
     break;
   }
-  if ( !found ) return false; // No more features
+  if ( !found )
+    return false; // No more features
 #if QGISDEBUG > 3
   QgsDebugMsg( QString( "cat = %1 type = %2 id = %3" ).arg( cat ).arg( type ).arg( id ) );
 #endif
@@ -655,16 +662,15 @@
 
   // Open map
   QgsGrass::init();
-  QgsGrass::resetError();
-  if ( setjmp( QgsGrass::fatalErrorEnv() ) == 0 )
+
+  try
   {
     layer.mapId = openMap( gisdbase, location, mapset, mapName );
   }
-  QgsGrass::clearErrorEnv();
-
-  if ( QgsGrass::getError() == QgsGrass::FATAL )
+  catch ( QgsGrass::Exception &e )
   {
-    QgsDebugMsg( QString( "Cannot open vector map: %1" ).arg( QgsGrass::getErrorMessage() ) );
+    Q_UNUSED( e );
+    QgsDebugMsg( QString( "Cannot open vector map: %1" ).arg( e.what() ) );
     return -1;
   }
 
@@ -1002,7 +1008,7 @@
   QgsDebugMsg( QString( "Setting  gisdbase, location: %1, %2" ).arg( gisdbase ).arg( location ) );
 
   // Find the vector
-  const char *ms = G_find_vector2( mapName.toAscii().data(), mapset.toAscii().data() ) ;
+  const char *ms = G_find_vector2( mapName.toUtf8().data(), mapset.toUtf8().data() ) ;
 
   if ( ms == NULL )
   {
@@ -1020,53 +1026,56 @@
 
   // Do we have topology and cidx (level2)
   int level = 2;
-  QgsGrass::resetError();
-  Vect_set_open_level( 2 );
-  Vect_open_old_head( map.map, mapName.toAscii().data(), mapset.toAscii().data() );
-  if ( QgsGrass::getError() == QgsGrass::FATAL )
+  try
   {
-    QgsDebugMsg( QString( "Cannot open GRASS vector head on level2: %1" ).arg( QgsGrass::getErrorMessage() ) );
-    level = 1;
+    Vect_set_open_level( 2 );
+    Vect_open_old_head( map.map, mapName.toUtf8().data(), mapset.toUtf8().data() );
+    Vect_close( map.map );
   }
-  else
+  catch ( QgsGrass::Exception &e )
   {
-    Vect_close( map.map );
+    Q_UNUSED( e );
+    QgsDebugMsg( QString( "Cannot open GRASS vector head on level2: %1" ).arg( e.what() ) );
+    level = 1;
   }
 
   if ( level == 1 )
   {
     QMessageBox::StandardButton ret = QMessageBox::question( 0, "Warning",
-                                      "GRASS vector map " + mapName +
-                                      + " does not have topology. Build topology?",
+                                      tr( "GRASS vector map %1 does not have topology. Build topology?" ).arg( mapName ),
                                       QMessageBox::Ok | QMessageBox::Cancel );
 
     if ( ret == QMessageBox::Cancel ) return -1;
   }
 
   // Open vector
-  QgsGrass::resetError(); // to "catch" error after Vect_open_old()
-  Vect_set_open_level( level );
-  Vect_open_old( map.map, mapName.toAscii().data(), mapset.toAscii().data() );
-
-  if ( QgsGrass::getError() == QgsGrass::FATAL )
+  try
   {
-    QgsDebugMsg( QString( "Cannot open GRASS vector: %1" ).arg( QgsGrass::getErrorMessage() ) );
+    Vect_set_open_level( level );
+    Vect_open_old( map.map, mapName.toUtf8().data(), mapset.toUtf8().data() );
+  }
+  catch ( QgsGrass::Exception &e )
+  {
+    Q_UNUSED( e );
+    QgsDebugMsg( QString( "Cannot open GRASS vector: %1" ).arg( e.what() ) );
     return -1;
   }
 
   if ( level == 1 )
   {
-    QgsGrass::resetError();
+    try
+    {
 #if defined(GRASS_VERSION_MAJOR) && defined(GRASS_VERSION_MINOR) && \
     ( ( GRASS_VERSION_MAJOR == 6 && GRASS_VERSION_MINOR >= 4 ) || GRASS_VERSION_MAJOR > 6 )
-    Vect_build( map.map );
+      Vect_build( map.map );
 #else
-    Vect_build( map.map, stderr );
+      Vect_build( map.map, stderr );
 #endif
-
-    if ( QgsGrass::getError() == QgsGrass::FATAL )
+    }
+    catch ( QgsGrass::Exception &e )
     {
-      QgsDebugMsg( QString( "Cannot build topology: %1" ).arg( QgsGrass::getErrorMessage() ) );
+      Q_UNUSED( e );
+      QgsDebugMsg( QString( "Cannot build topology: %1" ).arg( e.what() ) );
       return -1;
     }
   }
@@ -1092,13 +1101,14 @@
   map->valid = false;
   map->version++;
 
-  QgsGrass::setLocation( map->gisdbase.toAscii().constData(), map->location.toAscii().constData() );
+  QgsGrass::setLocation( map->gisdbase.toUtf8().constData(), map->location.toUtf8().constData() );
 
   // TODO: Should be done better / in other place ?
   // TODO: Is it necessary for close ?
-  G__setenv(( char * )"MAPSET", map->mapset.toAscii().data() );
+  G__setenv(( char * )"MAPSET", map->mapset.toUtf8().data() );
 
-  if ( closeMap ) Vect_close( map->map );
+  if ( closeMap )
+    Vect_close( map->map );
 
   QFileInfo di( map->gisdbase + "/" + map->location + "/" + map->mapset + "/vector/" + map->mapName );
   map->lastModified = di.lastModified();
@@ -1107,17 +1117,15 @@
   map->lastAttributesModified = di.lastModified();
 
   // Reopen vector
-  QgsGrass::resetError(); // to "catch" error after Vect_open_old()
-  Vect_set_open_level( 2 );
-  if ( setjmp( QgsGrass::fatalErrorEnv() ) == 0 )
+  try
   {
-    Vect_open_old( map->map, map->mapName.toAscii().data(), map->mapset.toAscii().data() );
+    Vect_set_open_level( 2 );
+    Vect_open_old( map->map, map->mapName.toUtf8().data(), map->mapset.toUtf8().data() );
   }
-  QgsGrass::clearErrorEnv();
-
-  if ( QgsGrass::getError() == QgsGrass::FATAL )
+  catch ( QgsGrass::Exception &e )
   {
-    QgsDebugMsg( QString( "Cannot reopen GRASS vector: %1" ).arg( QgsGrass::getErrorMessage() ) );
+    Q_UNUSED( e );
+    QgsDebugMsg( QString( "Cannot reopen GRASS vector: %1" ).arg( e.what() ) );
 
     // if reopen fails, mLayers should be also updated
     for ( unsigned int i = 0; i <  mLayers.size(); i++ )
@@ -1167,8 +1175,16 @@
     {
       bool mapsetunset = G__getenv( "MAPSET" ) == NULL || *G__getenv( "MAPSET" ) == 0;
       if ( mapsetunset )
-        G__setenv(( char * )"MAPSET", mMaps[mapId].mapset.toAscii().data() );
-      Vect_close( mMaps[mapId].map );
+        G__setenv(( char * )"MAPSET", mMaps[mapId].mapset.toUtf8().data() );
+      try
+      {
+        Vect_close( mMaps[mapId].map );
+      }
+      catch ( QgsGrass::Exception &e )
+      {
+        Q_UNUSED( e );
+        QgsDebugMsg( QString( "Vect_close failed: %1" ).arg( e.what() ) );
+      }
       if ( mapsetunset )
         G__setenv(( char * )"MAPSET", "" );
     }
@@ -1268,7 +1284,7 @@
     GATT *att = ( GATT * ) bsearch( &key, mLayers[layerId].attributes, mLayers[layerId].nAttributes,
                                     sizeof( GATT ), cmpAtt );
 
-    for ( QgsAttributeList::const_iterator iter = attlist.begin(); iter != attlist.end();++iter )
+    for ( QgsAttributeList::const_iterator iter = attlist.begin(); iter != attlist.end(); ++iter )
     {
       if ( att != NULL )
       {
@@ -1306,16 +1322,15 @@
   const char *oldlocale = setlocale( LC_NUMERIC, NULL );
   setlocale( LC_NUMERIC, "C" );
 
-  if ( setjmp( QgsGrass::fatalErrorEnv() ) == 0 )
+  try
   {
     G_get_default_window( &cellhd );
   }
-  QgsGrass::clearErrorEnv();
-
-  if ( QgsGrass::getError() == QgsGrass::FATAL )
+  catch ( QgsGrass::Exception &e )
   {
+    Q_UNUSED( e );
     setlocale( LC_NUMERIC, oldlocale );
-    QgsDebugMsg( QString( "Cannot get default window: %1" ).arg( QgsGrass::getErrorMessage() ) );
+    QgsDebugMsg( QString( "Cannot get default window: %1" ).arg( e.what() ) );
     return QgsCoordinateReferenceSystem();
   }
 
@@ -1390,7 +1405,7 @@
     return false;
 
   /* Check if current user is owner of mapset */
-  if ( G__mapset_permissions2( mGisdbase.toAscii().data(), mLocation.toAscii().data(), mMapset.toAscii().data() ) != 1 )
+  if ( G__mapset_permissions2( mGisdbase.toUtf8().data(), mLocation.toUtf8().data(), mMapset.toUtf8().data() ) != 1 )
     return false;
 
   // TODO: check format? (cannot edit OGR layers)
@@ -1464,50 +1479,51 @@
   GMAP *map = &( mMaps[mLayers[mLayerId].mapId] );
   map->valid = false;
 
-  QgsGrass::setLocation( map->gisdbase.toAscii().constData(), map->location.toAscii().constData() );
+  QgsGrass::setLocation( map->gisdbase.toUtf8().constData(), map->location.toUtf8().constData() );
 
   // Set current mapset (mapset was previously checked by isGrassEditable() )
   // TODO: Should be done better / in other place ?
-  G__setenv(( char * )"MAPSET", map->mapset.toAscii().data() );
+  G__setenv(( char * )"MAPSET", map->mapset.toUtf8().data() );
 
   Vect_close( map->map );
 
   // TODO: Catch error
-
-  QgsGrass::resetError();
-  int level = Vect_open_update( map->map, map->mapName.toAscii().data(), map->mapset.toAscii().data() );
-  if ( level < 2 )
+  int level = -1;
+  try
   {
-    if ( QgsGrass::getError() == QgsGrass::FATAL )
+    level = Vect_open_update( map->map, map->mapName.toUtf8().data(), map->mapset.toUtf8().data() );
+    if ( level < 2 )
     {
-      QgsDebugMsg( QString( "Cannot open GRASS vector for update: %1" ).arg( QgsGrass::getErrorMessage() ) );
-    }
-    else
-    {
       QgsDebugMsg( "Cannot open GRASS vector for update on level 2." );
     }
+  }
+  catch ( QgsGrass::Exception &e )
+  {
+    Q_UNUSED( e );
+    QgsDebugMsg( QString( "Cannot open GRASS vector for update: %1" ).arg( e.what() ) );
+  }
 
+  if ( level < 2 )
+  {
     // reopen vector for reading
-    QgsGrass::resetError();
-    Vect_set_open_level( 2 );
-    level = Vect_open_old( map->map, map->mapName.toAscii().data(), map->mapset.toAscii().data() );
-
-    if ( level < 2 )
+    try
     {
-      if ( QgsGrass::getError() == QgsGrass::FATAL )
+      Vect_set_open_level( 2 );
+      level = Vect_open_old( map->map, map->mapName.toUtf8().data(), map->mapset.toUtf8().data() );
+      if ( level < 2 )
       {
-        QgsDebugMsg( QString( "Cannot reopen GRASS vector: %1" ).arg( QgsGrass::getErrorMessage() ) );
+        QgsDebugMsg( QString( "Cannot reopen GRASS vector: %1" ).arg( QgsGrass::errorMessage() ) );
       }
-      else
-      {
-        QgsDebugMsg( "Cannot reopen GRASS vector on level 2." );
-      }
     }
-    else
+    catch ( QgsGrass::Exception &e )
     {
-      map->valid = true;
+      Q_UNUSED( e );
+      QgsDebugMsg( QString( "Cannot reopen GRASS vector: %1" ).arg( e.what() ) );
     }
 
+    if ( level >= 2 )
+      map->valid = true;
+
     return false;
   }
   Vect_set_category_index_update( map->map );
@@ -1539,12 +1555,12 @@
   map->valid = false;
   map->version++;
 
-  QgsGrass::setLocation( map->gisdbase.toAscii().constData(), map->location.toAscii().constData() );
+  QgsGrass::setLocation( map->gisdbase.toUtf8().constData(), map->location.toUtf8().constData() );
 
   // Set current mapset (mapset was previously checked by isGrassEditable() )
   // TODO: Should be done better / in other place ?
   // TODO: Is it necessary for build/close ?
-  G__setenv(( char * ) "MAPSET", map->mapset.toAscii().data() );
+  G__setenv(( char * ) "MAPSET", map->mapset.toUtf8().data() );
 
 #if defined(GRASS_VERSION_MAJOR) && defined(GRASS_VERSION_MINOR) && \
     ( ( GRASS_VERSION_MAJOR == 6 && GRASS_VERSION_MINOR >= 4 ) || GRASS_VERSION_MAJOR > 6 )
@@ -1588,14 +1604,15 @@
   map->lastAttributesModified = di.lastModified();
 
   // Reopen vector
-  QgsGrass::resetError(); // to "catch" error after Vect_open_old()
-  Vect_set_open_level( 2 );
-
-  Vect_open_old( map->map, map->mapName.toAscii().data(), map->mapset.toAscii().data() );
-
-  if ( QgsGrass::getError() == QgsGrass::FATAL )
+  try
   {
-    QgsDebugMsg( QString( "Cannot reopen GRASS vector: %1" ).arg( QgsGrass::getErrorMessage() ) );
+    Vect_set_open_level( 2 );
+    Vect_open_old( map->map, map->mapName.toUtf8().data(), map->mapset.toUtf8().data() );
+  }
+  catch ( QgsGrass::Exception &e )
+  {
+    Q_UNUSED( e );
+    QgsDebugMsg( QString( "Cannot reopen GRASS vector: %1" ).arg( e.what() ) );
     return false;
   }
 
@@ -1828,7 +1845,7 @@
     return key;
   }
 
-  *key = QString::fromAscii( fi->key );
+  *key = QString::fromUtf8( fi->key );
   return key;
 }
 
@@ -1937,7 +1954,7 @@
   db_init_string( &dbstr );
   QString query;
   query.sprintf( "select * from %s where %s = %d", fi->table, fi->key, cat );
-  db_set_string( &dbstr, query.toAscii().data() );
+  db_set_string( &dbstr, query.toUtf8().data() );
 
   QgsDebugMsg( QString( "SQL: %1" ).arg( db_get_string( &dbstr ) ) );
 
@@ -2010,7 +2027,7 @@
   if ( driver == NULL )
   {
     QgsDebugMsg( QString( "Cannot open database %1 by driver %2" ).arg( fi->database ).arg( fi->driver ) );
-    *error = QString::fromAscii( "Cannot open database" );
+    *error = QString::fromUtf8( "Cannot open database" );
     return error;
   }
 
@@ -2030,7 +2047,7 @@
   //  -> it is possible to edit only in current locales at present
   // QCString qcs = mEncoding->fromUnicode(query);
 
-  QByteArray qcs = query.toLocal8Bit();
+  QByteArray qcs = query.toUtf8();
   QgsDebugMsg( QString( "qcs: %1" ).arg( qcs.data() ) );
 
   char *cs = new char[qcs.length() + 1];
@@ -2095,7 +2112,7 @@
   if ( driver == NULL )
   {
     QgsDebugMsg( QString( "Cannot open database %1 by driver %2" ).arg( fi->database ).arg( fi->driver ) );
-    *error = QString::fromAscii( "Cannot open database" );
+    *error = QString::fromUtf8( "Cannot open database" );
     return error;
   }
 
@@ -2157,7 +2174,7 @@
   if ( driver == NULL )
   {
     QgsDebugMsg( QString( "Cannot open database %1 by driver %2" ).arg( fi->database ).arg( fi->driver ) );
-    *error = QString::fromAscii( "Cannot open database" );
+    *error = QString::fromUtf8( "Cannot open database" );
     return error;
   }
 
@@ -2306,7 +2323,7 @@
   if ( driver == NULL )
   {
     QgsDebugMsg( QString( "Cannot open database %1 by driver %2" ).arg( fi->database ).arg( fi->driver ) );
-    *error = QString::fromAscii( "Cannot open database" );
+    *error = QString::fromUtf8( "Cannot open database" );
     return error;
   }
 



More information about the QGIS-commit mailing list