Fixed N_SE-38563, N_SE-38552
[apps/osp/Settings.git] / src / StEventsNotificationForm.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                StEventsNotificationForm.cpp
19  * @brief               This is the implementation file for EventsNotificationForm class.
20  */
21
22 #include "StEventsNotificationForm.h"
23 #include "StResourceManager.h"
24 #include "StTypes.h"
25
26 using namespace Tizen::Base;
27 using namespace Tizen::Graphics;
28 using namespace Tizen::Ui;
29 using namespace Tizen::Ui::Controls;
30 using namespace Tizen::Ui::Scenes;
31
32 static const int ID_GROUP_NOTIFICATION = 0;
33 static const int ID_GROUP_NOTIFICATION_ITEM_COUNT = 3;
34 static const int ID_ITEM_NOTIFICATION_EMAIL = 0;
35 static const int ID_ITEM_NOTOFICATION_MESSAGE = 1;
36 static const int ID_ITEM_NOTOFICATION_INSTANT_MESSENGER = 2;
37
38 static const int ID_GROUP_COUNT = 1;
39 static const int ID_GROUP_MAX_ITEM_COUNT = ID_GROUP_NOTIFICATION_ITEM_COUNT;
40
41 NotificationForm::NotificationForm(void)
42 {
43 }
44
45 NotificationForm::~NotificationForm(void)
46 {
47 }
48
49 void
50 NotificationForm::CreateFooter(void)
51 {
52         Footer* pFooter = GetFooter();
53         AppAssert(pFooter);
54
55         pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
56         pFooter->SetBackButton();
57         pFooter->AddActionEventListener(*this);
58
59         SetFormBackEventListener(this);
60 }
61
62 result
63 NotificationForm::OnInitializing(void)
64 {
65         CreateHeader(ResourceManager::GetString(L"IDS_ST_BODY_EVENTS_NOTIFICATIONS"));
66         CreateFooter();
67         CreateTableView();
68
69         AppLogDebug("ENTER");
70
71         return E_SUCCESS;
72 }
73
74 result
75 NotificationForm::OnTerminating(void)
76 {
77         __pTableView = null;
78
79         SetFormBackEventListener(null);
80         return E_SUCCESS;
81 }
82
83 void
84 NotificationForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
85 {
86         __pTableView->UpdateTableView();
87 }
88
89 void
90 NotificationForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
91 {
92 }
93
94 void
95 NotificationForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
96 {
97         SceneManager* pSceneManager = SceneManager::GetInstance();
98         AppAssert(pSceneManager);
99
100         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), null);
101 }
102
103 int
104 NotificationForm::GetGroupCount(void)
105 {
106         AppLogDebug("ENTER");
107         return ID_GROUP_COUNT;
108 }
109
110 int
111 NotificationForm::GetItemCount(int groupIndex)
112 {
113         int itemCount = 0;
114
115         if (groupIndex == ID_GROUP_NOTIFICATION)
116         {
117                 itemCount = ID_GROUP_NOTIFICATION_ITEM_COUNT;
118         }
119
120         AppLogDebug("GetItemCount %d", itemCount);
121
122         return itemCount;
123 }
124
125 TableViewGroupItem*
126 NotificationForm::CreateGroupItem(int groupIndex, int itemWidth)
127 {
128         AppLogDebug("ENTER");
129
130         int itemHeight = H_GROUP_INDEX_NO_TITLE_DEFAULT;
131         LabelTextStyle style = LABEL_TEXT_STYLE_BOLD;
132         Rectangle itemMainRectangle;
133         String groupText;
134         Label* pLabel = null;
135
136         TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
137
138         itemMainRectangle.x = X_GROUP_INDEX_DEFAULT_LABEL;
139         itemMainRectangle.y = Y_GROUP_INDEX_DEFAULT_LABEL;
140         itemMainRectangle.width = itemWidth;
141         itemMainRectangle.height = itemHeight;
142
143         RelativeLayout relativeLayout;
144         relativeLayout.Construct();
145
146         pItem->Construct(relativeLayout, Dimension(itemWidth, itemHeight));
147         pItem->SetBackgroundColor(COLOR_BG_GROUP_INDEX_DEFAULT);
148
149         pLabel = new (std::nothrow) Label();
150         pLabel->Construct(itemMainRectangle, groupText);
151         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
152         pLabel->SetTextConfig(FONT_SIZE_GROUP_TITLE_TEXT, style);
153         pLabel->SetTextColor(COLOR_HELP_TEXT_TYPE_01);
154
155         pItem->AddControl(pLabel);
156         relativeLayout.SetMargin(*pLabel, itemMainRectangle.x, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
157         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
158         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
159         pItem->SetEnabled(false);
160
161         return pItem;
162 }
163
164 TableViewItem*
165 NotificationForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
166 {
167         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
168
169         Rectangle itemMainRectangle;
170         TableViewAnnexStyle style = TABLE_VIEW_ANNEX_STYLE_NORMAL;
171         String itemMainText;
172         Label* pLabel = null;
173         int fontSize = GetFontSize();
174
175         switch (itemIndex)
176         {
177         case ID_ITEM_NOTIFICATION_EMAIL:
178                 {
179                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_EMAIL");
180                 }
181                 break;
182
183         case ID_ITEM_NOTOFICATION_MESSAGE:
184                 {
185                         itemMainText = ResourceManager::GetString(L"IDS_ST_BODY_SIDEBAR_MESSAGES");
186                 }
187                 break;
188
189         case ID_ITEM_NOTOFICATION_INSTANT_MESSENGER:
190                 {
191                         itemMainText = ResourceManager::GetString(L"IDS_COM_BODY_INSTANT_MESSENGER");
192                 }
193                 break;
194
195         default:
196                 break;
197         }
198
199         ItemTypeOneLine(itemMainRectangle);
200         TableViewItem* pItem = new (std::nothrow) TableViewItem();
201
202         RelativeLayout relativeLayout;
203         relativeLayout.Construct();
204
205         pItem->Construct(relativeLayout, Dimension(itemWidth, H_GROUP_ITEM_DEFAULT), style);
206         pItem->SetBackgroundColor(COLOR_BG_GROUP_ITEM_DEFAULT);
207
208         pLabel = new (std::nothrow) Label();
209         pLabel->Construct(itemMainRectangle, itemMainText);
210         pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
211         pLabel->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
212         pLabel->SetTextColor(COLOR_MAIN_TEXT);
213
214         pItem->AddControl(pLabel);
215         relativeLayout.SetMargin(*pLabel, 0, RELATIVE_LAYOUT_RIGHT_MARGIN, 0, 0);
216         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_LEFT_TO_LEFT);
217         relativeLayout.SetRelation(*pLabel, pItem, RECT_EDGE_RELATION_RIGHT_TO_RIGHT);
218
219         return pItem;
220 }
221
222 bool
223 NotificationForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
224 {
225         AppLogDebug("ENTER");
226
227         delete pItem;
228         pItem = null;
229
230         return true;
231 }
232
233 bool
234 NotificationForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
235 {
236         AppLogDebug("ENTER");
237
238         delete pItem;
239         pItem = null;
240
241         return true;
242 }
243
244 void
245 NotificationForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
246 {
247         SceneManager* pSceneManager = SceneManager::GetInstance();
248         AppAssert(pSceneManager);
249
250         AppLogDebug("group[%d] index[%d]", groupIndex, itemIndex);
251
252         switch (itemIndex)
253         {
254         case ID_ITEM_NOTIFICATION_EMAIL:
255                 {
256                         // TODO: make scene or call appControl.
257                         ShowMessageBox(ResourceManager::GetString(L"IDS_EMAIL_POP_ALERT"), ResourceManager::GetString(L"IDS_ST_POP_NOT_SUPPORTED"));
258                 }
259                 break;
260
261         case ID_ITEM_NOTOFICATION_MESSAGE:
262                 {
263                         // TODO: make scene or call appControl.
264                         ShowMessageBox(ResourceManager::GetString(L"IDS_EMAIL_POP_ALERT"), ResourceManager::GetString(L"IDS_ST_POP_NOT_SUPPORTED"));
265                 }
266                 break;
267
268         case ID_ITEM_NOTOFICATION_INSTANT_MESSENGER:
269                 {
270                         // TODO: make scene or call appControl
271                         ShowMessageBox(ResourceManager::GetString(L"IDS_EMAIL_POP_ALERT"), ResourceManager::GetString(L"IDS_ST_POP_NOT_SUPPORTED"));
272                 }
273                 break;
274
275         default:
276                 break;
277         }
278 }
279
280 int
281 NotificationForm::GetDefaultGroupItemHeight(void)
282 {
283         return H_GROUP_INDEX_NO_TITLE_DEFAULT;
284 }
285
286 int
287 NotificationForm::GetDefaultItemHeight(void)
288 {
289         return H_GROUP_ITEM_DEFAULT;
290 }
291
292 void
293 NotificationForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
294 {
295 }
296
297 void
298 NotificationForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
299 {
300 }
301
302 void
303 NotificationForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
304 {
305 }
306
307 void
308 NotificationForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
309 {
310 }