Initialize Tizen 2.3
[apps/osp/Contacts.git] / src / CtSearchListEventListener.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file        CtSearchListEventListener.cpp
19  * @brief       This is the implementation file for the SearchListEventListener class.
20  */
21
22 #include "CtContactListPresentationModel.h"
23 #include "CtContactsApp.h"
24 #include "CtResourceManager.h"
25 #include "CtSearchListEventListener.h"
26 #include "CtSearchListItem.h"
27
28 using namespace Tizen::Base;
29 using namespace Tizen::Graphics;
30 using namespace Tizen::Ui::Controls;
31
32 static const int IDA_LIST_ELEMENT_DELETE = 40;
33 static const int IDA_LIST_ELEMENT_CALL = 41;
34 static const int IDA_LIST_ELEMENT_MESSAGE = 42;
35 static const int IDA_LIST_ELEMENT_VIDEO_CALL = 43;
36
37
38 static const unsigned int COLOR_DELETE_ELEMENT_NORMAL = Color32<208, 82, 82>::Value;
39 static const unsigned int COLOR_DELETE_ELEMENT_PRESSED = Color32<194, 71, 71>::Value;
40 static const unsigned int COLOR_DELETE_ELEMENT_TEXT = Color32<248, 246, 239>::Value;
41
42 static const int H_GROUP_ITEM = 76;
43 static const int H_ITEM = 112;
44 static const int X_LIST_ITEM_TEXT_MARGIN = 32;
45
46 SearchListEventListener::SearchListEventListener(ListAnnexStyle itemAnnexStyle, ContactListPresentationModel* pContactListPresentationModel)
47 : __pContactListPresentationModel(pContactListPresentationModel)
48 , __itemAnnexStyle(itemAnnexStyle)
49 , __showDeleteOption(true)
50 {
51 }
52
53 SearchListEventListener::~SearchListEventListener(void)
54 {
55 }
56
57 int
58 SearchListEventListener::GetGroupCount(void)
59 {
60         if (__pContactListPresentationModel->GetSearchedContactCount() != 0)
61         {
62                 return 1;
63         }
64         else
65         {
66                 return 0;
67         }
68 }
69
70 int
71 SearchListEventListener::GetItemCount(int groupIndex)
72 {
73         return __pContactListPresentationModel->GetSearchedContactCount();
74 }
75
76 Tizen::Ui::Controls::ListItemBase*
77 SearchListEventListener::CreateItem(int groupIndex, int itemIndex, int itemWidth)
78 {
79         String name;
80         String phoneNumber;
81         Bitmap* pThumbnail = null;
82         CustomItem* pItem = null;
83         SearchListItem* pCustomElement = null;
84         int searchItemWidth = itemWidth;
85         int groupItemMainIndex = 0;
86         int ItemMainIndex = 0;
87
88         ContactsApp *pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
89
90         if (__itemAnnexStyle == LIST_ANNEX_STYLE_MARK)
91         {
92                 searchItemWidth -= (ListItemBase::GetAnnexWidth(LIST_ANNEX_STYLE_MARK) + X_LIST_ITEM_TEXT_MARGIN);
93         }
94         __pContactListPresentationModel->GetSearchedContactItemInfo(itemIndex, name, pThumbnail);
95
96         pItem = new (std::nothrow) CustomItem();
97         pItem->Construct(Dimension(itemWidth, H_ITEM + pContactsApp->GetFontHeightOffset()), __itemAnnexStyle);
98
99         pCustomElement = new (std::nothrow) SearchListItem(name, pThumbnail, __pContactListPresentationModel->GetSearchText());
100
101         pItem->AddElement(Rectangle(0, 0, searchItemWidth, H_ITEM + pContactsApp->GetFontHeightOffset()), 0, *(static_cast<ICustomElement *>(pCustomElement)));
102
103
104         if (pContactsApp->GetOperationId().IsEmpty() == false || __itemAnnexStyle == LIST_ANNEX_STYLE_MARK)
105         {
106                 return pItem;
107         }
108
109         __pContactListPresentationModel->GetItemMainIndex(itemIndex, groupItemMainIndex, ItemMainIndex);
110
111         bool isCallEnabled = true;
112         bool isMessageEnabled = true;
113         if (__pContactListPresentationModel->GetDefaultPhoneNumber(groupItemMainIndex, ItemMainIndex).IsEmpty())
114         {
115                 isCallEnabled = false;
116         }
117
118         if ((__pContactListPresentationModel->GetDefaultPhoneNumber(groupItemMainIndex, ItemMainIndex).IsEmpty()) && (__pContactListPresentationModel->GetDefaultEmail(groupItemMainIndex, ItemMainIndex).IsEmpty()))
119         {
120                 isMessageEnabled = false;
121         }
122
123         ListContextItem* pItemContext = new (std::nothrow) ListContextItem();
124         pItemContext->Construct();
125         pItemContext->AddElement(IDA_LIST_ELEMENT_CALL, ResourceManager::GetString(L"IDS_COM_BODY_CALL"), isCallEnabled);
126         pItemContext->AddElement(IDA_LIST_ELEMENT_MESSAGE, ResourceManager::GetString(L"IDS_COM_BODY_MESSAGE"), isMessageEnabled);
127 #if __SUPPORT_VIDEO_CALL
128         pItemContext->AddElement(IDA_LIST_ELEMENT_VIDEO_CALL, ResourceManager::GetString(L"IDS_COM_BODY_VIDEO_CALL"), isCallEnabled);
129 #endif
130         if (__showDeleteOption == true)
131         {
132                 pItemContext->AddElement(IDA_LIST_ELEMENT_DELETE, ResourceManager::GetString(L"IDS_COM_SK_DELETE"));
133         }
134         pItemContext->SetElementBackgroundColor(IDA_LIST_ELEMENT_DELETE, LIST_CONTEXT_ITEM_ELEMENT_STATUS_NORMAL, COLOR_DELETE_ELEMENT_NORMAL);
135         pItemContext->SetElementBackgroundColor(IDA_LIST_ELEMENT_DELETE, LIST_CONTEXT_ITEM_ELEMENT_STATUS_PRESSED, COLOR_DELETE_ELEMENT_PRESSED);
136         pItemContext->SetElementTextColor(IDA_LIST_ELEMENT_DELETE, LIST_CONTEXT_ITEM_ELEMENT_STATUS_NORMAL, COLOR_DELETE_ELEMENT_TEXT);
137
138         pItem->SetContextItem(pItemContext);
139
140         return pItem;
141 }
142
143 Tizen::Ui::Controls::GroupItem*
144 SearchListEventListener::CreateGroupItem(int groupIndex, int itemWidth)
145 {
146         GroupItem* pItem = new (std::nothrow) GroupItem();
147         pItem->Construct(Dimension(itemWidth, H_GROUP_ITEM));
148         pItem->SetElement(ResourceManager::GetString("IDS_COM_BODY_CONTACTS") + L" (" + Integer::ToString(__pContactListPresentationModel->GetSearchedContactCount()) + L")");
149
150         return pItem;
151 }
152
153 bool
154 SearchListEventListener::DeleteItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth)
155 {
156         CustomItem* pCustomItem = static_cast<CustomItem *>(pItem);
157         pCustomItem->RemoveAllElements();
158
159         delete pItem;
160         pItem = null;
161
162         return true;
163 }
164
165 bool
166 SearchListEventListener::DeleteGroupItem(int groupIndex, Tizen::Ui::Controls::GroupItem* pItem, int itemWidth)
167 {
168         delete pItem;
169         pItem = null;
170
171         return true;
172 }
173
174 void
175 SearchListEventListener::SetShowDeleteOption(bool showDeleteOption)
176 {
177         __showDeleteOption = showDeleteOption;
178 }