Exemple #1
0
int QBookDevel::getPid(const char *exe) {
    static struct dirent *ent;
    DIR *dir = opendir("/proc");
    if (!dir)
          return 0;
    while( (ent = readdir(dir)) ) {
      if(!ent || !ent->d_name) {
          closedir(dir);
          return 0;
      }
      if(*ent->d_name < '0' || *ent->d_name > '9')
          continue;

      QString *path = new QString();
      path->append("/proc/");
      path->append(ent->d_name);
      path->append("/exe");
      qDebug () << *path;
      QFileInfo f = QFileInfo(*path);

      if (f.isSymLink()) {
           QFileInfo l = QFileInfo (f.symLinkTarget());
            if (l.completeBaseName() == exe) {
                closedir(dir);
                return atoi(ent->d_name);
            }
      }
      // We need to check also cmdline as a lot of binaries are links to busybox
      path = new QString();
      path->append("/proc/");
      path->append(ent->d_name);
      path->append("/cmdline");
      QFile *file = new QFile(*path);
      delete path;
      if (!file->open(QIODevice::ReadOnly))
          continue;

      QTextStream stream(file);
      QString line = stream.readLine();
      file->close();
      delete file;
      QStringList args = line.split((QChar)0); // cmdline is separated with NULLs!
      if (args.size() > 0) {
          f = QFileInfo (args.at(0));
          if (f.completeBaseName() == exe) {
              closedir(dir);
              return atoi(ent->d_name);
          }

      }
    }
    closedir(dir);
    return 0;
}
Exemple #2
0
void ExifWrapper::parseFile( ExifData& data )
{

    // prepare data
    QFileInfo info (data.FilePath);

    // skip known extensions
    if (isUnsupportedFileType(info.suffix())) {
        data.Extention = info.suffix();
        data.FileName = info.completeBaseName();
        return;
    }

    // decide what tool to use, we want exiv2 only for jpg
    if (isEqual(info.suffix(), "jpg") ) {
		data = doParse(EXIV2, data.FilePath);
        if (data.CreateDate.isInvalid()) {
            qWarning() << "Parsing failed once, retrying.";
            data = doParse(EXIFTOOL, data.FilePath);
            if (data.CreateDate.isInvalid()) {
                qWarning() << "Parsing failed again, giving up on file" << data.FilePath;
            }
        }
    }
    else {
        data = doParse(EXIFTOOL, data.FilePath);
    }

}
Exemple #3
0
void TabDivePhotos::saveSubtitles()
{
	QVector<QString> selectedPhotos;
	if (!ui->photosView->selectionModel()->hasSelection())
		return;
	QModelIndexList indexes = ui->photosView->selectionModel()->selectedRows();
	if (indexes.count() == 0)
		indexes = ui->photosView->selectionModel()->selectedIndexes();
	selectedPhotos.reserve(indexes.count());
	for (const auto &photo: indexes) {
		if (photo.isValid()) {
			QString fileUrl = photo.data(Qt::DisplayPropertyRole).toString();
			if (!fileUrl.isEmpty()) {
				QFileInfo fi = QFileInfo(fileUrl);
				QFile subtitlefile;
				subtitlefile.setFileName(QString(fi.path()) + "/" + fi.completeBaseName() + ".ass");
				int offset = photo.data(Qt::UserRole + 1).toInt();
				int duration = photo.data(Qt::UserRole + 2).toInt();
				// Only videos have non-zero duration
				if (!duration)
					continue;
				struct membuffer b = { 0 };
				save_subtitles_buffer(&b, &displayed_dive, offset, duration);
				char *data = detach_buffer(&b);
				subtitlefile.open(QIODevice::WriteOnly);
				subtitlefile.write(data, strlen(data));
				subtitlefile.close();
				free(data);
			}

		}
	}
}
Exemple #4
0
QString AddToArchive::detectBaseName(const QStringList &paths) const
{
    QFileInfo fileInfo = QFileInfo(paths.first());
    QDir parentDir = fileInfo.dir();
    QString base = parentDir.absolutePath() + QLatin1Char('/');

    if (paths.size() > 1) {
        if (!parentDir.isRoot()) {
            // Use directory name for the new archive.
            base += parentDir.dirName();
        }
    } else {
        // Strip filename of its extension, but only if present (see #362690).
        if (!QMimeDatabase().mimeTypeForFile(fileInfo.fileName(), QMimeDatabase::MatchExtension).isDefault()) {
            base += fileInfo.completeBaseName();
        } else {
            base += fileInfo.fileName();
        }
    }

    // Special case for compressed tar archives.
    if (base.right(4).toUpper() == QLatin1String(".TAR")) {
        base.chop(4);
    }

    if (base.endsWith(QLatin1Char('/'))) {
        base.chop(1);
    }

    return base;
}
QLibrary* RazorPluginInfo::loadLibrary(const QString& libDir) const
{
    QString baseName, path;
    QFileInfo fi = QFileInfo(fileName());
    path = fi.canonicalPath();
    baseName = value("X-Razor-Library", fi.completeBaseName()).toString();

    QString soPath = QString("%1/lib%2.so").arg(libDir, baseName);
    QLibrary* library = new QLibrary(soPath);

    if (!library->load())
    {
        qWarning() << QString("Can't load plugin lib \"%1\"").arg(soPath) << library->errorString();
        delete library;
        return 0;
    }

    QString locale = QLocale::system().name();
    QTranslator* translator = new QTranslator(library);

    translator->load(QString("%1/%2/%2_%3.qm").arg(path, baseName, locale));
    qApp->installTranslator(translator);

    return library;
}
void RecurseDirectory(const QString dir, bool recursion)
{
    QDir dirEnt(dir);
    QFileInfoList list = dirEnt.entryInfoList();
    for(int i = 0; i < list.count(); i++)
    {
        QFileInfo info = list[i];

        QString filePath = info.filePath();
        QString fileExt = info.suffix().toLower();
        QString name = dir + QDir::separator();
        if(recursion && info.isDir())
        {
            // recursive
            if(info.fileName() != ".." && info.fileName() != ".")
            {
                RecurseDirectory(filePath, recursion);
            }
        }
        else
            if(imageExtensions.contains(fileExt))
            {
                if(!QFile::exists(name + info.completeBaseName() + QString(".atlas")))
                {
                    packerData *data = new packerData;
                    data->path = info.absoluteFilePath();
                    data->file = filePath.replace(topImageDir, "");
                    //                qDebug() << "Packing " << data->path << "...";
                    mainPacker->addItem(data->path, data);
                }
            }
    }
}
    foreach (QFileInfo sourceInfo, sourceInfoList) {
        QImage sourceImage(sourceInfo.absoluteFilePath());
        QImage scaledSourceImage = sourceImage.scaled(225,225,Qt::KeepAspectRatio);
        int sourceWidth = sourceImage.width();
        int destWidth = scaledSourceImage.width();
        double scaleBackFactor = (double)sourceWidth/destWidth; // as we keep aspect ratio, this is sufficient to scale rectangle back
        qDebug() << sourceInfo.fileName();
        QList<QRect> destRects;
        QFileInfo destFileInfo = makeDestFileInfo(sourceDir, sourceInfo, destDir);
        if (faceCropper->crop(scaledSourceImage,destRects)) {
//            facelookupTable.addFile(sourceInfo, destRects, destFileInfo, scaleBackFactor);
            if (destRects.count()>1) {
                for (int i=0; i< destRects.count(); ++i) {
                    QRect destRect = destRects.at(i);
                    QRect destRectScaled(destRect.topLeft()*scaleBackFactor, destRect.bottomRight()*scaleBackFactor);
                    QImage destImage = sourceImage.copy(destRectScaled);
                    QString destString = destFileInfo.absolutePath();
                    destString.append(QDir::separator());
                    destDir.mkpath(destString);
                    destString.append(destFileInfo.completeBaseName());
                    destString.append("_");
                    destString.append(QString::number(i));
                    destString.append(".");
                    destString.append(destFileInfo.suffix());
                    destImage.save(destString);
                }
            } else if (destRects.count()==1){
                QRect destRect = destRects.first();
                QRect destRectScaled(destRect.topLeft()*scaleBackFactor, destRect.bottomRight()*scaleBackFactor);
                QImage destImage = sourceImage.copy(destRectScaled);
                destDir.mkpath(destFileInfo.absolutePath());
                destImage.save(destFileInfo.absoluteFilePath());
            }
        }
    }
Exemple #8
0
void MainWindow::refreshListFiles(){
    ui->menuFichiers_r_cents->clear();
    disconnect(ui->menuFichiers_r_cents, SIGNAL(triggered(QAction*)),
               this, SLOT(test(QAction*)));
    QList<QFileInfo*>* files = core->getList();
    if(files->isEmpty()){
        ui->menuFichiers_r_cents->setEnabled(false);
    }else{
        ui->menuFichiers_r_cents->setEnabled(true);
        for(QList<QFileInfo*>::const_iterator it = files->begin();
            it != files->end(); it++){
            QFileInfo* file = static_cast<QFileInfo *>(*it);
            QAction * action = new QAction(this);
            if(file && action){
                action->setData(file->absoluteFilePath());
                action->setText(file->completeBaseName());
                ui->menuFichiers_r_cents->addAction(action);
            }
        }
        QAction * action = new QAction(this);
        if(action){
            action->setText("Effacer");
            ui->menuFichiers_r_cents->addSeparator();
            ui->menuFichiers_r_cents->addAction(action);
        }
        connect(ui->menuFichiers_r_cents, SIGNAL(triggered(QAction*)),
                this, SLOT(test(QAction*)));
    }
}
Exemple #9
0
void LanguageManager::setCurrentName( const QString & name )
{
	if ( name == currentName_ )
		return;

	if ( !currentName_.isNull() )
	{
		LanguageInfo & languageInfo = languageInfoForName_[ currentName_ ];

		for ( QListIterator<QTranslator*> it( languageInfo.translators ); it.hasNext(); )
			QCoreApplication::instance()->removeTranslator( it.next() );

		qDeleteAll( languageInfo.translators );
		languageInfo.translators.clear();
	}

	currentName_ = name;

	if ( !currentName_.isNull() )
	{
		LanguageInfo & languageInfo = languageInfoForName_[ currentName_ ];

		if ( !languageInfo.isTranslatorFileNamesUpdated )
		{
			languageInfo.isTranslatorFileNamesUpdated = true;

			QDir langDir( QmDirPath );
			for ( QListIterator<QFileInfo> it( langDir.entryInfoList(
				QStringList() << QmLanguageTemplate.arg( currentName_ ), QDir::Files | QDir::CaseSensitive ) ); it.hasNext(); )
			{
				const QFileInfo qmFileInfo = it.next();

				QString moduleName;
				QString suffix;
				if ( !_splitFileName( qmFileInfo.completeBaseName(), &moduleName, &suffix ) )
					continue;

				Q_ASSERT( suffix == currentName_ );

				languageInfo.translatorFileNames << qmFileInfo.filePath();
			}
		}

		for ( QStringListIterator fileNameIt( languageInfo.translatorFileNames ); fileNameIt.hasNext(); )
		{
			const QString & fileName = fileNameIt.next();

			QTranslator * moduleTranslator = new QTranslator( this );
			if ( !moduleTranslator->load( fileName ) )
			{
				delete moduleTranslator;
				continue;
			}

			languageInfo.translators << moduleTranslator;

			QCoreApplication::instance()->installTranslator( moduleTranslator );
		}
	}
}
void MainWindow::batchTransform()
{
	QFileDialog dialog(this);
	dialog.setFileMode(QFileDialog::ExistingFiles);
	QStringList fileNames;
	if (dialog.exec())
		fileNames = dialog.selectedFiles();
	else
		return;

	QString prefix = QInputDialog::getText(this, tr("Replacement Workspace"),
			tr("Enter a prefix for the new files:"));
	QString suffix = QInputDialog::getText(this, tr("Replacement Workspace"),
			tr("Enter a suffix for the new files:"));

	GetListFromTable();

	for (int i = 0; i < fileNames.length(); i++)
	{
		QString extension;
		QFile file(fileNames.at(i));
		QFileInfo *info = new QFileInfo(file);
		if (info->suffix().length() == 0)
			extension = "";
		else
			extension = "." + info->suffix();
		QString newFilename = info->absolutePath() + "/" + prefix
				+ info->completeBaseName() + suffix + extension;
		mRe->processFile( fileNames.at(i) , newFilename );
	}
}
void ViewTableListWidget::getViews()
{
    QDir rootdir("view//");
    rootdir.setFilter(rootdir.filter()|QDir::NoDotAndDotDot);
    QStringList strings;
    strings<<"*";
    list = rootdir.entryInfoList(strings);
    qDebug()<<list.length();
    //QFileInfoList list = rootdir.entryInfoList(strings);
   // qDebug()<<*list.begin();

    QFileInfoList::iterator i = list.begin();
    QFileInfo tempinfo;
    while(i != list.end())
    {
        tempinfo = *i;
        if(tempinfo.completeBaseName()==QString(tr("纯C程序题")))
        {
            //qDebug()<<tr("相等");
         //   rename("view//asdsagashg","view//newfilename");
           // tempinfo.setFile("haha");
        }
      //  qDebug()<<tempinfo.completeBaseName();
        i++;
    }
   /* list.clear();
    qDebug()<<list.length();*/
}
SearchFile::SearchFile( SearchTreeItem* parent,
						const QueryHit* const pHit, const QFileInfo& fileInfo ) :
	SearchTreeItem( parent ),
	m_vHashes( HashSet( pHit->m_vHashes ) )
{
	m_eType = SearchFileType;

	m_pItemData[FILE]      = fileInfo.completeBaseName();
	m_pItemData[EXTENSION] = fileInfo.suffix();
	m_pItemData[SIZE]      = formatBytes( pHit->m_nObjectSize );
	m_pItemData[RATING]    = "";
	m_pItemData[STATUS]    = "";
	m_pItemData[HOSTCOUNT] = 1;
	m_pItemData[SPEED]     = "";
	m_pItemData[CLIENT]    = "";
	m_pItemData[COUNTRY]   = "";

	const Hash* const * const pHashes = &m_vHashes[0];
	for ( quint8 i = 0, nSize = m_vHashes.size(); i < nSize; ++i )
	{
		if ( pHashes[i] )
		{
			( ( TreeRoot* )m_pParentItem )->registerHash( *pHashes[i], this );
		}
	}
}
SearchHit::SearchHit( SearchTreeItem* parent,
					  QueryHit* pHit, const QFileInfo& fileInfo ) :
	SearchTreeItem( parent )
{
	m_eType = SearchHitType;

	m_pItemData[FILE]      = fileInfo.completeBaseName();
	m_pItemData[EXTENSION] = fileInfo.suffix();
	m_pItemData[SIZE]      = formatBytes( pHit->m_nObjectSize );
	m_pItemData[RATING]    = "";
	m_pItemData[STATUS]    = "";
	m_pItemData[HOSTCOUNT] = pHit->m_pHitInfo.data()->m_oNodeAddress.toString();
	m_pItemData[SPEED]     = "";
	m_pItemData[CLIENT]    = vendorCodeToName( pHit->m_pHitInfo.data()->m_sVendor );
	m_pItemData[COUNTRY]   = pHit->m_pHitInfo.data()->m_oNodeAddress.countryName();

	QString sCountry       = pHit->m_pHitInfo.data()->m_oNodeAddress.country();

	m_oHitData.iNetwork  = NetworkIconProvider::icon( DiscoveryProtocol::G2 );
	m_oHitData.iCountry  = NetworkIconProvider::icon( sCountry );
	m_oHitData.pQueryHit = QueryHitSharedPtr( pHit );

	// properly initialize filter data
	delete m_pFilter;
	m_pFilter = new SearchFilter::HitFilter( pHit );
}
Exemple #14
0
LanguageManager::LanguageManager()
{
	// lookup qm files under the :/lang dir

	QDir langDir( QmDirPath );
	for ( QListIterator<QFileInfo> it( langDir.entryInfoList(
		QStringList() << QmTemplate.arg( QmInfoPrefix ), QDir::Files | QDir::CaseSensitive ) ); it.hasNext(); )
	{
		const QFileInfo qmFileInfo = it.next();

		QString moduleName;
		QString suffix;
		if ( !_splitFileName( qmFileInfo.completeBaseName(), &moduleName, &suffix ) )
			continue;

		Q_ASSERT( moduleName == QmInfoPrefix );
		Q_ASSERT( !languageInfoForName_.contains( suffix ) );

		QTranslator * infoTranslator = new QTranslator( this );
		if ( !infoTranslator->load( qmFileInfo.filePath() ) )
		{
			delete infoTranslator;
			continue;
		}

		LanguageInfo languageInfo;
		languageInfo.isNull = false;
		languageInfo.name = suffix;
		languageInfo.englishName = infoTranslator->translate( "LanguageManager", LanguageNameInEnglish );
		languageInfo.nativeName = infoTranslator->translate( "LanguageManager", LanguageNameInNative );

		languageInfoForName_[ languageInfo.name ] = languageInfo;
		names_ << languageInfo.name;
	}

	QString defaultName;

	const QLocale currentLocale;
	if ( languageInfoForName_.contains( currentLocale.name() ) )
	{
		defaultName = currentLocale.name();
	}
	else
	{
		const QString localeLangName = currentLocale.name().left( currentLocale.name().indexOf( QLatin1Char( '_' ) ) );
		if ( languageInfoForName_.contains( localeLangName ) )
		{
			defaultName = localeLangName;
		}
		else
		{
			if ( languageInfoForName_.contains( DefaultLanguageName ) )
				defaultName = DefaultLanguageName;
		}
	}

	if ( !defaultName.isNull() )
		setCurrentName( defaultName );
}
QString RotoCanvas::getSeqPaddedFrameNumber(QFileInfo frameFI)
{
    QString baseName=frameFI.completeBaseName();
    int digitCount=RotoCanvas::getSeqDigitCount(frameFI);
    //qInfo()<<"getSeqPaddedFrameNumber digitCount:"<<digitCount;
    QString result=baseName.right(digitCount);
    return result;
}
Exemple #16
0
void ImageCache::load(const QString &themename)
{
    QString prefix = QDir::toNativeSeparators(Config::getInstance()->plexydeskBasePath() +
            QLatin1String("/share/plexy/themepack/") +
            themename
            + QLatin1String("/resources/"));

    QDir dir(prefix);
    dir.setFilter(QDir::Files);
    QFileInfoList list = dir.entryInfoList();

    for (int i = 0; i < list.size(); i++)
    {
        QFileInfo file = list.at(i);
        d->map[file.completeBaseName()] = QPixmap(QDir::toNativeSeparators(file.absoluteFilePath()));
        d->fileHash[file.completeBaseName()] = file.absoluteFilePath();
    }
}
void	win_char_editor::bg_list_fill()
{
	bg_list->clear();
        QDir dir = QDir(directory_ivf);
	QFileInfoList list = dir.entryInfoList();
    for (int i = 0; i < list.size(); ++i) 
		{
		QFileInfo fi = list.at(i);
		
		if (fi.isFile())
			if (fi.completeBaseName().length() == 4)
				{
				bool ok;
				bg_list->addItem(QString(QChar(fi.completeBaseName().toInt(&ok, 16))) + "  " + fi.baseName());
				}
        }
	
}
Exemple #18
0
QString SceneImporter::ImportGroupNode(const QString &filename)
{
  QString projectFolder = Session::Get()->GetProjectFolder();
  if (filename.startsWith(projectFolder, Qt::CaseInsensitive))
    {
      // the file is aready within the project.
      // just chop of the project folder and we are done
      QString fn = filename;
      fn.replace(projectFolder, "", Qt::CaseInsensitive);
      return fn;
    }

  // group nodes get imported into the meshes folder
  QString meshesDestFolder = projectFolder + "/meshes/";

  // the same folder corresponds to the folder containing the xgroup file
  QFileInfo info (filename);
  QString meshesSrcFolder = info.absolutePath();

  // all the mesh files are located wihtin a subfolder with the same name
  // as the filename of the xgroup file
  QString subDir = info.completeBaseName();
  QString groupFileName = info.fileName();

  // now test if the dest file or the dest folder already exists
  QDir testFile (meshesDestFolder + "/" + groupFileName);
  QDir testFolder (meshesDestFolder + "/" + subDir);
  if (testFile.exists() || testFolder.exists())
    {
      // they already exist... so we cannot add it
      return QString::Null();
    }

  // create the subfolder where the mesh files will get stored
  QDir destDir (meshesDestFolder);
  if (!destDir.mkdir(subDir))
    {
      return QString::Null();
    }

  // scan all the source files
  QDir srcFolder (meshesSrcFolder + "/" + subDir);
  QFileInfoList files = srcFolder.entryInfoList();
  foreach (QFileInfo fi, files)
    {
      if (fi.isFile())
        {
          QFile::copy(fi.absoluteFilePath(), meshesDestFolder + "/" + subDir + "/" + fi.fileName());
        }
    }
  QFile::copy (filename, meshesDestFolder + "/" + groupFileName);

  QString fn = meshesDestFolder + "/" + groupFileName;
  fn.replace(projectFolder, "", Qt::CaseInsensitive);
  return fn;
}
Exemple #19
0
// Loads file from "Segmentino" output.
void SegmentController::loadFile()
{
    // Guess filename from audio file:
    QString audioFilename = Dispatch::getAudioFilename();
    QFileInfo finfo = QFileInfo(audioFilename);
    QString path = finfo.path();
    QString basename = finfo.completeBaseName();
    QString filename = path + "/" + basename
            + "_vamp_segmentino_segmentino_segmentation.csv";
    loadFile(filename);
}
void Adiciona_musica_album::on_ok_cancel_browse_accepted()
{
    QModelIndexList lista_temp;
    QVariant verifica;
    bool verifica_exist;
    verifica_exist = false;
    QFileInfo file;
    int it = 0;

    lista_temp = ui_ama->listView->selectionModel()->selectedIndexes();

    foreach(const QModelIndex &index, lista_temp) // ciclo que percorre as musicas seleccionadas
    {

        verifica = index.data().toString().toLocal8Bit().constData();
        if(!vec_ama.empty()) //verifica se vector que tem as musicas seleccionadas previamente está vazio
        {
            for(int l = 0; l < (int) vec_ama.size(); l++)
            {
                QString s = QString::fromStdString(vec_ama[l].nome);
                s = s + ".mp3";
                qDebug() << "s = " << s;
                qDebug() << "verifica = " << index.data().toString().toLocal8Bit().constData();
                if(strcmp(s.toLocal8Bit().constData(),index.data().toString().toLocal8Bit().constData()) == 0) //condição que impede a adição da mesma música 2 vezes
                {
                    verifica_exist = true;
                }
            }
            index.data().toString().toLocal8Bit().constData();
        }

        if(verifica_exist == false)
        {
            lista_ama.append(index.data(Qt::DisplayRole));
            file = QFileInfo(lista_ama.at(iterador).toString());
            iterador++;
        }

        if(strcmp(file.suffix().toLocal8Bit().constData(),"mp3") == 0 && verifica_exist == false) // verifica se o ficheiro é mp3
        {
            /*Caso a música seleccionada cumpra todos os requisitos anteriores, então será incluída em vec*/

            vec_ama.push_back(musicas());
            int i;
            i = vec_ama.size();
            i--;
                    vec_ama[i].path = filemodel->filePath(lista_temp.at(it));
                    vec_ama[i].extension = file.suffix();
                    vec_ama[i].nome = file.completeBaseName().toStdString();
                    vec_ama[i].empty = false;
                    it++;
         }
        verifica_exist = false;
    }
Exemple #21
0
ExifData ExifWrapper::doParse( eLookup type, const QString& path )
{
    QFileInfo info (path);
    ExifData data;
    data.FilePath = path;
    data.Extention = info.suffix();
    data.FileName = info.completeBaseName();
    data.AbsolutePath = info.absolutePath();

    BaseLookup* lookup = NULL;
    if (type == EXIFTOOL) {
        lookup = new ExifToolLookup;
    }
    else {
        lookup = new Exiv2Lookup;
    }
    QString processPath = this->osSpecificPath() + lookup->processName() + this->osSpecificExtension();

#if defined (Q_WS_WIN) || defined( Q_WS_MAC)
    if (!QFile::exists(processPath) ) {
        qCritical() << "process not found" << processPath;
    }
#endif

    // start process
    QStringList args;
    args << lookup->processParams() << path;
    QProcess* process = new QProcess;

    process->start(processPath, args);
    // and wait for it to finish
    process->waitForReadyRead();
    process->waitForFinished();

    // make sure we have all events processed
    //qApp->processEvents();

    // now read and parse the result
    QByteArray bytes = process->readAllStandardOutput();
    QString message(bytes.constData());
    QStringList result = message.split("\n");

    data.CreateDate = ExifDate(findValue(result, lookup->createDate()));
    data.CameraModel = findValue(result, lookup->cameraModel());
    data.CameraMake = findValue(result, lookup->cameraMake());
    data.MimeType = findValue(result, lookup->mimeType());
    
    delete process;
    delete lookup;
    // finally data should be up-to-date
    return data;
}
QString RotoCanvas::getSeqName(QFileInfo frameFI)
{
    QString result;
    QString baseName=frameFI.completeBaseName(); //baseName would get file from file.tar.gz or from file.myvideo0000.png, where completeBaseName gets file.tar or file.myvideo0000
    result=baseName;
    // now remove any trailing digits to get the "sequence name":
    int newLength=result.length();
    while ( newLength>0 && baseName.at(newLength-1).isDigit() ) {
        newLength--;
    }
    if (newLength!=result.length()) result = result.left(newLength);
    return result;
}
void MainWindow::RecurseDirectory(const QString &dir)
{
    QDir dirEnt(dir);
    QFileInfoList list = dirEnt.entryInfoList();
    for (int i = 0; i < list.count() && !recursiveLoaderDone;i++)
    {
        recursiveLoaderCounter++;
        QFileInfo info = list[i];

        QString filePath = info.filePath();
        QString fileExt = info.suffix().toLower();
        QString name = dir + QDir::separator();
        if (info.isDir())
        {
            // recursive
            if (info.fileName()!=".." && info.fileName()!=".")
                RecurseDirectory(filePath);
        }
        else if(imageExtensions.contains(fileExt))
        {
            if(!QFile::exists(name+info.completeBaseName()+QString(".atlas")))
            {
                ui->tilesList->addItem(filePath.replace(topImageDir, ""));
                packerData * data = new packerData;
                data->listItem = ui->tilesList->item(ui->tilesList->count() - 1);
                data->path = info.absoluteFilePath();
                packer.addItem(data->path, data);
            }
        }
        if(recursiveLoaderCounter == 500)
        {
            if(QMessageBox::No ==
                    QMessageBox::question(
                        this,
                        tr("Directory is too big"),
                        tr("It seems that directory <b>") + topImageDir +
                        tr("</b> is too big. "
                           "Loading may take HUGE amount of time and memory. "
                           "Please, check directory again. <br>"
                           "Do you want to continue?"),
                        QMessageBox::Yes,
                        QMessageBox::No))
            {
                recursiveLoaderDone = true;
                recursiveLoaderCounter++;
                continue;
            }
            ui->previewWithImages->setChecked(false);
        }
    }
}
QUrl SDeclarativeStyleInternal::toolBarIconPath(const QUrl &path, bool inverted) const
{
    if (!path.isEmpty()) {
        const QString scheme = path.scheme();
        const QFileInfo fileInfo = path.path();
        const QString completeBaseName = fileInfo.completeBaseName();

        if ((scheme.isEmpty() || scheme == QLatin1String("file") || scheme == QLatin1String("qrc"))
            && completeBaseName.startsWith(QLatin1String("toolbar-"))
            && completeBaseName.lastIndexOf(QLatin1Char('.')) == -1)
                return imagePath(completeBaseName, inverted);
    }
    return path;
}
Exemple #25
0
//the format defaults to "PNG" if not specified
void QgsMapCanvas::saveAsImage( const QString& theFileName, QPixmap * theQPixmap, const QString& theFormat )
{
  //
  //check if the optional QPaintDevice was supplied
  //
  if ( theQPixmap != NULL )
  {
    // render
    QPainter painter;
    painter.begin( theQPixmap );
    QgsMapRendererCustomPainterJob job( mSettings, &painter );
    job.start();
    job.waitForFinished();
    emit renderComplete( &painter );
    painter.end();

    theQPixmap->save( theFileName, theFormat.toLocal8Bit().data() );
  }
  else //use the map view
  {
    mMap->contentImage().save( theFileName, theFormat.toLocal8Bit().data() );
  }
  //create a world file to go with the image...
  QgsRectangle myRect = mapSettings().visibleExtent();
  QString myHeader;
  // note: use 17 places of precision for all numbers output
  //Pixel XDim
  myHeader += qgsDoubleToString( mapUnitsPerPixel() ) + "\r\n";
  //Rotation on y axis - hard coded
  myHeader += "0 \r\n";
  //Rotation on x axis - hard coded
  myHeader += "0 \r\n";
  //Pixel YDim - almost always negative - see
  //http://en.wikipedia.org/wiki/World_file#cite_note-2
  myHeader += '-' + qgsDoubleToString( mapUnitsPerPixel() ) + "\r\n";
  //Origin X (center of top left cell)
  myHeader += qgsDoubleToString( myRect.xMinimum() + ( mapUnitsPerPixel() / 2 ) ) + "\r\n";
  //Origin Y (center of top left cell)
  myHeader += qgsDoubleToString( myRect.yMaximum() - ( mapUnitsPerPixel() / 2 ) ) + "\r\n";
  QFileInfo myInfo  = QFileInfo( theFileName );
  // allow dotted names
  QString myWorldFileName = myInfo.absolutePath() + '/' + myInfo.completeBaseName() + '.' + theFormat + 'w';
  QFile myWorldFile( myWorldFileName );
  if ( !myWorldFile.open( QIODevice::WriteOnly ) ) //don't use QIODevice::Text
  {
    return;
  }
  QTextStream myStream( &myWorldFile );
  myStream << myHeader;
} // saveAsImage
void QGTManagerItem::loadModel(const QFileInfo &fileInfo) {
	if (this->m_isValid = fileInfo.exists()) {
		this->m_fileInfo = fileInfo;
		this->m_model = new Model(
				fileInfo.canonicalFilePath().toStdString(),
				fileInfo.completeBaseName().toStdString());
		if (Settings::instance().applicationSettings().usingPrebuiltKdTree()) {
			this->m_model->updateKdTree();
		}
	} else {
		this->m_fileInfo = QFileInfo();
		this->m_model = new Model();
	}
	this->m_defaultProvider = new Provider(this->m_model);
	this->m_defaultRenderer = new Renderer(this->m_defaultProvider);
}
Exemple #27
0
void PluginTransfer::onStreamsRequestFinished() {
    if (m_streamsRequest->status() == ResourcesRequest::Ready) {
        const QVariantMap result = m_streamsRequest->result().toMap();
        
        if (result.contains("items")) {
            const QVariantList list = result.value("items").toList();
            
            foreach (const QVariant &v, list) {
                const QVariantMap stream = v.toMap();
                
                if (stream.value("id") == streamId()) {
                    const QFileInfo info(downloadPath() + fileName());
                    QString suffix = info.suffix();
                    
                    if (suffix.isEmpty()) {
                        suffix = stream.value("ext").toString();
                        
                        if (!suffix.isEmpty()) {
                            if (!suffix.startsWith(".")) {
                                suffix.prepend(".");
                            }
                            
                            setFileName(info.completeBaseName() + suffix);
                        }
                    }
                    
                    startDownload(stream.value("url").toString());
                    return;
                }
            }
        }
        else if (result.contains("service")) {
            const QString service = result.value("service").toString();
            
            if (service == Resources::SOUNDCLOUD) {
                soundcloudStreamsRequest()->get(result.value("id").toString());
            }
            else {
                setErrorString(tr("Attempted redirect to unsupported service '%1'").arg(service));
                Logger::log("PluginTransfer::onStreamsRequestFinished(). Error: " + errorString());
                setStatus(Failed);
            }
            
            return;
        }
    }
Exemple #28
0
QString ModelBaker::createBaseTextureFileName(const QFileInfo& textureFileInfo) {
    // first make sure we have a unique base name for this texture
    // in case another texture referenced by this model has the same base name
    auto& nameMatches = _textureNameMatchCount[textureFileInfo.baseName()];

    QString baseTextureFileName{ textureFileInfo.completeBaseName() };

    if (nameMatches > 0) {
        // there are already nameMatches texture with this name
        // append - and that number to our baked texture file name so that it is unique
        baseTextureFileName += "-" + QString::number(nameMatches);
    }

    // increment the number of name matches
    ++nameMatches;

    return baseTextureFileName;
}
int RotoCanvas::getSeqDigitCount(QFileInfo frameFI)
{
    int result=-1;
    QString baseName=frameFI.completeBaseName();
    int digitCount=0;
    int index=baseName.length()-1;
    while (index>=0) {
        if (baseName.at(index).isDigit()) {
            index--;
            digitCount++;
        }
        else {
            break;
        }
    }
    if (digitCount>0) result=digitCount; // result=baseName.left(baseName.length()-digitCount).toInt();
    return result;
}
void AddFilmWindow::OpenFilm()
{
    QString openPath = eFilmFileName->text();

    if( openPath.isEmpty() )
    {
        openPath = settings->GetLastFilmPath();
    }

    QFileInfo fileName = QFileDialog::getOpenFileName( this, tr("Select film"), openPath,
                                                       tr("Video files (%1)").arg( FilesExtensions::GetFilmExtensionsForFilter() ) );

    if( fileName.isFile() )
    {
        eFilmFileName->setText( fileName.absoluteFilePath() );

          // Set the file name, title and year (if presents in file name)
        QString title = fileName.completeBaseName();
        int year = 0;

        if( eTitle->text().isEmpty() )
        {
            eTitle->setText( FilmItem::GetClearedTitle( title, &year ) );
        }

        if( sbYear->value() == sbYear->minimum() )
        {
            sbYear->setValue( year );
        }

          // Setting the path to the image file, if found in the same directory
        QString posterFileName = FilesExtensions::SearchForEponymousImage( fileName.absoluteFilePath() );

        if( !posterFileName.isEmpty() )
        {
            ePosterFileName->setText( posterFileName );
            bOpenPoster->setText( tr("Clear") );
        }

        settings->SetLastFilmPath( fileName.absolutePath() );
        bOpenPoster->setFocus();
    }
}