3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.tizenopensource.org/license
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
20 #include "DetailForm.h"
22 using namespace Osp::App;
23 using namespace Osp::Base;
24 using namespace Osp::Base::Collection;
25 using namespace Osp::Ui;
26 using namespace Osp::Ui::Controls;
27 using namespace Osp::Content;
28 using namespace Osp::Graphics;
30 static const int MAX_LISTVIEW_ITEM_SIZE = 70;
31 static const int MAX_CONTENTTYPE_COUNT = 4;
33 MainForm::MainForm(void)
34 : __contentType(CONTENT_TYPE_OTHER)
35 , __pEFContentName(null)
36 , __pLblContentList(null)
37 , __pLblContentName(null)
38 , __pLblContentType(null)
39 , __pSearchResultForm(null)
41 , __pSearchButton(null)
45 MainForm::~MainForm(void)
51 MainForm::Initialize()
53 // Construct an XML form
54 Form::Construct(L"IDF_MAINFORM");
60 MainForm::OnInitializing(void)
64 Footer* pFooter = GetFooter();
67 r = pFooter->SetStyle(FOOTER_STYLE_SEGMENTED_TEXT );
68 TryReturn(E_SUCCESS == r, r, "pFooter->SetStyle failed by %s.", GetErrorMessage(r));
69 r = pFooter->SetBackButton();
70 TryReturn(E_SUCCESS == r, r, "pFooter->SetBackButton failed by %s.", GetErrorMessage(r));
71 SetFormBackEventListener(this);
75 __pLblContentType = static_cast<Label *>(GetControl(L"IDC_LABEL1"));
76 TryReturn(__pLblContentType != null, r = E_FAILURE, "GetControl() failed by %s.", GetErrorMessage(r));
79 __pLblContentName = static_cast<Label *>(GetControl(L"IDC_LABEL2"));
80 TryReturn(__pLblContentName != null, r = E_FAILURE, "GetControl() failed by %s.", GetErrorMessage(r));
82 // ContentName EditField
83 __pEFContentName = static_cast<EditField *>(GetControl(L"IDC_EDITFIELD1"));
84 TryReturn(__pEFContentName != null, r = E_FAILURE, "GetControl() failed by %s.", GetErrorMessage(r));
86 __pSearchButton = static_cast<Button *>(GetControl(L"IDC_BUTTON_SEARCH"));
87 TryReturn(__pSearchButton != null, r = E_FAILURE, "GetControl() failed by %s.", GetErrorMessage(r));
89 __pSearchButton->AddActionEventListener(*this);
97 MainForm::OnTerminating(void)
101 if (__pContentSearchImpl != null)
103 delete __pContentSearchImpl;
112 result r = E_SUCCESS;
114 Frame *pFrame = Application::GetInstance()->GetAppFrame()->GetFrame();
116 // initialize ListView for ContentType
117 __pListView = new (std::nothrow) ListView();
118 TryReturn(__pListView != null, r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] __pListView is null.");
120 rect = this->GetClientAreaBounds();
121 r = __pListView->Construct(Rectangle(rect.x, __pLblContentType->GetBounds().y + MAX_LISTVIEW_ITEM_SIZE, rect.width, __pLblContentName->GetBounds().y - __pLblContentType->GetBounds().y - MAX_LISTVIEW_ITEM_SIZE - 20), true, false);
122 TryCatch(E_SUCCESS == r, , "ListView::Construct() failed by %s.", GetErrorMessage(r));
124 r = __pListView->SetItemProvider(*this);
125 TryCatch(E_SUCCESS == r, , "ListView::SetItemProvider() failed by %s.", GetErrorMessage(r));
127 __pListView->AddListViewItemEventListener(*this);
128 r = this->AddControl(*__pListView);
129 TryCatch(E_SUCCESS == r, , "AddControl() failed by %s.", GetErrorMessage(r));
131 __pContentSearchImpl = new (std::nothrow) ContentSearchSampleImpl();
132 TryCatch(__pContentSearchImpl != null, r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] __pContentSearchImpl is null.");
134 // Create a SearchResultForm
135 __pSearchResultForm = new (std::nothrow) SearchResultForm;
136 TryCatch(__pSearchResultForm != null, r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] __pSearchResultForm is null.");
138 __pSearchResultForm->Initialize();
140 // Add the form to the frame
141 pFrame->AddControl(*__pSearchResultForm);
143 // Create a SearchResultForm
144 __pDetailForm = new (std::nothrow) DetailForm;
145 TryCatch(__pDetailForm != null, r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] __pDetailForm is null.");
147 __pDetailForm->Initialize();
149 // Add the form to the frame
150 pFrame->AddControl(*__pDetailForm);
158 delete __pContentSearchImpl;
159 __pContentSearchImpl = null;
161 delete __pSearchResultForm;
162 __pSearchResultForm = null;
164 delete __pDetailForm;
165 __pDetailForm = null;
171 MainForm::SetDefaultContentType(void)
174 CheckContentTypeList((int)CONTENT_TYPE_OTHER);
178 MainForm::SearchContent(void)
180 result r = E_SUCCESS;
183 Frame *pFrame = null;
186 queryString = __pEFContentName->GetText();
188 r = __pContentSearchImpl->SearchContent(__contentType, queryString);
189 TryCatch(E_SUCCESS == r, , "Content Search failed by %s.", GetErrorMessage(r));
191 // display search result list
192 pFrame = Application::GetInstance()->GetAppFrame()->GetFrame();
193 pFrame->SetCurrentForm(*__pSearchResultForm);
194 __pSearchResultForm->DisplayResultList(__pContentSearchImpl);
197 // show error message
203 MainForm::ReSearchContent(void)
205 result r = E_SUCCESS;
207 Frame *pFrame = null;
210 r = __pContentSearchImpl->RefreshSearchContent();
211 TryCatch(E_SUCCESS == r, , "Content Search failed by %s.", GetErrorMessage(r));
213 // display search result list
214 pFrame = Application::GetInstance()->GetAppFrame()->GetFrame();
215 pFrame->SetCurrentForm(*__pSearchResultForm);
216 __pSearchResultForm->DisplayResultList(__pContentSearchImpl);
219 // show error message
225 MainForm::ShowErrorMsg(result r)
232 r = popStr.Format(128, L"Error [%s]", GetErrorMessage(r));
233 TryReturn(r == E_SUCCESS, , "popStr.Format failed");
234 r = msgBox.Construct("Message", popStr, MSGBOX_STYLE_NONE, 2000);
237 r = msgBox.ShowAndWait(modalResult);
238 TryReturn(r == E_SUCCESS, , "msgBox.ShowAndWait failed");
244 MainForm::UncheckContentType(int index)
246 for (int i = CONTENT_TYPE_OTHER; i <= CONTENT_TYPE_ALL; i++)
253 if (__pListView->IsItemChecked(i))
255 __pListView->SetItemChecked(i, false);
256 __pListView->RefreshList(i, LIST_REFRESH_TYPE_ITEM_MODIFY);
262 MainForm::CheckContentTypeList(int prevCheck)
264 bool checkFlag = false;
266 for (int i = CONTENT_TYPE_OTHER; i <= CONTENT_TYPE_ALL; i++)
268 if (__pListView->IsItemChecked(i))
274 if (checkFlag == false)
276 __pListView->SetItemChecked(prevCheck, true);
277 __pListView->RefreshList(prevCheck, LIST_REFRESH_TYPE_ITEM_MODIFY);
282 MainForm::OnUserEventReceivedN(RequestId requestId, IList* pArgs)
284 result r = E_SUCCESS;
288 case ID_REFRESH_SEARCH:
290 r = ReSearchContent();
293 case ID_DISPLAY_CONTENTINFO:
295 Frame *pFrame = Application::GetInstance()->GetAppFrame()->GetFrame();
296 Integer* pIndex = null;
300 pIndex = (Integer*)(pArgs->GetAt(0));
301 pFrame->SetCurrentForm(*__pDetailForm);
302 __pDetailForm->LoadContentInfo(__pContentSearchImpl->GetSearchResultItem(pIndex->ToInt()));
311 pArgs->RemoveAll(true);
318 MainForm::OnActionPerformed(const Control& source, int actionId)
320 if (source.GetName() == L"IDC_BUTTON_SEARCH")
327 MainForm::OnListViewItemStateChanged(ListView &listView, int index, int elementId, ListItemStatus status)
329 if (status == LIST_ITEM_STATUS_CHECKED)
331 __contentType = (ContentType)index;
332 UncheckContentType(index);
334 else if (status == LIST_ITEM_STATUS_UNCHECKED)
336 CheckContentTypeList(__contentType);
341 MainForm::OnListViewItemSwept(ListView &listView, int index, SweepDirection direction)
346 MainForm::OnListViewContextItemStateChanged(ListView &listView, int index, int elementId, ListContextItemStatus state)
351 MainForm::GetItemCount(void)
353 return MAX_CONTENTTYPE_COUNT;
357 MainForm::CreateItem(int index, int itemWidth)
359 String contentTypeName;
360 ListAnnexStyle style = LIST_ANNEX_STYLE_MARK;
361 CustomItem* pItem = new (std::nothrow) CustomItem();
362 TryReturn(pItem != null, pItem, "pItem is null.");
364 pItem->Construct(Dimension(itemWidth, MAX_LISTVIEW_ITEM_SIZE), style);
368 case CONTENT_TYPE_IMAGE:
369 contentTypeName = L"Image";
371 case CONTENT_TYPE_AUDIO:
372 contentTypeName = L"Audio";
374 case CONTENT_TYPE_VIDEO:
375 contentTypeName = L"Video";
377 case CONTENT_TYPE_OTHER:
378 contentTypeName = L"Other";
384 pItem->AddElement(Rectangle(20, 0, itemWidth - 20, MAX_LISTVIEW_ITEM_SIZE), 100, contentTypeName);
390 MainForm::DeleteItem(int index, ListItemBase* pItem, int itemWidth)
399 MainForm::OnFormBackRequested(Form& source)
401 Application::GetInstance()->Terminate();