Add SetAction() for AbstractItem
[platform/core/api/notification.git] / notification-ex / abstract_item.h
1 /*
2  * Copyright (c) 2019 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 #ifndef NOTIFICATION_EX_ABSTRACT_ITEM_H_
18 #define NOTIFICATION_EX_ABSTRACT_ITEM_H_
19
20 #include <time.h>
21
22 #include <memory>
23 #include <string>
24 #include <list>
25
26 #include "notification-ex/abstract_action.h"
27 #include "notification-ex/ex_bundle.h"
28 #include "notification-ex/iitem_info.h"
29
30 #ifndef EXPORT_API
31 #define EXPORT_API __attribute__((visibility("default")))
32 #endif
33
34 namespace notification {
35 namespace item {
36
37 class EXPORT_API Color {
38  public:
39   Color() {
40     a_ = 0;
41     r_ = 0;
42     g_ = 0;
43     b_ = 0;
44   }
45   Color(unsigned char a, unsigned char r, unsigned char g, unsigned char b)
46     : a_(a), r_(r), g_(g), b_(b) {
47   }
48   virtual ~Color() = default;
49
50   unsigned char GetAVal() const {
51     return a_;
52   }
53   unsigned char GetRVal() const {
54     return r_;
55   }
56   unsigned char GetGVal() const {
57     return g_;
58   }
59   unsigned char GetBVal() const {
60     return b_;
61   }
62
63  private:
64   unsigned char a_;
65   unsigned char r_;
66   unsigned char g_;
67   unsigned char b_;
68 };  // class Color
69
70 class EXPORT_API Padding {
71  public:
72   Padding() {
73     left_ = 0;
74     top_ = 0;
75     right_ = 0;
76     bottom_ = 0;
77   }
78   Padding(int left, int top, int right, int bottom)
79     : left_(left), top_(top), right_(right), bottom_(bottom) {
80   }
81   virtual ~Padding() = default;
82
83   int GetLeft() const {
84     return left_;
85   }
86   int GetTop() const {
87     return top_;
88   }
89   int GetRight() const {
90     return right_;
91   }
92   int GetBottom() const {
93     return bottom_;
94   }
95
96  private:
97   int left_;
98   int top_;
99   int right_;
100   int bottom_;
101 };  // class  Padding
102
103 class EXPORT_API Geometry {
104  public:
105   Geometry() {
106     x_ = 0;
107     y_ = 0;
108     w_ = 0;
109     h_ = 0;
110   }
111   Geometry(int x, int y, int w, int h) : x_(x), y_(y), w_(w), h_(h) {
112   }
113   virtual ~Geometry() = default;
114
115   int GetX() const {
116     return x_;
117   }
118   int GetY() const {
119     return y_;
120   }
121   int GetWidth() const {
122     return w_;
123   }
124   int GetHeight() const {
125     return h_;
126   }
127
128  private:
129   int x_;
130   int y_;
131   int w_;
132   int h_;
133 };  // class Geometry
134
135 class EXPORT_API Style {
136  public:
137   Style() {
138   }
139   Style(Color color, Padding padding, Geometry geometry)
140     : color_(color), padding_(padding), geometry_(geometry) {
141   }
142   virtual ~Style() = default;
143
144   Padding GetPadding() const {
145     return padding_;
146   }
147   Color GetColor() const {
148     return color_;
149   }
150   Geometry GetGeometry() const {
151     return geometry_;
152   }
153
154  private:
155   Color color_;
156   Padding padding_;
157   Geometry geometry_;
158 };  // class Style
159
160 class EXPORT_API LEDInfo {
161  public:
162   LEDInfo() {
163     Color(0, 0, 0, 0);
164   }
165   explicit LEDInfo(Color color)
166     : color_(color) {
167   }
168   virtual ~LEDInfo() = default;
169
170   void SetOnPeriod(int ms) {
171     on_period_ = ms;
172   }
173   int GetOnPeriod() const {
174     return on_period_;
175   }
176   void SetOffPeriod(int ms) {
177     off_period_ = ms;
178   }
179   int GetOffPeriod() const {
180     return off_period_;
181   }
182
183   Color GetColor() const {
184     return color_;
185   }
186
187  private:
188   Color color_;
189   int on_period_ = 0;
190   int off_period_ = 0;
191 };  // clss LEDInfo
192
193 class EXPORT_API AbstractItem {
194  public:
195   enum Type {
196     NullObject,
197     Text,
198     Image,
199     Icon,
200     Button,
201     ChatMessage,
202     CheckBox,
203     IconText,
204     InputSelector,
205     Group,
206     Entry,
207     Progress,
208     Time,
209     Custom = 100
210   };
211
212   enum Policy {
213     None,
214     OnBootClear,
215     SimMode,
216   };
217
218  public:
219   AbstractItem(
220       std::shared_ptr<AbstractAction> action = std::shared_ptr<AbstractAction>({}));
221   AbstractItem(std::string id,
222       std::shared_ptr<AbstractAction> action = std::shared_ptr<AbstractAction>({}));
223   virtual ~AbstractItem() = 0;
224   virtual Bundle Serialize() const = 0;
225   virtual void Deserialize(Bundle b) = 0;
226   virtual AbstractItem& FindByID(std::string id) = 0;
227   virtual int GetType() const = 0;
228   static int GetType(Bundle b);
229   virtual std::list<std::string> GetSharedPath() const;
230   std::string GetId() const;
231   void SetId(std::string id);
232   std::shared_ptr<AbstractAction> GetAction() const;
233   void SetAction(std::shared_ptr<AbstractAction> action);
234   std::shared_ptr<Style> GetStyle() const;
235   void SetStyle(std::shared_ptr<Style> style);
236   void SetVisible(bool visible);
237   bool GetVisible() const;
238   void SetEnable(bool enable);
239   bool GetEnable() const;
240   void AddReceiver(std::string receiver_group);
241   void RemoveReceiver(std::string receiver_group);
242   std::list<std::string> GetReceiverList();
243   bool CanReceive(std::string id) const;
244   void SetPolicy(Policy policy);
245   Policy GetPolicy() const;
246   std::string GetChannel() const;
247   void SetChannel(std::string channel);
248   void SetLEDInfo(std::shared_ptr<LEDInfo> led);
249   std::shared_ptr<LEDInfo> GetLEDInfo() const;
250   void SetSoundPath(std::string path);
251   void SetVibrationPath(std::string path);
252   std::string GetSoundPath() const;
253   std::string GetVibrationPath() const;
254   std::shared_ptr<IItemInfo> GetInfo() const;
255   std::string GetSenderAppId() const;
256   void SetSenderAppId(std::string sender_appid);
257   std::string GetTag();
258   void SetTag();
259
260  private:
261   class Impl;
262   std::unique_ptr<Impl> impl_;
263 };  // class AbstractItem
264
265 }  // namespace item
266 }  // namespace notification
267
268 #endif  // NOTIFICATION_EX_ABSTRACT_ITEM_H_