Skip to content
Permalink
Browse files

implemented to show file size on disk for macOS/Linux.(refs #33)

  • Loading branch information...
haraki committed Jun 24, 2019
1 parent ca50063 commit dd08c2eb4930614966f832c2391e1cfcec945a03
Showing with 63 additions and 14 deletions.
  1. +4 −2 doublefolderpanel.cpp
  2. +25 −1 file.cpp
  3. +2 −0 file.h
  4. +3 −0 fileattributesdialog.cpp
  5. +1 −0 fileattributesdialog.h
  6. +28 −11 fileattributesdialog.ui
@@ -691,19 +691,21 @@ void DoubleFolderPanel::onAttributes()
}

QFileInfo fileInfo = activeForm->getCurrentFileInfo();
QFile file(fileInfo.absoluteFilePath());
QString filePath = fileInfo.absoluteFilePath();
QFile file(filePath);

FileAttributesDialog dialog(fileInfo,
file.permissions(),
file.fileTime(QFile::FileBirthTime),
file.fileTime(QFile::FileModificationTime),
File::getFileSizeOnDisk(filePath),
parentWidget());
if(dialog.exec() != QDialog::Accepted)
{
return;
}

emitChangeFileAttributes(fileInfo.absoluteFilePath(),
emitChangeFileAttributes(filePath,
dialog.getPermissions(),
dialog.getCreated(),
dialog.getLastModified());
@@ -1,4 +1,5 @@
#include <QDebug>
#include <QString>
#include <QDebug>
#include "file.h"
#include "copyworker.h"
#include "removeworker.h"
@@ -7,6 +8,11 @@
#include "settings.h"
#include "mainwindow.h"

#ifdef Q_OS_WIN
#else
#include <sys/stat.h>
#endif

namespace Farman
{

@@ -20,6 +26,24 @@ File::~File()
{
}

qint64 File::getFileSizeOnDisk(const QString& filePath)
{
#ifdef Q_OS_WIN
return 0;
#else
struct stat statBuf;

if(lstat(filePath.toUtf8(), &statBuf) == -1)
{
return -1;
}

qDebug() << "st_size : " << statBuf.st_size << ", st_blocks : " << statBuf.st_blocks;

return statBuf.st_blocks * 512;
#endif
}

bool File::copyFile(const QStringList& srcPaths, const QString& dstDirPath)
{
CopyWorker* copyWorker = new CopyWorker(srcPaths, dstDirPath, false);
2 file.h
@@ -18,6 +18,8 @@ class File : public QObject
explicit File(MainWindow* mainWindow);
~File();

static qint64 getFileSizeOnDisk(const QString& filePath);

Q_SIGNALS:
void createNewFileFinished(const QString& filePath);

@@ -12,6 +12,7 @@ FileAttributesDialog::FileAttributesDialog(const QFileInfo& fileInfo,
QFile::Permissions permissions,
const QDateTime& created,
const QDateTime& lastModified,
const qint64 fileSizeOnDisk,
QWidget *parent/* = Q_NULLPTR*/) :
QDialog(parent),
ui(new Ui::FileAttributesDialog),
@@ -28,10 +29,12 @@ FileAttributesDialog::FileAttributesDialog(const QFileInfo& fileInfo,
if(fileInfo.isDir())
{
ui->informationFileSizeLabel->setText("- ");
ui->informationSizeOnDiskLabel->setText("- ");
}
else
{
ui->informationFileSizeLabel->setText(QString("%L1 ").arg(fileInfo.size()) + tr("Bytes"));
ui->informationSizeOnDiskLabel->setText(QString("%L1 ").arg(fileSizeOnDisk) + tr("Bytes"));
}

ui->ownershipUserLabel->setText(fileInfo.owner());
@@ -23,6 +23,7 @@ class FileAttributesDialog : public QDialog
QFile::Permissions permissions,
const QDateTime& created,
const QDateTime& lastModified,
const qint64 fileSizeOnDisk,
QWidget *parent = Q_NULLPTR);
~FileAttributesDialog();

@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>320</width>
<height>505</height>
<height>529</height>
</rect>
</property>
<property name="sizePolicy">
@@ -56,14 +56,7 @@
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="informationMimeLabel">
<property name="text">
<string>MIME</string>
</property>
</widget>
</item>
<item row="3" column="0">
<item row="1" column="0">
<widget class="QLabel" name="informationMimeHeadLabel">
<property name="text">
<string>MIME :</string>
@@ -73,7 +66,14 @@
</property>
</widget>
</item>
<item row="4" column="0">
<item row="1" column="1">
<widget class="QLabel" name="informationMimeLabel">
<property name="text">
<string>MIME</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="informationFileSizeHeadLabel">
<property name="text">
<string>File size :</string>
@@ -83,13 +83,30 @@
</property>
</widget>
</item>
<item row="4" column="1">
<item row="2" column="1">
<widget class="QLabel" name="informationFileSizeLabel">
<property name="text">
<string>File size</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="informationSizeOnDiskHeadLabel">
<property name="text">
<string>Size on disk :</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="informationSizeOnDiskLabel">
<property name="text">
<string>Size on disk</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

0 comments on commit dd08c2e

Please sign in to comment.
You can’t perform that action at this time.