示例#1
0
FileInfo toFileInfo(const QFileInfo &info)
{
    FileInfo fi;

    fi.m_valid = true;
    fi.m_exists = info.exists();
    fi.m_permissions = info.permissions();
    fi.m_isSymlink = info.isSymLink();
    fi.m_type = FileInfo::System;
    fi.m_hidden = info.isHidden();
    fi.m_size = -1;
    fi.m_lastModified = info.lastModified();

    if (info.isDir())
        fi.m_type = FileInfo::Dir;
    else if (info.isFile())
        fi.m_type = FileInfo::File;
    else if (!info.exists() && info.isSymLink())
        fi.m_type = FileInfo::System;

    if (fi.type() == FileInfo::Dir)
        fi.m_size = 0;
    else if (fi.type() == FileInfo::File)
        fi.m_size = info.size();
    if (!info.exists() && !info.isSymLink())
        fi.m_size = -1;

    return fi;
}
示例#2
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;
  }
DocumentWatcher::Details::Details(const QFileInfo& info) :
	path(info.canonicalFilePath()),
	modified(info.lastModified()),
	permissions(info.permissions()),
	ignored(false)
{
}
示例#4
0
static inline std::string permissions(const QFileInfo &fi)
{
    std::string result = permissions(fi.permissions());
    if (fi.isSymLink())
        result[0] = 'l';
    else if (fi.isDir())
        result[0] = 'd';
    return result;
}
示例#5
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)
{};
示例#6
0
void CentralDirFileHeader::initFromFile( const QFileInfo& file )
{
    LocalFileHeader::initFromFile( file );

    setPermissions( file.permissions(), file.isDir() );

    // Windows Only: Add the files attributes to externalAttr (e.g. archive, readonly, system etc.)
    quint32 attr = getFileAttributes( file.filePath() );

    if ( attr & 0x20 )  // Archive
        externalFileAttr |= 0x20;
    if ( attr & 0x10 )  // Folder
        externalFileAttr |= 0x10;
    if ( attr & 0x08 )  // System
        externalFileAttr |= 0x08;
    if ( attr & 0x02 )  // Hidden
        externalFileAttr |= 0x02;
    if ( attr & 0x01 )  // ReadOnly
        externalFileAttr |= 0x01;
}
示例#7
0
文件: widget.cpp 项目: AWeinb/qTox
void Widget::confirmExecutableOpen(const QFileInfo file)
{
    static const QStringList dangerousExtensions = { "app", "bat", "com", "cpl", "dmg", "exe", "hta", "jar", "js", "jse", "lnk", "msc", "msh", "msh1", "msh1xml", "msh2", "msh2xml", "mshxml", "msi", "msp", "pif", "ps1", "ps1xml", "ps2", "ps2xml", "psc1", "psc2", "py", "reg", "scf", "sh", "src", "vb", "vbe", "vbs", "ws", "wsc", "wsf", "wsh" };

    if (dangerousExtensions.contains(file.suffix()))
    {
        if (!GUI::askQuestion(tr("Executable file", "popup title"), tr("You have asked qTox to open an executable file. Executable files can potentially damage your computer. Are you sure want to open this file?", "popup text"), false, true))
        {
            return;
        }
        
        // The user wants to run this file, so make it executable and run it
        QFile(file.filePath()).setPermissions(file.permissions() | QFile::ExeOwner | QFile::ExeUser | QFile::ExeGroup | QFile::ExeOther);
        QProcess::startDetached(file.filePath());
    }
    else
    {
        QDesktopServices::openUrl(QUrl::fromLocalFile(file.filePath()));
    }
}
示例#8
0
void FileInfoWidget::slotSelectionChanged(const QItemSelection&, const QItemSelection&)
{
    Page* pPage = dynamic_cast<Page*>(parent());
    if (pPage)
    {
        QFileSystemModel* pModel = dynamic_cast<QFileSystemModel*>(pPage->mpFileList->model());
        if (pModel)
        {
            QFileInfo info = pModel->fileInfo(pPage->mpFileList->currentIndex());
            if (info.isFile() && qPrintable(info.absoluteFilePath()))
            {
                QPixmap pixmap(info.absoluteFilePath());
                double dScale = pixmap.width() > pixmap.height() ? (double)imageSize.width() / pixmap.width() : (double)imageSize.height() / pixmap.height();
                dScale *= 0.9;
                mpImage->setPixmap(pixmap.scaled(pixmap.width() * dScale, pixmap.height() * dScale));
            }
            else mpImage->setPixmap(transparentImage);

            mpAbsolutePath->setText(QString("File Path: %1").arg(info.absoluteFilePath()));
            mpPermissions->setText(QString("Permissions: %1").arg(info.permissions(), 0, 16));
            mpSize->setText(QString("Size: %1").arg(info.size()));
        }
    }
}
示例#9
0
bool MyDirEntry::equals(const QFileInfo& info) const{
  return (  isDir() == info.isDir()
    && owner == info.owner()
    && lastModified == info.lastModified()
    && permissions == info.permissions());
}