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