2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (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
8 // http://floralicense.org/license/
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.
18 * @file AccMainForm.cpp
19 * @brief This is the implementation file for MainForm class.
24 #include <FGraphics.h>
27 #include "AccMainForm.h"
29 #include "AccAccountPresentationModel.h"
31 using namespace Tizen::App;
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::Graphics;
35 using namespace Tizen::Social;
36 using namespace Tizen::Ui;
37 using namespace Tizen::Ui::Controls;
38 using namespace Tizen::Ui::Scenes;
40 static const int IDA_ADD_ACCOUNT = 20001;
42 MainForm::MainForm(void)
44 , __pSectionTableView(null)
46 , __isRunningAppControl(false)
50 MainForm::~MainForm(void)
55 MainForm::Initialize(void)
57 return Construct(IDL_MAIN_FORM);
61 MainForm::OnInitializing(void)
64 AddFocusEventListener(*this);
65 SetFormBackEventListener(this);
66 GetFooter()->AddActionEventListener(*this);
68 __pPm = AccountPresentationModel::GetInstance();
70 __pSectionTableView = static_cast<SectionTableView*>(GetControl(IDC_SECTIONTABLEVIEW));
71 __pSectionTableView->SetItemProvider(this);
72 __pSectionTableView->AddSectionTableViewItemEventListener(*this);
78 MainForm::OnTerminating(void)
85 MainForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
88 __pPm->AddAccountChangedEventListener(*this);
89 __pSectionTableView->UpdateTableView();
90 if (__pSectionTableView->GetSectionCount() == 0)
101 MainForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,const Tizen::Ui::Scenes::SceneId& nextSceneId)
103 AppLogDebug("ENTER");
104 __pPm->RemoveAccountChangedEventListener(*this);
108 MainForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
110 AppLogDebug("actionId: %d", actionId);
111 if (!__isRunningAppControl)
115 case IDA_ADD_ACCOUNT:
116 SceneManager::GetInstance()->GoForward(SceneTransitionId(ID_SCNT_ACCOUNT_ADD));
125 MainForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
127 AppLogDebug("ENTER");
128 UiApp::GetInstance()->Terminate();
131 Tizen::Ui::Controls::TableViewItem*
132 MainForm::CreateItem(int sectionIndex, int itemIndex, int itemWidth)
134 AppLogDebug("itemWidth: %d, sectionIndex: %d, itemIndex: %d", itemWidth, sectionIndex, itemIndex);
136 RelativeLayout layout;
139 TableViewItem* pItem = new (std::nothrow) TableViewItem();
140 pItem->Construct(layout, Dimension(itemWidth, 140));
142 Panel* pPanel = new (std::nothrow) Panel();
143 pPanel->Construct(IDL_PANEL_MULTI_LINE_ITEM);
145 Label* pMainLabel = static_cast<Label*>(pPanel->GetControl(IDC_LABEL_MAIN_TEXT));
146 pMainLabel->SetText(__pPm->GetAccountInfo(ACCOUNT_INFO_TYPE_USER_NAME, itemIndex));
148 Label* pSubLabel = static_cast<Label*>(pPanel->GetControl(IDC_LABEL_SUB_TEXT));
149 pSubLabel->SetText(__pPm->GetAccountInfo(ACCOUNT_INFO_TYPE_PROVIDER_NAME, itemIndex));
151 Bitmap* pIcon = __pPm->GetAccountIconN(itemIndex);
154 pIcon = UiApp::GetInstance()->GetAppResource()->GetBitmapN(L"A01_2_title_Icon_none.png");
157 Label* pIconLabel = static_cast<Label*>(pPanel->GetControl(IDC_LABEL_ICON));
158 pIconLabel->SetBackgroundBitmap(*pIcon);
161 pItem->AddControl(pPanel);
163 layout.SetHorizontalFitPolicy(*pPanel, FIT_POLICY_PARENT);
164 layout.SetVerticalFitPolicy(*pPanel, FIT_POLICY_PARENT);
171 MainForm::DeleteItem(int sectionIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem *pItem)
178 MainForm::GetDefaultItemHeight(void)
184 MainForm::GetItemCount(int sectionIndex)
186 AppLogDebug("sectionIndex: %d", sectionIndex);
187 switch (sectionIndex)
190 return __pPm->GetAccountCount();
197 MainForm::GetSectionCount(void)
199 if (__pPm->GetAccountCount() == 0)
210 MainForm::GetSectionFooter(int sectionIndex)
216 MainForm::GetSectionHeader(int sectionIndex)
218 switch (sectionIndex)
223 UiApp::GetInstance()->GetAppResource()->GetString(IDS_EMAIL_SK3_ACCOUNT_LIST, header);
232 MainForm::HasSectionFooter(int sectionIndex)
238 MainForm::HasSectionHeader(int sectionIndex)
240 switch (sectionIndex)
250 MainForm::UpdateItem(int sectionIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem *pItem)
255 MainForm::OnSectionTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::SectionTableView &tableView, int sectionIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem *pContextItem, bool activated)
257 AppLogDebug("Enter");
261 MainForm::OnSectionTableViewItemStateChanged(Tizen::Ui::Controls::SectionTableView &tableView, int sectionIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem *pItem, Tizen::Ui::Controls::TableViewItemStatus status)
263 AppLogDebug("sectionIndex: %d, itemIndex: %d", sectionIndex, itemIndex);
264 switch (sectionIndex)
268 if (!__isRunningAppControl)
270 AppId appId = __pPm->GetAccountAppId(itemIndex);
271 AppControl* pAppControl = AppManager::GetInstance()->FindAppControlN(appId, L"http://tizen.org/appcontrol/operation/account/configure");
274 HashMap argMap(SingleObjectDeleter);
276 argMap.Add(new (std::nothrow) String(L"http://tizen.org/appcontrol/data/account/id"), new (std::nothrow) String(Integer::ToString(__pPm->GetAccountId(itemIndex))));
278 result r = pAppControl->Start(null, null, &argMap, null);
280 TryReturnVoid(r == E_SUCCESS, "[%s] Failed to start appcontrol", GetErrorMessage(r));
281 __isRunningAppControl = true;
285 AppLogException("[%s] Failed to find appcontrol", GetErrorMessage(GetLastResult()));
296 MainForm::OnFocusGained(const Tizen::Ui::Control &source)
298 AppLogDebug("Enter");
299 __isRunningAppControl = false;
303 MainForm::OnFocusLost(const Tizen::Ui::Control &source)
305 AppLogDebug("Enter");
309 MainForm::OnAccountListChanged(void)
311 AppLogDebug("Enter");
312 __pSectionTableView->UpdateTableView();
313 if (__pSectionTableView->GetSectionCount() == 0)
324 MainForm::SetEmptyPanel(void)
328 Panel* pEmptyPanel = new (std::nothrow) Panel();
329 pEmptyPanel->Construct(IDL_PANEL_EMPTY_LIST);
330 __pSectionTableView->AddControl(pEmptyPanel);
331 __pSectionTableView->Invalidate(true);
332 __pEmptyPanel = pEmptyPanel;
337 MainForm::RemoveEmptyPanel(void)
341 __pSectionTableView->RemoveControl(__pEmptyPanel);
342 __pEmptyPanel = null;