summaryrefslogtreecommitdiff
path: root/Userland/Services/Clipboard/Storage.h
blob: ecd4f510c45c49947f2c9a68c21b62e59c304e2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
 * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/Function.h>
#include <AK/HashMap.h>
#include <AK/String.h>
#include <LibCore/AnonymousBuffer.h>

namespace Clipboard {

class Storage {
public:
    static Storage& the();
    ~Storage() = default;

    bool has_data() const { return m_buffer.is_valid(); }

    String const& mime_type() const { return m_mime_type; }
    HashMap<String, String> const& metadata() const { return m_metadata; }

    u8 const* data() const
    {
        if (!has_data())
            return nullptr;
        return m_buffer.data<u8>();
    }

    size_t data_size() const
    {
        if (has_data())
            return m_data_size;
        return 0;
    }

    void set_data(Core::AnonymousBuffer, String const& mime_type, HashMap<String, String> const& metadata);

    Function<void()> on_content_change;

    Core::AnonymousBuffer const& buffer() const { return m_buffer; }

private:
    Storage() = default;

    String m_mime_type;
    Core::AnonymousBuffer m_buffer;
    size_t m_data_size { 0 };
    HashMap<String, String> m_metadata;
};

}