2 * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Collections;
19 using System.Collections.Generic;
20 using System.Runtime.InteropServices;
22 namespace Tizen.Applications.ThemeManager
27 /// <since_tizen> 8 </since_tizen>
28 public class Theme : IDisposable
30 private bool _disposed = false;
31 private IntPtr _handle;
32 private string _id = String.Empty;
33 private string _version = String.Empty;
34 private string _toolVersion = String.Empty;
35 private string _title = String.Empty;
36 private string _resolution = String.Empty;
37 private string _preview = String.Empty;
38 private string _description = String.Empty;
41 /// A copy constructor of Theme.
43 /// <param name="theme">Theme class.</param>
44 /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
45 /// <exception cref="InvalidOperationException">Thrown when failed because of system error.</exception>
46 /// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
47 /// <since_tizen> 8 </since_tizen>
48 public Theme(Theme theme)
50 if (theme == null || theme._handle == IntPtr.Zero)
52 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(Interop.ThemeManager.ErrorCode.InvalidParameter, "Invalid parameter");
55 var err = Interop.ThemeManager.ErrorCode.None;
56 err = Interop.ThemeManager.ThemeClone(theme._handle, out _handle);
57 if (err != Interop.ThemeManager.ErrorCode.None)
59 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to clone handle");
63 internal Theme(IntPtr handle)
66 var err = Interop.ThemeManager.ErrorCode.None;
67 err = Interop.ThemeManager.GetId(handle, out _id);
68 if (err != Interop.ThemeManager.ErrorCode.None)
70 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get id");
73 err = Interop.ThemeManager.GetVersion(handle, out _version);
74 if (err != Interop.ThemeManager.ErrorCode.None)
76 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get version");
79 err = Interop.ThemeManager.GetToolVersion(handle, out _toolVersion);
80 if (err != Interop.ThemeManager.ErrorCode.None)
82 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get tool version");
85 err = Interop.ThemeManager.GetTitle(handle, out _title);
86 if (err != Interop.ThemeManager.ErrorCode.None)
88 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get title");
91 err = Interop.ThemeManager.GetResolution(handle, out _resolution);
92 if (err != Interop.ThemeManager.ErrorCode.None)
94 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get resolution");
97 err = Interop.ThemeManager.GetPreview(handle, out _preview);
98 if (err != Interop.ThemeManager.ErrorCode.None)
100 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get preview");
103 err = Interop.ThemeManager.GetDescription(handle, out _description);
104 if (err != Interop.ThemeManager.ErrorCode.None)
106 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get description");
113 /// <since_tizen> 8 </since_tizen>
114 public string Id { get { return _id; } }
119 /// <since_tizen> 8 </since_tizen>
120 public string Version { get { return _version; } }
123 /// A Theme ToolVersion
125 /// <since_tizen> 8 </since_tizen>
126 public string ToolVersion { get { return _toolVersion; } }
131 /// <since_tizen> 8 </since_tizen>
132 public string Title { get { return _title; } }
135 /// A Theme Resolution
137 /// <since_tizen> 8 </since_tizen>
138 public string Resolution { get { return _resolution; } }
143 /// <since_tizen> 8 </since_tizen>
144 public string Preview { get { return _preview; } }
147 /// A Theme Description
149 /// <since_tizen> 8 </since_tizen>
150 public string Description { get { return _description; } }
154 /// Gets the string corresponding with given key.
156 /// <param name="key">The string key to find information.</param>
157 /// <since_tizen> 8 </since_tizen>
158 /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
159 /// <exception cref="InvalidOperationException">Thrown when failed because of the system error.</exception>
160 /// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
161 public string GetString(string key)
164 var err = Interop.ThemeManager.GetString(_handle, key, out str);
165 if (err != Interop.ThemeManager.ErrorCode.None)
167 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get string value of the key");
174 /// Gets the string array corresponding with given key.
176 /// <param name="key">The string key to find information.</param>
177 /// <since_tizen> 8 </since_tizen>
178 /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
179 /// <exception cref="InvalidOperationException">Thrown when failed because of the system error.</exception>
180 /// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
181 public IEnumerable<string> GetStrings(string key)
186 var err = Interop.ThemeManager.GetStringArray(_handle, key, out val, out count);
187 if (err != Interop.ThemeManager.ErrorCode.None)
189 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get string array value of the key");
192 IntPtrToStringArray(val, count, out strings);
197 /// Gets the integer corresponding with given key.
199 /// <param name="key">The string key to find information.</param>
200 /// <since_tizen> 8 </since_tizen>
201 /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
202 /// <exception cref="InvalidOperationException">Thrown when failed because of the system error.</exception>
203 /// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
204 public int GetInt(string key)
207 var err = Interop.ThemeManager.GetInt(_handle, key, out val);
208 if (err != Interop.ThemeManager.ErrorCode.None)
210 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get integer value of the key");
217 /// Gets the float corresponding with given key.
219 /// <param name="key">The string key to find information.</param>
220 /// <since_tizen> 8 </since_tizen>
221 /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
222 /// <exception cref="InvalidOperationException">Thrown when failed because of the system error.</exception>
223 /// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
224 public float GetFloat(string key)
227 var err = Interop.ThemeManager.GetFloat(_handle, key, out val);
228 if (err != Interop.ThemeManager.ErrorCode.None)
230 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get float value of the key");
237 /// Gets the bool corresponding with given key.
239 /// <param name="key">The string key to find information.</param>
240 /// <since_tizen> 8 </since_tizen>
241 /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
242 /// <exception cref="InvalidOperationException">Thrown when failed because of the system error.</exception>
243 /// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
244 public bool GetBool(string key)
247 var err = Interop.ThemeManager.GetBool(_handle, key, out val);
248 if (err != Interop.ThemeManager.ErrorCode.None)
250 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get bool value of the key");
257 /// Gets the path corresponding with given key.
259 /// <param name="key">The string key to find information.</param>
260 /// <since_tizen> 8 </since_tizen>
261 /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
262 /// <exception cref="InvalidOperationException">Thrown when failed because of the system error.</exception>
263 /// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
264 public string GetPath(string key)
267 var err = Interop.ThemeManager.GetPath(_handle, key, out val);
268 if (err != Interop.ThemeManager.ErrorCode.None)
270 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get path value of the key");
277 /// Gets the path array corresponding with given key.
279 /// <param name="key">The string key to find information.</param>
280 /// <since_tizen> 8 </since_tizen>
281 /// <exception cref="ArgumentException">Thrown when failed because of an invalid argument.</exception>
282 /// <exception cref="InvalidOperationException">Thrown when failed because of the system error.</exception>
283 /// <exception cref="OutOfMemoryException">Thrown when failed because of out of memory.</exception>
284 public IEnumerable<string> GetPaths(string key)
289 var err = Interop.ThemeManager.GetPathArray(_handle, key, out val, out count);
290 if (err != Interop.ThemeManager.ErrorCode.None)
292 throw Interop.ThemeManager.ThemeManagerErrorFactory.GetException(err, "Failed to get path array value of the key");
295 IntPtrToStringArray(val, count, out paths);
299 static void IntPtrToStringArray(IntPtr unmanagedArray, int size, out string[] managedArray)
301 managedArray = new string[size];
302 IntPtr[] IntPtrArray = new IntPtr[size];
303 Marshal.Copy(unmanagedArray, IntPtrArray, 0, size);
304 for (int iterator = 0; iterator < size; iterator++)
306 managedArray[iterator] = Marshal.PtrToStringAnsi(IntPtrArray[iterator]);
310 /// Releases all resources used by the Theme class.
312 /// <since_tizen> 8 </since_tizen>
313 public void Dispose()
316 GC.SuppressFinalize(this);
320 /// Releases the unmanaged resources used by the Theme class specifying whether to perform a normal dispose operation.
322 /// <param name="disposing">true for a normal dispose operation; false to finalize the handle.</param>
323 protected virtual void Dispose(bool disposing)
328 if (_handle != IntPtr.Zero)
330 Interop.ThemeManager.ThemeDestroy(_handle);
331 _handle = IntPtr.Zero;