| 24 |
24 |
| 25 #include <purple.h> |
25 #include <purple.h> |
| 26 |
26 |
| 27 #include "pidgin/pidginnotificationlist.h" |
27 #include "pidgin/pidginnotificationlist.h" |
| 28 |
28 |
| |
29 #include "pidgin/pidginnotifiable.h" |
| 29 #include "pidgin/pidginnotificationaddcontact.h" |
30 #include "pidgin/pidginnotificationaddcontact.h" |
| 30 #include "pidgin/pidginnotificationauthorizationrequest.h" |
31 #include "pidgin/pidginnotificationauthorizationrequest.h" |
| 31 #include "pidgin/pidginnotificationconnectionerror.h" |
32 #include "pidgin/pidginnotificationconnectionerror.h" |
| 32 |
33 |
| |
34 enum { |
| |
35 PROP_0, |
| |
36 N_PROPERTIES, |
| |
37 /* Overrides */ |
| |
38 PROP_NEEDS_ATTENTION = N_PROPERTIES, |
| |
39 PROP_NOTIFICATION_COUNT, |
| |
40 }; |
| |
41 /* There's no global properties because we only have overrides right now. */ |
| |
42 |
| 33 struct _PidginNotificationList { |
43 struct _PidginNotificationList { |
| 34 GtkBox parent; |
44 GtkBox parent; |
| 35 |
45 |
| 36 GtkStack *stack; |
46 GtkStack *stack; |
| 37 GtkSingleSelection *selection_model; |
47 GtkSingleSelection *selection_model; |
| 38 }; |
48 }; |
| 39 |
|
| 40 G_DEFINE_FINAL_TYPE(PidginNotificationList, pidgin_notification_list, |
|
| 41 GTK_TYPE_BOX) |
|
| 42 |
49 |
| 43 /****************************************************************************** |
50 /****************************************************************************** |
| 44 * Helpers |
51 * Helpers |
| 45 *****************************************************************************/ |
52 *****************************************************************************/ |
| 46 static gboolean |
53 static gboolean |
| 100 NULL); |
107 NULL); |
| 101 |
108 |
| 102 return row; |
109 return row; |
| 103 } |
110 } |
| 104 |
111 |
| |
112 static guint |
| |
113 pidgin_notification_list_get_count(PidginNotificationList *list) { |
| |
114 g_return_val_if_fail(PIDGIN_IS_NOTIFICATION_LIST(list), 0); |
| |
115 |
| |
116 return g_list_model_get_n_items(G_LIST_MODEL(list->selection_model)); |
| |
117 } |
| |
118 |
| |
119 static gboolean |
| |
120 pidgin_notification_list_get_needs_attention(PidginNotificationList *list) { |
| |
121 guint count = 0; |
| |
122 |
| |
123 g_return_val_if_fail(PIDGIN_IS_NOTIFICATION_LIST(list), FALSE); |
| |
124 |
| |
125 count = g_list_model_get_n_items(G_LIST_MODEL(list->selection_model)); |
| |
126 |
| |
127 return (count > 0); |
| |
128 } |
| |
129 |
| 105 /****************************************************************************** |
130 /****************************************************************************** |
| 106 * Callbacks |
131 * Callbacks |
| 107 *****************************************************************************/ |
132 *****************************************************************************/ |
| 108 static void |
133 static void |
| 109 pidgin_notification_list_items_changed_cb(GListModel *model, |
134 pidgin_notification_list_items_changed_cb(GListModel *model, |
| 111 G_GNUC_UNUSED guint added, |
136 G_GNUC_UNUSED guint added, |
| 112 G_GNUC_UNUSED guint removed, |
137 G_GNUC_UNUSED guint removed, |
| 113 gpointer data) |
138 gpointer data) |
| 114 { |
139 { |
| 115 PidginNotificationList *list = data; |
140 PidginNotificationList *list = data; |
| |
141 GObject *obj = G_OBJECT(list); |
| 116 |
142 |
| 117 if(g_list_model_get_n_items(model) != 0) { |
143 if(g_list_model_get_n_items(model) != 0) { |
| 118 gtk_stack_set_visible_child_name(list->stack, "view"); |
144 gtk_stack_set_visible_child_name(list->stack, "view"); |
| 119 } else { |
145 } else { |
| 120 gtk_stack_set_visible_child_name(list->stack, "placeholder"); |
146 gtk_stack_set_visible_child_name(list->stack, "placeholder"); |
| 121 } |
147 } |
| |
148 |
| |
149 g_object_freeze_notify(obj); |
| |
150 g_object_notify(obj, "needs-attention"); |
| |
151 g_object_notify(obj, "notification-count"); |
| |
152 g_object_thaw_notify(obj); |
| 122 } |
153 } |
| 123 |
154 |
| 124 static void |
155 static void |
| 125 pidgin_notification_list_bind_cb(G_GNUC_UNUSED GtkSignalListItemFactory *self, |
156 pidgin_notification_list_bind_cb(G_GNUC_UNUSED GtkSignalListItemFactory *self, |
| 126 GObject *object, |
157 GObject *object, |
| 156 |
187 |
| 157 gtk_list_item_set_child(item, widget); |
188 gtk_list_item_set_child(item, widget); |
| 158 } |
189 } |
| 159 |
190 |
| 160 /****************************************************************************** |
191 /****************************************************************************** |
| |
192 * PidginNotifiable Implementation |
| |
193 *****************************************************************************/ |
| |
194 static void |
| |
195 pidgin_notification_list_notifiable_init(G_GNUC_UNUSED PidginNotifiableInterface *iface) { |
| |
196 } |
| |
197 |
| |
198 /****************************************************************************** |
| 161 * GObject Implementation |
199 * GObject Implementation |
| 162 *****************************************************************************/ |
200 *****************************************************************************/ |
| |
201 G_DEFINE_FINAL_TYPE_WITH_CODE( |
| |
202 PidginNotificationList, |
| |
203 pidgin_notification_list, |
| |
204 GTK_TYPE_BOX, |
| |
205 G_IMPLEMENT_INTERFACE(PIDGIN_TYPE_NOTIFIABLE, pidgin_notification_list_notifiable_init)) |
| |
206 |
| |
207 static void |
| |
208 pidgin_notification_list_get_property(GObject *obj, guint param_id, |
| |
209 GValue *value, GParamSpec *pspec) |
| |
210 { |
| |
211 PidginNotificationList *list = PIDGIN_NOTIFICATION_LIST(obj); |
| |
212 |
| |
213 switch(param_id) { |
| |
214 case PROP_NEEDS_ATTENTION: |
| |
215 g_value_set_boolean(value, |
| |
216 pidgin_notification_list_get_needs_attention(list)); |
| |
217 break; |
| |
218 case PROP_NOTIFICATION_COUNT: |
| |
219 g_value_set_uint(value, pidgin_notification_list_get_count(list)); |
| |
220 break; |
| |
221 default: |
| |
222 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); |
| |
223 break; |
| |
224 } |
| |
225 } |
| |
226 |
| 163 static void |
227 static void |
| 164 pidgin_notification_list_init(PidginNotificationList *list) { |
228 pidgin_notification_list_init(PidginNotificationList *list) { |
| 165 GListModel *model = NULL; |
229 GListModel *model = NULL; |
| 166 |
230 |
| 167 gtk_widget_init_template(GTK_WIDGET(list)); |
231 gtk_widget_init_template(GTK_WIDGET(list)); |
| 174 pidgin_notification_list_items_changed_cb(model, 0, 0, 0, list); |
238 pidgin_notification_list_items_changed_cb(model, 0, 0, 0, list); |
| 175 } |
239 } |
| 176 |
240 |
| 177 static void |
241 static void |
| 178 pidgin_notification_list_class_init(PidginNotificationListClass *klass) { |
242 pidgin_notification_list_class_init(PidginNotificationListClass *klass) { |
| |
243 GObjectClass *obj_class = G_OBJECT_CLASS(klass); |
| 179 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); |
244 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); |
| |
245 |
| |
246 obj_class->get_property = pidgin_notification_list_get_property; |
| |
247 |
| |
248 g_object_class_override_property(obj_class, PROP_NEEDS_ATTENTION, |
| |
249 "needs-attention"); |
| |
250 g_object_class_override_property(obj_class, PROP_NOTIFICATION_COUNT, |
| |
251 "notification-count"); |
| 180 |
252 |
| 181 gtk_widget_class_set_template_from_resource( |
253 gtk_widget_class_set_template_from_resource( |
| 182 widget_class, |
254 widget_class, |
| 183 "/im/pidgin/Pidgin3/notificationlist.ui" |
255 "/im/pidgin/Pidgin3/notificationlist.ui" |
| 184 ); |
256 ); |