~ubuntu-branches/ubuntu/precise/telepathy-mission-control-5/precise

« back to all changes in this revision

Viewing changes to mission-control-plugins/request.c

Tags: upstream-5.5.2
ImportĀ upstreamĀ versionĀ 5.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Mission Control plugin API - representation of a ChannelRequest
 
2
 *
 
3
 * Copyright (C) 2009 Nokia Corporation
 
4
 * Copyright (C) 2009 Collabora Ltd.
 
5
 *
 
6
 * This library is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU Lesser General Public
 
8
 * License as published by the Free Software Foundation; either
 
9
 * version 2.1 of the License, or (at your option) any later version.
 
10
 *
 
11
 * This library is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 * Lesser General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Lesser General Public
 
17
 * License along with this library; if not, write to the Free Software
 
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
19
 */
 
20
 
 
21
/**
 
22
 * SECTION:request
 
23
 * @title: McpRequest
 
24
 * @short_description: Request object, implemented by Mission Control
 
25
 * @see_also: #McpRequestPolicy
 
26
 * @include: mission-control-plugins/mission-control-plugins.h
 
27
 */
 
28
 
 
29
#include <mission-control-plugins/mission-control-plugins.h>
 
30
#include <mission-control-plugins/implementation.h>
 
31
 
 
32
#include <telepathy-glib/dbus.h>
 
33
#include <telepathy-glib/interfaces.h>
 
34
 
 
35
GType
 
36
mcp_request_get_type (void)
 
37
{
 
38
  static gsize once = 0;
 
39
  static GType type = 0;
 
40
 
 
41
  if (g_once_init_enter (&once))
 
42
    {
 
43
      static const GTypeInfo info = {
 
44
          sizeof (McpRequestIface),
 
45
          NULL, /* base_init */
 
46
          NULL, /* base_finalize */
 
47
          NULL, /* class_init */
 
48
          NULL, /* class_finalize */
 
49
          NULL, /* class_data */
 
50
          0, /* instance_size */
 
51
          0, /* n_preallocs */
 
52
          NULL, /* instance_init */
 
53
          NULL /* value_table */
 
54
      };
 
55
 
 
56
      type = g_type_register_static (G_TYPE_INTERFACE, "McpRequest",
 
57
          &info, 0);
 
58
      g_type_interface_add_prerequisite (type, G_TYPE_OBJECT);
 
59
 
 
60
      g_once_init_leave (&once, 1);
 
61
    }
 
62
 
 
63
  return type;
 
64
}
 
65
 
 
66
const gchar *
 
67
mcp_request_get_account_path (McpRequest *self)
 
68
{
 
69
  McpRequestIface *iface = MCP_REQUEST_GET_IFACE (self);
 
70
 
 
71
  g_return_val_if_fail (iface != NULL, NULL);
 
72
  g_return_val_if_fail (iface->get_account_path != NULL, NULL);
 
73
  return iface->get_account_path (self);
 
74
}
 
75
 
 
76
const gchar *
 
77
mcp_request_get_protocol (McpRequest *self)
 
78
{
 
79
  McpRequestIface *iface = MCP_REQUEST_GET_IFACE (self);
 
80
 
 
81
  g_return_val_if_fail (iface != NULL, NULL);
 
82
  g_return_val_if_fail (iface->get_protocol != NULL, NULL);
 
83
  return iface->get_protocol (self);
 
84
}
 
85
 
 
86
const gchar *
 
87
mcp_request_get_cm_name (McpRequest *self)
 
88
{
 
89
  McpRequestIface *iface = MCP_REQUEST_GET_IFACE (self);
 
90
 
 
91
  g_return_val_if_fail (iface != NULL, NULL);
 
92
  g_return_val_if_fail (iface->get_cm_name != NULL, NULL);
 
93
  return iface->get_cm_name (self);
 
94
}
 
95
 
 
96
gint64
 
97
mcp_request_get_user_action_time (McpRequest *self)
 
98
{
 
99
  McpRequestIface *iface = MCP_REQUEST_GET_IFACE (self);
 
100
 
 
101
  g_return_val_if_fail (iface != NULL, 0);
 
102
  g_return_val_if_fail (iface->get_user_action_time != NULL, 0);
 
103
  return iface->get_user_action_time (self);
 
104
}
 
105
 
 
106
guint
 
107
mcp_request_get_n_requests (McpRequest *self)
 
108
{
 
109
  McpRequestIface *iface = MCP_REQUEST_GET_IFACE (self);
 
110
 
 
111
  g_return_val_if_fail (iface != NULL, 0);
 
112
  g_return_val_if_fail (iface->get_n_requests != NULL, 0);
 
113
  return iface->get_n_requests (self);
 
114
}
 
115
 
 
116
GHashTable *
 
117
mcp_request_ref_nth_request (McpRequest *self,
 
118
    guint n)
 
119
{
 
120
  McpRequestIface *iface = MCP_REQUEST_GET_IFACE (self);
 
121
 
 
122
  g_return_val_if_fail (iface != NULL, NULL);
 
123
  g_return_val_if_fail (iface->ref_nth_request != NULL, NULL);
 
124
  return iface->ref_nth_request (self, n);
 
125
}
 
126
 
 
127
void
 
128
mcp_request_deny (McpRequest *self,
 
129
    GQuark domain,
 
130
    gint code,
 
131
    const gchar *message)
 
132
{
 
133
  McpRequestIface *iface = MCP_REQUEST_GET_IFACE (self);
 
134
 
 
135
  g_return_if_fail (iface != NULL);
 
136
  g_return_if_fail (domain != 0);
 
137
  g_return_if_fail (message != NULL);
 
138
  g_return_if_fail (iface->deny != NULL);
 
139
 
 
140
  iface->deny (self, domain, code, message);
 
141
}
 
142
 
 
143
gboolean
 
144
mcp_request_find_request_by_type (McpRequest *self,
 
145
    guint start_from,
 
146
    GQuark channel_type,
 
147
    guint *ret_index,
 
148
    GHashTable **ret_ref_requested_properties)
 
149
{
 
150
  guint i = start_from;
 
151
 
 
152
  while (1)
 
153
    {
 
154
      GHashTable *req = mcp_request_ref_nth_request (self, i);
 
155
 
 
156
      if (req == NULL)
 
157
        return FALSE;
 
158
 
 
159
      if (channel_type == 0 ||
 
160
          channel_type == g_quark_try_string (
 
161
            tp_asv_get_string (req, TP_IFACE_CHANNEL ".ChannelType")))
 
162
        {
 
163
          if (ret_index != NULL)
 
164
            *ret_index = i;
 
165
 
 
166
          if (ret_ref_requested_properties != NULL)
 
167
            *ret_ref_requested_properties = req;
 
168
          else
 
169
            g_hash_table_unref (req);
 
170
 
 
171
          return TRUE;
 
172
        }
 
173
 
 
174
      g_hash_table_unref (req);
 
175
      i++;
 
176
    }
 
177
}