示例#1
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;
  }
示例#2
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;
}
示例#3
0
MyDirEntry::MyDirEntry(const QFileInfo& info) : 
  name(info.fileName()),
  owner(info.owner()), 
  group(info.group()), 
  lastModified(info.lastModified()),
  permissions(info.permissions()),
  lastModifiedBy(hostName),
  parent(0)
{};
示例#4
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);
}
示例#5
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);
}
示例#6
0
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
//    QDir * _dir=new QDir();
//   // _dir->mkdir("tmp//audio");
//    _dir->mkpath("tmp/audio");

  /**/
    QDir directory(this->getPath());
    qDebug()<<"getIOSFilePath,m    :"<<this->getPath();
    QFileInfoList fileInfoList;
    if (this->hiddenFiles)
    {
        fileInfoList = directory.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System);
    }
    else
    {
        fileInfoList = directory.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot);
    }
    QFileInfo fileInfo;
    File file;
    QList<File> *fileList = new QList<File>;
    QFileIconProvider *provider = new QFileIconProvider;
    while (!fileInfoList.isEmpty())
    {
        if (this->procesEvents)
            qApp->processEvents();
        fileInfo = fileInfoList.takeFirst();

        file.fileIcon = provider->icon(fileInfo);
        file.fileName = fileInfo.fileName();
        qDebug()<<"IOSFileName:"<<file.fileName;
        file.fileSize = QString::number(fileInfo.size());
        file.fileDate = fileInfo.lastModified().toString("MMM dd yyyy");
        file.filePath = fileInfo.absoluteFilePath();
        file.filePermissions = "";
        file.fileOwner = fileInfo.owner();
        if (fileInfo.isDir())
            file.fileType = "dir";
        else
            file.fileType = "file";

        fileList->append(file);
    }
    delete provider;
    return fileList;
    return a.exec();
}
示例#7
0
//! [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);
}
示例#8
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());
        }
    }
}
示例#9
0
void QLocalFs::operationListChildren( QNetworkOperation *op )
{
#ifdef QLOCALFS_DEBUG
    qDebug( "QLocalFs: operationListChildren" );
#endif
    op->setState( StInProgress );

    dir = QDir( url()->path() );
    dir.setNameFilter( url()->nameFilter() );
    dir.setMatchAllDirs( TRUE );
    if ( !dir.isReadable() ) {
	QString msg = tr( "Could not read directory\n%1" ).arg( url()->path() );
	op->setState( StFailed );
	op->setProtocolDetail( msg );
	op->setErrorCode( (int)ErrListChildren );
	emit finished( op );
	return;
    }

    const QFileInfoList *filist = dir.entryInfoList( QDir::All | QDir::Hidden | QDir::System );
    if ( !filist ) {
	QString msg = tr( "Could not read directory\n%1" ).arg( url()->path() );
	op->setState( StFailed );
	op->setProtocolDetail( msg );
	op->setErrorCode( (int)ErrListChildren );
	emit finished( op );
	return;
    }

    emit start( op );

    QFileInfoListIterator it( *filist );
    QFileInfo *fi;
    QValueList<QUrlInfo> infos;
    while ( ( fi = it.current() ) != 0 ) {
	++it;
	infos << QUrlInfo( fi->fileName(), convertPermissions(fi), fi->owner(), fi->group(),
			   fi->size(), fi->lastModified(), fi->lastRead(), fi->isDir(), fi->isFile(),
			   fi->isSymLink(), fi->isWritable(), fi->isReadable(), fi->isExecutable() );
    }
    emit newChildren( infos, op );
    op->setState( StDone );
    emit finished( op );
}
示例#10
0
////////////////////////////////////////////////////////////////////////////////
//
// GeneralTab
//
////////////////////////////////////////////////////////////////////////////////
PermissionTab::PermissionTab(const QFileInfo& fileInfo, QWidget* parent)
{
  auto permissionGroup = new QGroupBox(tr("Permissions"));
  auto readable = new QCheckBox(tr("Readable"));
  if (fileInfo.isReadable())
    readable->setChecked(true);

  auto writable = new QCheckBox(tr("Writable"));
  if (fileInfo.isWritable())
    writable->setChecked(true);

  auto executable = new QCheckBox(tr("Executable"));
  if (fileInfo.isWritable())
    executable->setChecked(true);

  auto ownerLabel = new QLabel(tr("Owner"));
  auto ownerValueLabel = new QLabel(fileInfo.owner());
       ownerValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);

  auto groupLabel = new QLabel(tr("Group"));
  auto groupValueLabel = new QLabel(fileInfo.group());
       groupValueLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);

  auto permissionLayout = new QVBoxLayout;
  permissionLayout->addWidget(readable);
  permissionLayout->addWidget(writable);
  permissionLayout->addWidget(executable);
  permissionGroup->setLayout(permissionLayout);

  auto ownerGroup = new QGroupBox(tr("Ownership"));
  auto ownerLaout = new QVBoxLayout;
  ownerLaout->addWidget(ownerLabel);
  ownerLaout->addWidget(ownerValueLabel);
  ownerLaout->addWidget(groupLabel);
  ownerLaout->addWidget(groupValueLabel);
  ownerGroup->setLayout(ownerLaout);

  auto layout = new QVBoxLayout();
  layout->addWidget(permissionGroup);
  layout->addWidget(ownerGroup);
  layout->addStretch(1);

  this->setLayout(layout);
}
示例#11
0
void Q3LocalFs::operationListChildren( Q3NetworkOperation *op )
{
#ifdef QLOCALFS_DEBUG
    qDebug( "Q3LocalFs: operationListChildren" );
#endif
    op->setState( StInProgress );

    dir = QDir( url()->path() );
    dir.setNameFilter( url()->nameFilter() );
    dir.setMatchAllDirs( true );
    if ( !dir.isReadable() ) {
	QString msg = tr( "Could not read directory\n%1" ).arg( url()->path() );
	op->setState( StFailed );
	op->setProtocolDetail( msg );
	op->setErrorCode( (int)ErrListChildren );
	emit finished( op );
	return;
    }

    QFileInfoList filist = dir.entryInfoList(QDir::All | QDir::Hidden | QDir::System);
    if ( filist.isEmpty() ) {
	QString msg = tr( "Could not read directory\n%1" ).arg( url()->path() );
	op->setState( StFailed );
	op->setProtocolDetail( msg );
	op->setErrorCode( (int)ErrListChildren );
	emit finished( op );
	return;
    }

    emit start( op );

    Q3ValueList<QUrlInfo> infos;
    for (int i = 0; i < filist.size(); ++i) {
        QFileInfo fi = filist.at(i);
	infos << QUrlInfo( fi.fileName(), convertPermissions(&fi), fi.owner(), fi.group(),
			   fi.size(), fi.lastModified(), fi.lastRead(), fi.isDir(), fi.isFile(),
			   fi.isSymLink(), fi.isWritable(), fi.isReadable(), fi.isExecutable() );
    }
    emit newChildren( infos, op );
    op->setState( StDone );
    emit finished( op );
}
示例#12
0
QList<File> *Computer::getFileList()
{
    QDir directory(this->getPath());
    QFileInfoList fileInfoList;
    if (this->hiddenFiles)
    {
        fileInfoList = directory.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System);
    }
    else
    {
        fileInfoList = directory.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot);
    }
    QFileInfo fileInfo;
    File file;
    QList<File> *fileList = new QList<File>;
    QFileIconProvider *provider = new QFileIconProvider;
    while (!fileInfoList.isEmpty())
    {
        if (this->procesEvents)
            qApp->processEvents();
        fileInfo = fileInfoList.takeFirst();

        file.fileIcon = provider->icon(fileInfo);
        file.fileName = fileInfo.fileName();
        file.fileSize = QString::number(fileInfo.size());
        file.fileDate = fileInfo.lastModified().toString("MMM dd yyyy");
        file.filePath = fileInfo.absoluteFilePath();
        file.filePermissions = "";
        file.fileOwner = fileInfo.owner();
        if (fileInfo.isDir())
            file.fileType = "dir";
        else
            file.fileType = "file";

        fileList->append(file);
    }
    delete provider;
    return fileList;
}
示例#13
0
FileTreeItem::FileTreeItem(const QFileInfo & fileInfo,const FileTreeItem * parentItem,
                           bool scan_subdirs,bool encripted) {
    m_path = (parentItem->rootItem?"":parentItem->archivePath()) + fileInfo.fileName();
    if (fileInfo.isDir()) m_path += "/";
    m_perms = permissions(fileInfo);
    m_user = fileInfo.owner();
    m_group = fileInfo.group();
    m_link_to = fileInfo.symLinkTarget();
    m_file_size = fileInfo.size();
    m_date = fileInfo.lastModified();
    m_parentItem = (FileTreeItem *)parentItem;
    m_encripted = encripted;
    rootItem = false;
    if (is_dir()) {
        if (scan_subdirs) {
            QDirIterator di(fileInfo.filePath(),QDir::AllEntries | QDir::Hidden | QDir::System | QDir::NoDotAndDotDot);
            while (di.hasNext()) {
                di.next();
                appendChild(new FileTreeItem(QFileInfo(di.filePath()),this,true,encripted));
            }
        }
    }
}
示例#14
0
bool MyDirEntry::equals(const QFileInfo& info) const{
  return (  isDir() == info.isDir()
    && owner == info.owner()
    && lastModified == info.lastModified()
    && permissions == info.permissions());
}
示例#15
0
/** Creates the \c ls command result 
  *
  * It creates it in the packetData string.
  *
  */
void RainbruRPG::Network::Ftp::FtpTransfer::lsResult(){
  LOGI("LIST command result :");
  packetData="";
  unsigned int childs=1;

  QDir dir(currentDirectory );
  dir.setFilter(QDir::Dirs| QDir::Files| QDir::NoSymLinks);
  dir.setSorting(QDir::Name);

  QFileInfoList list = dir.entryInfoList();

  LOGCATS("Sending ");
  LOGCATI(list.size());
  LOGCATS(" files.");
  LOGCAT();

  for (int i = 0; i < list.size(); ++i) {
    QFileInfo fileInfo = list.at(i);

    // ====== User permissions
    // Diretory ?
    if (fileInfo.isDir()){
      packetData+="d";

      QDir dir2(fileInfo.absoluteFilePath());
      childs=dir2.count();

    }
    else{
      packetData+="-";
      childs=1;
    }

    packetData+=filePermissions(fileInfo.isReadable(),fileInfo.isWritable(),
				fileInfo.isExecutable());

    packetData+=filePermissions(fileInfo.permission(QFile::ReadGroup),
				fileInfo.permission(QFile::WriteGroup),
				fileInfo.permission(QFile::ExeGroup));

    packetData+=filePermissions(fileInfo.permission(QFile::ReadOther),
				fileInfo.permission(QFile::WriteOther),
				fileInfo.permission(QFile::ExeOther));

    // Child number
    QString sChild;
    sChild.setNum(childs);
    sChild=sChild.rightJustified(5);
    packetData+=sChild;

    // Owner and group names
    packetData+=' ';
    QString sOwner=fileInfo.owner();
    sOwner=sOwner.leftJustified(9);
    packetData+=sOwner;
    QString sGroup=fileInfo.group();
    sGroup=sGroup.leftJustified(9);
    packetData+=sGroup;

    // File size
    qint64 size=fileInfo.size();

    QString sSize=fileSizeToString(size);
    sSize=sSize.rightJustified(8);
    packetData+=sSize;

    // Last modified time
    packetData+=" ";
    QDateTime dt=fileInfo.lastModified();
    packetData+=dt.toString("yyyy-MM-dd hh:mm");

    // File name and EOL
    packetData+=" ";
    packetData+=fileInfo.fileName();
    packetData+="\n";
  }
  LOGI("PacketData done. LIST result can be sent");
  int i=  packetData.size();
  LOGCATS("PacketData lenght :");
  LOGCATI(i);
  LOGCAT();
}
示例#16
0
void CFileList::Load( QString *in_cwd )
{
#ifdef QT_V4LAYOUT
	Q3ListViewItem	*pListViewItem;
#else
	QListViewItem	*pListViewItem;
#endif
    QDir d;
	
	clear();
    if ( in_cwd )
    {
        cwd = *in_cwd;
    }

    d.setFilter( QDir::Files | QDir::Hidden );
    d.cd( cwd );
    d.setNameFilter("*.dsn");

#ifdef QT_V4LAYOUT
    const QFileInfoList list = d.entryInfoList();
    QFileInfo fi;                          // pointer for traversing

	for ( int i = 0; i < list.size(); i ++ ) {
        QString perm, size;
        char driver[ 128 ];

		fi = list.at(i);

        perm = "-";
        perm += fi.permission( QFileInfo::ReadUser ) ? "r" : "-";
        perm += fi.permission( QFileInfo::WriteUser ) ? "w" : "-";
        perm += fi.permission( QFileInfo::ExeUser ) ? "x" : "-";
        perm += fi.permission( QFileInfo::ReadGroup ) ? "r" : "-";
        perm += fi.permission( QFileInfo::WriteGroup ) ? "w" : "-";
        perm += fi.permission( QFileInfo::ExeGroup ) ? "x" : "-";
        perm += fi.permission( QFileInfo::ReadOther ) ? "r" : "-";
        perm += fi.permission( QFileInfo::WriteOther ) ? "w" : "-";
        perm += fi.permission( QFileInfo::ExeOther ) ? "x" : "-";

        size.sprintf( "%d bytes", fi.size());

        pListViewItem = new Q3ListViewItem( this, fi.fileName(), perm, fi.owner(), fi.group(), size );
    }
#else
    const QFileInfoList *list = d.entryInfoList();
    QFileInfoListIterator it( *list );      // create list iterator
    QFileInfo *fi;                          // pointer for traversing

    while ( (fi=it.current()) ) 
    {           // for each file...

        QString perm, size;
        char driver[ 128 ];

        perm = "-";
        perm += fi->permission( QFileInfo::ReadUser ) ? "r" : "-";
        perm += fi->permission( QFileInfo::WriteUser ) ? "w" : "-";
        perm += fi->permission( QFileInfo::ExeUser ) ? "x" : "-";
        perm += fi->permission( QFileInfo::ReadGroup ) ? "r" : "-";
        perm += fi->permission( QFileInfo::WriteGroup ) ? "w" : "-";
        perm += fi->permission( QFileInfo::ExeGroup ) ? "x" : "-";
        perm += fi->permission( QFileInfo::ReadOther ) ? "r" : "-";
        perm += fi->permission( QFileInfo::WriteOther ) ? "w" : "-";
        perm += fi->permission( QFileInfo::ExeOther ) ? "x" : "-";

        size.sprintf( "%d bytes", fi->size());

        pListViewItem = new QListViewItem( this, fi->fileName(), perm, fi->owner(), fi->group(), size );

        ++it;                               // goto next list element
    }
#endif
}
示例#17
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;
}