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