Exemple #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);
        }
Exemple #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);
            }
        }
Exemple #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);
            }
        }
Exemple #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);
            }
        }
Exemple #5
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);
            }
        }
        internal static Exception GetException(Interop.Shortcut.ErrorCode err, string msg)
        {
            switch (err)
            {
            case Interop.Shortcut.ErrorCode.InvalidParameter:
                return(new ArgumentException(err + " error occurred."));

            case Interop.Shortcut.ErrorCode.PermissionDenied:
                return(new UnauthorizedAccessException(err + " Permission denied (http://tizen.org/privilege/shortcut)"));

            case Interop.Shortcut.ErrorCode.NotSupported:
                return(new NotSupportedException(err + " Not Supported (http://tizen.org/feature/shortcut)"));

            case Interop.Shortcut.ErrorCode.OutOfMemory:
                return(new OutOfMemoryException(err + " error occurred."));

            default:
                Log.Error(LogTag, msg);
                return(new InvalidOperationException(err + " error occurred."));
            }
        }
Exemple #7
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);
            }
        }