2020-05-15 09:59:52 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-05-15 09:59:52 +02:00
|
|
|
*/
|
|
|
|
|
2020-05-14 22:51:15 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Function.h>
|
2020-09-05 16:26:22 +02:00
|
|
|
#include <AK/HashMap.h>
|
2020-05-14 22:51:15 +02:00
|
|
|
#include <AK/String.h>
|
2021-01-17 00:14:37 +01:00
|
|
|
#include <LibCore/AnonymousBuffer.h>
|
2020-05-14 22:51:15 +02:00
|
|
|
|
|
|
|
namespace Clipboard {
|
|
|
|
|
|
|
|
class Storage {
|
|
|
|
public:
|
|
|
|
static Storage& the();
|
|
|
|
~Storage();
|
|
|
|
|
2021-01-17 00:14:37 +01:00
|
|
|
bool has_data() const { return m_buffer.is_valid(); }
|
2020-05-14 22:51:15 +02:00
|
|
|
|
|
|
|
const String& mime_type() const { return m_mime_type; }
|
2020-09-05 16:26:22 +02:00
|
|
|
const HashMap<String, String>& metadata() const { return m_metadata; }
|
2020-05-14 22:51:15 +02:00
|
|
|
|
|
|
|
const u8* data() const
|
|
|
|
{
|
|
|
|
if (!has_data())
|
|
|
|
return nullptr;
|
2021-01-17 00:14:37 +01:00
|
|
|
return m_buffer.data<u8>();
|
2020-05-14 22:51:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t data_size() const
|
|
|
|
{
|
|
|
|
if (has_data())
|
|
|
|
return m_data_size;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-01-17 00:14:37 +01:00
|
|
|
void set_data(Core::AnonymousBuffer, const String& mime_type, const HashMap<String, String>& metadata);
|
2020-05-14 22:51:15 +02:00
|
|
|
|
|
|
|
Function<void()> on_content_change;
|
|
|
|
|
2021-01-17 00:14:37 +01:00
|
|
|
const Core::AnonymousBuffer& buffer() const { return m_buffer; }
|
|
|
|
|
2020-05-14 22:51:15 +02:00
|
|
|
private:
|
|
|
|
Storage();
|
|
|
|
|
|
|
|
String m_mime_type;
|
2021-01-17 00:14:37 +01:00
|
|
|
Core::AnonymousBuffer m_buffer;
|
2020-05-14 22:51:15 +02:00
|
|
|
size_t m_data_size { 0 };
|
2020-09-05 16:26:22 +02:00
|
|
|
HashMap<String, String> m_metadata;
|
2020-05-14 22:51:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|