AppFile.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) 2020, Linus Groh <linusg@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibCore/ConfigFile.h>
  8. #include <LibGUI/FileIconProvider.h>
  9. #include <LibGUI/Icon.h>
  10. namespace Desktop {
  11. class AppFile : public RefCounted<AppFile> {
  12. public:
  13. static constexpr const char* APP_FILES_DIRECTORY = "/res/apps";
  14. static NonnullRefPtr<AppFile> get_for_app(const StringView& app_name);
  15. static NonnullRefPtr<AppFile> open(const StringView& path);
  16. static void for_each(Function<void(NonnullRefPtr<AppFile>)>, const StringView& directory = APP_FILES_DIRECTORY);
  17. ~AppFile();
  18. bool is_valid() const { return m_valid; }
  19. String filename() const { return m_config->filename(); }
  20. String name() const;
  21. String executable() const;
  22. String category() const;
  23. Vector<String> launcher_file_types() const;
  24. Vector<String> launcher_protocols() const;
  25. bool spawn() const;
  26. GUI::Icon icon() const { return GUI::FileIconProvider::icon_for_path(executable()); };
  27. private:
  28. explicit AppFile(const StringView& path);
  29. bool validate() const;
  30. RefPtr<Core::ConfigFile> m_config;
  31. bool m_valid { false };
  32. };
  33. }