summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorNícolas F. R. A. Prado <n@nfraprado.net>2022-02-21 21:07:28 -0500
committerAndreas Kling <kling@serenityos.org>2022-02-24 08:47:55 +0100
commiteebdd86fbdb29b1bae532d8290b7fbcaa773b2f5 (patch)
tree7933a30c5b38494bcde5398b1ae9a4246386efcf /Userland
parent9d94c85b6a872ec460ae8379c9795293dfdad566 (diff)
downloadserenity-eebdd86fbdb29b1bae532d8290b7fbcaa773b2f5.zip
ClipboardHistory: Add Time column
Add a Time column to ClipboardHistory that shows the time when each item in the list was copied.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applets/ClipboardHistory/ClipboardHistoryModel.cpp14
-rw-r--r--Userland/Applets/ClipboardHistory/ClipboardHistoryModel.h11
-rw-r--r--Userland/Applets/ClipboardHistory/main.cpp2
3 files changed, 20 insertions, 7 deletions
diff --git a/Userland/Applets/ClipboardHistory/ClipboardHistoryModel.cpp b/Userland/Applets/ClipboardHistory/ClipboardHistoryModel.cpp
index 55654bb2ae..27f9f7cb7f 100644
--- a/Userland/Applets/ClipboardHistory/ClipboardHistoryModel.cpp
+++ b/Userland/Applets/ClipboardHistory/ClipboardHistoryModel.cpp
@@ -30,6 +30,8 @@ String ClipboardHistoryModel::column_name(int column) const
return "Type";
case Column::Size:
return "Size";
+ case Column::Time:
+ return "Time";
default:
VERIFY_NOT_REACHED();
}
@@ -62,7 +64,9 @@ GUI::Variant ClipboardHistoryModel::data(const GUI::ModelIndex& index, GUI::Mode
{
if (role != GUI::ModelRole::Display)
return {};
- auto& data_and_type = m_history_items[index.row()];
+ auto& item = m_history_items[index.row()];
+ auto& data_and_type = item.data_and_type;
+ auto& time = item.time;
switch (index.column()) {
case Column::Data:
if (data_and_type.mime_type.starts_with("text/"))
@@ -91,6 +95,8 @@ GUI::Variant ClipboardHistoryModel::data(const GUI::ModelIndex& index, GUI::Mode
return data_and_type.mime_type;
case Column::Size:
return AK::human_readable_size(data_and_type.data.size());
+ case Column::Time:
+ return time.to_string();
default:
VERIFY_NOT_REACHED();
}
@@ -98,14 +104,14 @@ GUI::Variant ClipboardHistoryModel::data(const GUI::ModelIndex& index, GUI::Mode
void ClipboardHistoryModel::add_item(const GUI::Clipboard::DataAndType& item)
{
- m_history_items.remove_first_matching([&](GUI::Clipboard::DataAndType& existing) {
- return existing.data == item.data && existing.mime_type == item.mime_type;
+ m_history_items.remove_first_matching([&](ClipboardItem& existing) {
+ return existing.data_and_type.data == item.data && existing.data_and_type.mime_type == item.mime_type;
});
if (m_history_items.size() == m_history_limit)
m_history_items.take_last();
- m_history_items.prepend(item);
+ m_history_items.prepend({ item, Core::DateTime::now() });
invalidate();
}
diff --git a/Userland/Applets/ClipboardHistory/ClipboardHistoryModel.h b/Userland/Applets/ClipboardHistory/ClipboardHistoryModel.h
index 133abaf44b..ec3de5f4d2 100644
--- a/Userland/Applets/ClipboardHistory/ClipboardHistoryModel.h
+++ b/Userland/Applets/ClipboardHistory/ClipboardHistoryModel.h
@@ -10,6 +10,7 @@
#include <AK/Vector.h>
#include <LibConfig/Listener.h>
+#include <LibCore/DateTime.h>
#include <LibGUI/Clipboard.h>
#include <LibGUI/Model.h>
@@ -23,12 +24,18 @@ public:
Data,
Type,
Size,
+ Time,
__Count
};
+ struct ClipboardItem {
+ GUI::Clipboard::DataAndType data_and_type;
+ Core::DateTime time;
+ };
+
virtual ~ClipboardHistoryModel() override = default;
- const GUI::Clipboard::DataAndType& item_at(int index) const { return m_history_items[index]; }
+ const ClipboardItem& item_at(int index) const { return m_history_items[index]; }
void remove_item(int index);
// ^GUI::Model
@@ -49,6 +56,6 @@ private:
// ^GUI::Clipboard::ClipboardClient
virtual void clipboard_content_did_change(const String&) override { add_item(GUI::Clipboard::the().fetch_data_and_type()); }
- Vector<GUI::Clipboard::DataAndType> m_history_items;
+ Vector<ClipboardItem> m_history_items;
size_t m_history_limit;
};
diff --git a/Userland/Applets/ClipboardHistory/main.cpp b/Userland/Applets/ClipboardHistory/main.cpp
index 93b6ecf309..7205401108 100644
--- a/Userland/Applets/ClipboardHistory/main.cpp
+++ b/Userland/Applets/ClipboardHistory/main.cpp
@@ -38,7 +38,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
table_view->set_model(model);
table_view->on_activation = [&](GUI::ModelIndex const& index) {
- auto& data_and_type = model->item_at(index.row());
+ auto& data_and_type = model->item_at(index.row()).data_and_type;
GUI::Clipboard::the().set_data(data_and_type.data, data_and_type.mime_type, data_and_type.metadata);
};