Further improvements in autofill forms 20/88020/7
authorKamil Nowac <k.nowac@samsung.com>
Mon, 12 Sep 2016 13:11:42 +0000 (15:11 +0200)
committerKamil Nowa? <k.nowac@samsung.com>
Fri, 16 Sep 2016 10:07:06 +0000 (03:07 -0700)
[Issue]    http://suprem.sec.samsung.net/jira/browse/TWF-2046
[Problem]  Profile name was not updated
[Solution] Changed the way of getting the id, and
           added variable for actual name
[Verify]   Add autofill profile and save it
           It should be visible in the list
           and should be editable

Change-Id: I651e88e6292dc93e969a8690a75a59d225ffa1f0

services/SettingsUI/SettingsAFCreator.cpp
services/SettingsUI/SettingsAFCreator.h
services/SettingsUI/SettingsAFProfile.cpp
services/SettingsUI/SettingsAFProfile.h
services/SettingsUI/SettingsPrettySignalConnector.h

index e57fd9f93b1af60a092b9519ab969679b1ddf5cb..5f2c3a2b777cc7fba4e963365170836d2a0e3532 100644 (file)
@@ -34,6 +34,7 @@ inline std::string _trim(std::string& s, const std::string& drop = TRIM_SPACE)
 
 SettingsAFCreator::SettingsAFCreator(Evas_Object* parent, bool profile_exists)
     : m_scroller(nullptr)
+    , m_box(nullptr)
     , m_editErrorcode(update_error_none)
     , m_saveErrorcode(save_error_none)
     , m_editFieldItemClass(nullptr)
@@ -42,7 +43,6 @@ SettingsAFCreator::SettingsAFCreator(Evas_Object* parent, bool profile_exists)
     , m_profile_exists(profile_exists)
 {
     init(parent);
-    loadProfile();
 };
 
 SettingsAFCreator::~SettingsAFCreator()
@@ -55,8 +55,19 @@ bool SettingsAFCreator::loadProfile(void)
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
 
     Ewk_Autofill_Profile* profile = nullptr;
-    if (m_profile_exists)
-        profile = ewk_context_form_autofill_profile_get(m_ewkContext, 1);
+    if (m_profile_exists) {
+        void* item_data(nullptr);
+        Eina_List* list(nullptr);
+        Eina_List* entire_item_list(
+            ewk_context_form_autofill_profile_get_all(ewk_context_default_get()));
+
+        EINA_LIST_FOREACH(entire_item_list, list, item_data) {
+            if (item_data) {
+                profile = static_cast<Ewk_Autofill_Profile*>(item_data);
+                break;
+            }
+        }
+    }
 
     createNewAutoFillFormItem(profile);
 
@@ -67,9 +78,9 @@ void SettingsAFCreator::createNewAutoFillFormItem(Ewk_Autofill_Profile* profile)
 {
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
     if (!profile)
-        m_item  = std::shared_ptr<AutoFillFormItem>(new AutoFillFormItem(nullptr));
+        m_item  = std::make_shared<AutoFillFormItem>(nullptr);
     else {
-        AutoFillFormItemData* item_data = new AutoFillFormItemData;
+        auto item_data = new AutoFillFormItemData;
         if (!item_data) {
             BROWSER_LOGE("Malloc failed to get item_data");
             return;
@@ -89,7 +100,7 @@ void SettingsAFCreator::createNewAutoFillFormItem(Ewk_Autofill_Profile* profile)
         item_data->activation = false;
         item_data->compose_mode = profile_edit;
 
-        m_item = std::shared_ptr<AutoFillFormItem>(new AutoFillFormItem(item_data));
+        m_item = std::make_shared<AutoFillFormItem>(item_data);
         delete item_data;
         item_data = nullptr;
         return;
@@ -98,6 +109,8 @@ void SettingsAFCreator::createNewAutoFillFormItem(Ewk_Autofill_Profile* profile)
 
 bool SettingsAFCreator::populateLayout(Evas_Object* parent)
 {
+    loadProfile();
+
     m_entryLimitSize.max_char_count = 0;
     m_entryLimitSize.max_byte_count = AUTO_FILL_FORM_ENTRY_MAX_COUNT;
     m_edjFilePath = EDJE_DIR;
@@ -325,6 +338,7 @@ Eina_Bool SettingsAFCreator::applyEntryData(void)
     std::string full_name_str = std::string(full_name);
     full_name_str = _trim(full_name_str);
     full_name = full_name_str.c_str();
+    SPSC.setProfileName(full_name);
 
     if (full_name && strlen(full_name) && !isEntryHasOnlySpace(full_name))
         m_item->setName(full_name);
index 90b0181532b8c743b58d49e8099622b796a0dee6..6ded32efac35602f8b6475633ce4ad5618e70d31 100644 (file)
@@ -79,8 +79,8 @@ private:
     void addItems();
 protected:
     std::map<unsigned, ItemData> m_buttonsMap;
-    Evas_Object *m_scroller;
-    Evas_Object *m_box;
+    Evas_Objectm_scroller;
+    Evas_Objectm_box;
 
     profileEditErrorcode m_editErrorcode;
     profileSaveErrorcode m_saveErrorcode;
index 2e57866510dceddba8f14a3feaa99bad6eb96de2..5771202a95216c337b67ca092fd4d83056a34509 100644 (file)
@@ -22,8 +22,11 @@ namespace base_ui{
 
 SettingsAFProfile::SettingsAFProfile(Evas_Object* parent)
     : m_profile(nullptr)
+    , m_itemData(nullptr)
+    , m_profileName(std::string())
 {
     init(parent);
+    SPSC.setProfileName.connect([this](std::string name){m_profileName = name;});
 };
 
 SettingsAFProfile::~SettingsAFProfile()
@@ -34,28 +37,38 @@ SettingsAFProfile::~SettingsAFProfile()
 void SettingsAFProfile::updateButtonMap()
 {
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
-    // TODO Fix profile name update after profile saving
     ItemData profileName;
-    m_profile = ewk_context_form_autofill_profile_get(ewk_context_default_get(), 1);
+    void* item_data(nullptr);
+    Eina_List* list(nullptr);
+    Eina_List* entire_item_list(
+        ewk_context_form_autofill_profile_get_all(ewk_context_default_get()));
+
+    // ID for the item is not always 1 so we need to return the first existing one
+    EINA_LIST_FOREACH(entire_item_list, list, item_data) {
+        if (item_data) {
+            m_profile = static_cast<Ewk_Autofill_Profile*>(item_data);
+            break;
+        }
+    }
     if (!m_profile)
         profileName.buttonText = _(Translations::SettingsAutoFillProfileSetMyProfile.c_str());
-    else
+    else if (m_profileName.empty())
         profileName.buttonText = ewk_autofill_profile_data_get(m_profile, EWK_PROFILE_NAME);
-    m_buttonsMap[0] = profileName;
+    else
+        profileName.buttonText = m_profileName;
+    m_itemData = std::make_shared<ItemData>(profileName);
 }
 
 bool SettingsAFProfile::populateList(Evas_Object* genlist)
 {
     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
-    updateButtonMap();
 
     m_naviframe->setLeftButtonVisible(false);
     m_naviframe->setRightButtonVisible(false);
     m_naviframe->setPrevButtonVisible(true);
     m_naviframe->setTitle(_(Translations::SettingsAutoFillProfileTitle.c_str()));
 
-    elm_genlist_clear(genlist);
-    appendGenlist(genlist, m_setting_item_class, &m_buttonsMap[0], _select_profile_cb);
+    appendGenlist(genlist, m_setting_item_class, m_itemData.get(), _select_profile_cb);
     return true;
 }
 
index 8ae640d6dc7a78e8ff472878ad934879b1891c08..4e8e7de665b09a6a802e0003e19db5572bde939f 100644 (file)
@@ -45,8 +45,9 @@ public:
     virtual void updateButtonMap();
     static void _select_profile_cb(void* data, Evas_Object*, void*);
 protected:
-    std::map<unsigned, ItemData> m_buttonsMap;
     Ewk_Autofill_Profile* m_profile;
+    std::shared_ptr<ItemData> m_itemData;
+    std::string m_profileName;
 };
 
 }
index 4031ee1d579f92f9894a9b910d022faab4f64f72..b1d66fc70b0d59d49052dd2bbab3b3d68efc11d8 100644 (file)
@@ -73,6 +73,7 @@ public:
     B_SIG<void (int)> setSearchEngineSubText;
     B_SIG<void (int)> setContentDestination;
     B_SIG<void ()> showTextPopup;
+    B_SIG<void (std::string)> setProfileName;
 
 private:
     SettingsPrettySignalConnector(){};