]> git.0d.be Git - empathy.git/blob - src/empathy-notifications-approver.c
add EmpathyNotificationsApprover
[empathy.git] / src / empathy-notifications-approver.c
1 /* * Copyright (C) 2009 Collabora Ltd.
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
16  *
17  * Authors: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
18  */
19
20 #include <config.h>
21 #include <string.h>
22
23 #include <libnotify/notification.h>
24 #include <libnotify/notify.h>
25 #include <telepathy-glib/telepathy-glib.h>
26
27 #include <libempathy-gtk/empathy-notify-manager.h>
28
29 #include "empathy-event-manager.h"
30
31 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
32 #include <libempathy/empathy-debug.h>
33
34 #include "empathy-notifications-approver.h"
35
36 struct _EmpathyNotificationsApproverPrivate
37 {
38   EmpathyEventManager *event_mgr;
39   EmpathyNotifyManager *notify_mgr;
40 };
41
42 G_DEFINE_TYPE (EmpathyNotificationsApprover, empathy_notifications_approver,
43     G_TYPE_OBJECT);
44
45 static EmpathyNotificationsApprover *notifications_approver = NULL;
46
47 static GObject *
48 notifications_approver_constructor (GType type,
49     guint n_construct_params,
50     GObjectConstructParam *construct_params)
51 {
52   GObject *retval;
53
54   if (notifications_approver != NULL)
55     return g_object_ref (notifications_approver);
56
57   retval = G_OBJECT_CLASS (empathy_notifications_approver_parent_class)->
58       constructor (type, n_construct_params, construct_params);
59
60   notifications_approver = EMPATHY_NOTIFICATIONS_APPROVER (retval);
61   g_object_add_weak_pointer (retval, (gpointer) &notifications_approver);
62
63   return retval;
64 }
65
66 static void
67 notifications_approver_dispose (GObject *object)
68 {
69   EmpathyNotificationsApprover *self = (EmpathyNotificationsApprover *) object;
70
71   tp_clear_object (&self->priv->event_mgr);
72   tp_clear_object (&self->priv->notify_mgr);
73
74   G_OBJECT_CLASS (empathy_notifications_approver_parent_class)->dispose (
75       object);
76 }
77
78 static void
79 empathy_notifications_approver_class_init (
80     EmpathyNotificationsApproverClass *klass)
81 {
82   GObjectClass *object_class = G_OBJECT_CLASS (klass);
83
84   object_class->dispose = notifications_approver_dispose;
85   object_class->constructor = notifications_approver_constructor;
86
87   g_type_class_add_private (object_class,
88       sizeof (EmpathyNotificationsApproverPrivate));
89 }
90
91 static void
92 empathy_notifications_approver_init (EmpathyNotificationsApprover *self)
93 {
94   EmpathyNotificationsApproverPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
95     EMPATHY_TYPE_NOTIFICATIONS_APPROVER, EmpathyNotificationsApproverPrivate);
96
97   self->priv = priv;
98
99   self->priv->event_mgr = empathy_event_manager_dup_singleton ();
100   self->priv->notify_mgr = empathy_notify_manager_dup_singleton ();
101 }
102
103 EmpathyNotificationsApprover *
104 empathy_notifications_approver_dup_singleton (void)
105 {
106   return g_object_new (EMPATHY_TYPE_NOTIFICATIONS_APPROVER, NULL);
107 }