08f159c80e003abf0d508b6ab25f79e9cc09d654
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.WidgetApplication / Tizen.Applications / WidgetApplication.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 Tizen.Applications.CoreBackend;
12
13 namespace Tizen.Applications
14 {
15     /// <summary>
16     /// Represents a widget application.
17     /// </summary>
18     public class WidgetApplication : CoreApplication
19     {
20         /// <summary>
21         /// Initializes WidgetApplication class.
22         /// </summary>
23         /// <param name="typeInfo">map structure for derived class type and widget id</param>
24         public WidgetApplication(IDictionary<Type, string> typeInfo) : base(new WidgetCoreBackend())
25         {
26             WidgetCoreBackend core = Backend as WidgetCoreBackend;
27
28             core?.CreateWidgetTypes(typeInfo);
29         }
30
31         /// <summary>
32         /// Initializes WidgetApplication class.
33         /// </summary>
34         /// <remarks> Widget id will be replaced as application id</remarks>
35         /// <param name="type">derived class type</param>
36         public WidgetApplication(Type type) : base(new WidgetCoreBackend())
37         {
38             WidgetCoreBackend core = Backend as WidgetCoreBackend;
39
40             core?.CreateWidgetTypes(new Dictionary<Type, string>() { {type, ApplicationInfo.ApplicationId } });
41         }
42
43         /// <summary>
44         /// Gets all instances of the widget associated with the type
45         /// </summary>
46         /// <param name="type">Class type for the widget</param>
47         public IEnumerable<WidgetBase> GetInstances(Type type)
48         {
49             WidgetCoreBackend core = Backend as WidgetCoreBackend;
50
51             if (core == null)
52                 return null;
53
54             foreach (WidgetType w in core.WidgetTypes)
55             {
56                 if (w.ClassType == type)
57                 {
58                     return w.WidgetInstances;
59                 }
60             }
61
62             return null;
63         }
64
65         /// <summary>
66         /// Runs the widget application's main loop.
67         /// </summary>
68         /// <param name="args">Arguments from commandline.</param>
69         public override void Run(string[] args)
70         {
71             base.Run(args);
72         }
73     }
74 }