summaryrefslogtreecommitdiff
path: root/lib-contact/ct-setting/src/CtSettingPopup.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib-contact/ct-setting/src/CtSettingPopup.cpp')
-rw-r--r--lib-contact/ct-setting/src/CtSettingPopup.cpp145
1 files changed, 145 insertions, 0 deletions
diff --git a/lib-contact/ct-setting/src/CtSettingPopup.cpp b/lib-contact/ct-setting/src/CtSettingPopup.cpp
new file mode 100644
index 0000000..a1dca2a
--- /dev/null
+++ b/lib-contact/ct-setting/src/CtSettingPopup.cpp
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "CtString.h"
+#include "ContactsDebug.h"
+#include "CtSettingPopup.h"
+
+
+CtSettingPopup::__ItemData::__ItemData() :
+ target(TargetStorage::DEVICE),
+ iconType(0)
+{
+
+}
+
+CtSettingPopup::CtSettingPopup(CtSettingData* settingData, const char* popupTitle) :
+ __settingData(settingData),
+ __popupTitle(popupTitle),
+ __resultCb(NULL),
+ __genlist(NULL),
+ __externalStorageId(0)
+{
+}
+
+bool CtSettingPopup::getSupportedStoragesCallback(int storageId, storage_type_e type, storage_state_e state, const char *path, void *userData)
+{
+ WENTER();
+ WPRET_VM(userData == NULL, false, "User data == NULL");
+
+ if (type == STORAGE_TYPE_EXTERNAL)
+ {
+ CtSettingPopup* settigPopup = static_cast<CtSettingPopup*>(userData);
+ settigPopup->__externalStorageId = storageId;
+ return false;
+ }
+
+ return true;
+}
+
+Evas_Object* CtSettingPopup::__createContent(Evas_Object *parent)
+{
+ // genlist class
+ Elm_Genlist_Item_Class* itc = elm_genlist_item_class_new();
+ WPRET_VM(!itc, NULL, "elm_genlist_item_class_new() failed");
+ itc->item_style = "type1";
+ itc->func.text_get = [](void* data, Evas_Object* obj, const char* part)->char*
+ {
+ __ItemData* itemData = static_cast<__ItemData*>(data);
+ if(!strcmp(part, "elm.text")) {
+ return strdup(itemData->label.c_str());
+ }
+
+ return NULL;
+ };
+
+ itc->func.del = [](void* data, Evas_Object* obj)
+ {
+ __ItemData* itemData = static_cast<__ItemData*>(data);
+ delete itemData;
+ };
+
+ __genlist = elm_genlist_add(parent);
+ elm_object_style_set( __genlist, "popup" );
+ elm_genlist_homogeneous_set(__genlist, EINA_TRUE);
+ elm_genlist_mode_set( __genlist, ELM_LIST_COMPRESS );
+ elm_scroller_content_min_limit( __genlist, EINA_FALSE, EINA_TRUE ); // Automatically pop-up height is calculated
+
+ elm_object_content_set(parent, __genlist);
+
+ int itemCount = 0;
+ __ItemData* itemData = NULL;
+
+ int error = storage_foreach_device_supported(getSupportedStoragesCallback, this);
+
+ if (error == STORAGE_ERROR_NONE)
+ {
+ storage_state_e state;
+ storage_get_state(__externalStorageId, &state);
+
+ if (state == STORAGE_STATE_MOUNTED)
+ {
+ itemData = new __ItemData();
+ itemData->label = V_("IDS_PB_OPT_SD_CARD");
+ itemData->target = TargetStorage::SD_CARD;
+ elm_genlist_item_append(__genlist, itc, itemData, NULL, ELM_GENLIST_ITEM_NONE, __onItemSelected, this);
+ itemCount++;
+ }
+ }
+
+ itemData = new __ItemData();
+ itemData->label = V_("IDS_PB_OPT_DEVICE");
+ itemData->target = TargetStorage::DEVICE;
+ elm_genlist_item_append(__genlist, itc, itemData, NULL, ELM_GENLIST_ITEM_NONE, __onItemSelected, this);
+ itemCount++;
+
+ elm_genlist_item_class_free(itc);
+
+ evas_object_show(__genlist);
+
+ return __genlist;
+
+}
+
+void CtSettingPopup::setOnResultCb(std::function<void (TargetStorage)> resultCb)
+{
+ __resultCb = resultCb;
+}
+
+Evas_Object* CtSettingPopup::onCreate( Evas_Object* parent, void* viewParam)
+{
+ WHIT();
+
+ setTitle(__popupTitle.c_str());
+
+ setContent([this](Evas_Object* parent)->Evas_Object* {
+ return __createContent(parent);
+ });
+
+ return WPopup::onCreate(parent, viewParam);
+}
+
+void CtSettingPopup::__onItemSelected(void* data, Evas_Object* obj, void* event_info)
+{
+ Elm_Object_Item *item = (Elm_Object_Item *)event_info;
+ __ItemData* itemData = (__ItemData*)elm_object_item_data_get(item);
+
+ CtSettingPopup* popup = static_cast<CtSettingPopup*>(data);
+ if( popup->__resultCb) {
+ popup->__resultCb(itemData->target);
+ }
+}