예제 #1
0
  QString ResourceLocator::unique(const QString& src, const QSet<QString>& lst)
  {
    QFileInfo fi(src);
    QString start = fi.path() + "/" + fi.baseName();
    QString suffix = fi.completeSuffix().isEmpty() ? "" : "." + fi.completeSuffix();

    QString file = src;
    QFileInfo fi2(file);
    int i = -1;
    while (QFile::exists(file) || lst.contains(fi2.absoluteFilePath())) {
      if (i == -1) {
        QRegExp re("(\\d+)$");
        int p = re.indexIn(start);
        if (p >= 0) {
          start = start.left(p);
          i = re.cap(1).toInt() + 1;
        } else {
          i = 1;
        }
      }

      file = start + QString::number(i++) + suffix;
      fi2.setFile(file);
    }

    return file;
  }
예제 #2
0
파일: p8.cpp 프로젝트: 5432935/crossbridge
void foo2() {
  ADL::Outer o;
  ADL::Inner i;
  fo(o);
  fi(i);
  fi2(i);
}
예제 #3
0
// Compare images:
bool KOFilter::imageCompare(const QString &dir1File, const QString &dir2File)
{
    // Check src file:
    QFileInfo fi1(dir1File);

    // Check dst file:
    QFileInfo fi2(dir2File);

    // Check files:
    if (!fi1.exists() || !fi2.exists())
        return false;

    QImage img1(dir1File);
    QImage img2(dir2File);
    if (img1.size() != img2.size())
        return false;

    for (int j=0; j<img1.height(); j++)
        for (int i=0; i<img1.width(); i++)
        {
            QRgb color1 = img1.pixel(i, j);
            QRgb color2 = img2.pixel(i, j);
            if (color1 != color2)
                return false;
        }

    return true;
}
예제 #4
0
// Restituisce l'header da inviare per il prossimo elemento
// da tramsettere
QByteArray DuktoProtocol::nextElementHeader()
{
    QByteArray header;

    // Ricava il nome del file (se non è l'ultimo)
    if (mFilesToSend->size() == mFileCounter) return header;
    QString fullname = mFilesToSend->at(mFileCounter++);

    // Chiusura file precedente, se non è già stato chiuso
    if (mCurrentFile) {
        mCurrentFile->close();
        delete mCurrentFile;
        mCurrentFile = NULL;
    }

    // Verifico se si tratta di un invio testo
    if (fullname == "___DUKTO___TEXT___") {
		#if QT_VERSION < 0x050000
        header.append(fullname.toAscii() + '\0');
        #else
        header.append(fullname + '\0');
        #endif
        qint64 size = mTextToSend.toUtf8().length();
        header.append((char*) &size, sizeof(size));
        return header;
    }

    // Nome elemento
    QString name;

    // Verifico se si tratta di un invio screen
    if (mSendingScreen) {

        name = "Screenshot.jpg";
        mSendingScreen = false;
    }
    else
        name = fullname;

    // Aggiunta nome file all'header
    name.replace(mBasePath + "/", "");
    header.append(name.toUtf8() + '\0');

    // Dimensione elemento
    qint64 size = -1;
    QFileInfo fi2(fullname);
    if (fi2.isFile()) size = fi2.size();
    header.append((char*) &size, sizeof(size));

    // Apertura file
    if (size > -1) {
        mCurrentFile = new QFile(fullname);
        mCurrentFile->open(QIODevice::ReadOnly);
    }

    return header;
}
예제 #5
0
파일: applnk.cpp 프로젝트: opieproject/opie
void DocLnkSet::findChildren(const QString &dr, const QValueList<QRegExp> &mimeFilters, QDict<void> &reference, int depth)
{
    depth++;
    if ( depth > 10 )
  return;

    QDir dir( dr );

    /* Opie got a different approach
     * I guess it's geek vs. consumer
     * in this case to be discussed
     */
    if ( dir.exists( ".Qtopia-ignore" ) )
  return;

    const QFileInfoList *list = dir.entryInfoList();
    if ( list ) {
  QFileInfo* fi;
  for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) {
      QString bn = fi->fileName();
      if ( bn[0] != '.' ) {
    if ( fi->isDir()  ) {
        if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" )
      findChildren(fi->filePath(), mimeFilters, reference, depth);
    } else {
        if ( fi->extension(FALSE) == "desktop" ) {
      DocLnk* dl = new DocLnk( fi->filePath() );
      QFileInfo fi2(dl->file());
      bool match = FALSE;
      if ( !fi2.exists() ) {
          dir.remove( dl->file() );
      }
      if ( mimeFilters.count() == 0 ) {
          add( dl );
          match = TRUE;
      } else {
          for( QValueList<QRegExp>::ConstIterator it = mimeFilters.begin(); it != mimeFilters.end(); ++ it ) {
        if ( (*it).match(dl->type()) >= 0 ) {
            add(dl);
            match = TRUE;
        }
          }
      }
      if ( !match )
          delete dl;
        } else {
      if ( !reference.find(fi->fileName()) )
          reference.insert(fi->filePath(), (void*)2);
        }
    }
      }
  }
    }
}
예제 #6
0
void test_store_value_from_thread()
{
    boost::promise<int> pi2;
    boost::unique_future<int> fi2(pi2.get_future());
    boost::thread(set_promise_thread,&pi2);
    int j=fi2.get();
    BOOST_CHECK(j==42);
    BOOST_CHECK(fi2.is_ready());
    BOOST_CHECK(fi2.has_value());
    BOOST_CHECK(!fi2.has_exception());
    BOOST_CHECK(fi2.get_state()==boost::future_state::ready);
}
예제 #7
0
void Controls::on_actionSave_QML_triggered()
{
    QString modelFileName = m_model->fullPath();
    QFileInfo fi(modelFileName);
    QString qmlName = fi.baseName();
    qmlName = qmlName.mid(1).prepend(qmlName[0].toUpper()) + ".qml";
    QString path = fi.absoluteDir().absoluteFilePath(qmlName);
    QFileDialog::Options options = 0;
#ifdef Q_OS_LINUX
    // work around data loss bug with KDE: https://bugs.kde.org/show_bug.cgi?id=210904
    options = QFileDialog::DontUseNativeDialog;
#endif
    QString file = QFileDialog::getSaveFileName(this, tr("Save QML file"), path,
                                                tr("QML files (*.qml)"), 0, options);
    if (!file.isEmpty())
    {
        QFileInfo fi2(file);
        QDir d = fi2.absoluteDir();
        QString relName = d.relativeFilePath(modelFileName);
        QString n2 = fi2.baseName();
        n2 = n2.mid(1).prepend((n2[0].toUpper())) + ".qml";
        file = fi2.absolutePath() + "/" + n2;
        QmlGenerator gen(file);
        gen.setProperty("modelFileName", relName);
        saveSettings(modelFileName);
        QString options = m_model->getOptions();
        if (!options.isEmpty())
            gen.setProperty("options", options);
        QVector3D p = m_view->position();
        if (!qFuzzyIsNull(p.x()))
            gen.setProperty("x_translation", QString::number(p.x()));
        if (!qFuzzyIsNull(p.y()))
            gen.setProperty("y_translation", QString::number(p.y()));
        if (!qFuzzyIsNull(p.z()))
            gen.setProperty("z_translation", QString::number(p.z()));
        QVector3D o = m_view->orientation();
        if (!qFuzzyIsNull(o.x()))
            gen.setProperty("x_rotation", QString::number(o.x()));
        if (!qFuzzyIsNull(o.y()))
            gen.setProperty("y_rotation", QString::number(o.y()));
        if (!qFuzzyIsNull(o.z()))
            gen.setProperty("z_rotation", QString::number(o.z()));
        QVector3D s = m_view->scale();
        if (!qFuzzyIsNull(s.x()))
            gen.setProperty("x_scale", ((s.x() < 0.0f) ? QString::number(1.0f / qAbs(s.x())) : QString::number(s.x())));
        if (!qFuzzyIsNull(s.y()))
            gen.setProperty("y_scale", ((s.y() < 0.0f) ? QString::number(1.0f / qAbs(s.y())) : QString::number(s.y())));
        if (!qFuzzyIsNull(s.z()))
            gen.setProperty("z_scale", ((s.z() < 0.0f) ? QString::number(1.0f / qAbs(s.z())) : QString::number(s.z())));
        gen.save();
    }
}
void tst_QFileSystemEntry::suffix()
{
    QFETCH(QString, file);
    QFETCH(QString, expected);

    QFileSystemEntry fe(file);
    QCOMPARE(fe.suffix(), expected);

    QFileSystemEntry fi2(file);
    // first resolve the last slash
    (void) fi2.path();
    QCOMPARE(fi2.suffix(), expected);
}
void tst_QFileSystemEntry::completeBaseName()
{
    QFETCH(QString, file);
    QFETCH(QString, expected);

    QFileSystemEntry fi(file);
    QCOMPARE(fi.completeBaseName(), expected);

    QFileSystemEntry fi2(file);
    // first resolve the last slash
    (void) fi2.path();
    QCOMPARE(fi2.completeBaseName(), expected);
}
예제 #10
0
void PrefsFile::canWrite()
{
	if (m_ioEnabled)
	{
		QFile f(m_prefsFilePath);
		QFileInfo fi(f);
		if (fi.exists())
			m_ioEnabled = fi.isWritable();
		else
		{
			QFile f2(m_prefsFilePath.left(m_prefsFilePath.lastIndexOf("/")));
			QFileInfo fi2(f2);
			m_ioEnabled = fi2.isWritable();
		}
	}
}
예제 #11
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void writeOutput(bool didReplace, QStringList& outLines, QString filename)
{
  if(didReplace == true)
  {
    QFileInfo fi2(filename);
#if OVERWRITE_SOURCE_FILE
    QFile hOut(filename);
#else
    QString tmpPath = "/tmp/" + fi2.fileName();
    QFile hOut(tmpPath);
#endif
    hOut.open(QFile::WriteOnly);
    QTextStream stream( &hOut );
    stream << outLines.join("\n");
    hOut.close();

    qDebug() << "Saved File " << fi2.absoluteFilePath();
  }
}
예제 #12
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void writeOutput(bool didReplace, QVector<QString>& outLines, QString filename)
{
  if(didReplace == true)
  {
    QFileInfo fi2(filename);
#if OVERWRITE_SOURCE_FILE
    QFile hOut(filename);
#else
    QString tmpPath = "/tmp/" + fi2.fileName();
    QFile hOut(tmpPath);
#endif
    hOut.open(QFile::WriteOnly);
    QTextStream stream( &hOut );
    for(qint32 i = 0; i < outLines.size() - 1; i++)
    {
      stream << outLines[i] << "\n";
    }
    hOut.close();

    qDebug() << "Saved File " << fi2.absoluteFilePath();
  }
}
예제 #13
0
void Yahoo::newStock ()
{
  bool ok = FALSE;
  QString symbols = QInputDialog::getText(tr("New Yahoo Symbols"),
                                          tr("Enter symbols to add. Note: separate symbols with a space"),
				          QLineEdit::Normal,
				          QString::null,
				          &ok,
				          this);
  if (! symbols.length())
    return;

  QStringList l = QStringList::split(" ", symbols, FALSE);

  QString s;
  config.getData(Config::DataPath, s);
  s.append("/Stocks");
  QDir dir(s);
  if (! dir.exists(s))
  {
    if (! dir.mkdir(s))
    {
      qDebug("YahooDialog::newStock: Unable to create %s directory", s.latin1());
      return;
    }
  }

  if (! dir.exists(dataPath))
  {
    if (! dir.mkdir(dataPath))
    {
      qDebug("YahooDialog::newStock: Unable to create %s directory", dataPath.latin1());
      return;
    }
  }

  QStringList n;
  int loop;
  for (loop = 0; loop < (int) l.count(); loop++)
  {
    QString exchange;
    QString s = dataPath + "/";
    QFileInfo fi(l[loop]);

    if (fi.extension(FALSE).length())
    {
      exchange = fi.extension(FALSE).upper();
      s.append(fi.extension(FALSE).upper());
    }
    else
      s.append("US");

    if (! dir.exists(s))
      {
      if (! dir.mkdir(s))
      {
        qDebug("YahooDialog::newStock: Unable to create %s directory", s.latin1());
        continue;
      }
    }
    
    s.append("/");
    s.append(l[loop]);
    if (dir.exists(s))
      continue;

    if (plug.open(s, chartIndex))
    {
      qDebug("YahooDialog::newStock: could not open db %s", s.latin1());
      plug.close();
      continue;
    }

    n.append(s);
    plug.createNewStock();

    QFileInfo fi2(s);
    QString fn = fi2.fileName();
    DBIndexItem item;
    chartIndex->getIndexItem(fn, item);
    getExchange(exchange, s);
    item.setExchange(s);
    chartIndex->setIndexItem(fn, item);

    plug.close();
  }

  list->setFile(n);
  allSymbols->setCheckState(Qt::Unchecked);
  method->setCurrentIndex(0);
  methodChanged(0);
}
예제 #14
0
bool KviApplication::mapImageFile(QString &szRetPath,const QString &filename)
{
	szRetPath = filename;
	// can't map non absolute paths
	if(!KviFileUtils::isAbsolutePath(filename))return false;
	// can't map non existing paths
	if(!KviFileUtils::fileExists(filename))return false;

	QFileInfo fi = QFileInfo(filename);

	unsigned int size = fi.size();

	QString szBestMatch;

	while(szRetPath.indexOf(KVI_PATH_SEPARATOR) != -1)
	{
		KviQString::cutToFirst(szRetPath,KVI_PATH_SEPARATOR);

		if(szRetPath.isEmpty())break;

		QString szBuffer;

		int i;

		for(i=0;i<2;i++)
		{
			getLocalKvircDirectory(szBuffer,pics_localsubdirs[i],szRetPath);
			if(KviFileUtils::fileExists(szBuffer))
			{
				QFileInfo fi2(szBuffer);
				if(size == fi2.size())
				{
					// probably the same file
					szBestMatch = szRetPath;
				}
			}
		}

		for(i=0;i<2;i++)
		{
			getGlobalKvircDirectory(szBuffer,pics_globalsubdirs[i],szRetPath);
			//qDebug("CHECK %s",szBuffer.ptr());
			if(KviFileUtils::fileExists(szBuffer))
			{
				QFileInfo fi2(szBuffer);
				if(size == fi2.size())
				{
					// probably the same file
					szBestMatch = szRetPath;
				}
			}
		}

		// Last resort
		szBuffer = QDir::homePath();
		KviQString::ensureLastCharIs(szBuffer,KVI_PATH_SEPARATOR_CHAR);
		szBuffer.append(szRetPath);
		if(KviFileUtils::fileExists(szBuffer))
		{
			QFileInfo fi2(szBuffer);
			if(size == fi2.size())
			{
				// prolly the same file
				szBestMatch = szRetPath;
			}
		}
	}

	if(!szBestMatch.isEmpty())
	{
		szRetPath = szBestMatch;
		return true;
	}


	// no way to map it :/
	szRetPath = filename;
	return false;
}
예제 #15
0
Task::ReportResult GTest_hmmCompare::report() {

    QFileInfo fi1(env->getVar("COMMON_DATA_DIR")+"/"+file1Name);
    QString url1 = fi1.absoluteFilePath();
    IOAdapterFactory* iof1 = AppContext::getIOAdapterRegistry()->getIOAdapterFactoryById(IOAdapterUtils::url2io(url1));
    QScopedPointer<IOAdapter> io1(iof1->createIOAdapter());
    //QFile file1(fi1.absoluteFilePath());
    QFileInfo fi2(env->getVar("TEMP_DATA_DIR")+"/"+file2Name);
    QString url2 = fi2.absoluteFilePath();
    IOAdapterFactory* iof2 = AppContext::getIOAdapterRegistry()->getIOAdapterFactoryById(IOAdapterUtils::url2io(url2));
    QScopedPointer<IOAdapter> io2(iof2->createIOAdapter());
    fi2.absoluteDir().mkdir(fi2.absoluteDir().absolutePath()); // ???
    //QFile file2(fi2.absoluteFilePath());

    if(!io1->open(url1, IOAdapterMode_Read)){
        stateInfo.setError(  QString("File opening error \"%1\", description: ").arg(url1) );//+file1.errorString() );
        return ReportResult_Finished;
    }
    //file2.open(QIODevice::ReadOnly|QIODevice::Text);
    if(!io2->open(url2, IOAdapterMode_Read)){
        stateInfo.setError(  QString("File opening error \"%1\", description: ").arg(url2) );//+file2.errorString() );
        return ReportResult_Finished;
    }

    static int READ_BUFF_SIZE = 4096;

    qint64 len1, len2, line1 = 0, line2 = 0;
    QByteArray readBuffer1(READ_BUFF_SIZE, '\0'), readBuffer2(READ_BUFF_SIZE, '\0');
    char* cbuff1 = readBuffer1.data();
    char* cbuff2 = readBuffer2.data();
    QRegExp rx("CKSUM ");

    bool ok = false;
    while ( (len1 = io1->readUntil(cbuff1, READ_BUFF_SIZE, TextUtils::LINE_BREAKS, IOAdapter::Term_Include)) > 0 ) {
        line1++;
        if ((ok = rx.indexIn(QString(QByteArray(cbuff1, len1))) !=-1)) {
            break;
        }
    }
    if(!ok){
        stateInfo.setError(  QString("can't find CKSUM in file \"%1\"").arg(url1) );
        return ReportResult_Finished;
    }

    ok = false;
    while ( (len2 = io2->readUntil(cbuff2, READ_BUFF_SIZE, TextUtils::LINE_BREAKS, IOAdapter::Term_Include)) > 0 ) {
        line2++;
        if ((ok = rx.indexIn(QString(QByteArray(cbuff2, len2))) !=-1)) {
            break;
        }
    }
    if(!ok){
        stateInfo.setError(  QString("can't find CKSUM in file \"%1\"").arg(url2) );
        return ReportResult_Finished;
    }

    do{
        len1 = io1->readUntil(cbuff1, READ_BUFF_SIZE, TextUtils::LINE_BREAKS, IOAdapter::Term_Include);
        len2 = io2->readUntil(cbuff2, READ_BUFF_SIZE, TextUtils::LINE_BREAKS, IOAdapter::Term_Include);
        if(len1 == 0 && 0 != len2){
            stateInfo.setError(  QString("hmm-compare: files not equal, desc: files length mismatch") );
            return ReportResult_Finished;
        }
        line1++;line2++;
        QString s1 = QString::fromLatin1(cbuff1, len1).trimmed();
        QString s2 = QString::fromLatin1(cbuff2, len2).trimmed();

        if(s1 != s2)
        {
            stateInfo.setError( QString("hmm-compare: files not equal, desc: file1, line %1 \"%2\", expected file2, line %3 \"%4\"")
                .arg(line1).arg(s1).arg(line2).arg(s2) );
            return ReportResult_Finished;
        }

    } while(len1 > 0);

    return ReportResult_Finished;
}
예제 #16
0
 QString ResourceLocator::rename(const QString& src, const QString& new_base, const QSet<QString>& lst)
 {
   QFileInfo fi(src), fi2(new_base);
   return unique(fi.path() + "/" + fi2.fileName(), lst);
 }
예제 #17
0
void
finalProbComputation()
{
  int i,j;
  for(i = 0 ; i < numGram; i++) for (j = 0 ; j < 4 ; j++) counts13[i][j] = 0;
  FeatureTree* root = FeatureTree::roots(Feature::whichInt);
  assert(root);
  FeatTreeIter fi(root);
  FeatureTree* ft;
  /*
    first compute the Ds (discounts) for counts of 1, 2, and 3-up
  */
  for( ; fi.alive() ; fi.next() )
    {
      ft = fi.curr;
      int lev = fi.depth();
      if(lev < 2) continue;
      FeatMap& fm = ft->feats;
      FeatMap::iterator fmi = fm.begin();
      for( ; fmi != fm.end() ;fmi++)
	{
	  Feat& f = (*fmi).second;
	  int cnt = f.cnt();
	  if(cnt > 4) continue;
	  counts13[lev-2][cnt-1]++;
	}
    }
  for(i = 0 ; i <= numGram-2 ; i++)
    {
      float n1 = (float)counts13[i][0];
      float n2 = (float)counts13[i][1];
      float n3 = (float) counts13[i][2];
      float n4 = (float) counts13[i][3];
      float tmp = n1/(n1+2*n2);
      ds[i][0] = 1-(2*tmp*(n2/n1));
      ds[i][1] = 2-(3*tmp*(n3/n2));
      ds[i][2] = 3-(4*tmp*(n4/n3));
      for(j = 0 ; j < 3 ; j++)
	{
	  cerr << "ds " << i << " " << j << " " << ds[i][j] << endl;
	  cerr << n1 << "\t"<< n2 << "\t"<< n3 << "\t"<< n4 <<endl;
	  assert(ds[i][j] >= 0);
	  assert(ds[i][j] < j+1);
	}
    }
  FeatTreeIter fi2(root);
  /*
    Here we go through, and for each probability, actually compute it
    by p = (counts-D)/(total counts)
  */
  for( ; fi2.alive() ; fi2.next())
    {
      ft = fi2.curr;
      int lev = fi2.depth();
      if(lev < 1) continue;
      FeatMap& fm = ft->feats;
      FeatMap::iterator fmi = fm.begin();
      float totDel = 0;
      for( ; fmi != fm.end() ;fmi++)
	{
	  Feat& f = (*fmi).second;
	  float ind = (float)f.ind();
	  float denom = ft->count;
	  int wh = f.ind()-1;
	  if(ind > 2) wh = 2;
	  float dsl = 0;
	  if(lev > 1) dsl = ds[lev-2][wh]; //???;
	  float num = ind-dsl;
	  if(num < 0)
	    {
	      cerr << ind << " " << dsl << endl;
	      assert(num >= 0);
	    }
	  if(denom <= 0)
	    {
	      cerr << "Bad denom: " << denom << ft->ind
		   << " " << ft->featureInt << " " << lev << endl;
	      assert(denom > 0);
	    }
	  totDel += dsl;
	  f.g() = num/denom;
	  if(f.g() > 1)
	    {
	      cerr << "LDN " << lev << " " << denom << " " << num << endl;
	      assert(f.g() <= 1);
	    }
	  //cerr << "fg " << f.g() << endl;
	}
      ft->count = (int)((1000*totDel)/ft->count);
      assert(ft->count <= 1000);
    }
}
예제 #18
0
void DbPlugin::getSpreadHistory (BarData *barData, QDateTime &startDate)
{
  QString s = "FirstSymbol";
  QString fs;
  getData(s, fs);

  QString ss;
  s = "SecondSymbol";
  getData(s, ss);

  // get the first symbol bars
  QFileInfo fi(fs);
  QString fn = fi.fileName();

  DbPlugin db;
  if (db.open(fs, chartIndex))
  {
    qDebug("Spread::getSpreadHistory: cannot open first symbol chart");
    return;
  }

  BarData *bar = new BarData(fs);
  bar->setBarLength(barLength);
  db.setBarRange(barRange);
  db.getHistory(bar, startDate);
  db.close();

  // get the second symbol bars
  QFileInfo fi2(ss);
  fn = fi2.fileName();

  if (db.open(ss, chartIndex))
  {
    qDebug("Spread::getSpreadHistory: cannot open second symbol chart");
    delete bar;
    return;
  }

  BarData *bar2 = new BarData(ss);
  bar2->setBarLength(barLength);
  db.setBarRange(barRange);
  db.getHistory(bar2, startDate);
  db.close();

  // create lookup dict for first symbol bars
  QDict<Bar> lookup;
  lookup.setAutoDelete(TRUE);
  int loop;
  for (loop = 0; loop < bar->count(); loop++)
  {
    Bar *r = new Bar;
    QDateTime dt;
    bar->getDate(loop, dt);
    r->setDate(dt);
    r->setClose(bar->getClose(loop));
    r->getDateTimeString(FALSE, s);
    lookup.insert(s, r);
  }

  // match all second symbol bars
  for (loop = bar2->count() - 1; loop > -1; loop--)
  {
    Bar r;
    QDateTime dt;
    bar2->getDate(loop, dt);
    s = dt.toString("yyyyMMddhhmmss");
    Bar *tr = lookup.find(s);
    if (tr)
    {
      double t = tr->getClose() - bar2->getClose(loop);
      r.setDate(dt);
      r.setOpen(t);
      r.setHigh(t);
      r.setLow(t);
      r.setClose(t);
      barData->prepend(r);
    }
  }

  delete bar;
  delete bar2;
}
예제 #19
0
void SCFonts::AddScalableFonts(const QString &path, QString DocName)
{
	//Make sure this is not empty or we will scan the whole drive on *nix
	//QString::null+/ is / of course.
	if (path.isEmpty())
		return;
	FT_Library library = NULL;
	QString pathfile, fullpath;
//	bool error;
//	error =
	FT_Init_FreeType( &library );
	QString pathname(path);
	if ( !pathname.endsWith("/") )
		pathname += "/";
	pathname=QDir::toNativeSeparators(pathname);
	QDir d(pathname, "*", QDir::Name, QDir::Dirs | QDir::Files | QDir::Readable);
	if ((d.exists()) && (d.count() != 0))
	{
		for (uint dc = 0; dc < d.count(); ++dc)
		{
			// readdir may return . or .., which we don't want to recurse
			// over. Skip 'em.
			if (d[dc] == "." || d[dc] == "..")
				continue;
			fullpath = pathname+d[dc];
			QFileInfo fi(fullpath);
			if (!fi.exists())      // Sanity check for broken Symlinks
				continue;
			
			qApp->processEvents();
			
			bool symlink = fi.isSymLink();
			if (symlink)
			{
				QFileInfo fi3(fi.readLink());
				if (fi3.isRelative())
					pathfile = pathname+fi.readLink();
				else
					pathfile = fi3.absoluteFilePath();
			}
			else
				pathfile = fullpath;
			QFileInfo fi2(pathfile);
			if (fi2.isDir()) 
			{
				if (symlink)
				{
					// Check if symlink points to a parent directory
					// in order to avoid infinite recursion
					QString fullpath2 = fullpath, pathfile2 = pathfile;
					if (ScCore->isWinGUI())
					{
						// Ensure both path use same separators on Windows
						fullpath2 = QDir::toNativeSeparators(fullpath2.toLower());
						pathfile2 = QDir::toNativeSeparators(pathfile2.toLower());
					}
					if (fullpath2.startsWith(pathfile2))
						continue;
				}
				if (DocName.isEmpty())
					AddScalableFonts(pathfile);
				continue;
			}
			QString ext = fi.suffix().toLower();
			QString ext2 = fi2.suffix().toLower();
			if ((ext != ext2) && (ext.isEmpty())) 
				ext = ext2;
			if ((ext == "ttc") || (ext == "dfont") || (ext == "pfa") || (ext == "pfb") || (ext == "ttf") || (ext == "otf"))
			{
				AddScalableFont(pathfile, library, DocName);
			}
#ifdef Q_OS_MAC
			else if (ext.isEmpty() && DocName.isEmpty())
			{
				bool error = AddScalableFont(pathfile, library, DocName);
				if (error)
					error = AddScalableFont(pathfile + "/..namedfork/rsrc",library, DocName);
			}
#endif				
		}
	}
	FT_Done_FreeType(library);
}
예제 #20
0
//------------------------------------------------------------------------------
void PlotAlignmentValidation::plotChi2(const char *inputFile)
{
  // Opens the file (it should be OfflineValidation(Parallel)_result.root)
  // and reads and plots the norm_chi^2 and h_chi2Prob -distributions.

  // First set default style: plots are already formatted
  TStyle defStyle("Default","Default Style");
  defStyle.cd();
  gStyle->SetOptStat(1);
  TGaxis::SetMaxDigits(3);

  Bool_t errorflag = kTRUE;
  TFile* fi1 = new TFile(inputFile,"read");
  TDirectoryFile* mta1 = NULL;
  TDirectoryFile* mtb1 = NULL;
  TCanvas* normchi = NULL;
  TCanvas* chiprob = NULL;
  if (fi1 != NULL) {
    mta1 = (TDirectoryFile*) fi1->Get("TrackerOfflineValidationStandalone");
    if(mta1 != NULL) {
      mtb1 = (TDirectoryFile*) mta1->Get("GlobalTrackVariables");
      if(mtb1 != NULL) {
        normchi = (TCanvas*) mtb1->Get("h_normchi2");
	chiprob = (TCanvas*) mtb1->Get("h_chi2Prob");
        if (normchi != NULL && chiprob != NULL) {
          errorflag = kFALSE;
        }
      }
    }
  }
  if(errorflag)
  {
    std::cout << "PlotAlignmentValidation::plotChi2: Can't find data from given file,"
              << " no chi^2-plots produced" << std::endl;
    return;
  }

  // Small adjustments: move the legend right so that it doesn't block
  // the exponent of the y-axis scale
  TLegend* l = (TLegend*)findObjectFromCanvas(normchi, "TLegend");
  if (l != 0) {
    l->SetX1NDC(0.25);
  }
  l = (TLegend*)findObjectFromCanvas(chiprob, "TLegend");
  if (l != 0) {
    l->SetX1NDC(0.25);
  }

  chiprob->Draw();
  normchi->Draw();

  // EPS-files
  normchi->Print((outputDir + "/h_normchi2.eps").c_str());
  chiprob->Print((outputDir + "/h_chi2Prob.eps").c_str());

  // ROOT-files
  TFile fi2((outputDir + "/h_normchi2.root").c_str(), "recreate");
  normchi->Write();
  fi2.Close();

  TFile fi3((outputDir + "/h_chi2Prob.root").c_str(), "recreate");
  chiprob->Write();
  fi3.Close();

  fi1->Close();
  TGaxis::SetMaxDigits(4);

}