Welcome to mirror list, hosted at ThFree Co, Russian Federation.

bookmark_catalog.hpp « map - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 352f0fd6097631940a04e5ec1f6eee885edd5249 (plain)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#pragma once

#include "kml/types.hpp"

#include "platform/remote_file.hpp"
#include "platform/safe_callback.hpp"

#include <array>
#include <functional>
#include <memory>
#include <set>
#include <string>
#include <vector>

class BookmarkCatalog
{
public:
  struct Tag
  {
    using Color = std::array<float, 3>;

    std::string m_id;
    Color m_color;
    std::string m_name;
  };

  struct TagGroup
  {
    std::string m_name;
    std::vector<Tag> m_tags;
  };

  struct CustomProperty
  {
    std::string m_key;
    std::string m_name;
    bool m_isRequired = true;

    struct Option
    {
      std::string m_value;
      std::string m_name;
    };
    std::vector<Option> m_options;
  };

  using TagGroups = std::vector<TagGroup>;
  using TagGroupsCallback = platform::SafeCallback<void(bool success, TagGroups const &,
                                                        uint32_t maxTagsCount)>;
  using CustomProperties = std::vector<CustomProperty>;
  using CustomPropertiesCallback = platform::SafeCallback<void(bool success, CustomProperties const &)>;
  using InvalidTokenHandler = std::function<void()>;

  void RegisterByServerId(std::string const & id);
  void UnregisterByServerId(std::string const & id);

  enum class DownloadResult
  {
    Success,
    NetworkError,
    ServerError,
    AuthError,
    DiskError,
    NeedPayment
  };
  using DownloadStartCallback = std::function<void()>;
  using DownloadFinishCallback = std::function<void(DownloadResult result,
                                                    std::string const & description,
                                                    std::string const & filePath)>;
  void Download(std::string const & id, std::string const & accessToken,
                DownloadStartCallback && startHandler, DownloadFinishCallback && finishHandler);

  bool IsDownloading(std::string const & id) const;
  bool HasDownloaded(std::string const & id) const;
  size_t GetDownloadingCount() const { return m_downloadingIds.size(); }

  std::string GetDownloadUrl(std::string const & serverId) const;
  std::string GetWebEditorUrl(std::string const & serverId, std::string const & language) const;
  std::string GetFrontendUrl() const;

  void RequestTagGroups(std::string const & language, TagGroupsCallback && callback) const;

  void RequestCustomProperties(std::string const & language,
                               CustomPropertiesCallback && callback) const;

  enum class UploadResult
  {
    Success,
    NetworkError,
    ServerError,
    AuthError,
    MalformedDataError,
    AccessError,
    InvalidCall
  };
  using UploadSuccessCallback = platform::SafeCallback<void(UploadResult result,
                                                            std::shared_ptr<kml::FileData> fileData,
                                                            bool originalFileExists,
                                                            bool originalFileUnmodified)>;
  using UploadErrorCallback = platform::SafeCallback<void(UploadResult result,
                                                          std::string const & description)>;

  struct UploadData
  {
    std::string m_serverId;
    kml::AccessRules m_accessRules = kml::AccessRules::DirectLink;
    std::string m_userName;
    std::string m_userId;
  };

  void Upload(UploadData uploadData, std::string const & accessToken,
              std::shared_ptr<kml::FileData> fileData, std::string const & pathToKmb,
              UploadSuccessCallback && uploadSuccessCallback,
              UploadErrorCallback && uploadErrorCallback);

  // Handler can be called from non-UI thread.
  void SetInvalidTokenHandler(InvalidTokenHandler && onInvalidToken);

private:
  std::set<std::string> m_downloadingIds;
  std::set<std::string> m_registeredInCatalog;
  InvalidTokenHandler m_onInvalidToken;
};