- add sources.
[platform/framework/web/crosswalk.git] / src / ui / message_center / notifier_settings.h
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
3 // found in the LICENSE file.
4
5 #ifndef UI_MESSAGE_CENTER_NOTIFIER_SETTINGS_H_
6 #define UI_MESSAGE_CENTER_NOTIFIER_SETTINGS_H_
7
8 #include <string>
9
10 #include "base/strings/string16.h"
11 #include "ui/gfx/image/image.h"
12 #include "ui/message_center/message_center_export.h"
13 #include "url/gurl.h"
14
15 namespace message_center {
16
17 class NotifierSettingsDelegate;
18 class NotifierSettingsProvider;
19
20 // Brings up the settings dialog and returns a weak reference to the delegate,
21 // which is typically the view. If the dialog already exists, it is brought to
22 // the front, otherwise it is created.
23 MESSAGE_CENTER_EXPORT NotifierSettingsDelegate* ShowSettings(
24     NotifierSettingsProvider* provider,
25     gfx::NativeView context);
26
27 // The struct to distinguish the notifiers.
28 struct MESSAGE_CENTER_EXPORT NotifierId {
29   enum NotifierType {
30     APPLICATION,
31     WEB_PAGE,
32     SYSTEM_COMPONENT,
33     SYNCED_NOTIFICATION_SERVICE,
34   };
35
36   // Constructor for APPLICATION and SYNCED_NOTIFICATION_SERVICE type.
37   NotifierId(NotifierType type, const std::string& id);
38
39   // Constructor for WEB_PAGE type.
40   explicit NotifierId(const GURL& url);
41
42   // Constructor for system component types. The type should be positive.
43   explicit NotifierId(int type);
44
45   // The default constructor which doesn't specify the notifier. Used for tests.
46   NotifierId();
47
48   bool operator==(const NotifierId& other) const;
49
50   NotifierType type;
51
52   // The identifier of the app notifier. Empty if it's not APPLICATION or
53   // SYNCED_NOTIFICATION_SERVICE.
54   std::string id;
55
56   // The URL pattern of the notifer.
57   GURL url;
58
59   // The type of system component notifier, usually used in ash. -1 if it's not
60   // the system component. See also: ash/system/system_notifier.h
61   int system_component_type;
62 };
63
64 // The struct to hold the information of notifiers. The information will be
65 // used by NotifierSettingsView.
66 struct MESSAGE_CENTER_EXPORT Notifier {
67   Notifier(const NotifierId& notifier_id, const string16& name, bool enabled);
68   ~Notifier();
69
70   NotifierId notifier_id;
71
72   // The human-readable name of the notifier such like the extension name.
73   // It can be empty.
74   string16 name;
75
76   // True if the source is allowed to send notifications. True is default.
77   bool enabled;
78
79   // The icon image of the notifier. The extension icon or favicon.
80   gfx::Image icon;
81
82  private:
83   DISALLOW_COPY_AND_ASSIGN(Notifier);
84 };
85
86 struct MESSAGE_CENTER_EXPORT NotifierGroup {
87   NotifierGroup(const gfx::Image& icon,
88                 const string16& name,
89                 const string16& login_info,
90                 size_t index);
91   ~NotifierGroup();
92
93   // Icon of a notifier group.
94   const gfx::Image icon;
95
96   // Display name of a notifier group.
97   const string16 name;
98
99   // More display information about the notifier group.
100   string16 login_info;
101
102   // Unique identifier for the notifier group so that they can be selected in
103   // the UI.
104   const size_t index;
105
106  private:
107   DISALLOW_COPY_AND_ASSIGN(NotifierGroup);
108 };
109
110 // An observer class implemented by the view of the NotifierSettings to get
111 // notified when the controller has changed data.
112 class MESSAGE_CENTER_EXPORT NotifierSettingsObserver {
113  public:
114   // Called when an icon in the controller has been updated.
115   virtual void UpdateIconImage(const NotifierId& notifier_id,
116                                const gfx::Image& icon) = 0;
117
118   // Called when any change happens to the set of notifier groups.
119   virtual void NotifierGroupChanged() = 0;
120 };
121
122 // A class used by NotifierSettingsView to integrate with a setting system
123 // for the clients of this module.
124 class MESSAGE_CENTER_EXPORT NotifierSettingsProvider {
125  public:
126   virtual ~NotifierSettingsProvider() {};
127
128   // Sets the delegate.
129   virtual void AddObserver(NotifierSettingsObserver* observer) = 0;
130   virtual void RemoveObserver(NotifierSettingsObserver* observer) = 0;
131
132   // Returns the number of notifier groups available.
133   virtual size_t GetNotifierGroupCount() const = 0;
134
135   // Requests the model for a particular notifier group.
136   virtual const message_center::NotifierGroup& GetNotifierGroupAt(
137       size_t index) const = 0;
138
139   // Returns true if the notifier group at |index| is active.
140   virtual bool IsNotifierGroupActiveAt(size_t index) const = 0;
141
142   // Informs the settings provider that further requests to GetNotifierList
143   // should return notifiers for the specified notifier group.
144   virtual void SwitchToNotifierGroup(size_t index) = 0;
145
146   // Requests the currently active notifier group.
147   virtual const message_center::NotifierGroup& GetActiveNotifierGroup()
148       const = 0;
149
150   // Collects the current notifier list and fills to |notifiers|. Caller takes
151   // the ownership of the elements of |notifiers|.
152   virtual void GetNotifierList(std::vector<Notifier*>* notifiers) = 0;
153
154   // Called when the |enabled| for the |notifier| has been changed by user
155   // operation.
156   virtual void SetNotifierEnabled(const Notifier& notifier, bool enabled) = 0;
157
158   // Called when the settings window is closed.
159   virtual void OnNotifierSettingsClosing() = 0;
160
161   // Called to determine if a particular notifier can respond to a request for
162   // more information.
163   virtual bool NotifierHasAdvancedSettings(const NotifierId& notifier_id)
164       const = 0;
165
166   // Called upon request for more information about a particular notifier.
167   virtual void OnNotifierAdvancedSettingsRequested(
168       const NotifierId& notifier_id,
169       const std::string* notification_id) = 0;
170 };
171
172 }  // namespace message_center
173
174 #endif  // UI_MESSAGE_CENTER_NOTIFIER_SETTINGS_H_