TizenRefApp-5806 refactored mechanism of popup-management to get read of dependencies... 41/60041/2
authorAndrey Klimenko <and.klimenko@samsung.com>
Mon, 22 Feb 2016 16:47:27 +0000 (18:47 +0200)
committerAndrey Klimenko <and.klimenko@samsung.com>
Tue, 23 Feb 2016 09:37:56 +0000 (11:37 +0200)
Change-Id: Ib0b9618e613334c4dd2bc989a509fe65ccf26ecc
Signed-off-by: Andrey Klimenko <and.klimenko@samsung.com>
src/Common/View/inc/PopupList.h
src/Common/View/inc/PopupListItem.h [new file with mode: 0644]
src/Common/View/src/PopupList.cpp
src/Common/View/src/PopupListItem.cpp [new file with mode: 0644]
src/Conversation/Main/Controller/inc/Conversation.h
src/Conversation/Main/Controller/inc/PopupRecipientListItem.h [new file with mode: 0644]
src/Conversation/Main/Controller/src/Conversation.cpp
src/Conversation/Main/Controller/src/PopupRecipientListItem.cpp [new file with mode: 0644]

index 04d5fcc..b2c40a9 100644 (file)
 
 #include "Popup.h"
 #include "ListView.h"
+#include "PopupListItem.h"
 
 namespace Msg
 {
-    class PopupList;
-    class PopupListItem;
-    typedef void (*PopupListItemPressedCb)(PopupListItem &item, void *userData);
-
-    #define POPUPLIST_ITEM_PRESSED_CB(ClassName, method) [](PopupListItem &item, void *userData) \
-    {                                                                                            \
-        static_cast<ClassName*>(userData)->method(item);                                         \
-    }
-
-    class PopupListItem
-        : public ListItem
-    {
-        friend class PopupList;
-        public:
-            PopupListItem(PopupList &parent, const std::string &text, PopupListItemPressedCb cb, void *userData);
-            PopupList &getParent();
-
-        private:
-            virtual std::string getText(ListItem &item, const char *part);
-
-        private:
-            PopupList &m_Parent;
-            std::string m_Text;
-            PopupListItemPressedCb m_Cb;
-            void *m_pUserData;
-    };
-
     class PopupList
         : public Popup
         , private IListViewListener
@@ -59,6 +33,7 @@ namespace Msg
             PopupList(PopupManager &parent);
             virtual ~PopupList();
 
+            void appendItem(PopupListItem &item);
             void appendItem(const std::string &text, PopupListItemPressedCb cb, void *userData);
             ListView &getListView();
 
diff --git a/src/Common/View/inc/PopupListItem.h b/src/Common/View/inc/PopupListItem.h
new file mode 100644 (file)
index 0000000..bb9811f
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2009-2016 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.
+ *
+ */
+
+#ifndef PopupListItem_h_
+#define PopupListItem_h_
+
+#include "ListItem.h"
+
+namespace Msg
+{
+    class PopupList;
+    class PopupListItem;
+    typedef void (*PopupListItemPressedCb)(PopupListItem &item, void *userData);
+    #define POPUPLIST_ITEM_PRESSED_CB(ClassName, method) [](PopupListItem &item, void *userData) \
+    {                                                                                            \
+        static_cast<ClassName*>(userData)->method(item);                                         \
+    }
+
+    /**
+     * Generic Popup-list item class
+     */
+    class PopupListItem: public ListItem
+    {
+    public:
+        PopupListItem(PopupList &parent, PopupListItemPressedCb cb, void *userData);
+        PopupList &getParent();
+        void fireCallback();
+    private:
+        PopupList &m_Parent;
+        PopupListItemPressedCb m_Cb;
+        void *m_pUserData;
+    };
+
+    /**
+     * A class of popup-item with single text displayed
+     */
+    class PopupTextListItem: public PopupListItem
+    {
+    public:
+        PopupTextListItem(PopupList &parent, const std::string &text, PopupListItemPressedCb cb, void *userData);
+        virtual ~PopupTextListItem();
+    private:
+        virtual std::string getText(ListItem &item, const char *part);
+    private:
+        std::string m_Text;
+    };
+}
+
+#endif /* PopupListItem_h_ */
index 460f802..6297743 100644 (file)
 
 using namespace Msg;
 
-const ListItemStyleRef listItemStyle = ListItemStyle::create("type1");
-
-PopupListItem::PopupListItem(PopupList &parent, const std::string &text, PopupListItemPressedCb cb, void *userData)
-    : ListItem(listItemStyle)
-    , m_Parent(parent)
-    , m_Text(text)
-    , m_Cb(cb)
-    , m_pUserData(userData)
-{
-}
-
-PopupList &PopupListItem::getParent()
-{
-    return m_Parent;
-}
-
-std::string PopupListItem::getText(ListItem &item, const char *part)
-{
-    if(strcmp(part, "elm.text") == 0)
-        return m_Text;
-    return std::string();
-}
-
 PopupList::PopupList(Evas_Object *parent)
     : Popup(parent)
     , m_pList(nullptr)
@@ -61,9 +38,14 @@ PopupList::~PopupList()
 {
 }
 
+void PopupList::appendItem(PopupListItem &item)
+{
+    m_pList->appendItem(item);
+}
+
 void PopupList::appendItem(const std::string &text, PopupListItemPressedCb cb, void *userData)
 {
-    m_pList->appendItem(*new PopupListItem(*this, text, cb, userData));
+    m_pList->appendItem(*new PopupTextListItem(*this, text, cb, userData));
 }
 
 void PopupList::create()
@@ -90,6 +72,5 @@ ListView &PopupList::getListView()
 void PopupList::onListItemSelected(ListItem &listItem)
 {
     PopupListItem &it = static_cast<PopupListItem&>(listItem);
-    if(it.m_Cb)
-        it.m_Cb(it, it.m_pUserData);;
+    it.fireCallback();
 }
diff --git a/src/Common/View/src/PopupListItem.cpp b/src/Common/View/src/PopupListItem.cpp
new file mode 100644 (file)
index 0000000..ad497d2
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2009-2016 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 "PopupListItem.h"
+
+using namespace Msg;
+
+const ListItemStyleRef listItemStyle = ListItemStyle::create("type1");
+
+PopupListItem::PopupListItem(PopupList &parent, PopupListItemPressedCb cb, void *userData)
+    : ListItem(listItemStyle)
+    , m_Parent(parent)
+    , m_Cb(cb)
+    , m_pUserData(userData)
+{
+}
+
+void PopupListItem::fireCallback()
+{
+    if (m_Cb)
+        m_Cb(*this, m_pUserData);
+}
+
+PopupList &PopupListItem::getParent()
+{
+    return m_Parent;
+}
+
+PopupTextListItem::PopupTextListItem(PopupList &parent, const std::string &text, PopupListItemPressedCb cb, void *userData)
+    : PopupListItem(parent, cb, userData)
+    , m_Text(text)
+{
+}
+
+PopupTextListItem::~PopupTextListItem()
+{
+}
+
+std::string PopupTextListItem::getText(ListItem &item, const char *part)
+{
+    if(strcmp(part, "elm.text") == 0)
+        return m_Text;
+    return std::string();
+}
index e7a73ac..e4048c5 100644 (file)
@@ -165,7 +165,8 @@ namespace Msg
             void showNoRecipPopup();
             PopupList &createPopupList(const std::string &title);
             void showSendResultPopup(MsgTransport::SendResult result);
-
+            void showUnsavedRecipientPopup(const std::string &address);
+            void showSavedRecipientPopup(const std::string &title, int personId);
             void sendMessage();
             void read(Message &msg);
             void readMsgAddress(Message &msg);
@@ -189,9 +190,6 @@ namespace Msg
             ConvList *m_pConvList;
             AttachPanel m_AttachPanel;
             DefferedCmd m_DefferedCmd;
-
-            // TODO: remove usage of pre-saved person-id of contact-recipient after implementation of modal popup routine
-            int m_SelectedPersonId;
             ContactEditor m_ContactEditor;
             IConversationListener *m_pListener;
     };
diff --git a/src/Conversation/Main/Controller/inc/PopupRecipientListItem.h b/src/Conversation/Main/Controller/inc/PopupRecipientListItem.h
new file mode 100644 (file)
index 0000000..9270724
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2009-2016 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.
+ *
+ */
+
+#ifndef PopupRecipientListItem_h_
+#define PopupRecipientListItem_h_
+
+#include "PopupListItem.h"
+
+namespace Msg
+{
+    class PopupAddressListItem
+        : public PopupTextListItem
+    {
+    public:
+        PopupAddressListItem(PopupList &parent, const std::string &text, const std::string &address,
+                PopupListItemPressedCb cb, void *userData);
+        virtual ~PopupAddressListItem();
+        std::string getAddress() const;
+    private:
+        std::string m_Address;
+    };
+
+
+    class PopupPersonIdListItem
+        : public PopupTextListItem
+    {
+    public:
+        PopupPersonIdListItem(PopupList &parent, const std::string &text, int personId,
+                PopupListItemPressedCb cb, void *userData);
+        virtual ~PopupPersonIdListItem();
+        int getPersonId() const;
+    private:
+        int m_PersonId;
+    };
+}
+
+#endif /* PopupRecipientListItem_h_ */
index 5c2e213..0903f7f 100644 (file)
@@ -27,6 +27,7 @@
 #include "ContactViewer.h"
 #include "VoiceCall.h"
 #include "Viewer.h"
+#include "PopupRecipientListItem.h"
 
 #include <Elementary.h>
 #include <sstream>
@@ -46,7 +47,6 @@ Conversation::Conversation(NaviFrameController &parent)
     , m_IsMms(false)
     , m_pConvList(nullptr)
     , m_AttachPanel(getApp())
-    , m_SelectedPersonId(-1)
     , m_pListener(nullptr)
 {
     create();
@@ -135,42 +135,59 @@ void Conversation::recipientClickHandler(const std::string &address)
     ContactPersonAddressRef contactPersonAddress = getApp().getContactManager().getContactPersonAddress(address);
     if(contactPersonAddress)
     {
-        m_SelectedPersonId = contactPersonAddress->getPersonId();
+        int selectedPersonId = contactPersonAddress->getPersonId();
         if(m_Mode == NewMessageMode)
         {
             MbeRecipientItem *pItem = m_pRecipPanel->getSelectedItem();
             if(pItem)
             {
-                PopupList &popup = createPopupList(pItem->getDispName());
-                popup.appendItem(msg("IDS_MSGF_OPT_REMOVE"), POPUPLIST_ITEM_PRESSED_CB(Conversation, onRemoveItemPressed), this);
-                popup.appendItem(msg("IDS_MSG_OPT_EDIT"), POPUPLIST_ITEM_PRESSED_CB(Conversation, onEditItemPressed), this);
-                popup.appendItem(msg("IDS_MSG_OPT_VIEW_CONTACT_DETAILS_ABB"), POPUPLIST_ITEM_PRESSED_CB(Conversation, onViewContactDetailsItemPressed), this);
-                popup.show();
+                showSavedRecipientPopup(pItem->getDispName(), selectedPersonId);
             }
         }
         else if(m_Mode == ConversationMode)
         {
-            ContactViewer::launch(m_SelectedPersonId);
-            m_SelectedPersonId = -1;
+            ContactViewer::launch(selectedPersonId);
         }
     }
     else
     {
-        PopupList &popup = createPopupList(address);
-        if(m_Mode == NewMessageMode)
-        {
-            popup.appendItem(msg("IDS_MSGF_OPT_REMOVE"), POPUPLIST_ITEM_PRESSED_CB(Conversation, onRemoveItemPressed), this);
-            popup.appendItem(msg("IDS_MSG_OPT_EDIT"), POPUPLIST_ITEM_PRESSED_CB(Conversation, onEditItemPressed), this);
-        }
-        else if(m_Mode == ConversationMode)
-        {
-            popup.appendItem(msg("IDS_MSG_OPT_MAKE_VOICE_CALL"), POPUPLIST_ITEM_PRESSED_CB(Conversation, onMakeVoiceItemPressed), this);
-        }
+        showUnsavedRecipientPopup(address);
+    }
+}
+
+void Conversation::showSavedRecipientPopup(const std::string &title, int personId)
+{
+    PopupList &popup = createPopupList(title);
+    popup.appendItem(msg("IDS_MSGF_OPT_REMOVE"), POPUPLIST_ITEM_PRESSED_CB(Conversation, onRemoveItemPressed), this);
+    popup.appendItem(msg("IDS_MSG_OPT_EDIT"), POPUPLIST_ITEM_PRESSED_CB(Conversation, onEditItemPressed), this);
+    popup.appendItem(*new PopupPersonIdListItem(popup, msg("IDS_MSG_OPT_VIEW_CONTACT_DETAILS_ABB"), personId,
+            POPUPLIST_ITEM_PRESSED_CB(Conversation, onViewContactDetailsItemPressed), this));
+    popup.show();
+}
 
-        popup.appendItem(msg("IDS_MSG_OPT_CREATE_CONTACT_ABB"), POPUPLIST_ITEM_PRESSED_CB(Conversation, onCreateContactItemPressed), this);
-        popup.appendItem(msg("IDS_MSG_OPT_UPDATE_CONTACT"), POPUPLIST_ITEM_PRESSED_CB(Conversation, onUpdateContactItemPressed), this);
-        popup.show();
+void Conversation::showUnsavedRecipientPopup(const std::string &address)
+{
+    PopupList &popup = createPopupList(address);
+    if(m_Mode == NewMessageMode)
+    {
+        popup.appendItem(*new PopupAddressListItem(popup, msg("IDS_MSGF_OPT_REMOVE"), address,
+                POPUPLIST_ITEM_PRESSED_CB(Conversation, onRemoveItemPressed), this));
+
+        popup.appendItem(*new PopupAddressListItem(popup, msg("IDS_MSG_OPT_EDIT"), address,
+                POPUPLIST_ITEM_PRESSED_CB(Conversation, onEditItemPressed), this));
+    }
+    else if(m_Mode == ConversationMode)
+    {
+        popup.appendItem(*new PopupAddressListItem(popup, msg("IDS_MSG_OPT_MAKE_VOICE_CALL"), address,
+                POPUPLIST_ITEM_PRESSED_CB(Conversation, onMakeVoiceItemPressed), this));
     }
+
+    popup.appendItem(*new PopupAddressListItem(popup, msg("IDS_MSG_OPT_CREATE_CONTACT_ABB"), address,
+                POPUPLIST_ITEM_PRESSED_CB(Conversation, onCreateContactItemPressed), this));
+
+    popup.appendItem(*new PopupAddressListItem(popup, msg("IDS_MSG_OPT_UPDATE_CONTACT"), address,
+                POPUPLIST_ITEM_PRESSED_CB(Conversation, onUpdateContactItemPressed), this));
+    popup.show();
 }
 
 void Conversation::contactChangedHandler()
@@ -874,34 +891,25 @@ void Conversation::onAddRecipientsItemPressed(ContextPopupItem &item)
 void Conversation::onMakeVoiceItemPressed(PopupListItem &item)
 {
     MSG_LOG("");
+    std::string address = static_cast<PopupAddressListItem&>(item).getAddress();
     item.getParent().destroy();
-    MbeRecipientItem *pItem = m_pRecipPanel->getSelectedItem();
-    if(pItem)
-        VoiceCall::launch(pItem->getAddress());
-
-    m_SelectedPersonId = -1;
+    VoiceCall::launch(address);
 }
 
 void Conversation::onCreateContactItemPressed(PopupListItem &item)
 {
     MSG_LOG("");
+    std::string address = static_cast<PopupAddressListItem&>(item).getAddress();
     item.getParent().destroy();
-    MbeRecipientItem *pItem = m_pRecipPanel->getSelectedItem();
-    if(pItem)
-        m_ContactEditor.launch(pItem->getAddress(), ContactEditor::CreateOp);
-
-    m_SelectedPersonId = -1;
+    m_ContactEditor.launch(address, ContactEditor::CreateOp);
 }
 
 void Conversation::onUpdateContactItemPressed(PopupListItem &item)
 {
     MSG_LOG("");
+    std::string address = static_cast<PopupAddressListItem&>(item).getAddress();
     item.getParent().destroy();
-    MbeRecipientItem *pItem = m_pRecipPanel->getSelectedItem();
-    if(pItem)
-        m_ContactEditor.launch(pItem->getAddress(), ContactEditor::EditOp);
-
-    m_SelectedPersonId = -1;
+    m_ContactEditor.launch(address, ContactEditor::EditOp);
 }
 
 void Conversation::onRemoveItemPressed(PopupListItem &item)
@@ -909,7 +917,6 @@ void Conversation::onRemoveItemPressed(PopupListItem &item)
     MSG_LOG("");
     item.getParent().destroy();
     m_pRecipPanel->removeSelectedItem();
-    m_SelectedPersonId = -1;
 }
 
 void Conversation::onEditItemPressed(PopupListItem &item)
@@ -917,15 +924,14 @@ void Conversation::onEditItemPressed(PopupListItem &item)
     MSG_LOG("");
     item.getParent().destroy();
     m_pRecipPanel->editSelectedItem();
-    m_SelectedPersonId = -1;
 }
 
 void Conversation::onViewContactDetailsItemPressed(PopupListItem &item)
 {
     MSG_LOG("");
+    int personId = static_cast<PopupPersonIdListItem&>(item).getPersonId();
     item.getParent().destroy();
-    ContactViewer::launch(m_SelectedPersonId);
-    m_SelectedPersonId = -1;
+    ContactViewer::launch(personId);
 }
 
 void Conversation::onAllItemsDeleted(ConvList &list)
diff --git a/src/Conversation/Main/Controller/src/PopupRecipientListItem.cpp b/src/Conversation/Main/Controller/src/PopupRecipientListItem.cpp
new file mode 100644 (file)
index 0000000..2d7ade1
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2009-2016 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 "PopupRecipientListItem.h"
+
+using namespace Msg;
+
+PopupAddressListItem::PopupAddressListItem(PopupList &parent, const std::string &text, const std::string &address,
+        PopupListItemPressedCb cb, void *userData)
+    : PopupTextListItem(parent, text, cb, userData)
+    , m_Address(address)
+{
+}
+
+PopupAddressListItem::~PopupAddressListItem()
+{
+}
+
+std::string PopupAddressListItem::getAddress() const
+{
+    return m_Address;
+}
+
+
+PopupPersonIdListItem::PopupPersonIdListItem(PopupList &parent, const std::string &text, int personId,
+        PopupListItemPressedCb cb, void *userData)
+    : PopupTextListItem(parent, text, cb, userData)
+    , m_PersonId(personId)
+{
+}
+
+PopupPersonIdListItem::~PopupPersonIdListItem()
+{
+}
+
+int PopupPersonIdListItem::getPersonId() const
+{
+    return m_PersonId;
+}