pidgin/pidginnotificationlist.c

changeset 41441
e114ed471a1e
child 41514
a96768bacb59
equal deleted inserted replaced
41440:348cc74f084e 41441:e114ed471a1e
1 /*
2 * Pidgin - Internet Messenger
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
4 *
5 * Pidgin is the legal property of its developers, whose names are too numerous
6 * to list here. Please refer to the COPYRIGHT file distributed with this
7 * source distribution.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, see <https://www.gnu.org/licenses/>.
21 */
22
23 #include <glib/gi18n-lib.h>
24
25 #include <purple.h>
26
27 #include "pidgin/pidginnotificationlist.h"
28
29 #include "pidgin/pidginnotificationconnectionerror.h"
30
31 struct _PidginNotificationList {
32 GtkBox parent;
33
34 GtkWidget *list_box;
35 };
36
37 G_DEFINE_TYPE(PidginNotificationList, pidgin_notification_list, GTK_TYPE_BOX)
38
39 /******************************************************************************
40 * Helpers
41 *****************************************************************************/
42 static GtkWidget *
43 pidgin_notification_list_unknown_notification(PurpleNotification *notification) {
44 GtkWidget *widget = NULL;
45 gchar *label = NULL;
46 const gchar *title = NULL;
47
48 title = purple_notification_get_title(notification);
49 if(title != NULL) {
50 label = g_strdup_printf(_("Unknown notification type %d: %s"),
51 purple_notification_get_notification_type(notification),
52 title);
53 } else {
54 label = g_strdup_printf(_("Unknown notification type %d"),
55 purple_notification_get_notification_type(notification));
56 }
57
58 widget = gtk_label_new(label);
59
60 g_free(label);
61
62 return widget;
63 }
64
65 static GtkWidget *
66 pidgin_notification_list_create_widget_func(gpointer item, gpointer data) {
67 PurpleNotification *notification = item;
68 GtkWidget *widget = NULL;
69
70 switch(purple_notification_get_notification_type(notification)) {
71 case PURPLE_NOTIFICATION_TYPE_CONNECTION_ERROR:
72 widget = pidgin_notification_connection_error_new(notification);
73 break;
74 default:
75 widget = pidgin_notification_list_unknown_notification(notification);
76 break;
77 }
78
79 if(!GTK_IS_WIDGET(widget)) {
80 widget = pidgin_notification_list_unknown_notification(notification);
81 }
82
83 return widget;
84 }
85
86 /******************************************************************************
87 * GObject Implementation
88 *****************************************************************************/
89 static void
90 pidgin_notification_list_init(PidginNotificationList *list) {
91 PurpleNotificationManager *manager = NULL;
92 GListModel *model = NULL;
93
94 gtk_widget_init_template(GTK_WIDGET(list));
95
96 manager = purple_notification_manager_get_default();
97 model = purple_notification_manager_get_model(manager);
98
99 gtk_list_box_bind_model(GTK_LIST_BOX(list->list_box), model,
100 pidgin_notification_list_create_widget_func,
101 list, NULL);
102 }
103
104 static void
105 pidgin_notification_list_class_init(PidginNotificationListClass *klass) {
106 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
107
108 gtk_widget_class_set_template_from_resource(
109 widget_class,
110 "/im/pidgin/Pidgin3/Notifications/list.ui"
111 );
112
113 gtk_widget_class_bind_template_child(widget_class, PidginNotificationList,
114 list_box);
115 }
116
117 /******************************************************************************
118 * API
119 *****************************************************************************/
120 GtkWidget *
121 pidgin_notification_list_new(void) {
122 return g_object_new(PIDGIN_TYPE_NOTIFICATION_LIST, NULL);
123 }

mercurial