Initialize Tizen 2.3
[apps/osp/Contacts.git] / src / CtMainForm.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        CtMainForm.cpp
19  * @brief       This is the implementation file for the MainForm class.
20  */
21
22 #include <FApp.h>
23 #include "CtContactsApp.h"
24 #include "CtMainForm.h"
25 #include "CtResourceManager.h"
26 #include "CtSceneRegister.h"
27 #include "CtTypes.h"
28
29 using namespace Tizen::App;
30 using namespace Tizen::Base;
31 using namespace Tizen::Graphics;
32 using namespace Tizen::Ui;
33 using namespace Tizen::Ui::Controls;
34 using namespace Tizen::Ui::Scenes;
35
36 static const int IDA_HEADER_CONTACTS = 10;
37 static const int IDA_HEADER_GROUPS = 11;
38 static const int IDA_HEADER_FAVORITES = 12;
39
40 static const wchar_t* IDB_TAB_ICON_CONTACTS = L"C02_tab_icon_contacts.png";
41 static const wchar_t* IDB_TAB_ICON_GROUPS = L"C02_tab_icon_groups.png";
42 static const wchar_t* IDB_TAB_ICON_FAVORITES = L"C02_tab_icon_favourites.png";
43 static const wchar_t* IDB_TAB_ICON_CONTACTS_PRESSED = L"C02_tab_icon_contacts_press.png";
44 static const wchar_t* IDB_TAB_ICON_GROUPS_PRESSED = L"C02_tab_icon_groups_press.png";
45 static const wchar_t* IDB_TAB_ICON_FAVORITES_PRESSED = L"C02_tab_icon_favourites_press.png";
46
47 MainForm::MainForm(void)
48 {
49 }
50
51 MainForm::~MainForm(void)
52 {
53 }
54
55 void
56 MainForm::Initialize(void)
57 {
58         Construct(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_HEADER | FORM_STYLE_FOOTER);
59 }
60
61 result
62 MainForm::OnInitializing(void)
63 {
64         result r = E_SUCCESS;
65
66         Header* pHeader = GetHeader();
67
68         r = pHeader->SetStyle(HEADER_STYLE_TAB);
69         if (r != E_SUCCESS)
70         {
71                 return r;
72         }
73
74         r = pHeader->SetTabEditModeEnabled(false);
75         if (r != E_SUCCESS)
76         {
77                 return r;
78         }
79
80         HeaderItem headerContacts;
81         headerContacts.Construct(IDA_HEADER_CONTACTS);
82         r = headerContacts.SetText(ResourceManager::GetString(L"IDS_COM_BODY_CONTACTS"));
83         if (r != E_SUCCESS)
84         {
85                 return r;
86         }
87
88         headerContacts.SetIcon(HEADER_ITEM_STATUS_NORMAL, ResourceManager::GetBitmapN(IDB_TAB_ICON_CONTACTS));
89         headerContacts.SetIcon(HEADER_ITEM_STATUS_PRESSED, ResourceManager::GetBitmapN(IDB_TAB_ICON_CONTACTS_PRESSED));
90
91         HeaderItem headerGroups;
92         headerGroups.Construct(IDA_HEADER_GROUPS);
93         r = headerGroups.SetText(ResourceManager::GetString(L"IDS_PB_BODY_GROUPS"));
94         if (r != E_SUCCESS)
95         {
96                 return r;
97         }
98
99         headerGroups.SetIcon(HEADER_ITEM_STATUS_NORMAL, ResourceManager::GetBitmapN(IDB_TAB_ICON_GROUPS));
100         headerGroups.SetIcon(HEADER_ITEM_STATUS_PRESSED, ResourceManager::GetBitmapN(IDB_TAB_ICON_GROUPS_PRESSED));
101
102         HeaderItem headerFavorites;
103         headerFavorites.Construct(IDA_HEADER_FAVORITES);
104         r = headerFavorites.SetText(ResourceManager::GetString(L"IDS_PB_ITAB4_FAVOURITES"));
105         if (r != E_SUCCESS)
106         {
107                 return r;
108         }
109
110         headerFavorites.SetIcon(HEADER_ITEM_STATUS_NORMAL, ResourceManager::GetBitmapN(IDB_TAB_ICON_FAVORITES));
111         headerFavorites.SetIcon(HEADER_ITEM_STATUS_PRESSED, ResourceManager::GetBitmapN(IDB_TAB_ICON_FAVORITES_PRESSED));
112
113         r = pHeader->AddItem(headerContacts);
114         if (r != E_SUCCESS)
115         {
116                 return r;
117         }
118         r = pHeader->AddItem(headerGroups);
119         if (r != E_SUCCESS)
120         {
121                 return r;
122         }
123         r = pHeader->AddItem(headerFavorites);
124         if (r != E_SUCCESS)
125         {
126                 return r;
127         }
128
129         SetFormBackEventListener(this);
130
131         __clientBounds = GetClientAreaBoundsF();
132
133         return r;
134 }
135
136 result
137 MainForm::OnTerminating(void)
138 {
139         result r = E_SUCCESS;
140
141         return r;
142 }
143
144 void
145 MainForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
146 {
147         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
148         TryReturnVoid(pContactsApp != null, "Unable to cast UiApp to ContactsApp");
149
150         if (pContactsApp->GetOperationId().Equals(OPERATION_ID_PICK, true))
151         {
152                 result r = AppControlProviderManager::GetInstance()->SendAppControlResult(pContactsApp->GetRequestId(), APP_CTRL_RESULT_CANCELED, null);
153                 AppLogDebug("[%s] The return result from SendAppControlResult().", GetErrorMessage(r));
154                 UiApp::GetInstance()->Terminate();
155                 return;
156         }
157
158         SceneManager *pSceneManager = SceneManager::GetInstance();
159         SceneId curSceneId = pSceneManager->GetCurrentSceneId();
160
161         if (curSceneId == IDSCN_CONTACT_LIST || curSceneId == IDSCN_FAVORITE_LIST || curSceneId == IDSCN_GROUP_LIST)
162         {
163                 UiApp::GetInstance()->Terminate();
164         }
165         else if (SceneManager::GetInstance()->GoBackward(BackwardSceneTransition()) != E_SUCCESS)
166         {
167                 UiApp::GetInstance()->Terminate();
168         }
169 }
170
171 FloatRectangle
172 MainForm::GetClientBounds()
173 {
174
175         return __clientBounds;
176 }