Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/details.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,8 @@ qulonglong PackageKit::Details::size() const
{
return value(QLatin1String("size")).toULongLong();
}

qulonglong PackageKit::Details::downloadSize() const
{
return value(QLatin1String("download-size")).toULongLong();
}
Comment on lines +70 to +73

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

0 is ambiguous: it means both "unknown/unsupported" and "zero bytes to download".

When a backend does not implement pk_backend_job_details_full(), value("download-size") returns a default QVariant and toULongLong() returns 0 — the same value returned for a legitimately zero-byte download. Issue #64 explicitly calls this out as something that must be handled.

The existing size() has the same design, so changing the return type is a bigger API decision; but at minimum consider a companion predicate:

💡 Suggested companion accessor

In details.h:

 qulonglong downloadSize() const;
+bool hasDownloadSize() const;

In details.cpp:

+bool PackageKit::Details::hasDownloadSize() const
+{
+    return contains(QLatin1String("download-size"));
+}

Callers can then do:

if (details.hasDownloadSize())
    showDownloadSize(details.downloadSize());
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/details.cpp` around lines 70 - 73, The current
PackageKit::Details::downloadSize() returns 0 for both "unknown" and an actual
zero-byte download because value(QLatin1String("download-size")).toULongLong()
returns 0 for a default QVariant; add a companion predicate
PackageKit::Details::hasDownloadSize() (declare in details.h and define in
details.cpp) that checks the underlying QVariant for the "download-size" key
using value(QLatin1String("download-size")).isValid() &&
value(QLatin1String("download-size")).canConvert<qulonglong>() (or equivalent
checks for non-null/convertibility), and update callers to call
hasDownloadSize() before using downloadSize().

2 changes: 2 additions & 0 deletions src/details.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class PACKAGEKITQT_LIBRARY Details : public QVariantMap

qulonglong size() const;

qulonglong downloadSize() const;

};

}
Expand Down
Loading