Exemplo n.º 1
0
        /// <summary>
        /// Gets the preset list of the shortcut template from the installed package.
        /// </summary>
        /// <since_tizen> 4 </since_tizen>
        /// <param name="appId">The application ID.</param>
        /// <returns>The List of ShortcutTemplate.</returns>
        /// <feature>http://tizen.org/feature/shortcut</feature>
        /// <privilege>http://tizen.org/privilege/shortcut</privilege>
        /// <exception cref="ArgumentException">Thrown when an argument is invalid.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown in case the permission is denied.</exception>
        /// <exception cref="NotSupportedException">Thrown when the shortcut is not supported.</exception>
        /// <exception cref="OutOfMemoryException">Thrown in case of out of memory.</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
        public static IEnumerable <ShortcutTemplate> GetTemplateList(string appId)
        {
            shortcutTemplates.Clear();

            if (string.IsNullOrEmpty(appId))
            {
                throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.InvalidParameter, null);
            }

            Interop.Shortcut.ListCallback callback = (appName, iconPath, shortcutName, extrakey, extraData, user_data) =>
            {
                ShortcutTemplate template = new ShortcutTemplate
                {
                    AppId        = appName,
                    ShortcutName = shortcutName,
                    IconPath     = iconPath,
                    ExtraKey     = extrakey,
                    ExtraData    = extraData,
                };

                shortcutTemplates.Add(template);

                return(0);
            };

            Interop.Shortcut.ErrorCode err = Interop.Shortcut.GetList(appId, callback, IntPtr.Zero);
            if (err < Interop.Shortcut.ErrorCode.None)
            {
                throw ShortcutErrorFactory.GetException(err, "unable to get ShortcutTemplate Lists");
            }

            return(shortcutTemplates);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds a shortcut on the home-screen.
        /// </summary>
        /// <since_tizen> 4 </since_tizen>
        /// <param name="shortcut">Object that contains the shortcut information.</param>
        /// <feature>http://tizen.org/feature/shortcut</feature>
        /// <privilege>http://tizen.org/privilege/shortcut</privilege>
        /// <exception cref="ArgumentException">Thrown when an argument is invalid.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown in case the permission is denied.</exception>
        /// <exception cref="NotSupportedException">Thrown when the shortcut is not supported.</exception>
        /// <exception cref="OutOfMemoryException">Thrown in case of out of memory.</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
        public static void Add(HomeShortcutInfo shortcut)
        {
            Interop.Shortcut.ErrorCode err = Interop.Shortcut.ErrorCode.None;

            try
            {
                int type;

                if (string.IsNullOrEmpty(shortcut.Uri))
                {
                    type = 0;
                }
                else
                {
                    type = 1;
                }

                err = Interop.Shortcut.AddToHome(shortcut.ShortcutName, type, shortcut.Uri, shortcut.IconPath, Convert.ToInt32(shortcut.IsAllowDuplicate));
                if (err != Interop.Shortcut.ErrorCode.None)
                {
                    throw ShortcutErrorFactory.GetException(err, "unable to add shortcut");
                }
            }
            catch (Exception e)
            {
                throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.IoError, e.Message);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds a shortcut on the home-screen.
        /// </summary>
        /// <since_tizen> 4 </since_tizen>
        /// <param name="shortcut">Object that contains the shortcut information.</param>
        /// <feature>http://tizen.org/feature/shortcut</feature>
        /// <privilege>http://tizen.org/privilege/shortcut</privilege>
        /// <exception cref="ArgumentException">Thrown when an argument is invalid.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown in case the permission is denied.</exception>
        /// <exception cref="NotSupportedException">Thrown when the shortcut is not supported.</exception>
        /// <exception cref="OutOfMemoryException">Thrown in case of out of memory.</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
        public static void Add(WidgetShortcutInfo shortcut)
        {
            Interop.Shortcut.ErrorCode err = Interop.Shortcut.ErrorCode.None;

            if (shortcut.Period < 0.0)
            {
                throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.InvalidParameter, "Invalid parameter");
            }

            try
            {
                if (widgetAddResult == null)
                {
                    widgetAddResult = new Interop.Shortcut.ResultCallback(WidgetAddResultCallback);
                }

                err = Interop.Shortcut.AddToWidget(shortcut.ShortcutName, shortcut.WidgetSize, shortcut.WidgetId, shortcut.IconPath, shortcut.Period, Convert.ToInt32(shortcut.IsAllowDuplicate), widgetAddResult, IntPtr.Zero);
                if (err != Interop.Shortcut.ErrorCode.None)
                {
                    throw ShortcutErrorFactory.GetException(err, "unable to add widget");
                }
            }
            catch (Exception e)
            {
                throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.IoError, e.Message);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Removes a shortcut from home by the ShortcutName.
        /// </summary>
        /// <since_tizen> 4 </since_tizen>
        /// <param name="shortcutName">The shortcut name string.</param>
        /// <feature>http://tizen.org/feature/shortcut</feature>
        /// <privilege>http://tizen.org/privilege/shortcut</privilege>
        /// <exception cref="ArgumentException">Thrown when an argument is invalid.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown in case the permission is denied.</exception>
        /// <exception cref="NotSupportedException">Thrown when the shortcut is not supported.</exception>
        /// <exception cref="OutOfMemoryException">Thrown in case of out of memory.</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
        public static void Delete(string shortcutName)
        {
            Interop.Shortcut.ErrorCode err = Interop.Shortcut.ErrorCode.None;

            if (shortcutName == null)
            {
                throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.InvalidParameter, "Invalid parameter");
            }

            try
            {
                if (shortcutDeleteResult == null)
                {
                    shortcutDeleteResult = new Interop.Shortcut.ResultCallback(DeleteResultCallback);
                }

                err = Interop.Shortcut.Delete(shortcutName, shortcutDeleteResult, IntPtr.Zero);
                if (err != Interop.Shortcut.ErrorCode.None)
                {
                    throw ShortcutErrorFactory.GetException(err, "unable to delete shortcut");
                }
            }
            catch (Exception e)
            {
                throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.IoError, e.Message);
            }
        }
Exemplo n.º 5
0
        private static int DeleteResultCallback(int ret, IntPtr data)
        {
            if (ret != (int)Interop.Shortcut.ErrorCode.None)
            {
                throw ShortcutErrorFactory.GetException((Interop.Shortcut.ErrorCode)ret, "unable to delete shortcut");
            }

            return(0);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Removes a shortcut from home by the ShortcutInfo.
        /// </summary>
        /// <since_tizen> 4 </since_tizen>
        /// <param name="shortcut">Object that contains the shortcut information.</param>
        /// <feature>http://tizen.org/feature/shortcut</feature>
        /// <privilege>http://tizen.org/privilege/shortcut</privilege>
        /// <exception cref="ArgumentException">Thrown when an argument is invalid.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown in case the permission is denied.</exception>
        /// <exception cref="NotSupportedException">Thrown when the shortcut is not supported.</exception>
        /// <exception cref="OutOfMemoryException">Thrown in case of out of memory.</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
        public static void Delete(ShortcutInfo shortcut)
        {
            if (shortcut == null)
            {
                throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.InvalidParameter, "Invalid parameter");
            }

            try
            {
                Delete(shortcut.ShortcutName);
            }
            catch (Exception e)
            {
                throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.IoError, e.Message);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Registers a callback function to listen requests from the applications.
        /// </summary>
        /// <since_tizen> 4 </since_tizen>
        /// <param name="addedEvent">The callback function pointer that is invoked when Add() is requested.</param>
        /// <feature>http://tizen.org/feature/shortcut</feature>
        /// <privilege>http://tizen.org/privilege/shortcut</privilege>
        /// <remarks>
        /// Previous registered delegate function should be unregistered.
        /// </remarks>
        /// <exception cref="ArgumentException">Thrown when an argument is invalid.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown in case the permission is denied.</exception>
        /// <exception cref="NotSupportedException">Thrown when the shortcut is not supported.</exception>
        /// <exception cref="OutOfMemoryException">Thrown in case of out of memory.</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
        public static void RegisterEventHandler(ShortcutAdded addedEvent)
        {
            if (shortcutAddCallback == null)
            {
                shortcutAddCallback = new Interop.Shortcut.AddCallback(AddCallback);

                Interop.Shortcut.ErrorCode err = Interop.Shortcut.SetShortcutAddCallback(shortcutAddCallback, IntPtr.Zero);
                if (err != Interop.Shortcut.ErrorCode.None)
                {
                    shortcutAddCallback = null;
                    throw ShortcutErrorFactory.GetException(err, "unable to register callback");
                }

                shortcutAdded = addedEvent;
            }
            else
            {
                throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.InvalidParameter, null);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Removes a shortcut from home by the ShortcutName.
        /// </summary>
        /// <since_tizen> 4 </since_tizen>
        /// <param name="shortcutName">The shortcut name string.</param>
        /// <feature>http://tizen.org/feature/shortcut</feature>
        /// <privilege>http://tizen.org/privilege/shortcut</privilege>
        /// <exception cref="ArgumentException">Thrown when an argument is invalid.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown in case the permission is denied.</exception>
        /// <exception cref="NotSupportedException">Thrown when the shortcut is not supported.</exception>
        /// <exception cref="OutOfMemoryException">Thrown in case of out of memory.</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
        public static void Delete(string shortcutName)
        {
            Interop.Shortcut.ErrorCode err = Interop.Shortcut.ErrorCode.None;

            if (shortcutName == null)
            {
                throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.InvalidParameter, "Invalid parameter");
            }

            try
            {
                err = Interop.Shortcut.Delete(shortcutName);
                if (err != Interop.Shortcut.ErrorCode.None)
                {
                    throw ShortcutErrorFactory.GetException(err, "unable to delete shortcut");
                }
            }
            catch (Exception e)
            {
                throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.IoError, e.Message);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Unregisters a callback for the shortcut request.
        /// </summary>
        /// <since_tizen> 4 </since_tizen>
        /// <param name="deletedEvent">The callback function pointer that is used for RegisterCallback.</param>
        /// <feature>http://tizen.org/feature/shortcut</feature>
        /// <privilege>http://tizen.org/privilege/shortcut</privilege>
        /// <exception cref="ArgumentException">Thrown when an argument is invalid.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown in case the permission is denied.</exception>
        /// <exception cref="NotSupportedException">Thrown when the shortcut is not supported.</exception>
        public static void UnregisterEventHandler(ShortcutDeleted deletedEvent)
        {
            if (shortcutDeleted != null && shortcutDeleted.Equals(deletedEvent))
            {
                shortcutDeleted = null;

                if (shortcutDeleteCallback != null)
                {
                    Interop.Shortcut.UnsetShortcutDeleteCallback();
                    shortcutDeleteCallback = null;

                    int err = ErrorFacts.GetLastResult();
                    if (err != (int)Interop.Shortcut.ErrorCode.None)
                    {
                        throw ShortcutErrorFactory.GetException((Interop.Shortcut.ErrorCode)err, "unable to unregister callback");
                    }
                }
            }
            else
            {
                throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.InvalidParameter, null);
            }
        }