void SnapshotsFile::_processDirectory(const QString& sessionId, const QDir& rootDir, QMap<QString,Snapshot>& snapshotList) const { if (!rootDir.exists()) { return; } QDirIterator dit(rootDir.absolutePath(), QDir::NoFilter); while (dit.hasNext()) { dit.next(); // skip "." and ".." entries if (dit.fileName() == "." || dit.fileName() == "..") { continue; } QString fileName = dit.fileInfo().fileName(); if (dit.fileInfo().isFile()) { if (fileName.endsWith(SUFFIX)) { QString strippedFileName = fileName.left( fileName.length() - SUFFIX.length()); if ( !snapshotList.contains( strippedFileName ) ){ snapshotList.insert(strippedFileName, Snapshot(strippedFileName)); } QString dirName = rootDir.dirName(); if ( dirName == BASE_DIR ){ QDateTime lastModify = dit.fileInfo().lastModified(); QString lastModifyStr = lastModify.toString("ddd MMMM d yyyy"); snapshotList[strippedFileName].setCreatedDate( lastModifyStr ); QString description = read( sessionId, Carta::State::CartaObject::SNAPSHOT_INFO, strippedFileName); snapshotList[strippedFileName].setDescription( description ); } else { //Add in the state interfaces QString rootName = rootDir.dirName(); snapshotList[strippedFileName].setState(rootName, true); } } } else if (dit.fileInfo().isDir()){ QString subDirPath = dit.fileInfo().absoluteFilePath(); QDir subDir( subDirPath ); _processDirectory( sessionId, subDir, snapshotList); } } }
// collect_folder_contents void collect_folder_contents( BDirectory& dir, BList& list, bool& deep, bool& asked, BEntry& entry ) { while ( dir.GetNextEntry( &entry, true ) == B_OK ) { if ( !entry.IsDirectory() ) { BPath path; // since the directory will give us the entries in reverse order, // we put them each at the same index, effectively reversing the // items while adding them if ( entry.GetPath( &path ) == B_OK ) { BString* string = new BString( path.Path() ); if ( !list.AddItem( string, 0 ) ) delete string; // at least don't leak } } else { if ( !asked ) { // ask user if we should parse sub-folders as well BAlert* alert = new BAlert( "sub-folders?", _("Open files from all sub-folders as well?"), _("Cancel"), _("Open"), NULL, B_WIDTH_AS_USUAL, B_IDEA_ALERT ); int32 buttonIndex = alert->Go(); deep = buttonIndex == 1; asked = true; // never delete BAlerts!! } if ( deep ) { BDirectory subDir( &entry ); if ( subDir.InitCheck() == B_OK ) collect_folder_contents( subDir, list, deep, asked, entry ); } } } }
/* Helper function to initialize the Coral path. */ static void addDefaultPaths() { // if the CORAL_PATH environment variable is specified, add it to the path char* coralPathEnv = getenv( "CORAL_PATH" ); if( coralPathEnv ) co::addPath( coralPathEnv ); // add the '~/modules' dir (relative to the executable's dir) to the path std::string path; if( co::OS::getApplicationDir( path ) ) { path.append( "/modules" ); if( co::OS::isDir( path ) ) co::addPath( path ); } else { std::cerr << "Oops! Could not determine the current executable's path.\n"; } // add the current working dir to the path if( co::OS::getCurrentWorkingDir( path ) ) { // if the CWD contains a './modules' subdir, add it instead std::string subDir( path ); subDir.append( "/modules" ); if( co::OS::isDir( subDir ) ) co::addPath( subDir ); else co::addPath( path ); } else { std::cerr << "Oops! Could not determine the current working directory.\n"; } #if defined(CORAL_PATH) // if specified at compile time, add the contents of 'CORAL_PATH' to the path; co::addPath( CORAL_PATH ); #endif }
void NewProjectDlg::locationChanged( const QString & ) { m_location = m_pWidget->projectLocationURL->url(); QDir subDir(m_location); if ( !m_location.endsWith("/") ) m_location.append("/"); if ( !m_pWidget->projectNameEdit->text().isEmpty() ) m_location.append( m_pWidget->projectNameEdit->text().lower() + "/" ); m_pWidget->locationLabel->setText( m_location ); QDir dir(m_location); if ( dir.exists() || !subDir.exists() ) enableButtonOK(false); else enableButtonOK(true); }
void NewProjectDlg::locationChanged( const QString & ) { m_location = m_pWidget->projectLocationURL->url().toLocalFile(); qDebug() << "location changed to: " << m_location; QDir subDir(m_location); if ( !m_location.endsWith("/") ) m_location.append("/"); if ( !m_pWidget->projectNameEdit->text().isEmpty() ) m_location.append( m_pWidget->projectNameEdit->text().toLower() + "/" ); m_pWidget->locationLabel->setText( m_location ); QDir dir(m_location); qDebug() << "dir.exists: " << dir.exists() << " subdir.exists: " << subDir.exists(); if ( dir.exists() || !subDir.exists() ) { enableButtonOk(false); } else { enableButtonOk(true); } }
ProFileEditorWidget::Link ProFileEditorWidget::findLinkAt(const QTextCursor &cursor, bool /*resolveTarget*/, bool /*inNextSplit*/) { Link link; int lineNumber = 0, positionInBlock = 0; convertPosition(cursor.position(), &lineNumber, &positionInBlock); const QString block = cursor.block().text(); // check if the current position is commented out const int hashPos = block.indexOf(QLatin1Char('#')); if (hashPos >= 0 && hashPos < positionInBlock) return link; // find the beginning of a filename QString buffer; int beginPos = positionInBlock - 1; while (beginPos >= 0) { QChar c = block.at(beginPos); if (isValidFileNameChar(c)) { buffer.prepend(c); beginPos--; } else { break; } } // find the end of a filename int endPos = positionInBlock; while (endPos < block.count()) { QChar c = block.at(endPos); if (isValidFileNameChar(c)) { buffer.append(c); endPos++; } else { break; } } if (buffer.isEmpty()) return link; // remove trailing '\' since it can be line continuation char if (buffer.at(buffer.size() - 1) == QLatin1Char('\\')) { buffer.chop(1); endPos--; } // if the buffer starts with $$PWD accept it if (buffer.startsWith(QLatin1String("PWD/")) || buffer.startsWith(QLatin1String("PWD\\"))) { if (beginPos > 0 && block.mid(beginPos - 1, 2) == QLatin1String("$$")) { beginPos -=2; buffer = buffer.mid(4); } } QDir dir(QFileInfo(textDocument()->filePath()).absolutePath()); QString fileName = dir.filePath(buffer); QFileInfo fi(fileName); if (fi.exists()) { if (fi.isDir()) { QDir subDir(fi.absoluteFilePath()); QString subProject = subDir.filePath(subDir.dirName() + QLatin1String(".pro")); if (QFileInfo::exists(subProject)) fileName = subProject; else return link; } link.targetFileName = QDir::cleanPath(fileName); link.linkTextStart = cursor.position() - positionInBlock + beginPos + 1; link.linkTextEnd = cursor.position() - positionInBlock + endPos; } return link; }
int UPnpMedia::buildFileList(QString directory, int rootID, int itemID, MSqlQuery &query) { int parentid; QDir vidDir(directory); //VERBOSE(VB_UPNP, QString("buildFileList = %1, rootID = %2, itemID = //%3").arg(directory).arg(rootID).arg(itemID)); if (rootID > 0) parentid = rootID; else parentid = itemID; vidDir.setSorting( QDir::DirsFirst | QDir::Name ); QFileInfoList List = vidDir.entryInfoList(); // If we can't read it's contents move on if (List.isEmpty()) return itemID; for (QFileInfoList::iterator it = List.begin(); it != List.end(); ++it) { QFileInfo Info(*it); QString fName = Info.fileName(); QString fPath = Info.filePath(); // We don't want . or .. or something that specifically globs to // either. The "??" and "?" cases can happen when the backend is // running in a non-UTF-8 locale and comes across a UTF-8 filename if (fName == "." || fName == ".." || fName == "?" || fName == "??" || fName == ".?" || fName == "?.") continue; if (Info.isDir()) { // If we are about to recurse into the current directory (which // will cause an infinite recursive loop!), skip this entry. QDir subDir(fPath); if( subDir.canonicalPath() == vidDir.canonicalPath() ) continue; itemID++; query.prepare("INSERT INTO upnpmedia " "(intid, class, itemtype, parentid, itemproperties, " "filepath, filename, title, coverart) " "VALUES (:ITEMID, :ITEMCLASS, 'FOLDER', :PARENTID, '', " ":FILEPATH, :FILENAME, :TITLE, :COVERART)"); query.bindValue(":ITEMCLASS", sMediaType); query.bindValue(":ITEMID", itemID); query.bindValue(":PARENTID", parentid); query.bindValue(":FILEPATH", fPath); query.bindValue(":FILENAME", fName); query.bindValue(":TITLE", GetTitleName(fPath,fName)); query.bindValue(":COVERART", GetCoverArt(fPath)); if (!query.exec()) MythDB::DBError("UPnpMedia::buildFileList", query); itemID = buildFileList(fPath, 0, itemID, query); continue; } else { /* if (handler->validextensions.count() > 0) { QRegExp r; r.setPattern("^" + Info.suffix() + "$"); r.setCaseSensitive(false); QStringList result = handler->validextensions.grep(r); if (result.isEmpty()) { continue; } } */ itemID++; // VERBOSE(VB_UPNP, QString("UPnpMedia Video File : (%1) (%2)") // .arg(itemID) // .arg(fName)); query.prepare("INSERT INTO upnpmedia " "(intid, class, itemtype, parentid, itemproperties, " "filepath, filename, title, coverart) " "VALUES (:ITEMID, :ITEMCLASS, 'FILE', :PARENTID, '', " ":FILEPATH, :FILENAME, :TITLE, :COVERART)"); query.bindValue(":ITEMCLASS", sMediaType); query.bindValue(":ITEMID", itemID); query.bindValue(":PARENTID", parentid); query.bindValue(":FILEPATH", fPath); query.bindValue(":FILENAME", fName); query.bindValue(":TITLE", GetTitleName(fPath,fName)); query.bindValue(":COVERART", GetCoverArt(fPath)); if (!query.exec()) MythDB::DBError("UPnpMedia::buildFileList", query); } } return itemID; }
void ProFileEditorWidget::findLinkAt(const QTextCursor &cursor, Utils::ProcessLinkCallback &&processLinkCallback, bool /*resolveTarget*/, bool /*inNextSplit*/) { Link link; int line = 0; int column = 0; convertPosition(cursor.position(), &line, &column); const int positionInBlock = column - 1; const QString block = cursor.block().text(); // check if the current position is commented out const int hashPos = block.indexOf(QLatin1Char('#')); if (hashPos >= 0 && hashPos < positionInBlock) return processLinkCallback(link); // find the beginning of a filename QString buffer; int beginPos = positionInBlock - 1; int endPos = positionInBlock; // Check is cursor is somewhere on $${PWD}: const int chunkStart = std::max(0, positionInBlock - 7); const int chunkLength = 14 + std::min(0, positionInBlock - 7); QString chunk = block.mid(chunkStart, chunkLength); const QString curlyPwd = "$${PWD}"; const QString pwd = "$$PWD"; const int posCurlyPwd = chunk.indexOf(curlyPwd); const int posPwd = chunk.indexOf(pwd); bool doBackwardScan = true; if (posCurlyPwd >= 0) { const int end = chunkStart + posCurlyPwd + curlyPwd.count(); const int start = chunkStart + posCurlyPwd; if (start <= positionInBlock && end >= positionInBlock) { buffer = pwd; beginPos = chunkStart + posCurlyPwd - 1; endPos = end; doBackwardScan = false; } } else if (posPwd >= 0) { const int end = chunkStart + posPwd + pwd.count(); const int start = chunkStart + posPwd; if (start <= positionInBlock && end >= positionInBlock) { buffer = pwd; beginPos = start - 1; endPos = end; doBackwardScan = false; } } while (doBackwardScan && beginPos >= 0) { QChar c = block.at(beginPos); if (isValidFileNameChar(c)) { buffer.prepend(c); beginPos--; } else { break; } } if (doBackwardScan && beginPos > 0 && block.mid(beginPos - 1, pwd.count()) == pwd && (block.at(beginPos + pwd.count() - 1) == '/' || block.at(beginPos + pwd.count() - 1) == '\\')) { buffer.prepend("$$"); beginPos -= 2; } else if (doBackwardScan && beginPos >= curlyPwd.count() - 1 && block.mid(beginPos - curlyPwd.count() + 1, curlyPwd.count()) == curlyPwd) { buffer.prepend(pwd); beginPos -= curlyPwd.count(); } // find the end of a filename while (endPos < block.count()) { QChar c = block.at(endPos); if (isValidFileNameChar(c)) { buffer.append(c); endPos++; } else { break; } } if (buffer.isEmpty()) return processLinkCallback(link); // remove trailing '\' since it can be line continuation char if (buffer.at(buffer.size() - 1) == QLatin1Char('\\')) { buffer.chop(1); endPos--; } // if the buffer starts with $$PWD accept it if (buffer.startsWith("$$PWD/") || buffer.startsWith("$$PWD\\")) buffer = buffer.mid(6); QDir dir(textDocument()->filePath().toFileInfo().absolutePath()); QString fileName = dir.filePath(buffer); QFileInfo fi(fileName); if (fi.exists()) { if (fi.isDir()) { QDir subDir(fi.absoluteFilePath()); QString subProject = subDir.filePath(subDir.dirName() + QLatin1String(".pro")); if (QFileInfo::exists(subProject)) fileName = subProject; else return processLinkCallback(link); } link.targetFileName = QDir::cleanPath(fileName); link.linkTextStart = cursor.position() - positionInBlock + beginPos + 1; link.linkTextEnd = cursor.position() - positionInBlock + endPos; } processLinkCallback(link); }
static int dos_copydir(direntry_t *entry, MainParam_t *mp) /* copyes a directory to Dos */ { Arg_t * arg = (Arg_t *) (mp->arg); Arg_t newArg; time_t now; time_t date; int ret; const char *targetName = mpPickTargetName(mp); if (!arg->recursive && mp->basenameHasWildcard) return 0; if(entry && isSubdirOf(mp->targetDir, mp->File)) { fprintf(stderr, "Cannot recursively copy directory "); fprintPwd(stderr, entry,0); fprintf(stderr, " into one of its own subdirectories "); fprintPwd(stderr, getDirentry(mp->targetDir),0); fprintf(stderr, "\n"); return ERROR_ONE; } if (arg->mp.File->Class->get_data(arg->mp.File, & date, 0, 0, 0) < 0 ){ fprintf(stderr, "Can't stat source file\n"); return ERROR_ONE; } if(!arg->type && arg->verbose) fprintf(stderr,"Copying %s\n", mpGetBasename(mp)); if(entry && arg->preserveAttributes) arg->attr = entry->dir.attr; else arg->attr = 0; if (entry && (mp->targetDir == entry->Dir)){ arg->ch.ignore_entry = -1; arg->ch.source = entry->entry; } else { arg->ch.ignore_entry = -1; arg->ch.source = -2; } /* preserve mod time? */ if (arg->preserveTime) now = date; else getTimeNow(&now); newArg = *arg; newArg.mp.arg = &newArg; newArg.mp.targetName = 0; newArg.mp.basenameHasWildcard = 1; if(*targetName) { /* maybe the directory already exist. Use it */ newArg.mp.targetDir = subDir(mp->targetDir, targetName); if(!newArg.mp.targetDir) newArg.mp.targetDir = createDir(mp->targetDir, targetName, &arg->ch, arg->attr, now); } else newArg.mp.targetDir = mp->targetDir; if(!newArg.mp.targetDir) return ERROR_ONE; ret = mp->loop(mp->File, &newArg.mp, "*"); if(*targetName) FREE(&newArg.mp.targetDir); return ret | GOT_ONE; }
CMakeEditorWidget::Link CMakeEditorWidget::findLinkAt(const QTextCursor &cursor, bool/* resolveTarget*/, bool /*inNextSplit*/) { Link link; int lineNumber = 0, positionInBlock = 0; convertPosition(cursor.position(), &lineNumber, &positionInBlock); const QString block = cursor.block().text(); // check if the current position is commented out const int hashPos = block.indexOf(QLatin1Char('#')); if (hashPos >= 0 && hashPos < positionInBlock) return link; // find the beginning of a filename QString buffer; int beginPos = positionInBlock - 1; while (beginPos >= 0) { QChar c = block.at(beginPos); if (isValidFileNameChar(c)) { buffer.prepend(c); beginPos--; } else { break; } } // find the end of a filename int endPos = positionInBlock; while (endPos < block.count()) { QChar c = block.at(endPos); if (isValidFileNameChar(c)) { buffer.append(c); endPos++; } else { break; } } if (buffer.isEmpty()) return link; // TODO: Resolve variables QDir dir(textDocument()->filePath().toFileInfo().absolutePath()); QString fileName = dir.filePath(buffer); QFileInfo fi(fileName); if (fi.exists()) { if (fi.isDir()) { QDir subDir(fi.absoluteFilePath()); QString subProject = subDir.filePath(QLatin1String("CMakeLists.txt")); if (QFileInfo::exists(subProject)) fileName = subProject; else return link; } link.targetFileName = fileName; link.linkTextStart = cursor.position() - positionInBlock + beginPos + 1; link.linkTextEnd = cursor.position() - positionInBlock + endPos; } return link; }