*
* The file contains the definition of _AppControlListener classes.
*/
-#include <EWebKit2.h>
#include <FAppAppControl.h>
#include <FBaseSysLog.h>
-#include <FBaseUtilStringTokenizer.h>
+#include <FBaseUtilStringUtil.h>
#include "FWebCtrl_AppControlListener.h"
_MediaSelectionListener::_MediaSelectionListener(void)
- : __isSelectionCompleted(false)
- , __pSelectedFiles(null)
+ : __pWebFrame(null)
+ , __pMediaAppControl(null)
{
}
-
-_MediaSelectionListener::~_MediaSelectionListener(void)
+void
+_MediaSelectionListener::Construct(Evas_Object* pWebFrame, Tizen::App::AppControl* pMediaAppControl)
{
-
+ __pWebFrame = pWebFrame;
+ std::unique_ptr<AppControl> pAppControl(pMediaAppControl);
+ __pMediaAppControl = std::move(pAppControl);
}
-const ArrayList*
-_MediaSelectionListener::GetSelectedFiles(void) const
+_MediaSelectionListener::~_MediaSelectionListener(void)
{
- return __pSelectedFiles.get();
-}
-
-bool
-_MediaSelectionListener::IsSelectionCompleted(void) const
-{
- return __isSelectionCompleted;
}
void
_MediaSelectionListener::OnAppControlCompleteResponseReceived(const Tizen::App::AppId& providerId, const Tizen::Base::String& operationId, Tizen::App::AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pAppData)
{
- __isSelectionCompleted = true;
SysTryReturnVoidResult(NID_WEB_CTRL, pAppData && providerId == L"tizen.filemanager" && operationId == L"http://tizen.org/appcontrol/operation/pick", E_INVALID_ARG, "[E_INVALID_ARG] Invalid arguments to _MediaSelectionListener::OnAppControlCompleted");
- std::unique_ptr<ArrayList, AllElementsDeleter> pSelectedFiles(new (std::nothrow) ArrayList());
- SysTryReturnVoidResult(NID_WEB_CTRL, pSelectedFiles.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-
- result r = pSelectedFiles->Construct();
- SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
+ Eina_List* pSelectedFileNames = null;
+ int fileCount = 0;
- String *pFiles = static_cast< String* >(const_cast< Object* >(pAppData->GetValue(String("path"))));
- SysTryReturnVoidResult(NID_WEB_CTRL, pFiles, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ ArrayList *pSelectedFiles = dynamic_cast< ArrayList* >(const_cast< Object* >(pAppData->GetValue(String("http://tizen.org/appcontrol/data/selected"))));
+ SysTryCatch(NID_WEB_CTRL, pSelectedFiles, , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
- StringTokenizer strTok(*pFiles, L";");
- String token;
+ fileCount = pSelectedFiles->GetCount();
- while (strTok.HasMoreTokens())
+ for (int i = 0; i < fileCount; i++)
{
- strTok.GetNextToken(token);
- std::unique_ptr<String> pFile(new (std::nothrow) String(token));
- SysTryReturnVoidResult(NID_WEB_CTRL, pFile, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ std::unique_ptr<String> pFile((String*)pSelectedFiles->GetAt(i));
+ SysTryCatch(NID_WEB_CTRL, pFile, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
- r = pSelectedFiles->Add(*pFile);
- SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
- pFile.release();
+ std::unique_ptr<ByteBuffer> pByteBuf(StringUtil::StringToUtf8N(*pFile));
+ SysTryCatch(NID_WEB_CTRL, pByteBuf.get(), , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+ pSelectedFileNames = eina_list_append(pSelectedFileNames, strdup((const char*)pByteBuf->GetPointer()));
+ SysTryCatch(NID_WEB_CTRL, pSelectedFileNames, , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
}
- __pSelectedFiles = std::move(pSelectedFiles);
+ ewk_view_open_panel_reply(__pWebFrame, pSelectedFileNames, EINA_TRUE);
+ eina_list_free(pSelectedFileNames);
+
+ delete this;
+ return;
+
+CATCH:
+ ewk_view_open_panel_reply(__pWebFrame, null, EINA_TRUE);
+ eina_list_free(pSelectedFileNames);
+ delete this;
}
Eina_Bool
OnSelectUploadFile(Evas_Object* pView, Eina_Bool multipleFile, Eina_List* pAcceptTypes, const char* pCapture, void* pUserData)
{
- Eina_Bool ret = EINA_FALSE;
- Eina_List* pSelectedFileNames = null;
String isMultipleSelection(L"single");
+ result r = E_SUCCESS;
+
+ HashMap dataList;
+ String mode(L"selectionType");
+ String type(L"type");
+ _AppControlImpl* pMediaAppControlImpl = null;
+
+ int itemCount = 0;
+ String fileType = L"all";
if (multipleFile)
{
isMultipleSelection.Append(L"multiple");
}
+ std::unique_ptr<AppControl> pMediaAppControl(_AppManagerImpl::FindAppControlN(L"tizen.filemanager", L"http://tizen.org/appcontrol/operation/pick"));
+ SysTryReturn(NID_WEB_CTRL, pMediaAppControl.get(), EINA_TRUE, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
std::unique_ptr<_MediaSelectionListener> pMediaListener(new (std::nothrow) _MediaSelectionListener());
- SysTryCatch(NID_WEB_CTRL, pMediaListener.get(), , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ SysTryReturn(NID_WEB_CTRL, pMediaListener.get(), EINA_TRUE, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
- {
- int itemCount = eina_list_count(pAcceptTypes);
- String fileType = L"all";
+ pMediaListener->Construct(pView, pMediaAppControl.get());
+
+ itemCount = eina_list_count(pAcceptTypes);
- if (itemCount == 1)
+ if (itemCount == 1)
+ {
+ String item((char*)eina_list_nth(pAcceptTypes, 0));
+ if (item.StartsWith("image/",0))
{
- String item((char*)eina_list_nth(pAcceptTypes, 0));
- if (item.StartsWith("image/",0))
- {
- fileType = L"image";
- }
- else if (item.StartsWith("audio/",0))
- {
- fileType = L"audio";
- }
- else if (item.StartsWith("video/",0))
- {
- fileType = L"video";
- }
+ fileType = L"image";
}
-
- HashMap dataList;
- result r = dataList.Construct();
- SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
-
- String mode(L"selectionType");
- r = dataList.Add(mode, isMultipleSelection);
- SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
-
- String type(L"type");
- r = dataList.Add(type, fileType);
- SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
-
- std::unique_ptr<AppControl> pMediaAppControl(_AppManagerImpl::FindAppControlN(L"tizen.filemanager", L"http://tizen.org/appcontrol/operation/pick"));
- SysTryCatch(NID_WEB_CTRL, pMediaAppControl.get(), r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
-
- _AppControlImpl* pMediaAppControlImpl = _AppControlImpl::GetInstance(*pMediaAppControl);
- r = pMediaAppControlImpl->Start(null, null, &dataList, pMediaListener.get());
- SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
-
- while (true)
+ else if (item.StartsWith("audio/",0))
{
- if (pMediaListener->IsSelectionCompleted())
- {
- const ArrayList* pSelectedFiles = pMediaListener->GetSelectedFiles();
- SysTryCatch(NID_WEB_CTRL, pSelectedFiles, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
-
- int fileCount = pSelectedFiles->GetCount();
+ fileType = L"audio";
+ }
+ else if (item.StartsWith("video/",0))
+ {
+ fileType = L"video";
+ }
+ }
- for (int i = 0; i < fileCount; i++)
- {
- String* pFile = (String*)pSelectedFiles->GetAt(i);
- SysTryCatch(NID_WEB_CTRL, pFile, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
+ r = dataList.Construct();
+ SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
- std::unique_ptr<ByteBuffer> pByteBuf(StringUtil::StringToUtf8N(*pFile));
- SysTryCatch(NID_WEB_CTRL, pByteBuf.get(), r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
+ r = dataList.Add(mode, isMultipleSelection);
+ SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
- pSelectedFileNames = eina_list_append(pSelectedFileNames, strdup((const char*)pByteBuf->GetPointer()));
- }
+ r = dataList.Add(type, fileType);
+ SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
- ret = EINA_TRUE;
- break;
- }
+ pMediaAppControlImpl = _AppControlImpl::GetInstance(*pMediaAppControl.get());
+ r = pMediaAppControlImpl->Start(null, null, &dataList, pMediaListener.get());
+ SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
- ecore_main_loop_iterate();
- }
+ pMediaListener.release();
+ pMediaAppControl.release();
- ewk_view_open_panel_reply(pView, pSelectedFileNames, ret);
- return EINA_TRUE;
- }
+ return EINA_TRUE;
CATCH:
- ewk_view_open_panel_reply(pView, null, ret);
- eina_list_free(pSelectedFileNames);
+ ewk_view_open_panel_reply(pView, null, EINA_TRUE);
return EINA_TRUE;
}