! 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.). */
| 1598 | (number of columns and lines for ASCII, color-depth for images etc.). |
| 1599 | */ |
| 1600 | QString ImportFileWidget::fileInfoString(const QString& name) const { |
| 1601 | DEBUG(Q_FUNC_INFO << ", file name = " << STDSTRING(name)) |
| 1602 | QString infoString; |
| 1603 | QFileInfo fileInfo; |
| 1604 | QString fileTypeString; |
| 1605 | QIODevice* file = new QFile(name); |
| 1606 | |
| 1607 | QString fileName = absolutePath(name); |
| 1608 | |
| 1609 | if (!file) |
| 1610 | file = new QFile(fileName); |
| 1611 | |
| 1612 | if (file->open(QIODevice::ReadOnly)) { |
| 1613 | QStringList infoStrings; |
| 1614 | |
| 1615 | infoStrings << QStringLiteral("<u><b>") + fileName + QStringLiteral("</b></u><br>"); |
| 1616 | |
| 1617 | // File type given by "file" |
| 1618 | #ifdef Q_OS_LINUX |
| 1619 | const QString fileFullPath = safeExecutableName(QStringLiteral("file")); |
| 1620 | if (fileFullPath.isEmpty()) |
| 1621 | return i18n("file command not found"); |
| 1622 | |
| 1623 | QProcess proc; |
| 1624 | QStringList args; |
| 1625 | args << QStringLiteral("-b") << fileName; |
| 1626 | startHostProcess(proc, fileFullPath, args); |
| 1627 | |
| 1628 | if (proc.waitForReadyRead(1000) == false) |
| 1629 | infoStrings << i18n("Reading from file %1 failed.", fileName); |
| 1630 | else { |
| 1631 | fileTypeString = QLatin1String(proc.readLine()); |
| 1632 | if (fileTypeString.contains(i18n("cannot open"))) |
| 1633 | fileTypeString.clear(); |
| 1634 | else |
| 1635 | fileTypeString.remove(fileTypeString.length() - 1, 1); // remove '\n' |
| 1636 | } |
| 1637 | infoStrings << i18n("<b>File type:</b> %1", fileTypeString); |
| 1638 | #endif |
| 1639 | |
| 1640 | // General: |
| 1641 | fileInfo.setFile(fileName); |
| 1642 | infoStrings << QStringLiteral("<b>") << i18n("General:") << QStringLiteral("</b>"); |
| 1643 | |
| 1644 | infoStrings << i18n("Readable: %1", fileInfo.isReadable() ? i18n("yes") : i18n("no")); |
| 1645 | infoStrings << i18n("Writable: %1", fileInfo.isWritable() ? i18n("yes") : i18n("no")); |
| 1646 | infoStrings << i18n("Executable: %1", fileInfo.isExecutable() ? i18n("yes") : i18n("no")); |
| 1647 | |
| 1648 | infoStrings << i18n("Birth time: %1", fileInfo.birthTime().toString()); |
| 1649 | infoStrings << i18n("Last metadata changed: %1", fileInfo.metadataChangeTime().toString()); |
| 1650 | infoStrings << i18n("Last modified: %1", fileInfo.lastModified().toString()); |
| 1651 | infoStrings << i18n("Last read: %1", fileInfo.lastRead().toString()); |
| 1652 | infoStrings << i18n("Owner: %1", fileInfo.owner()); |
| 1653 | infoStrings << i18n("Group: %1", fileInfo.group()); |
| 1654 | infoStrings << i18n("Size: %1", i18np("%1 cByte", "%1 cBytes", fileInfo.size())); |
| 1655 | |
| 1656 | // Summary: |
| 1657 | infoStrings << QStringLiteral("<b>") << i18n("Summary:") << QStringLiteral("</b>"); |