QString ConfigFile::excludeFile(Scope scope) const { // prefer sync-exclude.lst, but if it does not exist, check for // exclude.lst for compatibility reasons in the user writeable // directories. QFileInfo fi; switch (scope) { case UserScope: fi.setFile(configPath(), exclFile); if (!fi.isReadable()) { fi.setFile(configPath(), QLatin1String("exclude.lst")); } if (!fi.isReadable()) { fi.setFile(configPath(), exclFile); } return fi.absoluteFilePath(); case SystemScope: return ConfigFile::excludeFileFromSystem(); } ASSERT(false); return QString(); }
// Check whether the file has changed on disk // by looking at the time stamp bool GLEFileInfo::hasChanged() { QFileInfo fi; QString mainFile(primaryFile()); if (mainFile.isEmpty()) { return false; } fi.setFile(mainFile); if (!fi.isReadable()) { return false; } QDateTime modifiedTime(fi.lastModified()); if (modifiedTime > lastModified) { return true; } else { for (int i = 0; i < filesToMonitor.size(); ++i) { GLEFileData data(filesToMonitor.at(i)); fi.setFile(data.fname); if (fi.isReadable() && fi.lastModified() > data.lastModified) { return true; } } return false; } }
QMap< QString, QString> ConfigBase::exportDatas( const QString &directory ) { QDir copyDirectory( directory ); QFileInfo fi; const QFileInfoList fil = copyDirectory.entryInfoList( QDir::Dirs | QDir::Files , QDir::Name ); QListIterator< QFileInfo > it( fil ); QMap< QString, QString> zipData; while ( it.hasNext() ) { fi = it.next(); if ( fi.fileName() == "." || fi.fileName() == ".." ) { ; } else { if ( fi.isDir() && fi.isReadable() ) { exportDatas( fi.absoluteFilePath() ); } else if ( fi.isFile() && fi.isReadable() ) { zipData.insert( fi.absolutePath(), fi.fileName() ); } } } return zipData; }
void ThirdStep::initializePage () { TotalSize_ = 0; QString path = field ("RootPath").toString (); QFileInfo pathInfo (path); if (pathInfo.isDir ()) { QDirIterator it (path, QDirIterator::Subdirectories); while (it.hasNext ()) { it.next (); QFileInfo info = it.fileInfo (); if (info.isFile () && info.isReadable ()) TotalSize_ += info.size (); } } else if (pathInfo.isFile () && pathInfo.isReadable ()) TotalSize_ += pathInfo.size (); quint64 max = std::log (static_cast<long double> (TotalSize_ / 102400)) * 80; quint32 pieceSize = 32 * 1024; int shouldIndex = 0; for (; TotalSize_ / pieceSize >= max; pieceSize *= 2, ++shouldIndex) ; if (shouldIndex > PieceSize_->count () - 1) shouldIndex = PieceSize_->count () - 1; PieceSize_->setCurrentIndex (shouldIndex); on_PieceSize__currentIndexChanged (); }
bool QTranslator::load(const QString & filename, const QString & directory, const QString & search_delimiters, const QString & suffix) { Q_D(QTranslator); d->clear(); QString fname = filename; QString prefix; if (QFileInfo(filename).isRelative()) { prefix = directory; if (prefix.length() && !prefix.endsWith(QLatin1Char('/'))) prefix += QLatin1Char('/'); } QString realname; QString delims; delims = search_delimiters.isNull() ? QString::fromLatin1("_.") : search_delimiters; for (;;) { QFileInfo fi; realname = prefix + fname + (suffix.isNull() ? QString::fromLatin1(".qm") : suffix); fi.setFile(realname); if (fi.isReadable() && fi.isFile()) break; realname = prefix + fname; fi.setFile(realname); if (fi.isReadable() && fi.isFile()) break; int rightmost = 0; for (int i = 0; i < (int)delims.length(); i++) { int k = fname.lastIndexOf(delims[i]); if (k > rightmost) rightmost = k; } // no truncations? fail if (rightmost == 0) return false; fname.truncate(rightmost); } // realname is now the fully qualified name of a readable file. return d->do_load(realname); }
void CalamaresApplication::initSettings() { QFileInfo settingsFile; if ( CalamaresUtils::isAppDataDirOverridden() ) { settingsFile = QFileInfo( CalamaresUtils::appDataDir().absoluteFilePath( "settings.conf" ) ); if ( !settingsFile.exists() || !settingsFile.isReadable() ) { cLog() << "FATAL ERROR: explicitly configured application data directory" << CalamaresUtils::appDataDir().absolutePath() << "does not contain a valid settings.conf file." << "\nCowardly refusing to continue startup without settings."; ::exit( EXIT_FAILURE ); } } else { QStringList settingsFileCandidatesByPriority; if ( isDebug() ) { settingsFileCandidatesByPriority.append( QDir::currentPath() + QDir::separator() + "settings.conf" ); } settingsFileCandidatesByPriority.append( CMAKE_INSTALL_FULL_SYSCONFDIR "/calamares/settings.conf" ); settingsFileCandidatesByPriority.append( CalamaresUtils::appDataDir() .absoluteFilePath( "settings.conf" ) ); foreach ( const QString& path, settingsFileCandidatesByPriority ) { QFileInfo pathFi( path ); if ( pathFi.exists() && pathFi.isReadable() ) { settingsFile = pathFi; break; } } if ( !settingsFile.exists() || !settingsFile.isReadable() ) { cLog() << "FATAL ERROR: none of the expected configuration file paths (" << settingsFileCandidatesByPriority.join( ", " ) << ") contain a valid settings.conf file." << "\nCowardly refusing to continue startup without settings."; ::exit( EXIT_FAILURE ); } }
/* * A more efficient way to do this would be to parse the relevant project files * before hand, or cache them as we go - but this works well enough so far. */ static QString findResourceInProject(const QString &resName) { QString s = resName; s.remove('"'); if (s.startsWith(":/")) s.remove(0, 1); else if (s.startsWith("qrc://")) s.remove(0, 5); else return QString(); if (auto *project = ProjectExplorer::ProjectTree::currentProject()) { const Utils::FileNameList files = project->files(ProjectExplorer::Project::AllFiles); for (const Utils::FileName &file : files) { if (!file.endsWith(".qrc")) continue; const QFileInfo fi = file.toFileInfo(); if (!fi.isReadable()) continue; const QString fileName = findResourceInFile(s, file.toString()); if (fileName.isEmpty()) continue; QString ret = fi.absolutePath(); if (!ret.endsWith('/')) ret.append('/'); ret.append(fileName); return ret; } } return QString(); }
void DialogCleanup::Cleanup( ) { // Get size before. unsigned int startSize = FileUtils::GetFolderSize( m_Path ); m_UI.output->appendPlainText( "Cleaning '" + m_Path + "' ..." ); // Go through files. QDir directory( m_Path ); QFileInfoList files = directory.entryInfoList(); for ( QFileInfoList::iterator i = files.begin(); i != files.end(); i++ ) { QFileInfo file = *i; if ( !file.isReadable() ) continue; if ( file.fileName() == "." || file.fileName() == ".." ) continue; if ( std::find( m_Preserved.begin(), m_Preserved.end(), file.fileName() ) == m_Preserved.end() ) { m_UI.output->appendPlainText( "Removing: " + file.fileName() ); if ( file.isDir() ) FileUtils::DeleteFolder( file.absoluteFilePath() ); if ( file.isFile() ) QFile::remove(file.absoluteFilePath()); } } // Get size after. unsigned int endSize = FileUtils::GetFolderSize( m_Path ); m_UI.output->appendPlainText( "Cleaning complete." ); m_UI.output->appendPlainText( "Cleaned " + QString::number( startSize - endSize ) + " megabytes." ); // Change UI to reflect completion. m_UI.btnDone->setText( "Close" ); }
void AddTask::accept () { QFileInfo dir (Ui_.LocalPath_->text ()); QString message; if (!dir.exists ()) message = tr ("Directory %1 doesn't exist, would you like to " "select another?").arg (dir.absolutePath ()); else if (!dir.isReadable ()) message = tr ("Directory %1 isn't readable, would you like to " "select another?").arg (dir.absolutePath ()); else if (!dir.isWritable ()) message = tr ("Directory %1 isn't writable, would you like to " "select another?").arg (dir.absolutePath ()); else if (!dir.isDir ()) message = tr ("%1 isn't a directory at all, would you like to " "select another?").arg (dir.absolutePath ()); else { QDialog::accept (); return; } if (QMessageBox::question (this, "LeechCraft", message, QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) on_BrowseButton__released (); else QDialog::reject (); }
void FolderNavigationWidget::openItem(const QModelIndex &srcIndex, bool openDirectoryAsProject) { const QString fileName = m_fileSystemModel->fileName(srcIndex); if (fileName == QLatin1String(".")) return; if (fileName == QLatin1String("..")) { // cd up: Special behaviour: The fileInfo of ".." is that of the parent directory. const QString parentPath = m_fileSystemModel->fileInfo(srcIndex).absoluteFilePath(); setCurrentDirectory(parentPath); return; } const QString path = m_fileSystemModel->filePath(srcIndex); if (m_fileSystemModel->isDir(srcIndex)) { const QFileInfo fi = m_fileSystemModel->fileInfo(srcIndex); if (!fi.isReadable() || !fi.isExecutable()) return; // Try to find project files in directory and open those. if (openDirectoryAsProject) { QDir dir(path); QStringList proFiles; foreach (const QFileInfo &i, dir.entryInfoList(ProjectExplorerPlugin::projectFileGlobs(), QDir::Files)) proFiles.append(i.absoluteFilePath()); if (!proFiles.isEmpty()) Core::ICore::instance()->openFiles(proFiles); return; } // Change to directory setCurrentDirectory(path); return; } // Open file. Core::ICore::instance()->openFiles(QStringList(path)); }
void FileBrowser::on_treeFiles_doubleClicked(QModelIndex index) { QFileInfo info = model->fileInfo(index); if(!info.isReadable() || !info.isDir()) return; setPath(info.canonicalFilePath()); }
void QtStyleManager::GetIconThemes(IconThemeList& iconThemes) const { iconThemes.clear(); iconThemes.push_back(IconTheme(QString( "<<default>>" ))); QStringList iconSearchPaths = QIcon::themeSearchPaths(); for(QStringList::Iterator pathIt = iconSearchPaths.begin(); pathIt != iconSearchPaths.end(); ++pathIt) { QDirIterator dirIt(*pathIt); while (dirIt.hasNext()) { QString current = dirIt.next(); QFileInfo info = dirIt.fileInfo(); if (info.isDir() && info.isReadable()) { QFileInfo themeFile( info.filePath() + QString("/index.theme") ); if( themeFile.exists() && themeFile.isFile() && themeFile.isReadable() ) { QString fileName = info.fileName(); iconThemes.push_back( IconTheme(fileName) ); } } } } }
void ResourceLoader::handleDirectoryChanged (const QString& path) { emit watchedDirectoriesChanged (); for (auto i = Entry2Paths_.begin (), end = Entry2Paths_.end (); i != end; ++i) i->removeAll (path); QFileInfo fi (path); if (fi.exists () && fi.isDir () && fi.isReadable ()) ScanPath (path); QStringList toRemove; for (auto i = Entry2Paths_.begin (), end = Entry2Paths_.end (); i != end; ++i) if (i->isEmpty ()) toRemove << i.key (); for (const auto& entry : toRemove) { Entry2Paths_.remove (entry); auto items = SubElemModel_->findItems (entry); for (auto item : SubElemModel_->findItems (entry)) SubElemModel_->removeRow (item->row ()); } }
bool ModList::installMod ( const QFileInfo& filename, int index ) { if(!filename.exists() || !filename.isReadable() || index < 0) { return false; } Mod m(filename); if(!m.valid()) return false; // if it's already there, replace the original mod (in place) int idx = mods.indexOf(m); if(idx != -1) { if(mods[idx].replace(m)) { auto left = this->index(index); auto right = this->index(index, columnCount(QModelIndex()) - 1); emit dataChanged(left, right); saveListFile(); emit changed(); return true; } return false; } auto type = m.type(); if(type == Mod::MOD_UNKNOWN) return false; if(type == Mod::MOD_SINGLEFILE || type == Mod::MOD_ZIPFILE) { QString newpath = PathCombine(m_dir.path(), filename.fileName()); if(!QFile::copy(filename.filePath(), newpath)) return false; m.repath(newpath); beginInsertRows(QModelIndex(), index, index); mods.insert(index,m); endInsertRows(); saveListFile(); emit changed(); return true; } else if(type == Mod::MOD_FOLDER) { QString from = filename.filePath(); QString to = PathCombine(m_dir.path(), filename.fileName()); if(!copyPath(from, to)) return false; m.repath(to); beginInsertRows(QModelIndex(), index, index); mods.insert(index,m); endInsertRows(); saveListFile(); emit changed(); return true; } return false; }
tlp::node addFileNode(const QFileInfo &infos, tlp::Graph *g) { tlp::node n = g->addNode(); _absolutePaths->setNodeValue(n,tlp::QStringToTlpString(infos.absoluteFilePath())); _baseNames->setNodeValue(n,tlp::QStringToTlpString(infos.baseName())); _createdDates->setNodeValue(n,tlp::QStringToTlpString(infos.created().toString())); _fileNames->setNodeValue(n,tlp::QStringToTlpString(infos.fileName())); _isDir->setNodeValue(n,infos.isDir()); _isExecutable->setNodeValue(n,infos.isExecutable()); _isReadable->setNodeValue(n,infos.isReadable()); _isSymlink->setNodeValue(n,infos.isSymLink()); _isWritable->setNodeValue(n,infos.isWritable()); _lastModifiedDates->setNodeValue(n,tlp::QStringToTlpString(infos.lastModified().toString())); _lastReadDates->setNodeValue(n,tlp::QStringToTlpString(infos.lastRead().toString())); _owners->setNodeValue(n,tlp::QStringToTlpString(infos.owner())); _permissions->setNodeValue(n,(int)(infos.permissions())); _suffixes->setNodeValue(n,tlp::QStringToTlpString(infos.suffix())); _sizes->setNodeValue(n,infos.size()); if (_useIcons) { std::string extension = infos.suffix().toStdString(); if (infos.isDir()) { _fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FolderO); tlp::ColorProperty *viewColor = graph->getProperty<tlp::ColorProperty>("viewColor"); viewColor->setNodeValue(n, dirColor); } else if (std::find(commonTextFilesExt.begin(), commonTextFilesExt.end(), extension) != commonTextFilesExt.end()) { _fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FileTextO); } else if (std::find(commonArchiveFilesExt.begin(), commonArchiveFilesExt.end(), extension) != commonArchiveFilesExt.end()) { _fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FileArchiveO); } else if (std::find(commonAudioFilesExt.begin(), commonAudioFilesExt.end(), extension) != commonAudioFilesExt.end()) { _fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FileAudioO); } else if (std::find(commonImageFilesExt.begin(), commonImageFilesExt.end(), extension) != commonImageFilesExt.end()) { _fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FileImageO); } else if (std::find(commonVideoFilesExt.begin(), commonVideoFilesExt.end(), extension) != commonVideoFilesExt.end()) { _fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FileVideoO); } else if (std::find(commonDevFilesExt.begin(), commonDevFilesExt.end(), extension) != commonDevFilesExt.end()) { _fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FileCodeO); } else if (extension == "pdf") { _fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FilePdfO); } else if (extension == "doc" || extension == "docx") { _fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FileWordO); } else if (extension == "xls" || extension == "xlsx") { _fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FileExcelO); } else if (extension == "ppt" || extension == "pptx") { _fontAwesomeIcon->setNodeValue(n, tlp::TulipFontAwesome::FilePowerpointO); } } return n; }
static bool compare_zone_files(QFileInfo first_file_info, QFileInfo second_file_info) { if (!first_file_info.isFile() || !second_file_info.isFile() || !first_file_info.isReadable() || !second_file_info.isReadable()) return false; qint64 first_file_size = first_file_info.size(); // sanity check - zoneinfo files should typically be less than // about 4kB, but leave room for growth if ((first_file_size > 200 * 1024) || (second_file_info.size() != first_file_size)) return false; QFile first_file(first_file_info.absoluteFilePath()); QByteArray first_file_data; first_file_data.resize(first_file_size); QFile second_file(second_file_info.absoluteFilePath()); QByteArray second_file_data; second_file_data.resize(first_file_size); if (first_file.open(QIODevice::ReadOnly)) { QDataStream in(&first_file); if (in.readRawData(first_file_data.data(), first_file_size) != first_file_size) { first_file.close(); return false; } first_file.close(); } if (second_file.open(QIODevice::ReadOnly)) { QDataStream in(&second_file); if (in.readRawData(second_file_data.data(), first_file_size) != first_file_size) { second_file.close(); return false; } second_file.close(); } if (first_file_data == second_file_data) return true; return false; }
static QString find_translation(const QLocale & locale, const QString & filename, const QString & prefix, const QString & directory, const QString & suffix) { QString path; if (QFileInfo(filename).isRelative()) { path = directory; if (!path.isEmpty() && !path.endsWith(QLatin1Char('/'))) path += QLatin1Char('/'); } QFileInfo fi; QString realname; QStringList fuzzyLocales; // see http://www.unicode.org/reports/tr35/#LanguageMatching for inspiration QStringList languages = locale.uiLanguages(); #if defined(Q_OS_UNIX) for (int i = languages.size()-1; i >= 0; --i) { QString lang = languages.at(i); QString lowerLang = lang.toLower(); if (lang != lowerLang) languages.insert(i+1, lowerLang); } #endif // try explicit locales names first foreach (QString localeName, languages) { localeName.replace(QLatin1Char('-'), QLatin1Char('_')); realname = path + filename + prefix + localeName + (suffix.isNull() ? QLatin1String(".qm") : suffix); fi.setFile(realname); if (fi.isReadable() && fi.isFile()) return realname; realname = path + filename + prefix + localeName; fi.setFile(realname); if (fi.isReadable() && fi.isFile()) return realname; fuzzyLocales.append(localeName); }
// Check by extension and type if this appears to be a loadable image bool IconProvider::loadCheck(const QFileInfo &info) const { if (info.isFile() && info.isReadable()) { const QString suffix = info.suffix(); if (!suffix.isEmpty()) return m_imageFormats.contains(suffix); } return false; }
bool MediaDeviceTrack::isPlayable() const { KUrl trackUrl = playableUrl(); QFileInfo trackFileInfo = QFileInfo( trackUrl.pathOrUrl() ); if( trackFileInfo.exists() && trackFileInfo.isFile() && trackFileInfo.isReadable() ) return true; return false; }
void Folder::checkLocalPath() { const QFileInfo fi(_definition.localPath); if( fi.isDir() && fi.isReadable() ) { qDebug() << "Checked local path ok"; } else { // Check directory again if( !FileSystem::fileExists(_definition.localPath, fi) ) { _syncResult.setErrorString(tr("Local folder %1 does not exist.").arg(_definition.localPath)); _syncResult.setStatus( SyncResult::SetupError ); } else if( !fi.isDir() ) { _syncResult.setErrorString(tr("%1 should be a folder but is not.").arg(_definition.localPath)); _syncResult.setStatus( SyncResult::SetupError ); } else if( !fi.isReadable() ) { _syncResult.setErrorString(tr("%1 is not readable.").arg(_definition.localPath)); _syncResult.setStatus( SyncResult::SetupError ); } } }
void RecentFileStatus::start(void) { QFileInfo fi; fi.setFile(m_filename); if (fi.isFile() && fi.isReadable()) { emit statusFound(m_filename, fi.size(), true); } else { emit statusFound(m_filename, 0, false); } }
/** Plays the sound file by calling the configured player, which has * been passed in the constructor. If sound file or player are not * accessable a simple beep is given out as fallback solution. */ void Sound::run() { QMutexLocker locker( &mutex ); QFileInfo info = QFileInfo( _sound ); if( ! info.isReadable() ) { printf("\a"); qWarning("Sound file %s is not readable", _sound.toLatin1().data() ); return; } QString player = GeneralConfig::instance()->getSoundPlayer(); if( player.isEmpty() ) { printf("\a"); qWarning("No sound player defined by user" ); return; } QStringList list = player.split(" "); info = QFileInfo( list[0] ); if( ! info.isExecutable() ) { printf("\a"); qWarning("Sound player %s is not executable", player.toLatin1().data() ); return; } QString cmd; if( player.contains( "%s" ) ) { // the sound file is enclosed in the command string cmd = player.replace( "%s", _sound ); } else { // the sound file can appended at the player end cmd = player + " " + _sound; } // qDebug( "%s", cmd.toLatin1().data() ); // Execute the player command, to play the passed sound. // QProcess::execute( cmd ) did not work at this place. Maybe it // uses also threads. The good old c-function system() works solid. system( cmd.toLatin1().data() ); }
QString MirallConfigFile::excludeFile(Scope scope) const { // prefer sync-exclude.lst, but if it does not exist, check for // exclude.lst for compatibility reasons in the user writeable // directories. const QString exclFile("sync-exclude.lst"); QFileInfo fi; if (scope != SystemScope) { fi.setFile( configPath(), exclFile ); if( ! fi.isReadable() ) { fi.setFile( configPath(), QLatin1String("exclude.lst") ); } if( ! fi.isReadable() ) { fi.setFile( configPath(), exclFile ); } } if (scope != UserScope) { // Check alternative places... if( ! fi.isReadable() ) { #ifdef Q_OS_WIN fi.setFile( QCoreApplication::applicationDirPath(), exclFile ); #endif #ifdef Q_OS_UNIX fi.setFile( QString( SYSCONFDIR "/%1").arg(Theme::instance()->appName()), exclFile ); #endif #ifdef Q_OS_MAC // exec path is inside the bundle fi.setFile( QCoreApplication::applicationDirPath(), QLatin1String("../Resources/") + exclFile ); #endif } } qDebug() << " ==> returning exclude file path: " << fi.absoluteFilePath(); return fi.absoluteFilePath(); qDebug() << "EMPTY exclude file path!"; return QString::null; }
foreach (QFileInfo f, files){ if (f.isDir()&&!f.isSymLink()&&f.isReadable()){ ++count_dirs; dirRound(f.absoluteFilePath()); } else { ++count_files; total_size+=f.size(); } }
void PreviewConfigurationWidget::PreviewConfigurationWidgetPrivate::addUserSkins(const QStringList &files) { if (files.empty()) return; const QStringList ::const_iterator fcend = files.constEnd(); for (QStringList::const_iterator it = files.constBegin(); it != fcend; ++it) { const QFileInfo fi(*it); if (fi.isDir() && fi.isReadable()) { m_ui.m_skinCombo->insertItem(m_browseSkinIndex++, fi.baseName(), QVariant(*it)); } else { qWarning() << "Unable to access the skin directory '" << *it << "'."; } } }
QStringList MetaDataExtractor::extractCSS(const QString& filename) { QFileInfo info = QFileInfo(filename); if (!info.isReadable()) { qDebug() << Q_FUNC_INFO << "Cannot read" << filename; } if (info.suffix () == "epub") { return EpubMetaDataExtractor::extractCSS(filename); } return QStringList(); }
bool MetaDataExtractor::extractCover(const QString& filename, QString& coverPath) { QFileInfo info = QFileInfo(filename); if (!info.isReadable()) { qDebug() << Q_FUNC_INFO << "Cannot read " << filename; return false; } if (info.suffix().toLower() == "epub") return EpubMetaDataExtractor::extractCover(filename, coverPath); else if (info.suffix().toLower() == "fb2") return Fb2MetaDataExtractor::extractCover(filename, coverPath); else if (info.suffix().toLower() == "mobi") return MobiMetaDataExtractor::extractCover(filename, coverPath); else return false; }
//! [7] PermissionsTab::PermissionsTab(const QFileInfo &fileInfo, QWidget *parent) : QWidget(parent) { QGroupBox *permissionsGroup = new QGroupBox(tr("Permissions")); QCheckBox *readable = new QCheckBox(tr("Readable")); if (fileInfo.isReadable()) readable->setChecked(true); QCheckBox *writable = new QCheckBox(tr("Writable")); if ( fileInfo.isWritable() ) writable->setChecked(true); QCheckBox *executable = new QCheckBox(tr("Executable")); if ( fileInfo.isExecutable() ) executable->setChecked(true); QGroupBox *ownerGroup = new QGroupBox(tr("Ownership")); QLabel *ownerLabel = new QLabel(tr("Owner")); QLabel *ownerValueLabel = new QLabel(fileInfo.owner()); ownerValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken); QLabel *groupLabel = new QLabel(tr("Group")); QLabel *groupValueLabel = new QLabel(fileInfo.group()); groupValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken); QVBoxLayout *permissionsLayout = new QVBoxLayout; permissionsLayout->addWidget(readable); permissionsLayout->addWidget(writable); permissionsLayout->addWidget(executable); permissionsGroup->setLayout(permissionsLayout); QVBoxLayout *ownerLayout = new QVBoxLayout; ownerLayout->addWidget(ownerLabel); ownerLayout->addWidget(ownerValueLabel); ownerLayout->addWidget(groupLabel); ownerLayout->addWidget(groupValueLabel); ownerGroup->setLayout(ownerLayout); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(permissionsGroup); mainLayout->addWidget(ownerGroup); mainLayout->addStretch(1); setLayout(mainLayout); }
bool MetaDataExtractor::getMetaData( const QString& filename, QString& title, QString& author, QString& publisher, QDateTime& date, QString& description, QString& format, bool& isDRMBook, QString& collection, QString& language) { QFileInfo info = QFileInfo(filename); bool result = false; if (!info.isReadable()) { qDebug() << Q_FUNC_INFO << "Cannot read " << filename; return false; } format = info.suffix().toLower(); if (format == "pdf") { result = PdfMetaDataExtractor::getMetaData(filename, title, author, publisher, date, description, language); } else if (info.suffix().toLower() == "epub") { collection = EpubMetaDataExtractor::getCollection(filename); result = EpubMetaDataExtractor::getMetaData(filename, title, author, publisher, date, description, isDRMBook, language); } else if (info.suffix().toLower() == "fb2" && info.size() < FILE_MAX_SIZE) { collection = Fb2MetaDataExtractor::getCollection(filename); result = Fb2MetaDataExtractor::getMetaData(filename, title, author, publisher, date, description, isDRMBook, language); } else if ( info.suffix().toLower() == "mobi" && info.size() < FILE_MAX_SIZE) { result = MobiMetaDataExtractor::getMetaData(filename, title, author, publisher, date, description, isDRMBook, language); } else if ( info.suffix().toLower() == "doc" || info.suffix().toLower() == "chm" || info.suffix().toLower() == "txt" || info.suffix().toLower() == "rtf" || info.suffix().toLower() == "html") { title = QFileInfo(filename).baseName(); result = true; } if(language.isEmpty()) language = UNDEFINED_LANGUAGE; return result; }
double MetaDataExtractor::getCollectionIndex(const QString& filename) { qDebug() << Q_FUNC_INFO; QFileInfo info = QFileInfo(filename); if (!info.isReadable()) { qDebug() << Q_FUNC_INFO << "Cannot read " << filename; return false; } QString format = info.suffix().toLower(); if (format == "epub") return EpubMetaDataExtractor::getCollectionIndex(filename); else if (format == "fb2") return Fb2MetaDataExtractor::getCollectionIndex(filename); }