1. Added 'Home and lock screen option' 2. Solved crop crash issue
[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
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         result r = File::Remove(filePath);
452         if (r != E_SUCCESS)
453         {
454                 MessageBox messageBox;
455                 messageBox.Construct(L"", ResourceManager::GetString(L"IDS_COM_POP_DELETE_FAILED"),
456                                 MSGBOX_STYLE_NONE, 3000);
457                 int modalResult = 0;
458                 messageBox.ShowAndWait(modalResult);
459                 AppLogDebug("EXIT 4(%s)", GetErrorMessage(GetLastResult()));
460
461                 return r;
462         }
463
464         if (filePath.StartsWith(Environment::GetMediaPath(), 0) == true
465                 || filePath.StartsWith(Environment::GetExternalStoragePath(), 0) == true)
466         {
467                 ContentManager::ScanFile(filePath);
468         }
469
470         __pPresentationModel->DeleteFilePathAt(currentIndex);
471         if (countPath == 1)
472         {
473                 UiApp* pApp = UiApp::GetInstance();
474                 pApp->Terminate();
475                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
476
477                 return r;
478         }
479         else if ((countPath - 1) == currentIndex)
480         {
481                 __pGallery->SetCurrentItemIndex(--currentIndex);
482         }
483
484         __pGallery->UpdateGallery();
485         filePath = __pPresentationModel->GetFilePathAt(currentIndex);
486         __pPresentationModel->RequestImage(filePath);
487
488         GetHeaderString(__pGallery->GetCurrentItemIndex(), strItemText, strItemIdxText);
489         __pHeader->SetTitleText(strItemText);
490         __pHeader->SetDescriptionText(strItemIdxText);
491
492         if (__visible == true)
493         {
494                 ImageViewerMediaType mediaType = CommonUtil::GetMediaType(filePath);
495
496                 if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE)
497                 {
498                         __pPlayButton->SetShowState(false);
499                 }
500                 else
501                 {
502                         __pPlayButton->SetShowState(true);
503                 }
504         }
505         Invalidate(true);
506         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
507
508         return r;
509 }
510
511 void
512 ImageViewerForm::CallVideoPlayer(void)
513 {
514         AppLogDebug("ENTER");
515         int index = __pGallery->GetCurrentItemIndex();
516         String filePath = __pPresentationModel->GetFilePathAt(index);
517         filePath.Insert(APPCONTROL_DATA_URI_FILE, 0);
518
519         AppLogDebug("ENTER(%ls)", filePath.GetPointer());
520
521         __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_VIDEO_PLAYER, APPCONTROL_OPERATION_ID_VIEW,
522                         &filePath, null, this);
523         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
524 }
525
526 void
527 ImageViewerForm::CreateGallery(void)
528 {
529         AppLogDebug("ENTER");
530         Rectangle clientRect = GetClientAreaBounds();
531         Rectangle rect = GetBounds();
532
533         __pGallery = new (std::nothrow) Gallery();
534         __pGallery->Construct(Rectangle(0, -clientRect.y, rect.width, rect.height));
535         __pGallery->SetName(L"GalleryControl");
536         __pGallery->SetItemProvider(*this);
537         __pGallery->AddGalleryEventListener(*this);
538         AddControl(*__pGallery);
539         __pGallery->SetTextOfEmptyGallery(ResourceManager::GetString(L"IDS_COM_BODY_LOADING"));
540
541         SlideShowTransitionEffect effect = __pPresentationModel->GetTransitionEffectOfSlideShow();
542
543         switch (effect)
544         {
545         case SLIDE_SHOW_TRANSITION_EFFECT_DISSOLVE:
546                 __pGallery->SetSlideShowAnimation(Controls::GALLERY_ANIMATION_DISSOLVE);
547                 break;
548         case SLIDE_SHOW_TRANSITION_EFFECT_ZOOM:
549                 __pGallery->SetSlideShowAnimation(Controls::GALLERY_ANIMATION_ZOOM);
550                 break;
551         case SLIDE_SHOW_TRANSITION_EFFECT_SLIDE:
552                 break;
553         }
554
555         __pGallery->SetSlideShowViewDuration(__pPresentationModel->GetDurationOfSlideShow());
556
557         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
558 }
559
560 result
561 ImageViewerForm::InitializePanelDetail()
562 {
563         AppLogDebug("ENTER");
564         __pScrollPanel = new (std::nothrow) ScrollPanel();
565
566         String arrayId[DETAIL_COUNT_MAX] =
567         {
568                         L"IDS_COM_BODY_DETAILS_NAME", L"IDS_IV_BODY_FILE_FORMAT", L"IDS_IV_BODY_DATE_CREATED",
569                         L"IDS_COM_BODY_SIZE", L"IDS_IV_BODY_RESOLUTION", L"IDS_COM_BODY_LOCATION",
570                         L"IDS_COM_BODY_LATITUDE", L"IDS_COM_BODY_LONGITUDE", L"IDS_IV_BODY_FILE_LOCATION"
571         };
572
573         if (__pScrollPanel == null)
574         {
575                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
576
577                 return E_INVALID_STATE;
578         }
579
580         Rectangle clientRect = GetClientAreaBounds();
581         result r = __pScrollPanel->Construct(Rectangle(0, 0, clientRect.width, clientRect.height));
582         if (r != E_SUCCESS)
583         {
584                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
585
586                 return E_INVALID_STATE;
587         }
588
589         __pDetail_Label = new (std::nothrow) Label();
590         __pDetail_Label->Construct(RECT_DETAILS_CONTORL_LABEL, ResourceManager::GetString(L"IDS_COM_BODY_DETAILS"));
591         __pScrollPanel->AddControl(*__pDetail_Label);
592         __pDetail_Label->SetTextVerticalAlignment(ALIGNMENT_TOP);
593         __pDetail_Label->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
594         __pDetail_Label->SetTextColor(Color::GetColor(COLOR_ID_WHITE));
595         __pDetail_Label->SetTextConfig(DETAIL_MAIN_FONT_SIZE, LABEL_TEXT_STYLE_BOLD);
596
597         for (int i = 0; i < DETAIL_COUNT_MAX; ++i)
598         {
599                 __pDetail_FileInfo_Label[i] = new (std::nothrow) Label();
600                 __pDetail_FileInfo_Label[i]->Construct(
601                                 Rectangle(X_DETAIL_FILEINFO_LABEL,
602                                                 GAP_H_DETAIL_TEXT * (i + 1) + H_DETAIL_MAIN_TEXT + (H_DETAIL_MAIN_TEXT + H_DETAIL_SUB_TEXT) * i,
603                                                 clientRect.width - GAP_W_END_OF_LABEL, H_DETAIL_FILEINFO_LABEL), ResourceManager::GetString(arrayId[i]));
604                 __pScrollPanel->AddControl(*__pDetail_FileInfo_Label[i]);
605
606                 __pDetail_FileInfo_Label[i]->SetTextVerticalAlignment(ALIGNMENT_TOP);
607                 __pDetail_FileInfo_Label[i]->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
608                 __pDetail_FileInfo_Label[i]->SetTextColor(Color::GetColor(COLOR_ID_GREY));
609                 __pDetail_FileInfo_Label[i]->SetTextConfig(DETAIL_SUB_FONT_SIZE, LABEL_TEXT_STYLE_BOLD);
610
611                 __pDetail_FileInfo_Value_Label[i] = new (std::nothrow) Label();
612
613                 if (i == DETAIL_COUNT_MAX - 1)
614                 {
615                         __pDetail_FileInfo_Value_Label[i]->Construct(
616                                         Rectangle(X_DETAIL_FILEINFO_LABEL,
617                                                         GAP_H_DETAIL_TEXT * (i + 1) + H_DETAIL_MAIN_TEXT + (H_DETAIL_MAIN_TEXT * i) + H_DETAIL_SUB_TEXT * (i + 1),
618                                                         clientRect.width - GAP_W_END_OF_LABEL, H_DETAIL_FILEINFO_VALUE_LABEL * 3), L"");
619                 }
620                 else
621                 {
622                         __pDetail_FileInfo_Value_Label[i]->Construct(
623                                         Rectangle(X_DETAIL_FILEINFO_LABEL,
624                                                         GAP_H_DETAIL_TEXT * (i + 1) + H_DETAIL_MAIN_TEXT + (H_DETAIL_MAIN_TEXT * i) + H_DETAIL_SUB_TEXT * (i + 1),
625                                                         clientRect.width - GAP_W_END_OF_LABEL, H_DETAIL_FILEINFO_VALUE_LABEL), L"");
626                 }
627
628                 __pScrollPanel->AddControl(*__pDetail_FileInfo_Value_Label[i]);
629
630                 __pDetail_FileInfo_Value_Label[i]->SetTextVerticalAlignment(ALIGNMENT_TOP);
631                 __pDetail_FileInfo_Value_Label[i]->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
632                 __pDetail_FileInfo_Value_Label[i]->SetTextColor(Color::GetColor(COLOR_ID_WHITE));
633                 __pDetail_FileInfo_Value_Label[i]->SetTextConfig(DETAIL_MAIN_FONT_SIZE, LABEL_TEXT_STYLE_BOLD);
634         }
635
636         __pScrollPanel->SetBackgroundColor(COLOR_HEADER_CONTORL_PANEL);
637         __pScrollPanel->SetShowState(false);
638
639         __pRenameButton = new (std::nothrow) Button();
640         Rectangle rect = GetBounds();
641         __pRenameButton->Construct(Rectangle(rect.width - W_RENAME_BUTTON - 20, Y_RENAME_BUTTON, W_RENAME_BUTTON, H_RENAME_BUTTON));
642         __pRenameButton->SetActionId(ACTION_ID_PANEL_HEADER_DETAILS_RENAME);
643         __pRenameButton->AddActionEventListener(*this);
644
645         Bitmap* pIcon = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_EDIT_NAME);
646         Bitmap* pIconBackground =
647                         ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_EDIT_NAME_NORMAL_BACKGROUND);
648         Bitmap* pIconPressed =
649                         ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_EDIT_NAME_NORMAL_BACKGROUND_PRESS);
650
651         if (pIcon != null && pIconPressed != null && pIconBackground != null)
652         {
653                 __pRenameButton->SetNormalBackgroundBitmap(*pIconBackground);
654                 __pRenameButton->SetPressedBackgroundBitmap(*pIconPressed);
655                 Point iconPosition(0, 0);
656                 __pRenameButton->SetNormalBitmap(iconPosition, *pIcon);
657                 __pRenameButton->SetPressedBitmap(iconPosition, *pIconPressed);
658         }
659         else
660         {
661                 __pRenameButton->SetColor(BUTTON_STATUS_NORMAL, COLOR_HEADER_BUTTON1);
662                 __pRenameButton->SetColor(BUTTON_STATUS_PRESSED, COLOR_HEADER_BUTTON1);
663         }
664         delete pIcon;
665         delete pIconPressed;
666         delete pIconBackground;
667
668         __pRenameButton->SetColor(BUTTON_STATUS_NORMAL, COLOR_HEADER_BUTTON1);
669         __pScrollPanel->AddControl(*__pRenameButton);
670
671
672         AddControl(*__pScrollPanel);
673         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
674
675         return E_SUCCESS;
676 }
677
678 result
679 ImageViewerForm::InitializePopup(void)
680 {
681         AppLogDebug("ENTER");
682         if (__pDeletePopup == null)
683         {
684                 __pDeletePopup = new (std::nothrow) Popup();
685                 __pDeletePopup->Construct(false, Dimension(W_DELETE_POPUP, H_DELETE_POPUP));
686
687                 Rectangle popupClientBounds = __pDeletePopup->GetClientAreaBounds();
688
689                 Label* pLabel = new (std::nothrow) Label();
690                 pLabel->Construct(Rectangle(0, 0, popupClientBounds.width, H_DELETE_LABEL),
691                                 ResourceManager::GetString(L"IDS_COM_BODY_DELETE") + L"?");
692
693                 Button* pDeleteButton = new (std::nothrow) Button();
694                 pDeleteButton->Construct(
695                                 Rectangle(0, Y_DELETE_BUTTON, popupClientBounds.width / 2 - GAP_W_POPUP_ITEM, H_DELETE_BUTTON),
696                                 ResourceManager::GetString(L"IDS_COM_BODY_DELETE"));
697                 pDeleteButton->SetColor(BUTTON_STATUS_NORMAL, COLOR_DELETE_BUTTON_NORMAL);
698                 pDeleteButton->SetColor(BUTTON_STATUS_PRESSED, COLOR_DELETE_BUTTON_PRESSED);
699                 pDeleteButton->SetTextColor(COLOR_DELETE_BUTTON_TEXT);
700                 pDeleteButton->SetActionId(ACTION_ID_DELETE_POPUP_DEL);
701                 pDeleteButton->AddActionEventListener(*this);
702
703                 Button* pCancelButton = new (std::nothrow) Button();
704                 pCancelButton->Construct(
705                                 Rectangle(popupClientBounds.width / 2 + GAP_W_POPUP_ITEM,
706                                                 Y_DELETE_BUTTON, popupClientBounds.width / 2 - GAP_W_POPUP_ITEM, H_DELETE_BUTTON),
707                                                 ResourceManager::GetString(L"IDS_COM_SK_CANCEL"));
708                 pCancelButton->SetActionId(ACTION_ID_DELETE_POPUP_CANCEL);
709                 pCancelButton->AddActionEventListener(*this);
710
711                 __pDeletePopup->AddControl(*pLabel);
712                 __pDeletePopup->AddControl(*pDeleteButton);
713                 __pDeletePopup->AddControl(*pCancelButton);
714         }
715         else
716         {
717                 __pDeletePopup->SetShowState(true);
718                 __pDeletePopup->Show();
719         }
720         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
721
722         return E_SUCCESS;
723 }
724
725 result
726 ImageViewerForm::InitializeContextMenuMore(void)
727 {
728         AppLogDebug("ENTER");
729         int currentIndex = __pGallery->GetCurrentItemIndex();
730         String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
731
732         ImageViewerMediaType mediaType = CommonUtil::GetMediaType(filePath);
733
734         if (__pContextMenuMore != null)
735         {
736                 delete __pContextMenuMore;
737                 __pContextMenuMore = null;
738         }
739
740         __pContextMenuMore = new (std::nothrow) ContextMenu();
741
742         __pContextMenuMore->Construct(Point(X_MORE, GetClientAreaBounds().y + GetClientAreaBounds().height),
743                         CONTEXT_MENU_STYLE_LIST, CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD);
744
745         if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE)
746         {
747                 __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_IV_OPT_SET_AS"),
748                                 ACTION_ID_CONTEXTMENU_SET_AS);
749                 __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_IV_BODY_CROP"), ACTION_ID_FOOTER_BUTTON_CROP);
750         }
751
752         if (__pGallery->GetItemCount() > 1)
753         {
754                 __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_IV_OPT_SLIDE_SHOW"),
755                                 ACTION_ID_FOOTER_BUTTON_SLIDE);
756         }
757         __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_DETAILS"),
758                         ACTION_ID_FOOTER_BUTTON_DETAILS);
759         __pContextMenuMore->SetShowState(false);
760         __pContextMenuMore->AddActionEventListener(*this);
761         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
762
763         return E_SUCCESS;
764 }
765
766 result
767 ImageViewerForm::InitializeContextMenuSetAs(void)
768 {
769         AppLogDebug("ENTER");
770
771         if (__pContextMenuSetAs != null)
772         {
773                 delete __pContextMenuSetAs;
774                 __pContextMenuSetAs = null;
775         }
776
777         __pContextMenuSetAs = new (std::nothrow) ContextMenu();
778         __pContextMenuSetAs->Construct(Point(X_MORE, GetClientAreaBounds().y + GetClientAreaBounds().height),
779                         CONTEXT_MENU_STYLE_LIST, CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD);
780
781         __pContextMenuSetAs->AddItem(ResourceManager::GetString(L"IDS_IV_HEADER_HOME_SCREEN_WALLPAPER_ABB"),
782                         ACTION_ID_CONTEXTMENU_HOME);
783         __pContextMenuSetAs->AddItem(ResourceManager::GetString(L"IDS_IV_HEADER_LOCK_SCREEN_WALLPAPER_ABB"),
784                         ACTION_ID_CONTEXTMENU_LOCK);
785         __pContextMenuSetAs->AddItem(L"Home and lock screens", ACTION_ID_CONTEXTMENU_HOME_AND_LOCK);
786         __pContextMenuSetAs->AddItem(ResourceManager::GetString(L"IDS_IV_BODY_CALLER_IMAGE"),
787                         ACTION_ID_CONTEXTMENU_CALLER);
788         __pContextMenuSetAs->AddActionEventListener(*this);
789         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
790
791         return E_SUCCESS;
792 }
793
794 result
795 ImageViewerForm::InitializeContextMenuShare(void)
796 {
797         AppLogDebug("ENTER");
798         if (__pContextMenuShare != null)
799         {
800                 delete __pContextMenuShare;
801                 __pContextMenuShare = null;
802         }
803         __pContextMenuShare = new (std::nothrow) ContextMenu();
804         __pContextMenuShare->Construct(Point((GetClientAreaBounds().width - (X_MORE * 4)) / 4 + X_MORE * 2,
805                         GetClientAreaBounds().y + GetClientAreaBounds().height), CONTEXT_MENU_STYLE_LIST,
806                         CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD);
807
808         __pContextMenuShare->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_MESSAGE"),
809                         ACTION_ID_CONTEXTMENU_MESSAGE);
810         __pContextMenuShare->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_EMAIL"), ACTION_ID_CONTEXTMENU_EMAIL);
811         __pContextMenuShare->AddActionEventListener(*this);
812         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
813
814         return E_SUCCESS;
815 }
816
817 long long
818 ImageViewerForm::GetFileSize(String filePath)
819 {
820         AppLogDebug("ENTER");
821         FileAttributes attr;
822         long long size = 0;
823
824         result r = File::GetAttributes(filePath, attr);
825         if (r != E_SUCCESS)
826         {
827                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
828
829                 return 0;
830         }
831         size = attr.GetFileSize();
832         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
833
834         return size;
835 }
836
837 result
838 ImageViewerForm::SetDetailInfo(void)
839 {
840         AppLogDebug("ENTER");
841
842         Rectangle clientRect = GetClientAreaBounds();
843         __pScrollPanel->SetBounds(0, 0, clientRect.width, clientRect.height);
844
845         int currentIndex = __pGallery->GetCurrentItemIndex();
846         String strFilePath = __pPresentationModel->GetFilePathAt(currentIndex);
847
848         ImageViewerMediaType mediaType = CommonUtil::GetMediaType(strFilePath);
849
850         String strResult[DETAIL_COUNT_MAX] = {EMPTY_SPACE, };
851
852         strResult[0] = __pPresentationModel->GetFileName(strFilePath);
853         strResult[1] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
854
855         FileAttributes attr;
856         result r = File::GetAttributes(strFilePath, attr);
857         if (r == E_SUCCESS)
858         {
859                 long long nSize = attr.GetFileSize();
860                 DateTime dateTime = attr.GetDateTime();
861                 strResult[2] = dateTime.ToString();
862
863                 if (nSize > SINGLE_GIGA_BYTE)
864                 {
865                         strResult[3].Format(FORMAT_BUFFER_SIZE, L"%lld ", nSize / SINGLE_GIGA_BYTE);
866                         strResult[3].Append(ResourceManager::GetString(L"IDS_COM_BODY_GB"));
867                 }
868                 else if (nSize > SINGLE_MEGA_BYTE)
869                 {
870                         strResult[3].Format(FORMAT_BUFFER_SIZE, L"%lld ", nSize / SINGLE_MEGA_BYTE);
871                         strResult[3].Append(ResourceManager::GetString(L"IDS_COM_BODY_MB"));
872                 }
873                 else if (nSize > SINGLE_KILO_BYTE)
874                 {
875                         strResult[3].Format(FORMAT_BUFFER_SIZE, L"%lld ", nSize / SINGLE_KILO_BYTE);
876                         strResult[3].Append(ResourceManager::GetString(L"IDS_COM_BODY_KB"));
877                 }
878                 else
879                 {
880                         strResult[3].Format(FORMAT_BUFFER_SIZE, L"%lld ", nSize);
881                         strResult[3].Append(ResourceManager::GetString(L"IDS_COM_BODY_B"));
882                 }
883         }
884         else
885         {
886                 strResult[2] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
887                 strResult[3] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
888         }
889
890         strResult[4] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
891         strResult[5] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
892         strResult[6] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
893         strResult[7] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
894         strResult[8] = strFilePath;
895         String fileName = File::GetFileName(strFilePath);
896         strResult[8].Remove(strResult[8].GetLength() - fileName.GetLength(), fileName.GetLength());
897
898         if (__initializeDisplayModeCurrent == APPCONTROL_MODE_WEB_LINK)
899         {
900                 strResult[0] = __downLordFileName;
901         }
902         else if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE)
903         {
904                 ImageMetadata* pImgMeta = ContentManagerUtil::GetImageMetaN(strFilePath);
905
906                 if (pImgMeta != null)
907                 {
908                         ImageContentInfo imageContentInfo;
909                         r = imageContentInfo.Construct(&strFilePath);
910                         if (r == E_SUCCESS)
911                         {
912                                 strResult[1] = imageContentInfo.GetMediaFormat();
913                                 strResult[4].Format(FORMAT_BUFFER_SIZE, L"%d x %d", pImgMeta->GetWidth(),
914                                                 pImgMeta->GetHeight());
915
916                                 if (imageContentInfo.GetLocationTag() != EMPTY_SPACE)
917                                 {
918                                         strResult[5].Format(FORMAT_BUFFER_SIZE, L"%ls", imageContentInfo.GetLocationTag().GetPointer());
919                                 }
920
921                                 if (pImgMeta->GetLatitude() > 1.0 && pImgMeta->GetLongitude() > 1.0)
922                                 {
923                                         strResult[6].Format(FORMAT_BUFFER_SIZE, L"%f", pImgMeta->GetLatitude());
924                                         strResult[7].Format(FORMAT_BUFFER_SIZE, L"%f", pImgMeta->GetLongitude());
925                                 }
926                         }
927                         delete pImgMeta;
928                 }
929         }
930         else if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_VIDEO)
931         {
932                 VideoMetadata* pVideoMeta = ContentManagerUtil::GetVideoMetaN(strFilePath);
933                 if (pVideoMeta != null)
934                 {
935                         VideoContentInfo videoContentInfo;
936                         r = videoContentInfo.Construct(&strFilePath);
937                         if (r == E_SUCCESS)
938                         {
939                                 strResult[1] = videoContentInfo.GetMediaFormat();
940                                 strResult[4].Format(FORMAT_BUFFER_SIZE, L"%d x %d", pVideoMeta->GetWidth(),
941                                                 pVideoMeta->GetHeight());
942                                 if (videoContentInfo.GetLocationTag() != EMPTY_SPACE)
943                                 {
944                                         strResult[5].Format(FORMAT_BUFFER_SIZE, L"%ls", videoContentInfo.GetLocationTag().GetPointer());
945                                 }
946                         }
947                 }
948         }
949
950         for (int i = 0; i < DETAIL_COUNT_MAX; ++i)
951         {
952                 __pDetail_FileInfo_Value_Label[i]->SetText(strResult[i]);
953                 __pDetail_FileInfo_Value_Label[i]->RequestRedraw();
954         }
955
956         if (__initializeDisplayModeCurrent == APPCONTROL_MODE_WEB_LINK)
957         {
958                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
959                 return r;
960         }
961
962         Rectangle rect = GetBounds();
963         __pRenameButton->SetBounds(Rectangle(rect.width - W_RENAME_BUTTON - 20, Y_RENAME_BUTTON, W_RENAME_BUTTON, H_RENAME_BUTTON));
964
965         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
966
967         return r;
968 }
969
970 result
971 ImageViewerForm::ShowPanelDetail(bool showStatus)
972 {
973         AppLogDebug("ENTER");
974         if (showStatus)
975         {
976                 SetDetailInfo();
977                 __pScrollPanel->SetShowState(true);
978                 __detail = false;
979         }
980         else
981         {
982                 __pScrollPanel->SetShowState(false);
983                 __detail = true;
984         }
985         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
986
987         return E_SUCCESS;
988 }
989
990 result
991 ImageViewerForm::ChangeFooterItem(bool isChanged, Footer* pFooter, int position)
992 {
993         AppLogDebug("ENTER");
994         FooterItem footerItem;
995         footerItem.Construct(ACTION_ID_FOOTER_BUTTON_DETAILS);
996         Bitmap* pfooterItem = null;
997
998         if (isChanged)
999         {
1000                 pfooterItem = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_DETAILS_CLOSE);
1001                 footerItem.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pfooterItem);
1002         }
1003         else
1004         {
1005                 pfooterItem = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_DETAILS);
1006                 footerItem.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pfooterItem);
1007         }
1008
1009         pFooter->SetItemAt(position, footerItem);
1010         pFooter->Invalidate(true);
1011
1012         delete pfooterItem;
1013         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1014
1015         return E_SUCCESS;
1016 }
1017
1018 void
1019 ImageViewerForm::DownloadFile(void)
1020 {
1021         AppLogDebug("ENTER");
1022         String DestPath = App::GetInstance()->GetAppRootPath() + TEMP_FILE_PATH_WEB_FILE;
1023         if (File::IsFileExist(DestPath) == false)
1024         {
1025                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1026                 return;
1027         }
1028
1029         ContentId contentId;
1030         ContentManager contentManager;
1031         contentManager.Construct();
1032
1033         ImageContentInfo imageContentInfo;
1034         imageContentInfo.Construct(null);
1035
1036         imageContentInfo.SetKeyword(L"platform, tizen");
1037         String sourcePath = DestPath;
1038         String destPath = Environment::GetMediaPath();
1039         destPath.Append(FOLDER_PATH_DOWNLOADS);
1040         destPath.Append(__downLordFileName);
1041
1042         contentId = contentManager.CreateContent(sourcePath, destPath, true, &imageContentInfo);
1043         ImageViewerForm::OnFormBackRequested(*this);
1044         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1045 }
1046
1047 int
1048 ImageViewerForm::GetItemCount(void)
1049 {
1050         AppLogDebug("ENTER");
1051         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1052
1053         return __pPresentationModel->GetFileCount();
1054 }
1055
1056 GalleryItem*
1057 ImageViewerForm::CreateItem(int index)
1058 {
1059         AppLogDebug("ENTER : index(%d)", index);
1060         GalleryItem* pGallery = new (std::nothrow) GalleryItem();
1061
1062         String filePath = __pPresentationModel->GetFilePathAt(index);
1063         ImageInfo* pImageInfo = __pPresentationModel->GetImageCacheAt(index);
1064         Bitmap* pBitmap = pImageInfo->GetBitmapN();
1065         if (pBitmap == null)
1066         {
1067                 pBitmap = GetQuickThumbnailN(filePath);
1068
1069                 if (pBitmap == null)
1070                 {
1071                         pBitmap = new (std::nothrow) Bitmap();
1072                         pBitmap->Construct(DUMMY_IMAGE_DIMENSION, BITMAP_PIXEL_FORMAT_RGB565);
1073                 }
1074         }
1075         pGallery->Construct(*pBitmap, filePath);
1076         delete pBitmap;
1077         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1078
1079         return pGallery;
1080 }
1081
1082 bool
1083 ImageViewerForm::DeleteItem(int index, GalleryItem* pItem)
1084 {
1085         AppLogDebug("ENTER index(%d)", index);
1086         ImageInfo* pImageInfo = __pPresentationModel->GetImageCacheAt(index);
1087         pImageInfo->ClearBitmap();
1088         delete pItem;
1089         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1090
1091         return true;
1092 }
1093
1094 void
1095 ImageViewerForm::OnGalleryCurrentItemChanged(Gallery& view, int index)
1096 {
1097         AppLogDebug("ENTER index(%d)", index);
1098
1099         String filePath = __pPresentationModel->GetFilePathAt(index);
1100         AppLogDebug("ENTER index(%d) filePath(%ls)", index, filePath.GetPointer());
1101         __pPresentationModel->RequestImage(filePath);
1102
1103         String strItemText;
1104         String strItemIdxText;
1105         GetHeaderString(__pGallery->GetCurrentItemIndex(), strItemText, strItemIdxText);
1106         __pHeader->SetTitleText(strItemText);
1107         __pHeader->SetDescriptionText(strItemIdxText);
1108
1109         if (__visible == true)
1110         {
1111                 ImageViewerMediaType mediaType = CommonUtil::GetMediaType(filePath);
1112                 if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_VIDEO)
1113                 {
1114                         __pPlayButton->SetShowState(true);
1115                 }
1116                 else
1117                 {
1118                         __pPlayButton->SetShowState(false);
1119                 }
1120         }
1121
1122         Invalidate(true);
1123         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1124 }
1125
1126 void
1127 ImageViewerForm::OnGalleryItemClicked(Gallery& view, int index)
1128 {
1129         AppLogDebug("ENTER");
1130
1131         String filePath = __pPresentationModel->GetFilePathAt(index);
1132         ContentType contentType = ContentManagerUtil::CheckContentType(filePath);
1133
1134         if (__visible == true)
1135         {
1136                 if (contentType == CONTENT_TYPE_VIDEO)
1137                 {
1138                         __pPlayButton->SetShowState(false);
1139                 }
1140
1141                 SetActionBarsVisible(FORM_ACTION_BAR_INDICATOR | FORM_ACTION_BAR_HEADER | FORM_ACTION_BAR_FOOTER, false);
1142                 __visible = false;
1143         }
1144         else
1145         {
1146                 if (contentType == CONTENT_TYPE_VIDEO)
1147                 {
1148                         __pPlayButton->SetShowState(true);
1149                 }
1150
1151                 SetActionBarsVisible(FORM_ACTION_BAR_INDICATOR | FORM_ACTION_BAR_HEADER | FORM_ACTION_BAR_FOOTER, true);
1152                 __visible = true;
1153
1154                 __pPlayButton->SetPosition(__pPlayButton->GetPosition().x, __pPlayButton->GetPosition().y - 1);
1155                 __pPlayButton->SetPosition(__pPlayButton->GetPosition().x, __pPlayButton->GetPosition().y + 1);
1156         }
1157
1158         Rectangle clientRect = GetClientAreaBounds();
1159         Rectangle rect = GetBounds();
1160         __pGallery->SetBounds(Rectangle(0, -clientRect.y, rect.width, rect.height));
1161         Invalidate(true);
1162         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1163 }
1164
1165 void
1166 ImageViewerForm::OnGallerySlideShowStarted(Gallery& gallery)
1167 {
1168         AppLogDebug("ENTER");
1169         PowerManager::KeepScreenOnState(true, false);
1170         if (__visible  == true)
1171         {
1172                 SetActionBarsVisible(FORM_ACTION_BAR_INDICATOR | FORM_ACTION_BAR_HEADER | FORM_ACTION_BAR_FOOTER, false);
1173
1174                 int index = __pGallery->GetCurrentItemIndex();
1175                 String filePath = __pPresentationModel->GetFilePathAt(index);
1176                 ContentType contentType = ContentManagerUtil::CheckContentType(filePath);
1177
1178                 if (contentType == CONTENT_TYPE_VIDEO)
1179                 {
1180                         __pPlayButton->SetShowState(false);
1181                 }
1182
1183                 __visible = false;
1184         }
1185
1186         Rectangle clientRect = GetClientAreaBounds();
1187         Rectangle rect = GetBounds();
1188         __pGallery->SetBounds(Rectangle(0, -clientRect.y, rect.width, rect.height));
1189         Invalidate(true);
1190         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1191 }
1192
1193 void
1194 ImageViewerForm::OnGallerySlideShowStopped(Gallery& gallery)
1195 {
1196         AppLogDebug("ENTER");
1197         PowerManager::KeepScreenOnState(false, true);
1198         int index = __pGallery->GetCurrentItemIndex();
1199
1200         if (__visible == false)
1201         {
1202                 SetActionBarsVisible(FORM_ACTION_BAR_INDICATOR | FORM_ACTION_BAR_HEADER | FORM_ACTION_BAR_FOOTER, true);
1203
1204                 String filePath = __pPresentationModel->GetFilePathAt(index);
1205                 ContentType contentType = ContentManagerUtil::CheckContentType(filePath);
1206                 if (contentType == CONTENT_TYPE_VIDEO)
1207                 {
1208                         __pPlayButton->SetShowState(true);
1209                 }
1210
1211                 __pPlayButton->SetPosition(__pPlayButton->GetPosition().x, __pPlayButton->GetPosition().y - 1);
1212                 __pPlayButton->SetPosition(__pPlayButton->GetPosition().x, __pPlayButton->GetPosition().y + 1);
1213
1214                 __visible = true;
1215         }
1216
1217         String strItemText;
1218         String strItemIdxText;
1219         GetHeaderString(index, strItemText, strItemIdxText);
1220         __pHeader->SetTitleText(strItemText);
1221         __pHeader->SetDescriptionText(strItemIdxText);
1222
1223         Rectangle clientRect = GetClientAreaBounds();
1224         Rectangle rect = GetBounds();
1225         __pGallery->SetBounds(Rectangle(0, -clientRect.y, rect.width, rect.height));
1226
1227         Invalidate(true);
1228         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1229 }
1230
1231 void
1232 ImageViewerForm::OnUpdateContentList(void)
1233 {
1234 }
1235
1236 result
1237 ImageViewerForm::OnTerminating(void)
1238 {
1239         AppLogDebug("ENTER");
1240
1241         if (__pTimer != null)
1242         {
1243                 __pTimer->Cancel();
1244                 delete __pTimer;
1245                 __pTimer = null;
1246         }
1247
1248         __pPresentationModel->ClearImageRequests();
1249         __pPresentationModel->RemoveListener(*this);
1250         __pPresentationModel->RemoveFileUpdateListener(*this);
1251
1252         if (__pContextMenuCopy != null)
1253         {
1254                 delete __pContextMenuCopy;
1255                 __pContextMenuCopy = null;
1256         }
1257
1258         if (__pContextMenuSetAs != null)
1259         {
1260                 delete __pContextMenuSetAs;
1261                 __pContextMenuSetAs = null;
1262         }
1263
1264         if (__pDeletePopup != null)
1265         {
1266                 delete __pDeletePopup;
1267                 __pDeletePopup = null;
1268         }
1269
1270         if (__pContextMenuShare != null)
1271         {
1272                 delete __pContextMenuShare;
1273                 __pContextMenuShare = null;
1274         }
1275
1276         if (__pContextMenuMore != null)
1277         {
1278                 delete __pContextMenuMore;
1279                 __pContextMenuMore = null;
1280         }
1281
1282         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1283
1284         return E_SUCCESS;
1285 }
1286
1287 void
1288 ImageViewerForm::OnActionPerformed(const Control& source, int actionId)
1289 {
1290         AppLogDebug("ENTER actionId(%d)", actionId);
1291         SceneManager* pSceneManager = SceneManager::GetInstance();
1292         InitShowGallery();
1293
1294         switch (actionId)
1295         {
1296         case ACTION_ID_FOOTER_MORE:
1297         {
1298                 InitializeContextMenuMore();
1299
1300                 __pContextMenuMore->SetShowState(true);
1301                 __pContextMenuMore->Show();
1302         }
1303         break;
1304         case ACTION_ID_CONTEXTMENU_SET_AS:
1305                 InitializeContextMenuSetAs();
1306
1307                 __pContextMenuSetAs->SetShowState(true);
1308                 __pContextMenuSetAs->Show();
1309                 break;
1310         case ACTION_ID_FOOTER_BUTTON_SHARE:
1311                 InitializeContextMenuShare();
1312
1313                 __pContextMenuShare->SetShowState(true);
1314                 __pContextMenuShare->Show();
1315                 break;
1316         case ACTION_ID_FOOTER_BUTTON_DELETE:
1317                 __pDeletePopup->SetShowState(true);
1318                 __pDeletePopup->Show();
1319                 break;
1320         case ACTION_ID_FOOTER_BUTTON_SLIDE:
1321         {
1322                 int repeatValue = 0;
1323
1324                 if (__pPresentationModel->GetFileCount() > 1)
1325                 {
1326                         __pGallery->UpdateGallery();
1327                         if (__detail == false)
1328                         {
1329                                 ShowPanelDetail(false);
1330                         }
1331
1332                         __pSettingPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
1333                                         ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
1334
1335                         if (repeatValue == 0)
1336                         {
1337                                 __pGallery->StartSlideShow(false);
1338                         }
1339                         else
1340                         {
1341                                 __pGallery->StartSlideShow(true);
1342                         }
1343                 }
1344                 break;
1345         }
1346         case ACTION_ID_FOOTER_BUTTON_CROP:
1347         {
1348                 String filePath;
1349                 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1350                 filePath = __pPresentationModel->GetFilePathAt(__pGallery->GetCurrentItemIndex());
1351                 pList->Add(new (std::nothrow) String(filePath));
1352                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_CROP), pList);
1353         }
1354         break;
1355         case ACTION_ID_FOOTER_BUTTON_ROTATE_RIGHT:
1356         {
1357                 int currentIndex = __pGallery->GetCurrentItemIndex();
1358                 String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
1359                 RotateMode rotateMode = ROTATE_MODE_RIGHT;
1360                 __pPresentationModel->SetImageRotateStatus(true);
1361                 RotateImage(filePath, rotateMode);
1362                 __pPresentationModel->RequestImage(filePath);
1363                 //Invalidate(true);
1364                 ContentManager contentManager;
1365                 contentManager.Construct();
1366                 contentManager.ScanFile(filePath);
1367         }
1368         break;
1369         case ACTION_ID_FOOTER_BUTTON_ROTATE_LEFT:
1370         {
1371                 int currentIndex = __pGallery->GetCurrentItemIndex();
1372                 String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
1373                 RotateMode rotateMode = ROTATE_MODE_LEFT;
1374                 __pPresentationModel->SetImageRotateStatus(true);
1375                 RotateImage(filePath, rotateMode);
1376                 __pPresentationModel->RequestImage(filePath);
1377                 //Invalidate(true);
1378                 ContentManager contentManager;
1379                 contentManager.Construct();
1380                 contentManager.ScanFile(filePath);
1381         }
1382         break;
1383         case ACTION_ID_FOOTER_BUTTON_DETAILS:
1384         {
1385                 ShowPanelDetail(__detail);
1386                 break;
1387         }
1388         case ACTION_ID_FOOTER_BUTTON_BACK:
1389                 ImageViewerForm::OnFormBackRequested(*this);
1390                 break;
1391         case ACTION_ID_FOOTER_BUTTON_DOWNLOAD:
1392                 DownloadFile();
1393                 break;
1394         case ACTION_ID_FOOTER_BUTTON_SAVE:
1395                 break;
1396         case ACTION_ID_PANEL_HEADER_DETAILS_RENAME:
1397         {
1398                 ArrayList* pSelectedIndex = new (std::nothrow) ArrayList(SingleObjectDeleter);
1399                 pSelectedIndex->Construct();
1400                 pSelectedIndex->Add(new (std::nothrow) Integer(__pGallery->GetCurrentItemIndex()));
1401                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_NAME_EDITOR), pSelectedIndex);
1402                 break;
1403         }
1404         case ACTION_ID_CONTEXTMENU_HOME:
1405         {
1406                 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1407                 pList->Add(new (std::nothrow) Integer(__pGallery->GetCurrentItemIndex()));
1408                 pList->Add(new (std::nothrow) Integer(SET_AT_TYPE_HOME_SCREEN_WALLPAPER));
1409                 __pPresentationModel->SetSetterIndex(__pGallery->GetCurrentItemIndex());
1410                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_SETTER), pList);
1411                 break;
1412         }
1413         case ACTION_ID_CONTEXTMENU_LOCK:
1414         {
1415                 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1416                 pList->Add(new (std::nothrow) Integer(__pGallery->GetCurrentItemIndex()));
1417                 pList->Add(new (std::nothrow) Integer(SET_AT_TYPE_LOCK_SCREEN_WALLPAPER));
1418                 __pPresentationModel->SetSetterIndex(__pGallery->GetCurrentItemIndex());
1419                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_SETTER), pList);
1420                 break;
1421         }
1422         case ACTION_ID_CONTEXTMENU_CALLER:
1423         {
1424                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
1425                 pDataList->Construct();
1426                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_SELECTION_MODE),
1427                                 new (std::nothrow) String(APPCONTROL_DATA_SINGLE));
1428                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_SOCIAL_ITEM_TYPE),
1429                                 new (std::nothrow) String(APPCONTROL_DATA_PERSON));
1430                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_SOCIAL_RESULT_TYPE),
1431                                 new (std::nothrow) String(APPCONTROL_DATA_ITEM_ID));
1432
1433                 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_CONTACTS,
1434                                 APPCONTROL_OPERATION_ID_PICK, null, pDataList, this);
1435                 break;
1436         }
1437
1438         case ACTION_ID_CONTEXTMENU_HOME_AND_LOCK:
1439         {
1440                 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1441                 pList->Add(new (std::nothrow) Integer(__pGallery->GetCurrentItemIndex()));
1442                 pList->Add(new (std::nothrow) Integer(SET_AT_TYPE_HOME_AND_LOCK_SCREEN_WALLPAPER));
1443                 __pPresentationModel->SetSetterIndex(__pGallery->GetCurrentItemIndex());
1444                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_SETTER), pList);
1445                 break;
1446                 break;
1447         }
1448
1449         case ACTION_ID_CONTEXTMENU_EMAIL:
1450         {
1451                 OnRequestEmailAction();
1452                 break;
1453         }
1454         case ACTION_ID_CONTEXTMENU_MESSAGE:
1455         {
1456                 OnRequestMessagesAction();
1457                 break;
1458         }
1459         case ACTION_ID_CONTEXTMENU_COPY:
1460         {
1461                 int currentIndex = __pGallery->GetCurrentItemIndex();
1462                 String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
1463
1464                 ClipboardItem item;
1465                 item.Construct(CLIPBOARD_DATA_TYPE_IMAGE, filePath);
1466                 Clipboard* pClipboard = Clipboard::GetInstance();
1467                 pClipboard->CopyItem(item);
1468                 break;
1469         }
1470         case ACTION_ID_DELETE_POPUP_DEL:
1471         {
1472                 __pDeletePopup->SetShowState(false);
1473                 __pDeletePopup->Show();
1474                 DeleteImageFile();
1475
1476                 if (__detail == false)
1477                 {
1478                         ShowPanelDetail(false);
1479                 }
1480                 break;
1481         }
1482         case ACTION_ID_DELETE_POPUP_CANCEL:
1483         {
1484                 __pDeletePopup->SetShowState(false);
1485                 __pDeletePopup->Show();
1486                 break;
1487         }
1488         case ACTION_ID_CONTORL_BUTTON_PLAY:
1489                 CallVideoPlayer();
1490                 break;
1491         default:
1492                 break;
1493         }
1494         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1495 }
1496
1497 void
1498 ImageViewerForm::RotateImage(String& filePath, RotateMode rotateMode)
1499 {
1500         result r = E_SUCCESS;
1501         ImageBuffer* pRotatedBuffer = null;
1502         ImageBuffer* pRotatedBuffer1 = null;
1503         ImageFormat imageFormat;
1504         int width = 0;
1505         int height = 0;
1506         pRotatedBuffer = new (std::nothrow) ImageBuffer();
1507         r = pRotatedBuffer->Construct(filePath);
1508         pRotatedBuffer->GetImageInfo(filePath, imageFormat, width, height);
1509         if (r == E_SUCCESS)
1510         {
1511                 if (rotateMode == ROTATE_MODE_RIGHT)
1512                 {
1513                         pRotatedBuffer1 = pRotatedBuffer->RotateN(IMAGE_ROTATION_90);
1514                 }
1515                 else
1516                 {
1517                         pRotatedBuffer1 = pRotatedBuffer->RotateN(IMAGE_ROTATION_270);
1518                 }
1519         }
1520         TryCatch(pRotatedBuffer1 != null, r = GetLastResult(), "RotateN failed:%s", GetErrorMessage(GetLastResult()));
1521         pRotatedBuffer1->EncodeToFile(filePath, imageFormat, true, 100);
1522         delete pRotatedBuffer1;
1523         delete pRotatedBuffer;
1524         return;
1525
1526 CATCH:
1527         if (pRotatedBuffer != null) //this buffer is no longer used
1528         {
1529                 delete pRotatedBuffer;
1530         }
1531         if (pRotatedBuffer1 != null) //this buffer is no longer used
1532         {
1533                 delete pRotatedBuffer1;
1534         }
1535         return;
1536 }
1537
1538 void
1539 ImageViewerForm::OnFormBackRequested(Form& source)
1540 {
1541         AppLogDebug("ENTER");
1542         if (__detail == false)
1543         {
1544                 ShowPanelDetail(false);
1545         }
1546         else
1547         {
1548                 UiApp* pApp = UiApp::GetInstance();
1549                 pApp->Terminate();
1550         }
1551         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1552 }
1553
1554 void
1555 ImageViewerForm::OnSceneActivatedN(const SceneId& previousSceneId,
1556                 const SceneId& currentSceneId, IList* pArgs)
1557 {
1558         AppLogDebug("ENTER");
1559
1560         Rectangle clientRect = GetClientAreaBounds();
1561         Rectangle rect = GetBounds();
1562
1563         __pGallery->SetBounds(Rectangle(0, -clientRect.y, rect.width, rect.height));
1564         __pScrollPanel->SetBounds(Rectangle(0, 0, clientRect.width, clientRect.height));
1565         __pPlayButton->SetBounds(Rectangle(clientRect.width / 2 - 80, clientRect.height / 2 - 80, 160, 160));
1566
1567         if (previousSceneId == IDSCN_IMAGE_NAME_EDITOR && currentSceneId == IDSCN_IMAGE_VIEWER)
1568         {
1569                 SetDetailInfo();
1570                 String strItemText(EMPTY_SPACE);
1571                 String strItemIdxText(EMPTY_SPACE);
1572                 GetHeaderString(__pGallery->GetCurrentItemIndex(), strItemText, strItemIdxText);
1573                 __pHeader->SetTitleText(strItemText);
1574                 __pHeader->SetDescriptionText(strItemIdxText);
1575                 Invalidate(true);
1576         }
1577
1578         if (__pGallery->GetCurrentItemIndex() < 0)
1579         {
1580                 SetFooterItemState(false);
1581         }
1582         else
1583         {
1584                 SetFooterItemState(true);
1585         }
1586         Invalidate(true);
1587         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1588 }
1589
1590 void
1591 ImageViewerForm::OnSceneDeactivated(const SceneId& currentSceneId,
1592                 const SceneId& nextSceneId)
1593 {
1594         AppLogDebug("ENTER");
1595         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1596 }
1597
1598 void
1599 ImageViewerForm::OnImageDecodedN(const int index)
1600 {
1601         AppLogDebug("ENTER");
1602         __pGallery->RefreshGallery(index, GALLERY_REFRESH_TYPE_ITEM_MODIFY);
1603         __pGallery->Draw();
1604         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1605 }
1606
1607 void
1608 ImageViewerForm::OnAppControlCompleteResponseReceived(const AppId& appId,
1609                 const String& operationId, AppCtrlResult appControlResult,
1610                 const IMap* pExtraData)
1611 {
1612         AppLogDebug("ENTER");
1613
1614         if (appId == APPCONTROL_PROVIDER_ID_CONTACTS
1615                         && operationId == APPCONTROL_OPERATION_ID_PICK
1616                         && appControlResult == APP_CTRL_RESULT_SUCCEEDED)
1617         {
1618                 const String* pContactId =
1619                                 static_cast<const String*>(pExtraData->GetValue(String(APPCONTROL_KEY_SOCIAL_ITEM_ID)));
1620                 SceneManager* pSceneManager = SceneManager::GetInstance();
1621                 long long lresult = 0;
1622                 if (pContactId != null && pContactId->GetLength() > 0)
1623                 {
1624                         LongLong::Parse(*pContactId, lresult);
1625                 }
1626                 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1627                 pList->Add(new (std::nothrow) Integer(__pGallery->GetCurrentItemIndex()));
1628                 pList->Add(new (std::nothrow) Integer(SET_AT_TYPE_CALLER_IMAGE));
1629                 pList->Add(new (std::nothrow) LongLong(lresult));
1630                 __pPresentationModel->SetSetterIndex(__pGallery->GetCurrentItemIndex());
1631                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_SETTER), pList);
1632         }
1633
1634         ImageViewerApp* pImageViewerApp = static_cast<ImageViewerApp*>(ImageViewerApp::GetInstance());
1635         pImageViewerApp->SetFrameEnabled(true);
1636         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1637 }
1638
1639 void
1640 ImageViewerForm::OnOverlayControlCreated(const Control& source)
1641 {
1642         AppLogDebug("ENTER");
1643         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1644 }
1645
1646 void
1647 ImageViewerForm::OnOverlayControlOpened(const Control& source)
1648 {
1649         AppLogDebug("ENTER");
1650         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1651 }
1652
1653 void
1654 ImageViewerForm::OnOverlayControlClosed(const Control& source)
1655 {
1656         AppLogDebug("ENTER");
1657         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1658 }
1659
1660 void
1661 ImageViewerForm::OnOtherControlSelected(const Control& source)
1662 {
1663         AppLogDebug("ENTER");
1664         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1665 }
1666
1667 void
1668 ImageViewerForm::InitShowGallery(void)
1669 {
1670         AppLogDebug("ENTER");
1671         if (__pGallery != null && __pGallery->IsVisible() == false)
1672         {
1673                 Canvas* pCanvas = GetCanvasN();
1674                 if (pCanvas == null || GetLastResult() != E_SUCCESS)
1675                 {
1676                         AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1677
1678                         return;
1679                 }
1680
1681                 pCanvas->Clear();
1682                 __pGallery->SetShowState(true);
1683                 delete pCanvas;
1684         }
1685         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1686 }
1687
1688 void
1689 ImageViewerForm::OnTimerExpired(Timer &timer)
1690 {
1691         int repeatValue = 0;
1692         AppLogDebug("ENTER");
1693         if (__pPresentationModel->GetFileCount() > 1)
1694         {
1695                 __pSettingPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
1696                                 ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
1697
1698                 if (repeatValue == 0)
1699                 {
1700                         __pGallery->StartSlideShow(false);
1701                 }
1702                 else
1703                 {
1704                         __pGallery->StartSlideShow(true);
1705                 }
1706         }
1707         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1708 }
1709
1710 void
1711 ImageViewerForm::OnContentTransferInProgress(RequestId requestId, int totalReceivedSize)
1712 {
1713         AppLogDebug("ENTER");
1714         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1715 }
1716
1717 void
1718 ImageViewerForm::OnContentUploadCompleted(RequestId requestId, result transferResult, const String& errorCode,
1719                 const String& errorMessage)
1720 {
1721         AppLogDebug("ENTER");
1722         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1723 }
1724
1725 void
1726 ImageViewerForm::OnContentDownloadCompleted(RequestId requestId, ContentId contentId,
1727                 result transferResult, const String& errorCode, const String& errorMessage)
1728 {
1729         AppLogDebug("ENTER");
1730         AppLogTag("IV", "ImageViewerForm::OnContentDownloadCompleted");
1731         AppLogTag("IV", "DownloadCompleted Error [%s]", GetErrorMessage(transferResult));
1732         AppLogTag("IV", "errorCode [%ls] errorMessage [%ls]", errorCode.GetPointer(), errorMessage.GetPointer());
1733         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1734 }
1735
1736 void
1737 ImageViewerForm::OnContentDownloadToBufferCompleted(RequestId reqId, ByteBuffer* pBuffer, result r,
1738                 const String& errorCode, const String& errorMessage)
1739 {
1740         AppLogDebug("ENTER");
1741         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1742 }
1743
1744 void
1745 ImageViewerForm::OnContentTransferCanceled(RequestId reqId, result res, const String& errorCode,
1746                 const String& errorMessage)
1747 {
1748         AppLogDebug("ENTER");
1749         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1750 }
1751
1752 void
1753 ImageViewerForm::RequestDecodeUrl(void)
1754 {
1755         AppLogDebug("ENTER");
1756
1757         String filePath = __pPresentationModel->GetFilePathAt(0);
1758
1759         if (filePath.StartsWith(WEB_URL_HTTP, 0) == false)
1760         {
1761                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1762
1763                 return;
1764         }
1765
1766         __downLordFileName = __pPresentationModel->GetFileName(filePath);
1767
1768         Image* pImage = new (std::nothrow) Image();
1769         pImage->Construct();
1770         Uri uri;
1771         RequestId reqId;
1772         uri.SetUri(filePath);
1773
1774         pImage->DecodeUrl(uri, BITMAP_PIXEL_FORMAT_RGB565, 720, 1280, reqId, *this, 5000);
1775
1776         delete pImage;
1777         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1778 }
1779
1780 void
1781 ImageViewerForm::OnImageDecodeUrlReceived (RequestId reqId, Bitmap *pBitmap,
1782                 result r, const String errorCode, const String errorMessage)
1783 {
1784         AppLogDebug("ENTER");
1785         Image* pImage = new (std::nothrow) Image();
1786         pImage->Construct();
1787
1788         String destPath = App::GetInstance()->GetAppRootPath() + TEMP_FILE_PATH_WEB_FILE;
1789         r = pImage->EncodeToFile(*pBitmap, IMG_FORMAT_JPG, destPath, true);
1790
1791         if (r == E_SUCCESS)
1792         {
1793                 __pPresentationModel->GetImageCacheAt(0)->SetFilePath(destPath);
1794                 __pPresentationModel->GetImageCacheAt(0)->SetBitmap(pBitmap);
1795
1796                 __pGallery->RefreshGallery(0, GALLERY_REFRESH_TYPE_ITEM_MODIFY);
1797                 __pGallery->Draw();
1798                 __pPresentationModel->RequestImage(destPath);
1799         }
1800         else
1801         {
1802                 AppLogDebug("ImageViewerForm::OnImageDecodeUrlReceived [%s]", GetErrorMessage(r));
1803         }
1804
1805         delete pImage;
1806         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1807 }
1808
1809 void
1810 ImageViewerForm::OnRequestEmailAction(void)
1811 {
1812         AppLogDebug("ENTER");
1813         int currentIndex = __pGallery->GetCurrentItemIndex();
1814
1815         if (__pPresentationModel->GetFileCount() <= 0)
1816         {
1817                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1818                 return;
1819         }
1820
1821         String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
1822
1823         HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
1824         pDataList->Construct();
1825
1826         IList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1827         pList->Add(new (std::nothrow) String(filePath));
1828
1829         pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pList);
1830
1831         __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_EMAIL, APPCONTROL_OPERATION_ID_COMPOSE,
1832                         null, pDataList, this);
1833         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1834 }
1835
1836 void
1837 ImageViewerForm::OnRequestMessagesAction(void)
1838 {
1839         AppLogDebug("ENTER");
1840         int currentIndex = __pGallery->GetCurrentItemIndex();
1841
1842         if (__pPresentationModel->GetFileCount() <= 0)
1843         {
1844                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1845                 return;
1846         }
1847
1848         String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
1849
1850         HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
1851         pDataList->Construct();
1852         pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_MESSAGE_TYPE),
1853                         new (std::nothrow) String(APPCONTROL_DATA_MMS));
1854
1855         IList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1856         pList->Add(new (std::nothrow) String(filePath));
1857
1858         pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pList);
1859
1860         __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_MESSAGES,
1861                         APPCONTROL_OPERATION_ID_COMPOSE, null, pDataList, this);
1862         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1863 }
1864
1865 void
1866 ImageViewerForm::SetFooterItemState(bool isEnable)
1867 {
1868         AppLogDebug("ENTER");
1869         if (__initializeDisplayModeCurrent == APPCONTROL_MODE_NORMAL)
1870         {
1871                 __pFooter->SetButtonEnabled(BUTTON_POSITION_LEFT, isEnable);
1872                 __pFooter->SetItemEnabled(0, isEnable);
1873                 __pFooter->SetItemEnabled(1, isEnable);
1874         }
1875         else if (__initializeDisplayModeCurrent == APPCONTROL_MODE_WEB_LINK)
1876         {
1877                 __pFooter->SetButtonEnabled(BUTTON_POSITION_LEFT, isEnable);
1878                 __pFooter->SetItemEnabled(0, isEnable);
1879                 __pFooter->SetItemEnabled(1, isEnable);
1880         }
1881         else if (__initializeDisplayModeCurrent == APPCONTROL_MODE_CROP)
1882         {
1883                 __pFooter->SetItemEnabled(0, isEnable);
1884         }
1885         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1886 }
1887
1888 Bitmap*
1889 ImageViewerForm::GetQuickThumbnailN(String& filePath)
1890 {
1891         AppLogDebug("ENTER");
1892         Bitmap* pBitmap = null;
1893
1894         if (filePath.GetLength() > 4)
1895         {
1896                 int totalPage = 0;
1897                 int totalCount = 0;
1898                 ContentSearch contentSearch;
1899                 ContentSearchResult* pResultItem = null;
1900                 IList* pContentInfoList = null;
1901                 String queryString;
1902                 ContentType contentType = ContentManagerUtil::CheckContentType(filePath);
1903                 result r = contentSearch.Construct(contentType);
1904                 AppLogDebug("r(%s)", GetErrorMessage(r));
1905                 if (r != E_SUCCESS)
1906                 {
1907                         pBitmap = new (std::nothrow) Bitmap();
1908                         r = pBitmap->Construct(DUMMY_IMAGE_DIMENSION, BITMAP_PIXEL_FORMAT_RGB565);
1909                         if (r == E_SUCCESS)
1910                         {
1911                                 return pBitmap;
1912                         }
1913                         else
1914                         {
1915                                 delete pBitmap;
1916                                 return null;
1917                         }
1918                 }
1919                 queryString = CONTENT_QUERY_PREFIX_FILENAME;
1920                 queryString.Append(L"'");
1921                 queryString.Append(__pPresentationModel->GetFileName(filePath));
1922                 queryString.Append(L"'");
1923
1924                 pContentInfoList = contentSearch.SearchN(PAGE_NO_CONTENT_SEARCH, COUNT_PER_PAGE_CONTENT_SEARCH,
1925                                 totalPage, totalCount, queryString, EMPTY_SPACE, SORT_ORDER_NONE);
1926
1927                 if ((pContentInfoList != null) && GetLastResult() == E_SUCCESS && (pContentInfoList->GetCount() > 0))
1928                 {
1929                         IEnumerator* pEnum = pContentInfoList->GetEnumeratorN();
1930                         while (pEnum->MoveNext() == E_SUCCESS)
1931                         {
1932                                 pResultItem = static_cast<ContentSearchResult*>(pEnum->GetCurrent());
1933                                 if (pResultItem == null)
1934                                 {
1935                                         continue;
1936                                 }
1937
1938                                 if (pResultItem->GetContentInfo()->GetContentPath().CompareTo(filePath) == 0)
1939                                 {
1940                                         pBitmap = pResultItem->GetContentInfo()->GetThumbnailN();
1941                                 }
1942                         }
1943                         delete pEnum;
1944                 }
1945
1946                 if (pContentInfoList != null)
1947                 {
1948                         delete pContentInfoList;
1949                 }
1950
1951                 if (pBitmap != null)
1952                 {
1953                         ImageViewerMediaType mediaType = CommonUtil::GetMediaType(filePath);
1954
1955                         if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE)
1956                         {
1957                                 ImageBuffer* imageBuffer = new (std::nothrow) ImageBuffer();
1958                                 result r = imageBuffer->Construct(filePath);
1959                                 if (r == E_SUCCESS)
1960                                 {
1961                                         if (imageBuffer->GetExifOrientation() == EXIF_ORIENTATION_RIGHT_TOP
1962                                                 || imageBuffer->GetExifOrientation() == EXIF_ORIENTATION_LEFT_BOTTOM)
1963                                         {
1964                                                 Dimension srcDim(imageBuffer->GetHeight(), imageBuffer->GetWidth());
1965                                                 pBitmap->Scale(srcDim);
1966                                         }
1967                                         else
1968                                         {
1969                                                 Dimension srcDim(imageBuffer->GetWidth(), imageBuffer->GetHeight());
1970                                                 pBitmap->Scale(srcDim);
1971                                         }
1972
1973                                         delete imageBuffer;
1974                                 }
1975                         }
1976                         else if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_VIDEO)
1977                         {
1978                                 VideoMetadata* pVideoMeta = ContentManagerUtil::GetVideoMetaN(filePath);
1979
1980                                 if (pVideoMeta != null && GetLastResult() == E_SUCCESS)
1981                                 {
1982                                         Dimension srcDim(pVideoMeta->GetWidth(), pVideoMeta->GetHeight());
1983                                         pBitmap->Scale(srcDim);
1984                                         delete pVideoMeta;
1985                                 }
1986                         }
1987                 }
1988                 else
1989                 {
1990                         Canvas mainCanvas;
1991                         mainCanvas.Construct(DUMMY_IMAGE_RECTANGLE);
1992                         mainCanvas.FillRectangle(Color::GetColor(COLOR_ID_WHITE), DUMMY_IMAGE_RECTANGLE);
1993                         pBitmap = new (std::nothrow) Bitmap();
1994                         pBitmap->Construct(mainCanvas, DUMMY_IMAGE_RECTANGLE);
1995                 }
1996         }
1997         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1998         return pBitmap;
1999 }
2000
2001 void ImageViewerForm::OnFormFileEventOccuered(const int index, const unsigned long eventId)
2002 {
2003         AppLogDebug(" ENTER");
2004         bool eventDelete = (eventId & FILE_EVENT_TYPE_DELETE_SELF);
2005         bool eventMove = (eventId & 0x8000);// (eventId & FILE_EVENT_TYPE_MOVE_SELF);
2006
2007         int currentIndex = __pGallery->GetCurrentItemIndex();
2008         int countPath = __pPresentationModel->GetFileCount();
2009
2010         if (countPath == 0 && eventDelete)
2011         {
2012                 UiApp* pApp = UiApp::GetInstance();
2013                 pApp->Terminate();
2014                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
2015         }
2016         AppLogDebug(" countPath is %d", countPath);
2017         AppLogDebug(" currentIndex is %d", currentIndex);
2018
2019         if (countPath == currentIndex && eventDelete)
2020         {
2021                 __pGallery->SetCurrentItemIndex(--currentIndex);
2022         }
2023         else if (eventMove)
2024         {
2025                 currentIndex = index;
2026                 __pGallery->SetCurrentItemIndex(currentIndex);
2027         }
2028
2029         String strItemText(EMPTY_SPACE);
2030         String strItemIdxText(EMPTY_SPACE);
2031
2032         __pGallery->UpdateGallery();
2033         AppLogDebug(" UpdateGallery is %d", currentIndex);
2034         String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
2035         __pPresentationModel->RequestImage(filePath);
2036
2037         GetHeaderString(currentIndex, strItemText, strItemIdxText);
2038         __pHeader->SetTitleText(strItemText);
2039         __pHeader->SetDescriptionText(strItemIdxText);
2040
2041         if (__visible == true)
2042         {
2043                 ImageViewerMediaType mediaType = CommonUtil::GetMediaType(filePath);
2044
2045                 if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE)
2046                 {
2047                         __pPlayButton->SetShowState(false);
2048                 }
2049                 else
2050                 {
2051                         __pPlayButton->SetShowState(true);
2052                 }
2053         }
2054         if (__detail == false)
2055         {
2056                 __pScrollPanel->SetShowState(false);
2057                 __detail = true;
2058         }
2059
2060         Invalidate(true);
2061         AppLogDebug("EXIT");
2062 }