bool Polyhedron_demo_polylines_io_plugin::save(const Scene_item* item, QFileInfo fileinfo) { const Scene_polylines_item* poly_item = qobject_cast<const Scene_polylines_item*>(item); if(!poly_item) return false; std::ofstream out(fileinfo.filePath().toUtf8()); out.precision(17); if(!out) { std::cerr << "Error! Cannot open file " << (const char*)fileinfo.filePath().toUtf8() << std::endl; return false; } typedef Scene_polylines_item::Polylines_container Polylines_container; typedef Polylines_container::value_type Polyline; typedef Polyline::value_type Point_3; QStringList metadata = item->property("polylines metadata").toStringList(); BOOST_FOREACH(const Polyline& polyline, poly_item->polylines) { out << polyline.size(); BOOST_FOREACH(const Point_3& p, polyline) { out << " " << p.x() << " " << p.y() << " " << p.z(); } if(!metadata.isEmpty()) { out << " " << qPrintable(metadata.front()); metadata.pop_front(); } out << std::endl; } return (bool) out; }
void FileSystemWidget::renameFile() { QFileInfo info = contextFileInfo(); if (!info.isFile()) { return; } QString fileName = QInputDialog::getText(m_liteApp->mainWindow(), tr("Rename File"),tr("New Name:"), QLineEdit::Normal,info.fileName()); if (!fileName.isEmpty() && fileName != info.fileName()) { QDir dir = contextDir(); #ifdef Q_OS_WIN if (!MoveFileW(info.filePath().toStdWString().c_str(),QFileInfo(dir,fileName).filePath().toStdWString().c_str())) { QMessageBox::information(m_liteApp->mainWindow(),tr("Rename File"), tr("Failed to rename the file!")); } #else if (!QFile::rename(info.filePath(),QFileInfo(dir,fileName).filePath())) { QMessageBox::information(m_liteApp->mainWindow(),tr("Rename File"), tr("Failed to rename the file!")); } #endif } }
/* * If a file is double-clicked, * process it if it is an ROI image. */ void dc_viewer::onFileItemDoubleClicked(QModelIndex idx) { QFileInfo fileInfo = this->fileModel->fileInfo(idx); QString prefix; if ( this->isValidROIImage(fileInfo, prefix)) { QFileInfo fi; fi.setFile(fileInfo.path(), prefix); this->filePrefix = fi.filePath(); loadFiles(); setDepthLookupTable(); calculate3DData(); refreshAllLabels(); } }
void parseFile(const QFileInfo& file, bool force_update=false) { if(!file.exists())return; if(file.isSymLink())return; //skip files in skiplist if(skip_paths.contains(file.fileName()))return; //force update on our files if(!force_update)force_update=our_paths.contains(file.filePath()); if(file.isDir()) { QString name=file.baseName(); //ignore system dirs if(name.length()==0 || name.at(0)==QChar('.'))return; QDir dir(file.absoluteFilePath()); QFileInfoList list = dir.entryInfoList( QDir::NoDotAndDotDot|QDir::Readable|QDir::Dirs|QDir::Files, QDir::DirsFirst|QDir::Name); QFileInfoList::const_iterator iter=list.constBegin(); for(;iter!=list.constEnd(); ++iter) { qDebug()<<"... "<<iter->filePath(); parseFile(*iter,force_update); } return; } if(file.isFile()) { filereported=false;//reset flag QStringList exts; exts<<"cpp"<<"c"<<"hpp"<<"h"<<"java"<<"qml"; QString ext=file.completeSuffix().toLower(); if(exts.contains(ext)) { qDebug()<<"Parsing "<<file.baseName(); processCXXFile(file.absoluteFilePath(),force_update); } else if(file.baseName().toLower()=="makefile") { qDebug()<<"Parsing "<<file.baseName(); processMakeFile(file.absoluteFilePath(),force_update); } } }
/// Save the document under a new file name bool Document::saveAs(void) { getMainWindow()->showMessage(QObject::tr("Save document under new filename...")); QString exe = qApp->applicationName(); QString fn = QFileDialog::getSaveFileName(getMainWindow(), QObject::tr("Save %1 Document").arg(exe), FileDialog::getWorkingDirectory(), QObject::tr("%1 document (*.FCStd)").arg(exe)); if (!fn.isEmpty()) { FileDialog::setWorkingDirectory(fn); QString file = fn.toLower(); if (!file.endsWith(QLatin1String(".fcstd"))) { fn += QLatin1String(".fcstd"); QFileInfo fi; fi.setFile(fn); if (fi.exists()) { // if we auto-append the extension make sure that we don't override an existing file int ret = QMessageBox::question(getMainWindow(), QObject::tr("Save As"), QObject::tr("%1 already exists.\n" "Do you want to replace it?").arg(fn), QMessageBox::Yes|QMessageBox::Default, QMessageBox::No|QMessageBox::Escape); if (ret != QMessageBox::Yes) fn = QString(); } } } if (!fn.isEmpty()) { QFileInfo fi; fi.setFile(fn); QString bn = fi.baseName(); const char * DocName = App::GetApplication().getDocumentName(getDocument()); // save as new file name Gui::WaitCursor wc; Command::doCommand(Command::Doc,"App.getDocument(\"%s\").saveAs('%s')" , DocName, (const char*)fn.toUtf8()); setModified(false); getMainWindow()->appendRecentFile(fi.filePath()); return true; } else { getMainWindow()->showMessage(QObject::tr("Saving aborted"), 2000); return false; } }
bool Dymola::getFinalVariablesFromDsFile(QString fileName_, MOVector<Variable> *variables,QString modelName) { variables->clear(); QFileInfo fileinfo = QFileInfo(fileName_); bool result = false; if (fileinfo.exists()) { QFile file(fileinfo.filePath()); file.open(QIODevice::ReadOnly); QTextStream* in = new QTextStream(&file); result = getFinalVariablesFromDsFile(in, variables,modelName); file.close(); delete in; } return result; }
void KisCustomBrushWidget::slotAddPredefined() { // Save in the directory that is likely to be: ~/.kde/share/apps/krita/brushes // a unique file with this brushname QString dir = KGlobal::dirs()->saveLocation("data", "krita/brushes"); QString extension; if (brushStyle->currentIndex() == 0) { extension = ".gbr"; } else { extension = ".gih"; } QString name = nameLineEdit->text(); QString tempFileName; { QFileInfo fileInfo; fileInfo.setFile(dir + name + extension); int i = 1; while (fileInfo.exists()) { fileInfo.setFile(dir + name + QString("%1").arg(i) + extension); i++; } tempFileName = fileInfo.filePath(); } // Add it to the brush server, so that it automatically gets to the mediators, and // so to the other brush choosers can pick it up, if they want to if (m_rServerAdapter) { KisGbrBrush * resource = static_cast<KisGbrBrush*>( m_brush.data() )->clone(); resource->setFilename(tempFileName); if (nameLineEdit->text().isEmpty()){ resource->setName(QDateTime::currentDateTime().toString("yyyy-MM-ddThh:mm")); }else{ resource->setName( name ); } if (colorAsMask->isChecked()){ resource->makeMaskImage(); } m_rServerAdapter->addResource( resource ); } }
void QERecipe::setRecipeFile(QString pValue) { QDomElement rootElement; QFile *file; QString data; bool flag; recipeFile = pValue; document.clear(); if (recipeFile.isEmpty()) { QFileInfo fileInfo; fileInfo.setFile( defaultFileLocation(), QString( "QERecipe.xml" ) ); filename = fileInfo.filePath(); } else { filename = recipeFile; } file = openQEFile( filename, (QIODevice::OpenModeFlag)((int)(QFile::ReadOnly | QFile::Text)) ); if (file) { data = file->readAll(); file->close(); flag = document.setContent(data); } else { flag = false; } if (flag) { refreshRecipeList(); } else { rootElement = document.createElement("epicsqt"); document.appendChild(rootElement); } }
const QPixmap Skin::getPixmap (const QString& file, const QString &path) { QDir dir (path); dir.setFilter (QDir::Files|QDir::NoDotAndDotDot); QFileInfoList list = dir.entryInfoList(); for (int i = 0; i < list.size(); ++i) { QFileInfo fileInfo = list.at(i); QString fname = fileInfo.fileName().toLower(); if (fname.section(".", 0, 0) == file) { return QPixmap (fileInfo.filePath()); } } return QPixmap (); }
void GopathBrowser::renameFile() { QFileInfo info = contextFileInfo(); if (!info.isFile()) { return; } QString fileName = QInputDialog::getText(m_liteApp->mainWindow(), tr("Rename File"),tr("File Name"), QLineEdit::Normal,info.fileName()); if (!fileName.isEmpty() && fileName != info.fileName()) { QDir dir = contextDir(); if (!QFile::rename(info.filePath(),QFileInfo(dir,fileName).filePath())) { QMessageBox::information(m_liteApp->mainWindow(),tr("Rename File"), tr("Failed to rename the file!")); } } }
bool Polyhedron_demo_ply_to_xyz_plugin::save(const Scene_item* item, QFileInfo fileinfo) { // Check extension (quietly) std::string extension = fileinfo.suffix().toUtf8().data(); if (extension != "ply" && extension != "PLY") return false; // This plugin supports point sets const Scene_points_with_normal_item* point_set_item = qobject_cast<const Scene_points_with_normal_item*>(item); if(!point_set_item) return false; // Save point set as .xyz std::ofstream out(fileinfo.filePath().toUtf8().data()); return point_set_item->write_ply_point_set(out); }
void FileBrowser::removeFile() { QFileInfo info = contextFileInfo(); if (!info.isFile()) { return; } int ret = QMessageBox::question(m_liteApp->mainWindow(),tr("Delete File"), tr("Are you sure that you want to permanently delete this file?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No); if (ret == QMessageBox::Yes) { if (!QFile::remove(info.filePath())) { QMessageBox::information(m_liteApp->mainWindow(),tr("Delete File"), tr("Failed to delete the file!")); } } }
void ChannelConfigurationsWidget::rename() { QItemSelection selection = ui->configs->selectionModel()->selection(); if(selection.indexes().size() != 1) return; QModelIndex index = selection.indexes()[0]; QFileInfo file = m_model->fileInfo(index); KeyboardDialog keyboard(tr("Rename %1").arg(file.fileName())); keyboard.setInput(file.baseName()); RootController::ref().presentDialog(&keyboard); if(!QFile::rename(file.filePath(), file.path() + "/" + keyboard.input() + "." + file.completeSuffix())) { qWarning() << "Failed to change name"; // TODO: Make this error user visible return; } }
void FileSystemWidget::removeFile() { QFileInfo info = contextFileInfo(); if (!info.isFile()) { return; } int ret = QMessageBox::question(m_liteApp->mainWindow(),tr("Remove File"), tr("Confirm remove the file and continue"), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::No); if (ret == QMessageBox::Yes) { if (!QFile::remove(info.filePath())) { QMessageBox::information(m_liteApp->mainWindow(),tr("Remove File"), tr("Failed to remove the file!")); } } }
void ProjectExplorer::fileClick() { int row = -1; QString rootpath = m_FileSystemModel->rootPath() + QString("/"); QModelIndexList indexlist = m_TreeView->selectionModel()->selectedIndexes(); foreach(QModelIndex index, indexlist) { if(index.row() != row && index.column() == 0) { QFileInfo fileInfo = m_FileSystemModel->fileInfo(index); QString absoultepath = fileInfo.filePath(); QString file = absoultepath.remove(rootpath); row = index.row(); emit fileClicked(file); } } }
QUrl LiteDoc::parserUrl(const QUrl &_url) { QDir root(m_liteApp->resourcePath()+"/welcome"); QUrl url = _url; if (url.isRelative() && !url.path().isEmpty()) { QFileInfo info; if (url.path().at(0) == '/') { info.setFile(root,url.path().right(url.path().length()-1)); } else if (m_lastUrl.scheme() == "file") { info.setFile(QFileInfo(m_lastUrl.toLocalFile()).absoluteDir(),url.path()); } if (info.exists() && info.isFile()) { url.setScheme("file"); url.setPath(info.filePath()); } } return url; }
bool PS_demo_xyz_plugin::save(const Scene_item* item, QFileInfo fileinfo) { // Check extension (quietly) std::string extension = fileinfo.suffix().toUtf8().data(); if (extension != "xyz" && extension != "XYZ" && extension != "pwn" && extension != "PWN") return false; // This plugin supports point sets const Point_set_scene_item* point_set_item = qobject_cast<const Point_set_scene_item*>(item); if(!point_set_item) return false; // Save point set as .xyz std::ofstream out(fileinfo.filePath().toUtf8().data()); return point_set_item->write_xyz_point_set(out); }
bool ModPlusExeCtrl::getFinalVariablesFromFile(QString fileName_, MOVector<Variable> *variables,QString _modelName) { variables->clear(); QFileInfo fileinfo = QFileInfo(fileName_); if (fileinfo.exists()) { QFile file(fileinfo.filePath()); file.open(QIODevice::ReadOnly); QTextStream* in = new QTextStream(&file); bool ok = getFinalVariablesFromFile(in, variables,_modelName); file.close(); delete in; return ok; } else return true; }
void TEDemo::loadSessionCommands() { for (int local=0; local<=1; local++) { // KApplication could support this technique better QString path = local ? kapp->localkdedir() + "/share/apps/konsole" : kapp->kde_datadir() + "/konsole"; QDir d( path ); if(!d.exists()) return; d.setFilter( QDir::Files | QDir::Readable ); d.setNameFilter( "*.kdelnk" ); const QFileInfoList *list = d.entryInfoList(); QFileInfoListIterator it( *list ); for(QFileInfo *fi; (fi=it.current()); ++it ) addSessionCommand(fi->filePath()); } }
void GeoEngine::saveTileToDisk(QUrl url, QByteArray dat) { //ne sauve pas une image vide if(dat.size()==0) return; TuileParams params = extractParamsFromUrl(url.toString()); QFileInfo fileinfo = convertTileToFileInfo(params); QDir dir(fileinfo.absolutePath()); if(!dir.exists()) dir.mkpath(dir.path()); QFile cacheFile(fileinfo.filePath()); cacheFile.open(QIODevice::WriteOnly); cacheFile.write(dat); cacheFile.close(); }
bool FileSystem::fileExists(const QString& filename, const QFileInfo& fileInfo) { #ifdef Q_OS_WIN if (isLnkFile(filename)) { // Use a native check. return fileExistsWin(filename); } #endif bool re = fileInfo.exists(); // if the filename is different from the filename in fileInfo, the fileInfo is // not valid. There needs to be one initialised here. Otherwise the incoming // fileInfo is re-used. if( fileInfo.filePath() != filename ) { QFileInfo myFI(filename); re = myFI.exists(); } return re; }
bool save(const CGAL::Three::Scene_item* item, QFileInfo fileinfo) { const Scene_surface_mesh_item* sm_item = qobject_cast<const Scene_surface_mesh_item*>(item); if(!sm_item) return false; std::ofstream out(fileinfo.filePath().toUtf8()); out.precision (std::numeric_limits<double>::digits10 + 2); if(fileinfo.suffix().toLower() == "off"){ return (sm_item && sm_item->save(out)); } if(fileinfo.suffix().toLower() == "obj"){ return (sm_item && sm_item->save_obj(out)); } return false; }
void TSystem::readDirectoryTree(TFilePathSet &dst, const TFilePath &path, bool groupFrames, bool onlyFiles) { if (!TFileStatus(path).isDirectory()) throw TSystemException(path, " is not a directory"); QFileInfoList fil = QDir(toQString(path)).entryInfoList(); int i; for (i = 0; i < fil.size(); i++) { QFileInfo fi = fil.at(i); if (fi.fileName() == QString(".") || fi.fileName() == QString("..")) continue; TFilePath son = TFilePath(fi.filePath().toStdWString()); if (TFileStatus(son).isDirectory()) { if (!onlyFiles) dst.push_back(son); readDirectoryTree(dst, son, groupFrames, onlyFiles); } else dst.push_back(son); } }
bool Polyhedron_demo_gocad_plugin::save(const CGAL::Three::Scene_item* item, QFileInfo fileinfo) { // This plugin supports polyhedrons const Scene_polyhedron_item* poly_item = qobject_cast<const Scene_polyhedron_item*>(item); if(!poly_item) return false; std::ofstream out(fileinfo.filePath().toUtf8()); Polyhedron* poly = const_cast<Polyhedron*>(poly_item->polyhedron()); write_gocad(*poly, out, qPrintable(fileinfo.baseName())); return true; }
void CentralDirFileHeader::initFromFile( const QFileInfo& file ) { LocalFileHeader::initFromFile( file ); setPermissions( file.permissions(), file.isDir() ); // Windows Only: Add the files attributes to externalAttr (e.g. archive, readonly, system etc.) quint32 attr = getFileAttributes( file.filePath() ); if ( attr & 0x20 ) // Archive externalFileAttr |= 0x20; if ( attr & 0x10 ) // Folder externalFileAttr |= 0x10; if ( attr & 0x08 ) // System externalFileAttr |= 0x08; if ( attr & 0x02 ) // Hidden externalFileAttr |= 0x02; if ( attr & 0x01 ) // ReadOnly externalFileAttr |= 0x01; }
bool PS_demo_off_plugin::save(const Scene_item* item, QFileInfo fileinfo) { // Check extension (quietly) std::string extension = fileinfo.suffix().toUtf8().data(); if (extension != "off" && extension != "OFF") return false; // This plugin supports polyhedrons and point sets const Scene_polyhedron_item* poly_item = qobject_cast<const Scene_polyhedron_item*>(item); const Point_set_scene_item* point_set_item = qobject_cast<const Point_set_scene_item*>(item); if(!poly_item && !point_set_item) return false; // Save polyhedron/point set as .off std::ofstream out(fileinfo.filePath().toUtf8().data()); return (poly_item && poly_item->save(out)) || (point_set_item && point_set_item->write_off_point_set(out)); }
int IioAdaptor::addDevice(int device) { QDir dir(deviceGetPath(device)); if (!dir.exists()) { sensordLogW() << "Directory ??? doesn't exists"; return 1; } QStringList filters; filters << "*_raw"; dir.setNameFilters(filters); QFileInfoList list = dir.entryInfoList(); for (int i = 0; i < list.size(); ++i) { QFileInfo fileInfo = list.at(i); addPath(fileInfo.filePath(),device*IIO_MAX_DEVICE_CHANNELS+i); } return 0; }
void AppSettings::getThemes(QString selTheme, QString themeDir){ //Getting installed themes QString aughtor="", license=""; QDir tmp(themeDir); tmp.setFilter(QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot); QFileInfoList list = tmp.entryInfoList(); // Getting converted icons from temp directory for (int i = 0; i < list.size(); ++i) { QFileInfo fileInfo = list.at(i); std::auto_ptr<QListWidgetItem> iconItem (new QListWidgetItem(listThemesView, 0)); QFile file(QString("%1/%2/theme.info").arg(themeDir).arg(fileInfo.fileName())); if (file.open(QIODevice::ReadOnly | QIODevice::Text)){ aughtor = file.readLine(); aughtor.remove ( "\n" ); license = file.readLine(); } if ((!aughtor.isEmpty()) and (!license.isEmpty())){ iconItem->setText(QString("%1 [%2; %3]").arg(fileInfo.fileName()).arg(aughtor).arg(license)); } else { iconItem->setText(fileInfo.fileName()); } iconItem->setToolTip(QString("%1/%2").arg(themeDir).arg(fileInfo.fileName())); iconItem->setIcon(QIcon(QString("%1/%2/data/wine.png").arg(themeDir).arg(fileInfo.fileName()))); if (!selTheme.isNull()){ if (selTheme==fileInfo.filePath()){ //Setting selection to selected theme listThemesView->setCurrentItem(iconItem.release()); //Loading pixmaps from theme //loadThemeIcons(fileInfo.filePath()); } } } return; }
void NewProjectDialog::crearArchivoProyecto() { if(!checkDates()) { QMessageBox::warning(this,tr("ToolsPCot - New projecto"),tr("write de name of project")); return; } QString dirProyecto=ui->lineEditFolderProject->text(); //Casos de la direccion en windows o linux barras inclinadas QFileInfo archivo; archivo.setFile(QDir(dirProyecto),ui->lineEditProjectFile->text()); _aProyecto=new ArchivoProyecto(0,archivo.filePath()); _aProyecto->setnameProyect(ui->lineEditProject->text()); _aProyecto->setdescriptionProyecte(ui->textEditDescription->toPlainText()); _aProyecto->setautorProyect(ui->lineEditAutor->text()); _aProyecto->setdateflight(ui->dateEditDateFlight->date()); }
bool KExiv2::Private::saveToXMPSidecar(const QFileInfo& finfo) const { QString filePath = KExiv2::sidecarFilePathForFile(finfo.filePath()); if (filePath.isEmpty()) { return false; } try { Exiv2::Image::AutoPtr image; image = Exiv2::ImageFactory::create(Exiv2::ImageType::xmp, (const char*)(QFile::encodeName(filePath))); return saveOperations(finfo, image); } catch( Exiv2::Error& e ) { printExiv2ExceptionError("Cannot save metadata to XMP sidecar using Exiv2 ", e); return false; } }