Modify share via message
[apps/osp/ImageViewer.git] / src / IvImageViewerForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file                IvImageViewerForm.cpp
19  * @brief               This is the implementation file for ImageViewerForm class.
20  */
21
22 #include <FApp.h>
23 #include "IvCommonUtil.h"
24 #include "IvImageInfo.h"
25 #include "IvImageViewerApp.h"
26 #include "IvImageViewerForm.h"
27 #include "IvImageViewerPresentationModel.h"
28 #include "IvResourceManager.h"
29 #include "IvSettingPresentationModel.h"
30 #include "IvTypes.h"
31
32 using namespace Tizen::App;
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35 using namespace Tizen::Base::Runtime;
36 using namespace Tizen::Base::Utility;
37 using namespace Tizen::Content;
38 using namespace Tizen::Graphics;
39 using namespace Tizen::Io;
40 using namespace Tizen::Media;
41 using namespace Tizen::System;
42 using namespace Tizen::Ui;
43 using namespace Tizen::Ui::Controls;
44 using namespace Tizen::Ui::Scenes;
45
46 static const unsigned int COLOR_HEADER_CONTORL_PANEL = Color32<0, 0, 0, 100>::Value;
47 static const unsigned int COLOR_HEADER_BUTTON1 = Color32<0, 0, 0, 100>::Value;
48 static const unsigned int COLOR_DELETE_BUTTON_NORMAL = Color32<208, 82, 82>::Value;
49 static const unsigned int COLOR_DELETE_BUTTON_PRESSED = Color32<194, 71, 71>::Value;
50 static const unsigned int COLOR_DELETE_BUTTON_TEXT = Color32<248, 246, 239>::Value;
51
52 static const Rectangle RECT_CONTORL_BUTTON_PLAY (280, 400, 160, 160);
53 static const Rectangle RECT_LANDSCAP_CONTORL_BUTTON_PLAY (560, 216, 160, 160);
54
55 static const Rectangle RECT_DETAILS_CONTORL_PANEL (0, 0, 720, 1008);
56 static const Rectangle RECT_LANDSCAPE_DETAILS_CONTORL_PANEL (0, 0, 1280, 484);
57 static const Rectangle RECT_DETAILS_CONTORL_LABEL (20, 0, 200, 48);
58
59 static const int GAP_LABEL_END = 60;
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 X_DETAIL_FILEINFO_LABEL = 20;
84 static const int W_DETAIL_FILEINFO_LABEL = 420;
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 = 8;
89 static const int W_DETAIL_FILEINFO_VALUE_LABEL = 650;
90 static const int H_DETAIL_FILEINFO_VALUE_LABEL = 56;
91
92 static const int X_MORE = 55;
93
94 static const int DETAIL_SUB_FONT_SIZE = 42;
95 static const int DETAIL_MAIN_FONT_SIZE = 48;
96 static const int DETAIL_COUNT_MAX = 9;
97
98 ImageViewerForm::ImageViewerForm(void)
99 : __initializeDisplayModeCurrent(APPCONTROL_MODE_NORMAL)
100 , __pHeader(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 , __pDecodeBitmap(null)
111 , __pContextMenuMore(null)
112 , __pContextMenuCopy(null)
113 , __pContextMenuSetAs(null)
114 , __pContextMenuShare(null)
115 , __pDeletePopup(null)
116 , __visible(true)
117 , __detail(true)
118 , __startSlide(false)
119 , __requestId(0)
120 , __pPresentationModel(null)
121 {
122         AppLogDebug("ENTER");
123
124         __pDetail_FileInfo_Value_Label[0] = null;
125         __pDetail_FileInfo_Value_Label[1] = null;
126         __pDetail_FileInfo_Value_Label[2] = null;
127         __pDetail_FileInfo_Value_Label[3] = null;
128         __pDetail_FileInfo_Value_Label[4] = null;
129         __pDetail_FileInfo_Value_Label[5] = null;
130         __pDetail_FileInfo_Value_Label[6] = null;
131         __pDetail_FileInfo_Value_Label[7] = null;
132         __pDetail_FileInfo_Value_Label[8] = null;
133         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
134 }
135
136 ImageViewerForm::~ImageViewerForm(void)
137 {
138         AppLogDebug("ENTER");
139         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
140 }
141
142 result
143 ImageViewerForm::Initialize()
144 {
145         AppLogDebug("ENTER");
146         __pPresentationModel = ImageViewerPresentationModel::GetInstance();
147
148         if (__pPresentationModel->GetFileCount() > 0)
149         {
150                 if (__pPresentationModel->GetType() == APPCONTROL_DATA_SLIDE_SHOW)
151                 {
152                         __startSlide = true;
153                 }
154         }
155
156         __pSettingPresentationModel = SettingPresentationModel::GetInstance();
157
158         int startIndex = __pPresentationModel->GetStartIndex();
159         String filePath = __pPresentationModel->GetFilePathAt(startIndex);
160
161         if (filePath.StartsWith(WEB_URL_HTTP, 0) == true)
162         {
163                 __initializeDisplayModeCurrent = APPCONTROL_MODE_WEB_LINK;
164         }
165         else if (__pPresentationModel->GetType() == APPCONTROL_DATA_MESSAGE)
166         {
167                 __initializeDisplayModeCurrent = APPCONTROL_MODE_MESSAGE;
168         }
169         else if (__pPresentationModel->GetType() == APPCONTROL_DATA_EMAIL)
170         {
171                 __initializeDisplayModeCurrent = APPCONTROL_MODE_EMAIL;
172         }
173         else
174         {
175                 __initializeDisplayModeCurrent = APPCONTROL_MODE_NORMAL;
176         }
177
178         result r = Form::Construct(IDL_FORM_IMAGE_VIEWER);
179
180         if (filePath == EMPTY_SPACE)
181         {
182                 MessageBox messageBox;
183                 messageBox.Construct(L"", ResourceManager::GetString(L"IDS_IV_POP_INVALID_IMAGE_FILE"), MSGBOX_STYLE_NONE,
184                                 3000);
185                 int modalResult = 0;
186                 messageBox.ShowAndWait(modalResult);
187
188                 UiApp* pApp = UiApp::GetInstance();
189                 pApp->Terminate();
190         }
191
192         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
193
194         return r;
195 }
196
197 result
198 ImageViewerForm::OnInitializing(void)
199 {
200         AppLogDebug("ENTER");
201         SetFormBackEventListener(this);
202         __pPresentationModel->AddListener(this);
203
204         CreateGallery();
205         InitializeDisplay(__initializeDisplayModeCurrent);
206         InitializePanelDetail();
207         InitializePopup();
208
209         if (    __initializeDisplayModeCurrent == APPCONTROL_MODE_NORMAL
210                         || __initializeDisplayModeCurrent == APPCONTROL_MODE_MESSAGE
211                         || __initializeDisplayModeCurrent == APPCONTROL_MODE_EMAIL)
212         {
213                 int index = __pPresentationModel->GetStartIndex();
214                 __pGallery->UpdateGallery();
215                 __pGallery->SetCurrentItemIndex(index);
216                 __pGallery->Draw();
217
218                 String filePath = __pPresentationModel->GetFilePathAt(index);
219                 __pPresentationModel->RequestImage(filePath);
220         }
221         else if (__initializeDisplayModeCurrent == APPCONTROL_MODE_WEB_LINK)
222         {
223                 RequestDecodeUrl();
224         }
225
226         if (__startSlide)
227         {
228                 __pTimer = new (std::nothrow) Timer();
229                 __pTimer->Construct(*this);
230                 __pTimer->Start(1);
231         }
232
233         result r = SetActionBarsTranslucent(FORM_ACTION_BAR_INDICATOR, true);
234         AddOrientationEventListener(*this);
235         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
236
237         return r;
238 }
239
240 result
241 ImageViewerForm::OnInitialized(void)
242 {
243         AppLogDebug("ENTER");
244         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
245
246         return E_SUCCESS;
247 }
248
249 void
250 ImageViewerForm::OnOrientationChanged(const Control &source, OrientationStatus orientationStatus)
251 {
252         AppLogDebug("ENTER");
253         if (__detail == false)
254         {
255                 ShowPanelDetail(true);
256         }
257         else
258         {
259                 ShowPanelDetail(false);
260         }
261
262         if (orientationStatus == ORIENTATION_STATUS_PORTRAIT ||
263                         orientationStatus == ORIENTATION_STATUS_PORTRAIT_REVERSE)
264         {
265                 Rectangle clientRect = GetClientAreaBounds();
266                 Rectangle rect = GetBounds();
267
268                 __pGallery->SetBounds(Rectangle(0, -clientRect.y, rect.width, rect.height));
269                 __pPlayButton->SetBounds(Rectangle(RECT_CONTORL_BUTTON_PLAY.x, RECT_CONTORL_BUTTON_PLAY.y,
270                                 RECT_CONTORL_BUTTON_PLAY.width, RECT_CONTORL_BUTTON_PLAY.height));
271
272                 Invalidate(true);
273         }
274         else if (orientationStatus == ORIENTATION_STATUS_LANDSCAPE ||
275                         orientationStatus == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
276         {
277                 Rectangle clientRect = GetClientAreaBounds();
278                 Rectangle rect = GetBounds();
279
280                 __pGallery->SetBounds(Rectangle(0, -clientRect.y, rect.width, rect.height));
281                 __pPlayButton->SetBounds(Rectangle(RECT_LANDSCAP_CONTORL_BUTTON_PLAY.x, RECT_LANDSCAP_CONTORL_BUTTON_PLAY.y,
282                                 RECT_LANDSCAP_CONTORL_BUTTON_PLAY.width, RECT_LANDSCAP_CONTORL_BUTTON_PLAY.height));
283
284                 Invalidate(true);
285         }
286         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
287 }
288
289 void
290 ImageViewerForm::InitializeDisplay(AppControlMode status)
291 {
292         AppLogDebug("ENTER");
293         String strItemText;
294         String strItemIdxText;
295
296         __pHeader = GetHeader();
297         __pHeader->AddActionEventListener(*this);
298
299         __pFooter = GetFooter();
300         __pFooter->AddActionEventListener(*this);
301         __pFooter->RemoveAllItems();
302
303         GetHeaderString(0, strItemText, strItemIdxText);
304         Rectangle rect = GetClientAreaBounds();
305         __pHeader->SetTitleText(strItemText);
306         __pHeader->SetDescriptionText(strItemIdxText);
307
308         if (status == APPCONTROL_MODE_NORMAL)
309         {
310                 __pPlayButton = new (std::nothrow) Button();
311                 if (__pPlayButton != null)
312                 {
313                         __pPlayButton->Construct(RECT_CONTORL_BUTTON_PLAY);
314                         __pPlayButton->SetActionId(ACTION_ID_CONTORL_BUTTON_PLAY);
315                         AddControl(*__pPlayButton);
316
317                         Bitmap* pNormalBackgroundBitmap = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_PLAY);
318                         __pPlayButton->SetNormalBackgroundBitmap(*pNormalBackgroundBitmap);
319                         delete pNormalBackgroundBitmap;
320
321                         Bitmap* pPressedBackgroundBitmap = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_PLAY);
322                         __pPlayButton->SetPressedBackgroundBitmap(*pPressedBackgroundBitmap);
323                         delete pPressedBackgroundBitmap;
324
325                         __pPlayButton->AddActionEventListener(*this);
326                         __pPlayButton->SetShowState(false);
327                 }
328
329                 __pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON_TEXT);
330                 __pFooter->RemoveButtonAt(BUTTON_POSITION_LEFT);
331                 __pFooter->SetBackButton();
332
333                 FooterItem  footerItem1;
334                 footerItem1.Construct(ACTION_ID_FOOTER_BUTTON_SHARE);
335                 Bitmap* pFooterItemShareNomal =
336                                 ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_FOOTER_ICON_SHARE_NORMAL);
337                 footerItem1.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pFooterItemShareNomal);
338
339                 FooterItem  footerItem2;
340                 footerItem2.Construct(ACTION_ID_FOOTER_BUTTON_DELETE);
341                 Bitmap* pFooterItemDeleteNomal =
342                                 ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_FOOTER_ICON_DELETE_NORMAL);
343                 footerItem2.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pFooterItemDeleteNomal);
344
345                 __pFooter->AddItem(footerItem1);
346                 __pFooter->AddItem(footerItem2);
347
348                 delete pFooterItemShareNomal;
349                 delete pFooterItemDeleteNomal;
350
351                 ButtonItem buttonItemMore;
352                 buttonItemMore.Construct(BUTTON_ITEM_STYLE_ICON, ACTION_ID_FOOTER_MORE);
353                 buttonItemMore.SetBackgroundBitmap(BUTTON_ITEM_STATUS_NORMAL,
354                                 ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_MORE_NORMAL));
355                 buttonItemMore.SetBackgroundBitmap(BUTTON_ITEM_STATUS_PRESSED,
356                                 ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_MORE_PRESSED));
357                 __pFooter->SetButton(BUTTON_POSITION_LEFT, buttonItemMore);
358         }
359         else if (status == APPCONTROL_MODE_WEB_LINK)
360         {
361                 __pFooter->RemoveButtonAt(BUTTON_POSITION_LEFT);
362                 __pFooter->SetBackButton();
363
364                 FooterItem  footerItem1;
365                 footerItem1.Construct(ACTION_ID_FOOTER_BUTTON_SHARE);
366                 Bitmap* pFooterItemShareNomal =
367                                 ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_FOOTER_ICON_SHARE_NORMAL);
368                 footerItem1.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pFooterItemShareNomal);
369
370                 FooterItem  footerItem2;
371                 footerItem2.Construct(ACTION_ID_FOOTER_BUTTON_DOWNLOAD);
372                 Bitmap* pFooterItemDownlordNomal = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_DOWNLOAD);
373                 footerItem2.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pFooterItemDownlordNomal);
374
375                 __pFooter->AddItem(footerItem1);
376                 __pFooter->AddItem(footerItem2);
377
378                 delete pFooterItemShareNomal;
379                 delete pFooterItemDownlordNomal;
380
381                 ButtonItem buttonItemMore;
382                 buttonItemMore.Construct(BUTTON_ITEM_STYLE_ICON, ACTION_ID_FOOTER_MORE);
383                 buttonItemMore.SetBackgroundBitmap(BUTTON_ITEM_STATUS_NORMAL,
384                                 ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_MORE_NORMAL));
385                 buttonItemMore.SetBackgroundBitmap(BUTTON_ITEM_STATUS_PRESSED,
386                                 ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_MORE_PRESSED));
387                 __pFooter->SetButton(BUTTON_POSITION_LEFT, buttonItemMore);
388
389                 __pFooter->AddItem(footerItem1);
390                 __pFooter->AddItem(footerItem2);
391         }
392         else if (status == APPCONTROL_MODE_CROP)
393         {
394                 FooterItem  footerItem1;
395                 footerItem1.Construct(ACTION_ID_FOOTER_BUTTON_SAVE);
396                 Bitmap* pfooterItem1 = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_SAVE);
397                 footerItem1.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pfooterItem1);
398
399                 FooterItem  footerItem2;
400                 footerItem2.Construct(ACTION_ID_FOOTER_BUTTON_BACK);
401                 Bitmap* pfooterItem2 = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_X);
402                 footerItem2.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pfooterItem2);
403
404                 __pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON);
405                 __pFooter->AddItem(footerItem1);
406                 __pFooter->AddItem(footerItem2);
407
408                 delete pfooterItem1;
409                 delete pfooterItem2;
410         }
411         else if (status == APPCONTROL_MODE_MESSAGE || status == APPCONTROL_MODE_EMAIL)
412         {
413                 __pPlayButton = new (std::nothrow) Button();
414                 if (__pPlayButton != null)
415                 {
416                         __pPlayButton->Construct(RECT_CONTORL_BUTTON_PLAY);
417                         __pPlayButton->SetActionId(ACTION_ID_CONTORL_BUTTON_PLAY);
418                         AddControl(*__pPlayButton);
419
420                         Bitmap* pNormalBackgroundBitmap = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_PLAY);
421                         __pPlayButton->SetNormalBackgroundBitmap(*pNormalBackgroundBitmap);
422                         delete pNormalBackgroundBitmap;
423
424                         Bitmap* pPressedBackgroundBitmap = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_PLAY);
425                         __pPlayButton->SetPressedBackgroundBitmap(*pPressedBackgroundBitmap);
426                         delete pPressedBackgroundBitmap;
427
428                         __pPlayButton->AddActionEventListener(*this);
429                         __pPlayButton->SetShowState(false);
430                 }
431
432                 __pFooter->SetBackButton();
433         }
434
435         String filePath = __pPresentationModel->GetFilePathAt(0);
436         ContentType contentType = ContentManagerUtil::CheckContentType(filePath);
437         if (contentType == CONTENT_TYPE_VIDEO)
438         {
439                 __pPlayButton->SetShowState(true);
440         }
441         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
442 }
443
444 void
445 ImageViewerForm::GetHeaderString(int index, String &fileName, String &page)
446 {
447         AppLogDebug("ENTER");
448         int allCount = __pPresentationModel->GetFileCount();
449         String pStr = __pPresentationModel->GetFilePathAt(index);
450         fileName = __pPresentationModel->GetFileName(pStr);
451         page.Format(FORMAT_BUFFER_SIZE, L"%d/%d", index + 1, allCount);
452         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
453 }
454
455 result
456 ImageViewerForm::DeleteImageFile()
457 {
458         AppLogDebug("ENTER");
459         int currentIndex = __pGallery->GetCurrentItemIndex();
460
461         String strItemText(EMPTY_SPACE);
462         String strItemIdxText(EMPTY_SPACE);
463         int countPath = __pPresentationModel->GetFileCount();
464         String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
465         result r = E_SUCCESS;
466         if (filePath.GetLength() == 0)
467         {
468                 UiApp* pApp = UiApp::GetInstance();
469                 pApp->Terminate();
470                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
471
472                 return E_FAILURE;
473         }
474
475         if (filePath.StartsWith(Environment::GetMediaPath(), 0) == true
476                         || filePath.StartsWith(Environment::GetExternalStoragePath(), 0) == true)
477         {
478                 ContentId contentId = __pPresentationModel->GetFileContentId(filePath);
479                 ContentManager contentManager;
480                 contentManager.Construct();
481                 r = contentManager.DeleteContent(contentId);
482                 if (r != E_SUCCESS)
483                 {
484                         r = File::Remove(filePath);
485                         if (r != E_SUCCESS)
486                         {
487                                 MessageBox messageBox;
488                                 messageBox.Construct(L"", ResourceManager::GetString(L"IDS_COM_POP_DELETE_FAILED"),
489                                                 MSGBOX_STYLE_NONE, 3000);
490                                 int modalResult = 0;
491                                 messageBox.ShowAndWait(modalResult);
492                                 AppLogDebug("EXIT 4(%s)", GetErrorMessage(GetLastResult()));
493
494                                 return r;
495                         }
496                 }
497         }
498         else
499         {
500                 r = File::Remove(filePath);
501         }
502
503         __pPresentationModel->DeleteFilePathAt(currentIndex);
504         if (countPath == 1)
505         {
506                 UiApp* pApp = UiApp::GetInstance();
507                 pApp->Terminate();
508                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
509
510                 return r;
511         }
512         else if ((countPath - 1) == currentIndex)
513         {
514                 __pGallery->SetCurrentItemIndex(--currentIndex);
515         }
516
517         __pGallery->UpdateGallery();
518         filePath = __pPresentationModel->GetFilePathAt(currentIndex);
519         __pPresentationModel->RequestImage(filePath);
520
521         GetHeaderString(__pGallery->GetCurrentItemIndex(), strItemText, strItemIdxText);
522         __pHeader->SetTitleText(strItemText);
523         __pHeader->SetDescriptionText(strItemIdxText);
524
525         if (__visible == true)
526         {
527                 ImageViewerMediaType mediaType = CommonUtil::GetMediaType(filePath);
528
529                 if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE)
530                 {
531                         __pPlayButton->SetShowState(false);
532                 }
533                 else
534                 {
535                         __pPlayButton->SetShowState(true);
536                 }
537         }
538         Invalidate(true);
539         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
540
541         return r;
542 }
543
544 void
545 ImageViewerForm::CallVideoPlayer(void)
546 {
547         AppLogDebug("ENTER");
548         int index = __pGallery->GetCurrentItemIndex();
549         String filePath = __pPresentationModel->GetFilePathAt(index);
550
551         HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
552         pDataList->Construct();
553         pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_TYPE),
554                         new (std::nothrow) String(APPCONTROL_DATA_VIDEO));
555         pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), new (std::nothrow) String(filePath));
556
557         __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_VIDEO_PLAYER,
558                         APPCONTROL_OPERATION_ID_PLAY, pDataList, this);
559         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
560 }
561
562 void
563 ImageViewerForm::CreateGallery(void)
564 {
565         AppLogDebug("ENTER");
566         Rectangle clientRect = GetClientAreaBounds();
567         Rectangle rect = GetBounds();
568
569         __pGallery = new (std::nothrow) Gallery();
570         __pGallery->Construct(Rectangle(0, -clientRect.y, rect.width, rect.height));
571         __pGallery->SetName(L"GalleryControl");
572         __pGallery->SetItemProvider(*this);
573         __pGallery->AddGalleryEventListener(*this);
574         AddControl(*__pGallery);
575         __pGallery->SetTextOfEmptyGallery(ResourceManager::GetString(L"IDS_COM_BODY_LOADING"));
576
577         SlideShowTransitionEffect effect = __pPresentationModel->GetTransitionEffectOfSlideShow();
578
579         switch (effect)
580         {
581         case SLIDE_SHOW_TRANSITION_EFFECT_DISSOLVE:
582                 __pGallery->SetSlideShowAnimation(Controls::GALLERY_ANIMATION_DISSOLVE);
583                 break;
584         case SLIDE_SHOW_TRANSITION_EFFECT_ZOOM:
585                 __pGallery->SetSlideShowAnimation(Controls::GALLERY_ANIMATION_ZOOM);
586                 break;
587         case SLIDE_SHOW_TRANSITION_EFFECT_SLIDE:
588                 break;
589         }
590
591         __pGallery->SetSlideShowViewDuration(__pPresentationModel->GetDurationOfSlideShow());
592
593         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
594 }
595
596 result
597 ImageViewerForm::InitializePanelDetail()
598 {
599         AppLogDebug("ENTER");
600         __pScrollPanel = new (std::nothrow) ScrollPanel();
601
602         String arrayId[DETAIL_COUNT_MAX] =
603         {
604                         L"IDS_COM_BODY_DETAILS_NAME", L"IDS_IV_BODY_FILE_FORMAT", L"IDS_IV_BODY_DATE_CREATED",
605                         L"IDS_COM_BODY_SIZE", L"IDS_IV_BODY_RESOLUTION", L"IDS_COM_BODY_LOCATION",
606                         L"IDS_COM_BODY_LATITUDE", L"IDS_COM_BODY_LONGITUDE", L"IDS_IV_BODY_FILE_LOCATION"
607         };
608
609         if (__pScrollPanel == null)
610         {
611                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
612
613                 return E_INVALID_STATE;
614         }
615
616         result r = __pScrollPanel->Construct(RECT_DETAILS_CONTORL_PANEL);
617         if (r != E_SUCCESS)
618         {
619                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
620
621                 return E_INVALID_STATE;
622         }
623
624         __pDetail_Label = new (std::nothrow) Label();
625         __pDetail_Label->Construct(RECT_DETAILS_CONTORL_LABEL, ResourceManager::GetString(L"IDS_COM_BODY_DETAILS"));
626         __pScrollPanel->AddControl(*__pDetail_Label);
627         __pDetail_Label->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
628         __pDetail_Label->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
629         __pDetail_Label->SetTextColor(Color::GetColor(COLOR_ID_WHITE));
630         __pDetail_Label->SetTextConfig(DETAIL_MAIN_FONT_SIZE, LABEL_TEXT_STYLE_NORMAL);
631
632         for (int i = 0; i < DETAIL_COUNT_MAX; ++i)
633         {
634                 __pDetail_FileInfo_Label[i] = new (std::nothrow) Label();
635                 __pDetail_FileInfo_Label[i]->Construct(
636                                 Rectangle(X_DETAIL_FILEINFO_LABEL,
637                                                 GAP_H_DETAIL_TEXT * (i + 1) + H_DETAIL_MAIN_TEXT + (H_DETAIL_MAIN_TEXT + H_DETAIL_SUB_TEXT) * i,
638                                                 W_DETAIL_FILEINFO_LABEL, H_DETAIL_FILEINFO_LABEL), ResourceManager::GetString(arrayId[i]));
639                 __pScrollPanel->AddControl(*__pDetail_FileInfo_Label[i]);
640
641                 __pDetail_FileInfo_Label[i]->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
642                 __pDetail_FileInfo_Label[i]->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
643                 __pDetail_FileInfo_Label[i]->SetTextColor(Color::GetColor(COLOR_ID_GREY));
644                 __pDetail_FileInfo_Label[i]->SetTextConfig(DETAIL_SUB_FONT_SIZE, LABEL_TEXT_STYLE_NORMAL);
645
646                 __pDetail_FileInfo_Value_Label[i] = new (std::nothrow) Label();
647                 __pDetail_FileInfo_Value_Label[i]->Construct(
648                                 Rectangle(X_DETAIL_FILEINFO_LABEL,
649                                                 GAP_H_DETAIL_TEXT * (i + 1) + H_DETAIL_MAIN_TEXT + (H_DETAIL_MAIN_TEXT * i) + H_DETAIL_SUB_TEXT * (i + 1),
650                                                 W_DETAIL_FILEINFO_VALUE_LABEL, H_DETAIL_FILEINFO_VALUE_LABEL), L"");
651                 __pScrollPanel->AddControl(*__pDetail_FileInfo_Value_Label[i]);
652
653                 __pDetail_FileInfo_Value_Label[i]->SetTextVerticalAlignment(ALIGNMENT_BOTTOM);
654                 __pDetail_FileInfo_Value_Label[i]->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
655                 __pDetail_FileInfo_Value_Label[i]->SetTextColor(Color::GetColor(COLOR_ID_WHITE));
656                 __pDetail_FileInfo_Value_Label[i]->SetTextConfig(DETAIL_MAIN_FONT_SIZE, LABEL_TEXT_STYLE_NORMAL);
657         }
658
659         __pScrollPanel->SetBackgroundColor(COLOR_HEADER_CONTORL_PANEL);
660         __pScrollPanel->SetShowState(false);
661
662         AddControl(*__pScrollPanel);
663         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
664
665         return E_SUCCESS;
666 }
667
668 result
669 ImageViewerForm::InitializePopup(void)
670 {
671         AppLogDebug("ENTER");
672         if (__pDeletePopup == null)
673         {
674                 __pDeletePopup = new (std::nothrow) Popup();
675                 __pDeletePopup->Construct(false, Dimension(W_DELETE_POPUP, H_DELETE_POPUP));
676
677                 Rectangle popupClientBounds = __pDeletePopup->GetClientAreaBounds();
678
679                 Label* pLabel = new (std::nothrow) Label();
680                 pLabel->Construct(Rectangle(0, 0, popupClientBounds.width, H_DELETE_LABEL),
681                                 ResourceManager::GetString(L"IDS_COM_BODY_DELETE") + L"?");
682
683                 Button* pDeleteButton = new (std::nothrow) Button();
684                 pDeleteButton->Construct(
685                                 Rectangle(0, Y_DELETE_BUTTON, popupClientBounds.width / 2 - GAP_W_POPUP_ITEM, H_DELETE_BUTTON),
686                                 ResourceManager::GetString(L"IDS_COM_BODY_DELETE"));
687                 pDeleteButton->SetColor(BUTTON_STATUS_NORMAL, COLOR_DELETE_BUTTON_NORMAL);
688                 pDeleteButton->SetColor(BUTTON_STATUS_PRESSED, COLOR_DELETE_BUTTON_PRESSED);
689                 pDeleteButton->SetTextColor(COLOR_DELETE_BUTTON_TEXT);
690                 pDeleteButton->SetActionId(ACTION_ID_DELETE_POPUP_DEL);
691                 pDeleteButton->AddActionEventListener(*this);
692
693                 Button* pCancelButton = new (std::nothrow) Button();
694                 pCancelButton->Construct(
695                                 Rectangle(popupClientBounds.width / 2 + GAP_W_POPUP_ITEM,
696                                                 Y_DELETE_BUTTON, popupClientBounds.width / 2 - GAP_W_POPUP_ITEM, H_DELETE_BUTTON),
697                                                 ResourceManager::GetString(L"IDS_COM_SK_CANCEL"));
698                 pCancelButton->SetActionId(ACTION_ID_DELETE_POPUP_CANCEL);
699                 pCancelButton->AddActionEventListener(*this);
700
701                 __pDeletePopup->AddControl(*pLabel);
702                 __pDeletePopup->AddControl(*pDeleteButton);
703                 __pDeletePopup->AddControl(*pCancelButton);
704         }
705         else
706         {
707                 __pDeletePopup->SetShowState(true);
708                 __pDeletePopup->Show();
709         }
710         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
711
712         return E_SUCCESS;
713 }
714
715 result
716 ImageViewerForm::InitializeContextMenuMore(void)
717 {
718         AppLogDebug("ENTER");
719         int currentIndex = __pGallery->GetCurrentItemIndex();
720         String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
721
722         ImageViewerMediaType mediaType = CommonUtil::GetMediaType(filePath);
723
724         if (__pContextMenuMore != null)
725         {
726                 delete __pContextMenuMore;
727                 __pContextMenuMore = null;
728         }
729
730         __pContextMenuMore = new (std::nothrow) ContextMenu();
731
732         __pContextMenuMore->Construct(Point(X_MORE, GetClientAreaBounds().y + GetClientAreaBounds().height),
733                         CONTEXT_MENU_STYLE_LIST, CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD);
734
735         if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE)
736         {
737                 __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_IV_OPT_SET_AS"),
738                                 ACTION_ID_CONTEXTMENU_SET_AS);
739         }
740
741         if (__pGallery->GetItemCount() > 1)
742         {
743                 __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_IV_OPT_SLIDE_SHOW"),
744                                 ACTION_ID_FOOTER_BUTTON_SLIDE);
745         }
746         __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_DETAILS"),
747                         ACTION_ID_FOOTER_BUTTON_DETAILS);
748         __pContextMenuMore->SetShowState(false);
749         __pContextMenuMore->AddActionEventListener(*this);
750         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
751
752         return E_SUCCESS;
753 }
754
755 result
756 ImageViewerForm::InitializeContextMenuSetAs(void)
757 {
758         AppLogDebug("ENTER");
759
760         if (__pContextMenuSetAs != null)
761         {
762                 delete __pContextMenuSetAs;
763                 __pContextMenuSetAs = null;
764         }
765
766         __pContextMenuSetAs = new (std::nothrow) ContextMenu();
767         __pContextMenuSetAs->Construct(Point(X_MORE, GetClientAreaBounds().y + GetClientAreaBounds().height),
768                         CONTEXT_MENU_STYLE_LIST, CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD);
769
770         __pContextMenuSetAs->AddItem(ResourceManager::GetString(L"IDS_IV_HEADER_HOME_SCREEN_WALLPAPER_ABB"),
771                         ACTION_ID_CONTEXTMENU_HOME);
772         __pContextMenuSetAs->AddItem(ResourceManager::GetString(L"IDS_IV_HEADER_LOCK_SCREEN_WALLPAPER_ABB"),
773                         ACTION_ID_CONTEXTMENU_LOCK);
774         __pContextMenuSetAs->AddItem(ResourceManager::GetString(L"IDS_IV_BODY_CALLER_IMAGE"),
775                         ACTION_ID_CONTEXTMENU_CALLER);
776         __pContextMenuSetAs->AddActionEventListener(*this);
777         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
778
779         return E_SUCCESS;
780 }
781
782 result
783 ImageViewerForm::InitializeContextMenuShare(void)
784 {
785         AppLogDebug("ENTER");
786         if (__pContextMenuShare != null)
787         {
788                 delete __pContextMenuShare;
789                 __pContextMenuShare = null;
790         }
791         __pContextMenuShare = new (std::nothrow) ContextMenu();
792         __pContextMenuShare->Construct(Point((GetClientAreaBounds().width - (X_MORE * 4)) / 4 + X_MORE * 2,
793                         GetClientAreaBounds().y + GetClientAreaBounds().height), CONTEXT_MENU_STYLE_LIST,
794                         CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD);
795
796         __pContextMenuShare->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_MESSAGE"),
797                         ACTION_ID_CONTEXTMENU_MESSAGE);
798         __pContextMenuShare->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_EMAIL"), ACTION_ID_CONTEXTMENU_EMAIL);
799         __pContextMenuShare->AddActionEventListener(*this);
800         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
801
802         return E_SUCCESS;
803 }
804
805 long long
806 ImageViewerForm::GetFileSize(String filePath)
807 {
808         AppLogDebug("ENTER");
809         FileAttributes attr;
810         long long size = 0;
811
812         result r = File::GetAttributes(filePath, attr);
813         if (r != E_SUCCESS)
814         {
815                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
816
817                 return 0;
818         }
819         size = attr.GetFileSize();
820         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
821
822         return size;
823 }
824
825 result
826 ImageViewerForm::SetDetailInfo(void)
827 {
828         AppLogDebug("ENTER");
829
830         Rectangle clientRect = GetClientAreaBounds();
831         AppLogDebug("PORTRAIT GetClientAreaBounds(%d %d %d %d)", clientRect.x, clientRect.y, clientRect.width, clientRect.height);
832         OrientationStatus currentOrientaton = GetOrientationStatus();
833
834         if (currentOrientaton == ORIENTATION_STATUS_LANDSCAPE || currentOrientaton == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
835         {
836                 __pScrollPanel->SetBounds(Rectangle(0, 0, clientRect.width, RECT_LANDSCAPE_DETAILS_CONTORL_PANEL.height));
837         }
838         else
839         {
840                 __pScrollPanel->SetBounds(0, 0, clientRect.width, RECT_DETAILS_CONTORL_PANEL.height);
841         }
842
843         int currentIndex = __pGallery->GetCurrentItemIndex();
844         String strFilePath = __pPresentationModel->GetFilePathAt(currentIndex);
845
846         ImageViewerMediaType mediaType = CommonUtil::GetMediaType(strFilePath);
847
848         String strResult[DETAIL_COUNT_MAX] = {EMPTY_SPACE, };
849
850         strResult[0] = __pPresentationModel->GetFileName(strFilePath);
851         strResult[1] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
852
853         FileAttributes attr;
854         result r = File::GetAttributes(strFilePath, attr);
855         if (r == E_SUCCESS)
856         {
857                 long long nSize = attr.GetFileSize();
858                 DateTime dateTime = attr.GetDateTime();
859                 strResult[2] = dateTime.ToString();
860
861                 if (nSize > SINGLE_GIGA_BYTE)
862                 {
863                         strResult[3].Format(FORMAT_BUFFER_SIZE, L"%lld ", nSize / SINGLE_GIGA_BYTE);
864                         strResult[3].Append(ResourceManager::GetString(L"IDS_COM_BODY_GB"));
865                 }
866                 else if (nSize > SINGLE_MEGA_BYTE)
867                 {
868                         strResult[3].Format(FORMAT_BUFFER_SIZE, L"%lld ", nSize / SINGLE_MEGA_BYTE);
869                         strResult[3].Append(ResourceManager::GetString(L"IDS_COM_BODY_MB"));
870                 }
871                 else if (nSize > SINGLE_KILO_BYTE)
872                 {
873                         strResult[3].Format(FORMAT_BUFFER_SIZE, L"%lld ", nSize / SINGLE_KILO_BYTE);
874                         strResult[3].Append(ResourceManager::GetString(L"IDS_COM_BODY_KB"));
875                 }
876                 else
877                 {
878                         strResult[3].Format(FORMAT_BUFFER_SIZE, L"%lld ", nSize);
879                         strResult[3].Append(ResourceManager::GetString(L"IDS_COM_BODY_B"));
880                 }
881         }
882         else
883         {
884                 strResult[2] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
885                 strResult[3] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
886         }
887
888         strResult[4] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
889         strResult[5] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
890         strResult[6] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
891         strResult[7] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
892         strResult[8] = strFilePath;
893
894         if (__initializeDisplayModeCurrent == APPCONTROL_MODE_WEB_LINK)
895         {
896                 strResult[0] = __downLordFileName;
897         }
898         else if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE)
899         {
900                 ImageMetadata* pImgMeta = ContentManagerUtil::GetImageMetaN(strFilePath);
901
902                 if (pImgMeta != null)
903                 {
904                         ImageContentInfo imageContentInfo;
905                         r = imageContentInfo.Construct(&strFilePath);
906                         if (r == E_SUCCESS)
907                         {
908                                 strResult[1] = imageContentInfo.GetMediaFormat();
909                                 strResult[4].Format(FORMAT_BUFFER_SIZE, L"%d x %d", pImgMeta->GetWidth(),
910                                                 pImgMeta->GetHeight());
911
912                                 if (imageContentInfo.GetLocationTag() != EMPTY_SPACE)
913                                 {
914                                         strResult[5].Format(FORMAT_BUFFER_SIZE, L"%ls", imageContentInfo.GetLocationTag().GetPointer());
915                                 }
916
917                                 if (pImgMeta->GetLatitude() > 1.0 && pImgMeta->GetLongitude() > 1.0)
918                                 {
919                                         strResult[6].Format(FORMAT_BUFFER_SIZE, L"%f", pImgMeta->GetLatitude());
920                                         strResult[7].Format(FORMAT_BUFFER_SIZE, L"%f", pImgMeta->GetLongitude());
921                                 }
922
923                                 strResult[8] = imageContentInfo.GetContentPath();
924                         }
925                         delete pImgMeta;
926                 }
927         }
928         else if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_VIDEO)
929         {
930                 VideoMetadata* pVideoMeta = ContentManagerUtil::GetVideoMetaN(strFilePath);
931                 if (pVideoMeta != null)
932                 {
933                         VideoContentInfo videoContentInfo;
934                         r = videoContentInfo.Construct(&strFilePath);
935                         if (r == E_SUCCESS)
936                         {
937                                 strResult[1] = videoContentInfo.GetMediaFormat();
938                                 strResult[4].Format(FORMAT_BUFFER_SIZE, L"%d x %d", pVideoMeta->GetWidth(),
939                                                 pVideoMeta->GetHeight());
940                                 if (videoContentInfo.GetLocationTag() != EMPTY_SPACE)
941                                 {
942                                         strResult[5].Format(FORMAT_BUFFER_SIZE, L"%ls", videoContentInfo.GetLocationTag().GetPointer());
943                                 }
944
945                                 strResult[8] = videoContentInfo.GetContentPath();
946                         }
947                 }
948         }
949
950         for (int i = 0; i < DETAIL_COUNT_MAX; ++i)
951         {
952                 __pDetail_FileInfo_Value_Label[i]->SetBounds(X_DETAIL_FILEINFO_LABEL, GAP_H_DETAIL_TEXT * (i + 1) + H_DETAIL_MAIN_TEXT + (H_DETAIL_MAIN_TEXT * i) + H_DETAIL_SUB_TEXT * (i + 1),
953                                 clientRect.width - GAP_LABEL_END, H_DETAIL_FILEINFO_VALUE_LABEL);
954                 __pDetail_FileInfo_Value_Label[i]->SetText(strResult[i]);
955                 __pDetail_FileInfo_Value_Label[i]->RequestRedraw();
956         }
957
958         if (__initializeDisplayModeCurrent == APPCONTROL_MODE_WEB_LINK)
959         {
960                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
961                 return r;
962         }
963
964         if (__pRenameButton == null)
965         {
966                 __pRenameButton = new (std::nothrow) Button();
967                 Rectangle rect = GetBounds();
968                 __pRenameButton->Construct(Rectangle(rect.width - W_RENAME_BUTTON, Y_RENAME_BUTTON, W_RENAME_BUTTON, H_RENAME_BUTTON));
969                 __pRenameButton->SetActionId(ACTION_ID_PANEL_HEADER_DETAILS_RENAME);
970
971                 Bitmap* pIcon = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_EDIT_NAME);
972                 Bitmap* pIconBackground =
973                                 ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_EDIT_NAME_NORMAL_BACKGROUND);
974                 Bitmap* pIconPressed =
975                                 ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_EDIT_NAME_NORMAL_BACKGROUND_PRESS);
976
977                 if (pIcon != null && pIconPressed != null && pIconBackground != null)
978                 {
979                         __pRenameButton->SetNormalBackgroundBitmap(*pIconBackground);
980                         __pRenameButton->SetPressedBackgroundBitmap(*pIconPressed);
981                         Point iconPosition(0, 0);
982                         __pRenameButton->SetNormalBitmap(iconPosition, *pIcon);
983                         __pRenameButton->SetPressedBitmap(iconPosition, *pIconPressed);
984                 }
985                 else
986                 {
987                         __pRenameButton->SetColor(BUTTON_STATUS_NORMAL, COLOR_HEADER_BUTTON1);
988                         __pRenameButton->SetColor(BUTTON_STATUS_PRESSED, COLOR_HEADER_BUTTON1);
989                 }
990                 delete pIcon;
991                 delete pIconPressed;
992                 delete pIconBackground;
993
994                 __pScrollPanel->AddControl(*__pRenameButton);
995                 __pRenameButton->SetColor(BUTTON_STATUS_NORMAL, COLOR_HEADER_BUTTON1);
996                 __pRenameButton->AddActionEventListener(*this);
997         }
998         else
999         {
1000                 Rectangle rect = GetBounds();
1001                 __pRenameButton->SetBounds(Rectangle(rect.width - W_RENAME_BUTTON, Y_RENAME_BUTTON, W_RENAME_BUTTON, H_RENAME_BUTTON));
1002         }
1003         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1004
1005         return r;
1006 }
1007
1008 result
1009 ImageViewerForm::ShowPanelDetail(bool showStatus)
1010 {
1011         AppLogDebug("ENTER");
1012         if (showStatus)
1013         {
1014                 SetDetailInfo();
1015                 __pScrollPanel->SetShowState(true);
1016                 __detail = false;
1017         }
1018         else
1019         {
1020                 __pScrollPanel->SetShowState(false);
1021                 __detail = true;
1022         }
1023         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1024
1025         return E_SUCCESS;
1026 }
1027
1028 result
1029 ImageViewerForm::ChangeFooterItem(bool isChanged, Footer* pFooter, int position)
1030 {
1031         AppLogDebug("ENTER");
1032         FooterItem footerItem;
1033         footerItem.Construct(ACTION_ID_FOOTER_BUTTON_DETAILS);
1034         Bitmap* pfooterItem = null;
1035
1036         if (isChanged)
1037         {
1038                 pfooterItem = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_DETAILS_CLOSE);
1039                 footerItem.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pfooterItem);
1040         }
1041         else
1042         {
1043                 pfooterItem = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_DETAILS);
1044                 footerItem.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pfooterItem);
1045         }
1046
1047         pFooter->SetItemAt(position, footerItem);
1048         pFooter->Invalidate(true);
1049
1050         delete pfooterItem;
1051         pfooterItem = null;
1052         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1053
1054         return E_SUCCESS;
1055 }
1056
1057 void
1058 ImageViewerForm::DownloadFile(void)
1059 {
1060         AppLogDebug("ENTER");
1061         String DestPath = App::GetInstance()->GetAppRootPath() + TEMP_FILE_PATH_WEB_FILE;
1062         if (File::IsFileExist(DestPath) == false)
1063         {
1064                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1065                 return;
1066         }
1067
1068         ContentId contentId;
1069         ContentManager contentManager;
1070         contentManager.Construct();
1071
1072         ImageContentInfo imageContentInfo;
1073         imageContentInfo.Construct(null);
1074
1075         imageContentInfo.SetKeyword(L"platform, tizen");
1076         String sourcePath = DestPath;
1077         String destPath = Environment::GetMediaPath();
1078         destPath.Append(FOLDER_PATH_DOWNLOADS);
1079         destPath.Append(__downLordFileName);
1080
1081         contentId = contentManager.CreateContent(sourcePath, destPath, true, &imageContentInfo);
1082         ImageViewerForm::OnFormBackRequested(*this);
1083         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1084 }
1085
1086 int
1087 ImageViewerForm::GetItemCount(void)
1088 {
1089         AppLogDebug("ENTER");
1090         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1091
1092         return __pPresentationModel->GetFileCount();
1093 }
1094
1095 GalleryItem*
1096 ImageViewerForm::CreateItem(int index)
1097 {
1098         AppLogDebug("ENTER : index(%d)", index);
1099         GalleryItem* pGallery = new (std::nothrow) GalleryItem();
1100
1101         String filePath = __pPresentationModel->GetFilePathAt(index);
1102         ImageInfo* pImageInfo = __pPresentationModel->GetImageCacheAt(index);
1103         Bitmap* pBitmap = pImageInfo->GetBitmapN();
1104         if (pBitmap == null)
1105         {
1106                 pBitmap = GetQuickThumbnailN(filePath);
1107
1108                 if (pBitmap == null)
1109                 {
1110                         pBitmap = new (std::nothrow) Bitmap();
1111                         pBitmap->Construct(DUMMY_IMAGE_DIMENSION, BITMAP_PIXEL_FORMAT_RGB565);
1112                 }
1113         }
1114         pGallery->Construct(*pBitmap, filePath);
1115         delete pBitmap;
1116         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1117
1118         return pGallery;
1119 }
1120
1121 bool
1122 ImageViewerForm::DeleteItem(int index, GalleryItem* pItem)
1123 {
1124         AppLogDebug("ENTER index(%d)", index);
1125         ImageInfo* pImageInfo = __pPresentationModel->GetImageCacheAt(index);
1126         pImageInfo->ClearBitmap();
1127         delete pItem;
1128         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1129
1130         return true;
1131 }
1132
1133 void
1134 ImageViewerForm::OnGalleryCurrentItemChanged(Gallery& view, int index)
1135 {
1136         AppLogDebug("ENTER index(%d)", index);
1137
1138         String filePath = __pPresentationModel->GetFilePathAt(index);
1139         AppLogDebug("ENTER index(%d) filePath(%ls)", index, filePath.GetPointer());
1140         __pPresentationModel->RequestImage(filePath);
1141
1142         String strItemText;
1143         String strItemIdxText;
1144         GetHeaderString(__pGallery->GetCurrentItemIndex(), strItemText, strItemIdxText);
1145         __pHeader->SetTitleText(strItemText);
1146         __pHeader->SetDescriptionText(strItemIdxText);
1147
1148         if (__visible == true)
1149         {
1150                 ImageViewerMediaType mediaType = CommonUtil::GetMediaType(filePath);
1151                 if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_VIDEO)
1152                 {
1153                         __pPlayButton->SetShowState(true);
1154                 }
1155                 else
1156                 {
1157                         __pPlayButton->SetShowState(false);
1158                 }
1159         }
1160
1161         Invalidate(true);
1162         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1163 }
1164
1165 void
1166 ImageViewerForm::OnGalleryItemClicked(Gallery& view, int index)
1167 {
1168         AppLogDebug("ENTER");
1169
1170         String filePath = __pPresentationModel->GetFilePathAt(index);
1171         ContentType contentType = ContentManagerUtil::CheckContentType(filePath);
1172
1173         if (__visible == true)
1174         {
1175                 if (contentType == CONTENT_TYPE_VIDEO)
1176                 {
1177                         __pPlayButton->SetShowState(false);
1178                 }
1179
1180                 SetActionBarsVisible(FORM_ACTION_BAR_INDICATOR | FORM_ACTION_BAR_HEADER | FORM_ACTION_BAR_FOOTER, false);
1181                 __visible = false;
1182         }
1183         else
1184         {
1185                 if (contentType == CONTENT_TYPE_VIDEO)
1186                 {
1187                         __pPlayButton->SetShowState(true);
1188                 }
1189
1190                 SetActionBarsVisible(FORM_ACTION_BAR_INDICATOR | FORM_ACTION_BAR_HEADER | FORM_ACTION_BAR_FOOTER, true);
1191                 __visible = true;
1192
1193                 __pPlayButton->SetPosition(__pPlayButton->GetPosition().x, __pPlayButton->GetPosition().y - 1);
1194                 __pPlayButton->SetPosition(__pPlayButton->GetPosition().x, __pPlayButton->GetPosition().y + 1);
1195         }
1196
1197         Rectangle clientRect = GetClientAreaBounds();
1198         Rectangle rect = GetBounds();
1199         __pGallery->SetBounds(Rectangle(0, -clientRect.y, rect.width, rect.height));
1200         Invalidate(true);
1201         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1202 }
1203
1204 void
1205 ImageViewerForm::OnGallerySlideShowStarted(Gallery& gallery)
1206 {
1207         AppLogDebug("ENTER");
1208         PowerManager::KeepScreenOnState(true, false);
1209         if (__visible  == true)
1210         {
1211                 SetActionBarsVisible(FORM_ACTION_BAR_INDICATOR | FORM_ACTION_BAR_HEADER | FORM_ACTION_BAR_FOOTER, false);
1212
1213                 int index = __pGallery->GetCurrentItemIndex();
1214                 String filePath = __pPresentationModel->GetFilePathAt(index);
1215                 ContentType contentType = ContentManagerUtil::CheckContentType(filePath);
1216
1217                 if (contentType == CONTENT_TYPE_VIDEO)
1218                 {
1219                         __pPlayButton->SetShowState(false);
1220                 }
1221
1222                 __visible = false;
1223         }
1224
1225         Rectangle clientRect = GetClientAreaBounds();
1226         Rectangle rect = GetBounds();
1227         __pGallery->SetBounds(Rectangle(0, -clientRect.y, rect.width, rect.height));
1228         Invalidate(true);
1229         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1230 }
1231
1232 void
1233 ImageViewerForm::OnGallerySlideShowStopped(Gallery& gallery)
1234 {
1235         AppLogDebug("ENTER");
1236         PowerManager::KeepScreenOnState(false, true);
1237         int index = __pGallery->GetCurrentItemIndex();
1238
1239         if (__visible == false)
1240         {
1241                 SetActionBarsVisible(FORM_ACTION_BAR_INDICATOR | FORM_ACTION_BAR_HEADER | FORM_ACTION_BAR_FOOTER, true);
1242
1243                 String filePath = __pPresentationModel->GetFilePathAt(index);
1244                 ContentType contentType = ContentManagerUtil::CheckContentType(filePath);
1245                 if (contentType == CONTENT_TYPE_VIDEO)
1246                 {
1247                         __pPlayButton->SetShowState(true);
1248                 }
1249
1250                 __pPlayButton->SetPosition(__pPlayButton->GetPosition().x, __pPlayButton->GetPosition().y - 1);
1251                 __pPlayButton->SetPosition(__pPlayButton->GetPosition().x, __pPlayButton->GetPosition().y + 1);
1252
1253                 __visible = true;
1254         }
1255
1256         String strItemText;
1257         String strItemIdxText;
1258         GetHeaderString(index, strItemText, strItemIdxText);
1259         __pHeader->SetTitleText(strItemText);
1260         __pHeader->SetDescriptionText(strItemIdxText);
1261
1262         Rectangle clientRect = GetClientAreaBounds();
1263         Rectangle rect = GetBounds();
1264         __pGallery->SetBounds(Rectangle(0, -clientRect.y, rect.width, rect.height));
1265
1266         Invalidate(true);
1267         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1268 }
1269
1270 void
1271 ImageViewerForm::OnUpdateContentList(void)
1272 {
1273 }
1274
1275 result
1276 ImageViewerForm::OnTerminating(void)
1277 {
1278         AppLogDebug("ENTER");
1279
1280         if (__pTimer != null)
1281         {
1282                 __pTimer->Cancel();
1283                 delete __pTimer;
1284                 __pTimer = null;
1285         }
1286
1287         __pPresentationModel->ClearImageRequests();
1288         __pPresentationModel->RemoveListener(*this);
1289
1290         if (__pContextMenuCopy != null)
1291         {
1292                 delete __pContextMenuCopy;
1293                 __pContextMenuCopy = null;
1294         }
1295
1296         if (__pContextMenuSetAs != null)
1297         {
1298                 delete __pContextMenuSetAs;
1299                 __pContextMenuSetAs = null;
1300         }
1301
1302         if (__pDeletePopup != null)
1303         {
1304                 delete __pDeletePopup;
1305                 __pDeletePopup = null;
1306         }
1307
1308         if (__pContextMenuShare != null)
1309         {
1310                 delete __pContextMenuShare;
1311                 __pContextMenuShare = null;
1312         }
1313
1314         if (__pContextMenuMore != null)
1315         {
1316                 delete __pContextMenuMore;
1317                 __pContextMenuMore = null;
1318         }
1319
1320         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1321
1322         return E_SUCCESS;
1323 }
1324
1325 void
1326 ImageViewerForm::OnActionPerformed(const Control& source, int actionId)
1327 {
1328         AppLogDebug("ENTER actionId(%d)", actionId);
1329         SceneManager* pSceneManager = SceneManager::GetInstance();
1330         InitShowGallery();
1331
1332         switch (actionId)
1333         {
1334         case ACTION_ID_FOOTER_MORE:
1335         {
1336                 InitializeContextMenuMore();
1337
1338                 __pContextMenuMore->SetShowState(true);
1339                 __pContextMenuMore->Show();
1340         }
1341         break;
1342         case ACTION_ID_CONTEXTMENU_SET_AS:
1343                 InitializeContextMenuSetAs();
1344
1345                 __pContextMenuSetAs->SetShowState(true);
1346                 __pContextMenuSetAs->Show();
1347                 break;
1348         case ACTION_ID_FOOTER_BUTTON_SHARE:
1349                 InitializeContextMenuShare();
1350
1351                 __pContextMenuShare->SetShowState(true);
1352                 __pContextMenuShare->Show();
1353                 break;
1354         case ACTION_ID_FOOTER_BUTTON_DELETE:
1355                 __pDeletePopup->SetShowState(true);
1356                 __pDeletePopup->Show();
1357                 break;
1358         case ACTION_ID_FOOTER_BUTTON_SLIDE:
1359         {
1360                 int repeatValue = 0;
1361
1362                 if (__pPresentationModel->GetFileCount() > 1)
1363                 {
1364                         __pGallery->UpdateGallery();
1365                         if (__detail == false)
1366                         {
1367                                 ShowPanelDetail(false);
1368                         }
1369
1370                         __pSettingPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
1371                                         ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
1372
1373                         if( repeatValue == 0)
1374                         {
1375                                 __pGallery->StartSlideShow(false);
1376                         }
1377                         else
1378                         {
1379                                 __pGallery->StartSlideShow(true);
1380                         }
1381                 }
1382                 break;
1383         }
1384         case ACTION_ID_FOOTER_BUTTON_DETAILS:
1385         {
1386                 ShowPanelDetail(__detail);
1387                 break;
1388         }
1389         case ACTION_ID_FOOTER_BUTTON_BACK:
1390                 ImageViewerForm::OnFormBackRequested(*this);
1391                 break;
1392         case ACTION_ID_FOOTER_BUTTON_DOWNLOAD:
1393                 DownloadFile();
1394                 break;
1395         case ACTION_ID_FOOTER_BUTTON_SAVE:
1396                 break;
1397         case ACTION_ID_PANEL_HEADER_DETAILS_RENAME:
1398         {
1399                 ArrayList* pSelectedIndex = new (std::nothrow) ArrayList(SingleObjectDeleter);
1400                 pSelectedIndex->Construct();
1401                 pSelectedIndex->Add(new (std::nothrow) Integer(__pGallery->GetCurrentItemIndex()));
1402                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_NAME_EDITOR), pSelectedIndex);
1403                 break;
1404         }
1405         case ACTION_ID_CONTEXTMENU_HOME:
1406         {
1407                 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1408                 pList->Add(new (std::nothrow) Integer(__pGallery->GetCurrentItemIndex()));
1409                 pList->Add(new (std::nothrow) Integer(SET_AT_TYPE_HOME_SCREEN_WALLPAPER));
1410                 __pPresentationModel->SetSetterIndex(__pGallery->GetCurrentItemIndex());
1411                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_SETTER), pList);
1412                 break;
1413         }
1414         case ACTION_ID_CONTEXTMENU_LOCK:
1415         {
1416                 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1417                 pList->Add(new (std::nothrow) Integer(__pGallery->GetCurrentItemIndex()));
1418                 pList->Add(new (std::nothrow) Integer(SET_AT_TYPE_LOCK_SCREEN_WALLPAPER));
1419                 __pPresentationModel->SetSetterIndex(__pGallery->GetCurrentItemIndex());
1420                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_SETTER), pList);
1421                 break;
1422         }
1423         case ACTION_ID_CONTEXTMENU_CALLER:
1424         {
1425                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
1426                 pDataList->Construct();
1427                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_SELECTION_MODE),
1428                                 new (std::nothrow) String(APPCONTROL_DATA_SINGLE));
1429                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_RETURN_TYPE),
1430                                 new (std::nothrow) String(APPCONTROL_DATA_CONTACT_ID));
1431
1432                 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_CONTACTS,
1433                                 APPCONTROL_OPERATION_ID_PICK, pDataList, this);
1434                 break;
1435         }
1436         case ACTION_ID_CONTEXTMENU_EMAIL:
1437         {
1438                 OnRequestEmailAction();
1439                 break;
1440         }
1441         case ACTION_ID_CONTEXTMENU_MESSAGE:
1442         {
1443                 OnRequestMessagesAction();
1444                 break;
1445         }
1446         case ACTION_ID_CONTEXTMENU_COPY:
1447         {
1448                 int currentIndex = __pGallery->GetCurrentItemIndex();
1449                 String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
1450
1451                 ClipboardItem item;
1452                 item.Construct(CLIPBOARD_DATA_TYPE_IMAGE, filePath);
1453                 Clipboard* pClipboard = Clipboard::GetInstance();
1454                 pClipboard->CopyItem(item);
1455                 break;
1456         }
1457         case ACTION_ID_DELETE_POPUP_DEL:
1458         {
1459                 __pDeletePopup->SetShowState(false);
1460                 __pDeletePopup->Show();
1461                 DeleteImageFile();
1462
1463                 if (__detail == false)
1464                 {
1465                         ShowPanelDetail(false);
1466                 }
1467                 break;
1468         }
1469         case ACTION_ID_DELETE_POPUP_CANCEL:
1470         {
1471                 __pDeletePopup->SetShowState(false);
1472                 __pDeletePopup->Show();
1473                 break;
1474         }
1475         case ACTION_ID_CONTORL_BUTTON_PLAY:
1476                 CallVideoPlayer();
1477                 break;
1478         default:
1479                 break;
1480         }
1481         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1482 }
1483
1484 void
1485 ImageViewerForm::OnFormBackRequested(Form& source)
1486 {
1487         AppLogDebug("ENTER");
1488         if (__detail == false)
1489         {
1490                 ShowPanelDetail(false);
1491         }
1492         else
1493         {
1494                 UiApp* pApp = UiApp::GetInstance();
1495                 pApp->Terminate();
1496         }
1497         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1498 }
1499
1500 void
1501 ImageViewerForm::OnSceneActivatedN(const SceneId& previousSceneId,
1502                 const SceneId& currentSceneId, IList* pArgs)
1503 {
1504         AppLogDebug("ENTER");
1505         OrientationStatus status = GetOrientationStatus();
1506         if (status == ORIENTATION_STATUS_PORTRAIT ||
1507                         status == ORIENTATION_STATUS_PORTRAIT_REVERSE)
1508         {
1509                 AppLogDebug("ORIENTATION_STATUS : PORTRAIT");
1510                 Rectangle clientRect = GetClientAreaBounds();
1511                 Rectangle rect = GetBounds();
1512                 __pGallery->SetBounds(Rectangle(0, -clientRect.y, rect.width, rect.height));
1513                 __pPlayButton->SetBounds(RECT_CONTORL_BUTTON_PLAY);
1514                 __pScrollPanel->SetBounds(RECT_DETAILS_CONTORL_PANEL);
1515         }
1516         else if (status == ORIENTATION_STATUS_LANDSCAPE ||
1517                         status == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
1518         {
1519                 AppLogDebug("ORIENTATION_STATUS : LANDSCAPE");
1520                 Rectangle clientRect = GetClientAreaBounds();
1521                 Rectangle rect = GetBounds();
1522                 __pGallery->SetBounds(Rectangle(0, -clientRect.y, rect.width, rect.height));
1523                 __pPlayButton->SetBounds(RECT_LANDSCAP_CONTORL_BUTTON_PLAY);
1524                 __pScrollPanel->SetBounds(RECT_LANDSCAPE_DETAILS_CONTORL_PANEL);
1525         }
1526
1527         if (previousSceneId == IDSCN_IMAGE_NAME_EDITOR && currentSceneId == IDSCN_IMAGE_VIEWER)
1528         {
1529                 SetDetailInfo();
1530                 String strItemText(EMPTY_SPACE);
1531                 String strItemIdxText(EMPTY_SPACE);
1532                 GetHeaderString(__pGallery->GetCurrentItemIndex(), strItemText, strItemIdxText);
1533                 __pHeader->SetTitleText(strItemText);
1534                 __pHeader->SetDescriptionText(strItemIdxText);
1535                 Invalidate(true);
1536         }
1537
1538         if (__pGallery->GetCurrentItemIndex() < 0)
1539         {
1540                 SetFooterItemState(false);
1541         }
1542         else
1543         {
1544                 SetFooterItemState(true);
1545         }
1546         Invalidate(true);
1547         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1548 }
1549
1550 void
1551 ImageViewerForm::OnSceneDeactivated(const SceneId& currentSceneId,
1552                 const SceneId& nextSceneId)
1553 {
1554         AppLogDebug("ENTER");
1555         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1556 }
1557
1558 void
1559 ImageViewerForm::OnImageDecodedN(const int index)
1560 {
1561         AppLogDebug("ENTER");
1562         __pGallery->RefreshGallery(index, GALLERY_REFRESH_TYPE_ITEM_MODIFY);
1563         __pGallery->Draw();
1564         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1565 }
1566
1567 void
1568 ImageViewerForm::OnAppControlCompleteResponseReceived(const AppId& appId,
1569                 const String& operationId, AppCtrlResult appControlResult,
1570                 const IMap* pExtraData)
1571 {
1572         AppLogDebug("ENTER");
1573
1574         if (appId == APPCONTROL_PROVIDER_ID_CONTACTS
1575                         && operationId == APPCONTROL_OPERATION_ID_PICK
1576                         && appControlResult == APP_CTRL_RESULT_SUCCEEDED)
1577         {
1578                 const String* pReturnType =
1579                                 static_cast<const String*>(pExtraData->GetValue(String(APPCONTROL_KEY_RETURN_TYPE)));
1580                 if (pReturnType != null && pReturnType->CompareTo(APPCONTROL_DATA_CONTACT_ID) == 0)
1581                 {
1582                         const String* pContactId =
1583                                         static_cast<const String*>(pExtraData->GetValue(String(APPCONTROL_KEY_VALUE)));
1584                         SceneManager* pSceneManager = SceneManager::GetInstance();
1585                         long long lresult = 0;
1586                         if (pContactId != null && pContactId->GetLength() > 0)
1587                         {
1588                                 LongLong::Parse(*pContactId, lresult);
1589                         }
1590                         ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1591                         pList->Add(new (std::nothrow) Integer(__pGallery->GetCurrentItemIndex()));
1592                         pList->Add(new (std::nothrow) Integer(SET_AT_TYPE_CALLER_IMAGE));
1593                         pList->Add(new (std::nothrow) LongLong(lresult));
1594                         __pPresentationModel->SetSetterIndex(__pGallery->GetCurrentItemIndex());
1595                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_SETTER), pList);
1596                 }
1597         }
1598
1599         ImageViewerApp* pImageViewerApp = static_cast<ImageViewerApp*>(ImageViewerApp::GetInstance());
1600         pImageViewerApp->SetFrameEnabled(true);
1601         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1602 }
1603
1604 void
1605 ImageViewerForm::OnOverlayControlCreated(const Control& source)
1606 {
1607         AppLogDebug("ENTER");
1608         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1609 }
1610
1611 void
1612 ImageViewerForm::OnOverlayControlOpened(const Control& source)
1613 {
1614         AppLogDebug("ENTER");
1615         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1616 }
1617
1618 void
1619 ImageViewerForm::OnOverlayControlClosed(const Control& source)
1620 {
1621         AppLogDebug("ENTER");
1622         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1623 }
1624
1625 void
1626 ImageViewerForm::OnOtherControlSelected(const Control& source)
1627 {
1628         AppLogDebug("ENTER");
1629         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1630 }
1631
1632 void
1633 ImageViewerForm::InitShowGallery(void)
1634 {
1635         AppLogDebug("ENTER");
1636         if (__pGallery != null && __pGallery->IsVisible() == false)
1637         {
1638                 Canvas* pCanvas = GetCanvasN();
1639                 if (pCanvas == null || GetLastResult() != E_SUCCESS)
1640                 {
1641                         AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1642
1643                         return;
1644                 }
1645
1646                 pCanvas->Clear();
1647                 __pGallery->SetShowState(true);
1648                 delete pCanvas;
1649                 pCanvas = null;
1650         }
1651         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1652 }
1653
1654 void
1655 ImageViewerForm::OnTimerExpired(Timer &timer)
1656 {
1657         int repeatValue = 0;
1658         AppLogDebug("ENTER");
1659         if (__pPresentationModel->GetFileCount() > 1)
1660         {
1661                 __pSettingPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
1662                                                         ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
1663
1664                 if( repeatValue == 0)
1665                 {
1666                         __pGallery->StartSlideShow(false);
1667                 }
1668                 else
1669                 {
1670                         __pGallery->StartSlideShow(true);
1671                 }
1672         }
1673         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1674 }
1675
1676 void
1677 ImageViewerForm::OnContentTransferInProgress(RequestId requestId, int totalReceivedSize)
1678 {
1679         AppLogDebug("ENTER");
1680         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1681 }
1682
1683 void
1684 ImageViewerForm::OnContentUploadCompleted(RequestId requestId, result transferResult, const String& errorCode,
1685                 const String& errorMessage)
1686 {
1687         AppLogDebug("ENTER");
1688         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1689 }
1690
1691 void
1692 ImageViewerForm::OnContentDownloadCompleted(RequestId requestId, ContentId contentId,
1693                 result transferResult, const String& errorCode, const String& errorMessage)
1694 {
1695         AppLogDebug("ENTER");
1696         AppLogTag("IV", "ImageViewerForm::OnContentDownloadCompleted");
1697         AppLogTag("IV", "DownloadCompleted Error [%s]", GetErrorMessage(transferResult));
1698         AppLogTag("IV", "errorCode [%ls] errorMessage [%ls]", errorCode.GetPointer(), errorMessage.GetPointer());
1699         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1700 }
1701
1702 void
1703 ImageViewerForm::OnContentDownloadToBufferCompleted(RequestId reqId, ByteBuffer* pBuffer, result r,
1704                 const String& errorCode, const String& errorMessage)
1705 {
1706         AppLogDebug("ENTER");
1707         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1708 }
1709
1710 void
1711 ImageViewerForm::OnContentTransferCanceled(RequestId reqId, result res, const String& errorCode,
1712                 const String& errorMessage)
1713 {
1714         AppLogDebug("ENTER");
1715         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1716 }
1717
1718 void
1719 ImageViewerForm::RequestDecodeUrl(void)
1720 {
1721         AppLogDebug("ENTER");
1722
1723         String filePath = __pPresentationModel->GetFilePathAt(0);
1724
1725         if (filePath.StartsWith(WEB_URL_HTTP, 0) == false)
1726         {
1727                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1728
1729                 return;
1730         }
1731
1732         __downLordFileName = __pPresentationModel->GetFileName(filePath);
1733
1734         Image* pImage = new (std::nothrow) Image();
1735         pImage->Construct();
1736         Uri uri;
1737         RequestId reqId;
1738         uri.SetUri(filePath);
1739
1740         pImage->DecodeUrl(uri, BITMAP_PIXEL_FORMAT_RGB565, 720, 1280, reqId, *this, 5000);
1741
1742         delete pImage;
1743         pImage = null;
1744         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1745 }
1746
1747 void
1748 ImageViewerForm::OnImageDecodeUrlReceived (RequestId reqId, Bitmap *pBitmap,
1749                 result r, const String errorCode, const String errorMessage)
1750 {
1751         AppLogDebug("ENTER");
1752         Image* pImage = new (std::nothrow) Image();
1753         pImage->Construct();
1754
1755         String destPath = App::GetInstance()->GetAppRootPath() + TEMP_FILE_PATH_WEB_FILE;
1756         r = pImage->EncodeToFile(*pBitmap, IMG_FORMAT_JPG, destPath, true);
1757
1758         if (r == E_SUCCESS)
1759         {
1760                 __pPresentationModel->GetImageCacheAt(0)->SetFilePath(destPath);
1761                 __pPresentationModel->GetImageCacheAt(0)->SetBitmap(pBitmap);
1762
1763                 __pGallery->RefreshGallery(0, GALLERY_REFRESH_TYPE_ITEM_MODIFY);
1764                 __pGallery->Draw();
1765                 __pPresentationModel->RequestImage(destPath);
1766         }
1767         else
1768         {
1769                 AppLogDebug("ImageViewerForm::OnImageDecodeUrlReceived [%s]", GetErrorMessage(r));
1770         }
1771
1772         delete pImage;
1773         pImage = null;
1774         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1775 }
1776
1777 void
1778 ImageViewerForm::OnRequestEmailAction(void)
1779 {
1780         AppLogDebug("ENTER");
1781         int currentIndex = __pGallery->GetCurrentItemIndex();
1782
1783         if (__pPresentationModel->GetFileCount() <= 0)
1784         {
1785                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1786                 return;
1787         }
1788
1789         String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
1790
1791         ImageViewerMediaType mediaType = CommonUtil::GetMediaType(filePath);
1792
1793         if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE || mediaType == IMAGE_VIEWER_MEDIA_TYPE_VIDEO)
1794         {
1795                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
1796                 pDataList->Construct();
1797                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_ATTACHMENTS),
1798                                 new (std::nothrow) String(filePath));
1799
1800                 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_EMAIL,
1801                                 APPCONTROL_OPERATION_ID_COMPOSE, pDataList, this);
1802         }
1803         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1804 }
1805
1806 void
1807 ImageViewerForm::OnRequestMessagesAction(void)
1808 {
1809         AppLogDebug("ENTER");
1810         int currentIndex = __pGallery->GetCurrentItemIndex();
1811
1812         if (__pPresentationModel->GetFileCount() <= 0)
1813         {
1814                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1815                 return;
1816         }
1817
1818         String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
1819
1820         ImageViewerMediaType mediaType = CommonUtil::GetMediaType(filePath);
1821
1822         if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE || mediaType == IMAGE_VIEWER_MEDIA_TYPE_VIDEO)
1823         {
1824                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
1825                 pDataList->Construct();
1826                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_TYPE),
1827                                                 new (std::nothrow) String(filePath));
1828                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_ATTACHMENTS),
1829                                 new (std::nothrow) String(APPCONTROL_DATA_MMS));
1830
1831                 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_MESSAGES,
1832                                 APPCONTROL_OPERATION_ID_COMPOSE, pDataList, this);
1833         }
1834         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1835 }
1836
1837 void
1838 ImageViewerForm::SetFooterItemState(bool isEnable)
1839 {
1840         AppLogDebug("ENTER");
1841         if (__initializeDisplayModeCurrent == APPCONTROL_MODE_NORMAL)
1842         {
1843                 __pFooter->SetButtonEnabled(BUTTON_POSITION_LEFT, isEnable);
1844                 __pFooter->SetItemEnabled(0, isEnable);
1845                 __pFooter->SetItemEnabled(1, isEnable);
1846         }
1847         else if (__initializeDisplayModeCurrent == APPCONTROL_MODE_WEB_LINK)
1848         {
1849                 __pFooter->SetButtonEnabled(BUTTON_POSITION_LEFT, isEnable);
1850                 __pFooter->SetItemEnabled(0, isEnable);
1851                 __pFooter->SetItemEnabled(1, isEnable);
1852         }
1853         else if (__initializeDisplayModeCurrent == APPCONTROL_MODE_CROP)
1854         {
1855                 __pFooter->SetItemEnabled(0, isEnable);
1856         }
1857         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1858 }
1859
1860 Bitmap*
1861 ImageViewerForm::GetQuickThumbnailN(String& filePath)
1862 {
1863         AppLogDebug("ENTER");
1864         Bitmap* pBitmap = null;
1865
1866         if (filePath.GetLength() > 4)
1867         {
1868                 int totalPage = 0;
1869                 int totalCount = 0;
1870                 ContentSearch contentSearch;
1871                 ContentSearchResult* pResultItem = null;
1872                 IList* pContentInfoList = null;
1873                 String queryString;
1874                 ContentType contentType = ContentManagerUtil::CheckContentType(filePath);
1875                 result r = contentSearch.Construct(contentType);
1876                 AppLogDebug("r(%s)", GetErrorMessage(r));
1877                 if (r != E_SUCCESS)
1878                 {
1879                         pBitmap = new (std::nothrow) Bitmap();
1880                         r = pBitmap->Construct(DUMMY_IMAGE_DIMENSION, BITMAP_PIXEL_FORMAT_RGB565);
1881                         if (r == E_SUCCESS)
1882                         {
1883                                 return pBitmap;
1884                         }
1885                         else
1886                         {
1887                                 delete pBitmap;
1888                                 return null;
1889                         }
1890                 }
1891                 queryString = CONTENT_QUERY_PREFIX_FILENAME;
1892                 queryString.Append(L"'");
1893                 queryString.Append(__pPresentationModel->GetFileName(filePath));
1894                 queryString.Append(L"'");
1895
1896                 pContentInfoList = contentSearch.SearchN(PAGE_NO_CONTENT_SEARCH, COUNT_PER_PAGE_CONTENT_SEARCH,
1897                                 totalPage, totalCount, queryString, EMPTY_SPACE, SORT_ORDER_NONE);
1898
1899                 if ((pContentInfoList != null) && GetLastResult() == E_SUCCESS && (pContentInfoList->GetCount() > 0))
1900                 {
1901                         IEnumerator* pEnum = pContentInfoList->GetEnumeratorN();
1902                         while (pEnum->MoveNext() == E_SUCCESS)
1903                         {
1904                                 pResultItem = static_cast<ContentSearchResult*>(pEnum->GetCurrent());
1905                                 if (pResultItem == null)
1906                                 {
1907                                         continue;
1908                                 }
1909
1910                                 if (pResultItem->GetContentInfo()->GetContentPath().CompareTo(filePath) == 0)
1911                                 {
1912                                         pBitmap = pResultItem->GetContentInfo()->GetThumbnailN();
1913                                 }
1914                         }
1915                         delete pEnum;
1916                 }
1917
1918                 if (pContentInfoList != null)
1919                 {
1920                         delete pContentInfoList;
1921                 }
1922
1923                 if (pBitmap != null)
1924                 {
1925                         ImageViewerMediaType mediaType = CommonUtil::GetMediaType(filePath);
1926                         if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE)
1927                         {
1928                                 ImageMetadata* pImgMeta = ContentManagerUtil::GetImageMetaN(filePath);
1929
1930                                 if (pImgMeta != null)
1931                                 {
1932                                         Dimension srcDim(pImgMeta->GetWidth(), pImgMeta->GetHeight());
1933                                         pBitmap->Scale(srcDim);
1934                                         delete pImgMeta;
1935                                 }
1936                                 else
1937                                 {
1938                                         ImageBuffer* imageBuffer = new (std::nothrow) ImageBuffer();
1939                                         result r = imageBuffer->Construct(filePath);
1940                                         if (r == E_SUCCESS)
1941                                         {
1942                                                 Dimension srcDim(imageBuffer->GetWidth(), imageBuffer->GetHeight());
1943                                                 pBitmap->Scale(srcDim);
1944                                                 delete imageBuffer;
1945                                         }
1946                                 }
1947                         }
1948                         else if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_VIDEO)
1949                         {
1950                                 VideoMetadata* pVideoMeta = ContentManagerUtil::GetVideoMetaN(filePath);
1951
1952                                 if (pVideoMeta != null && GetLastResult() == E_SUCCESS)
1953                                 {
1954                                         Dimension srcDim(pVideoMeta->GetWidth(), pVideoMeta->GetHeight());
1955                                         pBitmap->Scale(srcDim);
1956                                         delete pVideoMeta;
1957                                 }
1958                         }
1959                 }
1960                 else
1961                 {
1962                         Canvas mainCanvas;
1963                         mainCanvas.Construct(DUMMY_IMAGE_RECTANGLE);
1964                         mainCanvas.FillRectangle(Color::GetColor(COLOR_ID_WHITE), DUMMY_IMAGE_RECTANGLE);
1965                         pBitmap = new (std::nothrow) Bitmap();
1966                         pBitmap->Construct(mainCanvas, DUMMY_IMAGE_RECTANGLE);
1967                 }
1968         }
1969         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1970         return pBitmap;
1971 }