QString BaseCheckoutWizard::openProject(const QString &path, QString *errorMessage) { ProjectExplorer::ProjectExplorerPlugin *pe = ProjectExplorer::ProjectExplorerPlugin::instance(); if (!pe) { *errorMessage = tr("The Project Explorer is not available."); return QString(); } // Search the directory for project files const QDir dir(path); if (!dir.exists()) { *errorMessage = tr("'%1' does not exist."). arg(QDir::toNativeSeparators(path)); // Should not happen return QString(); } QFileInfoList projectFiles = findProjectFiles(dir, errorMessage); if (projectFiles.empty()) return QString(); // Open. Do not use a busy cursor here as additional wizards might pop up const QString projectFile = projectFiles.front().absoluteFilePath(); if (!pe->openProject(projectFile, errorMessage)) return QString(); return projectFile; }
void MultiplayerDialog::updateLandscapesList() { QDir pluginsDirectory = QDir( m_environment.getLandscapesDirectory() ); if ( !pluginsDirectory.exists() ) return; QStringList filesFilter; filesFilter.push_back( Core::LandscapeModel::Resources::LandscapeFileFilter ); QFileInfoList filesList = pluginsDirectory.entryInfoList( filesFilter ); if ( filesList.empty() ) return; for ( int i = 0; i < filesList.size(); ++i ) { QFileInfo fileInfo = filesList.at( i ); m_landscapesList->addItem( fileInfo.fileName() ); } m_landscapesList->setCurrentItem( m_landscapesList->item( 0 ) ); } // MultiplayerDialog::updateLandscapesList
// Gets the newest file name (i.e. the one with the highest integer suffix). QString QBenchmarkValgrindUtils::getNewestFileName() { QStringList nameFilters; QString base = QBenchmarkGlobalData::current->callgrindOutFileBase; Q_ASSERT(!base.isEmpty()); nameFilters << QString::fromLatin1("%1.*").arg(base); QFileInfoList fiList = QDir().entryInfoList(nameFilters, QDir::Files | QDir::Readable); Q_ASSERT(!fiList.empty()); int hiSuffix = -1; QFileInfo lastFileInfo; const QString pattern = QString::fromLatin1("%1.(\\d+)").arg(base); const QRegExp rx(pattern); foreach (QFileInfo fileInfo, fiList) { const int index = rx.indexIn(fileInfo.fileName()); Q_ASSERT(index == 0); Q_UNUSED(index); bool ok; const int suffix = rx.cap(1).toInt(&ok); Q_ASSERT(ok); Q_ASSERT(suffix >= 0); if (suffix > hiSuffix) { lastFileInfo = fileInfo; hiSuffix = suffix; } } return lastFileInfo.fileName(); }
void Widget::updateFileTable() { totalDownloads = 0; QString dir = qApp->applicationDirPath(); QTreeWidgetItem * root = new QTreeWidgetItem(0); QTreeWidgetItem * tempItem = root; QTreeWidgetItem * tmp; QDir sncdr(dir + "/Sync"); QFileInfoList syncDir = sncdr.entryInfoList(QDir::NoDotAndDotDot|QDir::AllEntries); while(!syncDir.empty()) { if(syncDir.at(0).isDir()) { tmp = scanDirectory(syncDir.at(0).filePath()); tmp->setText(0, syncDir.at(0).fileName()); ftpFiles->addTopLevelItem(tmp); totalDownloads++; } else { tmp = new QTreeWidgetItem(0); tmp->setText(0, syncDir.at(0).fileName()); ftpFiles->addTopLevelItem(tmp); totalDownloads++; } syncDir.removeAt(0); } }
// Try to find the project files in a project directory with some smartness static QFileInfoList findProjectFiles(const QDir &projectDir, QString *errorMessage) { const QStringList projectFilePatterns = ProjectExplorer::ProjectExplorerPlugin::projectFilePatterns(); // Project directory QFileInfoList projectFiles = projectDir.entryInfoList(projectFilePatterns, QDir::Files|QDir::NoDotAndDotDot|QDir::Readable); if (!projectFiles.empty()) return projectFiles; // Try a 'src' directory QFileInfoList srcDirs = projectDir.entryInfoList(QStringList(QLatin1String("src")), QDir::Dirs|QDir::NoDotAndDotDot|QDir::Readable); if (srcDirs.empty()) { *errorMessage = msgNoProjectFiles(projectDir, projectFilePatterns); return QFileInfoList(); } const QDir srcDir = QDir(srcDirs.front().absoluteFilePath()); projectFiles = srcDir.entryInfoList(projectFilePatterns, QDir::Files|QDir::NoDotAndDotDot|QDir::Readable); if (projectFiles.empty()) { *errorMessage = msgNoProjectFiles(srcDir, projectFilePatterns); return QFileInfoList(); } return projectFiles; }
// find default skins (resources) static const Skins &defaultSkins() { static Skins rc; if (rc.empty()) { const QString skinPath = QLatin1String(skinResourcePathC); QString pattern = QLatin1String("*."); pattern += QLatin1String(skinExtensionC); const QDir dir(skinPath, pattern); const QFileInfoList list = dir.entryInfoList(QDir::Dirs|QDir::NoDotAndDotDot, QDir::Name); if (list.empty()) return rc; const QFileInfoList::const_iterator lcend = list.constEnd(); for (QFileInfoList::const_iterator it = list.constBegin(); it != lcend; ++it) rc.push_back(SkinNamePath(it->baseName(), it->filePath())); } return rc; }
QString BaseCheckoutWizardFactory::openProject(const Utils::FileName &path, QString *errorMessage) { // Search the directory for project files const QDir dir(path.toString()); if (!dir.exists()) { *errorMessage = tr("\"%1\" does not exist."). arg(path.toUserOutput()); // Should not happen return QString(); } QFileInfoList projectFiles = findProjectFiles(dir, errorMessage); if (projectFiles.empty()) return QString(); // Open. Do not use a busy cursor here as additional wizards might pop up const QString projectFile = projectFiles.front().absoluteFilePath(); if (!ProjectExplorer::ProjectExplorerPlugin::instance()->openProject(projectFile, errorMessage)) return QString(); return projectFile; }
void StrainPipeData::init() { QFileInfo recipefi(directory.absoluteFilePath() + "/logdir/1.RECIPEFILE"); recipefi.exists() ? recipie.reset(new RecipieList(recipefi)) : recipie.reset(new RecipieList()); base_dir.setNameFilters(QStringList("metric_*quast.csv")); QFileInfoList quastFiles=base_dir.entryInfoList(); quastFiles.empty() ? questMetrics.reset(new QuastMetrics()) : questMetrics.reset(new QuastMetrics(quastFiles.first())); base_dir.setNameFilters(QStringList("metric_*cgal.csv")); QFileInfoList cgalFiles = base_dir.entryInfoList(); cgalFiles.empty() ? cgalMetrics.reset(new CgalMetrics()) : cgalMetrics.reset(new CgalMetrics(cgalFiles.first())); base_dir.setNameFilters(QStringList("metric_*ale.csv")); QFileInfoList aleFiles=base_dir.entryInfoList(); aleFiles.empty() ? aleMetrics.reset(new AleMetrics()) : aleMetrics.reset(new AleMetrics(aleFiles.first())); QString timesFilename = base_dir.absolutePath() + "/logdir/1stats/allstats.csv"; QFileInfo tfi(timesFilename); tfi.exists() ? runTimes.reset(new RunTimes(tfi , base_dir.dirName() , directory.absolutePath())) : runTimes.reset(new RunTimes()); // register the plot document object (only needed once, no matter how many // plots will be in the QTextDocument): QCPDocumentObject *plotObjectHandler = new QCPDocumentObject(); QTextDocument::documentLayout()-> registerHandler(QCPDocumentObject::PlotTextFormat, plotObjectHandler); }
void OBSRemux::beginRemux() { if (worker->isWorking) { stopRemux(); return; } bool proceedWithRemux = true; QFileInfoList overwriteFiles = queueModel->checkForOverwrites(); if (!overwriteFiles.empty()) { QString message = QTStr("Remux.FileExists"); message += "\n\n"; for (QFileInfo fileInfo : overwriteFiles) message += fileInfo.canonicalFilePath() + "\n"; if (OBSMessageBox::question(this, QTStr("Remux.FileExistsTitle"), message) != QMessageBox::Yes) proceedWithRemux = false; } if (!proceedWithRemux) return; // Set all jobs to "pending" first. queueModel->beginProcessing(); ui->progressBar->setVisible(true); ui->buttonBox->button(QDialogButtonBox::Ok)-> setText(QTStr("Remux.Stop")); setAcceptDrops(false); remuxNextEntry(); }
void Lib_initializer::load_python_group_scripts() { SmartPtr<Named_interface> ni = Root::instance()->interface(python_group_script_manager); Manager* mng = dynamic_cast<Manager*> (ni.raw_ptr()); appli_assert( mng ); std::string python_scripts_path(mng->plugin_path()); QString path(python_scripts_path.c_str()); // Loop on all the python scripts (*.py) in directory "path" QDir dir(path); QStringList filters; filters << "*.py"; dir.setNameFilters(filters); dir.setFilter(QDir::Files); const QFileInfoList list = dir.entryInfoList(); if (list.empty()) { // GsTLcerr << "No python scripts could be found.\n" << "Check that environment variable GSTLAPPLIHOME is set to " << "where SGeMS was installed\n" // << "or that directory plugins/ " + mng->plugin_path() + " contains python script files \n" << gstlIO::end; return; } QFileInfoList::const_iterator it = list.begin(); const QFileInfo* f_info = 0; for (; it != list.end(); ++it) { f_info = &(*it); // QLibrary wants the absolute path QString full_path = path + "/" + f_info->fileName(); QByteArray s1 = full_path.toLatin1(); QByteArray s2 = f_info->baseName().toLatin1(); Root::instance()->new_interface("pythongroupscript://" + std::string(s1.constData()), python_group_script_manager + "/" + std::string(s2.constData())); } }
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; }
// find default skins (resources) static const Skins &defaultSkins() { static Skins rc; if (rc.empty()) { #ifdef DEFAULT_SKINS_FROM_RESOURCE const QString skinPath = QLatin1String(skinResourcePathC); #else QString skinPath = QLibraryInfo::location(QLibraryInfo::PrefixPath); skinPath += QDir::separator(); skinPath += QLatin1String("tools"); skinPath += QDir::separator(); skinPath += QLatin1String("qvfb"); #endif QString pattern = QLatin1String("*."); pattern += QLatin1String(skinExtensionC); const QDir dir(skinPath, pattern); const QFileInfoList list = dir.entryInfoList(); if (list.empty()) return rc; const QFileInfoList::const_iterator lcend = list.constEnd(); for (QFileInfoList::const_iterator it = list.constBegin(); it != lcend; ++it) rc.push_back(SkinNamePath(it->baseName(), it->filePath())); } return rc; }
void ObjectWorkspace::UpdateResourceLists() { // If the context path in the registry is not valid, this will not be entered if (dtDAL::Project::GetInstance().IsContextValid()) { assert(!mContextPath.empty()); QDir directory(mContextPath.c_str()); if (directory.cd(QString(mContextPath.c_str()) + "/shaders")) { QStringList nameFilters; nameFilters << "*.xml"; QFileInfoList fileList = directory.entryInfoList(nameFilters, QDir::Files); // Try to load all definitions while (!fileList.empty()) { QFileInfo fileInfo = fileList.takeFirst(); mShaderDefinitionName = QString("%1/shaders/%2").arg(QString(mContextPath.c_str()), fileInfo.fileName()); emit LoadShaderDefinition(mShaderDefinitionName); } directory.cdUp(); } // Now load all the additional shader files in the shader lists. for (int shaderIndex = 0; shaderIndex < mAdditionalShaderFiles.size(); shaderIndex++) { emit LoadShaderDefinition(mAdditionalShaderFiles.at(shaderIndex).c_str()); } // Populate the map list. QStringList mapList; std::set<std::string> mapNames = dtDAL::Project::GetInstance().GetMapNames(); for (std::set<std::string>::iterator map = mapNames.begin(); map != mapNames.end(); map++) { mapList << map->c_str(); } for (int mapIndex = 0; mapIndex < mapList.size(); mapIndex++) { mResourceDock->OnNewMap(mapList.at(mapIndex).toStdString()); } // Populate the object list. QString staticMeshDir = QString(mContextPath.c_str()) + "/staticmeshes"; if (directory.cd(staticMeshDir)) { QStringList nameFilters; nameFilters << "*.ive" << "*.osg"; QFileInfoList fileList = directory.entryInfoList(nameFilters, QDir::Files); while (!fileList.empty()) { QFileInfo fileInfo = fileList.takeFirst(); mResourceDock->OnNewGeometry(staticMeshDir.toStdString(), fileInfo.fileName().toStdString()); } } } }
void RecordingsModel::scanRecords(const QString &path) { Q_ASSERT(mRecorder); // Current watching directories auto currentDirs = mWatcher->directories(); // Is the recursive search enabled auto recursiveSearch = mRecorder->recursiveSearch(); // Check if directory exists and add or remove it and // its subdirectories to the wathing list QDir dir(path); QStringList paths(path); if (dir.exists()) { // Check for subdirectories that should be added if (recursiveSearch) { QDirIterator it(path, QDir::Dirs, QDirIterator::Subdirectories); while (it.hasNext()) { paths << it.next(); } } mWatcher->addPaths(paths); } else { // Check for subdirectories that should be removed for (auto d: currentDirs) { if (d.startsWith(path)) { paths << d; } } mWatcher->removePaths(paths); } // Scan for updated and removed records for (int row = mData.size() - 1; row > -1; --row) { auto oldFileInfo = mData[row]; // Process entries only of the changed path if (oldFileInfo.absolutePath() != path) { continue; } QFileInfo newFileInfo(oldFileInfo); newFileInfo.refresh(); if (newFileInfo.exists()) { if (newFileInfo.lastModified() != oldFileInfo.lastModified()) { // The record was updated auto index = this->createIndex(row, 0); emit this->dataChanged(index, index, { Modified }); } } else { // The record was removed this->beginRemoveRows(QModelIndex(), row, row); mData.removeAt(row); this->endRemoveRows(); } } // Scan for new records auto flags = recursiveSearch ? QDirIterator::Subdirectories : QDirIterator::NoIteratorFlags; QDirIterator it(path, RecordingsModel::filters, QDir::Files, flags); QFileInfoList newRecords; while (it.hasNext()) { // Add a new record QFileInfo fileInfo(it.next()); if (!mData.contains(fileInfo)) { newRecords << fileInfo; } } if (!newRecords.empty()) { auto pos = mData.size(); this->beginInsertRows(QModelIndex(), pos, pos + newRecords.size() - 1); mData.append(newRecords); this->endInsertRows(); } }
void SynchroWindow::load(QString path) { QFileInfo fi(path); if (!fi.exists()) { QMessageBox::critical(0, "Synchro project", path + " doesn't exist"); return; } QDir dir(fi.dirPath(TRUE)); BrowserView * browser; path = dir.canonicalPath(); for (browser = browsers.first(); browser!= 0; browser = browsers.next()) { if (browser->get_dir().canonicalPath() == path) { QMessageBox::critical(0, "Project synchro", "Project instance already read"); return; } } if (has_backup_files(dir)) QMessageBox::critical(0, "Synchro project", path + " contains .bak files"); else if (! dir.mkdir("all.lock")) QMessageBox::critical(0, "Synchro project", (dir.exists("all.lock")) ? "\ The project is already locked by 'Project control' or 'Project syncho'\n\ (the directory '" + path +"/all.lock' exists)" : "Can't create directory '" + path +"/all.lock'"); else { QFileInfoList l = dir.entryInfoList("*.lock"); if (!l.empty()) { QList<QFileInfo>::iterator it = l.begin(); QFileInfo * pfi; QString ids; while (it != l.end()) { pfi = &(*it); if (pfi->isDir() && (my_baseName(*pfi) != "all")) ids += " " + my_baseName(*pfi); ++it; } if (! ids.isEmpty()) { QMessageBox::critical(0, "Synchro project", "The project " + path + " is edited by the users having these IDs :" + ids); dir.rmdir("all.lock"); return; } } Q3VBox * vbox = new Q3VBox(hbox); BrowserView * browser = new BrowserView(vbox); QApplication::setOverrideCursor(Qt::waitCursor); browser->set_project(dir); bool r = browser->get_project()->load(dir); QApplication::restoreOverrideCursor(); if (! r) { browser->close(); delete vbox; // note : all.lock will be deleted by BrowserView } else { if (browsers.isEmpty()) project_name = fi.fileName(); vbox->show(); browsers.append(browser); } } }
void Lib_initializer::load_action_plugins() { SmartPtr<Named_interface> ni = Root::instance()->interface(actions_manager); Manager* mng = dynamic_cast<Manager*> (ni.raw_ptr()); appli_assert( mng ); std::string action_plugin_path(mng->plugin_path()); QString path(action_plugin_path.c_str()); // Loop on all the library files (.so or .dll) in directory "path" QDir dir(path); QStringList filters; filters << "*.so" << "*.dll"; dir.setNameFilters(filters); dir.setFilter(QDir::Files); const QFileInfoList list = dir.entryInfoList(); if (list.empty()) { // GsTLlog << "No action plugin could be found.\n" << "Check that environment variable GSTLAPPLIHOME is set to " << "where SGeMS was installed\n" // << "or that directory plugins/actions actually contains plugins\n" << gstlIO::end; return; } QFileInfoList::const_iterator it = list.begin(); const QFileInfo* f_info; for (; it != list.end(); ++it) { f_info = &(*it); // QLibrary wants the absolute path QString abs_path(path + "/" + f_info->fileName()); QByteArray tmp = abs_path.toAscii(); GsTLlog << "Trying to load plug-in: " << tmp.constData() << "...\n"; QLibrary lib(abs_path); //lib.setAutoUnload( false ); lib.load(); if (!lib.isLoaded()) { GsTLlog << "The plug-in was not loaded: QLibrary::load failed. Aborting \n\n"; continue; } typedef int (*Init_func_prototype)(void); //// The function must be called [filename]_init() //QString init_func_name( f_info->baseName() + "_init" ); // The function must be called plugin_init() QString init_func_name = "plugin_init"; QByteArray tmp1 = init_func_name.toLatin1(); Init_func_prototype init_func = (Init_func_prototype) lib.resolve(tmp1.constData()); if (init_func) { init_func(); GsTLlog << "... OK\n\n"; } else { QByteArray n = init_func_name.toAscii(); GsTLlog << "unable to resolve symbol " << n.constData() << "\n\n"; } } Root::instance()->list_all(GsTLlog); }
void Lib_initializer::load_filters_plugins() { SmartPtr<Named_interface> ni = Root::instance()->interface(topLevelInputFilters_manager); Manager* mng = dynamic_cast<Manager*> (ni.raw_ptr()); appli_assert( mng ); std::string filters_plugin_path(mng->plugin_path()); QString path(filters_plugin_path.c_str()); // Loop on all the library files (.so or .dll) in directory "path" QDir dir(path); if (!dir.exists()) return; QStringList filters; filters << "*.so" << "*.dll"; dir.setNameFilters(filters); dir.setFilter(QDir::Files); const QFileInfoList list = dir.entryInfoList(); if (list.empty()) { GsTLlog << "No filter plugins found.\n" << gstlIO::end; return; } QFileInfoList::const_iterator it = list.begin(); const QFileInfo* f_info; for (; it != list.end(); ++it) { f_info = &(*it); // QLibrary wants the absolute path QString tmp = path + "/" + f_info->fileName(); QByteArray tmps = tmp.toLatin1(); appli_message( "loading file: " << tmps.constData()); QLibrary lib(path + "/" + f_info->fileName()); //lib.setAutoUnload( false ); lib.load(); if (!lib.isLoaded()) { appli_warning( "library not loaded " << std::endl ); continue; } typedef int (*Init_func_prototype)(void); // The function must be called [filename]_init() // QString init_func_name( f_info->baseName() + "_init" ); // The function must be called plugin_init() QString init_func_name = "plugin_init"; QByteArray tmp1 = init_func_name.toLatin1(); Init_func_prototype init_func = (Init_func_prototype) lib.resolve(tmp1.constData()); if (init_func) init_func(); else { QByteArray s = init_func_name.toLatin1(); appli_warning( "unable to resolve symbol " << s.constData() ); } } }