~aleteoryx/muditaos

ref: 05847f09d10bef7c7579b55de45f22a462ccb4b4 muditaos/module-apps/application-music-player/models/SongsRepository.hpp -rw-r--r-- 2.4 KiB
05847f09 — Paweł Joński [BH-743] Fix alarm deletion from DB 4 years ago
                                                                                
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <apps-common/Application.hpp>
#include <tags_fetcher/TagsFetcher.hpp>
#include <purefs/filesystem_paths.hpp>

#include <memory>
#include <optional>
#include <string>
#include <vector>

#include <cstddef>

namespace app::music_player
{
    class AbstractTagsFetcher
    {
      public:
        virtual ~AbstractTagsFetcher() noexcept = default;

        virtual std::optional<tags::fetcher::Tags> getFileTags(const std::string &filePath) const = 0;
    };

    class ServiceAudioTagsFetcher : public AbstractTagsFetcher
    {
      public:
        explicit ServiceAudioTagsFetcher(Application *application);

        std::optional<tags::fetcher::Tags> getFileTags(const std::string &filePath) const final;

      private:
        Application *application = nullptr;
    };

    class AbstractSongsRepository
    {
      public:
        virtual ~AbstractSongsRepository() noexcept = default;

        virtual void scanMusicFilesList()                                          = 0;
        virtual std::vector<tags::fetcher::Tags> getMusicFilesList() const         = 0;
        virtual std::size_t getFileIndex(const std::string &filePath) const        = 0;
        virtual std::string getNextFilePath(const std::string &filePath) const     = 0;
        virtual std::string getPreviousFilePath(const std::string &filePath) const = 0;
    };

    class SongsRepository : public AbstractSongsRepository
    {
        static constexpr auto musicSubfolderName = "music";

      public:
        explicit SongsRepository(std::unique_ptr<AbstractTagsFetcher> tagsFetcher,
                                 std::string musicFolderName = purefs::dir::getUserDiskPath() / musicSubfolderName);

        void scanMusicFilesList() override;
        std::vector<tags::fetcher::Tags> getMusicFilesList() const override;
        std::size_t getFileIndex(const std::string &filePath) const override;
        std::string getNextFilePath(const std::string &filePath) const override;
        std::string getPreviousFilePath(const std::string &filePath) const override;

      private:
        std::unique_ptr<AbstractTagsFetcher> tagsFetcher;
        std::string musicFolderName;
        std::vector<tags::fetcher::Tags> musicFiles;
    };
} // namespace app::music_player