Qt/FilesystemWidget: Add size column

This commit is contained in:
spycrab 2018-06-02 18:14:42 +02:00
parent f09f83c309
commit f6865117e4
3 changed files with 36 additions and 5 deletions

View File

@ -8,6 +8,19 @@ namespace DiscIO
{ {
FileInfo::~FileInfo() = default; 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; FileSystem::~FileSystem() = default;
} // namespace } // namespace DiscIO

View File

@ -86,6 +86,8 @@ public:
// The size of a file. // The size of a file.
// Not guaranteed to return a meaningful value for directories. // Not guaranteed to return a meaningful value for directories.
virtual u32 GetSize() const = 0; 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; virtual bool IsDirectory() const = 0;
// The number of files and directories in a directory, including those in subdirectories. // The number of files and directories in a directory, including those in subdirectories.
// Not guaranteed to return a meaningful value for files. // Not guaranteed to return a meaningful value for files.
@ -124,4 +126,4 @@ public:
// because it will check IsValid for you, will automatically pick the right type of 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. // and will cache the filesystem in case it's needed again later.
} // namespace } // namespace DiscIO

View File

@ -25,6 +25,8 @@
#include "DolphinQt2/QtUtils/ActionHelper.h" #include "DolphinQt2/QtUtils/ActionHelper.h"
#include "DolphinQt2/Resources.h" #include "DolphinQt2/Resources.h"
#include "UICommon/UICommon.h"
constexpr int ENTRY_PARTITION = Qt::UserRole; constexpr int ENTRY_PARTITION = Qt::UserRole;
constexpr int ENTRY_NAME = Qt::UserRole + 1; constexpr int ENTRY_NAME = Qt::UserRole + 1;
constexpr int ENTRY_TYPE = Qt::UserRole + 2; constexpr int ENTRY_TYPE = Qt::UserRole + 2;
@ -52,11 +54,18 @@ void FilesystemWidget::CreateWidgets()
{ {
auto* layout = new QVBoxLayout; 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 = new QTreeView(this);
m_tree_view->setModel(m_tree_model); m_tree_view->setModel(m_tree_model);
m_tree_view->setContextMenuPolicy(Qt::CustomContextMenu); 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 // Windows: Set style to (old) windows, which draws branch lines
#ifdef _WIN32 #ifdef _WIN32
@ -132,7 +141,14 @@ void FilesystemWidget::PopulateDirectory(int partition_id, QStandardItem* root,
item->setData(QString::fromStdString(info.GetPath()), ENTRY_NAME); item->setData(QString::fromStdString(info.GetPath()), ENTRY_NAME);
item->setData(QVariant::fromValue(info.IsDirectory() ? EntryType::Dir : EntryType::File), item->setData(QVariant::fromValue(info.IsDirectory() ? EntryType::Dir : EntryType::File),
ENTRY_TYPE); 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});
} }
} }