wrt-plugins-tizen_0.4.23
[framework/web/wrt-plugins-tizen.git] / src / Messaging / Conversation.cpp
index 26bc1a9..6e8f753 100644 (file)
@@ -39,7 +39,7 @@ Conversation::Conversation()
 
 Conversation::Conversation(unsigned int threadId, MessageType msgType)
 {
-       LogDebug("Enter");
+       LoggerD("Enter");
        
        if (msgType == EMAIL)
        {
@@ -57,11 +57,11 @@ Conversation::Conversation(unsigned int threadId, MessageType msgType)
        
 Conversation::Conversation(std::string threadId, MessageType msgType)
 {
-       LogDebug("Enter");
+       LoggerD("Enter");
        bool result = FALSE;
        std::istringstream stream(threadId);
        
-       LogDebug("threadId : " << threadId);
+       LoggerD("threadId : " << threadId);
        
        unsigned int number = 0;
        stream >> number;
@@ -86,11 +86,12 @@ Conversation::Conversation(msg_struct_t msg_thread)
 //void Conversation::makeConversationFromThread(msg_thread_view_t msg_thread)
 void Conversation::makeConversationFromThread(msg_struct_t msg_thread) 
 {
-       LogDebug("Enter");
+       LoggerD("Enter");
        msg_handle_t handle = MsgGetCommonHandle();
 
        msg_struct_list_s convViewList;
-       msg_struct_list_s *addr_list = NULL;
+       msg_list_handle_t addr_list = NULL;
+       msg_struct_t addr_info = NULL;
 
        msg_struct_t msgInfo = NULL;
        msg_struct_t sendOpt = NULL;
@@ -127,13 +128,13 @@ void Conversation::makeConversationFromThread(msg_struct_t msg_thread)
                        case MSG_TYPE_SMS_SYNCML:
                        case MSG_TYPE_SMS_REJECT:
                                m_type = SMS;
-                               LogDebug("Type:SMS");
+                               LoggerD("Type:SMS");
                                break;
                        case MSG_TYPE_MMS:
                        case MSG_TYPE_MMS_JAVA:
                        case MSG_TYPE_MMS_NOTI:
                                m_type = MMS;;
-                               LogDebug("Type:MMS");
+                               LoggerD("Type:MMS");
                                break;
                } 
                
@@ -152,7 +153,7 @@ void Conversation::makeConversationFromThread(msg_struct_t msg_thread)
                if (tempString != NULL)
                {
                        m_preview = tempString; 
-                       LogDebug("preview" << m_preview);
+                       LoggerD("preview" << m_preview);
                }
 
                err = msg_get_conversation_view_list(handle, m_Id, &convViewList);
@@ -183,9 +184,9 @@ void Conversation::makeConversationFromThread(msg_struct_t msg_thread)
                msg_get_int_value(convViewList.msg_struct_info[lastMsgIndex], MSG_CONV_MSG_DIRECTION_INT, &tempInt);
                int type = tempInt;
 
-               msg_get_list_handle(msgInfo, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
+               msg_get_list_handle(msgInfo, MSG_MESSAGE_ADDR_LIST_HND, (void **)&addr_list);
 
-               nToCnt = addr_list->nCount;
+               nToCnt = msg_list_length(addr_list);
 
                if (type == MSG_DIRECTION_TYPE_MT)
                {
@@ -193,7 +194,8 @@ void Conversation::makeConversationFromThread(msg_struct_t msg_thread)
                        if (nToCnt > 0 && nToCnt < MAX_TO_ADDRESS_CNT )
                        {
                                char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
-                               msg_get_str_value(addr_list->msg_struct_info[m_lastMessageId], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
+                               addr_info = (msg_struct_t)msg_list_nth_data(addr_list, m_lastMessageId);
+                               msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
                                
                                if (strNumber[0] != '\0')
                                {
@@ -201,18 +203,18 @@ void Conversation::makeConversationFromThread(msg_struct_t msg_thread)
                                }
                                else
                                {
-                                       LogDebug("address is null ");
+                                       LoggerD("address is null ");
                                }
                        }
                        else 
                        {
-                               LogDebug("address count index fail");
+                               LoggerD("address count index fail");
                        }
                        
                }
                else
                {
-                       LogDebug("Msg direction: MO, from will be omitted");
+                       LoggerD("Msg direction: MO, from will be omitted");
                }
 
                //      get thread subject
@@ -230,7 +232,8 @@ void Conversation::makeConversationFromThread(msg_struct_t msg_thread)
                        for (index = 0; index < nToCnt; index++)
                        {
                                char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
-                               msg_get_str_value(addr_list->msg_struct_info[index], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
+                               addr_info = (msg_struct_t)msg_list_nth_data(addr_list, index);
+                               msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
                                tempString = strNumber;
                                if (tempString != NULL)
                                {
@@ -240,13 +243,13 @@ void Conversation::makeConversationFromThread(msg_struct_t msg_thread)
                }
                else
                {
-                       LogDebug("address fetch fail" << addressCount);
+                       LoggerD("address fetch fail" << addressCount);
                }
        }
        catch (const WrtDeviceApis::Commons::Exception& ex) 
        {
                m_result = false;
-               LogError("Exception: " << ex.GetMessage());
+               LoggerE("Exception: " << ex.GetMessage());
        }
        
        msg_release_list_struct(&convViewList);
@@ -261,7 +264,7 @@ void Conversation::makeConversationFromThread(msg_struct_t msg_thread)
 void Conversation::makeConversationFromThreadIndex(unsigned int threadIndex)
 {
 /*
-       LogDebug("Enter");
+       LoggerD("Enter");
        MSG_HANDLE_T handle = MsgGetCommonHandle();
        MSG_LIST_S convViewList = {0, NULL};
        MSG_THREAD_VIEW_LIST_S threadViewList = {0, NULL};
@@ -282,7 +285,7 @@ void Conversation::makeConversationFromThreadIndex(unsigned int threadIndex)
 
                if (threadViewList.nCount < 0 || threadIndex >= (unsigned int)threadViewList.nCount)
                {
-                       LogDebug(threadIndex << ":" << threadViewList.nCount);
+                       LoggerD(threadIndex << ":" << threadViewList.nCount);
                        ThrowMsg(WrtDeviceApis::Commons::UnknownException, "invalid index reference" );
                }
 
@@ -302,13 +305,13 @@ void Conversation::makeConversationFromThreadIndex(unsigned int threadIndex)
                        case MSG_TYPE_SMS_SYNCML:
                        case MSG_TYPE_SMS_REJECT:
                                m_type = SMS;
-                               LogDebug("Type:SMS");
+                               LoggerD("Type:SMS");
                                break;
                        case MSG_TYPE_MMS:
                        case MSG_TYPE_MMS_JAVA:
                        case MSG_TYPE_MMS_NOTI:
                                m_type = MMS;;
-                               LogDebug("Type:MMS");
+                               LoggerD("Type:MMS");
                                break;
 //                     default:
                                // Todo email / chat
@@ -321,7 +324,7 @@ void Conversation::makeConversationFromThreadIndex(unsigned int threadIndex)
                if (tempString != NULL)
                {
                        m_preview = tempString; 
-                       LogDebug("preview" << m_preview);
+                       LoggerD("preview" << m_preview);
                }
 
                
@@ -336,7 +339,7 @@ void Conversation::makeConversationFromThreadIndex(unsigned int threadIndex)
                m_messageCount = convViewList.nCount;
                m_read = msg_is_read(convViewList.msgInfo[lastMsgIndex]);
                
-               LogDebug("lastMsgIndex:" << lastMsgIndex << ",message count:" << m_messageCount << ",read" << m_read);
+               LoggerD("lastMsgIndex:" << lastMsgIndex << ",message count:" << m_messageCount << ",read" << m_read);
 
                if (msg_get_direction_info(convViewList.msgInfo[lastMsgIndex]) == MSG_DIRECTION_TYPE_MT)
                {
@@ -352,18 +355,18 @@ void Conversation::makeConversationFromThreadIndex(unsigned int threadIndex)
                                }
                                else
                                {
-                                       LogDebug("address is null ");
+                                       LoggerD("address is null ");
                                }
                        }
                        else 
                        {
-                               LogDebug("address count index fail");
+                               LoggerD("address count index fail");
                        }
-                       LogDebug("from" << m_from);
+                       LoggerD("from" << m_from);
                }
                else
                {
-                       LogDebug("Msg direction: MO, from will be omitted");
+                       LoggerD("Msg direction: MO, from will be omitted");
                }
 
 
@@ -374,7 +377,7 @@ void Conversation::makeConversationFromThreadIndex(unsigned int threadIndex)
                        m_subject = tempString;
                }
 
-               LogDebug("subject" << m_subject);
+               LoggerD("subject" << m_subject);
                
 
                addressCount = msg_get_address_count(convViewList.msgInfo[lastMsgIndex]);
@@ -391,11 +394,11 @@ void Conversation::makeConversationFromThreadIndex(unsigned int threadIndex)
                                        m_to.push_back(tempString);
                                }
                        }
-                       LogDebug("address count" << addressCount);
+                       LoggerD("address count" << addressCount);
                }
                else
                {
-                       LogDebug("address fetch fail" << addressCount);
+                       LoggerD("address fetch fail" << addressCount);
                }
 
                if (msg_get_message_id(convViewList.msgInfo[lastMsgIndex]) >= 0 )
@@ -403,13 +406,13 @@ void Conversation::makeConversationFromThreadIndex(unsigned int threadIndex)
                        m_lastMessageId = msg_get_message_id(convViewList.msgInfo[lastMsgIndex]);
                }
 
-               LogDebug("message id" << m_lastMessageId);
+               LoggerD("message id" << m_lastMessageId);
 
        }
        catch (const WrtDeviceApis::Commons::Exception& ex) 
        {
                m_result = false;
-               LogError("Exception: " << ex.GetMessage());
+               LoggerE("Exception: " << ex.GetMessage());
        }
        if (convViewList.msgInfo != NULL) 
        {
@@ -426,7 +429,7 @@ void Conversation::makeConversationFromThreadIndex(unsigned int threadIndex)
 
 bool Conversation::makeConversationFromMsgId(unsigned int msgId, MessageType msgType)
 {
-       LogDebug("Enter");
+       LoggerD("Enter");
 
        msg_handle_t handle = MsgGetCommonHandle();
 
@@ -436,7 +439,8 @@ bool Conversation::makeConversationFromMsgId(unsigned int msgId, MessageType msg
        msg_struct_t msg_thread = NULL;
 
        msg_struct_list_s convViewList;
-       msg_struct_list_s *addr_list = NULL;
+       msg_list_handle_t addr_list = NULL;
+       msg_struct_t addr_info = NULL;
        
        msg_error_t err = MSG_SUCCESS;
 
@@ -465,7 +469,7 @@ bool Conversation::makeConversationFromMsgId(unsigned int msgId, MessageType msg
                // get threadId from message
                msg_get_int_value(msgInfo, MSG_MESSAGE_THREAD_ID_INT, &tempInt);
                m_Id = (unsigned int)tempInt;
-               LogDebug("m_Id : " << m_Id);
+               LoggerD("m_Id : " << m_Id);
 
                // get Thread
                msg_thread = msg_create_struct(MSG_STRUCT_THREAD_INFO);
@@ -483,25 +487,25 @@ bool Conversation::makeConversationFromMsgId(unsigned int msgId, MessageType msg
                        case MSG_TYPE_SMS_SYNCML:
                        case MSG_TYPE_SMS_REJECT:
                                m_type = SMS;
-                               LogDebug("Type:SMS");
+                               LoggerD("Type:SMS");
                                break;
                        case MSG_TYPE_MMS:
                        case MSG_TYPE_MMS_JAVA:
                        case MSG_TYPE_MMS_NOTI:
                                m_type = MMS;;
-                               LogDebug("Type:MMS");
+                               LoggerD("Type:MMS");
                                break;
                } 
 
                //      get thread time
                msg_get_int_value(msg_thread, MSG_THREAD_MSG_TIME_INT, &tempInt);
                m_time = tempInt;
-               LogDebug("m_time : " << m_time);
+               LoggerD("m_time : " << m_time);
 
                //      get thread unread count
                msg_get_int_value(msg_thread, MSG_THREAD_UNREAD_COUNT_INT, &tempInt);
                m_unreadMessages = tempInt;
-               LogDebug("m_unreadMessages : " << m_unreadMessages);
+               LoggerD("m_unreadMessages : " << m_unreadMessages);
 
                //      get thread preview
                msg_get_str_value(msg_thread, MSG_THREAD_MSG_DATA_STR, msgData, MAX_THREAD_DATA_LEN);
@@ -511,7 +515,7 @@ bool Conversation::makeConversationFromMsgId(unsigned int msgId, MessageType msg
                {
                        m_preview = tempString; 
                }
-               LogDebug("m_preview : " << m_preview);
+               LoggerD("m_preview : " << m_preview);
 
                err = msg_get_conversation_view_list(handle, m_Id, &convViewList);
                        
@@ -523,17 +527,17 @@ bool Conversation::makeConversationFromMsgId(unsigned int msgId, MessageType msg
                //      get thread message count
                lastMsgIndex = convViewList.nCount - 1;
                m_messageCount = convViewList.nCount;
-               LogDebug("m_messageCount : " << m_messageCount);
+               LoggerD("m_messageCount : " << m_messageCount);
 
                //      get thread read status
                msg_get_bool_value(convViewList.msg_struct_info[lastMsgIndex], MSG_CONV_MSG_READ_BOOL, &tempBool);
                m_read = tempBool;
-               LogDebug("m_read : " << m_read);
+               LoggerD("m_read : " << m_read);
 
                //      get thread last message Id
                msg_get_int_value(convViewList.msg_struct_info[lastMsgIndex], MSG_CONV_MSG_ID_INT, &tempInt);
                m_lastMessageId = tempInt;
-               LogDebug("m_lastMessageId : " << m_lastMessageId);
+               LoggerD("m_lastMessageId : " << m_lastMessageId);
 
                //      get thread from
                if (msg_get_message(handle, m_lastMessageId, msgInfo, sendOpt) != MSG_SUCCESS)
@@ -543,10 +547,10 @@ bool Conversation::makeConversationFromMsgId(unsigned int msgId, MessageType msg
 
                msg_get_int_value(convViewList.msg_struct_info[lastMsgIndex], MSG_CONV_MSG_DIRECTION_INT, &tempInt);
                int type = tempInt;
-               LogDebug("direction : " << type);
+               LoggerD("direction : " << type);
 
-               msg_get_list_handle(msgInfo, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
-               nToCnt = addr_list->nCount;
+               msg_get_list_handle(msgInfo, MSG_MESSAGE_ADDR_LIST_HND, (void **)&addr_list);
+               nToCnt = msg_list_length(addr_list);
 
                if (type == MSG_DIRECTION_TYPE_MT)
                {
@@ -554,7 +558,8 @@ bool Conversation::makeConversationFromMsgId(unsigned int msgId, MessageType msg
                        if (nToCnt > 0 && nToCnt < MAX_TO_ADDRESS_CNT )
                        {
                                char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
-                               msg_get_str_value(addr_list->msg_struct_info[nToCnt-1], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
+                               addr_info = (msg_struct_t)msg_list_nth_data(addr_list, nToCnt-1);
+                               msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
 
                                if (strNumber[0] != '\0')
                                {
@@ -562,36 +567,37 @@ bool Conversation::makeConversationFromMsgId(unsigned int msgId, MessageType msg
                                }
                                else
                                {
-                                       LogDebug("address is null ");
+                                       LoggerD("address is null ");
                                }
                        }               
                        else 
                        {
-                               LogDebug("address count index fail");
+                               LoggerD("address count index fail");
                        }
 
                }
                else
                {
-                       LogDebug("Msg direction: MO, from will be omitted");
+                       LoggerD("Msg direction: MO, from will be omitted");
                        //      get thread to           
                        if (nToCnt > 0 && nToCnt < MAX_TO_ADDRESS_CNT )
                        {
                                for (int index = 0; index < nToCnt; index++)
                                {
+                                       addr_info = (msg_struct_t)msg_list_nth_data(addr_list, index);
                                        char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
-                                       msg_get_str_value(addr_list->msg_struct_info[index], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
+                                       msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
                                        tempString = strNumber;
                                        if (tempString != NULL)
                                        {
-                                               LogDebug("m_to : " << tempString);
+                                               LoggerD("m_to : " << tempString);
                                                m_to.push_back(tempString);
                                        }
                                }
                        }
                        else
                        {
-                               LogDebug("address fetch fail");
+                               LoggerD("address fetch fail");
                        }
                }
 
@@ -603,18 +609,18 @@ bool Conversation::makeConversationFromMsgId(unsigned int msgId, MessageType msg
                {
                        m_subject = tempString; // convert char to string
                }               
-               LogDebug("m_subject : " << m_subject);
+               LoggerD("m_subject : " << m_subject);
                
        }
        catch (const WrtDeviceApis::Commons::UnknownException& ex)
        {
                m_result = false;
-               LogError("Exception: " << ex.GetMessage());
+               LoggerE("Exception: " << ex.GetMessage());
        }
        catch (const WrtDeviceApis::Commons::Exception& ex)
        {
                m_result = false;
-               LogError("Exception: " << ex.GetMessage());
+               LoggerE("Exception: " << ex.GetMessage());
        }
 
        msg_release_list_struct(&convViewList);
@@ -627,7 +633,7 @@ bool Conversation::makeConversationFromMsgId(unsigned int msgId, MessageType msg
 
 bool Conversation::makeConversationFromEmailThreadId(unsigned int emailTreadId)
 {
-       LogDebug("Enter");
+       LoggerD("Enter");
        
        email_mail_list_item_t *resultMail = NULL;
        email_mail_list_item_t *mailList = NULL;
@@ -659,13 +665,13 @@ bool Conversation::makeConversationFromEmailThreadId(unsigned int emailTreadId)
                // account Id
                m_unreadMessages = 0;
 
-               LogDebug("start email_get_mail_list");
+               LoggerD("start email_get_mail_list");
                if (email_get_mail_list(mailData->account_id, 0, emailTreadId, 0, resultMail->thread_item_count, 
                        EMAIL_SORT_DATETIME_HIGH, &mailList, &count) != EMAIL_ERROR_NONE)
                {
                        ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get email data fail" );
                }
-               LogDebug("end email_get_mail_list");
+               LoggerD("end email_get_mail_list");
                
                // unread msg count
                for (index = 0; index < count; index++)
@@ -674,7 +680,7 @@ bool Conversation::makeConversationFromEmailThreadId(unsigned int emailTreadId)
                        {
                                m_unreadMessages++;
                        }
-                       LogDebug(mailList[index].flags_seen_field);
+                       LoggerD(mailList[index].flags_seen_field);
                }
                
                // message count
@@ -696,42 +702,42 @@ bool Conversation::makeConversationFromEmailThreadId(unsigned int emailTreadId)
                if (resultMail->full_address_from[0] != '\0')
                {
                        m_from = resultMail->full_address_from;
-                       LogDebug(m_from);
+                       LoggerD(m_from);
                }
 
                // subject
                if (resultMail->subject[0] != '\0')
                {
                        m_subject = resultMail->subject;
-                       LogDebug(m_subject);            
+                       LoggerD(m_subject);             
                }
 
                if (mailData->full_address_to != NULL)
                {
-                       LogDebug("Header To " << mailData->full_address_to);
+                       LoggerD("Header To " << mailData->full_address_to);
                        m_to.push_back(mailData->full_address_to);
                }
 
                if (mailData->full_address_bcc != NULL)
                {
-                       LogDebug("Header Bcc " << mailData->full_address_bcc);
+                       LoggerD("Header Bcc " << mailData->full_address_bcc);
                        m_bcc.push_back(mailData->full_address_bcc);
                }
 
                if (mailData->full_address_cc != NULL)
                {
-                       LogDebug("Header CC " << mailData->full_address_cc);
+                       LoggerD("Header CC " << mailData->full_address_cc);
                        m_cc.push_back(mailData->full_address_cc);
                }
                
                m_lastMessageId = resultMail->mail_id;
-               LogDebug(m_lastMessageId);              
+               LoggerD(m_lastMessageId);               
                m_result = true;
        }
        catch (const WrtDeviceApis::Commons::Exception& ex) 
        {
                m_result = false;
-               LogError("Exception: " << ex.GetMessage());
+               LoggerE("Exception: " << ex.GetMessage());
        }
 
        if (mailData != NULL)
@@ -872,3 +878,4 @@ bool Conversation::getResult()
 
 }
 }
+