/* * Copyright (c) 2020, Nicholas Hollett * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include namespace LaunchServer { struct Handler { enum class Type { Default = 0, Application, UserPreferred, UserDefault }; Type handler_type; DeprecatedString name; DeprecatedString executable; HashTable mime_types {}; HashTable file_types {}; HashTable protocols {}; static DeprecatedString name_from_executable(StringView); void from_executable(Type, DeprecatedString const&); DeprecatedString to_details_str() const; }; class Launcher { public: Launcher(); static Launcher& the(); void load_handlers(DeprecatedString const& af_dir = Desktop::AppFile::APP_FILES_DIRECTORY); void load_config(Core::ConfigFile const&); bool open_url(const URL&, DeprecatedString const& handler_name); Vector handlers_for_url(const URL&); Vector handlers_with_details_for_url(const URL&); private: HashMap m_handlers; HashMap m_protocol_handlers; HashMap m_file_handlers; HashMap m_mime_handlers; bool has_mime_handlers(DeprecatedString const&); Optional mime_type_for_file(DeprecatedString path); Handler get_handler_for_executable(Handler::Type, DeprecatedString const&) const; size_t for_each_handler(DeprecatedString const& key, HashMap const& user_preferences, Function f); void for_each_handler_for_path(DeprecatedString const&, Function f); bool open_file_url(const URL&); bool open_with_user_preferences(HashMap const& user_preferences, DeprecatedString const& key, Vector const& arguments, DeprecatedString const& default_program = {}); bool open_with_handler_name(const URL&, DeprecatedString const& handler_name); }; }