1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 07:57:46 +00:00

Applets/ClipboardHistory: Add persistent storage

Clipboard entries are now preserved upon reboot :^). Unfortunately, it
only supports data with the mimetype "text/".

This is done by writing all entries as a JSON object in a file located
in ~/.data.

Co-authored-by: Sagittarius-a <sagittarius-a@users.noreply.github.com>
This commit is contained in:
Lucas CHOLLET 2023-03-08 16:13:42 -05:00 committed by Andrew Kaster
parent c09d0c4816
commit 07c6cebbab
5 changed files with 143 additions and 7 deletions

View file

@ -31,6 +31,9 @@ public:
struct ClipboardItem {
GUI::Clipboard::DataAndType data_and_type;
Core::DateTime time;
static ErrorOr<ClipboardItem> from_json(JsonObject const& object);
ErrorOr<JsonObject> to_json() const;
};
virtual ~ClipboardHistoryModel() override = default;
@ -41,6 +44,11 @@ public:
void clear();
bool is_empty() { return m_history_items.is_empty(); }
ErrorOr<void> read_from_file(DeprecatedString const& path);
ErrorOr<void> write_to_file(bool rewrite_all);
ErrorOr<void> invalidate_model_and_file(bool rewrite_all);
// ^GUI::Model
virtual GUI::Variant data(const GUI::ModelIndex&, GUI::ModelRole) const override;
@ -60,4 +68,6 @@ private:
Vector<ClipboardItem> m_history_items;
size_t m_history_limit;
DeprecatedString m_path;
};