Tizen 2.1 base
[apps/osp/ImageViewer.git] / src / IvImageViewerForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
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                IvImageViewerForm.cpp
19  * @brief               This is the implementation file for ImageViewerForm class.
20  */
21
22 #include <FApp.h>
23 #include "IvCommonUtil.h"
24 #include "IvImageInfo.h"
25 #include "IvImageViewerApp.h"
26 #include "IvImageViewerForm.h"
27 #include "IvImageViewerPresentationModel.h"
28 #include "IvResourceManager.h"
29 #include "IvTypes.h"
30
31 using namespace Tizen::App;
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::Base::Runtime;
35 using namespace Tizen::Base::Utility;
36 using namespace Tizen::Content;
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Io;
39 using namespace Tizen::Media;
40 using namespace Tizen::System;
41 using namespace Tizen::Ui;
42 using namespace Tizen::Ui::Controls;
43 using namespace Tizen::Ui::Scenes;
44
45 static const unsigned int COLOR_HEADER_CONTORL_PANEL = Color32<0, 0, 0, 100>::Value;
46 static const unsigned int COLOR_HEADER_BUTTON1 = Color32<0, 0, 0, 100>::Value;
47
48 static const Rectangle RECT_CONTORL_BUTTON_PLAY (280, 400, 160, 160);
49 static const Rectangle RECT_LANDSCAP_CONTORL_BUTTON_PLAY (560, 216, 160, 160);
50
51 static const Rectangle RECT_DETAILS_CONTORL_PANEL (0, 0, 720, 1008);
52 static const Rectangle RECT_LANDSCAPE_DETAILS_CONTORL_PANEL (0, 0, 1280, 484);
53 static const Rectangle RECT_DETAILS_CONTORL_LABEL (20, 0, 200, 48);
54
55 static const int GAP_LABEL_END = 60;
56 static const int GAP_W_POPUP_ITEM = 5;
57 static const int W_DELETE_POPUP = 600;
58 static const int H_DELETE_POPUP = 300;
59 static const int H_DELETE_LABEL = 180;
60 static const int Y_DELETE_BUTTON = 180;
61 static const int H_DELETE_BUTTON = 80;
62
63 static const Dimension DUMMY_IMAGE_DIMENSION    (720, 1280);
64 static const Rectangle DUMMY_IMAGE_RECTANGLE    (0, 0, 720, 1280);
65
66 static const int PAGE_NO_CONTENT_SEARCH = 1;
67 static const int COUNT_PER_PAGE_CONTENT_SEARCH = 10;
68
69 static const int FORMAT_BUFFER_SIZE = 256;
70
71 static const long long SINGLE_GIGA_BYTE = (1024 * 1024 * 1024);
72 static const long long SINGLE_MEGA_BYTE = (1024 * 1024);
73 static const long long SINGLE_KILO_BYTE = 1024;
74
75 static const int Y_RENAME_BUTTON = 100;
76 static const int H_RENAME_BUTTON = 64;
77 static const int W_RENAME_BUTTON = 64;
78
79 static const int X_DETAIL_FILEINFO_LABEL = 20;
80 static const int W_DETAIL_FILEINFO_LABEL = 420;
81 static const int H_DETAIL_FILEINFO_LABEL = 50;
82 static const int H_DETAIL_MAIN_TEXT = 48;
83 static const int H_DETAIL_SUB_TEXT = 42;
84 static const int GAP_H_DETAIL_TEXT = 8;
85 static const int W_DETAIL_FILEINFO_VALUE_LABEL = 650;
86 static const int H_DETAIL_FILEINFO_VALUE_LABEL = 56;
87
88 static const int X_MORE = 55;
89
90 static const int DETAIL_SUB_FONT_SIZE = 42;
91 static const int DETAIL_MAIN_FONT_SIZE = 48;
92 static const int DETAIL_COUNT_MAX = 9;
93
94 ImageViewerForm::ImageViewerForm(void)
95         : __initializeDisplayModeCurrent(APPCONTROL_MODE_NORMAL)
96         , __pHeader(null)
97         , __pFooter(null)
98         , __pScrollPanel(null)
99         , __pDetail_Label(null)
100         , __pLabelMessage(null)
101         , __pPlayButton(null)
102         , __pRenameButton(null)
103         , __pDetailFooterItem(null)
104         , __pGallery(null)
105         , __pTimer(null)
106         , __pDecodeBitmap(null)
107         , __pContextMenuMore(null)
108         , __pContextMenuCopy(null)
109         , __pContextMenuSetAs(null)
110         , __pContextMenuShare(null)
111         , __pDeletePopup(null)
112         , __visible(true)
113         , __detail(true)
114         , __startSlide(false)
115         , __requestId(0)
116         , __pPresentationModel(null)
117 {
118         AppLogDebug("ENTER");
119
120         __pDetail_FileInfo_Value_Label[0] = null;
121         __pDetail_FileInfo_Value_Label[1] = null;
122         __pDetail_FileInfo_Value_Label[2] = null;
123         __pDetail_FileInfo_Value_Label[3] = null;
124         __pDetail_FileInfo_Value_Label[4] = null;
125         __pDetail_FileInfo_Value_Label[5] = null;
126         __pDetail_FileInfo_Value_Label[6] = null;
127         __pDetail_FileInfo_Value_Label[7] = null;
128         __pDetail_FileInfo_Value_Label[8] = null;
129         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
130 }
131
132 ImageViewerForm::~ImageViewerForm(void)
133 {
134         AppLogDebug("ENTER");
135         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
136 }
137
138 result
139 ImageViewerForm::Initialize()
140 {
141         AppLogDebug("ENTER");
142         __pPresentationModel = ImageViewerPresentationModel::GetInstance();
143
144         if (__pPresentationModel->GetFileCount() > 0)
145         {
146                 if (__pPresentationModel->GetType() == APPCONTROL_DATA_SLIDE_SHOW)
147                 {
148                         __startSlide = true;
149                 }
150         }
151
152         int startIndex = __pPresentationModel->GetStartIndex();
153         String filePath = __pPresentationModel->GetFilePathAt(startIndex);
154
155         if (filePath.StartsWith(WEB_URL_HTTP, 0) == true)
156         {
157                 __initializeDisplayModeCurrent = APPCONTROL_MODE_WEB_LINK;
158         }
159         else if (__pPresentationModel->GetType() == APPCONTROL_DATA_EMAIL)
160         {
161                 __initializeDisplayModeCurrent = APPCONTROL_MODE_EMAIL;
162         }
163         else
164         {
165                 __initializeDisplayModeCurrent = APPCONTROL_MODE_NORMAL;
166         }
167
168         result r = Construct(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_HEADER | FORM_STYLE_FOOTER);
169         if (r == E_SUCCESS)
170         {
171                 SetOrientation(ORIENTATION_AUTOMATIC);
172         }
173
174         if (filePath == EMPTY_SPACE)
175         {
176                 MessageBox messageBox;
177                 messageBox.Construct(L"", ResourceManager::GetString(L"IDS_IV_POP_INVALID_IMAGE_FILE"), MSGBOX_STYLE_NONE,
178                                 3000);
179                 int modalResult = 0;
180                 messageBox.ShowAndWait(modalResult);
181
182                 UiApp* pApp = UiApp::GetInstance();
183                 pApp->Terminate();
184         }
185
186         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
187
188         return r;
189 }
190
191 result
192 ImageViewerForm::OnInitializing(void)
193 {
194         AppLogDebug("ENTER");
195         SetFormBackEventListener(this);
196         __pPresentationModel->AddListener(this);
197
198         CreateGallery();
199         InitializeDisplay(__initializeDisplayModeCurrent);
200         InitializePanelDetail();
201         InitializePopup();
202
203         if (    __initializeDisplayModeCurrent == APPCONTROL_MODE_NORMAL
204                 || __initializeDisplayModeCurrent == APPCONTROL_MODE_EMAIL)
205         {
206                 int index = __pPresentationModel->GetStartIndex();
207                 __pGallery->UpdateGallery();
208                 __pGallery->SetCurrentItemIndex(index);
209                 __pGallery->Draw();
210
211                 String filePath = __pPresentationModel->GetFilePathAt(index);
212                 __pPresentationModel->RequestImage(filePath);
213         }
214         else if (__initializeDisplayModeCurrent == APPCONTROL_MODE_WEB_LINK)
215         {
216                 RequestDecodeUrl();
217         }
218
219         if (__startSlide)
220         {
221                 __pTimer = new (std::nothrow) Timer();
222                 __pTimer->Construct(*this);
223                 __pTimer->Start(1);
224         }
225
226         result r = SetActionBarsTranslucent(FORM_ACTION_BAR_INDICATOR, true);
227         AddOrientationEventListener(*this);
228         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
229
230         return r;
231 }
232
233 result
234 ImageViewerForm::OnInitialized(void)
235 {
236         AppLogDebug("ENTER");
237         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
238
239         return E_SUCCESS;
240 }
241
242 void
243 ImageViewerForm::OnOrientationChanged(const Control &source, OrientationStatus orientationStatus)
244 {
245         AppLogDebug("ENTER");
246         if (__detail == false)
247         {
248                 ShowPanelDetail(true);
249         }
250         else
251         {
252                 ShowPanelDetail(false);
253         }
254
255         if (orientationStatus == ORIENTATION_STATUS_PORTRAIT ||
256                                 orientationStatus == ORIENTATION_STATUS_PORTRAIT_REVERSE)
257         {
258                 Rectangle clientRect = GetClientAreaBounds();
259                 Rectangle rect = GetBounds();
260
261                 __pGallery->SetBounds(Rectangle(0, -clientRect.y, rect.width, rect.height));
262                 __pPlayButton->SetBounds(Rectangle(RECT_CONTORL_BUTTON_PLAY.x, RECT_CONTORL_BUTTON_PLAY.y,
263                                 RECT_CONTORL_BUTTON_PLAY.width, RECT_CONTORL_BUTTON_PLAY.height));
264
265                 Invalidate(true);
266         }
267         else if (orientationStatus == ORIENTATION_STATUS_LANDSCAPE ||
268                         orientationStatus == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
269         {
270                 Rectangle clientRect = GetClientAreaBounds();
271                 Rectangle rect = GetBounds();
272
273                 __pGallery->SetBounds(Rectangle(0, -clientRect.y, rect.width, rect.height));
274                 __pPlayButton->SetBounds(Rectangle(RECT_LANDSCAP_CONTORL_BUTTON_PLAY.x, RECT_LANDSCAP_CONTORL_BUTTON_PLAY.y,
275                                 RECT_LANDSCAP_CONTORL_BUTTON_PLAY.width, RECT_LANDSCAP_CONTORL_BUTTON_PLAY.height));
276
277                 Invalidate(true);
278         }
279         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
280 }
281
282 void
283 ImageViewerForm::InitializeDisplay(AppControlMode status)
284 {
285         AppLogDebug("ENTER");
286         String strItemText;
287         String strItemIdxText;
288
289         __pHeader = GetHeader();
290         __pHeader->AddActionEventListener(*this);
291
292         __pFooter = GetFooter();
293         __pFooter->AddActionEventListener(*this);
294         __pFooter->RemoveAllItems();
295
296         GetHeaderString(0, strItemText, strItemIdxText);
297         Rectangle rect = GetClientAreaBounds();
298         __pHeader->SetTitleText(strItemText);
299         __pHeader->SetDescriptionText(strItemIdxText);
300
301         if (status == APPCONTROL_MODE_NORMAL)
302         {
303                 __pPlayButton = new (std::nothrow) Button();
304                 if (__pPlayButton != null)
305                 {
306                         __pPlayButton->Construct(RECT_CONTORL_BUTTON_PLAY);
307                         __pPlayButton->SetActionId(ACTION_ID_CONTORL_BUTTON_PLAY);
308                         AddControl(*__pPlayButton);
309
310                         Bitmap* pNormalBackgroundBitmap = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_PLAY);
311                         __pPlayButton->SetNormalBackgroundBitmap(*pNormalBackgroundBitmap);
312                         delete pNormalBackgroundBitmap;
313
314                         Bitmap* pPressedBackgroundBitmap = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_PLAY);
315                         __pPlayButton->SetPressedBackgroundBitmap(*pPressedBackgroundBitmap);
316                         delete pPressedBackgroundBitmap;
317
318                         __pPlayButton->AddActionEventListener(*this);
319                         __pPlayButton->SetShowState(false);
320                 }
321
322                 __pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON_TEXT);
323                 __pFooter->RemoveButtonAt(BUTTON_POSITION_LEFT);
324                 __pFooter->SetBackButton();
325
326                 FooterItem  footerItem1;
327                 footerItem1.Construct(ACTION_ID_FOOTER_BUTTON_SHARE);
328                 Bitmap* pFooterItemShareNomal =
329                                 ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_FOOTER_ICON_SHARE_NORMAL);
330                 footerItem1.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pFooterItemShareNomal);
331
332                 FooterItem  footerItem2;
333                 footerItem2.Construct(ACTION_ID_FOOTER_BUTTON_DELETE);
334                 Bitmap* pFooterItemDeleteNomal =
335                                 ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_FOOTER_ICON_DELETE_NORMAL);
336                 footerItem2.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pFooterItemDeleteNomal);
337
338                 __pFooter->AddItem(footerItem1);
339                 __pFooter->AddItem(footerItem2);
340
341                 delete pFooterItemShareNomal;
342                 delete pFooterItemDeleteNomal;
343
344                 ButtonItem buttonItemMore;
345                 buttonItemMore.Construct(BUTTON_ITEM_STYLE_ICON, ACTION_ID_FOOTER_MORE);
346                 buttonItemMore.SetBackgroundBitmap(BUTTON_ITEM_STATUS_NORMAL,
347                                 ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_MORE_NORMAL));
348                 buttonItemMore.SetBackgroundBitmap(BUTTON_ITEM_STATUS_PRESSED,
349                                 ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_MORE_PRESSED));
350                 __pFooter->SetButton(BUTTON_POSITION_LEFT, buttonItemMore);
351         }
352         else if (status == APPCONTROL_MODE_WEB_LINK)
353         {
354                 __pFooter->RemoveButtonAt(BUTTON_POSITION_LEFT);
355                 __pFooter->SetBackButton();
356
357                 FooterItem  footerItem1;
358                 footerItem1.Construct(ACTION_ID_FOOTER_BUTTON_SHARE);
359                 Bitmap* pFooterItemShareNomal =
360                                 ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_FOOTER_ICON_SHARE_NORMAL);
361                 footerItem1.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pFooterItemShareNomal);
362
363                 FooterItem  footerItem2;
364                 footerItem2.Construct(ACTION_ID_FOOTER_BUTTON_DOWNLOAD);
365                 Bitmap* pFooterItemDownlordNomal = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_DOWNLOAD);
366                 footerItem2.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pFooterItemDownlordNomal);
367
368                 __pFooter->AddItem(footerItem1);
369                 __pFooter->AddItem(footerItem2);
370
371                 delete pFooterItemShareNomal;
372                 delete pFooterItemDownlordNomal;
373
374                 ButtonItem buttonItemMore;
375                 buttonItemMore.Construct(BUTTON_ITEM_STYLE_ICON, ACTION_ID_FOOTER_MORE);
376                 buttonItemMore.SetBackgroundBitmap(BUTTON_ITEM_STATUS_NORMAL,
377                                 ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_MORE_NORMAL));
378                 buttonItemMore.SetBackgroundBitmap(BUTTON_ITEM_STATUS_PRESSED,
379                                 ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_MORE_PRESSED));
380                 __pFooter->SetButton(BUTTON_POSITION_LEFT, buttonItemMore);
381
382                 __pFooter->AddItem(footerItem1);
383                 __pFooter->AddItem(footerItem2);
384         }
385         else if (status == APPCONTROL_MODE_CROP)
386         {
387                 FooterItem  footerItem1;
388                 footerItem1.Construct(ACTION_ID_FOOTER_BUTTON_SAVE);
389                 Bitmap* pfooterItem1 = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_SAVE);
390                 footerItem1.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pfooterItem1);
391
392                 FooterItem  footerItem2;
393                 footerItem2.Construct(ACTION_ID_FOOTER_BUTTON_BACK);
394                 Bitmap* pfooterItem2 = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_X);
395                 footerItem2.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pfooterItem2);
396
397                 __pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON);
398                 __pFooter->AddItem(footerItem1);
399                 __pFooter->AddItem(footerItem2);
400
401                 delete pfooterItem1;
402                 delete pfooterItem2;
403         }
404         else if (status == APPCONTROL_MODE_EMAIL)
405         {
406                 __pPlayButton = new (std::nothrow) Button();
407                 if (__pPlayButton != null)
408                 {
409                         __pPlayButton->Construct(RECT_CONTORL_BUTTON_PLAY);
410                         __pPlayButton->SetActionId(ACTION_ID_CONTORL_BUTTON_PLAY);
411                         AddControl(*__pPlayButton);
412
413                         Bitmap* pNormalBackgroundBitmap = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_PLAY);
414                         __pPlayButton->SetNormalBackgroundBitmap(*pNormalBackgroundBitmap);
415                         delete pNormalBackgroundBitmap;
416
417                         Bitmap* pPressedBackgroundBitmap = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_PLAY);
418                         __pPlayButton->SetPressedBackgroundBitmap(*pPressedBackgroundBitmap);
419                         delete pPressedBackgroundBitmap;
420
421                         __pPlayButton->AddActionEventListener(*this);
422                         __pPlayButton->SetShowState(false);
423                 }
424
425                 __pFooter->SetBackButton();
426         }
427
428         String filePath = __pPresentationModel->GetFilePathAt(0);
429         ContentType contentType = ContentManagerUtil::CheckContentType(filePath);
430         if (contentType == CONTENT_TYPE_VIDEO)
431         {
432                 __pPlayButton->SetShowState(true);
433         }
434         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
435 }
436
437 void
438 ImageViewerForm::GetHeaderString(int index, String &fileName, String &page)
439 {
440         AppLogDebug("ENTER");
441         int allCount = __pPresentationModel->GetFileCount();
442         String pStr = __pPresentationModel->GetFilePathAt(index);
443         fileName = __pPresentationModel->GetFileName(pStr);
444         page.Format(FORMAT_BUFFER_SIZE, L"%d/%d", index + 1, allCount);
445         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
446 }
447
448 result
449 ImageViewerForm::DeleteImageFile()
450 {
451         AppLogDebug("ENTER");
452         int currentIndex = __pGallery->GetCurrentItemIndex();
453
454         String strItemText(EMPTY_SPACE);
455         String strItemIdxText(EMPTY_SPACE);
456         int countPath = __pPresentationModel->GetFileCount();
457         String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
458         result r = E_SUCCESS;
459         if (filePath.GetLength() == 0)
460         {
461                 UiApp* pApp = UiApp::GetInstance();
462                 pApp->Terminate();
463                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
464
465                 return E_FAILURE;
466         }
467
468         if (filePath.StartsWith(Environment::GetMediaPath(), 0) == true
469                         || filePath.StartsWith(Environment::GetExternalStoragePath(), 0) == true)
470         {
471                 ContentId contentId = __pPresentationModel->GetFileContentId(filePath);
472                 ContentManager contentManager;
473                 contentManager.Construct();
474                 r = contentManager.DeleteContent(contentId);
475                 if (r != E_SUCCESS)
476                 {
477                         r = File::Remove(filePath);
478                         if (r != E_SUCCESS)
479                         {
480                                 MessageBox messageBox;
481                                 messageBox.Construct(L"", ResourceManager::GetString(L"IDS_COM_POP_DELETE_FAILED"),
482                                                 MSGBOX_STYLE_NONE, 3000);
483                                 int modalResult = 0;
484                                 messageBox.ShowAndWait(modalResult);
485                                 AppLogDebug("EXIT 4(%s)", GetErrorMessage(GetLastResult()));
486
487                                 return r;
488                         }
489                 }
490         }
491         else
492         {
493                 r = File::Remove(filePath);
494         }
495
496         __pPresentationModel->DeleteFilePathAt(currentIndex);
497         if (countPath == 1)
498         {
499                 UiApp* pApp = UiApp::GetInstance();
500                 pApp->Terminate();
501                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
502
503                 return r;
504         }
505         else if ((countPath - 1) == currentIndex)
506         {
507                 __pGallery->SetCurrentItemIndex(--currentIndex);
508         }
509
510         __pGallery->UpdateGallery();
511         filePath = __pPresentationModel->GetFilePathAt(currentIndex);
512         __pPresentationModel->RequestImage(filePath);
513
514         GetHeaderString(__pGallery->GetCurrentItemIndex(), strItemText, strItemIdxText);
515         __pHeader->SetTitleText(strItemText);
516         __pHeader->SetDescriptionText(strItemIdxText);
517
518         if (__visible == true)
519         {
520                 ImageViewerMediaType mediaType = CommonUtil::GetMediaType(filePath);
521
522                 if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE)
523                 {
524                         __pPlayButton->SetShowState(false);
525                 }
526                 else
527                 {
528                         __pPlayButton->SetShowState(true);
529                 }
530         }
531         Invalidate(true);
532         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
533
534         return r;
535 }
536
537 void
538 ImageViewerForm::CallVideoPlayer(void)
539 {
540         AppLogDebug("ENTER");
541         int index = __pGallery->GetCurrentItemIndex();
542         String filePath = __pPresentationModel->GetFilePathAt(index);
543
544         HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
545         pDataList->Construct();
546         pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_TYPE),
547                         new (std::nothrow) String(APPCONTROL_DATA_VIDEO));
548         pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), new (std::nothrow) String(filePath));
549
550         __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_VIDEO_PLAYER,
551                         APPCONTROL_OPERATION_ID_PLAY, pDataList, this);
552         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
553 }
554
555 void
556 ImageViewerForm::CreateGallery(void)
557 {
558         AppLogDebug("ENTER");
559         Rectangle clientRect = GetClientAreaBounds();
560         Rectangle rect = GetBounds();
561
562         __pGallery = new (std::nothrow) Gallery();
563         __pGallery->Construct(Rectangle(0, -clientRect.y, rect.width, rect.height));
564         __pGallery->SetName(L"GalleryControl");
565         __pGallery->SetItemProvider(*this);
566         __pGallery->AddGalleryEventListener(*this);
567         AddControl(*__pGallery);
568         __pGallery->SetTextOfEmptyGallery(ResourceManager::GetString(L"IDS_COM_BODY_LOADING"));
569
570         SlideShowTransitionEffect effect = __pPresentationModel->GetTransitionEffectOfSlideShow();
571
572         switch (effect)
573         {
574         case SLIDE_SHOW_TRANSITION_EFFECT_PAGE:
575                 __pGallery->SetSlideShowAnimation(Controls::GALLERY_ANIMATION_PAGE);
576                 break;
577         case SLIDE_SHOW_TRANSITION_EFFECT_DISSOLVE:
578                 __pGallery->SetSlideShowAnimation(Controls::GALLERY_ANIMATION_DISSOLVE);
579                 break;
580         case SLIDE_SHOW_TRANSITION_EFFECT_ZOOM:
581                 __pGallery->SetSlideShowAnimation(Controls::GALLERY_ANIMATION_ZOOM);
582                 break;
583         case SLIDE_SHOW_TRANSITION_EFFECT_SLIDE:
584                 break;
585         }
586
587         __pGallery->SetSlideShowViewDuration(__pPresentationModel->GetDurationOfSlideShow());
588
589         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
590 }
591
592 result
593 ImageViewerForm::InitializePanelDetail()
594 {
595         AppLogDebug("ENTER");
596          __pScrollPanel = new (std::nothrow) ScrollPanel();
597
598          String arrayId[DETAIL_COUNT_MAX] =
599          {
600                 L"IDS_COM_BODY_DETAILS_NAME", L"IDS_IV_BODY_FILE_FORMAT", L"IDS_IV_BODY_DATE_CREATED",
601                 L"IDS_COM_BODY_SIZE", L"IDS_IV_BODY_RESOLUTION", L"IDS_COM_BODY_LOCATION",
602                 L"IDS_COM_BODY_LATITUDE", L"IDS_COM_BODY_LONGITUDE", L"IDS_IV_BODY_FILE_LOCATION"
603          };
604
605         if (__pScrollPanel == null)
606         {
607                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
608
609                 return E_INVALID_STATE;
610         }
611
612         result r = __pScrollPanel->Construct(RECT_DETAILS_CONTORL_PANEL);
613         if (r != E_SUCCESS)
614         {
615                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
616
617                 return E_INVALID_STATE;
618         }
619
620         __pDetail_Label = new (std::nothrow) Label();
621         __pDetail_Label->Construct(RECT_DETAILS_CONTORL_LABEL, ResourceManager::GetString(L"IDS_COM_BODY_DETAILS"));
622         __pScrollPanel->AddControl(*__pDetail_Label);
623         __pDetail_Label->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
624         __pDetail_Label->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
625         __pDetail_Label->SetTextColor(Color::GetColor(COLOR_ID_WHITE));
626         __pDetail_Label->SetTextConfig(DETAIL_MAIN_FONT_SIZE, LABEL_TEXT_STYLE_NORMAL);
627
628         for (int i = 0; i < DETAIL_COUNT_MAX; ++i)
629         {
630                 __pDetail_FileInfo_Label[i] = new (std::nothrow) Label();
631                 __pDetail_FileInfo_Label[i]->Construct(
632                                 Rectangle(X_DETAIL_FILEINFO_LABEL,
633                                 GAP_H_DETAIL_TEXT * (i + 1) + H_DETAIL_MAIN_TEXT + (H_DETAIL_MAIN_TEXT + H_DETAIL_SUB_TEXT) * i,
634                                 W_DETAIL_FILEINFO_LABEL, H_DETAIL_FILEINFO_LABEL), ResourceManager::GetString(arrayId[i]));
635                 __pScrollPanel->AddControl(*__pDetail_FileInfo_Label[i]);
636
637                 __pDetail_FileInfo_Label[i]->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
638                 __pDetail_FileInfo_Label[i]->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
639                 __pDetail_FileInfo_Label[i]->SetTextColor(Color::GetColor(COLOR_ID_GREY));
640                 __pDetail_FileInfo_Label[i]->SetTextConfig(DETAIL_SUB_FONT_SIZE, LABEL_TEXT_STYLE_NORMAL);
641
642                 __pDetail_FileInfo_Value_Label[i] = new (std::nothrow) Label();
643                 __pDetail_FileInfo_Value_Label[i]->Construct(
644                                 Rectangle(X_DETAIL_FILEINFO_LABEL,
645                                 GAP_H_DETAIL_TEXT * (i + 1) + H_DETAIL_MAIN_TEXT + (H_DETAIL_MAIN_TEXT * i) + H_DETAIL_SUB_TEXT * (i + 1),
646                                 W_DETAIL_FILEINFO_VALUE_LABEL, H_DETAIL_FILEINFO_VALUE_LABEL), L"");
647                 __pScrollPanel->AddControl(*__pDetail_FileInfo_Value_Label[i]);
648
649                 __pDetail_FileInfo_Value_Label[i]->SetTextVerticalAlignment(ALIGNMENT_BOTTOM);
650                 __pDetail_FileInfo_Value_Label[i]->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
651                 __pDetail_FileInfo_Value_Label[i]->SetTextColor(Color::GetColor(COLOR_ID_WHITE));
652                 __pDetail_FileInfo_Value_Label[i]->SetTextConfig(DETAIL_MAIN_FONT_SIZE, LABEL_TEXT_STYLE_NORMAL);
653         }
654
655         __pScrollPanel->SetBackgroundColor(COLOR_HEADER_CONTORL_PANEL);
656         __pScrollPanel->SetShowState(false);
657
658         AddControl(*__pScrollPanel);
659         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
660
661         return E_SUCCESS;
662 }
663
664 result
665 ImageViewerForm::InitializePopup(void)
666 {
667         AppLogDebug("ENTER");
668         if (__pDeletePopup == null)
669         {
670                 __pDeletePopup = new (std::nothrow) Popup();
671                 __pDeletePopup->Construct(false, Dimension(W_DELETE_POPUP, H_DELETE_POPUP));
672
673                 Rectangle popupClientBounds = __pDeletePopup->GetClientAreaBounds();
674
675                 Label* pLabel = new (std::nothrow) Label();
676                 pLabel->Construct(Rectangle(0, 0, popupClientBounds.width, H_DELETE_LABEL),
677                                 ResourceManager::GetString(L"IDS_COM_BODY_DELETE") + L"?");
678
679                 Button* pDeleteButton = new (std::nothrow) Button();
680                 pDeleteButton->Construct(
681                                 Rectangle(0, Y_DELETE_BUTTON, popupClientBounds.width / 2 - GAP_W_POPUP_ITEM, H_DELETE_BUTTON),
682                                 ResourceManager::GetString(L"IDS_COM_BODY_DELETE"));
683                 pDeleteButton->SetActionId(ACTION_ID_DELETE_POPUP_DEL);
684                 pDeleteButton->AddActionEventListener(*this);
685
686                 Button* pCancelButton = new (std::nothrow) Button();
687                 pCancelButton->Construct(
688                                 Rectangle(popupClientBounds.width / 2 + GAP_W_POPUP_ITEM,
689                                                 Y_DELETE_BUTTON, popupClientBounds.width / 2 - GAP_W_POPUP_ITEM, H_DELETE_BUTTON),
690                                                 ResourceManager::GetString(L"IDS_COM_SK_CANCEL"));
691                 pCancelButton->SetActionId(ACTION_ID_DELETE_POPUP_CANCEL);
692                 pCancelButton->AddActionEventListener(*this);
693
694                 __pDeletePopup->AddControl(*pLabel);
695                 __pDeletePopup->AddControl(*pDeleteButton);
696                 __pDeletePopup->AddControl(*pCancelButton);
697         }
698         else
699         {
700                 __pDeletePopup->SetShowState(true);
701                 __pDeletePopup->Show();
702         }
703         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
704
705         return E_SUCCESS;
706 }
707
708 result
709 ImageViewerForm::InitializeContextMenuMore(void)
710 {
711         AppLogDebug("ENTER");
712         int currentIndex = __pGallery->GetCurrentItemIndex();
713         String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
714
715         ImageViewerMediaType mediaType = CommonUtil::GetMediaType(filePath);
716
717         if (__pContextMenuMore != null)
718         {
719                 delete __pContextMenuMore;
720                 __pContextMenuMore = null;
721         }
722
723         __pContextMenuMore = new (std::nothrow) ContextMenu();
724
725         __pContextMenuMore->Construct(Point(X_MORE, GetClientAreaBounds().y + GetClientAreaBounds().height),
726                                 CONTEXT_MENU_STYLE_LIST, CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD);
727
728         if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE)
729         {
730                 __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_IV_OPT_SET_AS"),
731                                 ACTION_ID_CONTEXTMENU_SET_AS);
732         }
733
734         if (__pGallery->GetItemCount() > 1)
735         {
736                 __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_IV_OPT_SLIDE_SHOW"),
737                                 ACTION_ID_FOOTER_BUTTON_SLIDE);
738         }
739         __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_DETAILS"),
740                         ACTION_ID_FOOTER_BUTTON_DETAILS);
741         __pContextMenuMore->SetShowState(false);
742         __pContextMenuMore->AddActionEventListener(*this);
743         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
744
745         return E_SUCCESS;
746 }
747
748 result
749 ImageViewerForm::InitializeContextMenuSetAs(void)
750 {
751         AppLogDebug("ENTER");
752
753         if (__pContextMenuSetAs != null)
754         {
755                 delete __pContextMenuSetAs;
756                 __pContextMenuSetAs = null;
757         }
758
759         __pContextMenuSetAs = new (std::nothrow) ContextMenu();
760         __pContextMenuSetAs->Construct(Point(X_MORE, GetClientAreaBounds().y + GetClientAreaBounds().height),
761                         CONTEXT_MENU_STYLE_LIST, CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD);
762
763         __pContextMenuSetAs->AddItem(ResourceManager::GetString(L"IDS_IV_HEADER_HOME_SCREEN_WALLPAPER_ABB"),
764                         ACTION_ID_CONTEXTMENU_HOME);
765         __pContextMenuSetAs->AddItem(ResourceManager::GetString(L"IDS_IV_HEADER_LOCK_SCREEN_WALLPAPER_ABB"),
766                         ACTION_ID_CONTEXTMENU_LOCK);
767         __pContextMenuSetAs->AddItem(ResourceManager::GetString(L"IDS_IV_BODY_CALLER_IMAGE"),
768                         ACTION_ID_CONTEXTMENU_CALLER);
769         __pContextMenuSetAs->AddActionEventListener(*this);
770         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
771
772         return E_SUCCESS;
773 }
774
775 result
776 ImageViewerForm::InitializeContextMenuShare(void)
777 {
778         AppLogDebug("ENTER");
779         if (__pContextMenuShare != null)
780         {
781                 delete __pContextMenuShare;
782                 __pContextMenuShare = null;
783         }
784         __pContextMenuShare = new (std::nothrow) ContextMenu();
785         __pContextMenuShare->Construct(Point((GetClientAreaBounds().width - (X_MORE * 4)) / 4 + X_MORE * 2,
786                         GetClientAreaBounds().y + GetClientAreaBounds().height), CONTEXT_MENU_STYLE_LIST,
787                         CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD);
788
789         __pContextMenuShare->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_EMAIL"),ACTION_ID_CONTEXTMENU_EMAIL);
790         __pContextMenuShare->AddActionEventListener(*this);
791         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
792
793         return E_SUCCESS;
794 }
795
796 long long
797 ImageViewerForm::GetFileSize(String filePath)
798 {
799         AppLogDebug("ENTER");
800         FileAttributes attr;
801         long long size = 0;
802
803         result r = File::GetAttributes(filePath, attr);
804         if (r != E_SUCCESS)
805         {
806                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
807
808                 return 0;
809         }
810         size = attr.GetFileSize();
811         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
812
813         return size;
814 }
815
816 result
817 ImageViewerForm::SetDetailInfo(void)
818 {
819         AppLogDebug("ENTER");
820
821         Rectangle clientRect = GetClientAreaBounds();
822         AppLogDebug("PORTRAIT GetClientAreaBounds(%d %d %d %d)", clientRect.x, clientRect.y, clientRect.width, clientRect.height);
823         OrientationStatus currentOrientaton = GetOrientationStatus();
824
825         if (currentOrientaton == ORIENTATION_STATUS_LANDSCAPE || currentOrientaton == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
826         {
827                 __pScrollPanel->SetBounds(Rectangle(0, 0, clientRect.width, RECT_LANDSCAPE_DETAILS_CONTORL_PANEL.height));
828         }
829         else
830         {
831                 __pScrollPanel->SetBounds(0, 0, clientRect.width, RECT_DETAILS_CONTORL_PANEL.height);
832         }
833
834         int currentIndex = __pGallery->GetCurrentItemIndex();
835         String strFilePath = __pPresentationModel->GetFilePathAt(currentIndex);
836
837         ImageViewerMediaType mediaType = CommonUtil::GetMediaType(strFilePath);
838
839         String strResult[DETAIL_COUNT_MAX] = {EMPTY_SPACE, };
840
841         strResult[0] = __pPresentationModel->GetFileName(strFilePath);
842         strResult[1] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
843
844         FileAttributes attr;
845         result r = File::GetAttributes(strFilePath, attr);
846         if (r == E_SUCCESS)
847         {
848                 long long nSize = attr.GetFileSize();
849                 DateTime dateTime = attr.GetDateTime();
850                 strResult[2] = dateTime.ToString();
851
852                 if (nSize > SINGLE_GIGA_BYTE)
853                 {
854                         strResult[3].Format(FORMAT_BUFFER_SIZE, L"%lld GB", nSize / SINGLE_GIGA_BYTE);
855                 }
856                 else if (nSize > SINGLE_MEGA_BYTE)
857                 {
858                         strResult[3].Format(FORMAT_BUFFER_SIZE, L"%lld MB", nSize / SINGLE_MEGA_BYTE);
859                 }
860                 else if (nSize > SINGLE_KILO_BYTE)
861                 {
862                         strResult[3].Format(FORMAT_BUFFER_SIZE, L"%lld KB", nSize / SINGLE_KILO_BYTE);
863                 }
864                 else
865                 {
866                         strResult[3].Format(FORMAT_BUFFER_SIZE, L"%lld Byte", nSize);
867                 }
868         }
869         else
870         {
871                 strResult[2] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
872                 strResult[3] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
873         }
874
875         strResult[4] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
876         strResult[5] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
877         strResult[6] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
878         strResult[7] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
879         strResult[8] = strFilePath;
880
881         if (__initializeDisplayModeCurrent == APPCONTROL_MODE_WEB_LINK)
882         {
883                 strResult[0] = __downLordFileName;
884         }
885         else if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE)
886         {
887                 ImageMetadata* pImgMeta = ContentManagerUtil::GetImageMetaN(strFilePath);
888
889                 if (pImgMeta != null)
890                 {
891                         ImageContentInfo imageContentInfo;
892                         r = imageContentInfo.Construct(&strFilePath);
893                         if (r == E_SUCCESS)
894                         {
895                                 strResult[1] = imageContentInfo.GetMediaFormat();
896                                 strResult[4].Format(FORMAT_BUFFER_SIZE, L"%d x %d", pImgMeta->GetWidth(),
897                                                 pImgMeta->GetHeight());
898
899                                 if (imageContentInfo.GetLocationTag() != EMPTY_SPACE)
900                                 {
901                                         strResult[5].Format(FORMAT_BUFFER_SIZE, L"%ls", imageContentInfo.GetLocationTag().GetPointer());
902                                 }
903
904                                 if (pImgMeta->GetLatitude() > 1.0 && pImgMeta->GetLongitude() > 1.0)
905                                 {
906                                         strResult[6].Format(FORMAT_BUFFER_SIZE, L"%f", pImgMeta->GetLatitude());
907                                         strResult[7].Format(FORMAT_BUFFER_SIZE, L"%f", pImgMeta->GetLongitude());
908                                 }
909
910                                 strResult[8] = imageContentInfo.GetContentPath();
911                         }
912                         delete pImgMeta;
913                 }
914         }
915         else if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_VIDEO)
916         {
917                 VideoMetadata* pVideoMeta = ContentManagerUtil::GetVideoMetaN(strFilePath);
918                 if (pVideoMeta != null)
919                 {
920                         VideoContentInfo videoContentInfo;
921                         r = videoContentInfo.Construct(&strFilePath);
922                         if (r == E_SUCCESS)
923                         {
924                                 strResult[1] = videoContentInfo.GetMediaFormat();
925                                 strResult[4].Format(FORMAT_BUFFER_SIZE, L"%d x %d", pVideoMeta->GetWidth(),
926                                                 pVideoMeta->GetHeight());
927                                 if (videoContentInfo.GetLocationTag() != EMPTY_SPACE)
928                                 {
929                                         strResult[5].Format(FORMAT_BUFFER_SIZE, L"%ls", videoContentInfo.GetLocationTag().GetPointer());
930                                 }
931
932                                 strResult[8] = videoContentInfo.GetContentPath();
933                         }
934                 }
935         }
936
937         for (int i = 0; i < DETAIL_COUNT_MAX; ++i)
938         {
939                 __pDetail_FileInfo_Value_Label[i]->SetBounds(X_DETAIL_FILEINFO_LABEL, GAP_H_DETAIL_TEXT * (i + 1) + H_DETAIL_MAIN_TEXT + (H_DETAIL_MAIN_TEXT * i) + H_DETAIL_SUB_TEXT * (i + 1),
940                                                                                                                                 clientRect.width - GAP_LABEL_END, H_DETAIL_FILEINFO_VALUE_LABEL);
941                 __pDetail_FileInfo_Value_Label[i]->SetText(strResult[i]);
942                 __pDetail_FileInfo_Value_Label[i]->RequestRedraw();
943         }
944
945         if (__initializeDisplayModeCurrent == APPCONTROL_MODE_WEB_LINK)
946         {
947                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
948                 return r;
949         }
950
951         if (__pRenameButton == null)
952         {
953                 __pRenameButton = new (std::nothrow) Button();
954                 Rectangle rect = GetBounds();
955                 __pRenameButton->Construct(Rectangle(rect.width - W_RENAME_BUTTON, Y_RENAME_BUTTON, W_RENAME_BUTTON, H_RENAME_BUTTON));
956                 __pRenameButton->SetActionId(ACTION_ID_PANEL_HEADER_DETAILS_RENAME);
957
958                 Bitmap* pIcon = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_EDIT_NAME);
959                 Bitmap* pIconBackground =
960                                 ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_EDIT_NAME_NORMAL_BACKGROUND);
961                 Bitmap* pIconPressed =
962                                 ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_EDIT_NAME_NORMAL_BACKGROUND_PRESS);
963
964                 if (pIcon != null && pIconPressed != null && pIconBackground != null)
965                 {
966                         __pRenameButton->SetNormalBackgroundBitmap(*pIconBackground);
967                         __pRenameButton->SetPressedBackgroundBitmap(*pIconPressed);
968                         Point iconPosition(0, 0);
969                         __pRenameButton->SetNormalBitmap(iconPosition, *pIcon);
970                         __pRenameButton->SetPressedBitmap(iconPosition, *pIconPressed);
971                 }
972                 else
973                 {
974                         __pRenameButton->SetColor(BUTTON_STATUS_NORMAL, COLOR_HEADER_BUTTON1);
975                         __pRenameButton->SetColor(BUTTON_STATUS_PRESSED, COLOR_HEADER_BUTTON1);
976                 }
977                 delete pIcon;
978                 delete pIconPressed;
979                 delete pIconBackground;
980
981                 __pScrollPanel->AddControl(*__pRenameButton);
982                 __pRenameButton->SetColor(BUTTON_STATUS_NORMAL, COLOR_HEADER_BUTTON1);
983                 __pRenameButton->AddActionEventListener(*this);
984         }
985         else
986         {
987                 Rectangle rect = GetBounds();
988                 __pRenameButton->SetBounds(Rectangle(rect.width - W_RENAME_BUTTON, Y_RENAME_BUTTON, W_RENAME_BUTTON, H_RENAME_BUTTON));
989         }
990         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
991
992         return r;
993 }
994
995 result
996 ImageViewerForm::ShowPanelDetail(bool showStatus)
997 {
998         AppLogDebug("ENTER");
999         if (showStatus)
1000         {
1001                 SetDetailInfo();
1002                 __pScrollPanel->SetShowState(true);
1003                 __detail = false;
1004         }
1005         else
1006         {
1007                 __pScrollPanel->SetShowState(false);
1008                 __detail = true;
1009         }
1010         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1011
1012         return E_SUCCESS;
1013 }
1014
1015 result
1016 ImageViewerForm::ChangeFooterItem(bool isChanged, Footer* pFooter, int position)
1017 {
1018         AppLogDebug("ENTER");
1019         FooterItem footerItem;
1020         footerItem.Construct(ACTION_ID_FOOTER_BUTTON_DETAILS);
1021         Bitmap* pfooterItem = null;
1022
1023         if (isChanged)
1024         {
1025                 pfooterItem = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_DETAILS_CLOSE);
1026                 footerItem.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pfooterItem);
1027         }
1028         else
1029         {
1030                 pfooterItem = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_DETAILS);
1031                 footerItem.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pfooterItem);
1032         }
1033
1034         pFooter->SetItemAt(position, footerItem);
1035         pFooter->Invalidate(true);
1036
1037         delete pfooterItem;
1038         pfooterItem = null;
1039         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1040
1041         return E_SUCCESS;
1042 }
1043
1044 void
1045 ImageViewerForm::DownloadFile(void)
1046 {
1047         AppLogDebug("ENTER");
1048         String DestPath = App::GetInstance()->GetAppRootPath() + TEMP_FILE_PATH_WEB_FILE;
1049         if (File::IsFileExist(DestPath) == false)
1050         {
1051                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1052                 return;
1053         }
1054
1055         ContentId contentId;
1056         ContentManager contentManager;
1057         contentManager.Construct();
1058
1059         ImageContentInfo imageContentInfo;
1060         imageContentInfo.Construct(null);
1061
1062         imageContentInfo.SetKeyword(L"platform, tizen");
1063         String sourcePath = DestPath;
1064         String destPath = Environment::GetMediaPath();
1065         destPath.Append(FOLDER_PATH_DOWNLOADS);
1066         destPath.Append(__downLordFileName);
1067
1068         contentId = contentManager.CreateContent(sourcePath, destPath, true, &imageContentInfo);
1069         ImageViewerForm::OnFormBackRequested(*this);
1070         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1071 }
1072
1073 int
1074 ImageViewerForm::GetItemCount(void)
1075 {
1076         AppLogDebug("ENTER");
1077         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1078
1079         return __pPresentationModel->GetFileCount();
1080 }
1081
1082 GalleryItem*
1083 ImageViewerForm::CreateItem(int index)
1084 {
1085         AppLogDebug("ENTER : index(%d)", index);
1086         GalleryItem* pGallery = new (std::nothrow) GalleryItem();
1087
1088         String filePath = __pPresentationModel->GetFilePathAt(index);
1089         ImageInfo* pImageInfo = __pPresentationModel->GetImageCacheAt(index);
1090         Bitmap* pBitmap = pImageInfo->GetBitmapN();
1091         if (pBitmap == null)
1092         {
1093                 pBitmap = GetQuickThumbnailN(filePath);
1094
1095                 if (pBitmap == null)
1096                 {
1097                         pBitmap = new (std::nothrow) Bitmap();
1098                         pBitmap->Construct(DUMMY_IMAGE_DIMENSION, BITMAP_PIXEL_FORMAT_RGB565);
1099                 }
1100         }
1101         pGallery->Construct(*pBitmap, filePath);
1102         delete pBitmap;
1103     AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1104
1105         return pGallery;
1106 }
1107
1108 bool
1109 ImageViewerForm::DeleteItem(int index, GalleryItem* pItem)
1110 {
1111         AppLogDebug("ENTER index(%d)", index);
1112         ImageInfo* pImageInfo = __pPresentationModel->GetImageCacheAt(index);
1113         pImageInfo->ClearBitmap();
1114         delete pItem;
1115         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1116
1117         return true;
1118 }
1119
1120 void
1121 ImageViewerForm::OnGalleryCurrentItemChanged(Gallery& view, int index)
1122 {
1123         AppLogDebug("ENTER index(%d)", index);
1124
1125         String filePath = __pPresentationModel->GetFilePathAt(index);
1126         AppLogDebug("ENTER index(%d) filePath(%ls)", index, filePath.GetPointer());
1127         __pPresentationModel->RequestImage(filePath);
1128
1129         String strItemText;
1130         String strItemIdxText;
1131         GetHeaderString(__pGallery->GetCurrentItemIndex(), strItemText, strItemIdxText);
1132         __pHeader->SetTitleText(strItemText);
1133         __pHeader->SetDescriptionText(strItemIdxText);
1134
1135         if (__visible == true)
1136         {
1137                 ImageViewerMediaType mediaType = CommonUtil::GetMediaType(filePath);
1138                 if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_VIDEO)
1139                 {
1140                         __pPlayButton->SetShowState(true);
1141                 }
1142                 else
1143                 {
1144                         __pPlayButton->SetShowState(false);
1145                 }
1146         }
1147
1148         Invalidate(true);
1149         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1150 }
1151
1152 void
1153 ImageViewerForm::OnGalleryItemClicked(Gallery& view, int index)
1154 {
1155         AppLogDebug("ENTER");
1156
1157         String filePath = __pPresentationModel->GetFilePathAt(index);
1158         ContentType contentType = ContentManagerUtil::CheckContentType(filePath);
1159
1160         if (__visible == true)
1161         {
1162                 if (contentType == CONTENT_TYPE_VIDEO)
1163                 {
1164                         __pPlayButton->SetShowState(false);
1165                 }
1166
1167                 SetActionBarsVisible(FORM_ACTION_BAR_INDICATOR | FORM_ACTION_BAR_HEADER | FORM_ACTION_BAR_FOOTER, false);
1168                 __visible = false;
1169         }
1170         else
1171         {
1172                 if (contentType == CONTENT_TYPE_VIDEO)
1173                 {
1174                         __pPlayButton->SetShowState(true);
1175                 }
1176
1177                 SetActionBarsVisible(FORM_ACTION_BAR_INDICATOR | FORM_ACTION_BAR_HEADER | FORM_ACTION_BAR_FOOTER, true);
1178                 __visible = true;
1179
1180                 __pPlayButton->SetPosition(__pPlayButton->GetPosition().x, __pPlayButton->GetPosition().y - 1);
1181                 __pPlayButton->SetPosition(__pPlayButton->GetPosition().x, __pPlayButton->GetPosition().y + 1);
1182         }
1183
1184         Rectangle clientRect = GetClientAreaBounds();
1185         Rectangle rect = GetBounds();
1186         __pGallery->SetBounds(Rectangle(0, -clientRect.y, rect.width, rect.height));
1187         Invalidate(true);
1188         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1189 }
1190
1191 void
1192 ImageViewerForm::OnGallerySlideShowStarted(Gallery& gallery)
1193 {
1194         AppLogDebug("ENTER");
1195         PowerManager::KeepScreenOnState(true, false);
1196         if (__visible  == true)
1197         {
1198                 SetActionBarsVisible(FORM_ACTION_BAR_INDICATOR | FORM_ACTION_BAR_HEADER | FORM_ACTION_BAR_FOOTER, false);
1199
1200                 int index = __pGallery->GetCurrentItemIndex();
1201                 String filePath = __pPresentationModel->GetFilePathAt(index);
1202                 ContentType contentType = ContentManagerUtil::CheckContentType(filePath);
1203
1204                 if (contentType == CONTENT_TYPE_VIDEO)
1205                 {
1206                         __pPlayButton->SetShowState(false);
1207                 }
1208
1209                 __visible = false;
1210         }
1211
1212         Rectangle clientRect = GetClientAreaBounds();
1213         Rectangle rect = GetBounds();
1214         __pGallery->SetBounds(Rectangle(0, -clientRect.y, rect.width, rect.height));
1215         Invalidate(true);
1216         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1217 }
1218
1219 void
1220 ImageViewerForm::OnGallerySlideShowStopped(Gallery& gallery)
1221 {
1222         AppLogDebug("ENTER");
1223         PowerManager::KeepScreenOnState(false, true);
1224         int index = __pGallery->GetCurrentItemIndex();
1225
1226         if (__visible == false)
1227         {
1228                 SetActionBarsVisible(FORM_ACTION_BAR_INDICATOR | FORM_ACTION_BAR_HEADER | FORM_ACTION_BAR_FOOTER, true);
1229
1230                 String filePath = __pPresentationModel->GetFilePathAt(index);
1231                 ContentType contentType = ContentManagerUtil::CheckContentType(filePath);
1232                 if (contentType == CONTENT_TYPE_VIDEO)
1233                 {
1234                         __pPlayButton->SetShowState(true);
1235                 }
1236
1237                 __pPlayButton->SetPosition(__pPlayButton->GetPosition().x, __pPlayButton->GetPosition().y - 1);
1238                 __pPlayButton->SetPosition(__pPlayButton->GetPosition().x, __pPlayButton->GetPosition().y + 1);
1239
1240                 __visible = true;
1241         }
1242
1243         String strItemText;
1244         String strItemIdxText;
1245         GetHeaderString(index, strItemText, strItemIdxText);
1246         __pHeader->SetTitleText(strItemText);
1247         __pHeader->SetDescriptionText(strItemIdxText);
1248
1249         Rectangle clientRect = GetClientAreaBounds();
1250         Rectangle rect = GetBounds();
1251         __pGallery->SetBounds(Rectangle(0, -clientRect.y, rect.width, rect.height));
1252
1253         Invalidate(true);
1254         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1255 }
1256
1257 void
1258 ImageViewerForm::OnUpdateContentList(void)
1259 {
1260 }
1261
1262 result
1263 ImageViewerForm::OnTerminating(void)
1264 {
1265         AppLogDebug("ENTER");
1266
1267         if (__pTimer != null)
1268         {
1269                 __pTimer->Cancel();
1270                 delete __pTimer;
1271                 __pTimer = null;
1272         }
1273
1274         __pPresentationModel->ClearImageRequests();
1275         __pPresentationModel->RemoveListener(*this);
1276
1277         if (__pContextMenuCopy != null)
1278         {
1279                 delete __pContextMenuCopy;
1280                 __pContextMenuCopy = null;
1281         }
1282
1283         if (__pContextMenuSetAs != null)
1284         {
1285                 delete __pContextMenuSetAs;
1286                 __pContextMenuSetAs = null;
1287         }
1288
1289         if (__pDeletePopup != null)
1290         {
1291                 delete __pDeletePopup;
1292                 __pDeletePopup = null;
1293         }
1294
1295         if (__pContextMenuShare != null)
1296         {
1297                 delete __pContextMenuShare;
1298                 __pContextMenuShare = null;
1299         }
1300
1301         if (__pContextMenuMore != null)
1302         {
1303                 delete __pContextMenuMore;
1304                 __pContextMenuMore = null;
1305         }
1306
1307         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1308
1309         return E_SUCCESS;
1310 }
1311
1312 void
1313 ImageViewerForm::OnActionPerformed(const Control& source, int actionId)
1314 {
1315         AppLogDebug("ENTER actionId(%d)", actionId);
1316         SceneManager* pSceneManager = SceneManager::GetInstance();
1317         InitShowGallery();
1318
1319         switch (actionId)
1320         {
1321         case ACTION_ID_FOOTER_MORE:
1322         {
1323                 InitializeContextMenuMore();
1324
1325                 __pContextMenuMore->SetShowState(true);
1326                 __pContextMenuMore->Show();
1327         }
1328                 break;
1329         case ACTION_ID_CONTEXTMENU_SET_AS:
1330                 InitializeContextMenuSetAs();
1331
1332                 __pContextMenuSetAs->SetShowState(true);
1333                 __pContextMenuSetAs->Show();
1334                 break;
1335         case ACTION_ID_FOOTER_BUTTON_SHARE:
1336                 InitializeContextMenuShare();
1337
1338                 __pContextMenuShare->SetShowState(true);
1339                 __pContextMenuShare->Show();
1340                 break;
1341         case ACTION_ID_FOOTER_BUTTON_DELETE:
1342                 __pDeletePopup->SetShowState(true);
1343                 __pDeletePopup->Show();
1344                 break;
1345         case ACTION_ID_FOOTER_BUTTON_SLIDE:
1346         {
1347                 if (__pPresentationModel->GetFileCount() > 1)
1348                 {
1349                         __pGallery->UpdateGallery();
1350                         if (__detail == false)
1351                         {
1352                                 ShowPanelDetail(false);
1353                         }
1354                         __pGallery->StartSlideShow(true);
1355                 }
1356                 break;
1357         }
1358         case ACTION_ID_FOOTER_BUTTON_DETAILS:
1359         {
1360                 ShowPanelDetail(__detail);
1361                 break;
1362         }
1363         case ACTION_ID_FOOTER_BUTTON_BACK:
1364                 ImageViewerForm::OnFormBackRequested(*this);
1365                 break;
1366         case ACTION_ID_FOOTER_BUTTON_DOWNLOAD:
1367                 DownloadFile();
1368                 break;
1369         case ACTION_ID_FOOTER_BUTTON_SAVE:
1370                 break;
1371         case ACTION_ID_PANEL_HEADER_DETAILS_RENAME:
1372         {
1373                 ArrayList* pSelectedIndex = new (std::nothrow) ArrayList(SingleObjectDeleter);
1374                 pSelectedIndex->Construct();
1375                 pSelectedIndex->Add(new (std::nothrow) Integer(__pGallery->GetCurrentItemIndex()));
1376                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_NAME_EDITOR), pSelectedIndex);
1377                 break;
1378         }
1379         case ACTION_ID_CONTEXTMENU_HOME:
1380         {
1381                 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1382                 pList->Add(new (std::nothrow) Integer(__pGallery->GetCurrentItemIndex()));
1383                 pList->Add(new (std::nothrow) Integer(SET_AT_TYPE_HOME_SCREEN_WALLPAPER));
1384                 __pPresentationModel->SetSetterIndex(__pGallery->GetCurrentItemIndex());
1385                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_SETTER), pList);
1386                 break;
1387         }
1388         case ACTION_ID_CONTEXTMENU_LOCK:
1389         {
1390                 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1391                 pList->Add(new (std::nothrow) Integer(__pGallery->GetCurrentItemIndex()));
1392                 pList->Add(new (std::nothrow) Integer(SET_AT_TYPE_LOCK_SCREEN_WALLPAPER));
1393                 __pPresentationModel->SetSetterIndex(__pGallery->GetCurrentItemIndex());
1394                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_SETTER), pList);
1395                 break;
1396         }
1397         case ACTION_ID_CONTEXTMENU_CALLER:
1398         {
1399                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
1400                 pDataList->Construct();
1401                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_SELECTION_MODE),
1402                                 new (std::nothrow) String(APPCONTROL_DATA_SINGLE));
1403                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_RETURN_TYPE),
1404                                 new (std::nothrow) String(APPCONTROL_DATA_CONTACT_ID));
1405
1406                 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_CONTACTS,
1407                                 APPCONTROL_OPERATION_ID_PICK, pDataList, this);
1408                 break;
1409         }
1410         case ACTION_ID_CONTEXTMENU_EMAIL:
1411         {
1412                 OnRequestEmailAction();
1413                 break;
1414         }
1415         case ACTION_ID_CONTEXTMENU_COPY:
1416         {
1417                 int currentIndex = __pGallery->GetCurrentItemIndex();
1418                 String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
1419
1420                 ClipboardItem item;
1421                 item.Construct(CLIPBOARD_DATA_TYPE_IMAGE, filePath);
1422                 Clipboard* pClipboard = Clipboard::GetInstance();
1423                 pClipboard->CopyItem(item);
1424                 break;
1425         }
1426         case ACTION_ID_DELETE_POPUP_DEL:
1427         {
1428                 __pDeletePopup->SetShowState(false);
1429                 __pDeletePopup->Show();
1430                 DeleteImageFile();
1431
1432                 if (__detail == false)
1433                 {
1434                         ShowPanelDetail(false);
1435                 }
1436                 break;
1437         }
1438         case ACTION_ID_DELETE_POPUP_CANCEL:
1439         {
1440                 __pDeletePopup->SetShowState(false);
1441                 __pDeletePopup->Show();
1442                 break;
1443         }
1444         case ACTION_ID_CONTORL_BUTTON_PLAY:
1445                 CallVideoPlayer();
1446                 break;
1447         default:
1448                 break;
1449         }
1450         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1451 }
1452
1453 void
1454 ImageViewerForm::OnFormBackRequested(Form& source)
1455 {
1456         AppLogDebug("ENTER");
1457         if (__detail == false)
1458         {
1459                 ShowPanelDetail(false);
1460         }
1461         else
1462         {
1463                 UiApp* pApp = UiApp::GetInstance();
1464                 pApp->Terminate();
1465         }
1466         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1467 }
1468
1469 void
1470 ImageViewerForm::OnSceneActivatedN(const SceneId& previousSceneId,
1471                                                                                   const SceneId& currentSceneId, IList* pArgs)
1472 {
1473         AppLogDebug("ENTER");
1474     OrientationStatus status = GetOrientationStatus();
1475         if (status == ORIENTATION_STATUS_PORTRAIT ||
1476                         status == ORIENTATION_STATUS_PORTRAIT_REVERSE)
1477         {
1478                 AppLogDebug("ORIENTATION_STATUS : PORTRAIT");
1479                 Rectangle clientRect = GetClientAreaBounds();
1480                 Rectangle rect = GetBounds();
1481                 __pGallery->SetBounds(Rectangle(0, -clientRect.y, rect.width, rect.height));
1482                 __pPlayButton->SetBounds(RECT_CONTORL_BUTTON_PLAY);
1483                 __pScrollPanel->SetBounds(RECT_DETAILS_CONTORL_PANEL);
1484         }
1485         else if (status == ORIENTATION_STATUS_LANDSCAPE ||
1486                         status == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
1487         {
1488                 AppLogDebug("ORIENTATION_STATUS : LANDSCAPE");
1489                 Rectangle clientRect = GetClientAreaBounds();
1490                 Rectangle rect = GetBounds();
1491                 __pGallery->SetBounds(Rectangle(0, -clientRect.y, rect.width, rect.height));
1492                 __pPlayButton->SetBounds(RECT_LANDSCAP_CONTORL_BUTTON_PLAY);
1493                 __pScrollPanel->SetBounds(RECT_LANDSCAPE_DETAILS_CONTORL_PANEL);
1494         }
1495
1496         if (previousSceneId == IDSCN_IMAGE_NAME_EDITOR && currentSceneId == IDSCN_IMAGE_VIEWER)
1497         {
1498                 SetDetailInfo();
1499                 String strItemText(EMPTY_SPACE);
1500                 String strItemIdxText(EMPTY_SPACE);
1501                 GetHeaderString(__pGallery->GetCurrentItemIndex(), strItemText, strItemIdxText);
1502                 __pHeader->SetTitleText(strItemText);
1503                 __pHeader->SetDescriptionText(strItemIdxText);
1504                 Invalidate(true);
1505         }
1506
1507         if (__pGallery->GetCurrentItemIndex() < 0)
1508         {
1509                 SetFooterItemState(false);
1510         }
1511         else
1512         {
1513                 SetFooterItemState(true);
1514         }
1515         Invalidate(true);
1516         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1517 }
1518
1519 void
1520 ImageViewerForm::OnSceneDeactivated(const SceneId& currentSceneId,
1521                                                                                    const SceneId& nextSceneId)
1522 {
1523         AppLogDebug("ENTER");
1524         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1525 }
1526
1527 void
1528 ImageViewerForm::OnImageDecodedN(const int index)
1529 {
1530         AppLogDebug("ENTER");
1531         __pGallery->RefreshGallery(index, GALLERY_REFRESH_TYPE_ITEM_MODIFY);
1532         __pGallery->Draw();
1533         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1534 }
1535
1536 void
1537 ImageViewerForm::OnAppControlCompleteResponseReceived(const AppId& appId,
1538                 const String& operationId, AppCtrlResult appControlResult,
1539                 const IMap* pExtraData)
1540 {
1541         AppLogDebug("ENTER");
1542
1543         if (appId == APPCONTROL_PROVIDER_ID_CONTACTS
1544                 && operationId == APPCONTROL_OPERATION_ID_PICK
1545                 && appControlResult == APP_CTRL_RESULT_SUCCEEDED)
1546         {
1547                 const String* pReturnType =
1548                                 static_cast<const String*>(pExtraData->GetValue(String(APPCONTROL_KEY_RETURN_TYPE)));
1549                 if (pReturnType != null && pReturnType->CompareTo(APPCONTROL_DATA_CONTACT_ID) == 0)
1550                 {
1551                         const String* pContactId =
1552                                         static_cast<const String*>(pExtraData->GetValue(String(APPCONTROL_KEY_VALUE)));
1553                         SceneManager* pSceneManager = SceneManager::GetInstance();
1554                         long long lresult = 0;
1555                         if (pContactId != null && pContactId->GetLength() > 0)
1556                         {
1557                                 LongLong::Parse(*pContactId, lresult);
1558                         }
1559                         ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1560                         pList->Add(new (std::nothrow) Integer(__pGallery->GetCurrentItemIndex()));
1561                         pList->Add(new (std::nothrow) Integer(SET_AT_TYPE_CALLER_IMAGE));
1562                         pList->Add(new (std::nothrow) LongLong(lresult));
1563                         __pPresentationModel->SetSetterIndex(__pGallery->GetCurrentItemIndex());
1564                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_SETTER), pList);
1565                 }
1566         }
1567
1568         ImageViewerApp* pImageViewerApp = static_cast<ImageViewerApp*>(ImageViewerApp::GetInstance());
1569         pImageViewerApp->SetFrameEnabled(true);
1570         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1571 }
1572
1573 void
1574 ImageViewerForm::OnOverlayControlCreated(const Control& source)
1575 {
1576         AppLogDebug("ENTER");
1577         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1578 }
1579
1580 void
1581 ImageViewerForm::OnOverlayControlOpened(const Control& source)
1582 {
1583         AppLogDebug("ENTER");
1584         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1585 }
1586
1587 void
1588 ImageViewerForm::OnOverlayControlClosed(const Control& source)
1589 {
1590         AppLogDebug("ENTER");
1591         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1592 }
1593
1594 void
1595 ImageViewerForm::OnOtherControlSelected(const Control& source)
1596 {
1597         AppLogDebug("ENTER");
1598         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1599 }
1600
1601 void
1602 ImageViewerForm::InitShowGallery(void)
1603 {
1604         AppLogDebug("ENTER");
1605         if (__pGallery != null && __pGallery->IsVisible() == false)
1606         {
1607                 Canvas* pCanvas = GetCanvasN();
1608                 if (pCanvas == null || GetLastResult() != E_SUCCESS)
1609                 {
1610                         AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1611
1612                         return;
1613                 }
1614
1615                 pCanvas->Clear();
1616                 __pGallery->SetShowState(true);
1617                 delete pCanvas;
1618                 pCanvas = null;
1619         }
1620         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1621 }
1622
1623 void
1624 ImageViewerForm::OnTimerExpired(Timer &timer)
1625 {
1626         AppLogDebug("ENTER");
1627         if (__pPresentationModel->GetFileCount() > 1)
1628         {
1629                 __pGallery->StartSlideShow(true);
1630         }
1631         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1632 }
1633
1634 void
1635 ImageViewerForm::OnContentTransferInProgress(RequestId requestId, int totalReceivedSize)
1636 {
1637         AppLogDebug("ENTER");
1638         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1639 }
1640
1641 void
1642 ImageViewerForm::OnContentUploadCompleted(RequestId requestId, result transferResult, const String& errorCode,
1643                 const String& errorMessage)
1644 {
1645         AppLogDebug("ENTER");
1646         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1647 }
1648
1649 void
1650 ImageViewerForm::OnContentDownloadCompleted(RequestId requestId, ContentId contentId,
1651                 result transferResult, const String& errorCode, const String& errorMessage)
1652 {
1653         AppLogDebug("ENTER");
1654         AppLogTag("IV", "ImageViewerForm::OnContentDownloadCompleted");
1655         AppLogTag("IV", "DownloadCompleted Error [%s]", GetErrorMessage(transferResult));
1656         AppLogTag("IV", "errorCode [%ls] errorMessage [%ls]", errorCode.GetPointer(), errorMessage.GetPointer());
1657         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1658 }
1659
1660 void
1661 ImageViewerForm::OnContentDownloadToBufferCompleted(RequestId reqId, ByteBuffer* pBuffer, result r,
1662                 const String& errorCode, const String& errorMessage)
1663 {
1664         AppLogDebug("ENTER");
1665         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1666 }
1667
1668 void
1669 ImageViewerForm::OnContentTransferCanceled(RequestId reqId, result res, const String& errorCode,
1670                 const String& errorMessage)
1671 {
1672         AppLogDebug("ENTER");
1673         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1674 }
1675
1676 void
1677 ImageViewerForm::RequestDecodeUrl(void)
1678 {
1679         AppLogDebug("ENTER");
1680
1681         String filePath = __pPresentationModel->GetFilePathAt(0);
1682
1683         if (filePath.StartsWith(WEB_URL_HTTP, 0) == false)
1684         {
1685                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1686
1687                 return;
1688         }
1689
1690         __downLordFileName = __pPresentationModel->GetFileName(filePath);
1691
1692         Image* pImage = new (std::nothrow) Image();
1693         pImage->Construct();
1694         Uri uri;
1695         RequestId reqId;
1696         uri.SetUri(filePath);
1697
1698         pImage->DecodeUrl(uri, BITMAP_PIXEL_FORMAT_RGB565, 720, 1280, reqId, *this, 5000);
1699
1700         delete pImage;
1701         pImage = null;
1702         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1703 }
1704
1705 void
1706 ImageViewerForm::OnImageDecodeUrlReceived (RequestId reqId, Bitmap *pBitmap,
1707                 result r, const String errorCode, const String errorMessage)
1708 {
1709         AppLogDebug("ENTER");
1710         Image* pImage = new (std::nothrow) Image();
1711         pImage->Construct();
1712
1713         String destPath = App::GetInstance()->GetAppRootPath() + TEMP_FILE_PATH_WEB_FILE;
1714         r = pImage->EncodeToFile(*pBitmap, IMG_FORMAT_JPG, destPath, true);
1715
1716         if (r == E_SUCCESS)
1717         {
1718                 __pPresentationModel->GetImageCacheAt(0)->SetFilePath(destPath);
1719                 __pPresentationModel->GetImageCacheAt(0)->SetBitmap(pBitmap);
1720
1721                 __pGallery->RefreshGallery(0, GALLERY_REFRESH_TYPE_ITEM_MODIFY);
1722                 __pGallery->Draw();
1723                 __pPresentationModel->RequestImage(destPath);
1724         }
1725         else
1726         {
1727                 AppLogDebug("ImageViewerForm::OnImageDecodeUrlReceived [%s]", GetErrorMessage(r));
1728         }
1729
1730          delete pImage;
1731          pImage = null;
1732          AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1733 }
1734
1735 void
1736 ImageViewerForm::OnRequestEmailAction(void)
1737 {
1738         AppLogDebug("ENTER");
1739         int currentIndex = __pGallery->GetCurrentItemIndex();
1740
1741         if (__pPresentationModel->GetFileCount() <= 0)
1742         {
1743                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1744
1745                 return;
1746         }
1747
1748         String combineText = EMPTY_SPACE;
1749
1750         String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
1751
1752         if (filePath.EndsWith(CONTENT_EXT_PNG)
1753                 || filePath.EndsWith(CONTENT_EXT_BMP)
1754                 || filePath.EndsWith(CONTENT_EXT_JPG)
1755                 || filePath.EndsWith(CONTENT_EXT_GIF)
1756                 || filePath.EndsWith(CONTENT_EXT_TIF)
1757                 || filePath.EndsWith(CONTENT_EXT_MP4)
1758                 || filePath.EndsWith(CONTENT_EXT_3GP)
1759                 || filePath.EndsWith(CONTENT_EXT_AVI)
1760                 || filePath.EndsWith(CONTENT_EXT_RM)
1761                 || filePath.EndsWith(CONTENT_EXT_WMV)
1762                 || filePath.EndsWith(CONTENT_EXT_ASF))
1763         {
1764                 if (combineText.CompareTo(EMPTY_SPACE) != 0)
1765                 {
1766                         combineText.Append(L";");
1767                 }
1768
1769                 combineText.Append(filePath);
1770         }
1771
1772         HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
1773         pDataList->Construct();
1774         pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_ATTACHMENTS),
1775                         new (std::nothrow) String(combineText));
1776
1777         __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_EMAIL,
1778                         APPCONTROL_OPERATION_ID_COMPOSE, pDataList, this);
1779         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1780 }
1781
1782 void
1783 ImageViewerForm::SetFooterItemState(bool isEnable)
1784 {
1785         AppLogDebug("ENTER");
1786         if (__initializeDisplayModeCurrent == APPCONTROL_MODE_NORMAL)
1787         {
1788                 __pFooter->SetButtonEnabled(BUTTON_POSITION_LEFT, isEnable);
1789                 __pFooter->SetItemEnabled(0, isEnable);
1790                 __pFooter->SetItemEnabled(1, isEnable);
1791         }
1792         else if (__initializeDisplayModeCurrent == APPCONTROL_MODE_WEB_LINK)
1793         {
1794                 __pFooter->SetButtonEnabled(BUTTON_POSITION_LEFT, isEnable);
1795                 __pFooter->SetItemEnabled(0, isEnable);
1796                 __pFooter->SetItemEnabled(1, isEnable);
1797         }
1798         else if (__initializeDisplayModeCurrent == APPCONTROL_MODE_CROP)
1799         {
1800                 __pFooter->SetItemEnabled(0, isEnable);
1801         }
1802         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1803 }
1804
1805 Bitmap*
1806 ImageViewerForm::GetQuickThumbnailN(String& filePath)
1807 {
1808         AppLogDebug("ENTER");
1809         Bitmap* pBitmap = null;
1810
1811         if (filePath.GetLength() > 4)
1812         {
1813                 int totalPage = 0;
1814                 int totalCount = 0;
1815                 ContentSearch contentSearch;
1816                 ContentSearchResult* pResultItem = null;
1817                 IList* pContentInfoList = null;
1818                 String queryString;
1819                 ContentType contentType = ContentManagerUtil::CheckContentType(filePath);
1820                 result r = contentSearch.Construct(contentType);
1821                 AppLogDebug("r(%s)", GetErrorMessage(r));
1822                 if (r != E_SUCCESS)
1823                 {
1824                         pBitmap = new (std::nothrow) Bitmap();
1825                         r = pBitmap->Construct(DUMMY_IMAGE_DIMENSION, BITMAP_PIXEL_FORMAT_RGB565);
1826                         if (r == E_SUCCESS)
1827                         {
1828                                 return pBitmap;
1829                         }
1830                         else
1831                         {
1832                                 delete pBitmap;
1833                                 return null;
1834                         }
1835                 }
1836                 queryString = CONTENT_QUERY_PREFIX_FILENAME;
1837                 queryString.Append(L"'");
1838                 queryString.Append(__pPresentationModel->GetFileName(filePath));
1839                 queryString.Append(L"'");
1840
1841                 pContentInfoList = contentSearch.SearchN(PAGE_NO_CONTENT_SEARCH, COUNT_PER_PAGE_CONTENT_SEARCH,
1842                                 totalPage, totalCount, queryString, EMPTY_SPACE, SORT_ORDER_NONE);
1843
1844                 if ((pContentInfoList != null) && GetLastResult() == E_SUCCESS && (pContentInfoList->GetCount() > 0))
1845                 {
1846                         IEnumerator* pEnum = pContentInfoList->GetEnumeratorN();
1847                         while (pEnum->MoveNext() == E_SUCCESS)
1848                         {
1849                                 pResultItem = static_cast<ContentSearchResult*>(pEnum->GetCurrent());
1850                                 if (pResultItem == null)
1851                                 {
1852                                         continue;
1853                                 }
1854
1855                                 if (pResultItem->GetContentInfo()->GetContentPath().CompareTo(filePath) == 0)
1856                                 {
1857                                         pBitmap = pResultItem->GetContentInfo()->GetThumbnailN();
1858                                 }
1859                         }
1860                         delete pEnum;
1861                 }
1862
1863                 if (pContentInfoList != null)
1864                 {
1865                         delete pContentInfoList;
1866                 }
1867
1868                 if (pBitmap != null)
1869                 {
1870                         ImageViewerMediaType mediaType = CommonUtil::GetMediaType(filePath);
1871                         if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE)
1872                         {
1873                                 ImageMetadata* pImgMeta = ContentManagerUtil::GetImageMetaN(filePath);
1874
1875                                 if (pImgMeta != null)
1876                                 {
1877                                         Dimension srcDim(pImgMeta->GetWidth(), pImgMeta->GetHeight());
1878                                         pBitmap->Scale(srcDim);
1879                                         delete pImgMeta;
1880                                 }
1881                                 else
1882                                 {
1883                                         ImageBuffer* imageBuffer = new (std::nothrow) ImageBuffer();
1884                                         result r = imageBuffer->Construct(filePath);
1885                                         if (r == E_SUCCESS)
1886                                         {
1887                                                 Dimension srcDim(imageBuffer->GetWidth(), imageBuffer->GetHeight());
1888                                                 pBitmap->Scale(srcDim);
1889                                                 delete imageBuffer;
1890                                         }
1891                                 }
1892                         }
1893                         else if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_VIDEO)
1894                         {
1895                                 VideoMetadata* pVideoMeta = ContentManagerUtil::GetVideoMetaN(filePath);
1896
1897                                 if (pVideoMeta != null && GetLastResult() == E_SUCCESS)
1898                                 {
1899                                         Dimension srcDim(pVideoMeta->GetWidth(), pVideoMeta->GetHeight());
1900                                         pBitmap->Scale(srcDim);
1901                                         delete pVideoMeta;
1902                                 }
1903                         }
1904                 }
1905                 else
1906                 {
1907                         Canvas mainCanvas;
1908                         mainCanvas.Construct(DUMMY_IMAGE_RECTANGLE);
1909                         mainCanvas.FillRectangle(Color::GetColor(COLOR_ID_WHITE), DUMMY_IMAGE_RECTANGLE);
1910                         pBitmap = new (std::nothrow) Bitmap();
1911                         pBitmap->Construct(mainCanvas, DUMMY_IMAGE_RECTANGLE);
1912                 }
1913         }
1914         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1915         return pBitmap;
1916 }