Add Tizen.Application.ApplicationManager
[platform/core/csapi/tizenfx.git] / Tizen.Applications / Tizen.Applications / ApplicationManagerFilter.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
12 namespace Tizen.Applications
13 {
14     /// <summary>
15     /// InstalledApplicationFilter class. This class is a parameter of InstallerApplicationAppsAsync method.
16     /// </summary>
17     public class InstalledApplicationFilter : IDisposable
18     {
19         /// <summary>
20         /// Keys class. This class is a possible key to use in the InstalledApplicationFilter.
21         /// </summary>
22         public static class Keys
23         {
24             /// <summary>
25             ///
26             /// </summary>
27             public const string Id = "PACKAGE_INFO_PROP_APP_ID";
28             /// <summary>
29             ///
30             /// </summary>
31             public const string Type = "PACKAGE_INFO_PROP_APP_TYPE";
32             /// <summary>
33             ///
34             /// </summary>
35             public const string Category = "PACKAGE_INFO_PROP_APP_CATEGORY";
36             /// <summary>
37             ///
38             /// </summary>
39             public const string NoDisplay = "PACKAGE_INFO_PROP_APP_NODISPLAY";
40             /// <summary>
41             ///
42             /// </summary>
43             public const string TaskManage = "PACKAGE_INFO_PROP_APP_TASKMANAGE";
44         }
45
46         private IntPtr _handle;
47         private bool disposed = false;
48
49         public InstalledApplicationFilter(IDictionary<string, string> filter)
50         {
51             Interop.ApplicationManager.AppInfoFilterCreate(out _handle);
52             foreach (var item in filter)
53             {
54                 if ((item.Key == Keys.Id) || (item.Key == Keys.Type) || (item.Key == Keys.Category))
55                 {
56                     Interop.ApplicationManager.AppInfoFilterAddString(_handle, item.Key, item.Value);
57                 }
58                 else if ((item.Key == Keys.NoDisplay) || (item.Key == Keys.TaskManage))
59                 {
60                     Interop.ApplicationManager.AppInfoFilterAddBool(_handle, item.Key, Convert.ToBoolean(item.Value));
61                 }
62                 else
63                 {
64                     // Not Supported Key
65                     Console.WriteLine(item.Key + " is NOT supported for the InstalledApplicationFilter");
66                 }
67             }
68         }
69
70         internal IntPtr Handle
71         {
72             get
73             {
74                 return _handle;
75             }
76         }
77
78         ~InstalledApplicationFilter()
79         {
80             Dispose(false);
81         }
82
83         public void Dispose()
84         {
85             Dispose(true);
86             GC.SuppressFinalize(this);
87         }
88
89         private void Dispose(bool disposing)
90         {
91             if (disposed)
92                 return;
93             if (disposing)
94             {
95                 // to be used if there are any other disposable objects
96             }
97             if (_handle != IntPtr.Zero)
98             {
99                 Interop.ApplicationManager.AppInfoFilterDestroy(_handle);
100             }
101             disposed = true;
102         }
103     }
104
105     /// <summary>
106     /// InstalledApplicationMetadataFilter class. This class is a parameter of InstallerApplicationAppsAsync method.
107     /// </summary>
108     public class InstalledApplicationMetadataFilter : IDisposable
109     {
110         private IntPtr _handle;
111         private bool disposed = false;
112
113         public InstalledApplicationMetadataFilter(IDictionary<string, string> filter)
114         {
115             Interop.ApplicationManager.AppInfoMetadataFilterCreate(out _handle);
116             foreach (var item in filter)
117             {
118                 Interop.ApplicationManager.AppInfoMetadataFilterAdd(_handle, item.Key, item.Value);
119             }
120         }
121
122         internal IntPtr Handle
123         {
124             get
125             {
126                 return _handle;
127             }
128         }
129
130         ~InstalledApplicationMetadataFilter()
131         {
132             Dispose(false);
133         }
134
135         public void Dispose()
136         {
137             Dispose(true);
138             GC.SuppressFinalize(this);
139         }
140
141         private void Dispose(bool disposing)
142         {
143             if (disposed)
144                 return;
145             if (disposing)
146             {
147                 // to be used if there are any other disposable objects
148             }
149             if (_handle != IntPtr.Zero)
150             {
151                 Interop.ApplicationManager.AppInfoMetadataFilterDestroy(_handle);
152             }
153             disposed = true;
154         }
155     }
156 }