Browse Source

Display file and directory totals in client quota snapshots

master
evgeny 5 days ago
parent
commit
64d46cdef0
  1. 3
      tests/test_member_files_network.c
  2. 13
      tools/chatgui/src/member_files/browser.cpp
  3. 6
      tools/chatgui/tests/test_member_files_browser.cpp

3
tests/test_member_files_network.c

@ -210,7 +210,8 @@ static void tick(void* arg) {
t->phase = 20; request(t, MF_QUOTA, t->ids[AUTHOR]);
} else if (t->phase == 20 && t->answered) {
if (t->response.status || t->response.data_len != MF_QUOTA_BYTES || mf_get64(t->response.data) != BYTES ||
mf_get64(t->response.data + 8) != 8 * 1024 * 1024 || mf_get64(t->response.data + 16)) {
mf_get64(t->response.data + 8) != 8 * 1024 * 1024 || mf_get64(t->response.data + 16) ||
mf_get64(t->response.data + 24) != 1 || mf_get64(t->response.data + 32)) {
fail(t, "signed/encrypted quota response"); return;
}
t->phase = 3; request(t, MF_BEGIN_WRITE, t->ids[AUTHOR]);

13
tools/chatgui/src/member_files/browser.cpp

@ -51,7 +51,7 @@ MemberFileBrowser::MemberFileBrowser(DbManager* db, QWidget* parent) : QDialog(p
selectors->addWidget(new QLabel(text("Media server:"), this)); selectors->addWidget(m_servers, 1);
selectors->addWidget(new QLabel(text("Member:"), this)); selectors->addWidget(m_owners, 1); layout->addLayout(selectors);
m_quota = new QLabel(text("Select a member to see storage quota"), this);
m_quota->setObjectName("memberFilesQuota"); layout->addWidget(m_quota);
m_quota->setObjectName("memberFilesQuota"); m_quota->setWordWrap(true); layout->addWidget(m_quota);
auto* quotaTimer = new QTimer(this); quotaTimer->setInterval(2000);
connect(quotaTimer, &QTimer::timeout, this, [this]() { if (isVisible()) requestQuota(); }); quotaTimer->start();
auto* navigation = new QHBoxLayout;
@ -249,12 +249,17 @@ void MemberFileBrowser::onResponse(const uint8_t* data, int length) {
return;
}
quint64 used = mf_get64(r.data), limit = mf_get64(r.data + 8), reserved = mf_get64(r.data + 16);
quint64 files = mf_get64(r.data + 24), directories = mf_get64(r.data + 32);
QString label = text("Storage: %1 used / %2 total").arg(quotaSize(used), quotaSize(limit));
label += text(" · Files: %1 · Directories: %2").arg(QLocale().toString(files), QLocale().toString(directories));
if (reserved) label += text(" · Reserved for uploads: %1").arg(quotaSize(reserved));
m_quota->setText(label);
m_quota->setToolTip(text("Used: %1 bytes\nLimit: %2 bytes\nReserved: %3 bytes").arg(used).arg(limit).arg(reserved));
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "member_files: GUI quota owner=%llu used=%llu limit=%llu reserved=%llu",
(unsigned long long)owner(), (unsigned long long)used, (unsigned long long)limit, (unsigned long long)reserved);
m_quota->setToolTip(text("Used: %1 bytes\nLimit: %2 bytes\nReserved: %3 bytes\nFiles: %4\nDirectories: %5")
.arg(used).arg(limit).arg(reserved).arg(files).arg(directories));
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG,
"member_files: GUI quota owner=%llu used=%llu limit=%llu reserved=%llu files=%llu directories=%llu",
(unsigned long long)owner(), (unsigned long long)used, (unsigned long long)limit, (unsigned long long)reserved,
(unsigned long long)files, (unsigned long long)directories);
return;
}
if (r.request_id == m_listId && r.owner == owner() && QString::fromUtf8(r.path) == m_path) {

6
tools/chatgui/tests/test_member_files_browser.cpp

@ -47,9 +47,10 @@ private slots:
mf_gui_request previousQuota = quotaCaptured;
mf_message stats = quotaCaptured.message; stats.kind = MF_RESPONSE; stats.data_len = MF_QUOTA_BYTES;
mf_put64(stats.data, 2 * 1024 * 1024); mf_put64(stats.data + 8, 8 * 1024 * 1024); mf_put64(stats.data + 16, 1024 * 1024);
mf_put64(stats.data + 24, 42); mf_put64(stats.data + 32, 7);
uint8_t quotaPacket[16 + MF_WIRE_MAX]; mf_put64(quotaPacket, 42); mf_put64(quotaPacket + 8, 33);
int quotaLength = mf_encode(&stats, quotaPacket + 16, MF_WIRE_MAX); browser.onResponse(quotaPacket, quotaLength + 16);
QCOMPARE(quota->text(), QString("Storage: %1 used / %2 total · Reserved for uploads: %3")
QCOMPARE(quota->text(), QString("Storage: %1 used / %2 total · Files: 42 · Directories: 7 · Reserved for uploads: %3")
.arg(QLocale().formattedDataSize(2 * 1024 * 1024, 2), QLocale().formattedDataSize(8 * 1024 * 1024, 2),
QLocale().formattedDataSize(1024 * 1024, 2)));
QVERIFY(quota->toolTip().contains("2097152"));
@ -73,8 +74,9 @@ private slots:
browser.onResponse(quotaPacket, quotaLength + 16); QCOMPARE(quota->text(), QString("Loading quota…"));
stats = quotaCaptured.message; stats.kind = MF_RESPONSE; stats.data_len = MF_QUOTA_BYTES;
mf_put64(stats.data, 3 * 1024 * 1024); mf_put64(stats.data + 8, 8 * 1024 * 1024);
mf_put64(stats.data + 24, 12); mf_put64(stats.data + 32, 3);
quotaLength = mf_encode(&stats, quotaPacket + 16, MF_WIRE_MAX); browser.onResponse(quotaPacket, quotaLength + 16);
QString ownQuota = QString("Storage: %1 used / %2 total")
QString ownQuota = QString("Storage: %1 used / %2 total · Files: 12 · Directories: 3")
.arg(QLocale().formattedDataSize(3 * 1024 * 1024, 2), QLocale().formattedDataSize(8 * 1024 * 1024, 2));
QCOMPARE(quota->text(), ownQuota);
browser.onResponse(packet, length + 16); QCOMPARE(table->topLevelItemCount(), 0);

Loading…
Cancel
Save