Add string CROP
[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(ResourceManager::GetString(L"IDS_IV_BODY_CALLER_IMAGE"),
786                         ACTION_ID_CONTEXTMENU_CALLER);
787         __pContextMenuSetAs->AddActionEventListener(*this);
788         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
789
790         return E_SUCCESS;
791 }
792
793 result
794 ImageViewerForm::InitializeContextMenuShare(void)
795 {
796         AppLogDebug("ENTER");
797         if (__pContextMenuShare != null)
798         {
799                 delete __pContextMenuShare;
800                 __pContextMenuShare = null;
801         }
802         __pContextMenuShare = new (std::nothrow) ContextMenu();
803         __pContextMenuShare->Construct(Point((GetClientAreaBounds().width - (X_MORE * 4)) / 4 + X_MORE * 2,
804                         GetClientAreaBounds().y + GetClientAreaBounds().height), CONTEXT_MENU_STYLE_LIST,
805                         CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD);
806
807         __pContextMenuShare->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_MESSAGE"),
808                         ACTION_ID_CONTEXTMENU_MESSAGE);
809         __pContextMenuShare->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_EMAIL"), ACTION_ID_CONTEXTMENU_EMAIL);
810         __pContextMenuShare->AddActionEventListener(*this);
811         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
812
813         return E_SUCCESS;
814 }
815
816 long long
817 ImageViewerForm::GetFileSize(String filePath)
818 {
819         AppLogDebug("ENTER");
820         FileAttributes attr;
821         long long size = 0;
822
823         result r = File::GetAttributes(filePath, attr);
824         if (r != E_SUCCESS)
825         {
826                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
827
828                 return 0;
829         }
830         size = attr.GetFileSize();
831         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
832
833         return size;
834 }
835
836 result
837 ImageViewerForm::SetDetailInfo(void)
838 {
839         AppLogDebug("ENTER");
840
841         Rectangle clientRect = GetClientAreaBounds();
842         __pScrollPanel->SetBounds(0, 0, clientRect.width, clientRect.height);
843
844         int currentIndex = __pGallery->GetCurrentItemIndex();
845         String strFilePath = __pPresentationModel->GetFilePathAt(currentIndex);
846
847         ImageViewerMediaType mediaType = CommonUtil::GetMediaType(strFilePath);
848
849         String strResult[DETAIL_COUNT_MAX] = {EMPTY_SPACE, };
850
851         strResult[0] = __pPresentationModel->GetFileName(strFilePath);
852         strResult[1] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
853
854         FileAttributes attr;
855         result r = File::GetAttributes(strFilePath, attr);
856         if (r == E_SUCCESS)
857         {
858                 long long nSize = attr.GetFileSize();
859                 DateTime dateTime = attr.GetDateTime();
860                 strResult[2] = dateTime.ToString();
861
862                 if (nSize > SINGLE_GIGA_BYTE)
863                 {
864                         strResult[3].Format(FORMAT_BUFFER_SIZE, L"%lld ", nSize / SINGLE_GIGA_BYTE);
865                         strResult[3].Append(ResourceManager::GetString(L"IDS_COM_BODY_GB"));
866                 }
867                 else if (nSize > SINGLE_MEGA_BYTE)
868                 {
869                         strResult[3].Format(FORMAT_BUFFER_SIZE, L"%lld ", nSize / SINGLE_MEGA_BYTE);
870                         strResult[3].Append(ResourceManager::GetString(L"IDS_COM_BODY_MB"));
871                 }
872                 else if (nSize > SINGLE_KILO_BYTE)
873                 {
874                         strResult[3].Format(FORMAT_BUFFER_SIZE, L"%lld ", nSize / SINGLE_KILO_BYTE);
875                         strResult[3].Append(ResourceManager::GetString(L"IDS_COM_BODY_KB"));
876                 }
877                 else
878                 {
879                         strResult[3].Format(FORMAT_BUFFER_SIZE, L"%lld ", nSize);
880                         strResult[3].Append(ResourceManager::GetString(L"IDS_COM_BODY_B"));
881                 }
882         }
883         else
884         {
885                 strResult[2] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
886                 strResult[3] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
887         }
888
889         strResult[4] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
890         strResult[5] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
891         strResult[6] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
892         strResult[7] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
893         strResult[8] = strFilePath;
894         String fileName = File::GetFileName(strFilePath);
895         strResult[8].Remove(strResult[8].GetLength() - fileName.GetLength(), fileName.GetLength());
896
897         if (__initializeDisplayModeCurrent == APPCONTROL_MODE_WEB_LINK)
898         {
899                 strResult[0] = __downLordFileName;
900         }
901         else if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE)
902         {
903                 ImageMetadata* pImgMeta = ContentManagerUtil::GetImageMetaN(strFilePath);
904
905                 if (pImgMeta != null)
906                 {
907                         ImageContentInfo imageContentInfo;
908                         r = imageContentInfo.Construct(&strFilePath);
909                         if (r == E_SUCCESS)
910                         {
911                                 strResult[1] = imageContentInfo.GetMediaFormat();
912                                 strResult[4].Format(FORMAT_BUFFER_SIZE, L"%d x %d", pImgMeta->GetWidth(),
913                                                 pImgMeta->GetHeight());
914
915                                 if (imageContentInfo.GetLocationTag() != EMPTY_SPACE)
916                                 {
917                                         strResult[5].Format(FORMAT_BUFFER_SIZE, L"%ls", imageContentInfo.GetLocationTag().GetPointer());
918                                 }
919
920                                 if (pImgMeta->GetLatitude() > 1.0 && pImgMeta->GetLongitude() > 1.0)
921                                 {
922                                         strResult[6].Format(FORMAT_BUFFER_SIZE, L"%f", pImgMeta->GetLatitude());
923                                         strResult[7].Format(FORMAT_BUFFER_SIZE, L"%f", pImgMeta->GetLongitude());
924                                 }
925                         }
926                         delete pImgMeta;
927                 }
928         }
929         else if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_VIDEO)
930         {
931                 VideoMetadata* pVideoMeta = ContentManagerUtil::GetVideoMetaN(strFilePath);
932                 if (pVideoMeta != null)
933                 {
934                         VideoContentInfo videoContentInfo;
935                         r = videoContentInfo.Construct(&strFilePath);
936                         if (r == E_SUCCESS)
937                         {
938                                 strResult[1] = videoContentInfo.GetMediaFormat();
939                                 strResult[4].Format(FORMAT_BUFFER_SIZE, L"%d x %d", pVideoMeta->GetWidth(),
940                                                 pVideoMeta->GetHeight());
941                                 if (videoContentInfo.GetLocationTag() != EMPTY_SPACE)
942                                 {
943                                         strResult[5].Format(FORMAT_BUFFER_SIZE, L"%ls", videoContentInfo.GetLocationTag().GetPointer());
944                                 }
945                         }
946                 }
947         }
948
949         for (int i = 0; i < DETAIL_COUNT_MAX; ++i)
950         {
951                 __pDetail_FileInfo_Value_Label[i]->SetText(strResult[i]);
952                 __pDetail_FileInfo_Value_Label[i]->RequestRedraw();
953         }
954
955         if (__initializeDisplayModeCurrent == APPCONTROL_MODE_WEB_LINK)
956         {
957                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
958                 return r;
959         }
960
961                 Rectangle rect = GetBounds();
962                 __pRenameButton->SetBounds(Rectangle(rect.width - W_RENAME_BUTTON - 20, Y_RENAME_BUTTON, W_RENAME_BUTTON, H_RENAME_BUTTON));
963
964         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
965
966         return r;
967 }
968
969 result
970 ImageViewerForm::ShowPanelDetail(bool showStatus)
971 {
972         AppLogDebug("ENTER");
973         if (showStatus)
974         {
975                 SetDetailInfo();
976                 __pScrollPanel->SetShowState(true);
977                 __detail = false;
978         }
979         else
980         {
981                 __pScrollPanel->SetShowState(false);
982                 __detail = true;
983         }
984         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
985
986         return E_SUCCESS;
987 }
988
989 result
990 ImageViewerForm::ChangeFooterItem(bool isChanged, Footer* pFooter, int position)
991 {
992         AppLogDebug("ENTER");
993         FooterItem footerItem;
994         footerItem.Construct(ACTION_ID_FOOTER_BUTTON_DETAILS);
995         Bitmap* pfooterItem = null;
996
997         if (isChanged)
998         {
999                 pfooterItem = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_DETAILS_CLOSE);
1000                 footerItem.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pfooterItem);
1001         }
1002         else
1003         {
1004                 pfooterItem = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_DETAILS);
1005                 footerItem.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pfooterItem);
1006         }
1007
1008         pFooter->SetItemAt(position, footerItem);
1009         pFooter->Invalidate(true);
1010
1011         delete pfooterItem;
1012         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1013
1014         return E_SUCCESS;
1015 }
1016
1017 void
1018 ImageViewerForm::DownloadFile(void)
1019 {
1020         AppLogDebug("ENTER");
1021         String DestPath = App::GetInstance()->GetAppRootPath() + TEMP_FILE_PATH_WEB_FILE;
1022         if (File::IsFileExist(DestPath) == false)
1023         {
1024                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1025                 return;
1026         }
1027
1028         ContentId contentId;
1029         ContentManager contentManager;
1030         contentManager.Construct();
1031
1032         ImageContentInfo imageContentInfo;
1033         imageContentInfo.Construct(null);
1034
1035         imageContentInfo.SetKeyword(L"platform, tizen");
1036         String sourcePath = DestPath;
1037         String destPath = Environment::GetMediaPath();
1038         destPath.Append(FOLDER_PATH_DOWNLOADS);
1039         destPath.Append(__downLordFileName);
1040
1041         contentId = contentManager.CreateContent(sourcePath, destPath, true, &imageContentInfo);
1042         ImageViewerForm::OnFormBackRequested(*this);
1043         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1044 }
1045
1046 int
1047 ImageViewerForm::GetItemCount(void)
1048 {
1049         AppLogDebug("ENTER");
1050         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1051
1052         return __pPresentationModel->GetFileCount();
1053 }
1054
1055 GalleryItem*
1056 ImageViewerForm::CreateItem(int index)
1057 {
1058         AppLogDebug("ENTER : index(%d)", index);
1059         GalleryItem* pGallery = new (std::nothrow) GalleryItem();
1060
1061         String filePath = __pPresentationModel->GetFilePathAt(index);
1062         ImageInfo* pImageInfo = __pPresentationModel->GetImageCacheAt(index);
1063         Bitmap* pBitmap = pImageInfo->GetBitmapN();
1064         if (pBitmap == null)
1065         {
1066                 pBitmap = GetQuickThumbnailN(filePath);
1067
1068                 if (pBitmap == null)
1069                 {
1070                         pBitmap = new (std::nothrow) Bitmap();
1071                         pBitmap->Construct(DUMMY_IMAGE_DIMENSION, BITMAP_PIXEL_FORMAT_RGB565);
1072                 }
1073         }
1074         pGallery->Construct(*pBitmap, filePath);
1075         delete pBitmap;
1076         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1077
1078         return pGallery;
1079 }
1080
1081 bool
1082 ImageViewerForm::DeleteItem(int index, GalleryItem* pItem)
1083 {
1084         AppLogDebug("ENTER index(%d)", index);
1085         ImageInfo* pImageInfo = __pPresentationModel->GetImageCacheAt(index);
1086         pImageInfo->ClearBitmap();
1087         delete pItem;
1088         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1089
1090         return true;
1091 }
1092
1093 void
1094 ImageViewerForm::OnGalleryCurrentItemChanged(Gallery& view, int index)
1095 {
1096         AppLogDebug("ENTER index(%d)", index);
1097
1098         String filePath = __pPresentationModel->GetFilePathAt(index);
1099         AppLogDebug("ENTER index(%d) filePath(%ls)", index, filePath.GetPointer());
1100         __pPresentationModel->RequestImage(filePath);
1101
1102         String strItemText;
1103         String strItemIdxText;
1104         GetHeaderString(__pGallery->GetCurrentItemIndex(), strItemText, strItemIdxText);
1105         __pHeader->SetTitleText(strItemText);
1106         __pHeader->SetDescriptionText(strItemIdxText);
1107
1108         if (__visible == true)
1109         {
1110                 ImageViewerMediaType mediaType = CommonUtil::GetMediaType(filePath);
1111                 if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_VIDEO)
1112                 {
1113                         __pPlayButton->SetShowState(true);
1114                 }
1115                 else
1116                 {
1117                         __pPlayButton->SetShowState(false);
1118                 }
1119         }
1120
1121         Invalidate(true);
1122         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1123 }
1124
1125 void
1126 ImageViewerForm::OnGalleryItemClicked(Gallery& view, int index)
1127 {
1128         AppLogDebug("ENTER");
1129
1130         String filePath = __pPresentationModel->GetFilePathAt(index);
1131         ContentType contentType = ContentManagerUtil::CheckContentType(filePath);
1132
1133         if (__visible == true)
1134         {
1135                 if (contentType == CONTENT_TYPE_VIDEO)
1136                 {
1137                         __pPlayButton->SetShowState(false);
1138                 }
1139
1140                 SetActionBarsVisible(FORM_ACTION_BAR_INDICATOR | FORM_ACTION_BAR_HEADER | FORM_ACTION_BAR_FOOTER, false);
1141                 __visible = false;
1142         }
1143         else
1144         {
1145                 if (contentType == CONTENT_TYPE_VIDEO)
1146                 {
1147                         __pPlayButton->SetShowState(true);
1148                 }
1149
1150                 SetActionBarsVisible(FORM_ACTION_BAR_INDICATOR | FORM_ACTION_BAR_HEADER | FORM_ACTION_BAR_FOOTER, true);
1151                 __visible = true;
1152
1153                 __pPlayButton->SetPosition(__pPlayButton->GetPosition().x, __pPlayButton->GetPosition().y - 1);
1154                 __pPlayButton->SetPosition(__pPlayButton->GetPosition().x, __pPlayButton->GetPosition().y + 1);
1155         }
1156
1157         Rectangle clientRect = GetClientAreaBounds();
1158         Rectangle rect = GetBounds();
1159         __pGallery->SetBounds(Rectangle(0, -clientRect.y, rect.width, rect.height));
1160         Invalidate(true);
1161         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1162 }
1163
1164 void
1165 ImageViewerForm::OnGallerySlideShowStarted(Gallery& gallery)
1166 {
1167         AppLogDebug("ENTER");
1168         PowerManager::KeepScreenOnState(true, false);
1169         if (__visible  == true)
1170         {
1171                 SetActionBarsVisible(FORM_ACTION_BAR_INDICATOR | FORM_ACTION_BAR_HEADER | FORM_ACTION_BAR_FOOTER, false);
1172
1173                 int index = __pGallery->GetCurrentItemIndex();
1174                 String filePath = __pPresentationModel->GetFilePathAt(index);
1175                 ContentType contentType = ContentManagerUtil::CheckContentType(filePath);
1176
1177                 if (contentType == CONTENT_TYPE_VIDEO)
1178                 {
1179                         __pPlayButton->SetShowState(false);
1180                 }
1181
1182                 __visible = false;
1183         }
1184
1185         Rectangle clientRect = GetClientAreaBounds();
1186         Rectangle rect = GetBounds();
1187         __pGallery->SetBounds(Rectangle(0, -clientRect.y, rect.width, rect.height));
1188         Invalidate(true);
1189         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1190 }
1191
1192 void
1193 ImageViewerForm::OnGallerySlideShowStopped(Gallery& gallery)
1194 {
1195         AppLogDebug("ENTER");
1196         PowerManager::KeepScreenOnState(false, true);
1197         int index = __pGallery->GetCurrentItemIndex();
1198
1199         if (__visible == false)
1200         {
1201                 SetActionBarsVisible(FORM_ACTION_BAR_INDICATOR | FORM_ACTION_BAR_HEADER | FORM_ACTION_BAR_FOOTER, true);
1202
1203                 String filePath = __pPresentationModel->GetFilePathAt(index);
1204                 ContentType contentType = ContentManagerUtil::CheckContentType(filePath);
1205                 if (contentType == CONTENT_TYPE_VIDEO)
1206                 {
1207                         __pPlayButton->SetShowState(true);
1208                 }
1209
1210                 __pPlayButton->SetPosition(__pPlayButton->GetPosition().x, __pPlayButton->GetPosition().y - 1);
1211                 __pPlayButton->SetPosition(__pPlayButton->GetPosition().x, __pPlayButton->GetPosition().y + 1);
1212
1213                 __visible = true;
1214         }
1215
1216         String strItemText;
1217         String strItemIdxText;
1218         GetHeaderString(index, strItemText, strItemIdxText);
1219         __pHeader->SetTitleText(strItemText);
1220         __pHeader->SetDescriptionText(strItemIdxText);
1221
1222         Rectangle clientRect = GetClientAreaBounds();
1223         Rectangle rect = GetBounds();
1224         __pGallery->SetBounds(Rectangle(0, -clientRect.y, rect.width, rect.height));
1225
1226         Invalidate(true);
1227         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1228 }
1229
1230 void
1231 ImageViewerForm::OnUpdateContentList(void)
1232 {
1233 }
1234
1235 result
1236 ImageViewerForm::OnTerminating(void)
1237 {
1238         AppLogDebug("ENTER");
1239
1240         if (__pTimer != null)
1241         {
1242                 __pTimer->Cancel();
1243                 delete __pTimer;
1244                 __pTimer = null;
1245         }
1246
1247         __pPresentationModel->ClearImageRequests();
1248         __pPresentationModel->RemoveListener(*this);
1249         __pPresentationModel->RemoveFileUpdateListener(*this);
1250
1251         if (__pContextMenuCopy != null)
1252         {
1253                 delete __pContextMenuCopy;
1254                 __pContextMenuCopy = null;
1255         }
1256
1257         if (__pContextMenuSetAs != null)
1258         {
1259                 delete __pContextMenuSetAs;
1260                 __pContextMenuSetAs = null;
1261         }
1262
1263         if (__pDeletePopup != null)
1264         {
1265                 delete __pDeletePopup;
1266                 __pDeletePopup = null;
1267         }
1268
1269         if (__pContextMenuShare != null)
1270         {
1271                 delete __pContextMenuShare;
1272                 __pContextMenuShare = null;
1273         }
1274
1275         if (__pContextMenuMore != null)
1276         {
1277                 delete __pContextMenuMore;
1278                 __pContextMenuMore = null;
1279         }
1280
1281         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1282
1283         return E_SUCCESS;
1284 }
1285
1286 void
1287 ImageViewerForm::OnActionPerformed(const Control& source, int actionId)
1288 {
1289         AppLogDebug("ENTER actionId(%d)", actionId);
1290         SceneManager* pSceneManager = SceneManager::GetInstance();
1291         InitShowGallery();
1292
1293         switch (actionId)
1294         {
1295         case ACTION_ID_FOOTER_MORE:
1296         {
1297                 InitializeContextMenuMore();
1298
1299                 __pContextMenuMore->SetShowState(true);
1300                 __pContextMenuMore->Show();
1301         }
1302         break;
1303         case ACTION_ID_CONTEXTMENU_SET_AS:
1304                 InitializeContextMenuSetAs();
1305
1306                 __pContextMenuSetAs->SetShowState(true);
1307                 __pContextMenuSetAs->Show();
1308                 break;
1309         case ACTION_ID_FOOTER_BUTTON_SHARE:
1310                 InitializeContextMenuShare();
1311
1312                 __pContextMenuShare->SetShowState(true);
1313                 __pContextMenuShare->Show();
1314                 break;
1315         case ACTION_ID_FOOTER_BUTTON_DELETE:
1316                 __pDeletePopup->SetShowState(true);
1317                 __pDeletePopup->Show();
1318                 break;
1319         case ACTION_ID_FOOTER_BUTTON_SLIDE:
1320         {
1321                 int repeatValue = 0;
1322
1323                 if (__pPresentationModel->GetFileCount() > 1)
1324                 {
1325                         __pGallery->UpdateGallery();
1326                         if (__detail == false)
1327                         {
1328                                 ShowPanelDetail(false);
1329                         }
1330
1331                         __pSettingPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
1332                                         ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
1333
1334                         if (repeatValue == 0)
1335                         {
1336                                 __pGallery->StartSlideShow(false);
1337                         }
1338                         else
1339                         {
1340                                 __pGallery->StartSlideShow(true);
1341                         }
1342                 }
1343                 break;
1344         }
1345         case ACTION_ID_FOOTER_BUTTON_CROP:
1346         {
1347                 String filePath;
1348                 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1349                 filePath = __pPresentationModel->GetFilePathAt(__pGallery->GetCurrentItemIndex());
1350                 pList->Add(new (std::nothrow) String(filePath));
1351                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_CROP), pList);
1352         }
1353         break;
1354         case ACTION_ID_FOOTER_BUTTON_DETAILS:
1355         {
1356                 ShowPanelDetail(__detail);
1357                 break;
1358         }
1359         case ACTION_ID_FOOTER_BUTTON_BACK:
1360                 ImageViewerForm::OnFormBackRequested(*this);
1361                 break;
1362         case ACTION_ID_FOOTER_BUTTON_DOWNLOAD:
1363                 DownloadFile();
1364                 break;
1365         case ACTION_ID_FOOTER_BUTTON_SAVE:
1366                 break;
1367         case ACTION_ID_PANEL_HEADER_DETAILS_RENAME:
1368         {
1369                 ArrayList* pSelectedIndex = new (std::nothrow) ArrayList(SingleObjectDeleter);
1370                 pSelectedIndex->Construct();
1371                 pSelectedIndex->Add(new (std::nothrow) Integer(__pGallery->GetCurrentItemIndex()));
1372                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_NAME_EDITOR), pSelectedIndex);
1373                 break;
1374         }
1375         case ACTION_ID_CONTEXTMENU_HOME:
1376         {
1377                 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1378                 pList->Add(new (std::nothrow) Integer(__pGallery->GetCurrentItemIndex()));
1379                 pList->Add(new (std::nothrow) Integer(SET_AT_TYPE_HOME_SCREEN_WALLPAPER));
1380                 __pPresentationModel->SetSetterIndex(__pGallery->GetCurrentItemIndex());
1381                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_SETTER), pList);
1382                 break;
1383         }
1384         case ACTION_ID_CONTEXTMENU_LOCK:
1385         {
1386                 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1387                 pList->Add(new (std::nothrow) Integer(__pGallery->GetCurrentItemIndex()));
1388                 pList->Add(new (std::nothrow) Integer(SET_AT_TYPE_LOCK_SCREEN_WALLPAPER));
1389                 __pPresentationModel->SetSetterIndex(__pGallery->GetCurrentItemIndex());
1390                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_SETTER), pList);
1391                 break;
1392         }
1393         case ACTION_ID_CONTEXTMENU_CALLER:
1394         {
1395                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
1396                 pDataList->Construct();
1397                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_SELECTION_MODE),
1398                                 new (std::nothrow) String(APPCONTROL_DATA_SINGLE));
1399                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_SOCIAL_ITEM_TYPE),
1400                                 new (std::nothrow) String(APPCONTROL_DATA_PERSON));
1401                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_SOCIAL_RESULT_TYPE),
1402                                 new (std::nothrow) String(APPCONTROL_DATA_ITEM_ID));
1403
1404                 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_CONTACTS,
1405                                 APPCONTROL_OPERATION_ID_PICK, null, pDataList, this);
1406                 break;
1407         }
1408         case ACTION_ID_CONTEXTMENU_EMAIL:
1409         {
1410                 OnRequestEmailAction();
1411                 break;
1412         }
1413         case ACTION_ID_CONTEXTMENU_MESSAGE:
1414         {
1415                 OnRequestMessagesAction();
1416                 break;
1417         }
1418         case ACTION_ID_CONTEXTMENU_COPY:
1419         {
1420                 int currentIndex = __pGallery->GetCurrentItemIndex();
1421                 String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
1422
1423                 ClipboardItem item;
1424                 item.Construct(CLIPBOARD_DATA_TYPE_IMAGE, filePath);
1425                 Clipboard* pClipboard = Clipboard::GetInstance();
1426                 pClipboard->CopyItem(item);
1427                 break;
1428         }
1429         case ACTION_ID_DELETE_POPUP_DEL:
1430         {
1431                 __pDeletePopup->SetShowState(false);
1432                 __pDeletePopup->Show();
1433                 DeleteImageFile();
1434
1435                 if (__detail == false)
1436                 {
1437                         ShowPanelDetail(false);
1438                 }
1439                 break;
1440         }
1441         case ACTION_ID_DELETE_POPUP_CANCEL:
1442         {
1443                 __pDeletePopup->SetShowState(false);
1444                 __pDeletePopup->Show();
1445                 break;
1446         }
1447         case ACTION_ID_CONTORL_BUTTON_PLAY:
1448                 CallVideoPlayer();
1449                 break;
1450         default:
1451                 break;
1452         }
1453         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1454 }
1455
1456 void
1457 ImageViewerForm::OnFormBackRequested(Form& source)
1458 {
1459         AppLogDebug("ENTER");
1460         if (__detail == false)
1461         {
1462                 ShowPanelDetail(false);
1463         }
1464         else
1465         {
1466                 UiApp* pApp = UiApp::GetInstance();
1467                 pApp->Terminate();
1468         }
1469         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1470 }
1471
1472 void
1473 ImageViewerForm::OnSceneActivatedN(const SceneId& previousSceneId,
1474                 const SceneId& currentSceneId, IList* pArgs)
1475 {
1476         AppLogDebug("ENTER");
1477
1478         Rectangle clientRect = GetClientAreaBounds();
1479         Rectangle rect = GetBounds();
1480
1481         __pGallery->SetBounds(Rectangle(0, -clientRect.y, rect.width, rect.height));
1482         __pScrollPanel->SetBounds(Rectangle(0, 0, clientRect.width, clientRect.height));
1483         __pPlayButton->SetBounds(Rectangle(clientRect.width / 2 - 80, clientRect.height / 2 - 80, 160, 160));
1484
1485         if (previousSceneId == IDSCN_IMAGE_NAME_EDITOR && currentSceneId == IDSCN_IMAGE_VIEWER)
1486         {
1487                 SetDetailInfo();
1488                 String strItemText(EMPTY_SPACE);
1489                 String strItemIdxText(EMPTY_SPACE);
1490                 GetHeaderString(__pGallery->GetCurrentItemIndex(), strItemText, strItemIdxText);
1491                 __pHeader->SetTitleText(strItemText);
1492                 __pHeader->SetDescriptionText(strItemIdxText);
1493                 Invalidate(true);
1494         }
1495
1496         if (__pGallery->GetCurrentItemIndex() < 0)
1497         {
1498                 SetFooterItemState(false);
1499         }
1500         else
1501         {
1502                 SetFooterItemState(true);
1503         }
1504         Invalidate(true);
1505         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1506 }
1507
1508 void
1509 ImageViewerForm::OnSceneDeactivated(const SceneId& currentSceneId,
1510                 const SceneId& nextSceneId)
1511 {
1512         AppLogDebug("ENTER");
1513         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1514 }
1515
1516 void
1517 ImageViewerForm::OnImageDecodedN(const int index)
1518 {
1519         AppLogDebug("ENTER");
1520         __pGallery->RefreshGallery(index, GALLERY_REFRESH_TYPE_ITEM_MODIFY);
1521         __pGallery->Draw();
1522         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1523 }
1524
1525 void
1526 ImageViewerForm::OnAppControlCompleteResponseReceived(const AppId& appId,
1527                 const String& operationId, AppCtrlResult appControlResult,
1528                 const IMap* pExtraData)
1529 {
1530         AppLogDebug("ENTER");
1531
1532         if (appId == APPCONTROL_PROVIDER_ID_CONTACTS
1533                         && operationId == APPCONTROL_OPERATION_ID_PICK
1534                         && appControlResult == APP_CTRL_RESULT_SUCCEEDED)
1535         {
1536                 const String* pContactId =
1537                                 static_cast<const String*>(pExtraData->GetValue(String(APPCONTROL_KEY_SOCIAL_ITEM_ID)));
1538                 SceneManager* pSceneManager = SceneManager::GetInstance();
1539                 long long lresult = 0;
1540                 if (pContactId != null && pContactId->GetLength() > 0)
1541                 {
1542                         LongLong::Parse(*pContactId, lresult);
1543                 }
1544                 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1545                 pList->Add(new (std::nothrow) Integer(__pGallery->GetCurrentItemIndex()));
1546                 pList->Add(new (std::nothrow) Integer(SET_AT_TYPE_CALLER_IMAGE));
1547                 pList->Add(new (std::nothrow) LongLong(lresult));
1548                 __pPresentationModel->SetSetterIndex(__pGallery->GetCurrentItemIndex());
1549                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_SETTER), pList);
1550         }
1551
1552         ImageViewerApp* pImageViewerApp = static_cast<ImageViewerApp*>(ImageViewerApp::GetInstance());
1553         pImageViewerApp->SetFrameEnabled(true);
1554         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1555 }
1556
1557 void
1558 ImageViewerForm::OnOverlayControlCreated(const Control& source)
1559 {
1560         AppLogDebug("ENTER");
1561         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1562 }
1563
1564 void
1565 ImageViewerForm::OnOverlayControlOpened(const Control& source)
1566 {
1567         AppLogDebug("ENTER");
1568         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1569 }
1570
1571 void
1572 ImageViewerForm::OnOverlayControlClosed(const Control& source)
1573 {
1574         AppLogDebug("ENTER");
1575         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1576 }
1577
1578 void
1579 ImageViewerForm::OnOtherControlSelected(const Control& source)
1580 {
1581         AppLogDebug("ENTER");
1582         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1583 }
1584
1585 void
1586 ImageViewerForm::InitShowGallery(void)
1587 {
1588         AppLogDebug("ENTER");
1589         if (__pGallery != null && __pGallery->IsVisible() == false)
1590         {
1591                 Canvas* pCanvas = GetCanvasN();
1592                 if (pCanvas == null || GetLastResult() != E_SUCCESS)
1593                 {
1594                         AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1595
1596                         return;
1597                 }
1598
1599                 pCanvas->Clear();
1600                 __pGallery->SetShowState(true);
1601                 delete pCanvas;
1602         }
1603         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1604 }
1605
1606 void
1607 ImageViewerForm::OnTimerExpired(Timer &timer)
1608 {
1609         int repeatValue = 0;
1610         AppLogDebug("ENTER");
1611         if (__pPresentationModel->GetFileCount() > 1)
1612         {
1613                 __pSettingPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
1614                                 ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
1615
1616                 if (repeatValue == 0)
1617                 {
1618                         __pGallery->StartSlideShow(false);
1619                 }
1620                 else
1621                 {
1622                         __pGallery->StartSlideShow(true);
1623                 }
1624         }
1625         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1626 }
1627
1628 void
1629 ImageViewerForm::OnContentTransferInProgress(RequestId requestId, int totalReceivedSize)
1630 {
1631         AppLogDebug("ENTER");
1632         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1633 }
1634
1635 void
1636 ImageViewerForm::OnContentUploadCompleted(RequestId requestId, result transferResult, const String& errorCode,
1637                 const String& errorMessage)
1638 {
1639         AppLogDebug("ENTER");
1640         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1641 }
1642
1643 void
1644 ImageViewerForm::OnContentDownloadCompleted(RequestId requestId, ContentId contentId,
1645                 result transferResult, const String& errorCode, const String& errorMessage)
1646 {
1647         AppLogDebug("ENTER");
1648         AppLogTag("IV", "ImageViewerForm::OnContentDownloadCompleted");
1649         AppLogTag("IV", "DownloadCompleted Error [%s]", GetErrorMessage(transferResult));
1650         AppLogTag("IV", "errorCode [%ls] errorMessage [%ls]", errorCode.GetPointer(), errorMessage.GetPointer());
1651         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1652 }
1653
1654 void
1655 ImageViewerForm::OnContentDownloadToBufferCompleted(RequestId reqId, ByteBuffer* pBuffer, result r,
1656                 const String& errorCode, const String& errorMessage)
1657 {
1658         AppLogDebug("ENTER");
1659         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1660 }
1661
1662 void
1663 ImageViewerForm::OnContentTransferCanceled(RequestId reqId, result res, const String& errorCode,
1664                 const String& errorMessage)
1665 {
1666         AppLogDebug("ENTER");
1667         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1668 }
1669
1670 void
1671 ImageViewerForm::RequestDecodeUrl(void)
1672 {
1673         AppLogDebug("ENTER");
1674
1675         String filePath = __pPresentationModel->GetFilePathAt(0);
1676
1677         if (filePath.StartsWith(WEB_URL_HTTP, 0) == false)
1678         {
1679                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1680
1681                 return;
1682         }
1683
1684         __downLordFileName = __pPresentationModel->GetFileName(filePath);
1685
1686         Image* pImage = new (std::nothrow) Image();
1687         pImage->Construct();
1688         Uri uri;
1689         RequestId reqId;
1690         uri.SetUri(filePath);
1691
1692         pImage->DecodeUrl(uri, BITMAP_PIXEL_FORMAT_RGB565, 720, 1280, reqId, *this, 5000);
1693
1694         delete pImage;
1695         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1696 }
1697
1698 void
1699 ImageViewerForm::OnImageDecodeUrlReceived (RequestId reqId, Bitmap *pBitmap,
1700                 result r, const String errorCode, const String errorMessage)
1701 {
1702         AppLogDebug("ENTER");
1703         Image* pImage = new (std::nothrow) Image();
1704         pImage->Construct();
1705
1706         String destPath = App::GetInstance()->GetAppRootPath() + TEMP_FILE_PATH_WEB_FILE;
1707         r = pImage->EncodeToFile(*pBitmap, IMG_FORMAT_JPG, destPath, true);
1708
1709         if (r == E_SUCCESS)
1710         {
1711                 __pPresentationModel->GetImageCacheAt(0)->SetFilePath(destPath);
1712                 __pPresentationModel->GetImageCacheAt(0)->SetBitmap(pBitmap);
1713
1714                 __pGallery->RefreshGallery(0, GALLERY_REFRESH_TYPE_ITEM_MODIFY);
1715                 __pGallery->Draw();
1716                 __pPresentationModel->RequestImage(destPath);
1717         }
1718         else
1719         {
1720                 AppLogDebug("ImageViewerForm::OnImageDecodeUrlReceived [%s]", GetErrorMessage(r));
1721         }
1722
1723         delete pImage;
1724         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1725 }
1726
1727 void
1728 ImageViewerForm::OnRequestEmailAction(void)
1729 {
1730         AppLogDebug("ENTER");
1731         int currentIndex = __pGallery->GetCurrentItemIndex();
1732
1733         if (__pPresentationModel->GetFileCount() <= 0)
1734         {
1735                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1736                 return;
1737         }
1738
1739         String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
1740
1741         HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
1742         pDataList->Construct();
1743
1744         IList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1745         pList->Add(new (std::nothrow) String(filePath));
1746
1747         pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pList);
1748
1749         __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_EMAIL, APPCONTROL_OPERATION_ID_COMPOSE,
1750                         null, pDataList, this);
1751         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1752 }
1753
1754 void
1755 ImageViewerForm::OnRequestMessagesAction(void)
1756 {
1757         AppLogDebug("ENTER");
1758         int currentIndex = __pGallery->GetCurrentItemIndex();
1759
1760         if (__pPresentationModel->GetFileCount() <= 0)
1761         {
1762                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1763                 return;
1764         }
1765
1766         String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
1767
1768         HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
1769         pDataList->Construct();
1770         pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_MESSAGE_TYPE),
1771                         new (std::nothrow) String(APPCONTROL_DATA_MMS));
1772
1773         IList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1774         pList->Add(new (std::nothrow) String(filePath));
1775
1776         pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_PATH), (Object*)pList);
1777
1778         __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_MESSAGES,
1779                         APPCONTROL_OPERATION_ID_COMPOSE, null, pDataList, this);
1780         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1781 }
1782
1783 void
1784 ImageViewerForm::SetFooterItemState(bool isEnable)
1785 {
1786         AppLogDebug("ENTER");
1787         if (__initializeDisplayModeCurrent == APPCONTROL_MODE_NORMAL)
1788         {
1789                 __pFooter->SetButtonEnabled(BUTTON_POSITION_LEFT, isEnable);
1790                 __pFooter->SetItemEnabled(0, isEnable);
1791                 __pFooter->SetItemEnabled(1, isEnable);
1792         }
1793         else if (__initializeDisplayModeCurrent == APPCONTROL_MODE_WEB_LINK)
1794         {
1795                 __pFooter->SetButtonEnabled(BUTTON_POSITION_LEFT, isEnable);
1796                 __pFooter->SetItemEnabled(0, isEnable);
1797                 __pFooter->SetItemEnabled(1, isEnable);
1798         }
1799         else if (__initializeDisplayModeCurrent == APPCONTROL_MODE_CROP)
1800         {
1801                 __pFooter->SetItemEnabled(0, isEnable);
1802         }
1803         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1804 }
1805
1806 Bitmap*
1807 ImageViewerForm::GetQuickThumbnailN(String& filePath)
1808 {
1809         AppLogDebug("ENTER");
1810         Bitmap* pBitmap = null;
1811
1812         if (filePath.GetLength() > 4)
1813         {
1814                 int totalPage = 0;
1815                 int totalCount = 0;
1816                 ContentSearch contentSearch;
1817                 ContentSearchResult* pResultItem = null;
1818                 IList* pContentInfoList = null;
1819                 String queryString;
1820                 ContentType contentType = ContentManagerUtil::CheckContentType(filePath);
1821                 result r = contentSearch.Construct(contentType);
1822                 AppLogDebug("r(%s)", GetErrorMessage(r));
1823                 if (r != E_SUCCESS)
1824                 {
1825                         pBitmap = new (std::nothrow) Bitmap();
1826                         r = pBitmap->Construct(DUMMY_IMAGE_DIMENSION, BITMAP_PIXEL_FORMAT_RGB565);
1827                         if (r == E_SUCCESS)
1828                         {
1829                                 return pBitmap;
1830                         }
1831                         else
1832                         {
1833                                 delete pBitmap;
1834                                 return null;
1835                         }
1836                 }
1837                 queryString = CONTENT_QUERY_PREFIX_FILENAME;
1838                 queryString.Append(L"'");
1839                 queryString.Append(__pPresentationModel->GetFileName(filePath));
1840                 queryString.Append(L"'");
1841
1842                 pContentInfoList = contentSearch.SearchN(PAGE_NO_CONTENT_SEARCH, COUNT_PER_PAGE_CONTENT_SEARCH,
1843                                 totalPage, totalCount, queryString, EMPTY_SPACE, SORT_ORDER_NONE);
1844
1845                 if ((pContentInfoList != null) && GetLastResult() == E_SUCCESS && (pContentInfoList->GetCount() > 0))
1846                 {
1847                         IEnumerator* pEnum = pContentInfoList->GetEnumeratorN();
1848                         while (pEnum->MoveNext() == E_SUCCESS)
1849                         {
1850                                 pResultItem = static_cast<ContentSearchResult*>(pEnum->GetCurrent());
1851                                 if (pResultItem == null)
1852                                 {
1853                                         continue;
1854                                 }
1855
1856                                 if (pResultItem->GetContentInfo()->GetContentPath().CompareTo(filePath) == 0)
1857                                 {
1858                                         pBitmap = pResultItem->GetContentInfo()->GetThumbnailN();
1859                                 }
1860                         }
1861                         delete pEnum;
1862                 }
1863
1864                 if (pContentInfoList != null)
1865                 {
1866                         delete pContentInfoList;
1867                 }
1868
1869                 if (pBitmap != null)
1870                 {
1871                         ImageViewerMediaType mediaType = CommonUtil::GetMediaType(filePath);
1872
1873                         if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE)
1874                         {
1875                                 ImageBuffer* imageBuffer = new (std::nothrow) ImageBuffer();
1876                                 result r = imageBuffer->Construct(filePath);
1877                                 if (r == E_SUCCESS)
1878                                 {
1879                                         if (imageBuffer->GetExifOrientation() == EXIF_ORIENTATION_RIGHT_TOP
1880                                                 || imageBuffer->GetExifOrientation() == EXIF_ORIENTATION_LEFT_BOTTOM)
1881                                         {
1882                                                 Dimension srcDim(imageBuffer->GetHeight(), imageBuffer->GetWidth());
1883                                                 pBitmap->Scale(srcDim);
1884                                         }
1885                                         else
1886                                         {
1887                                                 Dimension srcDim(imageBuffer->GetWidth(), imageBuffer->GetHeight());
1888                                                 pBitmap->Scale(srcDim);
1889                                         }
1890
1891                                         delete imageBuffer;
1892                                 }
1893                         }
1894                         else if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_VIDEO)
1895                         {
1896                                 VideoMetadata* pVideoMeta = ContentManagerUtil::GetVideoMetaN(filePath);
1897
1898                                 if (pVideoMeta != null && GetLastResult() == E_SUCCESS)
1899                                 {
1900                                         Dimension srcDim(pVideoMeta->GetWidth(), pVideoMeta->GetHeight());
1901                                         pBitmap->Scale(srcDim);
1902                                         delete pVideoMeta;
1903                                 }
1904                         }
1905                 }
1906                 else
1907                 {
1908                         Canvas mainCanvas;
1909                         mainCanvas.Construct(DUMMY_IMAGE_RECTANGLE);
1910                         mainCanvas.FillRectangle(Color::GetColor(COLOR_ID_WHITE), DUMMY_IMAGE_RECTANGLE);
1911                         pBitmap = new (std::nothrow) Bitmap();
1912                         pBitmap->Construct(mainCanvas, DUMMY_IMAGE_RECTANGLE);
1913                 }
1914         }
1915         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1916         return pBitmap;
1917 }
1918
1919 void ImageViewerForm::OnFormFileEventOccuered(const int index, const unsigned long eventId)
1920 {
1921         AppLogDebug(" ENTER");
1922         bool eventDelete = (eventId & FILE_EVENT_TYPE_DELETE_SELF);
1923         bool eventMove = (eventId & 0x8000);// (eventId & FILE_EVENT_TYPE_MOVE_SELF);
1924
1925         int currentIndex = __pGallery->GetCurrentItemIndex();
1926         int countPath = __pPresentationModel->GetFileCount();
1927
1928         if (countPath == 0 && eventDelete)
1929         {
1930                 UiApp* pApp = UiApp::GetInstance();
1931                 pApp->Terminate();
1932                 AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
1933         }
1934         AppLogDebug(" countPath is %d", countPath);
1935         AppLogDebug(" currentIndex is %d", currentIndex);
1936
1937         if (countPath == currentIndex && eventDelete)
1938         {
1939                 __pGallery->SetCurrentItemIndex(--currentIndex);
1940         }
1941         else if (eventMove)
1942         {
1943                 currentIndex = index;
1944                 __pGallery->SetCurrentItemIndex(currentIndex);
1945         }
1946
1947         String strItemText(EMPTY_SPACE);
1948         String strItemIdxText(EMPTY_SPACE);
1949
1950         __pGallery->UpdateGallery();
1951         AppLogDebug(" UpdateGallery is %d", currentIndex);
1952         String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
1953         __pPresentationModel->RequestImage(filePath);
1954
1955         GetHeaderString(currentIndex, strItemText, strItemIdxText);
1956         __pHeader->SetTitleText(strItemText);
1957         __pHeader->SetDescriptionText(strItemIdxText);
1958
1959         if (__visible == true)
1960         {
1961                 ImageViewerMediaType mediaType = CommonUtil::GetMediaType(filePath);
1962
1963                 if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE)
1964                 {
1965                         __pPlayButton->SetShowState(false);
1966                 }
1967                 else
1968                 {
1969                         __pPlayButton->SetShowState(true);
1970                 }
1971         }
1972         if (__detail == false)
1973         {
1974                 __pScrollPanel->SetShowState(false);
1975                 __detail = true;
1976         }
1977
1978         Invalidate(true);
1979         AppLogDebug("EXIT");
1980 }