OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_MESSAGE_CENTER_NOTIFICATION_H_ | 5 #ifndef UI_MESSAGE_CENTER_NOTIFICATION_H_ |
6 #define UI_MESSAGE_CENTER_NOTIFICATION_H_ | 6 #define UI_MESSAGE_CENTER_NOTIFICATION_H_ |
7 | 7 |
8 #include <string> | |
8 #include <vector> | 9 #include <vector> |
9 | 10 |
10 #include "base/string16.h" | 11 #include "base/string16.h" |
11 #include "base/time.h" | 12 #include "base/time.h" |
13 #include "base/values.h" | |
12 #include "ui/gfx/image/image_skia.h" | 14 #include "ui/gfx/image/image_skia.h" |
13 #include "ui/message_center/message_center_export.h" | 15 #include "ui/message_center/message_center_export.h" |
14 #include "ui/notifications/notification_types.h" | 16 #include "ui/message_center/notification_types.h" |
15 | 17 |
16 namespace message_center { | 18 namespace message_center { |
17 | 19 |
18 struct MESSAGE_CENTER_EXPORT NotificationItem { | 20 struct MESSAGE_CENTER_EXPORT NotificationItem { |
19 string16 title; | 21 string16 title; |
20 string16 message; | 22 string16 message; |
21 | 23 |
22 NotificationItem(string16 title, string16 message); | 24 NotificationItem(const string16& title, const string16& message); |
23 }; | 25 }; |
24 | 26 |
25 struct MESSAGE_CENTER_EXPORT Notification { | 27 struct MESSAGE_CENTER_EXPORT ButtonInfo { |
26 Notification(); | 28 string16 title; |
29 gfx::ImageSkia icon; | |
30 | |
31 ButtonInfo(const string16& title); | |
32 }; | |
33 | |
34 class MESSAGE_CENTER_EXPORT Notification { | |
35 public: | |
36 Notification(NotificationType type, | |
37 const std::string& id, | |
38 const string16& title, | |
39 const string16& message, | |
40 const string16& display_source, | |
41 const std::string& extension_id, | |
42 const DictionaryValue* optional_fields); // May be NULL. | |
27 virtual ~Notification(); | 43 virtual ~Notification(); |
28 | 44 |
29 ui::notifications::NotificationType type; | 45 NotificationType type() const { return type_; } |
30 std::string id; | 46 const std::string& id() const { return id_; } |
31 string16 title; | 47 const string16& title() const { return title_; } |
32 string16 message; | 48 const string16& message() const { return message_; } |
33 string16 display_source; | 49 const string16& display_source() const { return display_source_; } |
34 std::string extension_id; | 50 const std::string& extension_id() const { return extension_id_; } |
35 | 51 |
36 // Begin unpacked values from optional_fields | 52 // Begin unpacked values from optional_fields. |
37 int priority; | 53 int priority() { return priority_; } |
38 base::Time timestamp; | 54 base::Time timestamp() const { return timestamp_; } |
39 int unread_count; | 55 int unread_count() const { return unread_count_; } |
40 std::vector<string16> button_titles; | 56 const string16& expanded_message() const { return expanded_message_; } |
41 string16 expanded_message; | 57 const std::vector<NotificationItem>& items() const { return items_; } |
42 std::vector<NotificationItem> items; | 58 // End unpacked values. |
43 // End unpacked values | |
44 | 59 |
45 // Images fetched asynchronously | 60 // Images fetched asynchronously. |
46 gfx::ImageSkia primary_icon; | 61 const gfx::ImageSkia& primary_icon() const { return primary_icon_; } |
47 gfx::ImageSkia image; | 62 void set_primary_icon(const gfx::ImageSkia& icon) { primary_icon_ = icon; } |
48 std::vector<gfx::ImageSkia> button_icons; | |
49 | 63 |
50 bool is_read; // True if this has been seen in the message center | 64 const gfx::ImageSkia& image() const { return image_; } |
51 bool shown_as_popup; // True if this has been shown as a popup notification | 65 void set_image(const gfx::ImageSkia& image) { image_ = image; } |
66 | |
67 // Buttons, with icons fetched asynchronously. | |
68 const std::vector<ButtonInfo>& buttons() const { return buttons_; } | |
69 bool SetButtonIcon(size_t index, const gfx::ImageSkia& icon); | |
70 | |
71 // Status in MessageCenter. | |
72 bool is_read() const { return is_read_; } | |
73 void set_is_read(bool is_read) { is_read_ = is_read; } | |
74 | |
75 bool shown_as_popup() const { return shown_as_popup_; } | |
76 void set_shown_as_popup(bool shown_as_popup) { | |
77 shown_as_popup_ = shown_as_popup; | |
78 } | |
79 | |
80 // Used to keep the order of notificaitons with the same timestamp. | |
dewittj
2013/02/20 23:47:54
spelling notificaiton->notification
Dmitry Titov
2013/02/23 00:58:51
Done.
| |
81 // The notification with lesser serial_number is considered 'older'. | |
82 unsigned serial_number() { return serial_number_; } | |
83 | |
84 private: | |
85 // Unpacks the provided |optional_fields| and applies the values to override | |
86 // the notificaiton's data members. | |
dewittj
2013/02/20 23:47:54
notificaiton->notification
miket_OOO
2013/02/22 21:07:09
It might be easier to set up a nightly cron job ov
Dmitry Titov
2013/02/23 00:58:51
Done.
Dmitry Titov
2013/02/23 00:58:51
Next time we build an IDE, we should built the spe
| |
87 void ApplyOptionalFields(const DictionaryValue* optional_fields); | |
88 | |
89 NotificationType type_; | |
90 std::string id_; | |
91 string16 title_; | |
92 string16 message_; | |
93 string16 display_source_; | |
94 std::string extension_id_; | |
95 int priority_; | |
96 base::Time timestamp_; | |
97 unsigned serial_number_; | |
98 int unread_count_; | |
99 string16 expanded_message_; | |
100 std::vector<NotificationItem> items_; | |
101 gfx::ImageSkia primary_icon_; | |
102 gfx::ImageSkia image_; | |
103 std::vector<ButtonInfo> buttons_; | |
104 bool is_read_; // True if this has been seen in the message center. | |
105 bool shown_as_popup_; // True if this has been shown as a popup notification. | |
106 | |
107 DISALLOW_COPY_AND_ASSIGN(Notification); | |
52 }; | 108 }; |
53 | 109 |
54 } // namespace message_center | 110 } // namespace message_center |
55 | 111 |
56 #endif // UI_MESSAGE_CENTER_NOTIFICATION_H_ | 112 #endif // UI_MESSAGE_CENTER_NOTIFICATION_H_ |
OLD | NEW |