src/mn-server.gob (3401B) - raw
1 /*
2 * Mail Notification
3 * Copyright (C) 2003-2008 Jean-Yves Lefort <jylefort@brutele.be>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 %headertop{
21 #include <dbus/dbus-glib.h>
22 %}
23
24 %h{
25 #define MN_SERVER_SERVICE "org.gnome.MailNotification"
26 #define MN_SERVER_PATH "/org/gnome/MailNotification"
27 #define MN_SERVER_INTERFACE "org.gnome.MailNotification"
28 %}
29
30 %{
31 #include <glib/gi18n.h>
32 #include <dbus/dbus-glib-bindings.h>
33 #include "mn-shell.h"
34 #include "mn-util.h"
35 %}
36
37 %afterdecls{
38 #include "mn-server-dbus.h"
39 %}
40
41 /*
42 * We hold the GDK lock because D-Bus interface methods are run from a
43 * main loop callback.
44 */
45
46 class MN:Server from G:Object
47 {
48 class_init (class)
49 {
50 dbus_g_object_type_install_info(TYPE_SELF, &dbus_glib_mn_server_object_info);
51 }
52
53 private gboolean
54 has_mailboxes (self, gboolean *ret (check null), GError **err)
55 {
56 *ret = mn_shell->mailboxes->list != NULL;
57 return TRUE;
58 }
59
60 private gboolean
61 get_summary (self, char **ret (check null), GError **err)
62 {
63 *ret = mn_shell_get_summary(mn_shell);
64 return TRUE;
65 }
66
67 private gboolean
68 consider_new_mail_as_read (self, GError **err)
69 {
70 GDK_THREADS_ENTER();
71 mn_shell_consider_new_mail_as_read(mn_shell);
72 GDK_THREADS_LEAVE();
73
74 return TRUE;
75 }
76
77 private gboolean
78 update (self, GError **err)
79 {
80 GDK_THREADS_ENTER();
81 mn_shell_update(mn_shell);
82 GDK_THREADS_LEAVE();
83
84 return TRUE;
85 }
86
87 private gboolean
88 display_properties (self, GError **err)
89 {
90 GDK_THREADS_ENTER();
91 mn_shell_show_properties_dialog(mn_shell, 0);
92 GDK_THREADS_LEAVE();
93
94 return TRUE;
95 }
96
97 private gboolean
98 display_about (self, GError **err)
99 {
100 GDK_THREADS_ENTER();
101 mn_shell_show_about_dialog(mn_shell, 0);
102 GDK_THREADS_LEAVE();
103
104 return TRUE;
105 }
106
107 private gboolean
108 quit (self, GError **err)
109 {
110 GDK_THREADS_ENTER();
111 mn_shell_quit(mn_shell);
112 GDK_THREADS_LEAVE();
113
114 return TRUE;
115 }
116
117 /* returns NULL if already registered */
118 public gboolean
119 start (DBusGConnection *bus (check null),
120 DBus:G:Proxy *bus_proxy (check null type))
121 {
122 Self *self;
123 GError *err = NULL;
124 unsigned int name_reply;
125
126 self = GET_NEW;
127
128 dbus_g_connection_register_g_object(bus, MN_SERVER_PATH, G_OBJECT(self));
129
130 if (! org_freedesktop_DBus_request_name(bus_proxy,
131 MN_SERVER_SERVICE,
132 DBUS_NAME_FLAG_DO_NOT_QUEUE,
133 &name_reply,
134 &err))
135 {
136 mn_show_fatal_error_dialog(NULL, _("Unable to register the Mail Notification D-Bus server: %s."), err->message);
137 g_error_free(err);
138 }
139
140 if (name_reply != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
141 {
142 g_object_unref(self);
143 return FALSE;
144 }
145
146 return TRUE;
147 }
148 }