Example #1
0
void Note::createFromFile( QFile &file ) {
    if ( file.open( QIODevice::ReadOnly ) )
    {
        QTextStream in( &file );
        in.setCodec("UTF-8");

        // qDebug() << file.size() << in.readAll();
        QString noteText = in.readAll();
        file.close();

        QFileInfo fileInfo;
        fileInfo.setFile( file );

        // create a nicer name by removing ".txt"
        // TODO: make sure name is ownNote conform
        QString name = fileInfo.fileName();
        name.chop( 4 );

        this->name = name;
        this->fileName = fileInfo.fileName();
        this->noteText = noteText;
        this->fileCreated = fileInfo.created();
        this->fileLastModified = fileInfo.lastModified();
        this->store();
    }

}
Example #2
0
static KUrl promptUser (QWidget *parent, const KUrl& url, const QString& suggestedName)
{
    KUrl destUrl;
    int result = KIO::R_OVERWRITE;
    const QString fileName ((suggestedName.isEmpty() ? url.fileName() : suggestedName));

    do {
        // convert filename to URL using fromPath to avoid trouble with ':' in filenames (#184202)
        destUrl = KFileDialog::getSaveFileName(KUrl::fromPath(fileName), QString(), parent);

        if (destUrl.isLocalFile()) {
            QFileInfo finfo (destUrl.toLocalFile());
            if (finfo.exists()) {
                QDateTime now = QDateTime::currentDateTime();
                KIO::RenameDialog dlg (parent, i18n("Overwrite File?"), url, destUrl,
                                       KIO::RenameDialog_Mode(KIO::M_OVERWRITE | KIO::M_SKIP),
                                       -1, finfo.size(),
                                       now.toTime_t(), finfo.created().toTime_t(),
                                       now.toTime_t(), finfo.lastModified().toTime_t());
                result = dlg.exec();
            }
        }
    } while (result == KIO::R_CANCEL && destUrl.isValid());

    return destUrl;
}
Example #3
0
QString DkUtils::convertDateString(const QString& date, const QFileInfo& file) {

	// convert date
	QString dateConverted;
	QStringList dateSplit = date.split(QRegExp("[/: \t]"));

	if (dateSplit.size() >= 3) {

		QDate dateV = QDate(dateSplit[0].toInt(), dateSplit[1].toInt(), dateSplit[2].toInt());
		dateConverted = dateV.toString(Qt::SystemLocaleShortDate);

		if (dateSplit.size() >= 6) {
			QTime time = QTime(dateSplit[3].toInt(), dateSplit[4].toInt(), dateSplit[5].toInt());
			dateConverted += " " + time.toString(Qt::SystemLocaleShortDate);
		}
	}
	else if (file.exists()) {
		QDateTime dateCreated = file.created();
		dateConverted += dateCreated.toString(Qt::SystemLocaleShortDate);
	}
	else
		dateConverted = "unknown date";

	return dateConverted;
}
Example #4
0
void Note::createFromFile(QFile &file) {
    if (file.open(QIODevice::ReadOnly)) {
        QTextStream in(&file);
        in.setCodec("UTF-8");

        // qDebug() << file.size() << in.readAll();
        QString noteText = in.readAll();
        file.close();

        QFileInfo fileInfo;
        fileInfo.setFile(file);

        // create a nicer name by removing the extension
        // TODO(pbek): make sure name is ownCloud Notes conform
        QString name = fileInfo.fileName();

        int lastPoint = name.lastIndexOf(".");
        name = name.left(lastPoint);

        this->name = name;
        this->fileName = fileInfo.fileName();
        this->noteText = noteText;
        this->fileCreated = fileInfo.created();
        this->fileLastModified = fileInfo.lastModified();
        this->store();
    }
}
Example #5
0
  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;
  }
void AdminDatabase::fillList()
{
	m_listView->clear();
	const QFileInfoList *files = m_dumpDir->entryInfoList("*.sql");
	
	if ( files )
	{
		QFileInfoListIterator it( *files );
		QFileInfo * fi = 0;
		while( (fi=it.current()) != 0 )
		{
			++it;
			KListViewItem *item = new KListViewItem(m_listView);
			
			item->setText(0, fi->baseName().section('.', 0,0) );
			
			QFile tmp(fi->absFilePath());
			tmp.open(IO_ReadOnly);
			QTextStream stream( &tmp );
			item->setText(1, stream.readLine().section("--",1,1));
			tmp.close();
			item->setText(2, fi->created().toString(Qt::ISODate));
		}
		
	}
}
Example #7
0
QMultiMap<QString,FileAttributes> ListFilesInDirectoryTest(QDir dir, bool Hash)
{
    extern Q_CORE_EXPORT int qt_ntfs_permission_lookup;
    qt_ntfs_permission_lookup++; // turn checking on
    QMultiMap<QString, FileAttributes> fileAttHashTable; //making hash table to store file attributes
    dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
    dir.setSorting(QDir::Name);
    QFileInfoList list = dir.entryInfoList();
    for (int i = 0; i < list.size(); ++i)
    {
       QFileInfo fileInfo = list.at(i);
       if (fileInfo.isFile())
       {
           FileAttributes tempFileAttributes;
           QDateTime date = fileInfo.lastModified();
           QString lastModified = date.toString();

            tempFileAttributes.absoluteFilePath = fileInfo.absoluteFilePath();
            tempFileAttributes.fileName = fileInfo.fileName();
            tempFileAttributes.filePath= fileInfo.path();
            if (Hash) tempFileAttributes.md5Hash = GetFileMd5hash(fileInfo.absoluteFilePath());
            tempFileAttributes.lastModified  = fileInfo.lastModified();
            tempFileAttributes.lastRead = fileInfo.lastRead();
            tempFileAttributes.created = fileInfo.created();
            tempFileAttributes.isHidden =  fileInfo.isHidden();
            tempFileAttributes.size = fileInfo.size();
            tempFileAttributes.owner = fileInfo.owner();
            fileAttHashTable.insert(fileInfo.absoluteFilePath(),tempFileAttributes);
       }

    }
return fileAttHashTable;
}
QDateTime
Wallpaper::fileTimeStamp (
        const QString &filePath)
{
    QFileInfo info (filePath);
    
    return info.created ();
}
Example #9
0
void XMLMoveThread::DelSDPicFile()
{
    //qDebug()<<tr("删除图片开始");
    QDir dir;
    if(!dir.exists("/SDHC"))
    {
        LogMsg("lane", tr("未检测到SD卡,不执行SD卡文件清理操作"));
        //qDebug()<<tr("未检测到SD卡,不执行SD卡文件清理操作");
        return;
    }
    QString dirName = "/SDHC/PicFile";
    if(!dir.exists(dirName))
    {
        LogMsg("lane", tr("SD中不存在图片备份,不执行SD卡文件清理操作"));
        //qDebug()<<tr("SD中不存在图片备份,不执行SD卡文件清理操作");
        return;
    }
    QDate curDate = QDateTime::currentDateTime().addDays(-getLaneInfo()->getPicSaveDay()).date();
    QString tmpFileName = curDate.toString("MMdd");
    dir.setPath(dirName);
    QFileInfoList dirList = dir.entryInfoList(QDir::Dirs,QDir::Time);
    QFileInfo dirInfo;
    int count = dirList.count();
    for(int i = count - 1;i > 0;i--)
    {
        //qDebug()<<tr("SD卡图片文件夹数量:%1").arg(count);
        //保留一个文件夹
        //        if(count <= 3)
        //        {
        //            qDebug()<<tr("保留一个文件夹");
        //            return;
        //        }
        dirInfo = dirList.at(i);
        if(!dirInfo.fileName().startsWith(".") && dirInfo.created().date() <= curDate)
            //if(dirInfo.fileName() == tmpFileName)
        {
            tmpFileName = dirInfo.fileName();
            //qDebug()<<tr("确定要删除文件目录:%1").arg(tmpFileName);
            dir.setPath(dirName + "/" + tmpFileName);
            QFileInfoList fileList = dir.entryInfoList(QDir::Files,QDir::Time);
            for(int i = 0;i < fileList.count();i++)
            {
                if(!dir.exists("/SDHC"))
                {
                    LogMsg("lane", tr("文件清理过程中检测不到SD卡"));
                    //qDebug()<<tr("文件清理过程中检测不到SD卡");
                    return;
                }
                QFile::remove(fileList.at(i).filePath());
            }
            dir.rmdir(dirInfo.filePath());
            //count --;
        }
    }
}
Example #10
0
/*!
    Cleans the cache so that its size is under the maximum cache size.
    Returns the current size of the cache.

    When the current size of the cache is greater than the maximumCacheSize()
    older cache files are removed until the total size is less then 90% of
    maximumCacheSize() starting with the oldest ones first using the file
    creation date to determine how old a cache file is.

    Subclasses can reimplement this function to change the order that cache
    files are removed taking into account information in the application
    knows about that QNetworkDiskCache does not, for example the number of times
    a cache is accessed.

    Note: cacheSize() calls expire if the current cache size is unknown.

    \sa maximumCacheSize(), fileMetaData()
 */
qint64 QNetworkDiskCache::expire()
{
    Q_D(QNetworkDiskCache);
    if (d->currentCacheSize >= 0 && d->currentCacheSize < maximumCacheSize())
        return d->currentCacheSize;

    if (cacheDirectory().isEmpty()) {
        qWarning() << "QNetworkDiskCache::expire() The cache directory is not set";
        return 0;
    }

    // close file handle to prevent "in use" error when QFile::remove() is called
    d->lastItem.reset();

    QDir::Filters filters = QDir::AllDirs | QDir:: Files | QDir::NoDotAndDotDot;
    QDirIterator it(cacheDirectory(), filters, QDirIterator::Subdirectories);

    QMultiMap<QDateTime, QString> cacheItems;
    qint64 totalSize = 0;
    while (it.hasNext()) {
        QString path = it.next();
        QFileInfo info = it.fileInfo();
        QString fileName = info.fileName();
        if (fileName.endsWith(CACHE_POSTFIX)) {
            cacheItems.insert(info.created(), path);
            totalSize += info.size();
        }
    }

    int removedFiles = 0;
    qint64 goal = (maximumCacheSize() * 9) / 10;
    QMultiMap<QDateTime, QString>::const_iterator i = cacheItems.constBegin();
    while (i != cacheItems.constEnd()) {
        if (totalSize < goal)
            break;
        QString name = i.value();
        QFile file(name);
        qint64 size = file.size();
        file.remove();
        totalSize -= size;
        ++removedFiles;
        ++i;
    }
#if defined(QNETWORKDISKCACHE_DEBUG)
    if (removedFiles > 0) {
        qDebug() << "QNetworkDiskCache::expire()"
                << "Removed:" << removedFiles
                << "Kept:" << cacheItems.count() - removedFiles;
    }
#endif
    return totalSize;
}
Example #11
0
/*!
    \internal
    Loads the information from /etc/mime.types from all installpaths, and the root directory
*/
void QMimeType::loadExtensions()
{
    QStringList paths;
    paths << QLatin1String("/") << Qtopia::installPaths();
    const int CheckIntervalSeconds = 60 * 10;

    const QString etcMimeTypesConst = QLatin1String("etc/mime.types");

    QFileInfo fi;
    foreach(QString path, paths)
    {
        QString file = QDir::cleanPath(path+etcMimeTypesConst);
        if(!loadedTimes()->contains(path) || loadedTimes()->value(path).secsTo(QDateTime::currentDateTime()) > CheckIntervalSeconds)
        {
            fi.setFile(file);
            if(fi.exists() && fi.created() > loadedTimes()->value(path))
            {
                loadExtensions(file);
                loadedTimes()->insert(path, fi.created());
            }
        }
    }
Example #12
0
TEST(codegen, DISABLED_reference)
{
  soft::Reference reference;
  QFileInfo info ("/tmp/thermo-edited.dat");
  reference.uri = "file://" + info.absoluteFilePath().toStdString();
  reference.created = info.created().toString("dd-mm-yyyy").toStdString();
  reference.owner = info.owner().toStdString();
  reference.lastModified = info.lastModified().toString("dd-mm-yyyy").toStdString();
  reference.sha1 = toStdBlob(sha1(info.absoluteFilePath()));

  soft::Storage storage("mongo2", "mongodb://localhost", "db=codegentest;coll=reference");
  storage.save(&reference);
}
Example #13
0
QFileInfo ImageFrame::getPreviousFile(QString file){
  int increment = 0;
  ProcessControl * pc = imageDisplay->getProcess();
  QFileInfo fi = QFileInfo(file);
  if(pc){
    increment = pc->getOptions()->output_period;
  }else{
    if(suggestedIncrement.contains(fi.path())){
      // There is already an increment for this directory, use that
      increment = suggestedIncrement.value(fi.path());
    }else{
      increment = discoverIncrement(fi);
      suggestedIncrement.insert(fi.path(),increment);
    }
  }  
  file = OutputWatcher::incrementFilename(file,-increment);
  QFileInfo ret = QFileInfo(file);
  if(ret.exists() && ret.created() <= fi.created()){
    return ret;
  }
  return QFileInfo();
}
Example #14
0
QDateTime VideoItem::getDate()
{
    QDateTime result;

    result = _videoData->pictureDate();
    if (!result.isValid()) {
        QFileInfo info;

        info.setFile(_fileName);

        result = info.created();
    }

    return result;
}
Example #15
0
TEST(codegen, DISABLED_collectionWithFileAndReference)
{
  soft::File file;
  soft::Reference reference;

  QFileInfo info ("/tmp/thermo-edited.dat");
  QFile data(info.absoluteFilePath());
  if (!data.open(QIODevice::ReadOnly)) {
    FAIL();
  }
  reference.uri = "file://" + info.absoluteFilePath().toStdString();
  reference.created = info.created().toString("dd-mm-yyyy").toStdString();
  reference.owner = info.owner().toStdString();
  reference.lastModified = info.lastModified().toString("dd-mm-yyyy").toStdString();
  reference.sha1 = toStdBlob(sha1(info.absoluteFilePath()));

  file.filename = info.fileName().toStdString();
  file.suffix = info.suffix().toStdString();
  file.size = info.size();
  auto buffer = data.readAll();
  file.data = toStdBlob(buffer);
  data.close();

  soft::Collection collection;
  collection.setName("thermo");
  collection.setVersion("1.0");
  collection.attachEntity("file1", &file);
  collection.attachEntity("ref", &reference);
  collection.connect("file1", "has-info", "ref");

  soft::Storage storage("mongo2", "mongodb://localhost", "db=codegentest;coll=collectiontest3");
  storage.save(&collection);

  soft::Collection copyCollection(collection.id());
  soft::Reference refCopy;
  copyCollection.attachEntity("myref", &refCopy);
  storage.load(&copyCollection);
  std::string name, version, ns, id;
  copyCollection.findEntity("ref", name, version, ns, id);
  soft::Reference refCopy2(id);
  storage.load(&refCopy2);
  ASSERT_EQ(refCopy.sha1, reference.sha1);
  ASSERT_EQ(refCopy2.sha1, reference.sha1);
  ASSERT_EQ(refCopy.uri, reference.uri);
  ASSERT_EQ(refCopy2.uri, reference.uri);
  ASSERT_EQ(refCopy.created, reference.created);
  ASSERT_EQ(refCopy2.created, reference.created);
}
Example #16
0
bool QMinizip::addFileToZip(QString filepath, QString newname)
{
    QFile file = { filepath };

    if (!file.exists())
        return false;

    if (!file.open(QIODevice::ReadOnly))
        return false;

    QFileInfo fileInfo = QFileInfo(file);

    QByteArray data = file.readAll();
    QDateTime created = fileInfo.created();

    return addDataToZip(&data, newname, created);
}
Example #17
0
void TupThemeSelector::loadSchemes()
{
    QDir themeDir(SHARE_DIR + "themes");
    
    if (themeDir.exists()) {
        m_allSchemes->clear();
        QFileInfoList files = themeDir.entryInfoList(QStringList() <<"*.tupt");
        
        for (int i = 0; i < files.count(); i++) {
             QFileInfo iterator = files[i];
             QTreeWidgetItem *item = new QTreeWidgetItem(m_allSchemes);
             item->setText(0, iterator.fileName());
             item->setText(1, iterator.owner());
             item->setText(2, iterator.created().toString());
        }
    }
}
void LoacalFileServer::display(QString* currentPath)
{
	//QString currentPath = root;
	this->setWindowTitle("LocalFileServer : "+(*currentPath));
	QDir rootDir(*currentPath);
	QList<QTreeWidgetItem *> itemList;
	QStringList tmplist;
	tmplist << "*";
	QFileInfoList list = rootDir.entryInfoList(tmplist);

	for(unsigned int i = 0;i<list.count();i++)
	{
		QFileInfo tmpFileInfo = list.at(i);

		QTreeWidgetItem *item = new QTreeWidgetItem;
		
		if(tmpFileInfo.fileName() == "." || tmpFileInfo.fileName() == "..")
				continue;

		item->setText(0,tmpFileInfo.fileName());
		
		if(tmpFileInfo.isDir())
		{
			item->setText(1,QString(""));
		}
		else
		{
			item->setText(1,QString::number(tmpFileInfo.size()));
		}
		
		item->setText(2,tmpFileInfo.created().toString("MMM dd yyyy"));
		
		item->setText(3,tmpFileInfo.lastModified().toString("MMM dd yyyy"));

		QPixmap pixmap(tmpFileInfo.isDir()?"./dir.png":"./file.png");
		item->setIcon(0,pixmap);
		
		itemList.push_back(item);

		//the path is whether the directory
		isDirectory[tmpFileInfo.fileName()] = tmpFileInfo.isDir();
	}

	fileWidget->addTopLevelItems(itemList);
}
Example #19
0
QDateTime ItemScanner::creationDateFromFilesystem(const QFileInfo& info)
{
    // creation date is not what it seems on Unix
    QDateTime ctime = info.created();
    QDateTime mtime = info.lastModified();

    if (ctime.isNull())
    {
        return mtime;
    }

    if (mtime.isNull())
    {
        return ctime;
    }

    return qMin(ctime, mtime);
}
Example #20
0
QDateTime DkUtils::convertDate(const QString& date, const QFileInfo& file) {

	// convert date
	QDateTime dateCreated;
	QStringList dateSplit = date.split(QRegExp("[/: \t]"));

	if (dateSplit.size() >= 3) {

		QDate dateV = QDate(dateSplit[0].toInt(), dateSplit[1].toInt(), dateSplit[2].toInt());
		QTime time;

		if (dateSplit.size() >= 6)
			time = QTime(dateSplit[3].toInt(), dateSplit[4].toInt(), dateSplit[5].toInt());

		dateCreated = QDateTime(dateV, time);
	}
	else if (file.exists())
		dateCreated = file.created();

	return dateCreated;
};
void DatePickerDialog::on_btnBrowse_clicked()
{
    //First check to see if the Library folder exists where the executable is (for USB sticks)
    QVariant lastDirVar = appsettings->value(this, GC_SETTINGS_LAST_IMPORT_PATH);
    QString lastDir = (lastDirVar != QVariant())
        ? lastDirVar.toString() : QDir::homePath();
    fileName = QFileDialog::getOpenFileName(
        this, tr("Import CSV"), lastDir,
        tr("Comma Separated Values (*.csv)"));
    if (!fileName.isEmpty()) {
        lastDir = QFileInfo(fileName).absolutePath();
        appsettings->setValue(GC_SETTINGS_LAST_IMPORT_PATH, lastDir);

        // Find the datetimestamp from the filename.
        // If we can't, use the creation time.
        // eg. GoldenCheetah YYYY_MM_DD_HH_MM_SS.csv
        //     Ergomo YYYYMMDD_HHMMSS_NAME_SURNAME.CSV
        QFileInfo *qfi = new QFileInfo(fileName);
        QString name = qfi->baseName();
        QRegExp rxGoldenCheetah("^(19|20)\\d\\d_[01]\\d_[0123]\\d_[012]\\d_[012345]\\d_[012345]\\d$");
        QRegExp rxErgomo("^(19|20)\\d\\d[01]\\d[0123]\\d_[012]\\d[012345]\\d[012345]\\d_[A-Z_]+$");
        if (rxGoldenCheetah.indexIn(name) == 0) {
            date = QDateTime::fromString(name.left(19), "yyyy_MM_dd_hh_mm_ss");
        } else if (rxErgomo.indexIn(name) == 0) {
            date = QDateTime::fromString(name.left(15), "yyyyMMdd_hhmmss");
        } else {
            date = qfi->created();
        }
	// and put it into the datePicker dialog
	dateTimeEdit->setDateTime(date);

    }
    txtBrowse->setText(fileName);

	// allow date to be changed, and enable OK button
	dateTimeEdit->setEnabled(TRUE);
	lblOccur->setEnabled(TRUE);
	btnOK->setEnabled(TRUE);
}
Example #22
0
int ImageFrame::discoverIncrement(QFileInfo fi) const{
  // We have no idea of the increment lets try to determine it the hard way
  QDir dir = QDir(fi.absolutePath());
  QStringList filters;
  QRegExp rep  = QRegExp("(.*)-(\\d+)");
  rep.exactMatch(fi.baseName());
  int iter1 = rep.cap(2).toInt();
  QString s = rep.cap(2);
  s.chop(4);
  filters << rep.cap(1)+"-"+s+"*"+fi.completeSuffix();
  dir.setNameFilters(filters);  
  dir.setFilter(QDir::Files|QDir::Readable);
  QStringList currentFiles = dir.entryList();
  int size = currentFiles.size();
  QFileInfo previous;
  QFileInfo next;
  for(int i = 0;i<size;i++){
    QFileInfo fi2 = QFileInfo(dir,currentFiles[i]);
    if(fi2.created() > fi.created()){
      if(next.fileName().isEmpty()){
	next = fi2;
      }else{
	if(fi2.created() < next.created()){
	  next = fi2;
	}
      }
    }else if(fi2.created() < fi.created()){
      if(previous.fileName().isEmpty()){
	previous = fi2;
      }else{
	if(fi2.created() > previous.created()){
	  previous = fi2;
	}
      }    
    }
  }
  int iter0 = -1;
  if(!previous.fileName().isEmpty()){
    rep.exactMatch(previous.baseName());
    iter0 = rep.cap(2).toInt();
  }
  int iter2 = -1;
  if(!next.fileName().isEmpty()){
    rep.exactMatch(next.baseName());
    iter2 = rep.cap(2).toInt();
  }
  if(iter0 == -1 && iter2 == -1){
    qDebug("Could not determine increment");
    return -1;
  }
  if(iter0 == -1){
    return iter2-iter1;
  }
  if(iter2 == -1){
    return iter1-iter0;
  }
  if(iter2-iter1 == iter1-iter0){
    return iter2-iter1;
  }else{
    qDebug("Iteration increment not constant");
    return iter2-iter1;
  }
  return -1;
}
Example #23
0
static bool isNotFromToday( const QFileInfo &fileInfo )
{
	auto creationDate = fileInfo.created().date();

	return creationDate != TODAY;
}
Example #24
0
/*!
    returns a string containing the general information about the file \c name
    and some content specific information
    (number of columns and lines for ASCII, color-depth for images etc.).
 */
QString FileDataSource::fileInfoString(const QString &name){
	QString infoString;
	QFileInfo fileInfo;
	QString fileTypeString;
	QIODevice *file = new QFile(name);

	QString fileName;
    if (name.at(0) != QDir::separator()) {
        fileName = QDir::homePath() + QDir::separator() + name;
    } else {
        fileName = name;
	}

	if(file==0)
		file = new QFile(fileName);

	if (file->open(QIODevice::ReadOnly)){
		QStringList infoStrings;

		//general information about the file
		infoStrings << "<u><b>" + fileName + "</b></u><br>";
		fileInfo.setFile(fileName);

		infoStrings << i18n("Readable: %1", fileInfo.isReadable() ? i18n("yes") : i18n("no"));

		infoStrings << i18n("Writable: %1", fileInfo.isWritable() ? i18n("yes") : i18n("no"));

		infoStrings << i18n("Executable: %1", fileInfo.isExecutable() ? i18n("yes") : i18n("no"));

		infoStrings << i18n("Created: %1", fileInfo.created().toString());
		infoStrings << i18n("Last modified: %1", fileInfo.lastModified().toString());
		infoStrings << i18n("Last read: %1", fileInfo.lastRead().toString());
		infoStrings << i18n("Owner: %1", fileInfo.owner());
		infoStrings << i18n("Group: %1", fileInfo.group());
		infoStrings << i18n("Size: %1", i18np("%1 cByte", "%1 cBytes", fileInfo.size()));

#ifdef HAVE_FITS
        if (fileName.endsWith(QLatin1String(".fits"))) {
            FITSFilter* fitsFilter = new FITSFilter;

            infoStrings << i18n("Images: %1", QString::number(fitsFilter->imagesCount(fileName) ));
            infoStrings << i18n("Tables: %1", QString::number(fitsFilter->tablesCount(fileName) ));

            delete fitsFilter;
        }
#endif

		// file type and type specific information about the file
#ifdef Q_OS_LINUX
		QProcess *proc = new QProcess();
		QStringList args;
		args<<"-b"<<fileName;
		proc->start( "file", args);

		if(proc->waitForReadyRead(1000) == false){
			infoStrings << i18n("Could not open file %1 for reading.", fileName);
		}else{
			fileTypeString = proc->readLine();
			if( fileTypeString.contains(i18n("cannot open")) )
				fileTypeString="";
			else {
				fileTypeString.remove(fileTypeString.length()-1,1);	// remove '\n'
			}
		}
		infoStrings << i18n("File type: %1", fileTypeString);
#endif

		//TODO depending on the file type, generate additional information about the file:
		//Number of lines for ASCII, color-depth for images etc. Use the specific filters here.
		// port the old labplot1.6 code.
		if( fileTypeString.contains("ASCII")){
			infoStrings << "<br/>";
			infoStrings << i18n("Number of columns: %1", AsciiFilter::columnNumber(fileName));

			infoStrings << i18n("Number of lines: %1", AsciiFilter::lineNumber(fileName));
		}
		infoString += infoStrings.join("<br/>");
	} else{
		infoString += i18n("Could not open file %1 for reading.", fileName);
	}

	return infoString;
}
/// compare directory based on session index
/// \param sessionOneDir first directory
/// \param sessionTwoDir second directory
/// \return True if first one is having less valued index
bool CompareDirOnSessionIndex(QFileInfo sessionOneDir, QFileInfo sessionTwoDir)
{
    return sessionOneDir.created() < sessionTwoDir.created();
}
Example #26
0
bool DkUtils::compDateCreated(const QFileInfo& lhf, const QFileInfo& rhf) {

	return lhf.created() < rhf.created();
}
Example #27
0
void XMLMoveThread::movePicFile()
{
    //加载图片文件夹
    QDir dir;
    if(!dir.exists("/SDHC"))
    {
        LogMsg("lane", tr("未检测到SD卡,退出备份"));
        //qDebug()<<tr("未检测到SD卡,退出图片备份");
        return;
    }
    dir.setPath("/Program_Data");
    QFileInfoList fileList = dir.entryInfoList(QDir::Dirs,QDir::Time);
    QFileInfo fileInfo;
    int fileCount = fileList.count();
    for(int i = fileCount - 1 ; i >= 0; i--)
    {
        //        if(fileCount <= 3)
        //        {
        //            qDebug()<<tr("保留当天文件夹");
        //            return;
        //        }
        //qDebug()<<tr("检测到图片文件夹数量:%1名称:%2").arg(fileList.count()).arg(fileList.at(i).fileName());
        fileInfo = fileList.at(i);
        //每个图片文件夹中的文件(去除根目录与最新文件夹)
        if(fileInfo.exists() && !fileInfo.fileName().startsWith(".") && fileInfo.created().date() != QDate::currentDate())
        {
            //sd卡中创建同名图片文件夹
            QDir picDir;
            QString SDPicDirName = "/SDHC/PicFile/"+fileInfo.fileName();
            //qDebug()<<tr("检测到图片文件夹%1").arg(SDPicDirName);
            if(!picDir.exists(SDPicDirName))
            {
                if(!picDir.mkpath(SDPicDirName))
                {
                    LogMsg("lane", tr("备份线程:图片文件夹%1创建失败").arg(SDPicDirName));
                    return;
                }
            }
            picDir.setPath("/Program_Data/"+fileInfo.fileName());
            QFileInfoList picList = picDir.entryInfoList(QDir::Files,QDir::Time);
            QFileInfo picFileInfo;
            bool delOver = true;
            for(int i = 0;i < picList.count();i++)
            {
                picFileInfo = picList.at(i);
                if(picFileInfo.exists())
                {
                    //qDebug()<<tr("图片文件:%1").arg(picFileInfo.fileName());
                    if(!dir.exists("/SDHC"))
                    {
                        LogMsg("lane", tr("未检测到SD卡,退出备份"));
                        //qDebug()<<tr("未检测到SD卡,退出图片备份");
                        return;
                    }
                    if(!QFile::copy(picFileInfo.filePath(),SDPicDirName+"/" + picFileInfo.fileName()))
                    {
                        LogMsg("lane", tr("%1文件复制失败,退出此次备份").arg(picFileInfo.filePath()));
                        //qDebug()<<tr("%1文件复制失败,退出此次备份").arg(picFileInfo.absoluteFilePath());
                        delOver = false;
                        break;
                    }
                    if(!QFile::remove(picFileInfo.filePath()))
                    {
                        LogMsg("lane", tr("%1文件删除失败,退出此次备份").arg(picFileInfo.filePath()));
                        delOver = false;
                        break;
                    }
                }
                msleep(500);
            }
            //文件夹内文件全部转移后删除文件夹
            if(delOver == true)
            {
                dir.rmdir(fileInfo.filePath());
                //fileCount = fileCount-1;
            }
        }
    }
}
bool RobotsGeneratorPluginBase::canGenerateTo(QString const &project)
{
	QFileInfo const fileInfo(QApplication::applicationDirPath() + "/" + defaultFilePath(project));
	int const difference = fileInfo.lastModified().toMSecsSinceEpoch() - fileInfo.created().toMSecsSinceEpoch();
	return !fileInfo.exists() || difference < maxTimestampsDifference;
}