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