From d21a52de4fa7add91bae6d796711cf1d7dbfc13c Mon Sep 17 00:00:00 2001 From: Bang Kwang min Date: Tue, 28 Aug 2012 09:41:06 +0900 Subject: [PATCH] Code Sync with Private GIT changes) Change notify winset to selectioninfo winset Apply changes of capi-web-url-download Resolve a prevent defect Enable to use notification of download CAPI Show the application in case of default service operation --- CMakeLists.txt | 11 +++++ packaging/org.tizen.download-manager.spec | 1 + src/download-manager-downloadItem.cpp | 76 ++++++++++++++++++++--------- src/download-manager-items.cpp | 4 +- src/download-manager-view.cpp | 66 ++++++++++++------------- src/download-manager-viewItem.cpp | 6 ++- src/include/download-manager-downloadItem.h | 3 ++ src/include/download-manager-view.h | 3 +- src/include/download-manager-viewItem.h | 47 +++++++++++++++--- src/main.cpp | 4 ++ 10 files changed, 152 insertions(+), 69 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3322587..c367539 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,7 @@ SET(DBDATADIR "${PREFIX}/data/db") SET(LOCALEDIR "${RESDIR}/locale") SET(ICONDIR "/opt/share/icons/default/small/") SET(HISTORYDB ".download-history.db") +SET(EDJE_DIR "${RESDIR}/edje") IF("${CMAKE_BUILD_TYPE}" STREQUAL "") SET(CMAKE_BUILD_TYPE "Release") @@ -56,6 +57,7 @@ pkg_check_modules(pkgs REQUIRED edje icu-i18n xdgmime + edje ) FIND_LIBRARY(LIB_DL dl) @@ -98,16 +100,25 @@ ADD_DEFINITIONS("-DDBDATADIR=\"${DBDATADIR}\"") ADD_DEFINITIONS("-DLOCALEDIR=\"${LOCALEDIR}\"") ADD_DEFINITIONS("-DICONDIR=\"${ICONDIR}\"") ADD_DEFINITIONS("-DHISTORYDB=\"${HISTORYDB}\"") +ADD_DEFINITIONS("-DEDJE_DIR=\"${EDJE_DIR}\"") ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} ${LIB_DL}) +ADD_CUSTOM_TARGET(download-manager.edj + COMMAND edje_cc -id ${CMAKE_SOURCE_DIR}/images + ${CMAKE_SOURCE_DIR}/res/download-manager.edc + ${CMAKE_BINARY_DIR}/res/download-manager.edj + DEPENDS ${CMAKE_SOURCE_DIR}/res/download-manager.edc) +ADD_DEPENDENCIES(${PROJECT_NAME} download-manager.edj) + INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${BINDIR}) INSTALL(DIRECTORY DESTINATION ${DATADIR}) INSTALL(DIRECTORY DESTINATION ${DBDATADIR}) INSTALL(FILES ${CMAKE_BINARY_DIR}/res/${PKGNAME}.xml DESTINATION /opt/share/packages) INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/res/images DESTINATION ${RESDIR}) +INSTALL(FILES ${CMAKE_BINARY_DIR}/res/download-manager.edj DESTINATION ${EDJE_DIR}) # i18n ADD_SUBDIRECTORY(po) diff --git a/packaging/org.tizen.download-manager.spec b/packaging/org.tizen.download-manager.spec index 6935329..54a1249 100644 --- a/packaging/org.tizen.download-manager.spec +++ b/packaging/org.tizen.download-manager.spec @@ -55,6 +55,7 @@ chmod 660 /opt/apps/org.tizen.download-manager/data/db/.download-history.db-jour /opt/apps/org.tizen.download-manager/bin/* /opt/apps/org.tizen.download-manager/data /opt/apps/org.tizen.download-manager/res/* +/opt/apps/org.tizen.download-manager/res/edje/* /opt/share/packages/org.tizen.download-manager.xml %changelog diff --git a/src/download-manager-downloadItem.cpp b/src/download-manager-downloadItem.cpp index e536790..e7b87a7 100644 --- a/src/download-manager-downloadItem.cpp +++ b/src/download-manager-downloadItem.cpp @@ -24,6 +24,7 @@ #include #include "download-manager-downloadItem.h" #include "download-manager-common.h" +#include "app_service.h" static Ecore_Pipe *ecore_pipe = NULL; static void __ecore_cb_pipe_update(void *data, void *buffer, unsigned int nbyte); @@ -135,6 +136,7 @@ void CbData::updateDownloadItem() DP_LOGD("registeredFilePath[%s]", m_registeredFilePath.c_str()); downloadItem->setRegisteredFilePath(m_registeredFilePath); } + downloadItem->destroyHandle(); break; case DA_CB::STOPPED: if (m_error != URL_DOWNLOAD_ERROR_NONE) { @@ -143,6 +145,7 @@ void CbData::updateDownloadItem() } else { downloadItem->setState(DL_ITEM::CANCELED); } + downloadItem->destroyHandle(); break; default: break; @@ -184,6 +187,10 @@ DownloadItem::DownloadItem(auto_ptr request) , m_fileSize(0) , m_downloadType(DL_TYPE::HTTP_DOWNLOAD) { +} + +void DownloadItem::createHandle() +{ int ret = url_download_create(&m_download_handle); if (ret != URL_DOWNLOAD_ERROR_NONE) { DP_LOGE("Fail to create download handle : [%d]", ret); @@ -219,19 +226,49 @@ DownloadItem::DownloadItem(auto_ptr request) DP_LOGE("Fail to set progress cb : [%d]", ret); return; } + + service_h service_handle; + ret = service_create(&service_handle); + if (ret < 0) { + DP_LOGE("Fail to create service handle"); + return; + } + + ret = service_set_package(service_handle, PACKAGE_NAME); + if (ret < 0) { + DP_LOGE("Fail to set package name"); + return; + } + ret = url_download_set_notification(m_download_handle, service_handle); + if (ret != URL_DOWNLOAD_ERROR_NONE) { + DP_LOGE("Fail to set notification : [%d]", ret); + return; + } + ret = service_destroy(service_handle); + if (ret < 0) { + DP_LOGE("Fail to create service handle"); + return; + } } DownloadItem::~DownloadItem() { DP_LOGD_FUNC(); + destroyHandle(); +} + +void DownloadItem::destroyHandle() +{ if (!m_download_handle) return; + DP_LOGD("download handle[%p]", m_download_handle); url_download_unset_started_cb(m_download_handle); url_download_unset_completed_cb(m_download_handle); url_download_unset_paused_cb(m_download_handle); url_download_unset_stopped_cb(m_download_handle); url_download_unset_progress_cb(m_download_handle); url_download_destroy(m_download_handle); + m_download_handle = NULL; } void DownloadItem::started_cb(url_download_h download, const char *name, @@ -311,40 +348,34 @@ void DownloadItem::progress_cb(url_download_h download, unsigned long long recei void DownloadItem::start(bool isRetry) { int ret = 0; - int id = 0; DP_LOGD_FUNC(); - if (!m_download_handle) { - DP_LOGE("handle is NULL"); + if (m_download_handle) { + destroyHandle(); + } + createHandle(); + + ret = url_download_set_url(m_download_handle, + m_aptr_request->getUrl().c_str()); + if (ret != URL_DOWNLOAD_ERROR_NONE) { + DP_LOGE("Fail to set url : [%d]", ret); m_state = DL_ITEM::FAILED; m_errorCode = ERROR::ENGINE_FAIL; notify(); return; } - - if (!isRetry) { - ret = url_download_set_url(m_download_handle, - m_aptr_request->getUrl().c_str()); + if (!m_aptr_request->getCookie().empty()) { + ret = url_download_add_http_header_field(m_download_handle, + "Cookie", m_aptr_request->getCookie().c_str()); if (ret != URL_DOWNLOAD_ERROR_NONE) { - DP_LOGE("Fail to set url : [%d]", ret); + DP_LOGE("Fail to set cookie : [%d]", ret); m_state = DL_ITEM::FAILED; m_errorCode = ERROR::ENGINE_FAIL; notify(); return; } - if (!m_aptr_request->getCookie().empty()) { - ret = url_download_add_http_header_field(m_download_handle, - "Cookie", m_aptr_request->getCookie().c_str()); - if (ret != URL_DOWNLOAD_ERROR_NONE) { - DP_LOGE("Fail to set cookie : [%d]", ret); - m_state = DL_ITEM::FAILED; - m_errorCode = ERROR::ENGINE_FAIL; - notify(); - return; - } - } } - ret = url_download_start(m_download_handle, &id); - DP_LOGD("URL download handle : handle[%p]id[%d]", m_download_handle, id); + ret = url_download_start(m_download_handle, &m_download_id); + DP_LOGD("URL download handle : handle[%p]id[%d]", m_download_handle, m_download_id); if (ret != URL_DOWNLOAD_ERROR_NONE) { m_state = DL_ITEM::FAILED; @@ -431,8 +462,7 @@ void DownloadItem::suspend() void DownloadItem::resume() { - int id = 0; - int ret = url_download_start(m_download_handle, &id); + int ret = url_download_start(m_download_handle, &m_download_id); if (ret != URL_DOWNLOAD_ERROR_NONE) { DP_LOGE("Fail to resume download : handle[%p] err[%d]", m_download_handle, ret); diff --git a/src/download-manager-items.cpp b/src/download-manager-items.cpp index 4e11734..e29879c 100644 --- a/src/download-manager-items.cpp +++ b/src/download-manager-items.cpp @@ -29,10 +29,10 @@ void Items::attachItem(Item *item) void Items::detachItem(Item *item) { vector::iterator it; - for (it = m_items.begin() ; it < m_items.end() ; it++) { + for (it = m_items.begin(); it < m_items.end(); it++) { if (*it == item) { - m_items.erase(it); delete item; + m_items.erase(it); } } } diff --git a/src/download-manager-view.cpp b/src/download-manager-view.cpp index b91e12a..9e52983 100644 --- a/src/download-manager-view.cpp +++ b/src/download-manager-view.cpp @@ -43,13 +43,13 @@ DownloadView::DownloadView(void) , eoCbItemDelete(NULL) , eoCbItemCancel(NULL) , eoCbItemEmpty(NULL) + , eoNotifyTimer(NULL) , eoBoxLayout(NULL) , eoBox(NULL) , eoDldList(NULL) , eoPopup(NULL) , eoSelectAllLayout(NULL) , eoAllCheckedBox(NULL) - , eoNotifyInfo(NULL) , eoNotifyInfoLayout(NULL) , m_allChecked(EINA_FALSE) #ifndef _TIZEN_PUBLIC @@ -99,6 +99,7 @@ void DownloadView::destroy() { DownloadEngine &engine = DownloadEngine::getInstance(); engine.deinitEngine(); + ecore_timer_del(eoNotifyTimer); } void DownloadView::show() @@ -265,11 +266,15 @@ void DownloadView::createBox() { DP_LOGD_FUNC(); eoBoxLayout = elm_layout_add(eoNaviBar); - elm_layout_theme_set(eoBoxLayout, "layout", "application", "noindicator"); + elm_layout_file_set(eoBoxLayout, + "/opt/apps/com.samsung.download-manager/res/edje/download-manager.edj", + "download/selectioninfo"); + evas_object_size_hint_weight_set(eoBoxLayout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(eoBoxLayout, EVAS_HINT_FILL, EVAS_HINT_FILL); eoBox = elm_box_add(eoBoxLayout); - elm_object_part_content_set(eoBoxLayout, "elm.swallow.content", eoBox ); + elm_object_part_content_set(eoBoxLayout, "gen.swallow.contents", eoBox); evas_object_show(eoBox); evas_object_show(eoBoxLayout); @@ -773,47 +778,30 @@ void DownloadView::handleCheckedState() void DownloadView::createNotifyInfo() { DP_LOGD_FUNC(); - eoNotifyInfo = elm_notify_add(eoBoxLayout); - elm_notify_orient_set(eoNotifyInfo, ELM_NOTIFY_ORIENT_BOTTOM); - evas_object_size_hint_weight_set(eoNotifyInfo, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(eoNotifyInfo, EVAS_HINT_FILL, EVAS_HINT_FILL); - evas_object_event_callback_add(eoNotifyInfo, EVAS_CALLBACK_SHOW, showNotifyInfoCB, eoLayout); - evas_object_event_callback_add(eoNotifyInfo, EVAS_CALLBACK_HIDE, hideNotifyInfoCB, eoLayout); - eoNotifyInfoLayout = elm_layout_add(eoNotifyInfo); - elm_object_content_set(eoNotifyInfo, eoNotifyInfoLayout); + eoNotifyInfoLayout = elm_layout_add(eoBoxLayout); + elm_object_part_content_set(eoBoxLayout, "sel.swallow.contents", + eoNotifyInfoLayout); + evas_object_size_hint_weight_set(eoNotifyInfoLayout, + EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(eoNotifyInfoLayout, + EVAS_HINT_FILL, EVAS_HINT_FILL); } void DownloadView::showNotifyInfo(int type, int selectedCount) { -#ifndef _TIZEN_PUBLIC - int angle = 0; -#endif string buf; DP_LOGD_FUNC(); -#ifndef _TIZEN_PUBLIC - angle = elm_win_rotation_get(eoWindow); -#endif - if (selectedCount == 0) { destroyNotifyInfo(); return; } - if (!eoNotifyInfo) + if (!eoNotifyInfoLayout) createNotifyInfo(); -#ifndef _TIZEN_PUBLIC - if (angle == 0 || angle == 180) - elm_layout_theme_set(eoNotifyInfoLayout, "standard", "selectioninfo", - "vertical/bottom_12"); - else - elm_layout_theme_set(eoNotifyInfoLayout, "standard", "selectioninfo", - "horizontal/bottom_12"); -#else elm_layout_theme_set(eoNotifyInfoLayout, "standard", "selectioninfo", - "vertical/bottom_12"); -#endif + "default"); buf.append(" "); if (type == DOWNLOAD_NOTIFY_SELECTED) { stringstream countStr; @@ -824,19 +812,29 @@ void DownloadView::showNotifyInfo(int type, int selectedCount) buf.append(")"); } else if (type == DOWNLOAD_NOTIFY_DELETED) { buf = S_("IDS_COM_POP_DELETED"); - elm_notify_timeout_set(eoNotifyInfo, 3); + if (eoNotifyTimer) { + ecore_timer_del(eoNotifyTimer); + eoNotifyTimer = NULL; + } + eoNotifyTimer = ecore_timer_add(3, deletedNotifyTimerCB, NULL); } - edje_object_part_text_set(_EDJ(eoNotifyInfoLayout), "elm.text", buf.c_str()); - evas_object_show(eoNotifyInfo); + elm_object_part_text_set(eoNotifyInfoLayout, "elm.text", buf.c_str()); + elm_object_signal_emit(eoBoxLayout, "show,selection,info", "elm"); + evas_object_show(eoNotifyInfoLayout); +} + +Eina_Bool DownloadView::deletedNotifyTimerCB(void *data) +{ + DownloadView& view = DownloadView::getInstance(); + view.destroyNotifyInfo(); + return ECORE_CALLBACK_RENEW; } void DownloadView::destroyNotifyInfo() { DP_LOGD_FUNC(); destroyEvasObj(eoNotifyInfoLayout); - destroyEvasObj(eoNotifyInfo); eoNotifyInfoLayout = NULL; - eoNotifyInfo = NULL; } /* Static callback function */ diff --git a/src/download-manager-viewItem.cpp b/src/download-manager-viewItem.cpp index 1d559fe..fd63d99 100644 --- a/src/download-manager-viewItem.cpp +++ b/src/download-manager-viewItem.cpp @@ -416,7 +416,7 @@ const char *ViewItem::getHumanFriendlyBytesStr(unsigned long int bytes, unitBytes = 1 << (10*unit); doubleTypeBytes = ((double)bytes / (double)(unitBytes)); // FIXME following code should be broken into another function, but leave it now to save function call time.s - char str[32] = {0}; + char str[64] = {0}; if (progressOption && fileSize() != 0) { /* using fixed point arithmetic to avoid floating point arithmetic */ const int fixed_point = 6; @@ -437,7 +437,9 @@ const char *ViewItem::getHumanFriendlyBytesStr(unsigned long int bytes, else snprintf(str, sizeof(str), "%.2f %s", doubleTypeBytes, unitStr[unit]); } - return string(str).c_str(); + str[63] = '\0'; + string temp = string(str); + return temp.c_str(); } unsigned long int ViewItem::receivedFileSize() diff --git a/src/include/download-manager-downloadItem.h b/src/include/download-manager-downloadItem.h index 6a3c7b5..be85e2f 100644 --- a/src/include/download-manager-downloadItem.h +++ b/src/include/download-manager-downloadItem.h @@ -56,6 +56,8 @@ public: void retry(void); void suspend(void); void resume(void); + void createHandle(void); + void destroyHandle(void); inline void *downloadHandle(void) { return (void *)m_download_handle;} inline void setDownloadHandle(url_download_h handle) { m_download_handle = handle; } @@ -119,6 +121,7 @@ private: string m_registeredFilePath; string m_mimeType; DL_TYPE::TYPE m_downloadType; + int m_download_id; }; class DownloadEngine { diff --git a/src/include/download-manager-view.h b/src/include/download-manager-view.h index bb7d20f..b46283d 100644 --- a/src/include/download-manager-view.h +++ b/src/include/download-manager-view.h @@ -92,6 +92,7 @@ private: static void genlistClickCB(void *data, Evas_Object *obj, void *event_info); static void cancelClickCB(void *data, Evas_Object *obj, void *event_info); static void errPopupResponseCB(void *data, Evas_Object *obj, void *event_info); + static Eina_Bool deletedNotifyTimerCB(void *data); private: DownloadView(); @@ -155,13 +156,13 @@ private: Elm_Object_Item *eoCbItemDelete; Elm_Object_Item *eoCbItemCancel; Elm_Object_Item *eoCbItemEmpty; + Ecore_Timer *eoNotifyTimer; Evas_Object *eoBoxLayout; Evas_Object *eoBox; Evas_Object *eoDldList; Evas_Object *eoPopup; Evas_Object *eoSelectAllLayout; Evas_Object *eoAllCheckedBox; - Evas_Object *eoNotifyInfo; Evas_Object *eoNotifyInfoLayout; Elm_Genlist_Item_Class dldGenlistGroupStyle; Eina_Bool m_allChecked; diff --git a/src/include/download-manager-viewItem.h b/src/include/download-manager-viewItem.h index 67890ce..cd7d91d 100644 --- a/src/include/download-manager-viewItem.h +++ b/src/include/download-manager-viewItem.h @@ -35,7 +35,10 @@ public: ~ViewItem(); static void create(Item *item); void destroy(void); - inline void deleteFromDB(void) { m_item->deleteFromDB(); } + inline void deleteFromDB(void) { + if (m_item) + m_item->deleteFromDB(); + } inline void setItem(Item *item) { m_item = item; } static void updateCB(void *); @@ -69,12 +72,42 @@ public: { return &dldHistoryGenlistStyle; } inline Elm_Genlist_Item_Class *elmGenlistFailedItemClass(void) { return &dldGenlistSlideStyle; } - inline ITEM::STATE state(void) { return m_item->state(); } - inline const char* stateStr(void) { return m_item->stateStr(); } - inline bool isFinished(void) { return m_item->isFinished(); } - inline bool isFinishedWithErr(void) { return m_item->isFinishedWithErr(); } - inline bool isPreparingDownload(void) { return m_item->isPreparingDownload(); } - inline bool isCompletedDownload(void) { return m_item->isCompletedDownload(); } + inline ITEM::STATE state(void) { + if (m_item) + return m_item->state(); + else + return ITEM::IDLE; + } + inline const char* stateStr(void) { + if (m_item) + return m_item->stateStr(); + else + return NULL; + } + inline bool isFinished(void) { + if (m_item) + return m_item->isFinished(); + else + return false; + } + inline bool isFinishedWithErr(void) { + if (m_item) + return m_item->isFinishedWithErr(); + else + return false; + } + inline bool isPreparingDownload(void) { + if (m_item) + return m_item->isPreparingDownload(); + else + return false; + } + inline bool isCompletedDownload(void) { + if (m_item) + return m_item->isCompletedDownload(); + else + return false; + } unsigned long int receivedFileSize(void); unsigned long int fileSize(void); diff --git a/src/main.cpp b/src/main.cpp index e80f3d4..f4dfce8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -217,6 +217,10 @@ static void __app_service(service_h s, void *data) return; } + if (s_url.empty()) { + view.activateWindow(); + return; + } DownloadRequest request(s_url, s_cookie); Item::create(request); #ifndef _SILENT_LAUNCH -- 2.7.4