TizenRefApp-5517 Implement calling of conversation or thread-list 80/57680/3
authorOleksander Kostenko <o.kostenko@samsung.com>
Wed, 20 Jan 2016 18:58:45 +0000 (20:58 +0200)
committerOleksander Kostenko <o.kostenko@samsung.com>
Thu, 21 Jan 2016 14:26:43 +0000 (16:26 +0200)
Change-Id: I60383c6a6efd7398ca65bed9f1ed50449593dffc
Signed-off-by: Oleksander Kostenko <o.kostenko@samsung.com>
18 files changed:
src/Common/AppControl/inc/AppControlCommand.h
src/Common/AppControl/inc/AppControlCommandMain.h [deleted file]
src/Common/AppControl/inc/AppControlDefault.h [moved from src/Common/AppControl/inc/AppControlNewMessage.h with 70% similarity]
src/Common/AppControl/src/AppControlCommandMain.cpp [deleted file]
src/Common/AppControl/src/AppControlDefault.cpp [moved from src/Common/AppControl/src/AppControlNewMessage.cpp with 62% similarity]
src/Common/AppControl/src/AppControlParser.cpp
src/Common/Controller/inc/NaviFrameController.h
src/Common/Controller/src/NaviFrameController.cpp
src/Common/MsgEngine/inc/MsgStorage.h
src/Common/MsgEngine/src/private/MsgStoragePrivate.cpp
src/Common/MsgEngine/src/private/MsgStoragePrivate.h
src/Common/View/inc/NaviFrameItem.h
src/Common/View/inc/NaviFrameView.h
src/Common/View/src/NaviFrameView.cpp
src/Conversation/Main/Controller/inc/Conversation.h
src/Conversation/Main/Controller/src/Conversation.cpp
src/MainApp/MainApp.cpp
src/MsgThread/Controller/src/MsgThread.cpp

index 9de35db..f870974 100644 (file)
@@ -33,8 +33,7 @@ namespace Msg
             enum OperationType
             {
                 OpUnknown,
-                OpMain,
-                OpNewMessage,
+                OpDefault,
                 OpComposeFamily /** For operations Compose, Share, MultiShare and ShareText */
             };
 
diff --git a/src/Common/AppControl/inc/AppControlCommandMain.h b/src/Common/AppControl/inc/AppControlCommandMain.h
deleted file mode 100644 (file)
index f003764..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.
- *
- */
-
-#ifndef AppControlCommandMain_h_
-#define AppControlCommandMain_h_
-
-#include "AppControlCommand.h"
-
-namespace Msg
-{
-    class AppControlCommandMain;
-    typedef std::shared_ptr<AppControlCommandMain> AppControlCommandMainRef;
-
-    class AppControlCommandMain
-        : public AppControlCommand
-    {
-        public:
-            AppControlCommandMain(const std::string &opMsg);
-            virtual ~AppControlCommandMain();
-
-        private:
-    };
-}
-
-#endif /* AppControlCommandMain_h_ */
@@ -15,8 +15,8 @@
  *
  */
 
-#ifndef AppControlNewMessage_h_
-#define AppControlNewMessage_h_
+#ifndef AppControlDefault_h_
+#define AppControlDefault_h_
 
 #include "AppControlCommand.h"
 #include "MsgTypes.h"
 
 namespace Msg
 {
-    class AppControlNewMessage;
-    typedef std::shared_ptr<AppControlNewMessage> AppControlNewMessageRef;
+    class AppControlDefault;
+    typedef std::shared_ptr<AppControlDefault> AppControlDefaultRef;
 
-    class AppControlNewMessage
+    class AppControlDefault
         : public AppControlCommand
     {
         public:
-            enum NewMessageType
+            enum DefaultType
             {
                 UnknownType,
+                MainType, //Type from home screen
                 ReplyType, //Type for reply message button clicked
-                NewMsgType, //Type for view message button clicked
+                ViewType, //Type for view message button clicked
                 NotificationType //Type from notification panel
             };
 
         public:
-            AppControlNewMessage(const std::string &opMsg, app_control_h handle);
-            virtual ~AppControlNewMessage();
+            AppControlDefault(const std::string &opMsg, app_control_h handle);
+            virtual ~AppControlDefault();
 
             MsgId getMessageId() const;
-            NewMessageType getNewMessageType() const;
+            DefaultType getDefaultType() const;
 
         private:
             bool isNotificationPanel(app_control_h handle) const;
@@ -55,8 +56,8 @@ namespace Msg
 
         private:
             MsgId m_MsgId;
-            NewMessageType m_NewMsgType;
+            DefaultType m_DefaultType;
     };
 }
 
-#endif /* AppControlNewMessage_h_ */
+#endif /* AppControlDefault_h_ */
diff --git a/src/Common/AppControl/src/AppControlCommandMain.cpp b/src/Common/AppControl/src/AppControlCommandMain.cpp
deleted file mode 100644 (file)
index 1d40a01..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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 "AppControlCommandMain.h"
-
-using namespace Msg;
-
-
-AppControlCommandMain::AppControlCommandMain(const std::string &opMsg)
-    : AppControlCommand(opMsg, OpMain)
-{
-}
-
-AppControlCommandMain::~AppControlCommandMain()
-{
-}
-
@@ -15,7 +15,7 @@
  *
  */
 
-#include "AppControlNewMessage.h"
+#include "AppControlDefault.h"
 
 using namespace Msg;
 
@@ -28,41 +28,44 @@ namespace
     const char *keyMsgId = "msgId";
 }
 
-AppControlNewMessage::AppControlNewMessage(const std::string &opMsg, app_control_h handle)
-    : AppControlCommand(opMsg, OpNewMessage)
+AppControlDefault::AppControlDefault(const std::string &opMsg, app_control_h handle)
+    : AppControlCommand(opMsg, OpDefault)
     , m_MsgId()
-    , m_NewMsgType(UnknownType)
+    , m_DefaultType(UnknownType)
 {
     parse(handle);
 }
 
-AppControlNewMessage::~AppControlNewMessage()
+AppControlDefault::~AppControlDefault()
 {
 
 }
 
-MsgId AppControlNewMessage::getMessageId() const
+MsgId AppControlDefault::getMessageId() const
 {
     return m_MsgId;
 }
 
-AppControlNewMessage::NewMessageType AppControlNewMessage::getNewMessageType() const
+AppControlDefault::DefaultType AppControlDefault::getDefaultType() const
 {
-    return m_NewMsgType;
+    return m_DefaultType;
 }
 
-void AppControlNewMessage::parse(app_control_h handle)
+void AppControlDefault::parse(app_control_h handle)
 {
     char *key = nullptr;
     app_control_get_extra_data(handle, keyType, &key);
     if(!key)
+    {
+        m_DefaultType = MainType;
         return;
+    }
 
-    std::string keyType = key;
+    std::string type = key;
     free(key);
-    if(keyType == valueReply)
-        m_NewMsgType = ReplyType;
-    else if(keyType == valueNewMsg)
+    if(type == valueReply)
+        m_DefaultType = ReplyType;
+    else if(type == valueNewMsg)
         viewMessage(handle);
     else
         MSG_LOG("Unknown type!");
@@ -76,17 +79,23 @@ void AppControlNewMessage::parse(app_control_h handle)
     free(msgIdStr);
 }
 
-bool AppControlNewMessage::isNotificationPanel(app_control_h handle) const
+bool AppControlDefault::isNotificationPanel(app_control_h handle) const
 {
     char *keyVal = nullptr;
     app_control_get_extra_data(handle, notificationPanel, &keyVal);
-    return keyVal != nullptr;
+    if(keyVal)
+    {
+        free(keyVal);
+        return true;
+    }
+    else
+        return false;
 }
 
-void AppControlNewMessage::viewMessage(app_control_h handle)
+void AppControlDefault::viewMessage(app_control_h handle)
 {
     if(isNotificationPanel(handle))
-        m_NewMsgType = NotificationType;
+        m_DefaultType = NotificationType;
     else
-        m_NewMsgType = NewMsgType;
+        m_DefaultType = ViewType;
 }
index 9f91b32..780cb20 100644 (file)
@@ -18,8 +18,7 @@
 #include "Logger.h"
 #include "AppControlParser.h"
 #include "AppControlCommand.h"
-#include "AppControlCommandMain.h"
-#include "AppControlNewMessage.h"
+#include "AppControlDefault.h"
 #include "AppControlCompose.h"
 
 #include <app_control.h>
@@ -35,8 +34,8 @@ namespace
 
     const OperationMap operationMap =
     {
-        {APP_CONTROL_OPERATION_DEFAULT, AppControlCommand::OpNewMessage},
-        {APP_CONTROL_OPERATION_MAIN, AppControlCommand::OpMain},
+        {APP_CONTROL_OPERATION_DEFAULT, AppControlCommand::OpDefault},
+        {APP_CONTROL_OPERATION_MAIN, AppControlCommand::OpDefault},
         {APP_CONTROL_OPERATION_COMPOSE, AppControlCommand::OpComposeFamily},
         {APP_CONTROL_OPERATION_SHARE, AppControlCommand::OpComposeFamily},
         {APP_CONTROL_OPERATION_MULTI_SHARE, AppControlCommand::OpComposeFamily},
@@ -67,17 +66,13 @@ AppControlCommandRef AppControlParser::parse(app_control_h handle)
 
     switch(opType)
     {
-        //TODO: Create classes for all operations
-        case AppControlCommand::OpMain:
-            cmd = std::make_shared<AppControlCommandMain>(opStr);
+        case AppControlCommand::OpDefault:
+            cmd = std::make_shared<AppControlDefault>(opStr, handle);
             break;
 
         case AppControlCommand::OpComposeFamily:
             cmd = std::make_shared<AppControlCompose>(opStr, handle);
             break;
-
-        // TODO: impl for other command types
-
         default:
         case AppControlCommand::OpUnknown:
             cmd = std::make_shared<AppControlCommand>(opStr, opType);
index c5dc410..fedea32 100644 (file)
@@ -22,8 +22,8 @@
 #include "NaviFrameView.h"
 #include "HwButtonListener.h"
 #include "AppControlCommand.h"
-#include "AppControlCommandMain.h"
 #include "AppControlCompose.h"
+#include "AppControlDefault.h"
 
 namespace Msg
 {
@@ -51,7 +51,7 @@ namespace Msg
             /**
              * Executes app control command of default type.
              */
-            void execCmd(const AppControlCommandMainRef &cmd);
+            void execCmd(const AppControlDefaultRef &cmd);
 
             /**
              * Executes app control command of compose type. This is Compose, Share, MultiShare, ShareText.
@@ -65,7 +65,8 @@ namespace Msg
 
         private:
             void init();
-
+            template<typename T>
+            T *getFrame() const;
             bool execCmd(const AppControlCommand &cmd);
 
             virtual void onHwBackButtonClicked();
index 0f9d44d..d501fad 100644 (file)
@@ -75,14 +75,28 @@ bool NaviFrameController::execCmd(const AppControlCommand &cmd)
     return true;
 }
 
-void NaviFrameController::execCmd(const AppControlCommandMainRef &cmd)
+void NaviFrameController::execCmd(const AppControlDefaultRef &cmd)
 {
     if(execCmd(*cmd))
     {
-        if(isEmpty())
+        AppControlDefault::DefaultType type = cmd->getDefaultType();
+
+        Conversation *conv = getFrame<Conversation>();
+        if(conv)
+            pop();
+
+        MsgThread *thread = getFrame<MsgThread>();
+        if(!thread && type != AppControlDefault::ReplyType)
+            push(*new MsgThread(*this));
+
+        if(type == AppControlDefault::ReplyType || type == AppControlDefault::ViewType)
+        {
+            push(*new Conversation(*this, cmd));
+        }
+        else if(type == AppControlDefault::NotificationType)
         {
-            MsgThread *threadFrame = new MsgThread(*this);
-            push(*threadFrame);
+            if(getMsgEngine().getStorage().getUnreadThreadCount() == 1)
+                push(*new Conversation(*this, cmd));
         }
     }
 }
@@ -104,6 +118,19 @@ void NaviFrameController::execCmd(const AppControlComposeRef &cmd)
     }
 }
 
+template<typename T>
+T *NaviFrameController::getFrame() const
+{
+    auto items = getItems();
+    for(NaviFrameItem *item : items)
+    {
+        T *frame = dynamic_cast<T*>(item);
+        if(frame)
+            return frame;
+    }
+    return nullptr;
+}
+
 void NaviFrameController::onHwBackButtonClicked()
 {
     pop();
index 330d939..56f5827 100644 (file)
@@ -51,6 +51,7 @@ namespace Msg
             virtual MsgAddressListRef getAddressList(ThreadId id) = 0;
             virtual MsgThreadListRef searchThread(const std::string &word) = 0;
             virtual void setReadStatus(ThreadId id) = 0;
+            virtual int getUnreadThreadCount() const = 0;
 
             // Message:
             virtual MessageSMSListRef getSimMsgList() = 0;
index a2e1067..e96ac19 100644 (file)
@@ -198,6 +198,32 @@ MsgThreadListRef MsgStoragePrivate::searchThread(const std::string &word)
     return res;
 }
 
+int MsgStoragePrivate::getUnreadThreadCount() const
+{
+    msg_struct_t sortRule = msg_create_struct(MSG_STRUCT_SORT_RULE);
+    msg_struct_list_s peerList;
+
+    int unreadThreadCount = 0;
+    bool oneThread = true;
+
+    msg_set_int_value(sortRule, MSG_SORT_RULE_SORT_TYPE_INT, MSG_SORT_BY_READ_STATUS);
+    msg_set_bool_value(sortRule, MSG_SORT_RULE_ACSCEND_BOOL, false);
+
+    msg_get_thread_view_list(m_ServiceHandle, sortRule, &peerList);
+    msg_release_struct(&sortRule);
+
+    for(int i = 0; i < peerList.nCount; i++)
+    {
+        int unreadCnt = 0;
+        msg_get_int_value(peerList.msg_struct_info[i], MSG_THREAD_UNREAD_COUNT_INT, &unreadCnt);
+
+        if(unreadCnt > 0)
+            unreadThreadCount++;
+    }
+
+    return unreadThreadCount;
+}
+
 MsgThreadItemRef MsgStoragePrivate::getThread(ThreadId id)
 {
     MsgThreadItemRef res;
index 5226977..7df9958 100644 (file)
@@ -43,6 +43,7 @@ namespace Msg
             virtual MsgAddressListRef getAddressList(ThreadId id);
             virtual MsgThreadListRef searchThread(const std::string &word);
             virtual void setReadStatus(ThreadId id);
+            virtual int getUnreadThreadCount() const;
 
             // Message:
             virtual MessageSMSListRef getSimMsgList();
index ad25411..a3d65ae 100644 (file)
 
 #include <string>
 #include <memory>
+#include <vector>
 #include <Elementary.h>
 
 namespace Msg
 {
     class NaviFrameView;
+    class NaviFrameItem;
+    typedef std::vector<NaviFrameItem*> NaviFrameItemList;
 
     class NaviFrameItem
         : public ViewItem
index 180e41f..57f61f1 100644 (file)
@@ -40,6 +40,10 @@ namespace Msg
              * Get count of pushed frames.
              */
             int getItemsCount() const;
+            /**
+             * Get list of pushed frames.
+             */
+            NaviFrameItemList getItems() const;
 
             /**
              * Checks if any frame was pushed.
index f80884c..cd6c4ff 100644 (file)
@@ -62,6 +62,27 @@ int NaviFrameView::getItemsCount() const
     return res;
 }
 
+NaviFrameItemList NaviFrameView::getItems() const
+{
+    NaviFrameItemList result;
+    Eina_List *list= elm_naviframe_items_get(getEo());
+
+    if(list)
+    {
+        Eina_List *l = nullptr;
+        void *obj = nullptr;
+
+        EINA_LIST_FOREACH(list, l, obj)
+        {
+            NaviFrameItem *item = static_cast<NaviFrameItem*>(elm_object_item_data_get(obj));
+            result.push_back(item);
+        }
+
+        eina_list_free(list);
+    }
+    return result;
+}
+
 bool NaviFrameView::isEmpty() const
 {
     return getItemsCount() <= 0;
@@ -75,11 +96,10 @@ void NaviFrameView::push(NaviFrameItem &item, Evas_Object *content)
 
 void NaviFrameView::push(NaviFrameItem &item, View &content)
 {
-    push(item, content.getEo());
+    push(item, content);
 }
 
 void NaviFrameView::pop()
 {
     elm_naviframe_item_pop(getEo());
 }
-
index 72a9cbb..ebd40c6 100644 (file)
@@ -30,6 +30,7 @@
 #include "ConvContactList.h"
 #include "ConvList.h"
 #include "AppControlCompose.h"
+#include "AppControlDefault.h"
 #include "AttachPanel.h"
 
 namespace Msg
@@ -50,7 +51,8 @@ namespace Msg
         , private IAttachPanelListener
     {
         public:
-            Conversation(NaviFrameController &parent, const AppControlComposeRef &cmd = AppControlComposeRef());
+            Conversation(NaviFrameController &parent, const AppControlComposeRef &cmd);
+            Conversation(NaviFrameController &parent, const AppControlDefaultRef &cmd);
             Conversation(NaviFrameController &parent, ThreadId threadId);
             virtual ~Conversation();
 
index 4f64d00..9847fae 100644 (file)
@@ -57,6 +57,19 @@ Conversation::Conversation(NaviFrameController &parent, const AppControlComposeR
     execCmd(cmd);
 }
 
+Conversation::Conversation(NaviFrameController &parent, const AppControlDefaultRef &cmd)
+    : Conversation(parent, false)
+{
+    if(cmd)
+        m_ThreadId = getMsgEngine().getStorage().getMessage(cmd->getMessageId())->getThreadId();
+
+    create();
+
+    if(cmd->getDefaultType() == AppControlDefault::ReplyType)
+        m_pBody->setFocus(true);
+
+}
+
 Conversation::Conversation(NaviFrameController &parent,ThreadId threadId)
     : Conversation(parent, false)
 {
@@ -68,7 +81,7 @@ Conversation::~Conversation()
 {
     // Call before delete all children:
     MSG_LOG("");
-
+    saveDraftMsg();
     getMsgEngine().getStorage().removeListener(*this);
     if(m_pBody)
         m_pBody->setListener(nullptr);
@@ -535,7 +548,6 @@ void Conversation::onHwBackButtonClicked()
         return;
     }
 
-    saveDraftMsg();
     getParent().pop();
 }
 
index e32eb8d..e51607c 100644 (file)
@@ -21,7 +21,7 @@
 #include "CallbackAssist.h"
 #include "Logger.h"
 #include "AppControlParser.h"
-#include "AppControlCommandMain.h"
+#include "AppControlDefault.h"
 #include "AppControlCompose.h"
 #include "PathUtils.h"
 #include "Config.h"
@@ -162,9 +162,9 @@ void MainApp::onAppControl(app_control_h app_control)
 
     switch(cmd->getOperationType())
     {
-        case AppControlCommand::OpMain:
+        case AppControlCommand::OpDefault:
             if(m_pRootController)
-                m_pRootController->execCmd(std::static_pointer_cast<AppControlCommandMain>(cmd));
+                m_pRootController->execCmd(std::static_pointer_cast<AppControlDefault>(cmd));
             break;
         case AppControlCommand::OpComposeFamily:
             if(m_pRootController)
index a2203c2..a381611 100644 (file)
@@ -96,7 +96,7 @@ void MsgThread::showMainCtxPopup()
 
 void MsgThread::composeNewMessage()
 {
-    Conversation *frame = new Conversation(getParent());
+    Conversation *frame = new Conversation(getParent(), AppControlComposeRef());
     getParent().push(*frame);
 }