Change delete string
[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_PAGE:
582                 __pGallery->SetSlideShowAnimation(Controls::GALLERY_ANIMATION_PAGE);
583                 break;
584         }
585
586         __pGallery->SetSlideShowViewDuration(__pPresentationModel->GetDurationOfSlideShow());
587
588         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
589 }
590
591 result
592 ImageViewerForm::InitializePanelDetail()
593 {
594         AppLogDebug("ENTER");
595         __pScrollPanel = new (std::nothrow) ScrollPanel();
596
597         String arrayId[DETAIL_COUNT_MAX] =
598         {
599                 L"IDS_COM_BODY_DETAILS_NAME", L"IDS_IV_BODY_FILE_FORMAT", L"IDS_IV_BODY_DATE_CREATED",
600                 L"IDS_COM_BODY_SIZE", L"IDS_IV_BODY_RESOLUTION", L"IDS_COM_BODY_LOCATION",
601                 L"IDS_COM_BODY_LATITUDE", L"IDS_COM_BODY_LONGITUDE", L"IDS_IV_BODY_FILE_LOCATION"
602         };
603
604         if (__pScrollPanel == null)
605         {
606                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
607
608                 return E_INVALID_STATE;
609         }
610
611         Rectangle clientRect = GetClientAreaBounds();
612         result r = __pScrollPanel->Construct(Rectangle(0, 0, clientRect.width, clientRect.height - __pLabel->GetHeight()));
613         if (r != E_SUCCESS)
614         {
615                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
616
617                 return E_INVALID_STATE;
618         }
619
620         __pDetail_Label = new (std::nothrow) Label();
621         __pDetail_Label->Construct(RECT_DETAILS_CONTORL_LABEL, ResourceManager::GetString(L"IDS_COM_BODY_DETAILS"));
622         __pScrollPanel->AddControl(*__pDetail_Label);
623         __pDetail_Label->SetTextVerticalAlignment(ALIGNMENT_TOP);
624         __pDetail_Label->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
625         __pDetail_Label->SetTextColor(Color::GetColor(COLOR_ID_WHITE));
626         __pDetail_Label->SetTextConfig(DETAIL_MAIN_FONT_SIZE, LABEL_TEXT_STYLE_BOLD);
627
628         for (int i = 0; i < DETAIL_COUNT_MAX; ++i)
629         {
630                 __pDetail_FileInfo_Label[i] = new (std::nothrow) Label();
631                 __pDetail_FileInfo_Label[i]->Construct(
632                                 Rectangle(X_DETAIL_FILEINFO_LABEL,
633                                                 GAP_H_DETAIL_TEXT * (i + 1) + H_DETAIL_MAIN_TEXT + (H_DETAIL_MAIN_TEXT + H_DETAIL_SUB_TEXT) * i,
634                                                 clientRect.width - GAP_W_END_OF_LABEL, H_DETAIL_FILEINFO_LABEL), ResourceManager::GetString(arrayId[i]));
635                 __pScrollPanel->AddControl(*__pDetail_FileInfo_Label[i]);
636
637                 __pDetail_FileInfo_Label[i]->SetTextVerticalAlignment(ALIGNMENT_TOP);
638                 __pDetail_FileInfo_Label[i]->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
639                 __pDetail_FileInfo_Label[i]->SetTextColor(Color::GetColor(COLOR_ID_GREY));
640                 __pDetail_FileInfo_Label[i]->SetTextConfig(DETAIL_SUB_FONT_SIZE, LABEL_TEXT_STYLE_BOLD);
641
642                 __pDetail_FileInfo_Value_Label[i] = new (std::nothrow) Label();
643
644                 if (i == DETAIL_COUNT_MAX - 1)
645                 {
646                         __pDetail_FileInfo_Value_Label[i]->Construct(
647                                         Rectangle(X_DETAIL_FILEINFO_LABEL,
648                                                         GAP_H_DETAIL_TEXT * (i + 1) + H_DETAIL_MAIN_TEXT + (H_DETAIL_MAIN_TEXT * i) + H_DETAIL_SUB_TEXT * (i + 1),
649                                                         clientRect.width - GAP_W_END_OF_LABEL, H_DETAIL_FILEINFO_VALUE_LABEL * 3), L"");
650                 }
651                 else
652                 {
653                         __pDetail_FileInfo_Value_Label[i]->Construct(
654                                         Rectangle(X_DETAIL_FILEINFO_LABEL,
655                                                         GAP_H_DETAIL_TEXT * (i + 1) + H_DETAIL_MAIN_TEXT + (H_DETAIL_MAIN_TEXT * i) + H_DETAIL_SUB_TEXT * (i + 1),
656                                                         clientRect.width - GAP_W_END_OF_LABEL, H_DETAIL_FILEINFO_VALUE_LABEL), L"");
657                 }
658
659                 __pScrollPanel->AddControl(*__pDetail_FileInfo_Value_Label[i]);
660
661                 __pDetail_FileInfo_Value_Label[i]->SetTextVerticalAlignment(ALIGNMENT_TOP);
662                 __pDetail_FileInfo_Value_Label[i]->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
663                 __pDetail_FileInfo_Value_Label[i]->SetTextColor(Color::GetColor(COLOR_ID_WHITE));
664                 __pDetail_FileInfo_Value_Label[i]->SetTextConfig(DETAIL_MAIN_FONT_SIZE, LABEL_TEXT_STYLE_BOLD);
665         }
666
667         __pScrollPanel->SetBackgroundColor(COLOR_HEADER_CONTROL_PANEL);
668         __pScrollPanel->SetShowState(false);
669
670         __pRenameButton = new (std::nothrow) Button();
671         Rectangle rect = GetBounds();
672         __pRenameButton->Construct(Rectangle(rect.width - W_RENAME_BUTTON - 20, Y_RENAME_BUTTON, W_RENAME_BUTTON, H_RENAME_BUTTON));
673         __pRenameButton->SetActionId(ACTION_ID_PANEL_HEADER_DETAILS_RENAME);
674         __pRenameButton->AddActionEventListener(*this);
675
676         Bitmap* pIcon = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_EDIT_NAME);
677         Bitmap* pIconBackground =
678                         ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_EDIT_NAME_NORMAL_BACKGROUND);
679         Bitmap* pIconPressed =
680                         ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_EDIT_NAME_NORMAL_BACKGROUND_PRESS);
681
682         if (pIcon != null && pIconPressed != null && pIconBackground != null)
683         {
684                 __pRenameButton->SetNormalBackgroundBitmap(*pIconBackground);
685                 __pRenameButton->SetPressedBackgroundBitmap(*pIconPressed);
686                 Point iconPosition(0, 0);
687                 __pRenameButton->SetNormalBitmap(iconPosition, *pIcon);
688                 __pRenameButton->SetPressedBitmap(iconPosition, *pIconPressed);
689         }
690         else
691         {
692                 __pRenameButton->SetColor(BUTTON_STATUS_NORMAL, COLOR_HEADER_BUTTON1);
693                 __pRenameButton->SetColor(BUTTON_STATUS_PRESSED, COLOR_HEADER_BUTTON1);
694         }
695         delete pIcon;
696         delete pIconPressed;
697         delete pIconBackground;
698
699         __pRenameButton->SetColor(BUTTON_STATUS_NORMAL, COLOR_HEADER_BUTTON1);
700         __pScrollPanel->AddControl(*__pRenameButton);
701
702
703         AddControl(*__pScrollPanel);
704         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
705
706         return E_SUCCESS;
707 }
708
709 result
710 ImageViewerForm::InitializePopup(void)
711 {
712         AppLogDebug("ENTER");
713         if (__pDeletePopup == null)
714         {
715                 __pDeletePopup = new (std::nothrow) Popup();
716                 __pDeletePopup->Construct(false, Dimension(W_DELETE_POPUP, H_DELETE_POPUP));
717
718                 Rectangle popupClientBounds = __pDeletePopup->GetClientAreaBounds();
719
720                 Label* pLabel = new (std::nothrow) Label();
721                 pLabel->Construct(Rectangle(0, 0, popupClientBounds.width, H_DELETE_LABEL),
722                                 ResourceManager::GetString(L"IDS_COM_POP_DELETE_Q"));
723
724                 Button* pDeleteButton = new (std::nothrow) Button();
725                 pDeleteButton->Construct(
726                                 Rectangle(0, Y_DELETE_BUTTON, popupClientBounds.width / 2 - GAP_W_POPUP_ITEM, H_DELETE_BUTTON),
727                                 ResourceManager::GetString(L"IDS_COM_BODY_DELETE"));
728                 pDeleteButton->SetColor(BUTTON_STATUS_NORMAL, COLOR_DELETE_BUTTON_NORMAL);
729                 pDeleteButton->SetColor(BUTTON_STATUS_PRESSED, COLOR_DELETE_BUTTON_PRESSED);
730                 pDeleteButton->SetTextColor(COLOR_DELETE_BUTTON_TEXT);
731                 pDeleteButton->SetActionId(ACTION_ID_DELETE_POPUP_DEL);
732                 pDeleteButton->AddActionEventListener(*this);
733
734                 Button* pCancelButton = new (std::nothrow) Button();
735                 pCancelButton->Construct(
736                                 Rectangle(popupClientBounds.width / 2 + GAP_W_POPUP_ITEM,
737                                                 Y_DELETE_BUTTON, popupClientBounds.width / 2 - GAP_W_POPUP_ITEM, H_DELETE_BUTTON),
738                                                 ResourceManager::GetString(L"IDS_COM_SK_CANCEL"));
739                 pCancelButton->SetActionId(ACTION_ID_DELETE_POPUP_CANCEL);
740                 pCancelButton->AddActionEventListener(*this);
741
742                 __pDeletePopup->AddControl(*pLabel);
743                 __pDeletePopup->AddControl(*pDeleteButton);
744                 __pDeletePopup->AddControl(*pCancelButton);
745         }
746         else
747         {
748                 __pDeletePopup->SetShowState(true);
749                 __pDeletePopup->Show();
750         }
751         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
752
753         return E_SUCCESS;
754 }
755
756 result
757 ImageViewerForm::InitializeContextMenuMore(void)
758 {
759         AppLogDebug("ENTER");
760         int currentIndex = __pGallery->GetCurrentItemIndex();
761         String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
762
763         ImageViewerMediaType mediaType = CommonUtil::GetMediaType(filePath);
764
765         if (__pContextMenuMore != null)
766         {
767                 delete __pContextMenuMore;
768                 __pContextMenuMore = null;
769         }
770
771         __pContextMenuMore = new (std::nothrow) ContextMenu();
772
773         __pContextMenuMore->Construct(Point(X_MORE,  GetClientAreaBounds().height),
774                         CONTEXT_MENU_STYLE_LIST, CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD);
775
776         if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE)
777         {
778                 __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_IV_OPT_SET_AS"),
779                                 ACTION_ID_CONTEXTMENU_SET_AS);
780                 __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_IV_BODY_CROP"), ACTION_ID_FOOTER_BUTTON_CROP);
781         }
782
783         if (__pGallery->GetItemCount() > 1)
784         {
785                 __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_IV_OPT_SLIDE_SHOW"),
786                                 ACTION_ID_FOOTER_BUTTON_SLIDE);
787         }
788         __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_DETAILS"),
789                         ACTION_ID_FOOTER_BUTTON_DETAILS);
790         __pContextMenuMore->SetShowState(false);
791         __pContextMenuMore->AddActionEventListener(*this);
792         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
793
794         return E_SUCCESS;
795 }
796
797 result
798 ImageViewerForm::InitializeContextMenuSetAs(void)
799 {
800         AppLogDebug("ENTER");
801
802         if (__pContextMenuSetAs != null)
803         {
804                 delete __pContextMenuSetAs;
805                 __pContextMenuSetAs = null;
806         }
807
808         __pContextMenuSetAs = new (std::nothrow) ContextMenu();
809         __pContextMenuSetAs->Construct(Point(X_MORE, GetClientAreaBounds().y + GetClientAreaBounds().height),
810                         CONTEXT_MENU_STYLE_LIST, CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD);
811
812         __pContextMenuSetAs->AddItem(ResourceManager::GetString(L"IDS_IV_HEADER_HOME_SCREEN_WALLPAPER_ABB"),
813                         ACTION_ID_CONTEXTMENU_HOME);
814         __pContextMenuSetAs->AddItem(ResourceManager::GetString(L"IDS_IV_HEADER_LOCK_SCREEN_WALLPAPER_ABB"),
815                         ACTION_ID_CONTEXTMENU_LOCK);
816         __pContextMenuSetAs->AddItem(ResourceManager::GetString(L"IDS_IV_BODY_HOME_AND_LOCK_SCREENS"),
817                         ACTION_ID_CONTEXTMENU_HOME_AND_LOCK);
818         __pContextMenuSetAs->AddItem(ResourceManager::GetString(L"IDS_IV_BODY_CALLER_IMAGE"),
819                         ACTION_ID_CONTEXTMENU_CALLER);
820         __pContextMenuSetAs->AddActionEventListener(*this);
821         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
822
823         return E_SUCCESS;
824 }
825
826 result
827 ImageViewerForm::InitializeContextMenuShare(void)
828 {
829         AppLogDebug("ENTER");
830         if (__pContextMenuShare != null)
831         {
832                 delete __pContextMenuShare;
833                 __pContextMenuShare = null;
834         }
835         __pContextMenuShare = new (std::nothrow) ContextMenu();
836         __pContextMenuShare->Construct(Point((GetClientAreaBounds().width - (X_MORE * 4)) / 4 + X_MORE * 2,
837                         GetClientAreaBounds().y + GetClientAreaBounds().height), CONTEXT_MENU_STYLE_LIST,
838                         CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD);
839
840         __pContextMenuShare->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_MESSAGE"),
841                         ACTION_ID_CONTEXTMENU_MESSAGE);
842         __pContextMenuShare->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_EMAIL"), ACTION_ID_CONTEXTMENU_EMAIL);
843         __pContextMenuShare->AddActionEventListener(*this);
844         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
845
846         return E_SUCCESS;
847 }
848
849 long long
850 ImageViewerForm::GetFileSize(String filePath)
851 {
852         AppLogDebug("ENTER");
853         FileAttributes attr;
854         long long size = 0;
855
856         result r = File::GetAttributes(filePath, attr);
857         if (r != E_SUCCESS)
858         {
859                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
860
861                 return 0;
862         }
863         size = attr.GetFileSize();
864         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
865
866         return size;
867 }
868
869 result
870 ImageViewerForm::SetDetailInfo(void)
871 {
872         AppLogDebug("ENTER");
873
874         Rectangle clientRect = GetClientAreaBounds();
875         __pScrollPanel->SetBounds(0,__pLabel->GetHeight(), clientRect.width, clientRect.height - __pLabel->GetHeight());
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
990                 if (i == DETAIL_COUNT_MAX - 1)
991                 {
992                         __pDetail_FileInfo_Value_Label[i]->SetBounds(
993                                         Rectangle(X_DETAIL_FILEINFO_LABEL,
994                                                         GAP_H_DETAIL_TEXT * (i + 1) + H_DETAIL_MAIN_TEXT + (H_DETAIL_MAIN_TEXT * i) + H_DETAIL_SUB_TEXT * (i + 1),
995                                                         clientRect.width - GAP_W_END_OF_LABEL, H_DETAIL_FILEINFO_VALUE_LABEL * 3));
996                 }
997                 else
998                 {
999                         __pDetail_FileInfo_Value_Label[i]->SetBounds(
1000                                         Rectangle(X_DETAIL_FILEINFO_LABEL,
1001                                                         GAP_H_DETAIL_TEXT * (i + 1) + H_DETAIL_MAIN_TEXT + (H_DETAIL_MAIN_TEXT * i) + H_DETAIL_SUB_TEXT * (i + 1),
1002                                                         clientRect.width - GAP_W_END_OF_LABEL, H_DETAIL_FILEINFO_VALUE_LABEL));
1003                 }
1004
1005                 __pDetail_FileInfo_Value_Label[i]->Invalidate(true);
1006         }
1007
1008         if (__initializeDisplayModeCurrent == APPCONTROL_MODE_WEB_LINK)
1009         {
1010                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1011                 return r;
1012         }
1013
1014         Rectangle rect = GetBounds();
1015         __pRenameButton->SetBounds(Rectangle(rect.width - W_RENAME_BUTTON - 20, Y_RENAME_BUTTON, W_RENAME_BUTTON, H_RENAME_BUTTON));
1016
1017         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1018
1019         return r;
1020 }
1021
1022 result
1023 ImageViewerForm::ShowPanelDetail(bool showStatus)
1024 {
1025         AppLogDebug("ENTER");
1026         if (showStatus)
1027         {
1028                 SetDetailInfo();
1029                 __pLabel->SetBackgroundColor(COLOR_HEADER_CONTROL_PANEL);
1030                 __pLabel->Invalidate(true);
1031                 __pScrollPanel->SetShowState(true);
1032                 __detail = false;
1033         }
1034         else
1035         {
1036                 __pLabel->SetBackgroundColor(COLOR_HEADER_CONTROL_LABEL);
1037                 __pLabel->Invalidate(true);
1038                 __pScrollPanel->SetShowState(false);
1039                 __detail = true;
1040         }
1041         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1042
1043         return E_SUCCESS;
1044 }
1045
1046 result
1047 ImageViewerForm::ChangeFooterItem(bool isChanged, Footer* pFooter, int position)
1048 {
1049         AppLogDebug("ENTER");
1050         FooterItem footerItem;
1051         footerItem.Construct(ACTION_ID_FOOTER_BUTTON_DETAILS);
1052         Bitmap* pfooterItem = null;
1053
1054         if (isChanged)
1055         {
1056                 pfooterItem = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_DETAILS_CLOSE);
1057                 footerItem.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pfooterItem);
1058         }
1059         else
1060         {
1061                 pfooterItem = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_DETAILS);
1062                 footerItem.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pfooterItem);
1063         }
1064
1065         pFooter->SetItemAt(position, footerItem);
1066         pFooter->Invalidate(true);
1067
1068         delete pfooterItem;
1069         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1070
1071         return E_SUCCESS;
1072 }
1073
1074 void
1075 ImageViewerForm::DownloadFile(void)
1076 {
1077         AppLogDebug("ENTER");
1078         String DestPath = App::GetInstance()->GetAppRootPath() + TEMP_FILE_PATH_WEB_FILE;
1079         if (File::IsFileExist(DestPath) == false)
1080         {
1081                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1082                 return;
1083         }
1084
1085         ContentId contentId;
1086         ContentManager contentManager;
1087         contentManager.Construct();
1088
1089         ImageContentInfo imageContentInfo;
1090         imageContentInfo.Construct(null);
1091
1092         imageContentInfo.SetKeyword(L"platform, tizen");
1093         String sourcePath = DestPath;
1094         String destPath = Environment::GetMediaPath();
1095         destPath.Append(FOLDER_PATH_DOWNLOADS);
1096         destPath.Append(__downLordFileName);
1097
1098         contentId = contentManager.CreateContent(sourcePath, destPath, true, &imageContentInfo);
1099         ImageViewerForm::OnFormBackRequested(*this);
1100         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1101 }
1102
1103 int
1104 ImageViewerForm::GetItemCount(void)
1105 {
1106         AppLogDebug("ENTER");
1107         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1108
1109         return __pPresentationModel->GetFileCount();
1110 }
1111
1112 GalleryItem*
1113 ImageViewerForm::CreateItem(int index)
1114 {
1115         AppLogDebug("ENTER : index(%d)", index);
1116         GalleryItem* pGallery = new (std::nothrow) GalleryItem();
1117
1118         int curIndex = index;
1119
1120         if (__shuffle == true && __pShuffledList != null)
1121         {
1122                 curIndex = __pShuffledList[index];
1123         }
1124
1125         String filePath = __pPresentationModel->GetFilePathAt(curIndex);
1126         ImageInfo* pImageInfo = __pPresentationModel->GetImageCacheAt(curIndex);
1127         Bitmap* pBitmap = pImageInfo->GetBitmapN();
1128
1129         if (pBitmap == null)
1130         {
1131                 pBitmap = GetQuickThumbnailN(filePath);
1132
1133                 if (pBitmap == null)
1134                 {
1135                         pBitmap = new (std::nothrow) Bitmap();
1136                         pBitmap->Construct(DUMMY_IMAGE_DIMENSION, BITMAP_PIXEL_FORMAT_RGB565);
1137                 }
1138         }
1139         pGallery->Construct(*pBitmap, filePath);
1140         delete pBitmap;
1141         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1142
1143         return pGallery;
1144 }
1145
1146 bool
1147 ImageViewerForm::DeleteItem(int index, GalleryItem* pItem)
1148 {
1149         AppLogDebug("ImageViewerForm::DeleteItem ENTER index(%d)", index);
1150         int curIndex = index;
1151
1152         if(__shuffle == true && __pShuffledList != null)
1153         {
1154                 curIndex = __pShuffledList[index];
1155         }
1156
1157
1158         ImageInfo* pImageInfo = __pPresentationModel->GetImageCacheAt(curIndex);
1159         pImageInfo->ClearBitmap();
1160         delete pItem;
1161         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1162
1163         return true;
1164 }
1165
1166 void
1167 ImageViewerForm::OnGalleryCurrentItemChanged(Gallery& view, int index)
1168 {
1169         AppLogDebug("ImageViewerForm::OnGalleryCurrentItemChanged index(%d)", index);
1170
1171         String filePath = __pPresentationModel->GetFilePathAt(index);
1172         AppLogDebug("ENTER index(%d) filePath(%ls)", index, filePath.GetPointer());
1173         __pPresentationModel->RequestImage(filePath);
1174
1175         String strItemIdxText;
1176         GetLabelText(__pGallery->GetCurrentItemIndex(), strItemIdxText);
1177         __pLabel->SetText(strItemIdxText);
1178
1179         if (__visible == true)
1180         {
1181                 ImageViewerMediaType mediaType = CommonUtil::GetMediaType(filePath);
1182                 if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_VIDEO)
1183                 {
1184                         __pPlayButton->SetShowState(true);
1185                 }
1186                 else
1187                 {
1188                         __pPlayButton->SetShowState(false);
1189                 }
1190         }
1191
1192         Invalidate(true);
1193         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1194 }
1195
1196 void
1197 ImageViewerForm::OnGalleryItemClicked(Gallery& view, int index)
1198 {
1199         AppLogDebug("ENTER");
1200
1201         String filePath = __pPresentationModel->GetFilePathAt(index);
1202         ContentType contentType = ContentManagerUtil::CheckContentType(filePath);
1203
1204         if (__visible == true)
1205         {
1206                 if (contentType == CONTENT_TYPE_VIDEO)
1207                 {
1208                         __pPlayButton->SetShowState(false);
1209                 }
1210
1211                 SetActionBarsVisible( FORM_ACTION_BAR_FOOTER, false);
1212                 __pLabel->SetShowState(false);
1213                 __visible = false;
1214         }
1215         else
1216         {
1217                 if (contentType == CONTENT_TYPE_VIDEO)
1218                 {
1219                         __pPlayButton->SetShowState(true);
1220                 }
1221
1222                 SetActionBarsVisible(FORM_ACTION_BAR_FOOTER, true);
1223                 __pLabel->SetShowState(true);
1224                 __visible = true;
1225
1226                 __pPlayButton->SetPosition(__pPlayButton->GetPosition().x, __pPlayButton->GetPosition().y - 1);
1227                 __pPlayButton->SetPosition(__pPlayButton->GetPosition().x, __pPlayButton->GetPosition().y + 1);
1228         }
1229
1230         Rectangle clientRect = GetClientAreaBounds();
1231         Rectangle rect = GetBounds();
1232         __pGallery->SetBounds(Rectangle(0, clientRect.y, rect.width, rect.height));
1233         Invalidate(true);
1234         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1235 }
1236
1237 void
1238 ImageViewerForm::OnGallerySlideShowStarted(Gallery& gallery)
1239 {
1240         AppLogDebug("ENTER");
1241         PowerManager::KeepScreenOnState(true, false);
1242         if (__visible  == true)
1243         {
1244                 SetActionBarsVisible(FORM_ACTION_BAR_FOOTER, false);
1245                 __pLabel->SetShowState(false);
1246
1247                 int index = __pGallery->GetCurrentItemIndex();
1248                 String filePath = __pPresentationModel->GetFilePathAt(index);
1249                 ContentType contentType = ContentManagerUtil::CheckContentType(filePath);
1250
1251                 if (contentType == CONTENT_TYPE_VIDEO)
1252                 {
1253                         __pPlayButton->SetShowState(false);
1254                 }
1255
1256                 __visible = false;
1257         }
1258
1259         Rectangle clientRect = GetClientAreaBounds();
1260         Rectangle rect = GetBounds();
1261         __pGallery->SetBounds(Rectangle(0, -clientRect.y, rect.width, rect.height));
1262         Invalidate(true);
1263         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1264 }
1265
1266 void
1267 ImageViewerForm::OnGallerySlideShowStopped(Gallery& gallery)
1268 {
1269         AppLogDebug("ImageViewerForm::OnGallerySlideShowStopped");
1270
1271         int index;
1272
1273         if(__shuffle == true)
1274         {
1275
1276                 if(__pShuffelTimer == null)
1277                 {
1278                         __pShuffelTimer = new (std::nothrow) Timer();
1279                         __pShuffelTimer->Construct(*this);
1280                 }
1281                 __pShuffelTimer->Start(1);
1282         }
1283         else
1284         {
1285                 index = __pGallery->GetCurrentItemIndex();
1286                 SlideShowStopped(index);
1287         }
1288
1289
1290         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1291 }
1292
1293 void
1294 ImageViewerForm::SlideShowStopped(int index)
1295 {
1296         AppLog("ImageViewerForm::SlideShowStopped");
1297         PowerManager::KeepScreenOnState(false, true);
1298
1299         if (__visible == false)
1300         {
1301                 SetActionBarsVisible(FORM_ACTION_BAR_FOOTER, true);
1302                 __pLabel->SetShowState(true);
1303                 String filePath = __pPresentationModel->GetFilePathAt(index);
1304                 ContentType contentType = ContentManagerUtil::CheckContentType(filePath);
1305                 if (contentType == CONTENT_TYPE_VIDEO)
1306                 {
1307                         __pPlayButton->SetShowState(true);
1308                 }
1309
1310                 __pPlayButton->SetPosition(__pPlayButton->GetPosition().x, __pPlayButton->GetPosition().y - 1);
1311                 __pPlayButton->SetPosition(__pPlayButton->GetPosition().x, __pPlayButton->GetPosition().y + 1);
1312
1313                 __visible = true;
1314         }
1315
1316         String strItemIdxText;
1317         GetLabelText(index, strItemIdxText);
1318         __pLabel->SetText(strItemIdxText);
1319
1320
1321         Rectangle clientRect = GetClientAreaBounds();
1322         Rectangle rect = GetBounds();
1323         __pGallery->SetBounds(Rectangle(0, -clientRect.y, rect.width, rect.height));
1324
1325         Invalidate(true);
1326 }
1327
1328 void
1329 ImageViewerForm::OnUpdateContentList(void)
1330 {
1331 }
1332
1333 result
1334 ImageViewerForm::OnTerminating(void)
1335 {
1336         AppLogDebug("ENTER");
1337
1338         if (__pTimer != null)
1339         {
1340                 __pTimer->Cancel();
1341                 delete __pTimer;
1342                 __pTimer = null;
1343         }
1344
1345         if(__pShuffelTimer)
1346         {
1347                 __pShuffelTimer->Cancel();
1348                 delete __pShuffelTimer;
1349                 __pShuffelTimer = null;
1350         }
1351
1352         __pPresentationModel->ClearImageRequests();
1353         __pPresentationModel->RemoveListener(*this);
1354         __pPresentationModel->RemoveFileUpdateListener(*this);
1355
1356         if (__pContextMenuCopy != null)
1357         {
1358                 delete __pContextMenuCopy;
1359                 __pContextMenuCopy = null;
1360         }
1361
1362         if (__pContextMenuSetAs != null)
1363         {
1364                 delete __pContextMenuSetAs;
1365                 __pContextMenuSetAs = null;
1366         }
1367
1368         if (__pDeletePopup != null)
1369         {
1370                 delete __pDeletePopup;
1371                 __pDeletePopup = null;
1372         }
1373
1374         if (__pContextMenuShare != null)
1375         {
1376                 delete __pContextMenuShare;
1377                 __pContextMenuShare = null;
1378         }
1379
1380         if (__pContextMenuMore != null)
1381         {
1382                 delete __pContextMenuMore;
1383                 __pContextMenuMore = null;
1384         }
1385
1386         if(__pShuffledList != null)
1387         {
1388                 free(__pShuffledList);
1389                 __pShuffledList = null;
1390         }
1391
1392         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1393
1394         return E_SUCCESS;
1395 }
1396
1397 void
1398 ImageViewerForm::OnActionPerformed(const Control& source, int actionId)
1399 {
1400         AppLogDebug("ENTER actionId(%d)", actionId);
1401         SceneManager* pSceneManager = SceneManager::GetInstance();
1402         InitShowGallery();
1403
1404         switch (actionId)
1405         {
1406         case ACTION_ID_FOOTER_MORE:
1407         {
1408                 InitializeContextMenuMore();
1409
1410                 __pContextMenuMore->SetShowState(true);
1411                 __pContextMenuMore->Show();
1412         }
1413         break;
1414         case ACTION_ID_CONTEXTMENU_SET_AS:
1415                 InitializeContextMenuSetAs();
1416
1417                 __pContextMenuSetAs->SetShowState(true);
1418                 __pContextMenuSetAs->Show();
1419                 break;
1420         case ACTION_ID_FOOTER_BUTTON_SHARE:
1421                 InitializeContextMenuShare();
1422
1423                 __pContextMenuShare->SetShowState(true);
1424                 __pContextMenuShare->Show();
1425                 break;
1426         case ACTION_ID_FOOTER_BUTTON_DELETE:
1427                 __pDeletePopup->SetShowState(true);
1428                 __pDeletePopup->Show();
1429                 break;
1430         case ACTION_ID_FOOTER_BUTTON_SLIDE:
1431         {
1432                 if (__pPopUp != null)
1433                 {
1434                         __pPopUp->SetShowState(true);
1435                         __pPopUp->Show();
1436                 }
1437
1438                 break;
1439         }
1440         case ACTION_ID_FOOTER_BUTTON_CROP:
1441         {
1442                 String filePath;
1443                 filePath = __pPresentationModel->GetFilePathAt(__pGallery->GetCurrentItemIndex());
1444                 ImageBuffer imagebuffer;
1445                 result r = imagebuffer.Construct(filePath);
1446                 if (r != E_SUCCESS)
1447                 {
1448                         return;
1449                 }
1450                 int imageWidth = imagebuffer.GetWidth();
1451                 int imageHeight = imagebuffer.GetHeight();
1452                 if (imageWidth <= (CROP_RECTANGLE_HEIGHT * 3) || imageHeight <= (CROP_RECTANGLE_HEIGHT * 3))
1453                 {
1454                         MessageBox messageBox;
1455                         String messageText = ResourceManager::GetString(L"IDS_IMGE_POP_IMAGE_IS_TOO_SMALL");
1456                         messageBox.Construct(L"", messageText, MSGBOX_STYLE_OK, 3000);
1457                         int modalResult = 0;
1458                     messageBox.ShowAndWait(modalResult);
1459                     return;
1460                 }
1461                 String cropMode = L"auto";
1462                 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1463                 pList->Add(new (std::nothrow) String(filePath));
1464                 pList->Add(new (std::nothrow) String(cropMode));
1465                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_CROP), pList);
1466         }
1467         break;
1468         case ACTION_ID_FOOTER_BUTTON_ROTATE_RIGHT:
1469         {
1470                 int currentIndex = __pGallery->GetCurrentItemIndex();
1471                 String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
1472                 RotateMode rotateMode = ROTATE_MODE_RIGHT;
1473                 RotateImage(filePath, rotateMode);
1474                 __pPresentationModel->RequestImage(filePath);
1475                 ContentManager::ScanFile(filePath);
1476         }
1477         break;
1478         case ACTION_ID_FOOTER_BUTTON_ROTATE_LEFT:
1479         {
1480                 int currentIndex = __pGallery->GetCurrentItemIndex();
1481                 String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
1482                 RotateMode rotateMode = ROTATE_MODE_LEFT;
1483                 RotateImage(filePath, rotateMode);
1484                 __pPresentationModel->RequestImage(filePath);
1485                 ContentManager::ScanFile(filePath);
1486         }
1487         break;
1488         case ACTION_ID_FOOTER_BUTTON_DETAILS:
1489         {
1490                 ShowPanelDetail(__detail);
1491                 break;
1492         }
1493         case ACTION_ID_FOOTER_BUTTON_BACK:
1494                 ImageViewerForm::OnFormBackRequested(*this);
1495                 break;
1496         case ACTION_ID_FOOTER_BUTTON_DOWNLOAD:
1497                 DownloadFile();
1498                 break;
1499         case ACTION_ID_FOOTER_BUTTON_SAVE:
1500                 break;
1501         case ACTION_ID_PANEL_HEADER_DETAILS_RENAME:
1502         {
1503                 ArrayList* pSelectedIndex = new (std::nothrow) ArrayList(SingleObjectDeleter);
1504                 pSelectedIndex->Construct();
1505                 pSelectedIndex->Add(new (std::nothrow) Integer(__pGallery->GetCurrentItemIndex()));
1506                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_NAME_EDITOR), pSelectedIndex);
1507                 break;
1508         }
1509         case ACTION_ID_CONTEXTMENU_HOME:
1510         {
1511                 String filePath = __pPresentationModel->GetFilePathAt(__pGallery->GetCurrentItemIndex());
1512                 String cropMode = "fit-to-screen";
1513                 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1514                 pList->Add(new (std::nothrow) String(filePath));
1515                 pList->Add(new (std::nothrow) String(cropMode));
1516                 pList->Add(new (std::nothrow) Integer(SET_AT_TYPE_HOME_SCREEN_WALLPAPER));
1517                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_CROP), pList);
1518                 break;
1519         }
1520         case ACTION_ID_CONTEXTMENU_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_LOCK_SCREEN_WALLPAPER));
1528                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_CROP), pList);
1529                 break;
1530         }
1531         case ACTION_ID_CONTEXTMENU_CALLER:
1532         {
1533                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
1534                 pDataList->Construct();
1535                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_SELECTION_MODE),
1536                                 new (std::nothrow) String(APPCONTROL_DATA_SINGLE));
1537                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_SOCIAL_ITEM_TYPE),
1538                                 new (std::nothrow) String(APPCONTROL_DATA_PERSON));
1539                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_SOCIAL_RESULT_TYPE),
1540                                 new (std::nothrow) String(APPCONTROL_DATA_ITEM_ID));
1541
1542                 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_CONTACTS,
1543                                 APPCONTROL_OPERATION_ID_SOCIAL_PICK, null, null, pDataList, this);
1544                 break;
1545         }
1546
1547         case ACTION_ID_CONTEXTMENU_HOME_AND_LOCK:
1548         {
1549                 String filePath = __pPresentationModel->GetFilePathAt(__pGallery->GetCurrentItemIndex());
1550                 String cropMode = "fit-to-screen";
1551                 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1552                 pList->Add(new (std::nothrow) String(filePath));
1553                 pList->Add(new (std::nothrow) String(cropMode));
1554                 pList->Add(new (std::nothrow) Integer(SET_AT_TYPE_HOME_AND_LOCK_SCREEN_WALLPAPER));
1555                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_CROP), pList);
1556                 break;
1557         }
1558
1559         case ACTION_ID_CONTEXTMENU_EMAIL:
1560         {
1561                 OnRequestEmailAction();
1562                 break;
1563         }
1564         case ACTION_ID_CONTEXTMENU_MESSAGE:
1565         {
1566                 OnRequestMessagesAction();
1567                 break;
1568         }
1569         case ACTION_ID_CONTEXTMENU_COPY:
1570         {
1571                 int currentIndex = __pGallery->GetCurrentItemIndex();
1572                 String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
1573
1574                 ClipboardItem item;
1575                 item.Construct(CLIPBOARD_DATA_TYPE_IMAGE, filePath);
1576                 Clipboard* pClipboard = Clipboard::GetInstance();
1577                 pClipboard->CopyItem(item);
1578                 break;
1579         }
1580         case ACTION_ID_DELETE_POPUP_DEL:
1581         {
1582                 __pDeletePopup->SetShowState(false);
1583                 __pDeletePopup->Show();
1584                 DeleteImageFile();
1585
1586                 if (__detail == false)
1587                 {
1588                         ShowPanelDetail(false);
1589                 }
1590                 break;
1591         }
1592         case ACTION_ID_DELETE_POPUP_CANCEL:
1593         {
1594                 __pDeletePopup->SetShowState(false);
1595                 __pDeletePopup->Show();
1596                 break;
1597         }
1598         case ACTION_ID_CONTORL_BUTTON_PLAY:
1599                 CallVideoPlayer();
1600                 break;
1601         default:
1602                 break;
1603         }
1604         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1605 }
1606
1607 void
1608 ImageViewerForm::RotateImage(String& filePath, RotateMode rotateMode)
1609 {
1610         result r = E_SUCCESS;
1611         ImageBuffer rotateBuffer;
1612         ImageBuffer* pRotatedBuffer = null;
1613         ImageFormat imageFormat;
1614         Image img;
1615         r = img.Construct();
1616
1617         if (r == E_SUCCESS)
1618         {
1619                 imageFormat = img.GetImageFormat(filePath);
1620         }
1621
1622         r = rotateBuffer.Construct(filePath);
1623         if (r == E_SUCCESS)
1624         {
1625                 if (rotateMode == ROTATE_MODE_RIGHT)
1626                 {
1627                         pRotatedBuffer = rotateBuffer.RotateN(IMAGE_ROTATION_90);
1628                 }
1629                 else
1630                 {
1631                         pRotatedBuffer = rotateBuffer.RotateN(IMAGE_ROTATION_270);
1632                 }
1633         }
1634
1635         if (pRotatedBuffer != null)
1636         {
1637                 r = pRotatedBuffer->EncodeToFile(filePath, imageFormat, true, 100);
1638                 delete pRotatedBuffer;
1639         }
1640         return;
1641 }
1642
1643 void
1644 ImageViewerForm::OnFormBackRequested(Form& source)
1645 {
1646         AppLogDebug("ENTER");
1647         if (__detail == false)
1648         {
1649                 ShowPanelDetail(false);
1650         }
1651         else
1652         {
1653                 UiApp* pApp = UiApp::GetInstance();
1654                 pApp->Terminate();
1655         }
1656         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1657 }
1658
1659 void
1660 ImageViewerForm::OnSceneActivatedN(const SceneId& previousSceneId,
1661                 const SceneId& currentSceneId, IList* pArgs)
1662 {
1663         AppLogDebug("ENTER");
1664
1665         Rectangle clientRect = GetClientAreaBounds();
1666         Rectangle rect = GetBounds();
1667
1668         __pGallery->SetBounds(Rectangle(0, clientRect.y, rect.width, rect.height));
1669         __pScrollPanel->SetBounds(Rectangle(0, __pLabel->GetHeight(), clientRect.width, clientRect.height -  __pLabel->GetHeight()));
1670         __pPlayButton->SetBounds(Rectangle(clientRect.width / 2 - 80, clientRect.height / 2 - 80, 160, 160));
1671
1672         if (previousSceneId == IDSCN_IMAGE_NAME_EDITOR && currentSceneId == IDSCN_IMAGE_VIEWER)
1673         {
1674                 SetDetailInfo();
1675                 String strItemIdxText(EMPTY_SPACE);
1676                 GetLabelText(__pGallery->GetCurrentItemIndex(), strItemIdxText);
1677                 __pLabel->SetText(strItemIdxText);
1678                 Invalidate(true);
1679         }
1680
1681         if (previousSceneId == IDSCN_IMAGE_CROP && pArgs != null)
1682         {
1683                 String filePath;
1684                 filePath = *(static_cast<String*>(pArgs->GetAt(0)));
1685                 delete pArgs;
1686                 int count = __pPresentationModel->GetFileCount();
1687                 __pPresentationModel->AddImageCache(filePath);
1688                 __pGallery->UpdateGallery();
1689                 __pGallery->SetCurrentItemIndex(count);
1690                 __pPresentationModel->RequestImage(filePath);
1691         }
1692
1693         if (__pGallery->GetCurrentItemIndex() < 0)
1694         {
1695                 SetFooterItemState(false);
1696         }
1697         else
1698         {
1699                 SetFooterItemState(true);
1700         }
1701         Invalidate(true);
1702         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1703 }
1704
1705 void
1706 ImageViewerForm::OnSceneDeactivated(const SceneId& currentSceneId,
1707                 const SceneId& nextSceneId)
1708 {
1709         AppLogDebug("ENTER");
1710         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1711 }
1712
1713 void
1714 ImageViewerForm::OnImageDecodedN(const int index)
1715 {
1716         AppLogDebug("ENTER");
1717         __pGallery->RefreshGallery(index, GALLERY_REFRESH_TYPE_ITEM_MODIFY);
1718         __pGallery->Draw();
1719         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1720 }
1721
1722 void
1723 ImageViewerForm::OnAppControlCompleteResponseReceived(const AppId& appId,
1724                 const String& operationId, AppCtrlResult appControlResult,
1725                 const IMap* pExtraData)
1726 {
1727         AppLogDebug("ENTER");
1728
1729         if (appId == APPCONTROL_PROVIDER_ID_CONTACTS
1730                         && operationId == APPCONTROL_OPERATION_ID_SOCIAL_PICK
1731                         && appControlResult == APP_CTRL_RESULT_SUCCEEDED)
1732         {
1733                 const ArrayList* pResultList =
1734                                 static_cast<const ArrayList*>(pExtraData->GetValue(String(APPCONTROL_KEY_SOCIAL_ITEM_ID)));
1735                 const String* pContactId = null;
1736
1737                 if (pResultList != null)
1738                 {
1739                         pContactId = static_cast<const String*>(pResultList->GetAt(0));
1740                 }
1741
1742                 long long lresult = 0;
1743                 if (pContactId != null && pContactId->GetLength() > 0)
1744                 {
1745                         LongLong::Parse(*pContactId, lresult);
1746                         String filePath = __pPresentationModel->GetFilePathAt(__pGallery->GetCurrentItemIndex());
1747                         String cropMode = "fit-to-screen";
1748                         ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1749                         pList->Add(new (std::nothrow) String(filePath));
1750                         pList->Add(new (std::nothrow) String(cropMode));
1751                         pList->Add(new (std::nothrow) Integer(SET_AT_TYPE_CALLER_IMAGE));
1752                         pList->Add(new (std::nothrow) LongLong(lresult));
1753                         SceneManager* pSceneManager = SceneManager::GetInstance();
1754                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_CROP), pList);
1755                 }
1756         }
1757
1758         ImageViewerApp* pImageViewerApp = static_cast<ImageViewerApp*>(ImageViewerApp::GetInstance());
1759         pImageViewerApp->SetFrameEnabled(true);
1760         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1761 }
1762
1763 void
1764 ImageViewerForm::OnOverlayControlCreated(const Control& source)
1765 {
1766         AppLogDebug("ENTER");
1767         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1768 }
1769
1770 void
1771 ImageViewerForm::OnOverlayControlOpened(const Control& source)
1772 {
1773         AppLogDebug("ENTER");
1774         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1775 }
1776
1777 void
1778 ImageViewerForm::OnOverlayControlClosed(const Control& source)
1779 {
1780         AppLogDebug("ENTER");
1781         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1782 }
1783
1784 void
1785 ImageViewerForm::OnOtherControlSelected(const Control& source)
1786 {
1787         AppLogDebug("ENTER");
1788         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1789 }
1790
1791 void
1792 ImageViewerForm::InitShowGallery(void)
1793 {
1794         AppLogDebug("ENTER");
1795         if (__pGallery != null && __pGallery->IsVisible() == false)
1796         {
1797                 Canvas* pCanvas = GetCanvasN();
1798                 if (pCanvas == null || GetLastResult() != E_SUCCESS)
1799                 {
1800                         AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1801
1802                         return;
1803                 }
1804
1805                 pCanvas->Clear();
1806                 __pGallery->SetShowState(true);
1807                 delete pCanvas;
1808         }
1809         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1810 }
1811
1812 void
1813 ImageViewerForm::OnTimerExpired(Timer &timer)
1814 {
1815         AppLog("ImageViewerForm::OnTimerExpired");
1816
1817         if(timer.Equals(*__pShuffelTimer) == true)
1818         {
1819                 AppLog("OnTimerExpired __pShuffelTimer");
1820                 int curItemIndex = __pGallery->GetCurrentItemIndex();
1821                 int index = __pShuffledList[curItemIndex];
1822
1823                 __shuffle = false;
1824
1825                 __pGallery->UpdateGallery();
1826
1827                 AppLog("ImageViewerForm::OnGallerySlideShowStopped index = %d, shuffelIndex = %d", curItemIndex, index);
1828
1829                 __pGallery->SetCurrentItemIndex(index);
1830                 __pGallery->Draw();
1831
1832                 SlideShowStopped(index);
1833                 return;
1834         }
1835
1836         int repeatValue  = 0;
1837         int shuffleValue = 0;
1838
1839         if (__pPresentationModel->GetFileCount() > 1)
1840         {
1841                 __pSettingPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
1842                                                         ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
1843
1844                  __pSettingPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
1845                                                         ENTRY_NAME_IMAGE_VIEWER_SHUFFLE_VALUE, shuffleValue);
1846
1847                 if (shuffleValue != 0)
1848                 {
1849                         __shuffelStartIndex = __pGallery->GetCurrentItemIndex();
1850                         CreateShuffledList(__pPresentationModel->GetFileCount());
1851                         __shuffle = true;
1852                 }
1853                 else
1854                 {
1855                         __shuffelStartIndex = 0;
1856                         __shuffle = false;
1857                 }
1858
1859                 if ( repeatValue == 0)
1860                 {
1861                         __pGallery->StartSlideShow(false);
1862                 }
1863                 else
1864                 {
1865                         __pGallery->StartSlideShow(true);
1866                 }
1867         }
1868         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1869 }
1870
1871 void
1872 ImageViewerForm::CreateShuffledList(int count)
1873 {
1874         AppLogDebug("ImageViewerForm::CreateShuffledList ENTER");
1875         if(__pShuffledList == null)
1876         {
1877                 __pShuffledList = new (std::nothrow) int[count];
1878                 for(int i = 0; i < count; i++)
1879                 {
1880                         __pShuffledList[i] = i;
1881                 }
1882         }
1883         for(int i = count - 1; i > 1; i--)
1884         {
1885                 int randomNum = Math::Rand() % (i+1);
1886                 int t = __pShuffledList[randomNum];
1887                 __pShuffledList[randomNum] = __pShuffledList[i];
1888                 __pShuffledList[i] = t;
1889         }
1890
1891         for(int i = 0; i < count; i++)
1892         {
1893                 AppLogDebug("ShuffeldList i = %d & Val = %d", i, __pShuffledList[i]);
1894         }
1895
1896         AppLogDebug("ImageViewerForm::CreateShuffledList EXIT");
1897 }
1898
1899 void
1900 ImageViewerForm::OnContentTransferInProgress(RequestId requestId, int totalReceivedSize)
1901 {
1902         AppLogDebug("ENTER");
1903         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1904 }
1905
1906 void
1907 ImageViewerForm::OnContentUploadCompleted(RequestId requestId, result transferResult, const String& errorCode,
1908                 const String& errorMessage)
1909 {
1910         AppLogDebug("ENTER");
1911         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1912 }
1913
1914 void
1915 ImageViewerForm::OnContentDownloadCompleted(RequestId requestId, ContentId contentId,
1916                 result transferResult, const String& errorCode, const String& errorMessage)
1917 {
1918         AppLogDebug("ENTER");
1919         AppLogTag("IV", "ImageViewerForm::OnContentDownloadCompleted");
1920         AppLogTag("IV", "DownloadCompleted Error [%s]", GetErrorMessage(transferResult));
1921         AppLogTag("IV", "errorCode [%ls] errorMessage [%ls]", errorCode.GetPointer(), errorMessage.GetPointer());
1922         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1923 }
1924
1925 void
1926 ImageViewerForm::OnContentDownloadToBufferCompleted(RequestId reqId, ByteBuffer* pBuffer, result r,
1927                 const String& errorCode, const String& errorMessage)
1928 {
1929         AppLogDebug("ENTER");
1930         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1931 }
1932
1933 void
1934 ImageViewerForm::OnContentTransferCanceled(RequestId reqId, result res, const String& errorCode,
1935                 const String& errorMessage)
1936 {
1937         AppLogDebug("ENTER");
1938         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1939 }
1940
1941 void
1942 ImageViewerForm::RequestDecodeUrl(void)
1943 {
1944         AppLogDebug("ENTER");
1945
1946         String filePath = __pPresentationModel->GetFilePathAt(0);
1947
1948         if (filePath.StartsWith(WEB_URL_HTTP, 0) == false)
1949         {
1950                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1951
1952                 return;
1953         }
1954
1955         __downLordFileName = __pPresentationModel->GetFileName(filePath);
1956
1957         Image* pImage = new (std::nothrow) Image();
1958         pImage->Construct();
1959         Uri uri;
1960         RequestId reqId;
1961         uri.SetUri(filePath);
1962
1963         pImage->DecodeUrl(uri, BITMAP_PIXEL_FORMAT_RGB565, 720, 1280, reqId, *this, 5000);
1964
1965         delete pImage;
1966         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1967 }
1968
1969 void
1970 ImageViewerForm::OnImageDecodeUrlReceived (RequestId reqId, Bitmap *pBitmap,
1971                 result r, const String errorCode, const String errorMessage)
1972 {
1973         AppLogDebug("ENTER");
1974         Image* pImage = new (std::nothrow) Image();
1975         pImage->Construct();
1976
1977         String destPath = App::GetInstance()->GetAppRootPath() + TEMP_FILE_PATH_WEB_FILE;
1978         r = pImage->EncodeToFile(*pBitmap, IMG_FORMAT_JPG, destPath, true);
1979
1980         if (r == E_SUCCESS)
1981         {
1982                 __pPresentationModel->GetImageCacheAt(0)->SetFilePath(destPath);
1983                 __pPresentationModel->GetImageCacheAt(0)->SetBitmap(pBitmap);
1984
1985                 __pGallery->RefreshGallery(0, GALLERY_REFRESH_TYPE_ITEM_MODIFY);
1986                 __pGallery->Draw();
1987                 __pPresentationModel->RequestImage(destPath);
1988         }
1989         else
1990         {
1991                 AppLogDebug("ImageViewerForm::OnImageDecodeUrlReceived [%s]", GetErrorMessage(r));
1992         }
1993
1994         delete pImage;
1995         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1996 }
1997
1998 void
1999 ImageViewerForm::OnRequestEmailAction(void)
2000 {
2001         AppLogDebug("ENTER");
2002         int currentIndex = __pGallery->GetCurrentItemIndex();
2003
2004         if (__pPresentationModel->GetFileCount() <= 0)
2005         {
2006                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
2007                 return;
2008         }
2009
2010         String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
2011
2012         HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
2013         pDataList->Construct();
2014
2015         ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
2016         pList->Add(new (std::nothrow) String(filePath));
2017
2018         pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), pList);
2019
2020         __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_EMAIL, APPCONTROL_OPERATION_ID_COMPOSE,
2021                         new (std::nothrow) String(APPCONTROL_URI_MAIL_TO), null, pDataList, this);
2022         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
2023 }
2024
2025 void
2026 ImageViewerForm::OnRequestMessagesAction(void)
2027 {
2028         AppLogDebug("ENTER");
2029         int currentIndex = __pGallery->GetCurrentItemIndex();
2030
2031         if (__pPresentationModel->GetFileCount() <= 0)
2032         {
2033                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
2034                 return;
2035         }
2036
2037         String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
2038
2039         HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
2040         pDataList->Construct();
2041         ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
2042         pList->Add(new (std::nothrow) String(filePath));
2043         pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), pList);
2044         pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_MESSAGE_TYPE), new (std::nothrow) String(APPCONTROL_DATA_MMS));
2045
2046         __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_MESSAGES, APPCONTROL_OPERATION_ID_COMPOSE, null,
2047                         null, pDataList, this);
2048         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
2049 }
2050
2051 void
2052 ImageViewerForm::SetFooterItemState(bool isEnable)
2053 {
2054         AppLogDebug("ENTER");
2055         if (__initializeDisplayModeCurrent == APPCONTROL_MODE_NORMAL)
2056         {
2057                 __pFooter->SetButtonEnabled(BUTTON_POSITION_LEFT, isEnable);
2058                 __pFooter->SetItemEnabled(0, isEnable);
2059                 __pFooter->SetItemEnabled(1, isEnable);
2060         }
2061         else if (__initializeDisplayModeCurrent == APPCONTROL_MODE_WEB_LINK)
2062         {
2063                 __pFooter->SetButtonEnabled(BUTTON_POSITION_LEFT, isEnable);
2064                 __pFooter->SetItemEnabled(0, isEnable);
2065                 __pFooter->SetItemEnabled(1, isEnable);
2066         }
2067         else if (__initializeDisplayModeCurrent == APPCONTROL_MODE_CROP)
2068         {
2069                 __pFooter->SetItemEnabled(0, isEnable);
2070         }
2071         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
2072 }
2073
2074 Bitmap*
2075 ImageViewerForm::GetQuickThumbnailN(String& filePath)
2076 {
2077         AppLogDebug("ENTER");
2078         Bitmap* pBitmap = null;
2079
2080         if (filePath.GetLength() > 4)
2081         {
2082                 int totalPage = 0;
2083                 int totalCount = 0;
2084                 ContentSearch contentSearch;
2085                 ContentSearchResult* pResultItem = null;
2086                 IList* pContentInfoList = null;
2087                 String queryString;
2088                 ContentType contentType = ContentManagerUtil::CheckContentType(filePath);
2089                 result r = contentSearch.Construct(contentType);
2090                 AppLogDebug("r(%s)", GetErrorMessage(r));
2091                 if (r != E_SUCCESS)
2092                 {
2093                         pBitmap = new (std::nothrow) Bitmap();
2094                         r = pBitmap->Construct(DUMMY_IMAGE_DIMENSION, BITMAP_PIXEL_FORMAT_RGB565);
2095                         if (r == E_SUCCESS)
2096                         {
2097                                 return pBitmap;
2098                         }
2099                         else
2100                         {
2101                                 delete pBitmap;
2102                                 return null;
2103                         }
2104                 }
2105                 queryString = CONTENT_QUERY_PREFIX_FILENAME;
2106                 queryString.Append(L"'");
2107                 queryString.Append(__pPresentationModel->GetFileName(filePath));
2108                 queryString.Append(L"'");
2109
2110                 pContentInfoList = contentSearch.SearchN(PAGE_NO_CONTENT_SEARCH, COUNT_PER_PAGE_CONTENT_SEARCH,
2111                                 totalPage, totalCount, queryString, EMPTY_SPACE, SORT_ORDER_NONE);
2112
2113                 if ((pContentInfoList != null) && GetLastResult() == E_SUCCESS && (pContentInfoList->GetCount() > 0))
2114                 {
2115                         IEnumerator* pEnum = pContentInfoList->GetEnumeratorN();
2116                         while (pEnum->MoveNext() == E_SUCCESS)
2117                         {
2118                                 pResultItem = static_cast<ContentSearchResult*>(pEnum->GetCurrent());
2119                                 if (pResultItem == null)
2120                                 {
2121                                         continue;
2122                                 }
2123
2124                                 if (pResultItem->GetContentInfo()->GetContentPath().CompareTo(filePath) == 0)
2125                                 {
2126                                         pBitmap = pResultItem->GetContentInfo()->GetThumbnailN();
2127                                 }
2128                         }
2129                         delete pEnum;
2130                 }
2131
2132                 if (pContentInfoList != null)
2133                 {
2134                         delete pContentInfoList;
2135                 }
2136
2137                 if (pBitmap != null)
2138                 {
2139                         ImageViewerMediaType mediaType = CommonUtil::GetMediaType(filePath);
2140
2141                         if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE)
2142                         {
2143                                 ImageBuffer* imageBuffer = new (std::nothrow) ImageBuffer();
2144                                 result r = imageBuffer->Construct(filePath);
2145                                 if (r == E_SUCCESS)
2146                                 {
2147                                         if (imageBuffer->GetExifOrientation() == EXIF_ORIENTATION_RIGHT_TOP
2148                                                         || imageBuffer->GetExifOrientation() == EXIF_ORIENTATION_LEFT_BOTTOM)
2149                                         {
2150                                                 Dimension srcDim(imageBuffer->GetHeight(), imageBuffer->GetWidth());
2151                                                 pBitmap->Scale(srcDim);
2152                                         }
2153                                         else
2154                                         {
2155                                                 Dimension srcDim(imageBuffer->GetWidth(), imageBuffer->GetHeight());
2156                                                 pBitmap->Scale(srcDim);
2157                                         }
2158
2159                                         delete imageBuffer;
2160                                 }
2161                         }
2162                         else if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_VIDEO)
2163                         {
2164                                 VideoMetadata* pVideoMeta = ContentManagerUtil::GetVideoMetaN(filePath);
2165
2166                                 if (pVideoMeta != null && GetLastResult() == E_SUCCESS)
2167                                 {
2168                                         Dimension srcDim(pVideoMeta->GetWidth(), pVideoMeta->GetHeight());
2169                                         pBitmap->Scale(srcDim);
2170                                         delete pVideoMeta;
2171                                 }
2172                         }
2173                 }
2174                 else
2175                 {
2176                         Canvas mainCanvas;
2177                         mainCanvas.Construct(DUMMY_IMAGE_RECTANGLE);
2178                         mainCanvas.FillRectangle(Color::GetColor(COLOR_ID_BLACK), DUMMY_IMAGE_RECTANGLE);
2179                         pBitmap = new (std::nothrow) Bitmap();
2180                         pBitmap->Construct(mainCanvas, DUMMY_IMAGE_RECTANGLE);
2181                 }
2182         }
2183         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
2184         return pBitmap;
2185 }
2186
2187 void ImageViewerForm::OnFormFileEventOccuered(const int index, const unsigned long eventId)
2188 {
2189         AppLogDebug(" ENTER");
2190
2191         int currentIndex = __pGallery->GetCurrentItemIndex();
2192         int fileCount = __pPresentationModel->GetFileCount();
2193
2194         if (fileCount == 0 && eventId == IV_FILE_DELETE)
2195         {
2196                 UiApp* pApp = UiApp::GetInstance();
2197                 pApp->Terminate();
2198                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
2199         }
2200
2201         if (fileCount <= currentIndex && eventId == IV_FILE_DELETE)
2202         {
2203                 currentIndex = fileCount - 1;
2204         }
2205         else if (eventId == IV_FILE_CREATE)
2206         {
2207                 currentIndex = index;
2208         }
2209
2210
2211         String strItemIdxText(EMPTY_SPACE);
2212         __pGallery->SetCurrentItemIndex(currentIndex);
2213         __pGallery->UpdateGallery();
2214         String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
2215         __pPresentationModel->RequestImage(filePath);
2216
2217         GetLabelText(currentIndex,strItemIdxText);
2218         __pLabel->SetText(strItemIdxText);
2219
2220         if (__visible == true)
2221         {
2222                 ImageViewerMediaType mediaType = CommonUtil::GetMediaType(filePath);
2223
2224                 if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE)
2225                 {
2226                         __pPlayButton->SetShowState(false);
2227                 }
2228                 else
2229                 {
2230                         __pPlayButton->SetShowState(true);
2231                 }
2232         }
2233         if (__detail == false)
2234         {
2235                 __pScrollPanel->SetShowState(false);
2236                 __detail = true;
2237         }
2238
2239         Invalidate(true);
2240         AppLogDebug("EXIT");
2241 }
2242
2243 void
2244 ImageViewerForm::OnSlideSettingPopUpItemSelected(int index)
2245 {
2246         if ( __pPopUp != NULL)
2247         {
2248                 __pPopUp->SetShowState(false);
2249         }
2250
2251         if (index == 0)   // start slide show
2252         {
2253         int repeatValue = 0;
2254                 int interval = 0 ;
2255                 int transitioneffect = 0;
2256
2257                 if (__pPresentationModel->GetFileCount() > 1)
2258                 {
2259                         int shuffleValue;
2260                         __pSettingPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
2261                                                                         ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, interval);
2262
2263                                 interval = interval * 1000;
2264                         AppLogDebug("The slide interval is %d", interval);
2265                                 __pGallery->SetSlideShowViewDuration(interval);
2266
2267
2268                         __pGallery->UpdateGallery();
2269
2270                         if (__detail == false)
2271                         {
2272                                 ShowPanelDetail(false);
2273                         }
2274
2275                         __pSettingPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
2276                                         ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
2277
2278                         __pSettingPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
2279                                         ENTRY_NAME_IMAGE_VIEWER_SHUFFLE_VALUE, shuffleValue);
2280
2281                          __pSettingPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
2282                                     ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, transitioneffect);
2283
2284                          if (transitioneffect == 1)
2285                          {
2286                                  __pGallery->SetSlideShowAnimation(GALLERY_ANIMATION_DISSOLVE);
2287                          }
2288                          else if (transitioneffect == 2)
2289                          {
2290                                  __pGallery->SetSlideShowAnimation(GALLERY_ANIMATION_ZOOM);
2291                          }
2292                          else
2293                          {
2294                                  __pGallery->SetSlideShowAnimation(GALLERY_ANIMATION_PAGE);
2295                          }
2296
2297                         if (shuffleValue != 0)
2298                         {
2299                                 __shuffelStartIndex = __pGallery->GetCurrentItemIndex();
2300                                 CreateShuffledList(__pPresentationModel->GetFileCount());
2301                                 __shuffle = true;
2302                         }
2303                         else
2304                         {
2305                                 __shuffelStartIndex = 0;
2306                                 __shuffle = false;
2307                         }
2308
2309                         if (repeatValue == 0)
2310                         {
2311                                 __pGallery->StartSlideShow(false);
2312                         }
2313                         else
2314                         {
2315                                 __pGallery->StartSlideShow(true);
2316                         }
2317                 }
2318         }
2319         else if (index == 1) // launch settings
2320         {
2321                 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_GALLERY,
2322                                 APPCONTROL_OPERATION_ID_CONFIGURE, null, null, null, this);
2323         }
2324 }