Refactor AppFW
[platform/core/csapi/tizenfx.git] / Tizen.Applications / Tizen.Applications.Manager / InstalledApplication.cs
1 /// Copyright 2016 by Samsung Electronics, Inc.,
2 ///
3 /// This software is the confidential and proprietary information
4 /// of Samsung Electronics, Inc. ("Confidential Information"). You
5 /// shall not disclose such Confidential Information and shall use
6 /// it only in accordance with the terms of the license agreement
7 /// you entered into with Samsung.
8
9 using System;
10 using System.Collections.Generic;
11 using System.Runtime.InteropServices;
12
13 namespace Tizen.Applications.Manager
14 {
15     /// <summary>
16     /// InstalledApplication class. This class has the methods and properties of InstalledApplication.
17     /// </summary>
18     public class InstalledApplication : IDisposable
19     {
20         private IntPtr _handle;
21         private bool disposed = false;
22
23         internal InstalledApplication(IntPtr handle)
24         {
25             _handle = handle;
26         }
27
28         /// <summary>
29         /// ApplicationId property.
30         /// </summary>
31         /// <returns>string application id.</returns>
32         public string ApplicationId
33         {
34             get
35             {
36                 IntPtr ptr = IntPtr.Zero;
37                 Interop.ApplicationManager.AppInfoGetAppId(_handle, out ptr);
38                 string appid = Marshal.PtrToStringAuto(ptr);
39                 return appid;
40             }
41         }
42         /// <summary>
43         /// PackageId property.
44         /// </summary>
45         /// <returns>string package id.</returns>
46         public string PackageId
47         {
48             get
49             {
50                 IntPtr ptr = IntPtr.Zero;
51                 Interop.ApplicationManager.AppInfoGetPackage(_handle, out ptr);
52                 string packageid = Marshal.PtrToStringAuto(ptr);
53                 return packageid;
54             }
55         }
56         /// <summary>
57         /// Label property.
58         /// </summary>
59         /// <returns>string label.</returns>
60         public string Label
61         {
62             get
63             {
64                 IntPtr ptr = IntPtr.Zero;
65                 Interop.ApplicationManager.AppInfoGetLabel(_handle, out ptr);
66                 string label = Marshal.PtrToStringAuto(ptr);
67                 return label;
68             }
69         }
70         /// <summary>
71         /// ExcutablePath property.
72         /// </summary>
73         /// <returns>string executable path.</returns>
74         public string ExcutablePath
75         {
76             get
77             {
78                 IntPtr ptr = IntPtr.Zero;
79                 Interop.ApplicationManager.AppInfoGetExec(_handle, out ptr);
80                 string exec = Marshal.PtrToStringAuto(ptr);
81                 return exec;
82             }
83         }
84         /// <summary>
85         /// IconPath property.
86         /// </summary>
87         /// <returns>string icon path.</returns>
88         public string IconPath
89         {
90             get
91             {
92                 IntPtr ptr = IntPtr.Zero;
93                 Interop.ApplicationManager.AppInfoGetIcon(_handle, out ptr);
94                 string path = Marshal.PtrToStringAuto(ptr);
95                 return path;
96             }
97         }
98         /// <summary>
99         /// Type property.
100         /// </summary>
101         /// <returns>string application type.</returns>
102         public string Type
103         {
104             get
105             {
106                 IntPtr ptr = IntPtr.Zero;
107                 Interop.ApplicationManager.AppInfoGetType(_handle, out ptr);
108                 string type = Marshal.PtrToStringAuto(ptr);
109                 return type;
110             }
111         }
112
113         /// <summary>
114         /// Metadata property.
115         /// </summary>
116         /// <returns>It returns IDictionary object with string key value pairs.</returns>
117         public IDictionary<String, String> Metadata
118         {
119             get
120             {
121                 IDictionary<string, string> metadata = new Dictionary<String, String>();
122
123                 Interop.ApplicationManager.AppInfoMetadataCallback cb = (string key, string value, IntPtr userData) =>
124                 {
125                     Console.WriteLine("AppInfoMetadataCallback");
126                     if (key.Length != 0)
127                     {
128                         metadata.Add(key, value);
129                     }
130                     return true;
131                 };
132
133                 Interop.ApplicationManager.AppInfoForeachMetadata(_handle, cb, IntPtr.Zero);
134
135                 return metadata;
136             }
137         }
138         /// <summary>
139         /// NoDisplay property.
140         /// </summary>
141         /// <returns>bool. If the application icon is not displayed on the menu screen, true; otherwise, false.</returns>
142         public bool NoDisplay
143         {
144             get
145             {
146                 bool nodisplay = false;
147                 Interop.ApplicationManager.AppInfoIsNodisplay(_handle, out nodisplay);
148                 return nodisplay;
149             }
150         }
151         /// <summary>
152         /// OnBoot property.
153         /// </summary>
154         /// <returns>bool. If the application will be automatically start on boot, true; otherwise, false.</returns>
155         public bool OnBoot
156         {
157             get
158             {
159                 bool onboot = false;
160                 Interop.ApplicationManager.AppInfoIsOnBoot(_handle, out onboot);
161                 return onboot;
162             }
163         }
164         /// <summary>
165         /// PreLoaded property.
166         /// </summary>
167         /// <returns>bool. If the application is preloaded, true; otherwise, false.</returns>
168         public bool PreLoaded
169         {
170             get
171             {
172                 bool preloaded = false;
173                 Interop.ApplicationManager.AppInfoIsPreLoad(_handle, out preloaded);
174                 return preloaded;
175             }
176         }
177         /// <summary>
178         /// GetLocalizedLabel method.
179         /// </summary>
180         /// <param name="locale">string locale.</param>
181         /// <returns>string Localized Label. It returns the label for the input locale.</returns>
182         public string GetLocalizedLabel(string locale)
183         {
184             IntPtr ptr = IntPtr.Zero;
185             Interop.ApplicationManager.AppInfoGetLocaledLabel(ApplicationId, locale, out ptr);
186             string label = Marshal.PtrToStringAuto(ptr);
187             return label;
188         }
189
190         ~InstalledApplication()
191         {
192             Dispose(false);
193         }
194
195         /// <summary>
196         /// 
197         /// </summary>
198         public void Dispose()
199         {
200             Dispose(true);
201             GC.SuppressFinalize(this);
202         }
203
204         private void Dispose(bool disposing)
205         {
206             if(disposed)
207                 return;
208             if(disposing)
209             {
210                 // to be used if there are any other disposable objects
211             }
212             if (_handle != IntPtr.Zero)
213             {
214                 Interop.ApplicationManager.AppInfoDestroy(_handle);
215             }
216             disposed = true;
217         }
218     }
219 }