Separated ICO System Controller from HomeScreen.
[profile/ivi/ico-uxf-homescreen.git] / tool / notification / send_notification.cpp
1 #include <cstdio>
2 #include <iostream>
3 #include <string>
4 #include <functional>
5 #include <algorithm>
6 #include "notification.h"
7 using namespace std;
8
9 const char *
10 errorToString(notification_error_e error)
11 {
12     const char *strerr = NULL;
13
14     switch (error) {
15     case NOTIFICATION_ERROR_NONE:
16         strerr = "NOTIFICATION_ERROR_NONE";
17         break;
18     case NOTIFICATION_ERROR_INVALID_DATA:
19         strerr = "NOTIFICATION_ERROR_INVALID_DATA";
20         break;
21     case NOTIFICATION_ERROR_NO_MEMORY:
22         strerr = "NOTIFICATION_ERROR_NO_MEMORY";
23         break;
24     case NOTIFICATION_ERROR_FROM_DB:
25         strerr = "NOTIFICATION_ERROR_FROM_DB";
26         break;
27     case NOTIFICATION_ERROR_ALREADY_EXIST_ID:
28         strerr = "NOTIFICATION_ERROR_ALREADY_EXIST_ID";
29         break;
30     case NOTIFICATION_ERROR_FROM_DBUS:
31         strerr = "NOTIFICATION_ERROR_FROM_DBUS";
32         break;
33     case NOTIFICATION_ERROR_NOT_EXIST_ID:
34         strerr = "NOTIFICATION_ERROR_NOT_EXIST_ID";
35         break;
36     case NOTIFICATION_ERROR_IO:
37         strerr = "NOTIFICATION_ERROR_IO";
38         break;
39     case NOTIFICATION_ERROR_SERVICE_NOT_READY:
40         strerr = "NOTIFICATION_ERROR_SERVICE_NOT_READY";
41         break;
42     case NOTIFICATION_ERROR_PERMISSION_DENIED:
43         strerr = "NOTIFICATION_ERROR_PERMISSION_DENIED";
44         break;
45     default:
46         strerr = "UNKOWN";
47         break;
48     }
49
50     return strerr;
51 }
52
53 int
54 insert_notification(notification_type_e type,
55                     int group_id,
56                     int priv_id,
57                     const char *pkgname,
58                     const char *title,
59                     const char *content,
60                     const char *icon)
61 {
62     notification_h noti = notification_new(type,
63                                            group_id,
64                                            priv_id);
65     if (NULL == noti) {
66         cout << "notification_new() failed." << endl;
67         return -1;
68     }
69
70     //set Pkgname
71     if (NULL == pkgname) {
72         return -1;
73     }
74
75     notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
76
77     noti_err = notification_set_pkgname(noti, pkgname);
78     if (noti_err != NOTIFICATION_ERROR_NONE) {
79         printf("notification_set_pkgname failed(%s).\n",
80                errorToString(noti_err));
81         return -1;
82     }
83      
84     //set Title 
85     if (NULL == title) {
86         return -1;
87     }
88     noti_err = notification_set_text(noti,
89                                      NOTIFICATION_TEXT_TYPE_TITLE,
90                                      title,
91                                      NULL,
92                                      NOTIFICATION_VARIABLE_TYPE_NONE);
93     if (noti_err != NOTIFICATION_ERROR_NONE) {
94         cout << "Failed to set notification title <error code>:"<< noti_err<<endl;
95         return -1;
96     }
97     
98     //set Content
99     if (NULL == content) {
100         return -1;
101     }
102     noti_err = notification_set_text(noti,
103                                      NOTIFICATION_TEXT_TYPE_CONTENT,
104                                      content,
105                                      NULL,
106                                      NOTIFICATION_VARIABLE_TYPE_NONE);
107     if (noti_err != NOTIFICATION_ERROR_NONE) {
108         cout << "Failed to set notification content <error code>:"<< noti_err<<endl;
109         return -1;
110     }
111     
112     //set Icon_path 
113     if (NULL == icon) {
114         return -1;
115     }
116     noti_err = notification_set_icon(noti, icon);
117     if (noti_err != NOTIFICATION_ERROR_NONE) {
118         cout <<"Failed to set icon_path <error code>:"<< noti_err <<endl;
119             return -1;
120     }
121
122     //insert to DB and appear on the notification_area
123     //noti_err = notification_update(noti);
124     int private_id = 0;
125     noti_err = notification_insert(noti, &private_id);
126     if (noti_err != NOTIFICATION_ERROR_NONE) {
127         printf("notification_insert failed(%s).\n",
128                errorToString(noti_err));
129         return -1;
130     } 
131
132     //free to notification
133     noti_err = notification_free(noti);
134     if (noti_err != NOTIFICATION_ERROR_NONE) {
135         cout <<"Failed to free notification <error code>:"<< noti_err <<endl;
136         return -1;
137     } 
138  
139     return 0;
140
141
142 int
143 main(int argc, char **argv)
144 {
145     const char* msgTyp = "TYPE_NOTI";
146     notification_type_e nType = NOTIFICATION_TYPE_NOTI;
147     
148     if (argc == 2) {
149         string sargv1(argv[1]);
150         if (0 == sargv1.compare("--ongoing")) {
151             msgTyp = "TYPE_ONGOING";
152             nType = NOTIFICATION_TYPE_ONGOING;
153         }
154     }
155
156     cout << "Notification TestProgram Start("<<msgTyp<<")=========" <<endl;
157     
158     insert_notification(nType,
159                         NOTIFICATION_GROUP_ID_DEFAULT,
160                         NOTIFICATION_PRIV_ID_NONE,
161                         "org.tizen.dialer",
162                         "test_title",
163                         "0123456789012345678901234",
164                         "/usr/share/icons/default/small/org.tizen.dialer.png");
165
166     insert_notification(nType,
167                         NOTIFICATION_GROUP_ID_NONE,
168                         NOTIFICATION_PRIV_ID_NONE,
169                         "GV3ySIINq7.GhostCluster",
170                         "test_title",
171                         "test_content",
172                         "/opt/share/icons/default/small/GV3ySIINq7.GhostCluster.png");
173
174     insert_notification(nType,
175                         NOTIFICATION_GROUP_ID_NONE,
176                         NOTIFICATION_PRIV_ID_NONE,
177                         "ODBQpKvkS1.Settings",
178                         "test_title",
179                         "test_content",
180                         "/opt/share/icons/default/small/ODBQpKvkS1.Settings.png");
181
182     insert_notification(nType,
183                         NOTIFICATION_GROUP_ID_NONE,
184                         NOTIFICATION_PRIV_ID_NONE,
185                         "lYjFlj49Q4.saythis",
186                         "test_title",
187                         "test_content",
188                         "/opt/share/icons/default/small/lYjFlj49Q4.saythis.png");
189
190     insert_notification(nType,
191                         NOTIFICATION_GROUP_ID_NONE,
192                         NOTIFICATION_PRIV_ID_NONE,
193                         "t8j6HTRpuz.MediaPlayer",
194                         "test_title",
195                         "test_content",
196                         "/opt/share/icons/default/small/t8j6HTRpuz.MediaPlayer.png");
197
198     cout << "Notification_TestProgram End!=========" <<endl;
199     return 0;
200 }