Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.WidgetApplication / Tizen.Applications / WidgetApplication.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18 using System.Collections.Generic;
19 using Tizen.Applications.CoreBackend;
20
21 namespace Tizen.Applications
22 {
23     /// <summary>
24     /// Represents a widget application.
25     /// </summary>
26     public class WidgetApplication : CoreApplication
27     {
28         /// <summary>
29         /// Initializes the WidgetApplication class with the type and application ID.
30         /// </summary>
31         /// <param name="typeInfo">Map structure for the derived class type and widget ID.</param>
32         public WidgetApplication(IDictionary<Type, string> typeInfo) : base(new WidgetCoreBackend())
33         {
34             WidgetCoreBackend core = Backend as WidgetCoreBackend;
35
36             core?.CreateWidgetTypes(typeInfo);
37         }
38
39         /// <summary>
40         /// Initializes the WidgetApplication class with the type.
41         /// </summary>
42         /// <remarks>Widget ID will be replaced as the application ID.</remarks>
43         /// <param name="type">Derived class type.</param>
44         public WidgetApplication(Type type) : base(new WidgetCoreBackend())
45         {
46             WidgetCoreBackend core = Backend as WidgetCoreBackend;
47
48             core?.CreateWidgetTypes(new Dictionary<Type, string>() { {type, ApplicationInfo.ApplicationId } });
49         }
50
51         /// <summary>
52         /// Gets all instances of the widget associated with the type.
53         /// </summary>
54         /// <param name="type">Class type for the widget.</param>
55         public IEnumerable<WidgetBase> GetInstances(Type type)
56         {
57             WidgetCoreBackend core = Backend as WidgetCoreBackend;
58
59             if (core == null)
60                 return null;
61
62             foreach (WidgetType w in core.WidgetTypes)
63             {
64                 if (w.ClassType == type)
65                 {
66                     return w.WidgetInstances;
67                 }
68             }
69
70             return null;
71         }
72
73         /// <summary>
74         /// Runs the widget application's main loop.
75         /// </summary>
76         /// <param name="args">Arguments from the commandline.</param>
77         public override void Run(string[] args)
78         {
79             base.Run(args);
80         }
81     }
82 }