2023-06-28 19:17:31 -06:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2023, the SerenityOS developers.
|
2023-10-28 10:30:42 +02:00
|
|
|
* Copyright (c) 2023, David Ganz <david.g.ganz@gmail.com>
|
2023-06-28 19:17:31 -06:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/JsonObject.h>
|
|
|
|
#include <AK/JsonValue.h>
|
|
|
|
#include <AK/Noncopyable.h>
|
|
|
|
#include <AK/OwnPtr.h>
|
2023-10-28 10:30:42 +02:00
|
|
|
#include <LibCore/DateTime.h>
|
2023-06-28 19:17:31 -06:00
|
|
|
#include <LibFileSystemAccessClient/Client.h>
|
|
|
|
#include <LibGUI/Window.h>
|
|
|
|
|
|
|
|
namespace Calendar {
|
|
|
|
|
2023-10-28 10:30:42 +02:00
|
|
|
struct Event {
|
|
|
|
String summary;
|
|
|
|
Core::DateTime start;
|
|
|
|
Core::DateTime end;
|
|
|
|
};
|
|
|
|
|
2023-06-28 19:17:31 -06:00
|
|
|
class EventManager {
|
|
|
|
AK_MAKE_NONCOPYABLE(EventManager);
|
|
|
|
AK_MAKE_NONMOVABLE(EventManager);
|
|
|
|
|
|
|
|
public:
|
|
|
|
static OwnPtr<EventManager> create();
|
|
|
|
|
2024-01-23 16:05:59 +00:00
|
|
|
ByteString const& current_filename() const { return m_current_filename; }
|
|
|
|
void set_filename(ByteString filename) { m_current_filename = move(filename); }
|
2023-06-28 19:17:31 -06:00
|
|
|
|
|
|
|
ErrorOr<void> save(FileSystemAccessClient::File& file);
|
|
|
|
ErrorOr<void> load_file(FileSystemAccessClient::File& file);
|
2023-10-28 10:30:42 +02:00
|
|
|
void add_event(Event);
|
|
|
|
void set_events(Vector<Event>);
|
2023-06-28 19:17:31 -06:00
|
|
|
void clear() { m_events.clear(); }
|
|
|
|
|
2023-11-17 21:04:18 +01:00
|
|
|
bool is_dirty() const { return m_dirty; }
|
2023-10-28 10:30:42 +02:00
|
|
|
Span<Event const> events() const { return m_events.span(); }
|
2023-06-28 19:17:31 -06:00
|
|
|
|
|
|
|
Function<void()> on_events_change;
|
|
|
|
|
|
|
|
private:
|
|
|
|
explicit EventManager();
|
|
|
|
|
2023-10-28 10:30:42 +02:00
|
|
|
ErrorOr<JsonArray> serialize_events();
|
|
|
|
ErrorOr<Vector<Event>> deserialize_events(JsonArray const& json);
|
|
|
|
|
|
|
|
Vector<Event> m_events;
|
2023-06-28 19:17:31 -06:00
|
|
|
|
|
|
|
bool m_dirty { false };
|
2024-01-23 16:05:59 +00:00
|
|
|
ByteString m_current_filename;
|
2023-06-28 19:17:31 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|