Permalink
Browse files

Qt/FilesystemWidget: Add size column

  • Loading branch information...
spycrab committed Jun 2, 2018
1 parent f09f83c commit f6865117e47fb48c58ab53af1297a79b850a345a
@@ -8,6 +8,19 @@ namespace DiscIO
{
FileInfo::~FileInfo() = default;
u64 FileInfo::GetTotalSize() const
{
if (!IsDirectory())
return GetSize();
u64 size = 0;
for (const auto& entry : *this)
size += entry.GetTotalSize();
return size;
}
FileSystem::~FileSystem() = default;
} // namespace
} // namespace DiscIO
@@ -86,6 +86,8 @@ class FileInfo
// The size of a file.
// Not guaranteed to return a meaningful value for directories.
virtual u32 GetSize() const = 0;
// For a file, returns its size. For a directory, returns the total size of its contents.
u64 GetTotalSize() const;
virtual bool IsDirectory() const = 0;
// The number of files and directories in a directory, including those in subdirectories.
// Not guaranteed to return a meaningful value for files.
@@ -124,4 +126,4 @@ class FileSystem
// because it will check IsValid for you, will automatically pick the right type of filesystem,
// and will cache the filesystem in case it's needed again later.
} // namespace
} // namespace DiscIO
@@ -25,6 +25,8 @@
#include "DolphinQt2/QtUtils/ActionHelper.h"
#include "DolphinQt2/Resources.h"
#include "UICommon/UICommon.h"
constexpr int ENTRY_PARTITION = Qt::UserRole;
constexpr int ENTRY_NAME = Qt::UserRole + 1;
constexpr int ENTRY_TYPE = Qt::UserRole + 2;
@@ -52,11 +54,18 @@ void FilesystemWidget::CreateWidgets()
{
auto* layout = new QVBoxLayout;
m_tree_model = new QStandardItemModel(0, 1);
m_tree_model = new QStandardItemModel(0, 2);
m_tree_model->setHorizontalHeaderLabels({tr("Name"), tr("Size")});
m_tree_view = new QTreeView(this);
m_tree_view->setModel(m_tree_model);
m_tree_view->setContextMenuPolicy(Qt::CustomContextMenu);
m_tree_view->header()->hide();
auto* header = m_tree_view->header();
header->setSectionResizeMode(0, QHeaderView::Stretch);
header->setSectionResizeMode(1, QHeaderView::ResizeToContents);
header->setStretchLastSection(false);
// Windows: Set style to (old) windows, which draws branch lines
#ifdef _WIN32
@@ -132,7 +141,14 @@ void FilesystemWidget::PopulateDirectory(int partition_id, QStandardItem* root,
item->setData(QString::fromStdString(info.GetPath()), ENTRY_NAME);
item->setData(QVariant::fromValue(info.IsDirectory() ? EntryType::Dir : EntryType::File),
ENTRY_TYPE);
root->appendRow(item);
const auto size = info.GetTotalSize();
auto* size_item = new QStandardItem(QString::fromStdString(UICommon::FormatSize(size)));
size_item->setTextAlignment(Qt::AlignRight);
size_item->setEditable(false);
root->appendRow({item, size_item});
}
}

0 comments on commit f686511

Please sign in to comment.