Files
waylight/src/Cache.hpp
Slendi d368760f78 A lot
Signed-off-by: Slendi <slendi@socopon.com>
2025-10-16 19:48:02 +03:00

61 lines
1.4 KiB
C++

#pragma once
#include <filesystem>
#include <optional>
#include <string>
#include <variant>
#include <vector>
#include <SQLiteCpp/Database.h>
namespace Waylight {
struct ApplicationCache {
enum class Type {
Application,
Link,
Directory,
};
struct Action {
std::string name;
// May not exist if DBusActivable=true
std::optional<std::string> exec;
// Freedesktop Desktop Entry Spec 11.2 Table 3 says:
//
// If the name is an absolute path, the given file will be used.
// If the name is not an absolute path, the algorithm described in
// the Icon Theme Specification will be used to locate the icon.
//
// Thus, when deserializing, we will just check if it starts with /
// to determine type.
std::optional<std::variant<std::filesystem::path, std::string>> icon;
};
int id;
std::filesystem::path desktop_entry_path;
Type type { Type::Application };
bool terminal { false };
bool no_display { false };
std::optional<std::string> path;
std::optional<std::string> comment;
std::vector<Action> actions; // There should always be at least 1.
bool dbus_activatable {}; // Unimplemented for now.
};
struct Cache {
explicit Cache(std::shared_ptr<SQLite::Database> db);
void rescan();
void dump();
void load();
private:
std::vector<ApplicationCache> m_apps;
std::vector<std::filesystem::path> m_app_dirs;
std::shared_ptr<SQLite::Database> m_db;
};
} // namespace Cache