コード例 #1
0
ファイル: fileutils.cpp プロジェクト: zhc921106/TexturePacker
QVector<QString> FileUtils::getAllFiles(const QString &path)
{
    QVector<QString> result;
    QDir dir(path);
    QFileInfoList fileInfoLists = dir.entryInfoList();
    QFileInfoList::const_iterator iterator = fileInfoLists.constBegin();

    for(; iterator != fileInfoLists.constEnd(); iterator++)
    {
        QString filename = iterator->fileName();

        if (!filename.startsWith("."))
        {
            if (iterator->isDir())
            {
                result += getAllFiles(iterator->absoluteFilePath());
            }
            else if (iterator->isFile())
            {
                result.push_back(iterator->absoluteFilePath());
            }
            else
            {
                //
            }
        }
    }

    return result;
}
コード例 #2
0
ファイル: galleryutil.cpp プロジェクト: freelyfree/mythtv
bool GalleryUtil::CopyDirectory(const QFileInfo src, QFileInfo &dst)
{
    QDir srcDir(src.absoluteFilePath());

    dst = MakeUniqueDirectory(dst);
    if (!dst.exists())
    {
        srcDir.mkdir(dst.absoluteFilePath());
        dst.refresh();
    }

    if (!dst.exists() || !dst.isDir())
        return false;

    bool ok = true;
    QDir dstDir(dst.absoluteFilePath());
    QFileInfoList list = srcDir.entryInfoList();
    QFileInfoList::const_iterator it = list.begin();
    for (; it != list.end(); ++it)
    {
        const QString fn = it->fileName();
        if (fn != "." && fn != "..")
        {
            QFileInfo dfi(dstDir, fn);
            ok &= Copy(*it, dfi);
        }
    }

    return ok;
}
コード例 #3
0
ファイル: galleryutil.cpp プロジェクト: DaveDaCoda/mythtv
bool GalleryUtil::MoveDirectory(const QFileInfo src, QFileInfo &dst)
{
    QDir srcDir(src.absoluteFilePath());

    dst = MakeUniqueDirectory(dst);
    if (!dst.exists())
    {
        srcDir.mkdir(dst.absoluteFilePath());
        dst.refresh();
    }

    if (!dst.exists() || !dst.isDir())
        return false;

    bool ok = true;
    QDir dstDir(dst.absoluteFilePath());
    srcDir.setFilter(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
    QFileInfoList list = srcDir.entryInfoList();
    QFileInfoList::const_iterator it = list.begin();
    for (; it != list.end(); ++it)
    {
        const QString fn = it->fileName();
        QFileInfo dfi(dstDir, fn);
        ok &= Move(*it, dfi);
    }

    return ok && FileDelete(src);
}
コード例 #4
0
ファイル: QBtCompareDirsDialog.cpp プロジェクト: sclown/bsc
//*******************************************************************
// read_dir                                                  PRIVATE
//-------------------------------------------------------------------
// Rekursywne odczytywanie calej zawartosci wskazanego katalogu.
// Odczytana zawrtosc katalogu jest zapamietywania w hash-tablicy.
//*******************************************************************
void QBtCompareDirsDialog::read_dir( const QString& in_parent,
                                     const QString& in_dir,
                                     DirMap& out_data ) const
{
   static const int sflag = QDir::AllDirs
                          | QDir::Files
                          | QDir::NoDotAndDotDot
                          | QDir::Readable
                          | QDir::Writable
                          | QDir::Hidden;
                   
   const QDir dir( in_dir, "*", QDir::Unsorted, QFlags<QDir::Filter>( sflag ) );
   const QFileInfoList items = dir.entryInfoList();

   FileMap files_map = FileMap();
   QFileInfoList::const_iterator it = items.begin();
   const QFileInfoList::const_iterator end = items.end();
   while( continue_ && ( it != end ) ) {
      if( it->isDir() ) read_dir( in_parent, it->absoluteFilePath(), out_data );
      else              files_map.insert( it->fileName(), *it );
      ++it;
   }
   QString path = in_dir;
   out_data.insert( path.remove( in_parent ), files_map );
}
コード例 #5
0
int QgsSVGDiagramFactoryWidget::addDirectoryToPreview( const QString& path )
{
  //go through all files of a directory
  QDir directory( path );
  if ( !directory.exists() || !directory.isReadable() )
  {
    return 1; //error
  }

  QFileInfoList fileList = directory.entryInfoList( QDir::Files );
  QFileInfoList::const_iterator fileIt = fileList.constBegin();

  QProgressDialog progress( "Adding Icons...", "Abort", 0, fileList.size() - 1, this );
  //cancel button does not seem to work properly with modal dialog
  //progress.setWindowModality(Qt::WindowModal);

  int counter = 0;
  for ( ; fileIt != fileList.constEnd(); ++fileIt )
  {

    progress.setLabelText( tr( "Creating icon for file %1" ).arg( fileIt->fileName() ) );
    progress.setValue( counter );
    QCoreApplication::processEvents();
    if ( progress.wasCanceled() )
    {
      break;
    }
    QString filePath = fileIt->absoluteFilePath();

    //test if file is svg or pixel format
    bool fileIsSvg = testSvgFile( filePath );

    //exclude files that are not svg or image
    if ( !fileIsSvg )
    {
      ++counter; continue;
    }

    QListWidgetItem * listItem = new QListWidgetItem( mPreviewListWidget );

    if ( fileIsSvg )
    {
      QIcon icon( filePath );
      listItem->setIcon( icon );
    }

    listItem->setText( "" );
    //store the absolute icon file path as user data
    listItem->setData( Qt::UserRole, fileIt->absoluteFilePath() );
    ++counter;
  }

  return 0;
}
コード例 #6
0
ファイル: galleryutil.cpp プロジェクト: DaveDaCoda/mythtv
bool GalleryUtil::DeleteDirectory(const QFileInfo &dir)
{
    if (!dir.exists())
        return false;

    QDir srcDir(dir.absoluteFilePath());
    srcDir.setFilter(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
    QFileInfoList list = srcDir.entryInfoList();
    QFileInfoList::const_iterator it = list.begin();
    for (; it != list.end(); ++it)
    {
        const QString fn = it->fileName();
        Delete(*it);
    }

    return FileDelete(dir);
}
コード例 #7
0
ファイル: galleryutil.cpp プロジェクト: freelyfree/mythtv
bool GalleryUtil::DeleteDirectory(const QFileInfo &dir)
{
    if (!dir.exists())
        return false;

    QDir srcDir(dir.absoluteFilePath());
    QFileInfoList list = srcDir.entryInfoList();
    QFileInfoList::const_iterator it = list.begin();
    for (; it != list.end(); ++it)
    {
        const QString fn = it->fileName();
        if (fn != "." && fn != "..")
            Delete(*it);
    }

    return FileDelete(dir);
}
コード例 #8
0
void QgsColorSchemeRegistry::addUserSchemes()
{
  QString palettesDir = QgsApplication::qgisSettingsDirPath() + "/palettes";

  QDir localDir;
  if ( !localDir.mkpath( palettesDir ) )
  {
    return;
  }

  QFileInfoList fileInfoList = QDir( palettesDir ).entryInfoList( QStringList( "*.gpl" ), QDir::Files );
  QFileInfoList::const_iterator infoIt = fileInfoList.constBegin();
  for ( ; infoIt != fileInfoList.constEnd(); ++infoIt )
  {
    addColorScheme( new QgsUserColorScheme( infoIt->fileName() ) );
  }
}
コード例 #9
0
ファイル: mainwindow.cpp プロジェクト: laybatin/ImageDomino
/*
 * FilesModelUpdate
 * extfilter_imgs_ 에 들어있는 파일들을 실제로 보여지도록 만든다.
 * 조그만 아이콘으로 만들기 위한 작업
 */
void MainWindow::FilesModelUpdate() {
    QFileInfoList::const_iterator iter;

    file_model_->clear();

    for (iter=extfilter_imgs_.begin(); iter!=extfilter_imgs_.end(); ++iter) {
        qDebug() << iter->absoluteFilePath();
        QImage img_buffer(iter->absoluteFilePath());
        QIcon icon = GetThumnail(&img_buffer);

        QStandardItem* item;
        if(!icon.isNull()) {
            item = new QStandardItem(icon,iter->fileName());
            file_model_->appendRow(item);
        }
    }


    extfilter_imgs_.clear();;

}
コード例 #10
0
ファイル: fileutils.cpp プロジェクト: zhc921106/TexturePacker
QVector<QString> FileUtils::getAllImageFiles(const QString & path)
{
    QVector<QString> result;
    QDir dir(path);
    QFileInfoList fileInfoLists = dir.entryInfoList();
    QFileInfoList::const_iterator iterator = fileInfoLists.constBegin();

    for(; iterator != fileInfoLists.constEnd(); iterator++)
    {
        QString filename = iterator->fileName();

        if (!filename.startsWith("."))
        {
            if (iterator->isDir())
            {
                result += getAllImageFiles(iterator->absoluteFilePath());
            }
            else if (iterator->isFile())
            {
                QString ext = iterator->completeSuffix();
                QString extLower = ext.toLower();
                if (extLower.endsWith("png") ||
                        extLower.endsWith("jpg") ||
                        extLower.endsWith("jpeg"))
                {
                    result.push_back(iterator->absoluteFilePath());
                }
            }
            else
            {
                //
            }
        }
    }

    return result;
}
コード例 #11
0
ファイル: File.C プロジェクト: BioITer/OpenMS
  bool File::fileList(const String& dir, const String& file_pattern, StringList& output, bool full_path)
  {
    QDir d(dir.toQString(), file_pattern.toQString(), QDir::Name, QDir::Files);
    QFileInfoList list = d.entryInfoList();

    //clear and check if empty
    output.clear();
    if (list.empty())
    {
      return false;
    }

    //resize output
    output.resize(list.size());

    //fill output
    UInt i = 0;
    for (QFileInfoList::const_iterator it = list.constBegin(); it != list.constEnd(); ++it)
    {
      output[i++] = full_path ? it->filePath() : it->fileName();
    }

    return true;
  }
コード例 #12
0
int QgsComposerPictureWidget::addDirectoryToPreview( const QString& path )
{
  //go through all files of a directory
  QDir directory( path );
  if ( !directory.exists() || !directory.isReadable() )
  {
    return 1; //error
  }

  QFileInfoList fileList = directory.entryInfoList( QDir::Files );
  QFileInfoList::const_iterator fileIt = fileList.constBegin();

  QProgressDialog progress( "Adding Icons...", "Abort", 0, fileList.size() - 1, this );
  //cancel button does not seem to work properly with modal dialog
  //progress.setWindowModality(Qt::WindowModal);

  int counter = 0;
  for ( ; fileIt != fileList.constEnd(); ++fileIt )
  {

    progress.setLabelText( tr( "Creating icon for file %1" ).arg( fileIt->fileName() ) );
    progress.setValue( counter );
    QCoreApplication::processEvents();
    if ( progress.wasCanceled() )
    {
      break;
    }
    QString filePath = fileIt->absoluteFilePath();

    //test if file is svg or pixel format
    bool fileIsPixel = false;
    bool fileIsSvg = testSvgFile( filePath );
    if ( !fileIsSvg )
    {
      fileIsPixel = testImageFile( filePath );
    }

    //exclude files that are not svg or image
    if ( !fileIsSvg && !fileIsPixel )
    {
      ++counter; continue;
    }

    QListWidgetItem * listItem = new QListWidgetItem( mPreviewListWidget );
    listItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );

    if ( fileIsSvg )
    {
      QIcon icon( filePath );
      listItem->setIcon( icon );
    }
    else //for pixel formats: create icon from scaled pixmap
    {
      QPixmap iconPixmap( filePath );
      if ( iconPixmap.isNull() )
      {
        ++counter; continue; //unknown file format or other problem
      }
      //set pixmap hardcoded to 30/30, same as icon size for mPreviewListWidget
      QPixmap scaledPixmap( iconPixmap.scaled( QSize( 30, 30 ), Qt::KeepAspectRatio ) );
      QIcon icon( scaledPixmap );
      listItem->setIcon( icon );
    }

    listItem->setText( "" );
    //store the absolute icon file path as user data
    listItem->setData( Qt::UserRole, fileIt->absoluteFilePath() );
    ++counter;
  }

  return 0;
}
コード例 #13
0
  openstudio::path WeatherFileFinder::find(const JobParams &t_params,
      const boost::optional<std::string> &t_filelocationname,
      const boost::optional<std::string> &t_weatherfilename)
  {
    openstudio::path epwdir;

    try {
      if (t_params.has("epwfile"))
      {
        openstudio::path epwfile = toPath(t_params.get("epwfile").children.at(0).value);

        if (!epwfile.empty() && boost::filesystem::exists(epwfile))
        {
          LOG(Info, "Valid epwfile found, returning: " << openstudio::toString(epwfile));

          return epwfile;
        }
      } else {
        LOG(Info, "No epwfile found in params, moving on for other methods of finding weather file");
      }
    } catch (const std::exception &) {
      // No epw dir set in params
      LOG(Info, "Error with epwfile found in params, moving on for other methods of finding weather file");
    }

    try {
      if (t_params.has("epwdir"))
      {
        epwdir = toPath(t_params.get("epwdir").children.at(0).value);
      }
    } catch (const std::exception &) {
      // No epw dir set in params
      LOG(Info, "No EPWDir known finding weather file will be much harder");
    }

    if (epwdir.empty() || !boost::filesystem::exists(epwdir) || !boost::filesystem::is_directory(epwdir))
    {
      LOG(Info, "The configured EPWDir either does not exist or is not a directory: " << toString(epwdir));
    }


    if (t_weatherfilename)
    {
      openstudio::path p = toPath(*t_weatherfilename);

      if (!boost::filesystem::exists(p))
      {
        p = epwdir / toPath(*t_weatherfilename);

        if (!boost::filesystem::exists(p))
        {
          LOG(Info, "Weather file discovered from comment header cannot be found at: " << toString(p));
        } else {
          return p;
        }
        LOG(Info, "Weather file discovered from comment header cannot be found at: " << *t_weatherfilename);
      } else {
        return p;
      }

    }

    if (t_filelocationname)
    {
      LOG(Info, "attempting to find weather file from location name: " << *t_filelocationname);

      // We did not have an epw set, so let's try to find one
      try {
        QDir dir(openstudio::toQString(epwdir), "*.epw");
        QFileInfoList files = dir.entryInfoList();

        std::set<std::string> desiredname = getNameComponents(*t_filelocationname);

        openstudio::path bestmatch;
        size_t matchsize = 0;

        for (QFileInfoList::const_iterator itr = files.begin();
            itr != files.end();
            ++itr)
        {
          std::set<std::string> foundname = getNameComponents(openstudio::toString(itr->fileName()));

          std::vector<std::string> matches;
          std::set_intersection(desiredname.begin(), desiredname.end(), foundname.begin(), foundname.end(),
              std::back_inserter(matches));

          if (matches.size() > matchsize)
          {
            matchsize = matches.size();
            bestmatch = openstudio::toPath(itr->absoluteFilePath());
          }
        }

        if (matchsize > 2)
        {
          LOG(Info, "Adding best match epw from the list found: " << toString(bestmatch));
          return bestmatch;
        } else {
          LOG(Info, "No best match epw file found, continuing with no epw set");
        }

      } catch (const std::exception &) {
        LOG(Info, "No EPw file set and no epwdir provided. We are continuing, but EnergyPlus will likely fail");
      }
    } else {
      LOG(Info, "No EPw file set and no location information parsed from IDF. We are continuing, but EnergyPlus will likely fail");
    }  

    LOG(Info, "No weather file found");

    return openstudio::path();
  }
コード例 #14
0
ファイル: ImagePane.cpp プロジェクト: kenschweller/qtmaze
static void PopulateWithImages(QListWidget * const imagelist, const QString &path)
{
	QDir imagesDir(path);
	QStringList extensions;
	extensions << "*.jpg" << "*.png" << "*.bmp" << "*.gif";
	const QFileInfoList fileList = imagesDir.entryInfoList(extensions, QDir::Files, QDir::Name | QDir::IgnoreCase);
	for (QFileInfoList::const_iterator it = fileList.begin(); it != fileList.end(); ++it)
	{
		QListWidgetItem * const item = new QListWidgetItem(QIcon(QPixmap(it->absoluteFilePath())), it->fileName());
		imagelist->addItem(item);
	}
}
コード例 #15
0
ファイル: LocalProcess.cpp プロジェクト: CUEBoxer/OpenStudio
  LocalProcess::FileSet LocalProcess::dirFiles(const QString &dir) const
  {
    QFileInfoList fil;

    
    QDir subdirs(dir, "mergedjob-*", QDir::Name, QDir::Dirs);
    QFileInfoList mergedjobdirs = subdirs.entryInfoList();

    for (QFileInfoList::const_iterator itr = mergedjobdirs.begin();
         itr != mergedjobdirs.end();
         ++itr)
    {

      QDir mergeddir(itr->absoluteFilePath(), "", QDir::Name, QDir::Files);
      fil.append(mergeddir.entryInfoList());
    }
  

    QDir d(dir, "", QDir::Name, QDir::Files);
    fil.append(d.entryInfoList());

    QFileInfoList filtered;

    // Filter out all files that are part of the set of input files. Everything remaining should be an outputfile
    for (QFileInfoList::const_iterator itr = fil.begin();
         itr != fil.end();
         ++itr)
    {
      bool partofinput = false;
      for (std::vector<std::pair<openstudio::path, openstudio::path> >::const_iterator itr2 = m_requiredFiles.begin();
          itr2 != m_requiredFiles.end();
          ++itr2)
      {
        QString fileName = itr->fileName();
        QString fileName2 = toQString(itr2->second.filename());
        if (fileName == fileName2)
        {
          partofinput = true;
          break;
        }
      }

      if (!partofinput)
      {
        filtered.push_back(*itr);
      }
    }

    FileSet out;

    typedef FileInfo (*filetransform)(QFileInfo);

    try{
      std::transform(filtered.begin(), filtered.end(), std::inserter(out, out.end()), 
          static_cast<filetransform>(&RunManager_Util::dirFile));
    } catch(openstudio::Exception& e) {
      LOG_AND_THROW("Exception caught " << e.what());
    }

    return out;
  }
コード例 #16
0
bool genEmoji(QString emoji_in, const QString &emoji_out) {
	QDir d(emoji_in);
	if (!d.exists()) {
		cout << "Could not open emoji input dir '" << emoji_in.toUtf8().constData() << "'!\n";
		QCoreApplication::exit(1);
		return false;
	}
	emoji_in = d.absolutePath() + '/';
	QString emoji_in_200x = d.absolutePath() + "_200x/";
	QDir d_200x(emoji_in_200x);
	if (!d.exists()) {
		cout << "Could not open emoji _200x input dir '" << emoji_in_200x.toUtf8().constData() << "'!\n";
		QCoreApplication::exit(1);
		return false;
	}

	int currentRow = 0, currentColumn = 0;
	uint32 min1 = 0xFFFFFFFF, max1 = 0, min2 = 0xFFFFFFFF, max2 = 0;

	QStringList filters;
    filters << "*.png" << "*.gif";
	QFileInfoList emojis = d.entryInfoList(filters, QDir::Files | QDir::NoDotAndDotDot | QDir::Readable);
	for (QFileInfoList::const_iterator i = emojis.cbegin(), e = emojis.cend(); i != e; ++i) {
		QString s = i->fileName();
		QRegularExpressionMatch m = QRegularExpression("^([A-F0-9]+)\\.(png|gif)$").match(s);
		if (m.hasMatch()) {
			EmojiData data;
			QString num = m.captured(1);
			if (num.size() != 4 && num.size() != 8 && num.size() != 16) {
				cout << "Bad name found '" << s.toUtf8().constData() << "'!\n";
				continue;
			}

			data.code = ("0x" + num.mid(0, 8)).toUInt(0, 16);
			if (num.size() > 8) {
				data.code2 = ("0x" + num.mid(8)).toUInt(0, 16);
			} else {
				data.code2 = 0;
			}
			data.name = emoji_in + s;
			data.name_200x = emoji_in_200x + s;
			data.x = currentColumn;
			data.y = currentRow;
			++currentColumn;

			if (currentColumn == inRow) {
				++currentRow;
				currentColumn = 0;
			}
			uint32 high = data.code >> 16;
			if (!high) { // small codes
				if (data.code == 169 || data.code == 174) { // two small
				} else {
					if (data.code < min1) min1 = data.code;
					if (data.code > max1) max1 = data.code;
				}
			} else if (high == 35 || high >= 48 && high < 58) { // digits
			} else {
				if (data.code < min2) min2 = data.code;
				if (data.code > max2) max2 = data.code;
			}
			EmojisData::const_iterator i = emojisData.constFind(data.code);
			if (i != emojisData.cend()) {
				cout << QString("Bad emoji code (duplicate) %1 %2 and %3 %4").arg(data.code).arg(data.code2).arg(i->code).arg(i->code2).toUtf8().constData() << "\n";
				continue;
			}
			emojisData.insert(data.code, data);
		} else {