8857184e07e05925033a27d1d5ec193453aba7d1
[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    * Constructor.
59    * Determines type of visual and whether the url is local or remote
60    * @param[in] url The URL to store and resolve
61    */
62   VisualUrl(const std::string& url);
63
64   /**
65    * Copy constructor
66    * @param[in] url The VisualUrl to copy
67    */
68   VisualUrl(const VisualUrl& url);
69
70   /**
71    * Assignment operator
72    * @param[in] url The VisualUrl to copy
73    */
74   VisualUrl& operator=(const VisualUrl& url);
75
76   /**
77    * Get the full URL
78    * @return The url
79    */
80   const std::string& GetUrl() const;
81
82   /**
83    * Get the visual type of the URL
84    * @return The visual type of the URL
85    */
86   Type GetType() const;
87
88   /**
89    * Is the URL is local to the device, or remote?
90    * @return the location of the resource
91    */
92   ProtocolType GetProtocolType() const;
93
94   /**
95    * Is the URL valid?
96    * @return true if the URL has length
97    */
98   bool IsValid() const;
99
100   /**
101    * @return true if the location is LOCAL, i.e. is loadable from local file system
102    */
103   bool IsLocalResource() const;
104
105   /**
106    * @return the location part of the url
107    */
108   std::string GetLocation() const;
109
110   /**
111    * Helper to create a URL of type TEXTURE
112    * @param location the location of the texture
113    * @return the Url
114    */
115   static std::string CreateTextureUrl(const std::string& location);
116
117 private:
118   std::string  mUrl;
119   Type         mType;
120   ProtocolType mLocation;
121 };
122
123 } // namespace Internal
124
125 } // namespace Toolkit
126
127 } // namespace Dali
128
129 #endif /* DALI_TOOLKIT_INTERNAL_VISUAL_URL_H */