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