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