a772bd109456c445a67b8a4a53694fb184128530
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / visual-url.h
1 #ifndef DALI_TOOLKIT_INTERNAL_VISUAL_URL_H
2 #define DALI_TOOLKIT_INTERNAL_VISUAL_URL_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 #include <string>
21
22 namespace Dali
23 {
24 namespace Toolkit
25 {
26 namespace Internal
27 {
28 class VisualUrl
29 {
30 public:
31   /**
32    * The type of the URL based on the string contents
33    */
34   enum Type
35   {
36     REGULAR_IMAGE,
37     N_PATCH,
38     SVG,
39     GIF,
40     WEBP,
41     JSON
42   };
43
44   enum ProtocolType
45   {
46     LOCAL,   ///< file in local file system
47     TEXTURE, ///< texture uploaded to texture manager
48     REMOTE   ///< remote image
49   };
50
51   /**
52    * Default Constructor.
53    * Resulting URL is not valid
54    */
55   VisualUrl();
56
57   /**
58    * Default Destructor.
59    * Delete an external texture if if protocolType is TEXTURE.
60    */
61   ~VisualUrl();
62
63   /**
64    * Constructor.
65    * Determines type of visual and whether the url is local or remote
66    * Notify that it is using an external texture if if protocolType is TEXTURE.
67    *
68    * @param[in] url The URL to store and resolve
69    */
70   VisualUrl(const std::string& url);
71
72   /**
73    * Copy constructor
74    * @param[in] url The VisualUrl to copy
75    */
76   VisualUrl(const VisualUrl& url);
77
78   /**
79    * Assignment operator
80    * @param[in] url The VisualUrl to copy
81    */
82   VisualUrl& operator=(const VisualUrl& url);
83
84   /**
85    * Get the full URL
86    * @return The url
87    */
88   const std::string& GetUrl() const;
89
90   /**
91    * Get the visual type of the URL
92    * @return The visual type of the URL
93    */
94   Type GetType() const;
95
96   /**
97    * Is the URL is local to the device, or remote?
98    * @return the location of the resource
99    */
100   ProtocolType GetProtocolType() const;
101
102   /**
103    * Is the URL valid?
104    * @return true if the URL has length
105    */
106   bool IsValid() const;
107
108   /**
109    * @return true if the location is LOCAL, i.e. is loadable from local file system
110    */
111   bool IsLocalResource() const;
112
113   /**
114    * @return the location part of the url
115    */
116   std::string GetLocation() const;
117
118   /**
119    * Helper to create a URL of type TEXTURE
120    * @param location the location of the texture
121    * @return the Url
122    */
123   static std::string CreateTextureUrl(const std::string& location);
124
125   /**
126    * Helper to get a ProtocolType from url
127    * @param url the url of the texture
128    * @return the protocol type
129    */
130   static VisualUrl::ProtocolType GetProtocolType(const std::string& url);
131
132   /**
133    * Helper to get a location from url
134    * @param url the location of the texture
135    * @return the location
136    */
137   static std::string GetLocation(const std::string& url);
138 private:
139   std::string  mUrl;
140   Type         mType;
141   ProtocolType mLocation;
142 };
143
144 } // namespace Internal
145
146 } // namespace Toolkit
147
148 } // namespace Dali
149
150 #endif /* DALI_TOOLKIT_INTERNAL_VISUAL_URL_H */