2 * Copyright 2010, Haiku, Inc. All Rights Reserved.
3 * Copyright 2008-2009, Pier Luigi Fiorini. All Rights Reserved.
4 * Copyright 2004-2008, Michael Davidson. All Rights Reserved.
5 * Copyright 2004-2007, Mikael Eiman. All Rights Reserved.
6 * Distributed under the terms of the MIT License.
9 * Michael Davidson, slaad@bong.com.au
10 * Mikael Eiman, mikael@eiman.tv
11 * Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
15 #include <Notification.h>
16 #include <NotificationReceived.h>
18 const type_code kTypeCode
= 'ipnt';
21 NotificationReceived::NotificationReceived()
24 fType(B_INFORMATION_NOTIFICATION
),
26 fLastReceived(time(NULL
))
31 NotificationReceived::NotificationReceived(const char* title
,
32 notification_type type
, bool enabled
)
37 fLastReceived(time(NULL
))
42 NotificationReceived::~NotificationReceived()
48 NotificationReceived::AllowsTypeCode(type_code code
) const
50 return code
== kTypeCode
;
55 NotificationReceived::Flatten(void* buffer
, ssize_t numBytes
) const
58 msg
.AddString("notify_title", fTitle
);
59 msg
.AddInt32("notify_type", (int32
)fType
);
60 msg
.AddInt32("notify_lastreceived", (int32
)fLastReceived
);
61 msg
.AddBool("notify_enabled", fEnabled
);
63 if (numBytes
< msg
.FlattenedSize())
66 return msg
.Flatten((char*)buffer
, numBytes
);
71 NotificationReceived::FlattenedSize() const
74 msg
.AddString("notify_title", fTitle
);
75 msg
.AddInt32("notify_type", (int32
)fType
);
76 msg
.AddInt32("notify_lastreceived", (int32
)fLastReceived
);
77 msg
.AddBool("notify_enabled", fEnabled
);
79 return msg
.FlattenedSize();
84 NotificationReceived::IsFixedSize() const
91 NotificationReceived::TypeCode() const
98 NotificationReceived::Unflatten(type_code code
, const void* buffer
,
101 if (code
!= kTypeCode
)
105 status_t error
= msg
.Unflatten((const char*)buffer
);
108 msg
.FindString("notify_title", &fTitle
);
109 msg
.FindInt32("notify_type", (int32
*)&fType
);
110 msg
.FindInt32("notify_lastreceived", (int32
*)&fLastReceived
);
111 msg
.FindBool("notify_enabled", &fEnabled
);
119 NotificationReceived::Title()
121 return fTitle
.String();
126 NotificationReceived::Type()
133 NotificationReceived::SetType(notification_type type
)
140 NotificationReceived::LastReceived()
142 return fLastReceived
;
147 NotificationReceived::Allowed()
154 NotificationReceived::UpdateTimeStamp()
156 fLastReceived
= time(NULL
);
161 NotificationReceived::SetTimeStamp(time_t time
)
163 fLastReceived
= time
;