예제 #1
0
int openFile( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo )
{
	PtArg_t args[1];
	int *fileFlag;
	char *fileName;

	/* eliminate 'unreferenced' warnings */
	widget = widget, apinfo = apinfo, cbinfo = cbinfo;

	/* get the type of file to open */
	PtSetArg(&args[0], Pt_ARG_USER_DATA, &fileFlag, sizeof(int));
	PtGetResources(widget, 1, args);

	/* get the file name from the text widget */
	PtSetArg(&args[0], Pt_ARG_TEXT_STRING, &fileName, 0);
	PtGetResources(ABW_fileSelFileName, 1, args);

	switch(*fileFlag) {
	case ROOT_FILE_READ:
		readRoot(fileName);

		/* save the name of the root file in the proc table for rex session */
		strncpy(myptp->p_root, fileName, P_LROOTNAME);
		break;
	case ROOT_FILE_WRITE:
		writeRoot(fileName);

		/* save the name of the root file in the proc table for rex session */
		strncpy(myptp->p_root, fileName, P_LROOTNAME);
		break;
	case RASTER_FILE_SAVE:
		saveRaster(fileName);
	default:
		break;
	}
	return( Pt_CONTINUE );
}
예제 #2
0
bool QgsOSMXmlImport::import()
{
  mError.clear();

  // open input
  mInputFile.setFileName( mXmlFileName );
  if ( !mInputFile.open( QIODevice::ReadOnly ) )
  {
    mError = QString( "Cannot open input file: %1" ).arg( mXmlFileName );
    return false;
  }

  // open output

  if ( QFile::exists( mDbFileName ) )
  {
    if ( !QFile( mDbFileName ).remove() )
    {
      mError = QString( "Database file cannot be overwritten: %1" ).arg( mDbFileName );
      return false;
    }
  }

  if ( !createDatabase() )
  {
    // mError is set in createDatabase()
    return false;
  }

  qDebug( "starting import" );

  int retX = sqlite3_exec( mDatabase, "BEGIN", NULL, NULL, 0 );
  Q_ASSERT( retX == SQLITE_OK );
  Q_UNUSED( retX );

  // start parsing

  QXmlStreamReader xml( &mInputFile );

  while ( !xml.atEnd() )
  {
    xml.readNext();

    if ( xml.isEndDocument() )
      break;

    if ( xml.isStartElement() )
    {
      if ( xml.name() == "osm" )
        readRoot( xml );
      else
        xml.raiseError( "Invalid root tag" );
    }
  }

  int retY = sqlite3_exec( mDatabase, "COMMIT", NULL, NULL, 0 );
  Q_ASSERT( retY == SQLITE_OK );
  Q_UNUSED( retY );

  createIndexes();

  if ( xml.hasError() )
  {
    mError = QString( "XML error: %1" ).arg( xml.errorString() );
    return false;
  }

  closeDatabase();

  return true;
}