Rename DeviceProviderBase as BasicProvider
[platform/core/context/context-provider.git] / src / email / Email.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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 #include <email-api-etc.h>
18 #include "Email.h"
19
20 using namespace ctx;
21
22 SocialStatusEmail::SocialStatusEmail()  :
23         BasicProvider(SOCIAL_ST_SUBJ_EMAIL),
24         __dbusSignalId(-1),
25         __dbusWatcher(DBusType::SESSION)
26 {
27 }
28
29 SocialStatusEmail::~SocialStatusEmail()
30 {
31 }
32
33 bool SocialStatusEmail::isSupported()
34 {
35         return getSystemInfoBool("tizen.org/feature/network.telephony");
36 }
37
38 void SocialStatusEmail::submitTriggerItem()
39 {
40         registerTriggerItem(OPS_SUBSCRIBE,
41                         "{"
42                                 "\"Event\":{\"type\":\"string\",\"values\":[\"Received\",\"Sent\"]}"
43                         "}",
44                         NULL);
45 }
46
47 void SocialStatusEmail::onSignal(const char* sender, const char* path, const char* iface, const char* name, GVariant* param)
48 {
49         gint subType = 0;
50         gint gi1 = 0;
51         const gchar *gc = NULL;
52         gint gi2 = 0;
53         gint gi3 = 0;
54
55         g_variant_get(param, "(ii&sii)", &subType, &gi1, &gc, &gi2, &gi3);
56
57         if (subType == NOTI_DOWNLOAD_FINISH) {
58                 //TODO: Check if this signal actually means that there are new mails
59                 _D("sub type: %d, gi1: %d, gc: %s, gi2: %d, gi3: %d", subType, gi1, gc, gi2, gi3);
60                 Json dataUpdated;
61                 dataUpdated.set(NULL, SOCIAL_ST_EVENT, SOCIAL_ST_RECEIVED);
62                 publish(NULL, ERR_NONE, dataUpdated);
63
64         } else if (subType == NOTI_SEND_FINISH) {
65                 _D("sub type: %d, gi1: %d, gc: %s, gi2: %d, gi3: %d", subType, gi1, gc, gi2, gi3);
66                 Json dataUpdated;
67                 dataUpdated.set(NULL, SOCIAL_ST_EVENT, SOCIAL_ST_SENT);
68                 publish(NULL, ERR_NONE, dataUpdated);
69         }
70 }
71
72
73 int SocialStatusEmail::subscribe()
74 {
75         __dbusSignalId = __dbusWatcher.watch(NULL, NULL, "User.Email.NetworkStatus", "email", this);
76         IF_FAIL_RETURN_TAG(__dbusSignalId >= 0, ERR_OPERATION_FAILED, _E, "Email dbus signal subscription failed");
77         return ERR_NONE;
78 }
79
80
81 int SocialStatusEmail::unsubscribe()
82 {
83         __dbusWatcher.unwatch(__dbusSignalId);
84         return ERR_NONE;
85 }