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