Refact: ContactViewer class. 58/92158/1 submit/tizen/20161013.132833
authorDenis Dolzhenko <d.dolzhenko@samsung.com>
Thu, 13 Oct 2016 12:52:41 +0000 (15:52 +0300)
committerDenis Dolzhenko <d.dolzhenko@samsung.com>
Thu, 13 Oct 2016 12:52:41 +0000 (15:52 +0300)
Change-Id: I56d8cb024cafe40e30e36fe0259503b611ef0abb
Signed-off-by: Denis Dolzhenko <d.dolzhenko@samsung.com>
src/Common/AppControl/inc/ContactViewer.h
src/Common/AppControl/src/ContactViewer.cpp
src/Conversation/Main/Controller/src/Conversation.cpp
src/Viewer/Controller/src/Viewer.cpp

index c13f838..5e38b90 100644 (file)
@@ -29,25 +29,33 @@ namespace Msg
     class ContactViewer
     {
         public:
+            static ContactViewer &getInst();
+
             /**
              * @brief Launches view-operation.
              * @param[in] id Contact person id or MyProfile id
              * @param[in] ownerType PersonType or MyProfileType
              * @return true in case of success, otherwise returns false.
              */
-            static bool launch(int id, ContactAddress::OwnerType ownerType);
+            bool launch(int id, ContactAddress::OwnerType ownerType);
 
             /**
              * @brief Launches view-operation.
              * @param[in] address reference to ContactAddress object.
              * @return true in case of success, otherwise returns false.
              */
-            static bool launch(const ContactAddress &address);
+            bool launch(const ContactAddress &address);
 
         private:
+            ContactViewer();
+            ~ContactViewer();
             ContactViewer(const ContactViewer&) = delete;
             ContactViewer& operator=(const ContactViewer&) = delete;
-            static const char *toStr(ContactAddress::OwnerType type);
+            const char *toStr(ContactAddress::OwnerType type);
+            void reset();
+
+        private:
+            app_control_h m_Handle;
     };
 }
 
index bc262fd..2e4672e 100644 (file)
@@ -30,22 +30,48 @@ namespace
     const char *myProfileTypeStr = "my_profile";
 }
 
+ContactViewer::ContactViewer()
+    : m_Handle()
+{
+
+}
+
+ContactViewer::~ContactViewer()
+{
+    reset();
+}
+
+ContactViewer &ContactViewer::getInst()
+{
+    static ContactViewer inst;
+    return inst;
+}
+
+void ContactViewer::reset()
+{
+    if(m_Handle)
+    {
+        app_control_send_terminate_request(m_Handle);
+        app_control_destroy(m_Handle);
+        m_Handle = nullptr;
+    }
+}
+
 bool ContactViewer::launch(int id, ContactAddress::OwnerType ownerType)
 {
     bool res = false;
-    app_control_h svc_handle = nullptr;
 
-    if(APP_CONTROL_ERROR_NONE == app_control_create(&svc_handle))
+    reset();
+    if(APP_CONTROL_ERROR_NONE == app_control_create(&m_Handle))
     {
-        app_control_set_operation(svc_handle, APP_CONTROL_OPERATION_VIEW);
-        app_control_set_mime(svc_handle, mimeContact);
-        app_control_add_extra_data(svc_handle, APP_CONTROL_DATA_TYPE, toStr(ownerType));
-        app_control_add_extra_data(svc_handle, APP_CONTROL_DATA_ID, std::to_string(id).c_str());
-        app_control_set_launch_mode(svc_handle, APP_CONTROL_LAUNCH_MODE_GROUP);
-        int ret = app_control_send_launch_request(svc_handle, nullptr, nullptr);
+        app_control_set_operation(m_Handle, APP_CONTROL_OPERATION_VIEW);
+        app_control_set_mime(m_Handle, mimeContact);
+        app_control_add_extra_data(m_Handle, APP_CONTROL_DATA_TYPE, toStr(ownerType));
+        app_control_add_extra_data(m_Handle, APP_CONTROL_DATA_ID, std::to_string(id).c_str());
+        app_control_set_launch_mode(m_Handle, APP_CONTROL_LAUNCH_MODE_GROUP);
+        int ret = app_control_send_launch_request(m_Handle, nullptr, nullptr);
         MSG_LOG("Result code: ", ret);
         res = ret == APP_CONTROL_ERROR_NONE;
-        app_control_destroy(svc_handle);
     }
 
     return res;
index ac0eb48..2293bb7 100644 (file)
@@ -195,7 +195,7 @@ void Conversation::recipientClickHandler(const std::string &address)
         {
             if(m_pRecipPanel)
                 m_pRecipPanel->unselectMbeItem();
-            ContactViewer::launch(*contactAddress);
+            ContactViewer::getInst().launch(*contactAddress);
         }
     }
     else
@@ -1383,7 +1383,7 @@ void Conversation::onViewContactDetailsItemPressed(PopupListItem &item)
     int id = static_cast<PopupPersonIdListItem&>(item).getContactId();
     auto ownerType = static_cast<PopupPersonIdListItem&>(item).getContactOwnerType();
     item.getParent().destroy();
-    ContactViewer::launch(id, ownerType);
+    ContactViewer::getInst().launch(id, ownerType);
 }
 
 void Conversation::onAllConvItemsDeleted(ConvList &list)
index 9723bed..be14d9c 100644 (file)
@@ -228,7 +228,7 @@ void Viewer::recipientClickHandler(const std::string &address)
     m_SelectedAddress = address;
     ContactAddressRef contactAddress = getApp().getContactManager().getContactAddress(address);
     if(contactAddress)
-        ContactViewer::launch(*contactAddress);
+        ContactViewer::getInst().launch(*contactAddress);
     else
         showRecipPopup(address);
 }