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