2 * Copyright (c) 2017 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.
17 namespace Tizen.Applications.Shortcut
22 /// This class provides the some functions to add, delete shortcut.
24 public static class ShortcutManager
26 private const string LogTag = "Tizen.Applications.Shortcut";
28 private static Interop.Shortcut.ResultCallback shortcutAddResult = null;
30 private static Interop.Shortcut.ResultCallback widgetAddResult = null;
32 private static Interop.Shortcut.ResultCallback shortcutDeleteResult = null;
35 /// Adds a shortcut on home-screen.
37 /// <since_tizen> 3 </since_tizen>
38 /// <param name="shortcut">Object that contain shortcut info.</param>
39 /// <feature>http://tizen.org/feature/shortcut</feature>
40 /// <privilege>http://tizen.org/privilege/shortcut</privilege>
41 /// <exception cref="ArgumentException">Thrown when argument is invalid.</exception>
42 /// <exception cref="UnauthorizedAccessException">Thrown in case of permission denied.</exception>
43 /// <exception cref="NotSupportedException">Thrown when Shortcut is not supported.</exception>
44 /// <exception cref="OutOfMemoryException">Thrown in case of out of memory.</exception>
45 /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
46 public static void Add(HomeShortcutInfo shortcut)
48 Interop.Shortcut.ErrorCode err = Interop.Shortcut.ErrorCode.None;
54 if (shortcut.Uri == null || shortcut.Uri == String.Empty)
63 if (shortcutAddResult == null)
65 shortcutAddResult = new Interop.Shortcut.ResultCallback(ShortcutAddResultCallback);
68 err = Interop.Shortcut.AddToHome(shortcut.ShortcutName, type, shortcut.Uri, shortcut.IconPath, Convert.ToInt32(shortcut.IsAllowDuplicate), shortcutAddResult, IntPtr.Zero);
69 if (err != Interop.Shortcut.ErrorCode.None)
71 throw ShortcutErrorFactory.GetException(err, "unable to add shortcut");
76 throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.IoError, e.Message);
81 /// Adds a shortcut on home-screen.
83 /// <since_tizen> 3 </since_tizen>
84 /// <param name="shortcut">Object that contain shortcut info.</param>
85 /// <feature>http://tizen.org/feature/shortcut</feature>
86 /// <privilege>http://tizen.org/privilege/shortcut</privilege>
87 /// <exception cref="ArgumentException">Thrown when argument is invalid.</exception>
88 /// <exception cref="UnauthorizedAccessException">Thrown in case of permission denied.</exception>
89 /// <exception cref="NotSupportedException">Thrown when Shortcut is not supported.</exception>
90 /// <exception cref="OutOfMemoryException">Thrown in case of out of memory.</exception>
91 /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
92 public static void Add(WidgetShortcutInfo shortcut)
94 Interop.Shortcut.ErrorCode err = Interop.Shortcut.ErrorCode.None;
96 if (shortcut.Period < 0.0)
98 throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.InvalidParameter, "Invalid parameter");
103 if (widgetAddResult == null)
105 widgetAddResult = new Interop.Shortcut.ResultCallback(WidgetAddResultCallback);
108 err = Interop.Shortcut.AddToWidget(shortcut.ShortcutName, shortcut.WidgetSize, shortcut.WidgetId, shortcut.IconPath, shortcut.Period, Convert.ToInt32(shortcut.IsAllowDuplicate), null, IntPtr.Zero);
109 if (err != Interop.Shortcut.ErrorCode.None)
111 throw ShortcutErrorFactory.GetException(err, "unable to add shortcut");
116 throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.IoError, e.Message);
121 /// Removes a shortcut from home by ShortcutName.
123 /// <since_tizen> 3 </since_tizen>
124 /// <param name="shortcutName">Shortcut name string.</param>
125 /// <feature>http://tizen.org/feature/shortcut</feature>
126 /// <privilege>http://tizen.org/privilege/shortcut</privilege>
127 /// <exception cref="ArgumentException">Thrown when argument is invalid.</exception>
128 /// <exception cref="UnauthorizedAccessException">Thrown in case of permission denied.</exception>
129 /// <exception cref="NotSupportedException">Thrown when Shortcut is not supported.</exception>
130 /// <exception cref="OutOfMemoryException">Thrown in case of out of memory.</exception>
131 /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
132 public static void Delete(string shortcutName)
134 Interop.Shortcut.ErrorCode err = Interop.Shortcut.ErrorCode.None;
136 if (shortcutName == null)
138 throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.InvalidParameter, "Invalid parameter");
143 if (shortcutDeleteResult == null)
145 shortcutDeleteResult = new Interop.Shortcut.ResultCallback(DeleteResultCallback);
148 err = Interop.Shortcut.Delete(shortcutName, shortcutDeleteResult, IntPtr.Zero);
149 if (err != Interop.Shortcut.ErrorCode.None)
151 throw ShortcutErrorFactory.GetException(err, "unable to delete shortcut");
156 throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.IoError, e.Message);
161 /// Removes a shortcut from home by ShortcutInfo.
163 /// <since_tizen> 3 </since_tizen>
164 /// <param name="shortcut">Object that contain shortcut info.</param>
165 /// <feature>http://tizen.org/feature/shortcut</feature>
166 /// <privilege>http://tizen.org/privilege/shortcut</privilege>
167 /// <exception cref="ArgumentException">Thrown when argument is invalid.</exception>
168 /// <exception cref="UnauthorizedAccessException">Thrown in case of permission denied.</exception>
169 /// <exception cref="NotSupportedException">Thrown when Shortcut is not supported.</exception>
170 /// <exception cref="OutOfMemoryException">Thrown in case of out of memory.</exception>
171 /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
172 public static void Delete(ShortcutInfo shortcut)
174 if (shortcut == null)
176 throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.InvalidParameter, "Invalid parameter");
181 Delete(shortcut.ShortcutName);
185 throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.IoError, e.Message);
189 private static int ShortcutAddResultCallback(int ret, IntPtr data)
191 if (ret != (int)Interop.Shortcut.ErrorCode.None)
193 throw ShortcutErrorFactory.GetException((Interop.Shortcut.ErrorCode)ret, "unable to add shortcut");
199 private static int WidgetAddResultCallback(int ret, IntPtr data)
201 if (ret != (int)Interop.Shortcut.ErrorCode.None)
203 throw ShortcutErrorFactory.GetException((Interop.Shortcut.ErrorCode)ret, "unable to add widget");
209 private static int DeleteResultCallback(int ret, IntPtr data)
211 if (ret != (int)Interop.Shortcut.ErrorCode.None)
213 throw ShortcutErrorFactory.GetException((Interop.Shortcut.ErrorCode)ret, "unable to delete shortcut");