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