Fixed jira issue N_SE-26400
[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 , __pDecodeBitmap(null)
107 , __pContextMenuMore(null)
108 , __pContextMenuCopy(null)
109 , __pContextMenuSetAs(null)
110 , __pContextMenuShare(null)
111 , __pDeletePopup(null)
112 , __visible(true)
113 , __detail(true)
114 , __startSlide(false)
115 , __requestId(0)
116 , __pPresentationModel(null)
117 {
118         AppLogDebug("ENTER");
119         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
120 }
121
122 ImageViewerForm::~ImageViewerForm(void)
123 {
124         AppLogDebug("ENTER");
125         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
126 }
127
128 result
129 ImageViewerForm::Initialize()
130 {
131         AppLogDebug("ENTER");
132         __pPresentationModel = ImageViewerPresentationModel::GetInstance();
133
134         if (__pPresentationModel->GetFileCount() > 0)
135         {
136                 if (__pPresentationModel->GetType() == APPCONTROL_DATA_SLIDE_SHOW)
137                 {
138                         __startSlide = true;
139                 }
140         }
141
142         __pSettingPresentationModel = SettingPresentationModel::GetInstance();
143
144         int startIndex = __pPresentationModel->GetStartIndex();
145         String filePath = __pPresentationModel->GetFilePathAt(startIndex);
146
147         if (filePath.StartsWith(WEB_URL_HTTP, 0) == true)
148         {
149                 __initializeDisplayModeCurrent = APPCONTROL_MODE_WEB_LINK;
150         }
151         else if (__pPresentationModel->GetType() == APPCONTROL_DATA_MESSAGE)
152         {
153                 __initializeDisplayModeCurrent = APPCONTROL_MODE_MESSAGE;
154         }
155         else if (__pPresentationModel->GetType() == APPCONTROL_DATA_EMAIL)
156         {
157                 __initializeDisplayModeCurrent = APPCONTROL_MODE_EMAIL;
158         }
159         else
160         {
161                 __initializeDisplayModeCurrent = APPCONTROL_MODE_NORMAL;
162         }
163
164         result r = Form::Construct(IDL_FORM_IMAGE_VIEWER);
165
166         if (filePath == EMPTY_SPACE)
167         {
168                 MessageBox messageBox;
169                 messageBox.Construct(L"", ResourceManager::GetString(L"IDS_IV_POP_INVALID_IMAGE_FILE"), MSGBOX_STYLE_NONE,
170                                 3000);
171                 int modalResult = 0;
172                 messageBox.ShowAndWait(modalResult);
173
174                 UiApp* pApp = UiApp::GetInstance();
175                 pApp->Terminate();
176         }
177
178         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
179
180         return r;
181 }
182
183 result
184 ImageViewerForm::OnInitializing(void)
185 {
186         AppLogDebug("ENTER");
187         SetFormBackEventListener(this);
188         __pPresentationModel->AddListener(this);
189
190         CreateGallery();
191         InitializeDisplay(__initializeDisplayModeCurrent);
192         InitializePanelDetail();
193         InitializePopup();
194
195         if (    __initializeDisplayModeCurrent == APPCONTROL_MODE_NORMAL
196                         || __initializeDisplayModeCurrent == APPCONTROL_MODE_MESSAGE
197                         || __initializeDisplayModeCurrent == APPCONTROL_MODE_EMAIL)
198         {
199                 int index = __pPresentationModel->GetStartIndex();
200                 __pGallery->UpdateGallery();
201                 __pGallery->SetCurrentItemIndex(index);
202                 __pGallery->Draw();
203
204                 String filePath = __pPresentationModel->GetFilePathAt(index);
205                 __pPresentationModel->RequestImage(filePath);
206         }
207         else if (__initializeDisplayModeCurrent == APPCONTROL_MODE_WEB_LINK)
208         {
209                 RequestDecodeUrl();
210         }
211
212         if (__startSlide)
213         {
214                 __pTimer = new (std::nothrow) Timer();
215                 __pTimer->Construct(*this);
216                 __pTimer->Start(1);
217         }
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         }
729
730         if (__pGallery->GetItemCount() > 1)
731         {
732                 __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_IV_OPT_SLIDE_SHOW"),
733                                 ACTION_ID_FOOTER_BUTTON_SLIDE);
734         }
735         __pContextMenuMore->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_DETAILS"),
736                         ACTION_ID_FOOTER_BUTTON_DETAILS);
737         __pContextMenuMore->SetShowState(false);
738         __pContextMenuMore->AddActionEventListener(*this);
739         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
740
741         return E_SUCCESS;
742 }
743
744 result
745 ImageViewerForm::InitializeContextMenuSetAs(void)
746 {
747         AppLogDebug("ENTER");
748
749         if (__pContextMenuSetAs != null)
750         {
751                 delete __pContextMenuSetAs;
752                 __pContextMenuSetAs = null;
753         }
754
755         __pContextMenuSetAs = new (std::nothrow) ContextMenu();
756         __pContextMenuSetAs->Construct(Point(X_MORE, GetClientAreaBounds().y + GetClientAreaBounds().height),
757                         CONTEXT_MENU_STYLE_LIST, CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD);
758
759         __pContextMenuSetAs->AddItem(ResourceManager::GetString(L"IDS_IV_HEADER_HOME_SCREEN_WALLPAPER_ABB"),
760                         ACTION_ID_CONTEXTMENU_HOME);
761         __pContextMenuSetAs->AddItem(ResourceManager::GetString(L"IDS_IV_HEADER_LOCK_SCREEN_WALLPAPER_ABB"),
762                         ACTION_ID_CONTEXTMENU_LOCK);
763         __pContextMenuSetAs->AddItem(ResourceManager::GetString(L"IDS_IV_BODY_CALLER_IMAGE"),
764                         ACTION_ID_CONTEXTMENU_CALLER);
765         __pContextMenuSetAs->AddActionEventListener(*this);
766         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
767
768         return E_SUCCESS;
769 }
770
771 result
772 ImageViewerForm::InitializeContextMenuShare(void)
773 {
774         AppLogDebug("ENTER");
775         if (__pContextMenuShare != null)
776         {
777                 delete __pContextMenuShare;
778                 __pContextMenuShare = null;
779         }
780         __pContextMenuShare = new (std::nothrow) ContextMenu();
781         __pContextMenuShare->Construct(Point((GetClientAreaBounds().width - (X_MORE * 4)) / 4 + X_MORE * 2,
782                         GetClientAreaBounds().y + GetClientAreaBounds().height), CONTEXT_MENU_STYLE_LIST,
783                         CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD);
784
785         __pContextMenuShare->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_MESSAGE"),
786                         ACTION_ID_CONTEXTMENU_MESSAGE);
787         __pContextMenuShare->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_EMAIL"), ACTION_ID_CONTEXTMENU_EMAIL);
788         __pContextMenuShare->AddActionEventListener(*this);
789         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
790
791         return E_SUCCESS;
792 }
793
794 long long
795 ImageViewerForm::GetFileSize(String filePath)
796 {
797         AppLogDebug("ENTER");
798         FileAttributes attr;
799         long long size = 0;
800
801         result r = File::GetAttributes(filePath, attr);
802         if (r != E_SUCCESS)
803         {
804                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
805
806                 return 0;
807         }
808         size = attr.GetFileSize();
809         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
810
811         return size;
812 }
813
814 result
815 ImageViewerForm::SetDetailInfo(void)
816 {
817         AppLogDebug("ENTER");
818
819         Rectangle clientRect = GetClientAreaBounds();
820         __pScrollPanel->SetBounds(0, 0, clientRect.width, clientRect.height);
821
822         int currentIndex = __pGallery->GetCurrentItemIndex();
823         String strFilePath = __pPresentationModel->GetFilePathAt(currentIndex);
824
825         ImageViewerMediaType mediaType = CommonUtil::GetMediaType(strFilePath);
826
827         String strResult[DETAIL_COUNT_MAX] = {EMPTY_SPACE, };
828
829         strResult[0] = __pPresentationModel->GetFileName(strFilePath);
830         strResult[1] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
831
832         FileAttributes attr;
833         result r = File::GetAttributes(strFilePath, attr);
834         if (r == E_SUCCESS)
835         {
836                 long long nSize = attr.GetFileSize();
837                 DateTime dateTime = attr.GetDateTime();
838                 strResult[2] = dateTime.ToString();
839
840                 if (nSize > SINGLE_GIGA_BYTE)
841                 {
842                         strResult[3].Format(FORMAT_BUFFER_SIZE, L"%lld ", nSize / SINGLE_GIGA_BYTE);
843                         strResult[3].Append(ResourceManager::GetString(L"IDS_COM_BODY_GB"));
844                 }
845                 else if (nSize > SINGLE_MEGA_BYTE)
846                 {
847                         strResult[3].Format(FORMAT_BUFFER_SIZE, L"%lld ", nSize / SINGLE_MEGA_BYTE);
848                         strResult[3].Append(ResourceManager::GetString(L"IDS_COM_BODY_MB"));
849                 }
850                 else if (nSize > SINGLE_KILO_BYTE)
851                 {
852                         strResult[3].Format(FORMAT_BUFFER_SIZE, L"%lld ", nSize / SINGLE_KILO_BYTE);
853                         strResult[3].Append(ResourceManager::GetString(L"IDS_COM_BODY_KB"));
854                 }
855                 else
856                 {
857                         strResult[3].Format(FORMAT_BUFFER_SIZE, L"%lld ", nSize);
858                         strResult[3].Append(ResourceManager::GetString(L"IDS_COM_BODY_B"));
859                 }
860         }
861         else
862         {
863                 strResult[2] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
864                 strResult[3] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
865         }
866
867         strResult[4] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
868         strResult[5] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
869         strResult[6] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
870         strResult[7] = ResourceManager::GetString(L"IDS_COM_BODY_UNKNOWN");
871         strResult[8] = strFilePath;
872         String fileName = File::GetFileName(strFilePath);
873         strResult[8].Remove(strResult[8].GetLength() - fileName.GetLength(), fileName.GetLength());
874
875         if (__initializeDisplayModeCurrent == APPCONTROL_MODE_WEB_LINK)
876         {
877                 strResult[0] = __downLordFileName;
878         }
879         else if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE)
880         {
881                 ImageMetadata* pImgMeta = ContentManagerUtil::GetImageMetaN(strFilePath);
882
883                 if (pImgMeta != null)
884                 {
885                         ImageContentInfo imageContentInfo;
886                         r = imageContentInfo.Construct(&strFilePath);
887                         if (r == E_SUCCESS)
888                         {
889                                 strResult[1] = imageContentInfo.GetMediaFormat();
890                                 strResult[4].Format(FORMAT_BUFFER_SIZE, L"%d x %d", pImgMeta->GetWidth(),
891                                                 pImgMeta->GetHeight());
892
893                                 if (imageContentInfo.GetLocationTag() != EMPTY_SPACE)
894                                 {
895                                         strResult[5].Format(FORMAT_BUFFER_SIZE, L"%ls", imageContentInfo.GetLocationTag().GetPointer());
896                                 }
897
898                                 if (pImgMeta->GetLatitude() > 1.0 && pImgMeta->GetLongitude() > 1.0)
899                                 {
900                                         strResult[6].Format(FORMAT_BUFFER_SIZE, L"%f", pImgMeta->GetLatitude());
901                                         strResult[7].Format(FORMAT_BUFFER_SIZE, L"%f", pImgMeta->GetLongitude());
902                                 }
903                         }
904                         delete pImgMeta;
905                 }
906         }
907         else if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_VIDEO)
908         {
909                 VideoMetadata* pVideoMeta = ContentManagerUtil::GetVideoMetaN(strFilePath);
910                 if (pVideoMeta != null)
911                 {
912                         VideoContentInfo videoContentInfo;
913                         r = videoContentInfo.Construct(&strFilePath);
914                         if (r == E_SUCCESS)
915                         {
916                                 strResult[1] = videoContentInfo.GetMediaFormat();
917                                 strResult[4].Format(FORMAT_BUFFER_SIZE, L"%d x %d", pVideoMeta->GetWidth(),
918                                                 pVideoMeta->GetHeight());
919                                 if (videoContentInfo.GetLocationTag() != EMPTY_SPACE)
920                                 {
921                                         strResult[5].Format(FORMAT_BUFFER_SIZE, L"%ls", videoContentInfo.GetLocationTag().GetPointer());
922                                 }
923                         }
924                 }
925         }
926
927         for (int i = 0; i < DETAIL_COUNT_MAX; ++i)
928         {
929                 __pDetail_FileInfo_Value_Label[i]->SetText(strResult[i]);
930                 __pDetail_FileInfo_Value_Label[i]->RequestRedraw();
931         }
932
933         if (__initializeDisplayModeCurrent == APPCONTROL_MODE_WEB_LINK)
934         {
935                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
936                 return r;
937         }
938
939         if (__pRenameButton == null)
940         {
941                 __pRenameButton = new (std::nothrow) Button();
942                 Rectangle rect = GetBounds();
943                 __pRenameButton->Construct(Rectangle(rect.width - W_RENAME_BUTTON, Y_RENAME_BUTTON, W_RENAME_BUTTON, H_RENAME_BUTTON));
944                 __pRenameButton->SetActionId(ACTION_ID_PANEL_HEADER_DETAILS_RENAME);
945
946                 Bitmap* pIcon = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_EDIT_NAME);
947                 Bitmap* pIconBackground =
948                                 ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_EDIT_NAME_NORMAL_BACKGROUND);
949                 Bitmap* pIconPressed =
950                                 ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_EDIT_NAME_NORMAL_BACKGROUND_PRESS);
951
952                 if (pIcon != null && pIconPressed != null && pIconBackground != null)
953                 {
954                         __pRenameButton->SetNormalBackgroundBitmap(*pIconBackground);
955                         __pRenameButton->SetPressedBackgroundBitmap(*pIconPressed);
956                         Point iconPosition(0, 0);
957                         __pRenameButton->SetNormalBitmap(iconPosition, *pIcon);
958                         __pRenameButton->SetPressedBitmap(iconPosition, *pIconPressed);
959                 }
960                 else
961                 {
962                         __pRenameButton->SetColor(BUTTON_STATUS_NORMAL, COLOR_HEADER_BUTTON1);
963                         __pRenameButton->SetColor(BUTTON_STATUS_PRESSED, COLOR_HEADER_BUTTON1);
964                 }
965                 delete pIcon;
966                 delete pIconPressed;
967                 delete pIconBackground;
968
969                 __pScrollPanel->AddControl(*__pRenameButton);
970                 __pRenameButton->SetColor(BUTTON_STATUS_NORMAL, COLOR_HEADER_BUTTON1);
971                 __pRenameButton->AddActionEventListener(*this);
972         }
973         else
974         {
975                 Rectangle rect = GetBounds();
976                 __pRenameButton->SetBounds(Rectangle(rect.width - W_RENAME_BUTTON, Y_RENAME_BUTTON, W_RENAME_BUTTON, H_RENAME_BUTTON));
977         }
978         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
979
980         return r;
981 }
982
983 result
984 ImageViewerForm::ShowPanelDetail(bool showStatus)
985 {
986         AppLogDebug("ENTER");
987         if (showStatus)
988         {
989                 SetDetailInfo();
990                 __pScrollPanel->SetShowState(true);
991                 __detail = false;
992         }
993         else
994         {
995                 __pScrollPanel->SetShowState(false);
996                 __detail = true;
997         }
998         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
999
1000         return E_SUCCESS;
1001 }
1002
1003 result
1004 ImageViewerForm::ChangeFooterItem(bool isChanged, Footer* pFooter, int position)
1005 {
1006         AppLogDebug("ENTER");
1007         FooterItem footerItem;
1008         footerItem.Construct(ACTION_ID_FOOTER_BUTTON_DETAILS);
1009         Bitmap* pfooterItem = null;
1010
1011         if (isChanged)
1012         {
1013                 pfooterItem = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_DETAILS_CLOSE);
1014                 footerItem.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pfooterItem);
1015         }
1016         else
1017         {
1018                 pfooterItem = ResourceManager::GetBitmapN(IDB_IMAGE_VIEWERFORM_BUTTON_DETAILS);
1019                 footerItem.SetIcon(FOOTER_ITEM_STATUS_NORMAL, pfooterItem);
1020         }
1021
1022         pFooter->SetItemAt(position, footerItem);
1023         pFooter->Invalidate(true);
1024
1025         delete pfooterItem;
1026         pfooterItem = null;
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
1265         if (__pContextMenuCopy != null)
1266         {
1267                 delete __pContextMenuCopy;
1268                 __pContextMenuCopy = null;
1269         }
1270
1271         if (__pContextMenuSetAs != null)
1272         {
1273                 delete __pContextMenuSetAs;
1274                 __pContextMenuSetAs = null;
1275         }
1276
1277         if (__pDeletePopup != null)
1278         {
1279                 delete __pDeletePopup;
1280                 __pDeletePopup = null;
1281         }
1282
1283         if (__pContextMenuShare != null)
1284         {
1285                 delete __pContextMenuShare;
1286                 __pContextMenuShare = null;
1287         }
1288
1289         if (__pContextMenuMore != null)
1290         {
1291                 delete __pContextMenuMore;
1292                 __pContextMenuMore = null;
1293         }
1294
1295         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1296
1297         return E_SUCCESS;
1298 }
1299
1300 void
1301 ImageViewerForm::OnActionPerformed(const Control& source, int actionId)
1302 {
1303         AppLogDebug("ENTER actionId(%d)", actionId);
1304         SceneManager* pSceneManager = SceneManager::GetInstance();
1305         InitShowGallery();
1306
1307         switch (actionId)
1308         {
1309         case ACTION_ID_FOOTER_MORE:
1310         {
1311                 InitializeContextMenuMore();
1312
1313                 __pContextMenuMore->SetShowState(true);
1314                 __pContextMenuMore->Show();
1315         }
1316         break;
1317         case ACTION_ID_CONTEXTMENU_SET_AS:
1318                 InitializeContextMenuSetAs();
1319
1320                 __pContextMenuSetAs->SetShowState(true);
1321                 __pContextMenuSetAs->Show();
1322                 break;
1323         case ACTION_ID_FOOTER_BUTTON_SHARE:
1324                 InitializeContextMenuShare();
1325
1326                 __pContextMenuShare->SetShowState(true);
1327                 __pContextMenuShare->Show();
1328                 break;
1329         case ACTION_ID_FOOTER_BUTTON_DELETE:
1330                 __pDeletePopup->SetShowState(true);
1331                 __pDeletePopup->Show();
1332                 break;
1333         case ACTION_ID_FOOTER_BUTTON_SLIDE:
1334         {
1335                 int repeatValue = 0;
1336
1337                 if (__pPresentationModel->GetFileCount() > 1)
1338                 {
1339                         __pGallery->UpdateGallery();
1340                         if (__detail == false)
1341                         {
1342                                 ShowPanelDetail(false);
1343                         }
1344
1345                         __pSettingPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
1346                                         ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
1347
1348                         if( repeatValue == 0)
1349                         {
1350                                 __pGallery->StartSlideShow(false);
1351                         }
1352                         else
1353                         {
1354                                 __pGallery->StartSlideShow(true);
1355                         }
1356                 }
1357                 break;
1358         }
1359         case ACTION_ID_FOOTER_BUTTON_DETAILS:
1360         {
1361                 ShowPanelDetail(__detail);
1362                 break;
1363         }
1364         case ACTION_ID_FOOTER_BUTTON_BACK:
1365                 ImageViewerForm::OnFormBackRequested(*this);
1366                 break;
1367         case ACTION_ID_FOOTER_BUTTON_DOWNLOAD:
1368                 DownloadFile();
1369                 break;
1370         case ACTION_ID_FOOTER_BUTTON_SAVE:
1371                 break;
1372         case ACTION_ID_PANEL_HEADER_DETAILS_RENAME:
1373         {
1374                 ArrayList* pSelectedIndex = new (std::nothrow) ArrayList(SingleObjectDeleter);
1375                 pSelectedIndex->Construct();
1376                 pSelectedIndex->Add(new (std::nothrow) Integer(__pGallery->GetCurrentItemIndex()));
1377                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_NAME_EDITOR), pSelectedIndex);
1378                 break;
1379         }
1380         case ACTION_ID_CONTEXTMENU_HOME:
1381         {
1382                 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1383                 pList->Add(new (std::nothrow) Integer(__pGallery->GetCurrentItemIndex()));
1384                 pList->Add(new (std::nothrow) Integer(SET_AT_TYPE_HOME_SCREEN_WALLPAPER));
1385                 __pPresentationModel->SetSetterIndex(__pGallery->GetCurrentItemIndex());
1386                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_SETTER), pList);
1387                 break;
1388         }
1389         case ACTION_ID_CONTEXTMENU_LOCK:
1390         {
1391                 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1392                 pList->Add(new (std::nothrow) Integer(__pGallery->GetCurrentItemIndex()));
1393                 pList->Add(new (std::nothrow) Integer(SET_AT_TYPE_LOCK_SCREEN_WALLPAPER));
1394                 __pPresentationModel->SetSetterIndex(__pGallery->GetCurrentItemIndex());
1395                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_SETTER), pList);
1396                 break;
1397         }
1398         case ACTION_ID_CONTEXTMENU_CALLER:
1399         {
1400                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
1401                 pDataList->Construct();
1402                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_SELECTION_MODE),
1403                                 new (std::nothrow) String(APPCONTROL_DATA_SINGLE));
1404                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_RETURN_TYPE),
1405                                 new (std::nothrow) String(APPCONTROL_DATA_CONTACT_ID));
1406
1407                 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_CONTACTS,
1408                                 APPCONTROL_OPERATION_ID_PICK, pDataList, this);
1409                 break;
1410         }
1411         case ACTION_ID_CONTEXTMENU_EMAIL:
1412         {
1413                 OnRequestEmailAction();
1414                 break;
1415         }
1416         case ACTION_ID_CONTEXTMENU_MESSAGE:
1417         {
1418                 OnRequestMessagesAction();
1419                 break;
1420         }
1421         case ACTION_ID_CONTEXTMENU_COPY:
1422         {
1423                 int currentIndex = __pGallery->GetCurrentItemIndex();
1424                 String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
1425
1426                 ClipboardItem item;
1427                 item.Construct(CLIPBOARD_DATA_TYPE_IMAGE, filePath);
1428                 Clipboard* pClipboard = Clipboard::GetInstance();
1429                 pClipboard->CopyItem(item);
1430                 break;
1431         }
1432         case ACTION_ID_DELETE_POPUP_DEL:
1433         {
1434                 __pDeletePopup->SetShowState(false);
1435                 __pDeletePopup->Show();
1436                 DeleteImageFile();
1437
1438                 if (__detail == false)
1439                 {
1440                         ShowPanelDetail(false);
1441                 }
1442                 break;
1443         }
1444         case ACTION_ID_DELETE_POPUP_CANCEL:
1445         {
1446                 __pDeletePopup->SetShowState(false);
1447                 __pDeletePopup->Show();
1448                 break;
1449         }
1450         case ACTION_ID_CONTORL_BUTTON_PLAY:
1451                 CallVideoPlayer();
1452                 break;
1453         default:
1454                 break;
1455         }
1456         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1457 }
1458
1459 void
1460 ImageViewerForm::OnFormBackRequested(Form& source)
1461 {
1462         AppLogDebug("ENTER");
1463         if (__detail == false)
1464         {
1465                 ShowPanelDetail(false);
1466         }
1467         else
1468         {
1469                 UiApp* pApp = UiApp::GetInstance();
1470                 pApp->Terminate();
1471         }
1472         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1473 }
1474
1475 void
1476 ImageViewerForm::OnSceneActivatedN(const SceneId& previousSceneId,
1477                 const SceneId& currentSceneId, IList* pArgs)
1478 {
1479         AppLogDebug("ENTER");
1480
1481         Rectangle clientRect = GetClientAreaBounds();
1482         Rectangle rect = GetBounds();
1483
1484         __pGallery->SetBounds(Rectangle(0, -clientRect.y, rect.width, rect.height));
1485         __pScrollPanel->SetBounds(Rectangle(0, 0, clientRect.width, clientRect.height));
1486         __pPlayButton->SetBounds(Rectangle(clientRect.width / 2 - 80, clientRect.height / 2 - 80, 160, 160));
1487
1488         if (previousSceneId == IDSCN_IMAGE_NAME_EDITOR && currentSceneId == IDSCN_IMAGE_VIEWER)
1489         {
1490                 SetDetailInfo();
1491                 String strItemText(EMPTY_SPACE);
1492                 String strItemIdxText(EMPTY_SPACE);
1493                 GetHeaderString(__pGallery->GetCurrentItemIndex(), strItemText, strItemIdxText);
1494                 __pHeader->SetTitleText(strItemText);
1495                 __pHeader->SetDescriptionText(strItemIdxText);
1496                 Invalidate(true);
1497         }
1498
1499         if (__pGallery->GetCurrentItemIndex() < 0)
1500         {
1501                 SetFooterItemState(false);
1502         }
1503         else
1504         {
1505                 SetFooterItemState(true);
1506         }
1507         Invalidate(true);
1508         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1509 }
1510
1511 void
1512 ImageViewerForm::OnSceneDeactivated(const SceneId& currentSceneId,
1513                 const SceneId& nextSceneId)
1514 {
1515         AppLogDebug("ENTER");
1516         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1517 }
1518
1519 void
1520 ImageViewerForm::OnImageDecodedN(const int index)
1521 {
1522         AppLogDebug("ENTER");
1523         __pGallery->RefreshGallery(index, GALLERY_REFRESH_TYPE_ITEM_MODIFY);
1524         __pGallery->Draw();
1525         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1526 }
1527
1528 void
1529 ImageViewerForm::OnAppControlCompleteResponseReceived(const AppId& appId,
1530                 const String& operationId, AppCtrlResult appControlResult,
1531                 const IMap* pExtraData)
1532 {
1533         AppLogDebug("ENTER");
1534
1535         if (appId == APPCONTROL_PROVIDER_ID_CONTACTS
1536                         && operationId == APPCONTROL_OPERATION_ID_PICK
1537                         && appControlResult == APP_CTRL_RESULT_SUCCEEDED)
1538         {
1539                 const String* pReturnType =
1540                                 static_cast<const String*>(pExtraData->GetValue(String(APPCONTROL_KEY_RETURN_TYPE)));
1541                 if (pReturnType != null && pReturnType->CompareTo(APPCONTROL_DATA_CONTACT_ID) == 0)
1542                 {
1543                         const String* pContactId =
1544                                         static_cast<const String*>(pExtraData->GetValue(String(APPCONTROL_KEY_VALUE)));
1545                         SceneManager* pSceneManager = SceneManager::GetInstance();
1546                         long long lresult = 0;
1547                         if (pContactId != null && pContactId->GetLength() > 0)
1548                         {
1549                                 LongLong::Parse(*pContactId, lresult);
1550                         }
1551                         ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
1552                         pList->Add(new (std::nothrow) Integer(__pGallery->GetCurrentItemIndex()));
1553                         pList->Add(new (std::nothrow) Integer(SET_AT_TYPE_CALLER_IMAGE));
1554                         pList->Add(new (std::nothrow) LongLong(lresult));
1555                         __pPresentationModel->SetSetterIndex(__pGallery->GetCurrentItemIndex());
1556                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_SETTER), pList);
1557                 }
1558         }
1559
1560         ImageViewerApp* pImageViewerApp = static_cast<ImageViewerApp*>(ImageViewerApp::GetInstance());
1561         pImageViewerApp->SetFrameEnabled(true);
1562         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1563 }
1564
1565 void
1566 ImageViewerForm::OnOverlayControlCreated(const Control& source)
1567 {
1568         AppLogDebug("ENTER");
1569         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1570 }
1571
1572 void
1573 ImageViewerForm::OnOverlayControlOpened(const Control& source)
1574 {
1575         AppLogDebug("ENTER");
1576         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1577 }
1578
1579 void
1580 ImageViewerForm::OnOverlayControlClosed(const Control& source)
1581 {
1582         AppLogDebug("ENTER");
1583         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1584 }
1585
1586 void
1587 ImageViewerForm::OnOtherControlSelected(const Control& source)
1588 {
1589         AppLogDebug("ENTER");
1590         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1591 }
1592
1593 void
1594 ImageViewerForm::InitShowGallery(void)
1595 {
1596         AppLogDebug("ENTER");
1597         if (__pGallery != null && __pGallery->IsVisible() == false)
1598         {
1599                 Canvas* pCanvas = GetCanvasN();
1600                 if (pCanvas == null || GetLastResult() != E_SUCCESS)
1601                 {
1602                         AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1603
1604                         return;
1605                 }
1606
1607                 pCanvas->Clear();
1608                 __pGallery->SetShowState(true);
1609                 delete pCanvas;
1610                 pCanvas = null;
1611         }
1612         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1613 }
1614
1615 void
1616 ImageViewerForm::OnTimerExpired(Timer &timer)
1617 {
1618         int repeatValue = 0;
1619         AppLogDebug("ENTER");
1620         if (__pPresentationModel->GetFileCount() > 1)
1621         {
1622                 __pSettingPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
1623                                 ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
1624
1625                 if( repeatValue == 0)
1626                 {
1627                         __pGallery->StartSlideShow(false);
1628                 }
1629                 else
1630                 {
1631                         __pGallery->StartSlideShow(true);
1632                 }
1633         }
1634         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1635 }
1636
1637 void
1638 ImageViewerForm::OnContentTransferInProgress(RequestId requestId, int totalReceivedSize)
1639 {
1640         AppLogDebug("ENTER");
1641         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1642 }
1643
1644 void
1645 ImageViewerForm::OnContentUploadCompleted(RequestId requestId, result transferResult, const String& errorCode,
1646                 const String& errorMessage)
1647 {
1648         AppLogDebug("ENTER");
1649         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1650 }
1651
1652 void
1653 ImageViewerForm::OnContentDownloadCompleted(RequestId requestId, ContentId contentId,
1654                 result transferResult, const String& errorCode, const String& errorMessage)
1655 {
1656         AppLogDebug("ENTER");
1657         AppLogTag("IV", "ImageViewerForm::OnContentDownloadCompleted");
1658         AppLogTag("IV", "DownloadCompleted Error [%s]", GetErrorMessage(transferResult));
1659         AppLogTag("IV", "errorCode [%ls] errorMessage [%ls]", errorCode.GetPointer(), errorMessage.GetPointer());
1660         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1661 }
1662
1663 void
1664 ImageViewerForm::OnContentDownloadToBufferCompleted(RequestId reqId, ByteBuffer* pBuffer, result r,
1665                 const String& errorCode, const String& errorMessage)
1666 {
1667         AppLogDebug("ENTER");
1668         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1669 }
1670
1671 void
1672 ImageViewerForm::OnContentTransferCanceled(RequestId reqId, result res, const String& errorCode,
1673                 const String& errorMessage)
1674 {
1675         AppLogDebug("ENTER");
1676         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1677 }
1678
1679 void
1680 ImageViewerForm::RequestDecodeUrl(void)
1681 {
1682         AppLogDebug("ENTER");
1683
1684         String filePath = __pPresentationModel->GetFilePathAt(0);
1685
1686         if (filePath.StartsWith(WEB_URL_HTTP, 0) == false)
1687         {
1688                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1689
1690                 return;
1691         }
1692
1693         __downLordFileName = __pPresentationModel->GetFileName(filePath);
1694
1695         Image* pImage = new (std::nothrow) Image();
1696         pImage->Construct();
1697         Uri uri;
1698         RequestId reqId;
1699         uri.SetUri(filePath);
1700
1701         pImage->DecodeUrl(uri, BITMAP_PIXEL_FORMAT_RGB565, 720, 1280, reqId, *this, 5000);
1702
1703         delete pImage;
1704         pImage = null;
1705         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1706 }
1707
1708 void
1709 ImageViewerForm::OnImageDecodeUrlReceived (RequestId reqId, Bitmap *pBitmap,
1710                 result r, const String errorCode, const String errorMessage)
1711 {
1712         AppLogDebug("ENTER");
1713         Image* pImage = new (std::nothrow) Image();
1714         pImage->Construct();
1715
1716         String destPath = App::GetInstance()->GetAppRootPath() + TEMP_FILE_PATH_WEB_FILE;
1717         r = pImage->EncodeToFile(*pBitmap, IMG_FORMAT_JPG, destPath, true);
1718
1719         if (r == E_SUCCESS)
1720         {
1721                 __pPresentationModel->GetImageCacheAt(0)->SetFilePath(destPath);
1722                 __pPresentationModel->GetImageCacheAt(0)->SetBitmap(pBitmap);
1723
1724                 __pGallery->RefreshGallery(0, GALLERY_REFRESH_TYPE_ITEM_MODIFY);
1725                 __pGallery->Draw();
1726                 __pPresentationModel->RequestImage(destPath);
1727         }
1728         else
1729         {
1730                 AppLogDebug("ImageViewerForm::OnImageDecodeUrlReceived [%s]", GetErrorMessage(r));
1731         }
1732
1733         delete pImage;
1734         pImage = null;
1735         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1736 }
1737
1738 void
1739 ImageViewerForm::OnRequestEmailAction(void)
1740 {
1741         AppLogDebug("ENTER");
1742         int currentIndex = __pGallery->GetCurrentItemIndex();
1743
1744         if (__pPresentationModel->GetFileCount() <= 0)
1745         {
1746                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1747                 return;
1748         }
1749
1750         String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
1751
1752         ImageViewerMediaType mediaType = CommonUtil::GetMediaType(filePath);
1753
1754         if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE || mediaType == IMAGE_VIEWER_MEDIA_TYPE_VIDEO)
1755         {
1756                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
1757                 pDataList->Construct();
1758                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_ATTACHMENTS),
1759                                 new (std::nothrow) String(filePath));
1760
1761                 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_EMAIL,
1762                                 APPCONTROL_OPERATION_ID_COMPOSE, pDataList, this);
1763         }
1764         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1765 }
1766
1767 void
1768 ImageViewerForm::OnRequestMessagesAction(void)
1769 {
1770         AppLogDebug("ENTER");
1771         int currentIndex = __pGallery->GetCurrentItemIndex();
1772
1773         if (__pPresentationModel->GetFileCount() <= 0)
1774         {
1775                 AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
1776                 return;
1777         }
1778
1779         String filePath = __pPresentationModel->GetFilePathAt(currentIndex);
1780
1781         ImageViewerMediaType mediaType = CommonUtil::GetMediaType(filePath);
1782
1783         if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE || mediaType == IMAGE_VIEWER_MEDIA_TYPE_VIDEO)
1784         {
1785                 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
1786                 pDataList->Construct();
1787                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_TYPE),
1788                                 new (std::nothrow) String(filePath));
1789                 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_ATTACHMENTS),
1790                                 new (std::nothrow) String(APPCONTROL_DATA_MMS));
1791
1792                 __pPresentationModel->StartAppControl(APPCONTROL_PROVIDER_ID_MESSAGES,
1793                                 APPCONTROL_OPERATION_ID_COMPOSE, pDataList, this);
1794         }
1795         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1796 }
1797
1798 void
1799 ImageViewerForm::SetFooterItemState(bool isEnable)
1800 {
1801         AppLogDebug("ENTER");
1802         if (__initializeDisplayModeCurrent == APPCONTROL_MODE_NORMAL)
1803         {
1804                 __pFooter->SetButtonEnabled(BUTTON_POSITION_LEFT, isEnable);
1805                 __pFooter->SetItemEnabled(0, isEnable);
1806                 __pFooter->SetItemEnabled(1, isEnable);
1807         }
1808         else if (__initializeDisplayModeCurrent == APPCONTROL_MODE_WEB_LINK)
1809         {
1810                 __pFooter->SetButtonEnabled(BUTTON_POSITION_LEFT, isEnable);
1811                 __pFooter->SetItemEnabled(0, isEnable);
1812                 __pFooter->SetItemEnabled(1, isEnable);
1813         }
1814         else if (__initializeDisplayModeCurrent == APPCONTROL_MODE_CROP)
1815         {
1816                 __pFooter->SetItemEnabled(0, isEnable);
1817         }
1818         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1819 }
1820
1821 Bitmap*
1822 ImageViewerForm::GetQuickThumbnailN(String& filePath)
1823 {
1824         AppLogDebug("ENTER");
1825         Bitmap* pBitmap = null;
1826
1827         if (filePath.GetLength() > 4)
1828         {
1829                 int totalPage = 0;
1830                 int totalCount = 0;
1831                 ContentSearch contentSearch;
1832                 ContentSearchResult* pResultItem = null;
1833                 IList* pContentInfoList = null;
1834                 String queryString;
1835                 ContentType contentType = ContentManagerUtil::CheckContentType(filePath);
1836                 result r = contentSearch.Construct(contentType);
1837                 AppLogDebug("r(%s)", GetErrorMessage(r));
1838                 if (r != E_SUCCESS)
1839                 {
1840                         pBitmap = new (std::nothrow) Bitmap();
1841                         r = pBitmap->Construct(DUMMY_IMAGE_DIMENSION, BITMAP_PIXEL_FORMAT_RGB565);
1842                         if (r == E_SUCCESS)
1843                         {
1844                                 return pBitmap;
1845                         }
1846                         else
1847                         {
1848                                 delete pBitmap;
1849                                 return null;
1850                         }
1851                 }
1852                 queryString = CONTENT_QUERY_PREFIX_FILENAME;
1853                 queryString.Append(L"'");
1854                 queryString.Append(__pPresentationModel->GetFileName(filePath));
1855                 queryString.Append(L"'");
1856
1857                 pContentInfoList = contentSearch.SearchN(PAGE_NO_CONTENT_SEARCH, COUNT_PER_PAGE_CONTENT_SEARCH,
1858                                 totalPage, totalCount, queryString, EMPTY_SPACE, SORT_ORDER_NONE);
1859
1860                 if ((pContentInfoList != null) && GetLastResult() == E_SUCCESS && (pContentInfoList->GetCount() > 0))
1861                 {
1862                         IEnumerator* pEnum = pContentInfoList->GetEnumeratorN();
1863                         while (pEnum->MoveNext() == E_SUCCESS)
1864                         {
1865                                 pResultItem = static_cast<ContentSearchResult*>(pEnum->GetCurrent());
1866                                 if (pResultItem == null)
1867                                 {
1868                                         continue;
1869                                 }
1870
1871                                 if (pResultItem->GetContentInfo()->GetContentPath().CompareTo(filePath) == 0)
1872                                 {
1873                                         pBitmap = pResultItem->GetContentInfo()->GetThumbnailN();
1874                                 }
1875                         }
1876                         delete pEnum;
1877                 }
1878
1879                 if (pContentInfoList != null)
1880                 {
1881                         delete pContentInfoList;
1882                 }
1883
1884                 if (pBitmap != null)
1885                 {
1886                         ImageViewerMediaType mediaType = CommonUtil::GetMediaType(filePath);
1887
1888                         if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_IMAGE)
1889                         {
1890                                 ImageBuffer* imageBuffer = new (std::nothrow) ImageBuffer();
1891                                 result r = imageBuffer->Construct(filePath);
1892                                 if (r == E_SUCCESS)
1893                                 {
1894                                         if ( imageBuffer->GetExifOrientation() == EXIF_ORIENTATION_RIGHT_TOP ||
1895                                                         imageBuffer->GetExifOrientation() == EXIF_ORIENTATION_LEFT_BOTTOM)
1896                                         {
1897                                                 Dimension srcDim( imageBuffer->GetHeight(),imageBuffer->GetWidth());
1898                                                 pBitmap->Scale(srcDim);
1899                                         }
1900                                         else
1901                                         {
1902                                                 Dimension srcDim(imageBuffer->GetWidth(), imageBuffer->GetHeight());
1903                                                 pBitmap->Scale(srcDim);
1904                                         }
1905
1906                                         delete imageBuffer;
1907                                 }
1908                         }
1909                         else if (mediaType == IMAGE_VIEWER_MEDIA_TYPE_VIDEO)
1910                         {
1911                                 VideoMetadata* pVideoMeta = ContentManagerUtil::GetVideoMetaN(filePath);
1912
1913                                 if (pVideoMeta != null && GetLastResult() == E_SUCCESS)
1914                                 {
1915                                         Dimension srcDim(pVideoMeta->GetWidth(), pVideoMeta->GetHeight());
1916                                         pBitmap->Scale(srcDim);
1917                                         delete pVideoMeta;
1918                                 }
1919                         }
1920                 }
1921                 else
1922                 {
1923                         Canvas mainCanvas;
1924                         mainCanvas.Construct(DUMMY_IMAGE_RECTANGLE);
1925                         mainCanvas.FillRectangle(Color::GetColor(COLOR_ID_WHITE), DUMMY_IMAGE_RECTANGLE);
1926                         pBitmap = new (std::nothrow) Bitmap();
1927                         pBitmap->Construct(mainCanvas, DUMMY_IMAGE_RECTANGLE);
1928                 }
1929         }
1930         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1931         return pBitmap;
1932 }