tizen beta release
[framework/web/wrt-plugins-common.git] / src / modules / tizen / DEPRACATED / Gallery / GalleryRequestManager.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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  * @file        GalleryRequestManager.cpp
18  * @author      Wojciech Bielawski (w.bielawski@samsung.com)
19  * @version     0.1
20  */
21
22 #include <commons/Exception.h>
23 #include <API/Gallery/IGallery.h>
24 #include "GalleryRequestManager.h"
25 #include "Gallery.h"
26
27 using namespace WrtPlugins::Commons;
28 using namespace WrtPlugins::Api::Gallery;
29
30 namespace WrtPlugins {
31 namespace Platform {
32 void GalleryRequestManager::OnRequestReceived(
33         const IEventGetGalleriesPtr &event)
34 {
35     IGallerySetPtr galleries(new IGallerySet());
36     galleries->push_back(IGalleryPtr(new Gallery("Device")));
37     event->setGalleries(galleries);
38     event->setResult(ExceptionCodes::None);
39 }
40
41 void GalleryRequestManager::OnRequestReceived(const IEventOpenPtr &event)
42 {
43     Try
44     {
45         IGalleryPtr gallery(event->getGallery());
46         gallery->open();
47         event->setResult(ExceptionCodes::None);
48     }
49     Catch(Exception)
50     {
51         LogError("Gallery exception message: " <<
52                  _rethrown_exception.GetMessage() <<
53                  " Code: " << _rethrown_exception.getCode());
54         event->setResult(_rethrown_exception.getCode());
55     }
56 }
57
58 void GalleryRequestManager::OnRequestReceived(const IEventRefreshPtr &event)
59 {
60     Try
61     {
62         IGalleryPtr gallery(event->getGallery());
63         gallery->refresh();
64         event->setResult(ExceptionCodes::None);
65     }
66     Catch(Exception)
67     {
68         LogError("Gallery exception message: " <<
69                  _rethrown_exception.GetMessage() <<
70                  " Code: " << _rethrown_exception.getCode());
71         event->setResult(_rethrown_exception.getCode());
72     }
73 }
74
75 void GalleryRequestManager::OnRequestReceived(const IEventClosePtr &event)
76 {
77     Try
78     {
79         IGalleryPtr gallery(event->getGallery());
80         gallery->close();
81         event->setResult(ExceptionCodes::None);
82     }
83     Catch(Exception)
84     {
85         LogError("Gallery exception message: " <<
86                  _rethrown_exception.GetMessage() <<
87                  " Code: " << _rethrown_exception.getCode());
88         event->setResult(_rethrown_exception.getCode());
89     }
90 }
91
92 void GalleryRequestManager::OnRequestReceived(const IEventChangeViewPtr &event)
93 {
94     Try
95     {
96         IGalleryPtr gallery(event->getGallery());
97         gallery->changeView(event->getProperties());
98         event->setResult(ExceptionCodes::None);
99     }
100     Catch(Exception)
101     {
102         LogError("Gallery exception message: " <<
103                  _rethrown_exception.GetMessage() <<
104                  " Code: " << _rethrown_exception.getCode());
105         event->setResult(_rethrown_exception.getCode());
106     }
107 }
108
109 void GalleryRequestManager::OnRequestReceived(
110         const IEventGetMediaItemsPtr &event)
111 {
112     Try
113     {
114         IGalleryPtr gallery(event->getGallery());
115         IMediaItemsSetPtr mediaItems(gallery->getMediaItems());
116         event->setMediaItems(mediaItems);
117         event->setResult(ExceptionCodes::None);
118     }
119     Catch(Exception)
120     {
121         LogError("Gallery exception message: " <<
122                  _rethrown_exception.GetMessage() <<
123                  " Code: " << _rethrown_exception.getCode());
124         event->setResult(_rethrown_exception.getCode());
125     }
126 }
127
128 void GalleryRequestManager::OnRequestReceived(
129         const IEventGetMediaItemByIdPtr &event)
130 {
131     Try
132     {
133         IGalleryPtr gallery(event->getGallery());
134         IMediaItemPtr mediaItem(gallery->getMediaItemById(event->getId()));
135         event->setMediaItem(mediaItem);
136         event->setResult(ExceptionCodes::None);
137     }
138     Catch(Exception)
139     {
140         LogError("Gallery exception message: " <<
141                  _rethrown_exception.GetMessage() <<
142                  " Code: " << _rethrown_exception.getCode());
143         event->setResult(_rethrown_exception.getCode());
144     }
145 }
146 }
147 }