void MainWindow::closeEvent(QCloseEvent *event) { if(opt.arg_debug) printf("MainWindow::closeEvent()\n"); if(opt.exitpassword == 1) { bool ok; QString pass = QInputDialog::getText(this,tr("pvbrowser"),tr("Exit Password ?"),QLineEdit::Password,QString::null,&ok); if( ok && !pass.isEmpty() ) { // user entered something and pressed OK FILE *fp; fp = fopen(passfile(),"r"); if(fp == NULL) { fp = fopen(passfile(),"w"); if(fp != NULL) { fprintf(fp,"%s\n",pvpass(pass.toUtf8())); fclose(fp); } opt.exitpassword = 0; slotExit(); event->accept(); } else { const char *cptr; char buf[1024]; cptr = fgets(buf,sizeof(buf)-1,fp); fclose(fp); if(cptr != NULL && strncmp(buf,pvpass(pass.toUtf8()),strlen(buf)-1) != 0) { QMessageBox::information(this,"pvbrowser","Wrong Password",1); event->ignore(); } else { slotExit(); event->accept(); } } } else { event->ignore(); } } else { slotExit(); event->accept(); } }
void QgsApplication::init( QString customConfigPath ) { if ( customConfigPath.isEmpty() ) { if ( getenv( "QGIS_CUSTOM_CONFIG_PATH" ) ) { customConfigPath = getenv( "QGIS_CUSTOM_CONFIG_PATH" ); } else { customConfigPath = QStringLiteral( "%1/.qgis3/" ).arg( QDir::homePath() ); } } qRegisterMetaType<QgsGeometry::Error>( "QgsGeometry::Error" ); qRegisterMetaType<QgsProcessingFeatureSourceDefinition>( "QgsProcessingFeatureSourceDefinition" ); qRegisterMetaType<QgsProcessingOutputLayerDefinition>( "QgsProcessingOutputLayerDefinition" ); QString prefixPath( getenv( "QGIS_PREFIX_PATH" ) ? getenv( "QGIS_PREFIX_PATH" ) : applicationDirPath() ); // QgsDebugMsg( QString( "prefixPath(): %1" ).arg( prefixPath ) ); // check if QGIS is run from build directory (not the install directory) QFile f; // "/../../.." is for Mac bundled app in build directory Q_FOREACH ( const QString &path, QStringList() << "" << "/.." << "/bin" << "/../../.." ) { f.setFileName( prefixPath + path + "/qgisbuildpath.txt" ); if ( f.exists() ) break; } if ( f.exists() && f.open( QIODevice::ReadOnly ) ) { ABISYM( mRunningFromBuildDir ) = true; ABISYM( mBuildSourcePath ) = f.readLine().trimmed(); ABISYM( mBuildOutputPath ) = f.readLine().trimmed(); qDebug( "Running from build directory!" ); qDebug( "- source directory: %s", ABISYM( mBuildSourcePath ).toUtf8().data() ); qDebug( "- output directory of the build: %s", ABISYM( mBuildOutputPath ).toUtf8().data() ); #ifdef _MSC_VER ABISYM( mCfgIntDir ) = prefixPath.split( '/', QString::SkipEmptyParts ).last(); qDebug( "- cfg: %s", ABISYM( mCfgIntDir ).toUtf8().data() ); #endif } if ( ABISYM( mRunningFromBuildDir ) ) { // we run from source directory - not installed to destination (specified prefix) ABISYM( mPrefixPath ) = QString(); // set invalid path #if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA) setPluginPath( ABISYM( mBuildOutputPath ) + '/' + QString( QGIS_PLUGIN_SUBDIR ) + '/' + ABISYM( mCfgIntDir ) ); #else setPluginPath( ABISYM( mBuildOutputPath ) + '/' + QStringLiteral( QGIS_PLUGIN_SUBDIR ) ); #endif setPkgDataPath( ABISYM( mBuildSourcePath ) ); // directly source path - used for: doc, resources, svg ABISYM( mLibraryPath ) = ABISYM( mBuildOutputPath ) + '/' + QGIS_LIB_SUBDIR + '/'; #if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA) ABISYM( mLibexecPath ) = ABISYM( mBuildOutputPath ) + '/' + QGIS_LIBEXEC_SUBDIR + '/' + ABISYM( mCfgIntDir ) + '/'; #else ABISYM( mLibexecPath ) = ABISYM( mBuildOutputPath ) + '/' + QGIS_LIBEXEC_SUBDIR + '/'; #endif } else { char *prefixPath = getenv( "QGIS_PREFIX_PATH" ); if ( !prefixPath ) { #if defined(Q_OS_MACX) || defined(Q_OS_WIN) setPrefixPath( applicationDirPath(), true ); #elif defined(ANDROID) // this is "/data/data/org.qgis.qgis" in android QDir myDir( QDir::homePath() ); myDir.cdUp(); QString myPrefix = myDir.absolutePath(); setPrefixPath( myPrefix, true ); #else QDir myDir( applicationDirPath() ); myDir.cdUp(); QString myPrefix = myDir.absolutePath(); setPrefixPath( myPrefix, true ); #endif } else { setPrefixPath( prefixPath, true ); } } if ( !customConfigPath.isEmpty() ) { ABISYM( mConfigPath ) = customConfigPath + '/'; // make sure trailing slash is included } ABISYM( mDefaultSvgPaths ) << qgisSettingsDirPath() + QStringLiteral( "svg/" ); ABISYM( mAuthDbDirPath ) = qgisSettingsDirPath(); if ( getenv( "QGIS_AUTH_DB_DIR_PATH" ) ) { setAuthDatabaseDirPath( getenv( "QGIS_AUTH_DB_DIR_PATH" ) ); } // store system environment variables passed to application, before they are adjusted QMap<QString, QString> systemEnvVarMap; QString passfile( QStringLiteral( "QGIS_AUTH_PASSWORD_FILE" ) ); // QString, for comparison Q_FOREACH ( const QString &varStr, QProcess::systemEnvironment() ) { int pos = varStr.indexOf( QLatin1Char( '=' ) ); if ( pos == -1 ) continue; QString varStrName = varStr.left( pos ); QString varStrValue = varStr.mid( pos + 1 ); if ( varStrName != passfile ) { systemEnvVarMap.insert( varStrName, varStrValue ); } }