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