SHORTCUT_ERROR_NO_SPACE = TIZEN_ERROR_SHORTCUT | 0x0001, /**< There is no space to add a new shortcut */
SHORTCUT_ERROR_EXIST = TIZEN_ERROR_SHORTCUT | 0x0002, /**< Shortcut is already added */
SHORTCUT_ERROR_FAULT = TIZEN_ERROR_SHORTCUT | 0x0004, /**< Unrecoverable error */
+ SHORTCUT_ERROR_NOT_EXIST = TIZEN_ERROR_SHORTCUT | 0x0008, /**< Not exist shortcut(@b Since: 3.0) */
SHORTCUT_ERROR_COMM = TIZEN_ERROR_SHORTCUT | 0x0040 /**< Connection not established or communication problem */
};
/*
- *
* Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the License);
* @{
*/
-
struct result_cb_item {
result_internal_cb_t result_internal_cb;
result_cb_t result_cb;
void *data;
};
-
-/**
- * @brief Enumeration for shortcut error extension.
- * @since_tizen 3.0
- */
-enum shortcut_error_extension_e {
- SHORTCUT_ERROR_NOT_EXIST = TIZEN_ERROR_SHORTCUT | 0x0008, /* Not exist shortcut */
-};
-
-
-/**
- * @internal
- * @brief Called to the shortcut_remove_from_home request.
- * @since_tizen 3.0
- * @param[in] package_name The name of package
- * @param[in] name The name of the created shortcut icon
- * @param[in] sender_pid The process ID of who request shortcut_remove_from_home
- * @param[in] user_data The user data passed from the callback register function
- *
- * @return 0 on success, otherwise a negative error value
- * @retval #SHORTCUT_ERROR_NONE Successful
- * @retval #SHORTCUT_ERROR_INVALID_PARAMETER Invalid function parameter
- * @retval #SHORTCUT_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #SHORTCUT_ERROR_IO_ERROR I/O Error
- * @retval #SHORTCUT_ERROR_PERMISSION_DENIED Permission denied
- * @retval #SHORTCUT_ERROR_COMM Connection not established or communication problem
- * @retval #SHORTCUT_ERROR_NOT_EXIST Shortcut not exist
- */
-typedef int (*shortcut_remove_cb)(const char *package_name, const char *name, int sender_pid, void *user_data);
-
-
-/**
- * @internal
- * @brief Registers a callback function for the shortcut removal request.
- * @remarks Should be used in the homescreen.\n
- * Should check the return value of this function.
- * Prospective Clients: Homescreen.
- * @since_tizen 3.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/shortcut
- *
- * @param[in] request_cb The callback function pointer that is invoked when shortcut_remove_from_home is requested
- * @param[in] data The callback data to deliver to the callback function
- *
- * @return 0 on success, otherwise a negative error value
- * @retval #SHORTCUT_ERROR_NONE Successful
- * @retval #SHORTCUT_ERROR_INVALID_PARAMETER Invalid function parameter
- * @retval #SHORTCUT_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #SHORTCUT_ERROR_IO_ERROR I/O Error
- * @retval #SHORTCUT_ERROR_PERMISSION_DENIED Permission denied
- * @retval #SHORTCUT_ERROR_COMM Connection not established or communication problem
- * @pre You have to prepare a callback function.
- *
- * @post If a request is sent from the application, the registered callback will be invoked.
- *
- * @see shortcut_remove_cb
- */
-int shortcut_set_remove_cb(shortcut_remove_cb remove_cb, void *user_data);
-
-/**
- * @internal
- * @brief Removes a shortcut from home, asynchronously.
- * @since_tizen 3.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/shortcut
- * @param[in] name The name of the created shortcut icon
- * @param[in] result_cb The address of the callback function that is called when the result comes back from the viewer
- * @param[in] user_data The callback data that is used in the callback function
- *
- * @return 0 on success, otherwise a negative error value
- * @retval #SHORTCUT_ERROR_NONE Successful
- * @retval #SHORTCUT_ERROR_INVALID_PARAMETER Invalid function parameter
- * @retval #SHORTCUT_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #SHORTCUT_ERROR_IO_ERROR I/O Error
- * @retval #SHORTCUT_ERROR_PERMISSION_DENIED Permission denied
- * @retval #SHORTCUT_ERROR_NOT_SUPPORTED Not supported
- * @retval #SHORTCUT_ERROR_RESOURCE_BUSY Device or resource busy
- * @retval #SHORTCUT_ERROR_FAULT Unrecoverable error
- * @retval #SHORTCUT_ERROR_COMM Connection not established or communication problem
- *
- * @pre You have to prepare the callback function.
- *
- * @post You have to check the return status from the callback function which is passed by the argument.
- *
- * @see result_cb_t
- *
- * @par Example
- * @code
-
-#include <shortcut_internal.h>
-...
- int result_cb(int ret, void *data)
- {
- if (ret < 0)
- dlog_print("Failed to remove a shortcut: %d\n", ret);
-
- return 0;
- }
-
- ...
-
-{
- int result;
-
- result = shortcut_remove_from_home("shortcut_name", result_cb, NULL);
-
- if (result != SHORTCUT_ERROR_NONE) {
- dlog_print("Failed to remove a shortcut: %d\n", result);
- return result;
- }
-...
-
- }
-
- * @endcode
- */
-int shortcut_remove_from_home(const char *name, result_cb_t result_cb, void *user_data);
-
int _dbus_init(void);
int _dbus_signal_init();
char *_shortcut_get_pkgname_by_pid(void);
int _send_async_shortcut(GVariant *body, struct result_cb_item *cb_item, char *cmd);
int _check_privilege(void);
void _set_request_cb(shortcut_request_cb request_cb, void *data);
+void _set_remove_cb(shortcut_remove_cb remove_cb, void *data);
+void _unset_request_cb(void);
+void _unset_remove_cb(void);
int _dbus_set_watch_name();
/**
*/
int shortcut_add_to_home_widget(const char *name, shortcut_widget_size_e size, const char *widget_id, const char *icon, double period, int allow_duplicate, result_cb_t result_cb, void *data);
+/**
+ * @brief Removes a shortcut from home, asynchronously.
+ * @details If the callback function registered for a widget, the shortcut deletion is possible.
+ * @since_tizen 3.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/shortcut
+ * @param[in] name The name of the created shortcut icon
+ * @param[in] result_cb The address of the callback function that is called when the result comes back from the viewer
+ * @param[in] user_data The callback data that is used in the callback function
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SHORTCUT_ERROR_NONE Successful
+ * @retval #SHORTCUT_ERROR_INVALID_PARAMETER Invalid function parameter
+ * @retval #SHORTCUT_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #SHORTCUT_ERROR_IO_ERROR I/O Error
+ * @retval #SHORTCUT_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #SHORTCUT_ERROR_COMM Connection not established or communication problem
+ *
+ * @pre You have to prepare the callback function.
+ *
+ * @post You have to check the return status from the callback function which is passed by the argument.
+ *
+ * @see result_cb_t
+ *
+ * @par Example
+ * @code
+
+#include <shortcut_manager.h>
+
+...
+
+int result_cb(int ret, void *data)
+{
+ if (ret < 0)
+ dlog_print("Failed to remove a shortcut: %d\n", ret);
+
+ return 0;
+}
+
+...
+
+{
+ int result;
+
+ result = shortcut_remove_from_home("shortcut_name", result_cb, NULL);
+
+ if (result != SHORTCUT_ERROR_NONE) {
+ dlog_print("Failed to remove a shortcut: %d\n", result);
+ return result;
+ }
+...
+
+}
+
+ * @endcode
+ */
+int shortcut_remove_from_home(const char *name, result_cb_t result_cb, void *user_data);
/**
* @brief Called to receive the result of shortcut_get_list().
typedef int (*shortcut_request_cb)(const char *package_name, const char *name, int type, const char *content_info, const char *icon, int pid, double period, int allow_duplicate, void *data);
/**
- * @brief Registers a callback function to listen requests from applications.
+ * @brief Called to the shortcut_remove_from_home request.
+ * @since_tizen 3.0
+ * @param[in] package_name The name of package
+ * @param[in] name The name of the created shortcut icon
+ * @param[in] sender_pid The process ID of who request shortcut_remove_from_home
+ * @param[in] user_data The user data passed from the callback register function
+ * @return The result of handling a shortcut remove request\n
+ * This returns @c 0 if the remove_from_home request is handled successfully,
+ * otherwise it returns a proper errno.
+ * @see shortcut_set_remove_cb()
+ */
+typedef int (*shortcut_remove_cb)(const char *package_name, const char *name, int sender_pid, void *user_data);
+
+/**
+ * @brief Registers a callback function to listen the add requests from applications.
* @remarks Should be used in the homescreen.\n
* Should check the return value of this function.
- * Prospective Clients: Homescreen.
- * @since_tizen 2.4
+ * Prospective Clients: Homescreen.
+ * @since_tizen 2.4
* @privlevel public
* @privilege %http://tizen.org/privilege/shortcut
*
*/
int shortcut_set_request_cb(shortcut_request_cb request_cb, void *data);
+/**
+ * @brief Unregisters a callback for the shortcut request.
+ * @since_tizen 3.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/shortcut
+ *
+ * @see shortcut_set_request_cb
+ */
+void shortcut_unset_request_cb(void);
+
+/**
+ * @brief Registers the callback function to listen the remove requests from applications.
+ * @remarks Should be used in the homescreen.\n
+ * Should check the return value of this function.
+ * Prospective Clients: Homescreen.
+ * @since_tizen 3.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/shortcut
+ *
+ * @param[in] remove_cb The callback function pointer that is invoked when remove_from_home is requested
+ * @param[in] data The callback data to deliver to the callback function
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SHORTCUT_ERROR_NONE Successful
+ * @retval #SHORTCUT_ERROR_INVALID_PARAMETER Invalid function parameter
+ * @retval #SHORTCUT_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #SHORTCUT_ERROR_IO_ERROR I/O Error
+ * @retval #SHORTCUT_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #SHORTCUT_ERROR_COMM Connection not established or communication problem
+ * @pre You have to prepare a callback function.
+ *
+ * @post If a request is sent from the application, the registered callback will be invoked.
+ *
+ * @see remove_cb_t
+ * @see shortcut_error_e
+ */
+int shortcut_set_remove_cb(shortcut_remove_cb remove_cb, void *data);
+
+/**
+ * @brief Unregisters a callback for the shortcut remove.
+ * @since_tizen 3.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/shortcut
+ *
+ * @see shortcut_set_remove_cb
+ */
+void shortcut_unset_remove_cb(void);
/**
* @}
_request_callback_info.data = data;
}
+void _unset_request_cb(void)
+{
+ _request_callback_info.request_cb = NULL;
+ _request_callback_info.data = NULL;
+}
+
+void _set_remove_cb(shortcut_remove_cb remove_cb, void *data)
+{
+ _remove_callback_info.remove_cb = remove_cb;
+ _remove_callback_info.data = data;
+}
+
+void _unset_remove_cb(void)
+{
+ _remove_callback_info.remove_cb = NULL;
+ _remove_callback_info.data = NULL;
+}
+
int _dbus_set_watch_name()
{
if (provider_monitor_id == 0) {
return SHORTCUT_ERROR_NONE;
}
-
-EXPORT_API int shortcut_set_remove_cb(shortcut_remove_cb remove_cb, void *user_data)
-{
- int ret;
-
- if (remove_cb == NULL)
- return SHORTCUT_ERROR_INVALID_PARAMETER;
-
- ret = _dbus_init();
- if (ret != SHORTCUT_ERROR_NONE) {
- /* LCOV_EXCL_START */
- ErrPrint("Can't init dbus %d", ret);
- return ret;
- /* LCOV_EXCL_STOP */
- }
-
- ret = _dbus_signal_init();
- if (ret != SHORTCUT_ERROR_NONE) {
- /* LCOV_EXCL_START */
- ErrPrint("Can't init dbus_signal %d", ret);
- return ret;
- /* LCOV_EXCL_STOP */
- }
-
- ret = _send_service_register();
- if (ret != SHORTCUT_ERROR_NONE) {
- /* LCOV_EXCL_START */
- ErrPrint("Can't init ipc_monitor_register %d", ret);
- return ret;
- /* LCOV_EXCL_STOP */
- }
-
- ret = _dbus_set_watch_name();
- if (ret != SHORTCUT_ERROR_NONE) {
- /* LCOV_EXCL_START */
- ErrPrint("Can't init _dbus_set_watch_name %d", ret);
- return ret;
- /* LCOV_EXCL_STOP */
- }
-
- _remove_callback_info.remove_cb = remove_cb;
- _remove_callback_info.data = user_data;
-
- return SHORTCUT_ERROR_NONE;
-}
-
-EXPORT_API int shortcut_remove_from_home(const char *name, result_cb_t result_cb, void *user_data)
-{
- struct result_cb_item *item;
- char *appid;
- int ret;
- GVariant *body;
-
- if (name == NULL) {
- ErrPrint("name is NULL.");
- return SHORTCUT_ERROR_INVALID_PARAMETER;
- }
-
- ret = _dbus_init();
- if (ret != SHORTCUT_ERROR_NONE) {
- /* LCOV_EXCL_START */
- ErrPrint("Can't init dbus %d", ret);
- return ret;
- /* LCOV_EXCL_STOP */
- }
-
- ret = _check_privilege();
- if (ret != SHORTCUT_ERROR_NONE)
- return ret;
-
- appid = _shortcut_get_pkgname_by_pid();
- item = malloc(sizeof(struct result_cb_item));
- if (!item) {
- /* LCOV_EXCL_START */
- if (appid)
- free(appid);
-
- ErrPrint("Heap: %d\n", errno);
- return SHORTCUT_ERROR_OUT_OF_MEMORY;
- /* LCOV_EXCL_STOP */
- }
-
- item->result_cb = result_cb;
- item->result_internal_cb = NULL;
- item->data = user_data;
-
- body = g_variant_new("(iss)", getpid(), appid, name);
-
- ret = _send_async_shortcut(body, item, "remove_shortcut");
- if (ret != SHORTCUT_ERROR_NONE) {
- /* LCOV_EXCL_START */
- free(item);
- item = NULL;
- /* LCOV_EXCL_STOP */
- }
-
- if (appid)
- free(appid);
- if (body)
- g_variant_unref(body);
-
- return ret;
-
-}
-
EAPI int shortcut_set_request_cb(shortcut_request_cb request_cb, void *data)
{
- int ret = _dbus_init();
+ int ret;
if (request_cb == NULL)
return SHORTCUT_ERROR_INVALID_PARAMETER; /* LCOV_EXCL_LINE */
+ ret = _dbus_init();
if (ret != SHORTCUT_ERROR_NONE) {
/* LCOV_EXCL_START */
ErrPrint("Can't init dbus %d", ret);
return SHORTCUT_ERROR_NONE;
}
+EAPI void shortcut_unset_request_cb(void)
+{
+ _unset_request_cb();
+}
+
+EAPI int shortcut_set_remove_cb(shortcut_remove_cb remove_cb, void *data)
+{
+ int ret;
+
+ if (remove_cb == NULL)
+ return SHORTCUT_ERROR_INVALID_PARAMETER;
+
+ ret = _dbus_init();
+ if (ret != SHORTCUT_ERROR_NONE) {
+ /* LCOV_EXCL_START */
+ ErrPrint("Can't init dbus %d", ret);
+ return ret;
+ /* LCOV_EXCL_STOP */
+ }
+
+ ret = _dbus_signal_init();
+ if (ret != SHORTCUT_ERROR_NONE) {
+ /* LCOV_EXCL_START */
+ ErrPrint("Can't init dbus_signal %d", ret);
+ return ret;
+ /* LCOV_EXCL_STOP */
+ }
+
+ ret = _send_service_register();
+ if (ret != SHORTCUT_ERROR_NONE) {
+ /* LCOV_EXCL_START */
+ ErrPrint("Can't init ipc_monitor_register %d", ret);
+ return ret;
+ /* LCOV_EXCL_STOP */
+ }
+
+ ret = _dbus_set_watch_name();
+ if (ret != SHORTCUT_ERROR_NONE) {
+ /* LCOV_EXCL_START */
+ ErrPrint("Can't init _dbus_set_watch_name %d", ret);
+ return ret;
+ /* LCOV_EXCL_STOP */
+ }
+
+ _set_remove_cb(remove_cb, data);
+
+ return SHORTCUT_ERROR_NONE;
+}
+
+EAPI void shortcut_unset_remove_cb(void)
+{
+ _unset_remove_cb();
+}
+
EAPI int shortcut_add_to_home(const char *name, shortcut_type type, const char *uri,
const char *icon, int allow_duplicate, result_cb_t result_cb, void *data)
{
return ret;
appid = _shortcut_get_pkgname_by_pid();
+ if (appid == NULL) {
+ /* LCOV_EXCL_START */
+ ErrPrint("Can't get appid");
+ return SHORTCUT_ERROR_IO_ERROR;
+ /* LCOV_EXCL_STOP */
+ }
+
item = malloc(sizeof(struct result_cb_item));
if (!item) {
/* LCOV_EXCL_START */
return ret;
appid = _shortcut_get_pkgname_by_pid();
+ if (appid == NULL) {
+ /* LCOV_EXCL_START */
+ ErrPrint("Can't get appid");
+ return SHORTCUT_ERROR_IO_ERROR;
+ /* LCOV_EXCL_STOP */
+ }
+
item = malloc(sizeof(struct result_cb_item));
if (!item) {
/* LCOV_EXCL_START */
return ret;
}
+EAPI int shortcut_remove_from_home(const char *name, result_cb_t result_cb, void *user_data)
+{
+ struct result_cb_item *item;
+ char *appid;
+ int ret;
+ GVariant *body;
+
+ if (name == NULL) {
+ ErrPrint("name is NULL.");
+ return SHORTCUT_ERROR_INVALID_PARAMETER;
+ }
+
+ ret = _dbus_init();
+ if (ret != SHORTCUT_ERROR_NONE) {
+ /* LCOV_EXCL_START */
+ ErrPrint("Can't init dbus %d", ret);
+ return ret;
+ /* LCOV_EXCL_STOP */
+ }
+
+ ret = _check_privilege();
+ if (ret != SHORTCUT_ERROR_NONE)
+ return ret;
+
+ appid = _shortcut_get_pkgname_by_pid();
+ if (appid == NULL) {
+ /* LCOV_EXCL_START */
+ ErrPrint("Can't get appid");
+ return SHORTCUT_ERROR_IO_ERROR;
+ /* LCOV_EXCL_STOP */
+ }
+
+ item = malloc(sizeof(struct result_cb_item));
+ if (!item) {
+ /* LCOV_EXCL_START */
+ if (appid)
+ free(appid);
+
+ ErrPrint("Heap: %d\n", errno);
+ return SHORTCUT_ERROR_OUT_OF_MEMORY;
+ /* LCOV_EXCL_STOP */
+ }
+
+ item->result_cb = result_cb;
+ item->result_internal_cb = NULL;
+ item->data = user_data;
+
+ body = g_variant_new("(iss)", getpid(), appid, name);
+
+ ret = _send_async_shortcut(body, item, "remove_shortcut");
+ if (ret != SHORTCUT_ERROR_NONE) {
+ /* LCOV_EXCL_START */
+ free(item);
+ item = NULL;
+ /* LCOV_EXCL_STOP */
+ }
+
+ if (appid)
+ free(appid);
+ if (body)
+ g_variant_unref(body);
+
+ return ret;
+}
+
EAPI int shortcut_get_list(const char *package_name, shortcut_list_cb list_cb, void *data)
{
GDBusMessage *reply = NULL;