コード例 #1
0
ファイル: JNIUtil.cpp プロジェクト: Ranga123/test1
/**
 * Initialite the log file.
 * @param level the log level
 * @param the name of the log file
 */
void JNIUtil::initLogFile(int level, jstring path)
{
  // lock this operation
  JNICriticalSection cs(*g_logMutex);
  if (g_logLevel > noLog) // if the log file has been opened
    g_logStream.close();

  // remember the log level
  g_logLevel = level;
  JNIStringHolder myPath(path);
  if (g_logLevel > noLog) // if a new log file is needed
    {
      // open it
      g_logStream.open(myPath, std::ios::app);
    }
}
コード例 #2
0
ファイル: GLBufferAdapter.cpp プロジェクト: artcom/y60
    void
    BufferToFile::performAction(GLSourceBuffer theSourceBuffer)
    {
        {
            MAKE_SCOPE_TIMER(BufferAdapter_glReadPixels);
            BufferAdapter::performAction(theSourceBuffer);
        }
        Path myPath(_myFilename, UTF8);
        boost::shared_ptr<PLAnyBmp> myBmp;
        PixelEncoding myEncoding;

        switch(getComponents()) {
          case 1:
              if (_myFormat == PL_FT_JPEG) {
                  throw GLBufferAdapterException(std::string("unsupported pixel format 'gray' for jpeg encoding"), PLUS_FILE_LINE);
              }
              myEncoding = GRAY;
              break;
          case 3:
              myEncoding = RGB;
              break;
          case 4:
          default:
              myEncoding = RGBA;
              break;
        }

        PLPixelFormat pf;
        if (!mapPixelEncodingToFormat(myEncoding, pf)) {
            throw GLBufferAdapterException(std::string("unsupported pixel format"), PLUS_FILE_LINE);
        }
        {
            MAKE_SCOPE_TIMER(GLBufferAdapter_createBMP);
            myBmp = boost::shared_ptr<PLAnyBmp>(new PLAnyBmp());
            myBmp->Create( getWidth(), getHeight(), pf,
                          getBlock().begin() + getWidth() * (getHeight()-1) * getComponents(),
                          -1 * getWidth() * getComponents());
        }

        _myThreadPool.wait(_myThreadPool.size()*2); //allow only threadpool size pending tasks
        _myThreadPool.schedule(boost::bind(&BufferToFile::encodeBuffer, this,
                                           myPath.toLocale(), _myFormat, _myCompressionOrQualityLevel, myBmp));
    }
コード例 #3
0
DirItemInfo * DiskLocation::validateUrlPath(const QString& uPath)
{
    QString myPath(uPath);
    QFileInfo tmpUrl(uPath);
    if (tmpUrl.isRelative() && m_info)
    {
        tmpUrl.setFile(m_info->absoluteFilePath(), uPath);
        myPath  =  tmpUrl.absoluteFilePath();
    }
#if DEBUG_MESSAGES
    qDebug() << Q_FUNC_INFO << "path:" << myPath;
#endif
    DirItemInfo * item = new DirItemInfo(myPath);
    if (!item->isValid() || !item->exists() || !item->isContentReadable())
    {
        delete item;
        item = 0;
    }
    return item;
}
コード例 #4
0
ファイル: main.cpp プロジェクト: cyclingzealot/Quantum-GIS
int main( int argc, char *argv[] )
{
#ifdef WIN32  // Windows
#ifdef _MSC_VER
  _set_fmode( _O_BINARY );
#else //MinGW
  _fmode = _O_BINARY;
#endif  // _MSC_VER
#endif  // WIN32

  /////////////////////////////////////////////////////////////////
  // Command line options 'behaviour' flag setup
  ////////////////////////////////////////////////////////////////

  //
  // Parse the command line arguments, looking to see if the user has asked for any
  // special behaviours. Any remaining non command arguments will be kept aside to
  // be passed as a list of layers and / or a project that should be loaded.
  //

  int myIterations = 1;
  QString mySnapshotFileName = "";
  QString myLogFileName = "";
  QString myPrefixPath = "";
  int mySnapshotWidth = 800;
  int mySnapshotHeight = 600;
  QString myQuality = "";

  // This behaviour will set initial extent of map canvas, but only if
  // there are no command line arguments. This gives a usable map
  // extent when qgis starts with no layers loaded. When layers are
  // loaded, we let the layers define the initial extent.
  QString myInitialExtent = "";
  if ( argc == 1 )
    myInitialExtent = "-1,-1,1,1";

  // The user can specify a path which will override the default path of custom
  // user settings (~/.qgis) and it will be used for QSettings INI file
  QString configpath;

#ifndef WIN32
  ////////////////////////////////////////////////////////////////
  // USe the GNU Getopts utility to parse cli arguments
  // Invokes ctor `GetOpt (int argc, char **argv,  char *optstring);'
  ///////////////////////////////////////////////////////////////
  int optionChar;
  while ( 1 )
  {
    static struct option long_options[] =
    {
      /* These options set a flag. */
      {"help", no_argument, 0, '?'},
      /* These options don't set a flag.
       *  We distinguish them by their indices. */
      {"iterations",    required_argument, 0, 'i'},
      {"snapshot", required_argument, 0, 's'},
      {"log", required_argument, 0, 'l'},
      {"width",    required_argument, 0, 'w'},
      {"height",   required_argument, 0, 'h'},
      {"project",  required_argument, 0, 'p'},
      {"extent",   required_argument, 0, 'e'},
      {"optionspath", required_argument, 0, 'o'},
      {"configpath", required_argument, 0, 'c'},
      {"prefix", required_argument, 0, 'r'},
      {"quality", required_argument, 0, 'q'},
      {0, 0, 0, 0}
    };

    /* getopt_long stores the option index here. */
    int option_index = 0;

    optionChar = getopt_long( argc, argv, "islwhpeocrq",
                              long_options, &option_index );

    /* Detect the end of the options. */
    if ( optionChar == -1 )
      break;

    switch ( optionChar )
    {
      case 0:
        /* If this option set a flag, do nothing else now. */
        if ( long_options[option_index].flag != 0 )
          break;
        printf( "option %s", long_options[option_index].name );
        if ( optarg )
          printf( " with arg %s", optarg );
        printf( "\n" );
        break;

      case 'i':
        myIterations = QString( optarg ).toInt();
        break;

      case 's':
        mySnapshotFileName = QDir::convertSeparators( QFileInfo( QFile::decodeName( optarg ) ).absoluteFilePath() );
        break;

      case 'l':
        myLogFileName = QDir::convertSeparators( QFileInfo( QFile::decodeName( optarg ) ).absoluteFilePath() );
        break;

      case 'w':
        mySnapshotWidth = QString( optarg ).toInt();
        break;

      case 'h':
        mySnapshotHeight = QString( optarg ).toInt();
        break;

      case 'p':
        myProjectFileName = QDir::convertSeparators( QFileInfo( QFile::decodeName( optarg ) ).absoluteFilePath() );
        break;

      case 'e':
        myInitialExtent = optarg;
        break;

      case 'o':
        QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, optarg );
        break;

      case 'c':
        configpath = optarg;
        break;

      case 'r':
        myPrefixPath = optarg;
        break;

      case 'q':
        myQuality = optarg;
        break;

      case '?':
        usage( argv[0] );
        return 2;   // XXX need standard exit codes
        break;

      default:
        QgsDebugMsg( QString( "%1: getopt returned character code %2" ).arg( argv[0] ).arg( optionChar ) );
        return 1;   // XXX need standard exit codes
    }
  }

  // Add any remaining args to the file list - we will attempt to load them
  // as layers in the map view further down....
  QgsDebugMsg( QString( "Files specified on command line: %1" ).arg( optind ) );
  if ( optind < argc )
  {
    while ( optind < argc )
    {
#ifdef QGISDEBUG
      int idx = optind;
      QgsDebugMsg( QString( "%1: %2" ).arg( idx ).arg( argv[idx] ) );
#endif
      myFileList.append( QDir::convertSeparators( QFileInfo( QFile::decodeName( argv[optind++] ) ).absoluteFilePath() ) );
    }
  }
#else
  for ( int i = 1; i < argc; i++ )
  {
    QString arg = argv[i];

    if ( arg == "--help" || arg == "-?" )
    {
      usage( argv[0] );
      return 2;
    }
    else if ( i + 1 < argc && ( arg == "--iterations" || arg == "-i" ) )
    {
      myIterations = QString( argv[++i] ).toInt();
    }
    else if ( i + 1 < argc && ( arg == "--snapshot" || arg == "-s" ) )
    {
      mySnapshotFileName = QDir::convertSeparators( QFileInfo( QFile::decodeName( argv[++i] ) ).absoluteFilePath() );
    }
    else if ( i + 1 < argc && ( arg == "--log" || arg == "-l" ) )
    {
      myLogFileName = QDir::convertSeparators( QFileInfo( QFile::decodeName( argv[++i] ) ).absoluteFilePath() );
    }
    else if ( i + 1 < argc && ( arg == "--width" || arg == "-w" ) )
    {
      mySnapshotWidth = QString( argv[++i] ).toInt();
    }
    else if ( i + 1 < argc && ( arg == "--height" || arg == "-h" ) )
    {
      mySnapshotHeight = QString( argv[++i] ).toInt();
    }
    else if ( i + 1 < argc && ( arg == "--project" || arg == "-p" ) )
    {
      myProjectFileName = QDir::convertSeparators( QFileInfo( QFile::decodeName( argv[++i] ) ).absoluteFilePath() );
    }
    else if ( i + 1 < argc && ( arg == "--extent" || arg == "-e" ) )
    {
      myInitialExtent = argv[++i];
    }
    else if ( i + 1 < argc && ( arg == "--optionspath" || arg == "-o" ) )
    {
      QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, argv[++i] );
    }
    else if ( i + 1 < argc && ( arg == "--configpath" || arg == "-c" ) )
    {
      configpath = argv[++i];
      QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, configpath );
    }
    else if ( i + 1 < argc && ( arg == "--prefix" ) )
    {
      myPrefixPath = argv[++i];
    }
    else if ( i + 1 < argc && ( arg == "--quality" || arg == "-q" ) )
    {
      myQuality = argv[++i];
    }
    else
    {
      myFileList.append( QDir::convertSeparators( QFileInfo( QFile::decodeName( argv[i] ) ).absoluteFilePath() ) );
    }
  }
#endif //WIN32

  /////////////////////////////////////////////////////////////////////
  // Now we have the handlers for the different behaviours...
  ////////////////////////////////////////////////////////////////////

  /////////////////////////////////////////////////////////////////////
  // Initialise the application and the translation stuff
  /////////////////////////////////////////////////////////////////////

  if ( !configpath.isEmpty() )
  {
    // tell QSettings to use INI format and save the file in custom config path
    QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, configpath );
  }

  // TODO: Qt: there should be exactly one QCoreApplication object for console app.
  // but QgsApplication inherits from QApplication (GUI)
  // it is working, but maybe we should make QgsCoreApplication, which
  // could also be used by mapserver
  // Note (mkuhn,20.4.2013): Labeling does not work with QCoreApplication, because
  // fontconfig needs some X11 dependencies which are initialized in QApplication (GUI)
  // using it with QCoreApplication only crashes at the moment.
  // Only use QgsApplication( int, char **, bool GUIenabled, QString) for newer versions
  // so that this program may be run with old libraries
  //QgsApplication myApp( argc, argv, false, configpath );

  QCoreApplication *myApp;

#if VERSION_INT >= 10900
  myApp = new QgsApplication( argc, argv, false );
#else
  myApp = new QCoreApplication( argc, argv );
#endif

  if ( myPrefixPath.isEmpty() )
  {
    QDir dir( QCoreApplication::applicationDirPath() );
    dir.cdUp();
    myPrefixPath = dir.absolutePath();
  }
  QgsApplication::setPrefixPath( myPrefixPath, true );

  // Set up the QSettings environment must be done after qapp is created
  QgsApplication::setOrganizationName( "QuantumGIS" );
  QgsApplication::setOrganizationDomain( "qgis.org" );
  QgsApplication::setApplicationName( "QGIS2" );

  QgsProviderRegistry::instance( QgsApplication::pluginPath() );

#ifdef Q_OS_MACX
  // If the GDAL plugins are bundled with the application and GDAL_DRIVER_PATH
  // is not already defined, use the GDAL plugins in the application bundle.
  QString gdalPlugins( QCoreApplication::applicationDirPath().append( "/lib/gdalplugins" ) );
  if ( QFile::exists( gdalPlugins ) && !getenv( "GDAL_DRIVER_PATH" ) )
  {
    setenv( "GDAL_DRIVER_PATH", gdalPlugins.toUtf8(), 1 );
  }
#endif

  QSettings mySettings;

  // For non static builds on mac and win (static builds are not supported)
  // we need to be sure we can find the qt image
  // plugins. In mac be sure to look in the
  // application bundle...
#ifdef Q_WS_WIN
  QCoreApplication::addLibraryPath( QApplication::applicationDirPath()
                                    + QDir::separator() + "qtplugins" );
#endif
#ifdef Q_OS_MACX
  //qDebug("Adding qt image plugins to plugin search path...");
  CFURLRef myBundleRef = CFBundleCopyBundleURL( CFBundleGetMainBundle() );
  CFStringRef myMacPath = CFURLCopyFileSystemPath( myBundleRef, kCFURLPOSIXPathStyle );
  const char *mypPathPtr = CFStringGetCStringPtr( myMacPath, CFStringGetSystemEncoding() );
  CFRelease( myBundleRef );
  CFRelease( myMacPath );
  QString myPath( mypPathPtr );
  // if we are not in a bundle assume that the app is built
  // as a non bundle app and that image plugins will be
  // in system Qt frameworks. If the app is a bundle
  // lets try to set the qt plugin search path...
  QFileInfo myInfo( myPath );
  if ( myInfo.isBundle() )
  {
    // First clear the plugin search paths so we can be sure
    // only plugins from the bundle are being used
    QStringList myPathList;
    QCoreApplication::setLibraryPaths( myPathList );
    // Now set the paths inside the bundle
    myPath += "/Contents/plugins";
    QCoreApplication::addLibraryPath( myPath );
  }
#endif

  QgsBench *qbench = new QgsBench( mySnapshotWidth, mySnapshotHeight, myIterations );

  /////////////////////////////////////////////////////////////////////
  // 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 = QDir::convertSeparators( QFileInfo( QFile::decodeName( argv[i] ) ).absoluteFilePath() );
      if ( arg.contains( ".qgs" ) )
      {
        myProjectFileName = arg;
        break;
      }
    }
  }

  /////////////////////////////////////////////////////////////////////
  // Load a project file if one was specified
  /////////////////////////////////////////////////////////////////////
  if ( ! myProjectFileName.isEmpty() )
  {
    if ( ! qbench->openProject( myProjectFileName ) )
    {
      fprintf( stderr, "Cannot load project\n" );
      return 1;
    }
  }

  if ( ! myQuality.isEmpty() )
  {
    QPainter::RenderHints hints;
    QStringList list = myQuality.split( ',' );
    foreach ( QString q, list )
    {
      if ( q == "Antialiasing" ) hints |= QPainter::Antialiasing;
      else if ( q == "TextAntialiasing" ) hints |= QPainter::TextAntialiasing;
      else if ( q == "SmoothPixmapTransform" ) hints |= QPainter::SmoothPixmapTransform;
      else if ( q == "NonCosmeticDefaultPen" ) hints |= QPainter::NonCosmeticDefaultPen;
      else
      {
        fprintf( stderr, "Unknown quality option\n" );
        return 1;
      }
    }
    QgsDebugMsg( QString( "hints: %1" ).arg( hints ) );
    qbench->setRenderHints( hints );
  }
コード例 #5
0
ファイル: main.cpp プロジェクト: sjau/Mameri
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    // Load path to the mysql settings file
    QSettings myPath("Mameri", "mameri");
    myPath.beginGroup("MySQLPath");
    QString myLocation = myPath.value("location").toString();
    myPath.endGroup();

    QFileInfo myIni(myLocation);
    if(!myIni.isFile())
    {
        // Run install wizard
        installWizard wizard;
        wizard.exec();
    }
    // Load MySQL Settings
    QSettings myDBSettings(myLocation, QSettings::IniFormat);
    myDBSettings.beginGroup("MySQL");
    QString myHostname  = myDBSettings.value("hostname").toString();
    int myPort          = myDBSettings.value("port").toInt();
    QString myDbname    = myDBSettings.value("dbname").toString();
    QString myUsername  = myDBSettings.value("username").toString();
    QString myPassword  = myDBSettings.value("password").toString();
    myDBSettings.endGroup();

    // Connect to DB
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName(myHostname);
    db.setPort(myPort);
    db.setDatabaseName(myDbname);
    db.setUserName(myUsername);
    db.setPassword(myPassword);

    db.setConnectOptions();

    if(db.open())   {
        // User Login
        bool isValid = false;
        qApp->setProperty("isValid", isValid);

        loginForm loginFormObj;
        loginFormObj.setModal(true);
        int cancelLogin = loginFormObj.exec();
        // Kill process if cancel was used
        if(cancelLogin == 0) return 0;

        qDebug() << "Valid User? " << qApp->property("isValid");
        qDebug() << "User ID? " << qApp->property("userId");
        // Start main application window
    } else
    {
        qDebug() << "Couldn't connect to DB:" << db.lastError().text();
        qApp->quit();
    }
    mainWindow w;
    w.show();

    return a.exec();
}
コード例 #6
0
DirItemInfo * TrashLocation::validateUrlPath(const QString& urlPath)
{
     TrashItemInfo *item  =  0;
     QString  myPath(urlPath);

    //first void any relative path when is root
    if (m_info  && m_info->isRoot() && myPath.startsWith(QLatin1String("..")))
    {
        return item;
    }

    int firstSlash       = -1;

    // handle relative paths to the current
    if (!myPath.startsWith(LocationUrl::TrashRootURL) && m_info)
    {
        QFileInfo f;
        f.setFile(m_info->absoluteFilePath(), myPath);
        if (f.exists() && f.isDir())
        {
            TrashItemInfo *trashItem = static_cast<TrashItemInfo*> (m_info);
            item = new TrashItemInfo(trashItem->getTrashDir(), f.canonicalFilePath());
#if DEBUG_MESSAGES
            qDebug() << Q_FUNC_INFO << "cur path:" << m_info->absoluteFilePath()
                     << " new path:"  << item->absoluteFilePath()
                     << "url:"   << item->urlPath();
#endif
        }
        else
        {
           myPath = LocationUrl::TrashRootURL + urlPath;
        }
    }
    else
    {
        item  = new TrashItemInfo(myPath);
        if (!item->isRoot())
        {
            delete item;
            item = 0;
        }
    }

    //Not Relative, handle absolute path but it is not root
    if (item == 0)
    {       
        QString absTrashItem;
        QString trashItemFromRoot = myPath.mid(LocationUrl::TrashRootURL.size());
        foreach(const QString& trashRoot, allTrashes())
        {
            //this is the full path of the item, it does not mean it is a Trash top level item
            //example: trash:///Dir1/Dir2/Dir3  may be in /home/user/.local/share/Trash//Dir1/Dir2/Dir3
            absTrashItem = QTrashUtilInfo::filesTrashDir(trashRoot) + QDir::separator() + trashItemFromRoot;
            const QFileInfo info(absTrashItem);
            if (info.exists())
            {
                //check top level trash item
                firstSlash = trashItemFromRoot.indexOf(QDir::separator());
                QString toplevelDir = firstSlash != -1 ? trashItemFromRoot.left(firstSlash)
                                                       : trashItemFromRoot;

                QTrashUtilInfo topLevelTrashDirInfo;
                topLevelTrashDirInfo.setInfo(trashRoot, toplevelDir);
#if DEBUG_MESSAGES
                    qDebug() << Q_FUNC_INFO
                             <<  topLevelTrashDirInfo.absFile << "exists" << topLevelTrashDirInfo.existsFile()
                             <<  topLevelTrashDirInfo.absInfo << "exists" << topLevelTrashDirInfo.existsInfoFile();
#endif
                //check if a .trashinfo file for toplevel dir exists
                if (topLevelTrashDirInfo.existsInfoFile())
                {
                    item = new TrashItemInfo(QTrashUtilInfo::filesTrashDir(trashRoot), absTrashItem);
                    break;
                }
            }
        }