/*! Generates fully qualified path of cached resource from a URL. */ QString QNetworkDiskCachePrivate::cacheFileName(const QUrl &url) const { if (!url.isValid()) return QString(); QString fullpath = dataDirectory + uniqueFileName(url); return fullpath; }
void Profiler::compareLists() { QList<QString> list2; QString dataDirectory2 = "/home/asehati/Desktop/build-GraphFetcher-online-Desktop-Debug"; dataDirectory2.append("/profiles2/"); //2 means old resource list QFile listFile2(dataDirectory2 + uniqueFileName(this->url)); if(!listFile2.exists()) { qDebug() << "The old resource list file does not exist in profiles2 directory"; return; } QTextStream in2(&listFile2); if (!listFile2.open(QIODevice::ReadOnly | QIODevice::Text)) { qDebug() << "Could not open " << listFile2.fileName(); return; } QString line; while (!in2.atEnd()) { line = in2.readLine(); list2.append(line); } int count = 0; QSet<QUrl>::ConstIterator it = urlSet.constBegin(),end = urlSet.constEnd(); for (; it != end; ++it) { if(list2.contains((*it).toString(QUrl::FullyEncoded))) { count++; // qDebug() << (*it).toString(QUrl::FullyEncoded); } } qDebug() << "The ratio of new list that is already in old list (usefulness): " << (double)count / (double)urlSet.size(); // format in file: url usefulness hitRate statOut << this->url << "\t" << (double)count / (double)urlSet.size() << "\t" << (double)count / (double)list2.size() << "\n"; statOut.flush(); statFile.close(); listFile2.close(); list2.clear(); urlSet.clear(); }
int YoutubeDL::download(const QString URL, QString destination, QString fileName, QStringList params, bool autoName) { if ( ! isYoutubeDLappInstalled()) return EnumYoutubeDL::YOUTUBE_DL_APP_MISSING; // clean destination dir destination = QDir::cleanPath(destination); #ifdef Q_OS_WIN32 // fix Qt4.4.0 bug in windows if (destination.indexOf(":/") == -1) destination.replace(":", ":/"); #endif // check if is already downloading another file if (isDownloading()) return EnumHTTP::ALREADY_DOWNLOADING; // create the destination path, if it don't exists if ( ! QDir(destination).exists()) if ( ! QDir(destination).mkpath(destination)) return EnumHTTP::UNABLE_CREATE_DIR; // set a default name (only if it is empty) if (fileName.isEmpty()) fileName = "download.file"; fileName = QFileInfo(fileName).fileName(); // set destination file name fileName = cleanFileName(fileName); // get an unique file name for this download if (autoName) fileName = uniqueFileName(destination + "/" + fileName); else fileName = destination + "/" + fileName; // set file info destinationFile = QFileInfo(fileName); // set as downloading resuming = false; // build the command line QStringList commandLine = QStringList() << "-o" << fileName << URL; foreach (QString value, params) { commandLine << value.split("=", QString::SkipEmptyParts); }
void Profiler::setUrl(const QString &value) { QString filePath = uniqueFileName(QUrl(value)); listFile.setFileName(dataDirectory + filePath); // listFile.setFileName("ObjectGaps.txt"); if(listFile.exists()) listFile.remove(); listFile.open(QIODevice::WriteOnly | QIODevice::Text); out.setDevice(&listFile); url = value; qDebug() << "url: " << value << ", filePath: " << filePath; }
void MyWidget::fromClipboardToLineEdit() // слот { if (mpClipboard ->text().size() < 35) { uiForm ->lineEditInput ->setText(mpClipboard ->text()); qint32 n = getIndexString(mCurrentListFileName, uiForm ->lineEditInput ->text(), "OneWord"); if (n == -1) uiForm ->lineEditInput ->setFocus(); else { qDebug() << "Index = " << n; quint32 m = uniqueFileName(mCurrentListFileName, uiForm ->lineEditInput ->text()); if (m == 1) uiForm ->listWidgetFiles ->setCurrentRow(n); else uiForm ->listWidgetFiles ->setCurrentRow(mCurrentIndex); } } }
QStringList VideoConverter::getCommandLine() { QStringList parameters; QString extension; parameters << "-i" << validPath(videoItem->getVideoFile()); switch (convConfToUse.outputFormat) { case ofAVI: parameters << "-f" << "avi" << "-vcodec" << "mpeg4"; extension = ".avi"; break; case ofWMV: extension = ".wmv"; break; case ofMPEG1: parameters << "-vcodec" << "mpeg1video"; extension = ".mpg"; break; case ofMPEG2: parameters << "-vcodec" << "mpeg2video"; extension = ".mpeg"; break; case ofMP4: case ofMP4_hd: { QString vpre = convConfToUse.outputFormat == ofMP4 ? "default" : "hq"; // configure h264 codec #ifndef Q_OS_LINUX #ifdef Q_OS_WIN32 bool use_x264 = true; #else bool use_x264 = isRunningOn64bits(); #endif if (use_x264) parameters << "-vcodec" << "libx264" << "-fpre" << QFileInfo(ffmpegApp).absolutePath() + "/ffmpeg-presets/libx264-" + vpre + ".ffpreset"; else // no x264 support parameters << "-f" << "mp4" << "-vcodec" << "mpeg4"; #else parameters << "-vcodec" << "libx264" << "-vpre" << vpre; #endif extension = ".mp4"; break; } case ofAppleiPod: parameters << "-acodec" << "libfaac" << "-ab" << "128kb" << "-vcodec" << "mpeg4" << "-b" << "1200kb" << "-mbd" << "2" << "-cmp" << "2" << "-subcmp" << "2" << "-s" << "320x240"; extension = ".mp4"; break; case ofSonyPSP: parameters << "-acodec" << "libfaac" << "-ab" << "128kb" << "-vcodec" << "mpeg4" << "-b" << "1200kb" << "-mbd" << "2" << "-flags" << "+4mv" << "-trellis" << "2" << "-cmp" << "2" << "-subcmp" << "2" << "-r" << "30000/1001" << "-f" << "psp"; extension = ".mp4"; break; case of3GP: parameters << "-vcodec" << "mpeg4" << "-acodec" << "libfaac" << "-ar" << "8000" << "-ac" << "1" << "-ab" << "12.2k" << "-f" << "3gp"; extension = ".3gp"; break; case ofMP3: extension = ".mp3"; break; } // this is used only for NON Apple iPod videos if (convConfToUse.outputFormat != ofAppleiPod) { switch (convConfToUse.videoResolution) { case vrOriginal: break; case vr96x72: parameters << "-s" << "96x72"; break; case vr128x96: parameters << "-s" << "128x96"; break; case vr160x120: parameters << "-s" << "160x120"; break; case vr176x120: parameters << "-s" << "176x120"; break; case vr176x144: parameters << "-s" << "176x144"; break; case vr192x144: parameters << "-s" << "192x144"; break; case vr240x180: parameters << "-s" << "240x180"; break; case vr320x200: parameters << "-s" << "320x200"; break; case vr320x240: parameters << "-s" << "320x240"; break; case vr352x240: parameters << "-s" << "352x240"; break; case vr352x288: parameters << "-s" << "352x288"; break; case vr480x272: parameters << "-s" << "480x272"; break; case vr480x360: parameters << "-s" << "480x360"; break; case vr480x480: parameters << "-s" << "480x480"; break; case vr624x352: parameters << "-s" << "624x352"; break; case vr640x480: parameters << "-s" << "640x480"; break; case vr720x480: parameters << "-s" << "720x480"; break; case vr720x576: parameters << "-s" << "720x576"; break; } if (convConfToUse.videoFrameRate == vfr15) parameters << "-r" << "15"; else if (convConfToUse.videoFrameRate == vfr24) parameters << "-r" << "24"; else if (convConfToUse.videoFrameRate == vfr25) parameters << "-r" << "25"; else if (convConfToUse.videoFrameRate == vfr29_97) parameters << "-r" << "29.97"; else if (convConfToUse.videoFrameRate == vfr30) parameters << "-r" << "30"; switch (convConfToUse.audioSampleRatio) { case asrOriginal: break; case asr22050: parameters << "-ar" << "22050"; break; case asr44100: parameters << "-ar" << "44100"; break; } switch (convConfToUse.outputQuality) { case oqLower_quality: parameters << "-b" << "384k" << "-ab" << "64k"; break; case oqLow_quality: parameters << "-b" << "512k" << "-ab" << "80k"; break; case oqNormal_quality: parameters << "-b" << "640k" << "-ab" << "96k"; break; case oqMedium_quality: parameters << "-b" << "800k" << "-ab" << "96k"; break; case oqGood_quality: parameters << "-b" << "1000k" << "-ab" << "128k"; break; case oqSuperb_quality: parameters << "-b" << "1200k" << "-ab" << "128k"; break; case oqSame_quality: break; } } videoItem->setVideoFileSavedTo(uniqueFileName(changeFileExt(videoItem->getVideoFile(), extension)), this); parameters << "-y" << validPath(videoItem->getVideoFileSavedTo()); return parameters; }
void PMenu::writeConfig( QDir base_dir, PMenuItem *parent_item) { if( parent_item ) if( parent_item->read_only ) return; if( !base_dir.exists() ) { return; } QString name; const QStrList *temp_list = base_dir.entryList("*", QDir::Files); QStrList file_list; file_list.setAutoDelete(TRUE); QStrListIterator temp_it( *temp_list ); while( name = temp_it.current() ) { file_list.append(name); ++temp_it; } temp_list = base_dir.entryList("*", QDir::Dirs); QStrList dir_list; dir_list.setAutoDelete(TRUE); temp_it.toFirst(); while( name = temp_it.current() ) { if(name != "." && name != "..") dir_list.append(name); ++temp_it; } QString sort_order; PMenuItem *item; for( item = list.first(); item != 0; item = list.next() ) { // if( item->read_only ) // continue; if( item->entry_type == separator ) sort_order += ((QString) "SEPARATOR" + ','); else sort_order += (item->real_name + ','); if( item->getType() == submenu ) { if( !item->read_only ) { QDir sub_dir(base_dir); if( !sub_dir.cd(item->real_name) ) { base_dir.mkdir(item->real_name); if( !sub_dir.cd(item->real_name) ) continue; } item->sub_menu->writeConfig( sub_dir, item ); } dir_list.remove(item->real_name); } else { if( item->entry_type != separator ) { if( !item->read_only ) { if( item->real_name.isEmpty() ) item->real_name = uniqueFileName(item->text_name); item->writeConfig(base_dir); } file_list.remove(item->real_name); // + ".kdelnk"); } } } // remove files not in pmenu for( name = file_list.first(); name != 0; name = file_list.next() ) { if( isKdelnkFile(base_dir.absFilePath(name)) ) { //debug("will remove file: %s", (const char *) name ); base_dir.remove(name); } } // remove dirs not in pmenu for( name = dir_list.first(); name != 0; name = dir_list.next() ) { //debug("will remove dir: %s", (const char *) name ); QDir sub_dir(base_dir); if(sub_dir.cd(name)) { PMenu *new_menu = new PMenu; new_menu->writeConfig(sub_dir); delete new_menu; sub_dir.remove(".directory"); } base_dir.rmdir(name); } sort_order.truncate(sort_order.length()-1); QString file = base_dir.absPath(); file += "/.directory"; QFile config(file); if( !config.open(IO_ReadWrite) ) return; config.close(); KConfig kconfig(file); kconfig.setGroup("KDE Desktop Entry"); kconfig.writeEntry("SortOrder", sort_order); if( parent_item ) { kconfig.writeEntry("MiniIcon", parent_item->pixmap_name ); if( parent_item->big_pixmap_name.isEmpty() ) parent_item->big_pixmap_name = "folder.xpm"; kconfig.writeEntry("Icon", parent_item->big_pixmap_name ); kconfig.writeEntry("Name", parent_item->text_name, TRUE, FALSE, TRUE ); } kconfig.sync(); }
KUrl OutputDirectory::calcPath( FileListItem *fileListItem, Config *config, const QStringList& usedOutputNames ) { ConversionOptions *options = config->conversionOptionsManager()->getConversionOptions(fileListItem->conversionOptionsId); if( !options ) return KUrl(); QString path; KUrl url; QString extension; if( config->pluginLoader()->codecExtensions(options->codecName).count() > 0 ) extension = config->pluginLoader()->codecExtensions(options->codecName).first(); if( extension.isEmpty() ) extension = options->codecName; QString fileName; if( fileListItem->track == -1 ) fileName = fileListItem->url.fileName(); else fileName = QString().sprintf("%02i",fileListItem->tags->track) + " - " + fileListItem->tags->artist + " - " + fileListItem->tags->title + "." + extension; if( options->outputDirectoryMode == Specify ) { path = options->outputDirectory+"/"+fileName; if( config->data.general.useVFATNames || options->outputFilesystem == "vfat" ) path = vfatPath( path ); if( options->outputFilesystem == "ntfs" ) path = ntfsPath( path ); url = changeExtension( KUrl(path), extension ); if( config->data.general.conflictHandling == Config::Data::General::NewFileName ) url = uniqueFileName( url, usedOutputNames ); return url; } else if( options->outputDirectoryMode == MetaData ) { path = options->outputDirectory; // TODO a little bit redundant, adding %f if file name wasn't set properly // TODO these restrictions could be a little bit over the top if( path.right(1) == "/" ) path += "%f"; else if( path.lastIndexOf(QRegExp("%[abcdfgnpty]")) < path.lastIndexOf("/") ) path += "/%f"; const int fileNameBegin = path.lastIndexOf("/"); if( fileListItem->tags == 0 || ( path.mid(fileNameBegin).contains("%n") && fileListItem->tags->track == 0 ) || ( path.mid(fileNameBegin).contains("%t") && fileListItem->tags->title.isEmpty() ) ) { path = path.left( fileNameBegin ) + "/%f"; } path.replace( "\\[", "$quared_bracket_open$" ); path.replace( "\\]", "$quared_bracket_close$" ); QRegExp reg( "\\[(.*)%([abcdfgnpty])(.*)\\]" ); reg.setMinimal( true ); while( path.indexOf(reg) != -1 ) { if( fileListItem->tags && ( ( reg.cap(2) == "a" && !fileListItem->tags->artist.isEmpty() ) || ( reg.cap(2) == "b" && !fileListItem->tags->album.isEmpty() ) || ( reg.cap(2) == "c" && !fileListItem->tags->comment.isEmpty() ) || ( reg.cap(2) == "d" && fileListItem->tags->disc != 0 ) || ( reg.cap(2) == "g" && !fileListItem->tags->genre.isEmpty() ) || ( reg.cap(2) == "n" && fileListItem->tags->track != 0 ) || ( reg.cap(2) == "p" && !fileListItem->tags->composer.isEmpty() ) || ( reg.cap(2) == "t" && !fileListItem->tags->title.isEmpty() ) || ( reg.cap(2) == "y" && fileListItem->tags->year != 0 ) ) ) { path.replace( reg, "\\1%\\2\\3" ); } else { path.replace( reg, "" ); } } path.replace( "$quared_bracket_open$", "[" ); path.replace( "$quared_bracket_close$", "]" ); while( path.contains("//") ) path.replace( "//", "/" ); path.replace( "%a", "$replace_by_artist$" ); path.replace( "%b", "$replace_by_album$" ); path.replace( "%c", "$replace_by_comment$" ); path.replace( "%d", "$replace_by_disc$" ); path.replace( "%g", "$replace_by_genre$" ); path.replace( "%n", "$replace_by_track$" ); path.replace( "%p", "$replace_by_composer$" ); path.replace( "%t", "$replace_by_title$" ); path.replace( "%y", "$replace_by_year$" ); path.replace( "%f", "$replace_by_filename$" ); QString artist = ( fileListItem->tags == 0 || fileListItem->tags->artist.isEmpty() ) ? i18n("Unknown Artist") : fileListItem->tags->artist; artist.replace("/",","); path.replace( "$replace_by_artist$", artist ); QString album = ( fileListItem->tags == 0 || fileListItem->tags->album.isEmpty() ) ? i18n("Unknown Album") : fileListItem->tags->album; album.replace("/",","); path.replace( "$replace_by_album$", album ); QString comment = ( fileListItem->tags == 0 || fileListItem->tags->comment.isEmpty() ) ? i18n("No Comment") : fileListItem->tags->comment; comment.replace("/",","); path.replace( "$replace_by_comment$", comment ); QString disc = ( fileListItem->tags == 0 ) ? "0" : QString().sprintf("%i",fileListItem->tags->disc); path.replace( "$replace_by_disc$", disc ); QString genre = ( fileListItem->tags == 0 || fileListItem->tags->genre.isEmpty() ) ? i18n("Unknown Genre") : fileListItem->tags->genre; genre.replace("/",","); path.replace( "$replace_by_genre$", genre ); QString track = ( fileListItem->tags == 0 ) ? "00" : QString().sprintf("%02i",fileListItem->tags->track); path.replace( "$replace_by_track$", track ); QString composer = ( fileListItem->tags == 0 || fileListItem->tags->composer.isEmpty() ) ? i18n("Unknown Composer") : fileListItem->tags->composer; composer.replace("/",","); path.replace( "$replace_by_composer$", composer ); QString title = ( fileListItem->tags == 0 || fileListItem->tags->title.isEmpty() ) ? i18n("Unknown Title") : fileListItem->tags->title; title.replace("/",","); path.replace( "$replace_by_title$", title ); QString year = ( fileListItem->tags == 0 ) ? "0000" : QString().sprintf("%04i",fileListItem->tags->year); path.replace( "$replace_by_year$", year ); QString filename = fileName.left( fileName.lastIndexOf(".") ); filename.replace("/",","); path.replace( "$replace_by_filename$", filename ); if( config->data.general.useVFATNames || options->outputFilesystem == "vfat" ) path = vfatPath( path ); if( options->outputFilesystem == "ntfs" ) path = ntfsPath( path ); url = KUrl( path + "." + extension ); if( config->data.general.conflictHandling == Config::Data::General::NewFileName ) url = uniqueFileName( url, usedOutputNames ); return url; } else if( options->outputDirectoryMode == CopyStructure ) { QString basePath = options->outputDirectory; QString originalPath = fileListItem->url.pathOrUrl(); int cutpos = basePath.length(); while( basePath.left(cutpos) != originalPath.left(cutpos) ) { cutpos = basePath.lastIndexOf( '/', cutpos - 1 ); } // At this point, basePath and originalPath overlap on the left for cutpos characters (which might be 0). path = basePath+originalPath.mid(cutpos); if( config->data.general.useVFATNames || options->outputFilesystem == "vfat" ) path = vfatPath( path ); if( options->outputFilesystem == "ntfs" ) path = ntfsPath( path ); url = changeExtension( KUrl(path), extension ); if( config->data.general.conflictHandling == Config::Data::General::NewFileName ) url = uniqueFileName( url, usedOutputNames ); return url; } else // SourceDirectory { path = fileListItem->url.toLocalFile(); url = changeExtension( KUrl(path), extension ); if( config->data.general.conflictHandling == Config::Data::General::NewFileName ) url = uniqueFileName( url, usedOutputNames ); return url; } }