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