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