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 AccAddForm.cpp
19 * @brief This is the implementation file for AddForm class.
23 #include "AccAddForm.h"
26 using namespace Tizen::App;
27 using namespace Tizen::Base;
28 using namespace Tizen::Graphics;
29 using namespace Tizen::Ui;
30 using namespace Tizen::Ui::Controls;
31 using namespace Tizen::Ui::Scenes;
33 AddForm::AddForm(void)
35 , __pSectionTableView(null)
37 , __isRunningAppControl(false)
41 AddForm::~AddForm(void)
48 return Construct(IDL_ACCOUNT_ADD_FORM);
52 AddForm::OnInitializing(void)
55 AddFocusEventListener(*this);
56 SetFormBackEventListener(this);
58 __pPm = AccountPresentationModel::GetInstance();
60 __pSectionTableView = static_cast<SectionTableView*>(GetControl(IDC_SECTIONTABLEVIEW));
61 __pSectionTableView->SetItemProvider(this);
62 __pSectionTableView->AddSectionTableViewItemEventListener(*this);
68 AddForm::OnTerminating(void)
75 AddForm::OnAppControlCompleteResponseReceived(const Tizen::App::AppId& appId, const Tizen::Base::String& operationId, Tizen::App::AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pExtraData)
77 AppLogDebug("AppCtrlResult %d", appControlResult);
78 if (appControlResult == APP_CTRL_RESULT_SUCCEEDED)
80 result r = SceneManager::GetInstance()->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
83 r = SceneManager::GetInstance()->GoForward(SceneTransitionId(ID_SCNT_MAIN_FORM_BACK));
84 AppLogDebug("%s", GetErrorMessage(r));
87 else if (appControlResult == APP_CTRL_RESULT_FAILED || appControlResult == APP_CTRL_RESULT_ABORTED)
90 UiApp::GetInstance()->GetAppResource()->GetString(IDS_EMAIL_POP_UNABLE_TO_ADD_ACCOUNT, errorMsg);
94 msgBox.Construct(L"", errorMsg, MSGBOX_STYLE_NONE, 2000);
95 msgBox.ShowAndWait(modal);
100 AddForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
102 AppLogDebug("ENTER");
103 result r = SceneManager::GetInstance()->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
106 UiApp::GetInstance()->Terminate();
111 AddForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
113 AppLogDebug("ENTER");
114 __pPm->AddAccountChangedEventListener(*this);
115 __pSectionTableView->UpdateTableView();
116 if (__pSectionTableView->GetSectionCount() == 0)
127 AddForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
129 AppLogDebug("ENTER");
130 __pPm->RemoveAccountChangedEventListener(*this);
133 Tizen::Ui::Controls::TableViewItem*
134 AddForm::CreateItem(int sectionIndex, int itemIndex, int itemWidth)
136 AppLogDebug("itemWidth: %d, sectionIndex: %d, itemIndex: %d", itemWidth, sectionIndex, itemIndex);
138 RelativeLayout layout;
141 TableViewItem* pItem = new (std::nothrow) TableViewItem();
142 pItem->Construct(layout, Dimension(itemWidth, 112));
144 Panel* pPanel = new (std::nothrow) Panel();
145 pPanel->Construct(IDL_PANEL_SINGLE_LINE_ITEM);
147 Label* pMainLabel = static_cast<Label*>(pPanel->GetControl(IDC_LABEL_MAIN_TEXT));
148 pMainLabel->SetText(__pPm->GetAccountProviderName(itemIndex));
150 Bitmap* pIcon = __pPm->GetAccountProviderIconN(itemIndex);
153 pIcon = UiApp::GetInstance()->GetAppResource()->GetBitmapN(L"A01_2_title_Icon_none.png");
156 Label* pIconLabel = static_cast<Label*>(pPanel->GetControl(IDC_LABEL_ICON));
157 pIconLabel->SetBackgroundBitmap(*pIcon);
160 pItem->AddControl(pPanel);
162 layout.SetHorizontalFitPolicy(*pPanel, FIT_POLICY_PARENT);
163 layout.SetVerticalFitPolicy(*pPanel, FIT_POLICY_PARENT);
170 AddForm::DeleteItem(int sectionIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem *pItem)
177 AddForm::GetDefaultItemHeight(void)
183 AddForm::GetItemCount(int sectionIndex)
185 AppLogDebug("sectionIndex: %d", sectionIndex);
186 switch (sectionIndex)
189 return __pPm->GetAccountProviderCount();
196 AddForm::GetSectionCount(void)
198 if (__pPm->GetAccountProviderCount() == 0)
209 AddForm::GetSectionFooter(int sectionIndex)
215 AddForm::GetSectionHeader(int sectionIndex)
221 AddForm::HasSectionFooter(int sectionIndex)
227 AddForm::HasSectionHeader(int sectionIndex)
233 AddForm::UpdateItem(int sectionIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem *pItem)
238 AddForm::OnSectionTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::SectionTableView &tableView, int sectionIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem *pContextItem, bool activated)
243 AddForm::OnSectionTableViewItemStateChanged(Tizen::Ui::Controls::SectionTableView &tableView, int sectionIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem *pItem, Tizen::Ui::Controls::TableViewItemStatus status)
245 AppLogDebug("sectionIndex: %d, itemIndex: %d", sectionIndex, itemIndex);
246 switch (sectionIndex)
250 if (!__isRunningAppControl)
252 AppId appId = __pPm->GetAccountProviderAppId(itemIndex);
253 AppControl* pAppControl = AppManager::GetInstance()->FindAppControlN(appId, L"http://tizen.org/appcontrol/operation/account/add");
256 result r = pAppControl->Start(null, null, null, this);
258 TryReturnVoid(r == E_SUCCESS, "[%s] Failed to start appcontrol", GetErrorMessage(r));
260 __isRunningAppControl = true;
264 AppLogException("[%s] Failed to find appcontrol", GetErrorMessage(GetLastResult()));
275 AddForm::OnFocusGained(const Tizen::Ui::Control &source)
277 AppLogDebug("Enter");
278 __isRunningAppControl = false;
282 AddForm::OnFocusLost(const Tizen::Ui::Control &source)
284 AppLogDebug("Enter");
288 AddForm::OnAccountListChanged(void)
290 AppLogDebug("Enter");
291 __pSectionTableView->UpdateTableView();
292 if (__pSectionTableView->GetSectionCount() == 0)
303 AddForm::SetEmptyPanel(void)
307 Panel* pEmptyPanel = new (std::nothrow) Panel();
308 pEmptyPanel->Construct(IDL_PANEL_EMPTY_LIST);
311 UiApp::GetInstance()->GetAppResource()->GetString(IDS_NO_ACCOUNT_PROVIDERS, emptyText);
313 Label* pLabel = static_cast<Label*>(pEmptyPanel->GetControl(IDC_LABEL_TEXT));
314 pLabel->SetText(emptyText);
316 __pSectionTableView->AddControl(pEmptyPanel);
317 __pSectionTableView->Invalidate(true);
318 __pEmptyPanel = pEmptyPanel;
323 AddForm::RemoveEmptyPanel(void)
327 __pSectionTableView->RemoveControl(__pEmptyPanel);
328 __pEmptyPanel = null;