Add new string - Start slideshow, Slideshow setting
[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         AppLogDebug("ENTER(%ls)", filePath.GetPointer());
544
545         __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_VIDEO_PLAYER, APPCONTROL_OPERATION_ID_VIEW,
546                         &filePath, null, this);
547         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
548 }
549
550 void
551 ImageViewerForm::CreateGallery(void)
552 {
553         AppLogDebug("ENTER");
554         Rectangle clientRect = GetClientAreaBounds();
555         Rectangle rect = GetBounds();
556
557         __pGallery = new (std::nothrow) Gallery();
558         __pGallery->Construct(Rectangle(0, clientRect.y, rect.width, rect.height));
559         __pGallery->SetName(L"GalleryControl");
560         __pGallery->SetItemProvider(*this);
561         __pGallery->AddGalleryEventListener(*this);
562         __pGallery->SetBackgroundColor(COLOR_GALLERY_BG);
563         AddControl(*__pGallery);
564         __pGallery->SetTextOfEmptyGallery(ResourceManager::GetString(L"IDS_COM_BODY_LOADING"));
565
566         SlideShowTransitionEffect effect = __pPresentationModel->GetTransitionEffectOfSlideShow();
567
568         switch (effect)
569         {
570         case SLIDE_SHOW_TRANSITION_EFFECT_DISSOLVE:
571                 __pGallery->SetSlideShowAnimation(Controls::GALLERY_ANIMATION_DISSOLVE);
572                 break;
573         case SLIDE_SHOW_TRANSITION_EFFECT_ZOOM:
574                 __pGallery->SetSlideShowAnimation(Controls::GALLERY_ANIMATION_ZOOM);
575                 break;
576         case SLIDE_SHOW_TRANSITION_EFFECT_SLIDE:
577                 break;
578         }
579
580         __pGallery->SetSlideShowViewDuration(__pPresentationModel->GetDurationOfSlideShow());
581
582         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
583 }
584
585 result
586 ImageViewerForm::InitializePanelDetail()
587 {
588         AppLogDebug("ENTER");
589         __pScrollPanel = new (std::nothrow) ScrollPanel();
590
591         String arrayId[DETAIL_COUNT_MAX] =
592         {
593                 L"IDS_COM_BODY_DETAILS_NAME", L"IDS_IV_BODY_FILE_FORMAT", L"IDS_IV_BODY_DATE_CREATED",
594                 L"IDS_COM_BODY_SIZE", L"IDS_IV_BODY_RESOLUTION", L"IDS_COM_BODY_LOCATION",
595                 L"IDS_COM_BODY_LATITUDE", L"IDS_COM_BODY_LONGITUDE", L"IDS_IV_BODY_FILE_LOCATION"
596         };
597
598         if (__pScrollPanel == null)
599         {
600                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
601
602                 return E_INVALID_STATE;
603         }
604
605         Rectangle clientRect = GetClientAreaBounds();
606         result r = __pScrollPanel->Construct(Rectangle(0, 0, clientRect.width, clientRect.height - __pLabel->GetHeight()));
607         if (r != E_SUCCESS)
608         {
609                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
610
611                 return E_INVALID_STATE;
612         }
613
614         __pDetail_Label = new (std::nothrow) Label();
615         __pDetail_Label->Construct(RECT_DETAILS_CONTORL_LABEL, ResourceManager::GetString(L"IDS_COM_BODY_DETAILS"));
616         __pScrollPanel->AddControl(*__pDetail_Label);
617         __pDetail_Label->SetTextVerticalAlignment(ALIGNMENT_TOP);
618         __pDetail_Label->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
619         __pDetail_Label->SetTextColor(Color::GetColor(COLOR_ID_WHITE));
620         __pDetail_Label->SetTextConfig(DETAIL_MAIN_FONT_SIZE, LABEL_TEXT_STYLE_BOLD);
621
622         for (int i = 0; i < DETAIL_COUNT_MAX; ++i)
623         {
624                 __pDetail_FileInfo_Label[i] = new (std::nothrow) Label();
625                 __pDetail_FileInfo_Label[i]->Construct(
626                                 Rectangle(X_DETAIL_FILEINFO_LABEL,
627                                                 GAP_H_DETAIL_TEXT * (i + 1) + H_DETAIL_MAIN_TEXT + (H_DETAIL_MAIN_TEXT + H_DETAIL_SUB_TEXT) * i,
628                                                 clientRect.width - GAP_W_END_OF_LABEL, H_DETAIL_FILEINFO_LABEL), ResourceManager::GetString(arrayId[i]));
629                 __pScrollPanel->AddControl(*__pDetail_FileInfo_Label[i]);
630
631                 __pDetail_FileInfo_Label[i]->SetTextVerticalAlignment(ALIGNMENT_TOP);
632                 __pDetail_FileInfo_Label[i]->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
633                 __pDetail_FileInfo_Label[i]->SetTextColor(Color::GetColor(COLOR_ID_GREY));
634                 __pDetail_FileInfo_Label[i]->SetTextConfig(DETAIL_SUB_FONT_SIZE, LABEL_TEXT_STYLE_BOLD);
635
636                 __pDetail_FileInfo_Value_Label[i] = new (std::nothrow) Label();
637
638                 if (i == DETAIL_COUNT_MAX - 1)
639                 {
640                         __pDetail_FileInfo_Value_Label[i]->Construct(
641                                         Rectangle(X_DETAIL_FILEINFO_LABEL,
642                                                         GAP_H_DETAIL_TEXT * (i + 1) + H_DETAIL_MAIN_TEXT + (H_DETAIL_MAIN_TEXT * i) + H_DETAIL_SUB_TEXT * (i + 1),
643                                                         clientRect.width - GAP_W_END_OF_LABEL, H_DETAIL_FILEINFO_VALUE_LABEL * 3), L"");
644                 }
645                 else
646                 {
647                         __pDetail_FileInfo_Value_Label[i]->Construct(
648                                         Rectangle(X_DETAIL_FILEINFO_LABEL,
649                                                         GAP_H_DETAIL_TEXT * (i + 1) + H_DETAIL_MAIN_TEXT + (H_DETAIL_MAIN_TEXT * i) + H_DETAIL_SUB_TEXT * (i + 1),
650                                                         clientRect.width - GAP_W_END_OF_LABEL, H_DETAIL_FILEINFO_VALUE_LABEL), L"");
651                 }
652
653                 __pScrollPanel->AddControl(*__pDetail_FileInfo_Value_Label[i]);
654
655                 __pDetail_FileInfo_Value_Label[i]->SetTextVerticalAlignment(ALIGNMENT_TOP);
656                 __pDetail_FileInfo_Value_Label[i]->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
657                 __pDetail_FileInfo_Value_Label[i]->SetTextColor(Color::GetColor(COLOR_ID_WHITE));
658                 __pDetail_FileInfo_Value_Label[i]->SetTextConfig(DETAIL_MAIN_FONT_SIZE, LABEL_TEXT_STYLE_BOLD);
659         }
660
661         __pScrollPanel->SetBackgroundColor(COLOR_HEADER_CONTORL_PANEL);
662         __pScrollPanel->SetShowState(false);
663
664         __pRenameButton = new (std::nothrow) Button();
665         Rectangle rect = GetBounds();
666         __pRenameButton->Construct(Rectangle(rect.width - W_RENAME_BUTTON - 20, Y_RENAME_BUTTON, W_RENAME_BUTTON, H_RENAME_BUTTON));
667         __pRenameButton->SetActionId(ACTION_ID_PANEL_HEADER_DETAILS_RENAME);
668         __pRenameButton->AddActionEventListener(*this);
669
670         Bitmap* pIcon = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_EDIT_NAME);
671         Bitmap* pIconBackground =
672                         ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_EDIT_NAME_NORMAL_BACKGROUND);
673         Bitmap* pIconPressed =
674                         ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_EDIT_NAME_NORMAL_BACKGROUND_PRESS);
675
676         if (pIcon != null && pIconPressed != null && pIconBackground != null)
677         {
678                 __pRenameButton->SetNormalBackgroundBitmap(*pIconBackground);
679                 __pRenameButton->SetPressedBackgroundBitmap(*pIconPressed);
680                 Point iconPosition(0, 0);
681                 __pRenameButton->SetNormalBitmap(iconPosition, *pIcon);
682                 __pRenameButton->SetPressedBitmap(iconPosition, *pIconPressed);
683         }
684         else
685         {
686                 __pRenameButton->SetColor(BUTTON_STATUS_NORMAL, COLOR_HEADER_BUTTON1);
687                 __pRenameButton->SetColor(BUTTON_STATUS_PRESSED, COLOR_HEADER_BUTTON1);
688         }
689         delete pIcon;
690         delete pIconPressed;
691         delete pIconBackground;
692
693         __pRenameButton->SetColor(BUTTON_STATUS_NORMAL, COLOR_HEADER_BUTTON1);
694         __pScrollPanel->AddControl(*__pRenameButton);
695
696
697         AddControl(*__pScrollPanel);
698         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
699
700         return E_SUCCESS;
701 }
702
703 result
704 ImageViewerForm::InitializePopup(void)
705 {
706         AppLogDebug("ENTER");
707         if (__pDeletePopup == null)
708         {
709                 __pDeletePopup = new (std::nothrow) Popup();
710                 __pDeletePopup->Construct(false, Dimension(W_DELETE_POPUP, H_DELETE_POPUP));
711
712                 Rectangle popupClientBounds = __pDeletePopup->GetClientAreaBounds();
713
714                 Label* pLabel = new (std::nothrow) Label();
715                 pLabel->Construct(Rectangle(0, 0, popupClientBounds.width, H_DELETE_LABEL),
716                                 ResourceManager::GetString(L"IDS_COM_BODY_DELETE") + L"?");
717
718                 Button* pDeleteButton = new (std::nothrow) Button();
719                 pDeleteButton->Construct(
720                                 Rectangle(0, Y_DELETE_BUTTON, popupClientBounds.width / 2 - GAP_W_POPUP_ITEM, H_DELETE_BUTTON),
721                                 ResourceManager::GetString(L"IDS_COM_BODY_DELETE"));
722                 pDeleteButton->SetColor(BUTTON_STATUS_NORMAL, COLOR_DELETE_BUTTON_NORMAL);
723                 pDeleteButton->SetColor(BUTTON_STATUS_PRESSED, COLOR_DELETE_BUTTON_PRESSED);
724                 pDeleteButton->SetTextColor(COLOR_DELETE_BUTTON_TEXT);
725                 pDeleteButton->SetActionId(ACTION_ID_DELETE_POPUP_DEL);
726                 pDeleteButton->AddActionEventListener(*this);
727
728                 Button* pCancelButton = new (std::nothrow) Button();
729                 pCancelButton->Construct(
730                                 Rectangle(popupClientBounds.width / 2 + GAP_W_POPUP_ITEM,
731                                                 Y_DELETE_BUTTON, popupClientBounds.width / 2 - GAP_W_POPUP_ITEM, H_DELETE_BUTTON),
732                                                 ResourceManager::GetString(L"IDS_COM_SK_CANCEL"));
733                 pCancelButton->SetActionId(ACTION_ID_DELETE_POPUP_CANCEL);
734                 pCancelButton->AddActionEventListener(*this);
735
736                 __pDeletePopup->AddControl(*pLabel);
737                 __pDeletePopup->AddControl(*pDeleteButton);
738                 __pDeletePopup->AddControl(*pCancelButton);
739         }
740         else
741         {
742                 __pDeletePopup->SetShowState(true);
743                 __pDeletePopup->Show();
744         }
745         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
746
747         return E_SUCCESS;
748 }
749
750 result
751 ImageViewerForm::InitializeContextMenuMore(void)
752 {
753         AppLogDebug("ENTER");
754         int currentIndex = __pGallery->GetCurrentItemIndex();
755         String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
756
757         ImageViewerMediaType mediaType = CommonUtil::GetMediaType(filePath);
758
759         if (__pContextMenuMore != null)
760         {
761                 delete __pContextMenuMore;
762                 __pContextMenuMore = null;
763         }
764
765         __pContextMenuMore = new (std::nothrow) ContextMenu();
766
767         __pContextMenuMore->Construct(Point(X_MORE, GetClientAreaBounds().y + GetClientAreaBounds().height),
768                         CONTEXT_MENU_STYLE_LIST, CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD);
769
770         if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE)
771         {
772                 __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_IV_OPT_SET_AS"),
773                                 ACTION_ID_CONTEXTMENU_SET_AS);
774                 __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_IV_BODY_CROP"), ACTION_ID_FOOTER_BUTTON_CROP);
775         }
776
777         if (__pGallery->GetItemCount() > 1)
778         {
779                 __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_IV_OPT_SLIDE_SHOW"),
780                                 ACTION_ID_FOOTER_BUTTON_SLIDE);
781         }
782         __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_DETAILS"),
783                         ACTION_ID_FOOTER_BUTTON_DETAILS);
784         __pContextMenuMore->SetShowState(false);
785         __pContextMenuMore->AddActionEventListener(*this);
786         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
787
788         return E_SUCCESS;
789 }
790
791 result
792 ImageViewerForm::InitializeContextMenuSetAs(void)
793 {
794         AppLogDebug("ENTER");
795
796         if (__pContextMenuSetAs != null)
797         {
798                 delete __pContextMenuSetAs;
799                 __pContextMenuSetAs = null;
800         }
801
802         __pContextMenuSetAs = new (std::nothrow) ContextMenu();
803         __pContextMenuSetAs->Construct(Point(X_MORE, GetClientAreaBounds().y + GetClientAreaBounds().height),
804                         CONTEXT_MENU_STYLE_LIST, CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD);
805
806         __pContextMenuSetAs->AddItem(ResourceManager::GetString(L"IDS_IV_HEADER_HOME_SCREEN_WALLPAPER_ABB"),
807                         ACTION_ID_CONTEXTMENU_HOME);
808         __pContextMenuSetAs->AddItem(ResourceManager::GetString(L"IDS_IV_HEADER_LOCK_SCREEN_WALLPAPER_ABB"),
809                         ACTION_ID_CONTEXTMENU_LOCK);
810         __pContextMenuSetAs->AddItem(L"Home and lock screens", ACTION_ID_CONTEXTMENU_HOME_AND_LOCK);
811         __pContextMenuSetAs->AddItem(ResourceManager::GetString(L"IDS_IV_BODY_CALLER_IMAGE"),
812                         ACTION_ID_CONTEXTMENU_CALLER);
813         __pContextMenuSetAs->AddActionEventListener(*this);
814         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
815
816         return E_SUCCESS;
817 }
818
819 result
820 ImageViewerForm::InitializeContextMenuShare(void)
821 {
822         AppLogDebug("ENTER");
823         if (__pContextMenuShare != null)
824         {
825                 delete __pContextMenuShare;
826                 __pContextMenuShare = null;
827         }
828         __pContextMenuShare = new (std::nothrow) ContextMenu();
829         __pContextMenuShare->Construct(Point((GetClientAreaBounds().width - (X_MORE * 4)) / 4 + X_MORE * 2,
830                         GetClientAreaBounds().y + GetClientAreaBounds().height), CONTEXT_MENU_STYLE_LIST,
831                         CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD);
832
833         __pContextMenuShare->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_MESSAGE"),
834                         ACTION_ID_CONTEXTMENU_MESSAGE);
835         __pContextMenuShare->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_EMAIL"), ACTION_ID_CONTEXTMENU_EMAIL);
836         __pContextMenuShare->AddActionEventListener(*this);
837         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
838
839         return E_SUCCESS;
840 }
841
842 long long
843 ImageViewerForm::GetFileSize(String filePath)
844 {
845         AppLogDebug("ENTER");
846         FileAttributes attr;
847         long long size = 0;
848
849         result r = File::GetAttributes(filePath, attr);
850         if (r != E_SUCCESS)
851         {
852                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
853
854                 return 0;
855         }
856         size = attr.GetFileSize();
857         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
858
859         return size;
860 }
861
862 result
863 ImageViewerForm::SetDetailInfo(void)
864 {
865         AppLogDebug("ENTER");
866
867         Rectangle clientRect = GetClientAreaBounds();
868         __pScrollPanel->SetBounds(0,__pLabel->GetHeight(), clientRect.width, clientRect.height - __pLabel->GetHeight());
869
870         int currentIndex = __pGallery->GetCurrentItemIndex();
871         String strFilePath = __pPresentationModel->GetFilePathAt(currentIndex);
872
873         ImageViewerMediaType mediaType = CommonUtil::GetMediaType(strFilePath);
874
875         String strResult[DETAIL_COUNT_MAX] = {EMPTY_SPACE, };
876
877         strResult[0] = __pPresentationModel->GetFileName(strFilePath);
878         strResult[1] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
879
880         FileAttributes attr;
881         result r = File::GetAttributes(strFilePath, attr);
882         if (r == E_SUCCESS)
883         {
884                 long long nSize = attr.GetFileSize();
885                 DateTime dateTime = attr.GetDateTime();
886                 strResult[2] = dateTime.ToString();
887
888                 if (nSize > SINGLE_GIGA_BYTE)
889                 {
890                         strResult[3].Format(FORMAT_BUFFER_SIZE, L"%lld ", nSize / SINGLE_GIGA_BYTE);
891                         strResult[3].Append(ResourceManager::GetString(L"IDS_COM_BODY_GB"));
892                 }
893                 else if (nSize > SINGLE_MEGA_BYTE)
894                 {
895                         strResult[3].Format(FORMAT_BUFFER_SIZE, L"%lld ", nSize / SINGLE_MEGA_BYTE);
896                         strResult[3].Append(ResourceManager::GetString(L"IDS_COM_BODY_MB"));
897                 }
898                 else if (nSize > SINGLE_KILO_BYTE)
899                 {
900                         strResult[3].Format(FORMAT_BUFFER_SIZE, L"%lld ", nSize / SINGLE_KILO_BYTE);
901                         strResult[3].Append(ResourceManager::GetString(L"IDS_COM_BODY_KB"));
902                 }
903                 else
904                 {
905                         strResult[3].Format(FORMAT_BUFFER_SIZE, L"%lld ", nSize);
906                         strResult[3].Append(ResourceManager::GetString(L"IDS_COM_BODY_B"));
907                 }
908         }
909         else
910         {
911                 strResult[2] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
912                 strResult[3] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
913         }
914
915         strResult[4] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
916         strResult[5] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
917         strResult[6] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
918         strResult[7] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
919         strResult[8] = strFilePath;
920         String fileName = File::GetFileName(strFilePath);
921         strResult[8].Remove(strResult[8].GetLength() - fileName.GetLength(), fileName.GetLength());
922
923         if (strResult[8].StartsWith(Tizen::System::Environment::GetMediaPath(), 0) == true)
924         {
925                 strResult[8].Replace(Tizen::System::Environment::GetMediaPath(), MEDIA_ROOT_PHONE, 0);
926         }
927
928         if (__initializeDisplayModeCurrent == APPCONTROL_MODE_WEB_LINK)
929         {
930                 strResult[0] = __downLordFileName;
931         }
932         else if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE)
933         {
934                 ImageMetadata* pImgMeta = ContentManagerUtil::GetImageMetaN(strFilePath);
935
936                 if (pImgMeta != null)
937                 {
938                         ImageContentInfo imageContentInfo;
939                         r = imageContentInfo.Construct(&strFilePath);
940                         if (r == E_SUCCESS)
941                         {
942                                 strResult[1] = imageContentInfo.GetMediaFormat();
943                                 strResult[4].Format(FORMAT_BUFFER_SIZE, L"%d x %d", pImgMeta->GetWidth(),
944                                                 pImgMeta->GetHeight());
945
946                                 if (imageContentInfo.GetLocationTag() != EMPTY_SPACE)
947                                 {
948                                         strResult[5].Format(FORMAT_BUFFER_SIZE, L"%ls", imageContentInfo.GetLocationTag().GetPointer());
949                                 }
950
951                                 if (pImgMeta->GetLatitude() > 1.0 && pImgMeta->GetLongitude() > 1.0)
952                                 {
953                                         strResult[6].Format(FORMAT_BUFFER_SIZE, L"%f", pImgMeta->GetLatitude());
954                                         strResult[7].Format(FORMAT_BUFFER_SIZE, L"%f", pImgMeta->GetLongitude());
955                                 }
956                         }
957                         delete pImgMeta;
958                 }
959         }
960         else if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_VIDEO)
961         {
962                 VideoMetadata* pVideoMeta = ContentManagerUtil::GetVideoMetaN(strFilePath);
963                 if (pVideoMeta != null)
964                 {
965                         VideoContentInfo videoContentInfo;
966                         r = videoContentInfo.Construct(&strFilePath);
967                         if (r == E_SUCCESS)
968                         {
969                                 strResult[1] = videoContentInfo.GetMediaFormat();
970                                 strResult[4].Format(FORMAT_BUFFER_SIZE, L"%d x %d", pVideoMeta->GetWidth(),
971                                                 pVideoMeta->GetHeight());
972                                 if (videoContentInfo.GetLocationTag() != EMPTY_SPACE)
973                                 {
974                                         strResult[5].Format(FORMAT_BUFFER_SIZE, L"%ls", videoContentInfo.GetLocationTag().GetPointer());
975                                 }
976                         }
977                 }
978         }
979
980         for (int i = 0; i < DETAIL_COUNT_MAX; ++i)
981         {
982                 __pDetail_FileInfo_Value_Label[i]->SetText(strResult[i]);
983                 __pDetail_FileInfo_Value_Label[i]->RequestRedraw();
984         }
985
986         if (__initializeDisplayModeCurrent == APPCONTROL_MODE_WEB_LINK)
987         {
988                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
989                 return r;
990         }
991
992         Rectangle rect = GetBounds();
993         __pRenameButton->SetBounds(Rectangle(rect.width - W_RENAME_BUTTON - 20, Y_RENAME_BUTTON, W_RENAME_BUTTON, H_RENAME_BUTTON));
994
995         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
996
997         return r;
998 }
999
1000 result
1001 ImageViewerForm::ShowPanelDetail(bool showStatus)
1002 {
1003         AppLogDebug("ENTER");
1004         if (showStatus)
1005         {
1006                 SetDetailInfo();
1007                 __pScrollPanel->SetShowState(true);
1008                 __detail = false;
1009         }
1010         else
1011         {
1012                 __pScrollPanel->SetShowState(false);
1013                 __detail = true;
1014         }
1015         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1016
1017         return E_SUCCESS;
1018 }
1019
1020 result
1021 ImageViewerForm::ChangeFooterItem(bool isChanged, Footer* pFooter, int position)
1022 {
1023         AppLogDebug("ENTER");
1024         FooterItem footerItem;
1025         footerItem.Construct(ACTION_ID_FOOTER_BUTTON_DETAILS);
1026         Bitmap* pfooterItem = null;
1027
1028         if (isChanged)
1029         {
1030                 pfooterItem = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_DETAILS_CLOSE);
1031                 footerItem.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pfooterItem);
1032         }
1033         else
1034         {
1035                 pfooterItem = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_DETAILS);
1036                 footerItem.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pfooterItem);
1037         }
1038
1039         pFooter->SetItemAt(position, footerItem);
1040         pFooter->Invalidate(true);
1041
1042         delete pfooterItem;
1043         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1044
1045         return E_SUCCESS;
1046 }
1047
1048 void
1049 ImageViewerForm::DownloadFile(void)
1050 {
1051         AppLogDebug("ENTER");
1052         String DestPath = App::GetInstance()->GetAppRootPath() + TEMP_FILE_PATH_WEB_FILE;
1053         if (File::IsFileExist(DestPath) == false)
1054         {
1055                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1056                 return;
1057         }
1058
1059         ContentId contentId;
1060         ContentManager contentManager;
1061         contentManager.Construct();
1062
1063         ImageContentInfo imageContentInfo;
1064         imageContentInfo.Construct(null);
1065
1066         imageContentInfo.SetKeyword(L"platform, tizen");
1067         String sourcePath = DestPath;
1068         String destPath = Environment::GetMediaPath();
1069         destPath.Append(FOLDER_PATH_DOWNLOADS);
1070         destPath.Append(__downLordFileName);
1071
1072         contentId = contentManager.CreateContent(sourcePath, destPath, true, &imageContentInfo);
1073         ImageViewerForm::OnFormBackRequested(*this);
1074         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1075 }
1076
1077 int
1078 ImageViewerForm::GetItemCount(void)
1079 {
1080         AppLogDebug("ENTER");
1081         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1082
1083         return __pPresentationModel->GetFileCount();
1084 }
1085
1086 GalleryItem*
1087 ImageViewerForm::CreateItem(int index)
1088 {
1089         AppLogDebug("ENTER : index(%d)", index);
1090         GalleryItem* pGallery = new (std::nothrow) GalleryItem();
1091
1092         String filePath = __pPresentationModel->GetFilePathAt(index);
1093         ImageInfo* pImageInfo = __pPresentationModel->GetImageCacheAt(index);
1094         Bitmap* pBitmap = pImageInfo->GetBitmapN();
1095         if (pBitmap == null)
1096         {
1097                 pBitmap = GetQuickThumbnailN(filePath);
1098
1099                 if (pBitmap == null)
1100                 {
1101                         pBitmap = new (std::nothrow) Bitmap();
1102                         pBitmap->Construct(DUMMY_IMAGE_DIMENSION, BITMAP_PIXEL_FORMAT_RGB565);
1103                 }
1104         }
1105         pGallery->Construct(*pBitmap, filePath);
1106         delete pBitmap;
1107         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1108
1109         return pGallery;
1110 }
1111
1112 bool
1113 ImageViewerForm::DeleteItem(int index, GalleryItem* pItem)
1114 {
1115         AppLogDebug("ENTER index(%d)", index);
1116         ImageInfo* pImageInfo = __pPresentationModel->GetImageCacheAt(index);
1117         pImageInfo->ClearBitmap();
1118         delete pItem;
1119         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1120
1121         return true;
1122 }
1123
1124 void
1125 ImageViewerForm::OnGalleryCurrentItemChanged(Gallery& view, int index)
1126 {
1127         AppLogDebug("ENTER index(%d)", index);
1128
1129         String filePath = __pPresentationModel->GetFilePathAt(index);
1130         AppLogDebug("ENTER index(%d) filePath(%ls)", index, filePath.GetPointer());
1131         __pPresentationModel->RequestImage(filePath);
1132
1133         String strItemIdxText;
1134         GetLabelText(__pGallery->GetCurrentItemIndex(), strItemIdxText);
1135         __pLabel->SetText(strItemIdxText);
1136
1137         if (__visible == true)
1138         {
1139                 ImageViewerMediaType mediaType = CommonUtil::GetMediaType(filePath);
1140                 if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_VIDEO)
1141                 {
1142                         __pPlayButton->SetShowState(true);
1143                 }
1144                 else
1145                 {
1146                         __pPlayButton->SetShowState(false);
1147                 }
1148         }
1149
1150         Invalidate(true);
1151         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1152 }
1153
1154 void
1155 ImageViewerForm::OnGalleryItemClicked(Gallery& view, int index)
1156 {
1157         AppLogDebug("ENTER");
1158
1159         String filePath = __pPresentationModel->GetFilePathAt(index);
1160         ContentType contentType = ContentManagerUtil::CheckContentType(filePath);
1161
1162         if (__visible == true)
1163         {
1164                 if (contentType == CONTENT_TYPE_VIDEO)
1165                 {
1166                         __pPlayButton->SetShowState(false);
1167                 }
1168
1169                 SetActionBarsVisible( FORM_ACTION_BAR_FOOTER, false);
1170                 __pLabel->SetShowState(false);
1171                 __visible = false;
1172         }
1173         else
1174         {
1175                 if (contentType == CONTENT_TYPE_VIDEO)
1176                 {
1177                         __pPlayButton->SetShowState(true);
1178                 }
1179
1180                 SetActionBarsVisible(FORM_ACTION_BAR_FOOTER, true);
1181                 __pLabel->SetShowState(true);
1182                 __visible = true;
1183
1184                 __pPlayButton->SetPosition(__pPlayButton->GetPosition().x, __pPlayButton->GetPosition().y - 1);
1185                 __pPlayButton->SetPosition(__pPlayButton->GetPosition().x, __pPlayButton->GetPosition().y + 1);
1186         }
1187
1188         Rectangle clientRect = GetClientAreaBounds();
1189         Rectangle rect = GetBounds();
1190         __pGallery->SetBounds(Rectangle(0, clientRect.y, rect.width, rect.height));
1191         Invalidate(true);
1192         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1193 }
1194
1195 void
1196 ImageViewerForm::OnGallerySlideShowStarted(Gallery& gallery)
1197 {
1198         AppLogDebug("ENTER");
1199         PowerManager::KeepScreenOnState(true, false);
1200         if (__visible  == true)
1201         {
1202                 SetActionBarsVisible(FORM_ACTION_BAR_FOOTER, false);
1203                 __pLabel->SetShowState(false);
1204
1205                 int index = __pGallery->GetCurrentItemIndex();
1206                 String filePath = __pPresentationModel->GetFilePathAt(index);
1207                 ContentType contentType = ContentManagerUtil::CheckContentType(filePath);
1208
1209                 if (contentType == CONTENT_TYPE_VIDEO)
1210                 {
1211                         __pPlayButton->SetShowState(false);
1212                 }
1213
1214                 __visible = false;
1215         }
1216
1217         Rectangle clientRect = GetClientAreaBounds();
1218         Rectangle rect = GetBounds();
1219         __pGallery->SetBounds(Rectangle(0, -clientRect.y, rect.width, rect.height));
1220         Invalidate(true);
1221         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1222 }
1223
1224 void
1225 ImageViewerForm::OnGallerySlideShowStopped(Gallery& gallery)
1226 {
1227         AppLogDebug("ENTER");
1228         PowerManager::KeepScreenOnState(false, true);
1229         int index = __pGallery->GetCurrentItemIndex();
1230
1231         if (__visible == false)
1232         {
1233                 SetActionBarsVisible(FORM_ACTION_BAR_FOOTER, true);
1234                 __pLabel->SetShowState(true);
1235                 String filePath = __pPresentationModel->GetFilePathAt(index);
1236                 ContentType contentType = ContentManagerUtil::CheckContentType(filePath);
1237                 if (contentType == CONTENT_TYPE_VIDEO)
1238                 {
1239                         __pPlayButton->SetShowState(true);
1240                 }
1241
1242                 __pPlayButton->SetPosition(__pPlayButton->GetPosition().x, __pPlayButton->GetPosition().y - 1);
1243                 __pPlayButton->SetPosition(__pPlayButton->GetPosition().x, __pPlayButton->GetPosition().y + 1);
1244
1245                 __visible = true;
1246         }
1247
1248         String strItemIdxText;
1249         GetLabelText(index, strItemIdxText);
1250         __pLabel->SetText(strItemIdxText);
1251
1252
1253         Rectangle clientRect = GetClientAreaBounds();
1254         Rectangle rect = GetBounds();
1255         __pGallery->SetBounds(Rectangle(0, -clientRect.y, rect.width, rect.height));
1256
1257         Invalidate(true);
1258         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1259 }
1260
1261 void
1262 ImageViewerForm::OnUpdateContentList(void)
1263 {
1264 }
1265
1266 result
1267 ImageViewerForm::OnTerminating(void)
1268 {
1269         AppLogDebug("ENTER");
1270
1271         if (__pTimer != null)
1272         {
1273                 __pTimer->Cancel();
1274                 delete __pTimer;
1275                 __pTimer = null;
1276         }
1277
1278         __pPresentationModel->ClearImageRequests();
1279         __pPresentationModel->RemoveListener(*this);
1280         __pPresentationModel->RemoveFileUpdateListener(*this);
1281
1282         if (__pContextMenuCopy != null)
1283         {
1284                 delete __pContextMenuCopy;
1285                 __pContextMenuCopy = null;
1286         }
1287
1288         if (__pContextMenuSetAs != null)
1289         {
1290                 delete __pContextMenuSetAs;
1291                 __pContextMenuSetAs = null;
1292         }
1293
1294         if (__pDeletePopup != null)
1295         {
1296                 delete __pDeletePopup;
1297                 __pDeletePopup = null;
1298         }
1299
1300         if (__pContextMenuShare != null)
1301         {
1302                 delete __pContextMenuShare;
1303                 __pContextMenuShare = null;
1304         }
1305
1306         if (__pContextMenuMore != null)
1307         {
1308                 delete __pContextMenuMore;
1309                 __pContextMenuMore = null;
1310         }
1311
1312         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1313
1314         return E_SUCCESS;
1315 }
1316
1317 void
1318 ImageViewerForm::OnActionPerformed(const Control& source, int actionId)
1319 {
1320         AppLogDebug("ENTER actionId(%d)", actionId);
1321         SceneManager* pSceneManager = SceneManager::GetInstance();
1322         InitShowGallery();
1323
1324         switch (actionId)
1325         {
1326         case ACTION_ID_FOOTER_MORE:
1327         {
1328                 InitializeContextMenuMore();
1329
1330                 __pContextMenuMore->SetShowState(true);
1331                 __pContextMenuMore->Show();
1332         }
1333         break;
1334         case ACTION_ID_CONTEXTMENU_SET_AS:
1335                 InitializeContextMenuSetAs();
1336
1337                 __pContextMenuSetAs->SetShowState(true);
1338                 __pContextMenuSetAs->Show();
1339                 break;
1340         case ACTION_ID_FOOTER_BUTTON_SHARE:
1341                 InitializeContextMenuShare();
1342
1343                 __pContextMenuShare->SetShowState(true);
1344                 __pContextMenuShare->Show();
1345                 break;
1346         case ACTION_ID_FOOTER_BUTTON_DELETE:
1347                 __pDeletePopup->SetShowState(true);
1348                 __pDeletePopup->Show();
1349                 break;
1350         case ACTION_ID_FOOTER_BUTTON_SLIDE:
1351         {
1352                 if (__pPopUp != null)
1353                 {
1354                         __pPopUp->SetShowState(true);
1355                         __pPopUp->Show();
1356                 }
1357
1358                 break;
1359         }
1360         case ACTION_ID_FOOTER_BUTTON_CROP:
1361         {
1362                 String filePath;
1363                 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1364                 filePath = __pPresentationModel->GetFilePathAt(__pGallery->GetCurrentItemIndex());
1365                 pList->Add(new (std::nothrow) String(filePath));
1366                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_CROP), pList);
1367         }
1368         break;
1369         case ACTION_ID_FOOTER_BUTTON_ROTATE_RIGHT:
1370         {
1371                 int currentIndex = __pGallery->GetCurrentItemIndex();
1372                 String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
1373                 RotateMode rotateMode = ROTATE_MODE_RIGHT;
1374                 __pPresentationModel->SetImageRotateStatus(true);
1375                 RotateImage(filePath, rotateMode);
1376                 __pPresentationModel->RequestImage(filePath);
1377                 //Invalidate(true);
1378                 ContentManager contentManager;
1379                 contentManager.Construct();
1380                 contentManager.ScanFile(filePath);
1381         }
1382         break;
1383         case ACTION_ID_FOOTER_BUTTON_ROTATE_LEFT:
1384         {
1385                 int currentIndex = __pGallery->GetCurrentItemIndex();
1386                 String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
1387                 RotateMode rotateMode = ROTATE_MODE_LEFT;
1388                 __pPresentationModel->SetImageRotateStatus(true);
1389                 RotateImage(filePath, rotateMode);
1390                 __pPresentationModel->RequestImage(filePath);
1391                 //Invalidate(true);
1392                 ContentManager contentManager;
1393                 contentManager.Construct();
1394                 contentManager.ScanFile(filePath);
1395         }
1396         break;
1397         case ACTION_ID_FOOTER_BUTTON_DETAILS:
1398         {
1399                 ShowPanelDetail(__detail);
1400                 break;
1401         }
1402         case ACTION_ID_FOOTER_BUTTON_BACK:
1403                 ImageViewerForm::OnFormBackRequested(*this);
1404                 break;
1405         case ACTION_ID_FOOTER_BUTTON_DOWNLOAD:
1406                 DownloadFile();
1407                 break;
1408         case ACTION_ID_FOOTER_BUTTON_SAVE:
1409                 break;
1410         case ACTION_ID_PANEL_HEADER_DETAILS_RENAME:
1411         {
1412                 ArrayList* pSelectedIndex = new (std::nothrow) ArrayList(SingleObjectDeleter);
1413                 pSelectedIndex->Construct();
1414                 pSelectedIndex->Add(new (std::nothrow) Integer(__pGallery->GetCurrentItemIndex()));
1415                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_NAME_EDITOR), pSelectedIndex);
1416                 break;
1417         }
1418         case ACTION_ID_CONTEXTMENU_HOME:
1419         {
1420                 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1421                 pList->Add(new (std::nothrow) Integer(__pGallery->GetCurrentItemIndex()));
1422                 pList->Add(new (std::nothrow) Integer(SET_AT_TYPE_HOME_SCREEN_WALLPAPER));
1423                 __pPresentationModel->SetSetterIndex(__pGallery->GetCurrentItemIndex());
1424                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_SETTER), pList);
1425                 break;
1426         }
1427         case ACTION_ID_CONTEXTMENU_LOCK:
1428         {
1429                 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1430                 pList->Add(new (std::nothrow) Integer(__pGallery->GetCurrentItemIndex()));
1431                 pList->Add(new (std::nothrow) Integer(SET_AT_TYPE_LOCK_SCREEN_WALLPAPER));
1432                 __pPresentationModel->SetSetterIndex(__pGallery->GetCurrentItemIndex());
1433                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_SETTER), pList);
1434                 break;
1435         }
1436         case ACTION_ID_CONTEXTMENU_CALLER:
1437         {
1438                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
1439                 pDataList->Construct();
1440                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_SELECTION_MODE),
1441                                 new (std::nothrow) String(APPCONTROL_DATA_SINGLE));
1442                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_SOCIAL_ITEM_TYPE),
1443                                 new (std::nothrow) String(APPCONTROL_DATA_PERSON));
1444                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_SOCIAL_RESULT_TYPE),
1445                                 new (std::nothrow) String(APPCONTROL_DATA_ITEM_ID));
1446
1447                 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_CONTACTS,
1448                                 APPCONTROL_OPERATION_ID_PICK, null, pDataList, this);
1449                 break;
1450         }
1451
1452         case ACTION_ID_CONTEXTMENU_HOME_AND_LOCK:
1453         {
1454                 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1455                 pList->Add(new (std::nothrow) Integer(__pGallery->GetCurrentItemIndex()));
1456                 pList->Add(new (std::nothrow) Integer(SET_AT_TYPE_HOME_AND_LOCK_SCREEN_WALLPAPER));
1457                 __pPresentationModel->SetSetterIndex(__pGallery->GetCurrentItemIndex());
1458                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_SETTER), pList);
1459                 break;
1460                 break;
1461         }
1462
1463         case ACTION_ID_CONTEXTMENU_EMAIL:
1464         {
1465                 OnRequestEmailAction();
1466                 break;
1467         }
1468         case ACTION_ID_CONTEXTMENU_MESSAGE:
1469         {
1470                 OnRequestMessagesAction();
1471                 break;
1472         }
1473         case ACTION_ID_CONTEXTMENU_COPY:
1474         {
1475                 int currentIndex = __pGallery->GetCurrentItemIndex();
1476                 String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
1477
1478                 ClipboardItem item;
1479                 item.Construct(CLIPBOARD_DATA_TYPE_IMAGE, filePath);
1480                 Clipboard* pClipboard = Clipboard::GetInstance();
1481                 pClipboard->CopyItem(item);
1482                 break;
1483         }
1484         case ACTION_ID_DELETE_POPUP_DEL:
1485         {
1486                 __pDeletePopup->SetShowState(false);
1487                 __pDeletePopup->Show();
1488                 DeleteImageFile();
1489
1490                 if (__detail == false)
1491                 {
1492                         ShowPanelDetail(false);
1493                 }
1494                 break;
1495         }
1496         case ACTION_ID_DELETE_POPUP_CANCEL:
1497         {
1498                 __pDeletePopup->SetShowState(false);
1499                 __pDeletePopup->Show();
1500                 break;
1501         }
1502         case ACTION_ID_CONTORL_BUTTON_PLAY:
1503                 CallVideoPlayer();
1504                 break;
1505         default:
1506                 break;
1507         }
1508         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1509 }
1510
1511 void
1512 ImageViewerForm::RotateImage(String& filePath, RotateMode rotateMode)
1513 {
1514         result r = E_SUCCESS;
1515         ImageBuffer* pRotatedBuffer = null;
1516         ImageBuffer* pRotatedBuffer1 = null;
1517         ImageFormat imageFormat;
1518         int width = 0;
1519         int height = 0;
1520         pRotatedBuffer = new (std::nothrow) ImageBuffer();
1521         r = pRotatedBuffer->Construct(filePath);
1522         pRotatedBuffer->GetImageInfo(filePath, imageFormat, width, height);
1523         if (r == E_SUCCESS)
1524         {
1525                 if (rotateMode == ROTATE_MODE_RIGHT)
1526                 {
1527                         pRotatedBuffer1 = pRotatedBuffer->RotateN(IMAGE_ROTATION_90);
1528                 }
1529                 else
1530                 {
1531                         pRotatedBuffer1 = pRotatedBuffer->RotateN(IMAGE_ROTATION_270);
1532                 }
1533         }
1534         TryCatch(pRotatedBuffer1 != null, r = GetLastResult(), "RotateN failed:%s", GetErrorMessage(GetLastResult()));
1535         pRotatedBuffer1->EncodeToFile(filePath, imageFormat, true, 100);
1536         delete pRotatedBuffer1;
1537         delete pRotatedBuffer;
1538         return;
1539
1540         CATCH:
1541         if (pRotatedBuffer != null) //this buffer is no longer used
1542         {
1543                 delete pRotatedBuffer;
1544         }
1545         if (pRotatedBuffer1 != null) //this buffer is no longer used
1546         {
1547                 delete pRotatedBuffer1;
1548         }
1549         return;
1550 }
1551
1552 void
1553 ImageViewerForm::OnFormBackRequested(Form& source)
1554 {
1555         AppLogDebug("ENTER");
1556         if (__detail == false)
1557         {
1558                 ShowPanelDetail(false);
1559         }
1560         else
1561         {
1562                 UiApp* pApp = UiApp::GetInstance();
1563                 pApp->Terminate();
1564         }
1565         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1566 }
1567
1568 void
1569 ImageViewerForm::OnSceneActivatedN(const SceneId& previousSceneId,
1570                 const SceneId& currentSceneId, IList* pArgs)
1571 {
1572         AppLogDebug("ENTER");
1573
1574         Rectangle clientRect = GetClientAreaBounds();
1575         Rectangle rect = GetBounds();
1576
1577         __pGallery->SetBounds(Rectangle(0, clientRect.y, rect.width, rect.height));
1578         __pScrollPanel->SetBounds(Rectangle(0, __pLabel->GetHeight(), clientRect.width, clientRect.height -  __pLabel->GetHeight()));
1579         __pPlayButton->SetBounds(Rectangle(clientRect.width / 2 - 80, clientRect.height / 2 - 80, 160, 160));
1580
1581         if (previousSceneId == IDSCN_IMAGE_NAME_EDITOR && currentSceneId == IDSCN_IMAGE_VIEWER)
1582         {
1583                 SetDetailInfo();
1584                 String strItemIdxText(EMPTY_SPACE);
1585                 GetLabelText(__pGallery->GetCurrentItemIndex(), strItemIdxText);
1586                 __pLabel->SetText(strItemIdxText);
1587                 Invalidate(true);
1588         }
1589
1590         if (__pGallery->GetCurrentItemIndex() < 0)
1591         {
1592                 SetFooterItemState(false);
1593         }
1594         else
1595         {
1596                 SetFooterItemState(true);
1597         }
1598         Invalidate(true);
1599         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1600 }
1601
1602 void
1603 ImageViewerForm::OnSceneDeactivated(const SceneId& currentSceneId,
1604                 const SceneId& nextSceneId)
1605 {
1606         AppLogDebug("ENTER");
1607         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1608 }
1609
1610 void
1611 ImageViewerForm::OnImageDecodedN(const int index)
1612 {
1613         AppLogDebug("ENTER");
1614         __pGallery->RefreshGallery(index, GALLERY_REFRESH_TYPE_ITEM_MODIFY);
1615         __pGallery->Draw();
1616         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1617 }
1618
1619 void
1620 ImageViewerForm::OnAppControlCompleteResponseReceived(const AppId& appId,
1621                 const String& operationId, AppCtrlResult appControlResult,
1622                 const IMap* pExtraData)
1623 {
1624         AppLogDebug("ENTER");
1625
1626         if (appId == APPCONTROL_PROVIDER_ID_CONTACTS
1627                         && operationId == APPCONTROL_OPERATION_ID_PICK
1628                         && appControlResult == APP_CTRL_RESULT_SUCCEEDED)
1629         {
1630                 const String* pContactId =
1631                                 static_cast<const String*>(pExtraData->GetValue(String(APPCONTROL_KEY_SOCIAL_ITEM_ID)));
1632                 SceneManager* pSceneManager = SceneManager::GetInstance();
1633                 long long lresult = 0;
1634                 if (pContactId != null && pContactId->GetLength() > 0)
1635                 {
1636                         LongLong::Parse(*pContactId, lresult);
1637                 }
1638                 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1639                 pList->Add(new (std::nothrow) Integer(__pGallery->GetCurrentItemIndex()));
1640                 pList->Add(new (std::nothrow) Integer(SET_AT_TYPE_CALLER_IMAGE));
1641                 pList->Add(new (std::nothrow) LongLong(lresult));
1642                 __pPresentationModel->SetSetterIndex(__pGallery->GetCurrentItemIndex());
1643                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_SETTER), pList);
1644         }
1645
1646         ImageViewerApp* pImageViewerApp = static_cast<ImageViewerApp*>(ImageViewerApp::GetInstance());
1647         pImageViewerApp->SetFrameEnabled(true);
1648         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1649 }
1650
1651 void
1652 ImageViewerForm::OnOverlayControlCreated(const Control& source)
1653 {
1654         AppLogDebug("ENTER");
1655         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1656 }
1657
1658 void
1659 ImageViewerForm::OnOverlayControlOpened(const Control& source)
1660 {
1661         AppLogDebug("ENTER");
1662         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1663 }
1664
1665 void
1666 ImageViewerForm::OnOverlayControlClosed(const Control& source)
1667 {
1668         AppLogDebug("ENTER");
1669         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1670 }
1671
1672 void
1673 ImageViewerForm::OnOtherControlSelected(const Control& source)
1674 {
1675         AppLogDebug("ENTER");
1676         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1677 }
1678
1679 void
1680 ImageViewerForm::InitShowGallery(void)
1681 {
1682         AppLogDebug("ENTER");
1683         if (__pGallery != null && __pGallery->IsVisible() == false)
1684         {
1685                 Canvas* pCanvas = GetCanvasN();
1686                 if (pCanvas == null || GetLastResult() != E_SUCCESS)
1687                 {
1688                         AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1689
1690                         return;
1691                 }
1692
1693                 pCanvas->Clear();
1694                 __pGallery->SetShowState(true);
1695                 delete pCanvas;
1696         }
1697         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1698 }
1699
1700 void
1701 ImageViewerForm::OnTimerExpired(Timer &timer)
1702 {
1703         int repeatValue = 0;
1704         AppLogDebug("ENTER");
1705         if (__pPresentationModel->GetFileCount() > 1)
1706         {
1707                 __pSettingPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
1708                                 ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
1709
1710                 if (repeatValue == 0)
1711                 {
1712                         __pGallery->StartSlideShow(false);
1713                 }
1714                 else
1715                 {
1716                         __pGallery->StartSlideShow(true);
1717                 }
1718         }
1719         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1720 }
1721
1722 void
1723 ImageViewerForm::OnContentTransferInProgress(RequestId requestId, int totalReceivedSize)
1724 {
1725         AppLogDebug("ENTER");
1726         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1727 }
1728
1729 void
1730 ImageViewerForm::OnContentUploadCompleted(RequestId requestId, result transferResult, const String& errorCode,
1731                 const String& errorMessage)
1732 {
1733         AppLogDebug("ENTER");
1734         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1735 }
1736
1737 void
1738 ImageViewerForm::OnContentDownloadCompleted(RequestId requestId, ContentId contentId,
1739                 result transferResult, const String& errorCode, const String& errorMessage)
1740 {
1741         AppLogDebug("ENTER");
1742         AppLogTag("IV", "ImageViewerForm::OnContentDownloadCompleted");
1743         AppLogTag("IV", "DownloadCompleted Error [%s]", GetErrorMessage(transferResult));
1744         AppLogTag("IV", "errorCode [%ls] errorMessage [%ls]", errorCode.GetPointer(), errorMessage.GetPointer());
1745         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1746 }
1747
1748 void
1749 ImageViewerForm::OnContentDownloadToBufferCompleted(RequestId reqId, ByteBuffer* pBuffer, result r,
1750                 const String& errorCode, const String& errorMessage)
1751 {
1752         AppLogDebug("ENTER");
1753         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1754 }
1755
1756 void
1757 ImageViewerForm::OnContentTransferCanceled(RequestId reqId, result res, const String& errorCode,
1758                 const String& errorMessage)
1759 {
1760         AppLogDebug("ENTER");
1761         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1762 }
1763
1764 void
1765 ImageViewerForm::RequestDecodeUrl(void)
1766 {
1767         AppLogDebug("ENTER");
1768
1769         String filePath = __pPresentationModel->GetFilePathAt(0);
1770
1771         if (filePath.StartsWith(WEB_URL_HTTP, 0) == false)
1772         {
1773                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1774
1775                 return;
1776         }
1777
1778         __downLordFileName = __pPresentationModel->GetFileName(filePath);
1779
1780         Image* pImage = new (std::nothrow) Image();
1781         pImage->Construct();
1782         Uri uri;
1783         RequestId reqId;
1784         uri.SetUri(filePath);
1785
1786         pImage->DecodeUrl(uri, BITMAP_PIXEL_FORMAT_RGB565, 720, 1280, reqId, *this, 5000);
1787
1788         delete pImage;
1789         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1790 }
1791
1792 void
1793 ImageViewerForm::OnImageDecodeUrlReceived (RequestId reqId, Bitmap *pBitmap,
1794                 result r, const String errorCode, const String errorMessage)
1795 {
1796         AppLogDebug("ENTER");
1797         Image* pImage = new (std::nothrow) Image();
1798         pImage->Construct();
1799
1800         String destPath = App::GetInstance()->GetAppRootPath() + TEMP_FILE_PATH_WEB_FILE;
1801         r = pImage->EncodeToFile(*pBitmap, IMG_FORMAT_JPG, destPath, true);
1802
1803         if (r == E_SUCCESS)
1804         {
1805                 __pPresentationModel->GetImageCacheAt(0)->SetFilePath(destPath);
1806                 __pPresentationModel->GetImageCacheAt(0)->SetBitmap(pBitmap);
1807
1808                 __pGallery->RefreshGallery(0, GALLERY_REFRESH_TYPE_ITEM_MODIFY);
1809                 __pGallery->Draw();
1810                 __pPresentationModel->RequestImage(destPath);
1811         }
1812         else
1813         {
1814                 AppLogDebug("ImageViewerForm::OnImageDecodeUrlReceived [%s]", GetErrorMessage(r));
1815         }
1816
1817         delete pImage;
1818         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1819 }
1820
1821 void
1822 ImageViewerForm::OnRequestEmailAction(void)
1823 {
1824         AppLogDebug("ENTER");
1825         int currentIndex = __pGallery->GetCurrentItemIndex();
1826
1827         if (__pPresentationModel->GetFileCount() <= 0)
1828         {
1829                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1830                 return;
1831         }
1832
1833         String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
1834
1835         HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
1836         pDataList->Construct();
1837
1838         IList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1839         pList->Add(new (std::nothrow) String(filePath));
1840
1841         pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pList);
1842
1843         __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_EMAIL, APPCONTROL_OPERATION_ID_COMPOSE,
1844                         null, pDataList, this);
1845         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1846 }
1847
1848 void
1849 ImageViewerForm::OnRequestMessagesAction(void)
1850 {
1851         AppLogDebug("ENTER");
1852         int currentIndex = __pGallery->GetCurrentItemIndex();
1853
1854         if (__pPresentationModel->GetFileCount() <= 0)
1855         {
1856                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1857                 return;
1858         }
1859
1860         String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
1861
1862         HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
1863         pDataList->Construct();
1864         pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_MESSAGE_TYPE),
1865                         new (std::nothrow) String(APPCONTROL_DATA_MMS));
1866
1867         IList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1868         pList->Add(new (std::nothrow) String(filePath));
1869
1870         pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pList);
1871
1872         __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_MESSAGES,
1873                         APPCONTROL_OPERATION_ID_COMPOSE, null, pDataList, this);
1874         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1875 }
1876
1877 void
1878 ImageViewerForm::SetFooterItemState(bool isEnable)
1879 {
1880         AppLogDebug("ENTER");
1881         if (__initializeDisplayModeCurrent == APPCONTROL_MODE_NORMAL)
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_WEB_LINK)
1888         {
1889                 __pFooter->SetButtonEnabled(BUTTON_POSITION_LEFT, isEnable);
1890                 __pFooter->SetItemEnabled(0, isEnable);
1891                 __pFooter->SetItemEnabled(1, isEnable);
1892         }
1893         else if (__initializeDisplayModeCurrent == APPCONTROL_MODE_CROP)
1894         {
1895                 __pFooter->SetItemEnabled(0, isEnable);
1896         }
1897         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1898 }
1899
1900 Bitmap*
1901 ImageViewerForm::GetQuickThumbnailN(String& filePath)
1902 {
1903         AppLogDebug("ENTER");
1904         Bitmap* pBitmap = null;
1905
1906         if (filePath.GetLength() > 4)
1907         {
1908                 int totalPage = 0;
1909                 int totalCount = 0;
1910                 ContentSearch contentSearch;
1911                 ContentSearchResult* pResultItem = null;
1912                 IList* pContentInfoList = null;
1913                 String queryString;
1914                 ContentType contentType = ContentManagerUtil::CheckContentType(filePath);
1915                 result r = contentSearch.Construct(contentType);
1916                 AppLogDebug("r(%s)", GetErrorMessage(r));
1917                 if (r != E_SUCCESS)
1918                 {
1919                         pBitmap = new (std::nothrow) Bitmap();
1920                         r = pBitmap->Construct(DUMMY_IMAGE_DIMENSION, BITMAP_PIXEL_FORMAT_RGB565);
1921                         if (r == E_SUCCESS)
1922                         {
1923                                 return pBitmap;
1924                         }
1925                         else
1926                         {
1927                                 delete pBitmap;
1928                                 return null;
1929                         }
1930                 }
1931                 queryString = CONTENT_QUERY_PREFIX_FILENAME;
1932                 queryString.Append(L"'");
1933                 queryString.Append(__pPresentationModel->GetFileName(filePath));
1934                 queryString.Append(L"'");
1935
1936                 pContentInfoList = contentSearch.SearchN(PAGE_NO_CONTENT_SEARCH, COUNT_PER_PAGE_CONTENT_SEARCH,
1937                                 totalPage, totalCount, queryString, EMPTY_SPACE, SORT_ORDER_NONE);
1938
1939                 if ((pContentInfoList != null) && GetLastResult() == E_SUCCESS && (pContentInfoList->GetCount() > 0))
1940                 {
1941                         IEnumerator* pEnum = pContentInfoList->GetEnumeratorN();
1942                         while (pEnum->MoveNext() == E_SUCCESS)
1943                         {
1944                                 pResultItem = static_cast<ContentSearchResult*>(pEnum->GetCurrent());
1945                                 if (pResultItem == null)
1946                                 {
1947                                         continue;
1948                                 }
1949
1950                                 if (pResultItem->GetContentInfo()->GetContentPath().CompareTo(filePath) == 0)
1951                                 {
1952                                         pBitmap = pResultItem->GetContentInfo()->GetThumbnailN();
1953                                 }
1954                         }
1955                         delete pEnum;
1956                 }
1957
1958                 if (pContentInfoList != null)
1959                 {
1960                         delete pContentInfoList;
1961                 }
1962
1963                 if (pBitmap != null)
1964                 {
1965                         ImageViewerMediaType mediaType = CommonUtil::GetMediaType(filePath);
1966
1967                         if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE)
1968                         {
1969                                 ImageBuffer* imageBuffer = new (std::nothrow) ImageBuffer();
1970                                 result r = imageBuffer->Construct(filePath);
1971                                 if (r == E_SUCCESS)
1972                                 {
1973                                         if (imageBuffer->GetExifOrientation() == EXIF_ORIENTATION_RIGHT_TOP
1974                                                         || imageBuffer->GetExifOrientation() == EXIF_ORIENTATION_LEFT_BOTTOM)
1975                                         {
1976                                                 Dimension srcDim(imageBuffer->GetHeight(), imageBuffer->GetWidth());
1977                                                 pBitmap->Scale(srcDim);
1978                                         }
1979                                         else
1980                                         {
1981                                                 Dimension srcDim(imageBuffer->GetWidth(), imageBuffer->GetHeight());
1982                                                 pBitmap->Scale(srcDim);
1983                                         }
1984
1985                                         delete imageBuffer;
1986                                 }
1987                         }
1988                         else if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_VIDEO)
1989                         {
1990                                 VideoMetadata* pVideoMeta = ContentManagerUtil::GetVideoMetaN(filePath);
1991
1992                                 if (pVideoMeta != null && GetLastResult() == E_SUCCESS)
1993                                 {
1994                                         Dimension srcDim(pVideoMeta->GetWidth(), pVideoMeta->GetHeight());
1995                                         pBitmap->Scale(srcDim);
1996                                         delete pVideoMeta;
1997                                 }
1998                         }
1999                 }
2000                 else
2001                 {
2002                         Canvas mainCanvas;
2003                         mainCanvas.Construct(DUMMY_IMAGE_RECTANGLE);
2004                         mainCanvas.FillRectangle(Color::GetColor(COLOR_ID_WHITE), DUMMY_IMAGE_RECTANGLE);
2005                         pBitmap = new (std::nothrow) Bitmap();
2006                         pBitmap->Construct(mainCanvas, DUMMY_IMAGE_RECTANGLE);
2007                 }
2008         }
2009         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
2010         return pBitmap;
2011 }
2012
2013 void ImageViewerForm::OnFormFileEventOccuered(const int index, const unsigned long eventId)
2014 {
2015         AppLogDebug(" ENTER");
2016         bool eventDelete = (eventId & FILE_EVENT_TYPE_DELETE_SELF);
2017         bool eventMove = (eventId & 0x8000);// (eventId & FILE_EVENT_TYPE_MOVE_SELF);
2018
2019         int currentIndex = __pGallery->GetCurrentItemIndex();
2020         int countPath = __pPresentationModel->GetFileCount();
2021
2022         if (countPath == 0 && eventDelete)
2023         {
2024                 UiApp* pApp = UiApp::GetInstance();
2025                 pApp->Terminate();
2026                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
2027         }
2028         AppLogDebug(" countPath is %d", countPath);
2029         AppLogDebug(" currentIndex is %d", currentIndex);
2030
2031         if (countPath == currentIndex && eventDelete)
2032         {
2033                 __pGallery->SetCurrentItemIndex(--currentIndex);
2034         }
2035         else if (eventMove)
2036         {
2037                 currentIndex = index;
2038                 __pGallery->SetCurrentItemIndex(currentIndex);
2039         }
2040
2041         String strItemIdxText(EMPTY_SPACE);
2042
2043         __pGallery->UpdateGallery();
2044         AppLogDebug(" UpdateGallery is %d", currentIndex);
2045         String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
2046         __pPresentationModel->RequestImage(filePath);
2047
2048         GetLabelText(currentIndex,strItemIdxText);
2049         __pLabel->SetText(strItemIdxText);
2050
2051         if (__visible == true)
2052         {
2053                 ImageViewerMediaType mediaType = CommonUtil::GetMediaType(filePath);
2054
2055                 if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE)
2056                 {
2057                         __pPlayButton->SetShowState(false);
2058                 }
2059                 else
2060                 {
2061                         __pPlayButton->SetShowState(true);
2062                 }
2063         }
2064         if (__detail == false)
2065         {
2066                 __pScrollPanel->SetShowState(false);
2067                 __detail = true;
2068         }
2069
2070         Invalidate(true);
2071         AppLogDebug("EXIT");
2072 }
2073
2074 void
2075 ImageViewerForm::OnSlideSettingPopUpItemSelected(int index)
2076 {
2077
2078         if ( __pPopUp != NULL)
2079         {
2080                 __pPopUp->SetShowState(false);
2081         }
2082
2083         if (index == 0)   // start slide show
2084         {
2085                 int repeatValue = 0;
2086
2087                 if (__pPresentationModel->GetFileCount() > 1)
2088                 {
2089                         __pGallery->UpdateGallery();
2090
2091                         if (__detail == false)
2092                         {
2093                                 ShowPanelDetail(false);
2094                         }
2095
2096                         __pSettingPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
2097                                         ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
2098
2099                         if (repeatValue == 0)
2100                         {
2101                                 __pGallery->StartSlideShow(false);
2102                         }
2103                         else
2104                         {
2105                                 __pGallery->StartSlideShow(true);
2106                         }
2107                 }
2108         }
2109         else if (index == 1) // launch settings
2110         {
2111                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
2112                 pDataList->Construct();
2113
2114                 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_GALLERY,
2115                                 APPCONTROL_OPERATION_ID_CONFIGURE, null, null, this);
2116         }
2117 }