File: mn-server.gob

package info (click to toggle)
mail-notification 5.4.dfsg.1-13
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 6,448 kB
  • ctags: 9,615
  • sloc: ansic: 13,970; sh: 2,770; xml: 2,113; makefile: 58
file content (148 lines) | stat: -rw-r--r-- 3,401 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
 * Mail Notification
 * Copyright (C) 2003-2008 Jean-Yves Lefort <jylefort@brutele.be>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

%headertop{
#include <dbus/dbus-glib.h>
%}

%h{
#define MN_SERVER_SERVICE	"org.gnome.MailNotification"
#define MN_SERVER_PATH		"/org/gnome/MailNotification"
#define MN_SERVER_INTERFACE	"org.gnome.MailNotification"
%}

%{
#include <glib/gi18n.h>
#include <dbus/dbus-glib-bindings.h>
#include "mn-shell.h"
#include "mn-util.h"
%}

%afterdecls{
#include "mn-server-dbus.h"
%}

/*
 * We hold the GDK lock because D-Bus interface methods are run from a
 * main loop callback.
 */

class MN:Server from G:Object
{
  class_init (class)
  {
    dbus_g_object_type_install_info(TYPE_SELF, &dbus_glib_mn_server_object_info);
  }

  private gboolean
    has_mailboxes (self, gboolean *ret (check null), GError **err)
  {
    *ret = mn_shell->mailboxes->list != NULL;
    return TRUE;
  }

  private gboolean
    get_summary (self, char **ret (check null), GError **err)
  {
    *ret = mn_shell_get_summary(mn_shell);
    return TRUE;
  }

  private gboolean
    consider_new_mail_as_read (self, GError **err)
  {
    GDK_THREADS_ENTER();
    mn_shell_consider_new_mail_as_read(mn_shell);
    GDK_THREADS_LEAVE();

    return TRUE;
  }

  private gboolean
    update (self, GError **err)
  {
    GDK_THREADS_ENTER();
    mn_shell_update(mn_shell);
    GDK_THREADS_LEAVE();

    return TRUE;
  }

  private gboolean
    display_properties (self, GError **err)
  {
    GDK_THREADS_ENTER();
    mn_shell_show_properties_dialog(mn_shell, 0);
    GDK_THREADS_LEAVE();

    return TRUE;
  }

  private gboolean
    display_about (self, GError **err)
  {
    GDK_THREADS_ENTER();
    mn_shell_show_about_dialog(mn_shell, 0);
    GDK_THREADS_LEAVE();

    return TRUE;
  }

  private gboolean
    quit (self, GError **err)
  {
    GDK_THREADS_ENTER();
    mn_shell_quit(mn_shell);
    GDK_THREADS_LEAVE();

    return TRUE;
  }

  /* returns NULL if already registered */
  public gboolean
    start (DBusGConnection *bus (check null),
	   DBus:G:Proxy *bus_proxy (check null type))
  {
    Self *self;
    GError *err = NULL;
    unsigned int name_reply;

    self = GET_NEW;

    dbus_g_connection_register_g_object(bus, MN_SERVER_PATH, G_OBJECT(self));

    if (! org_freedesktop_DBus_request_name(bus_proxy,
					    MN_SERVER_SERVICE,
					    DBUS_NAME_FLAG_DO_NOT_QUEUE,
					    &name_reply,
					    &err))
      {
	mn_show_fatal_error_dialog(NULL, _("Unable to register the Mail Notification D-Bus server: %s."), err->message);
	g_error_free(err);
      }

    if (name_reply != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
      {
	g_object_unref(self);
	return FALSE;
      }

    return TRUE;
  }
}