~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.0
ImportĀ upstreamĀ versionĀ 5.5.0

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
#include <mission-control-plugins/mission-control-plugins.h>
 
22
#include <mission-control-plugins/implementation.h>
 
23
 
 
24
#include <telepathy-glib/dbus.h>
 
25
#include <telepathy-glib/interfaces.h>
 
26
 
 
27
GType
 
28
mcp_request_get_type (void)
 
29
{
 
30
  static gsize once = 0;
 
31
  static GType type = 0;
 
32
 
 
33
  if (g_once_init_enter (&once))
 
34
    {
 
35
      static const GTypeInfo info = {
 
36
          sizeof (McpRequestIface),
 
37
          NULL, /* base_init */
 
38
          NULL, /* base_finalize */
 
39
          NULL, /* class_init */
 
40
          NULL, /* class_finalize */
 
41
          NULL, /* class_data */
 
42
          0, /* instance_size */
 
43
          0, /* n_preallocs */
 
44
          NULL, /* instance_init */
 
45
          NULL /* value_table */
 
46
      };
 
47
 
 
48
      type = g_type_register_static (G_TYPE_INTERFACE, "McpRequest",
 
49
          &info, 0);
 
50
      g_type_interface_add_prerequisite (type, G_TYPE_OBJECT);
 
51
 
 
52
      g_once_init_leave (&once, 1);
 
53
    }
 
54
 
 
55
  return type;
 
56
}
 
57
 
 
58
const gchar *
 
59
mcp_request_get_account_path (McpRequest *self)
 
60
{
 
61
  McpRequestIface *iface = MCP_REQUEST_GET_IFACE (self);
 
62
 
 
63
  g_return_val_if_fail (iface != NULL, NULL);
 
64
  g_return_val_if_fail (iface->get_account_path != NULL, NULL);
 
65
  return iface->get_account_path (self);
 
66
}
 
67
 
 
68
const gchar *
 
69
mcp_request_get_protocol (McpRequest *self)
 
70
{
 
71
  McpRequestIface *iface = MCP_REQUEST_GET_IFACE (self);
 
72
 
 
73
  g_return_val_if_fail (iface != NULL, NULL);
 
74
  g_return_val_if_fail (iface->get_protocol != NULL, NULL);
 
75
  return iface->get_protocol (self);
 
76
}
 
77
 
 
78
const gchar *
 
79
mcp_request_get_cm_name (McpRequest *self)
 
80
{
 
81
  McpRequestIface *iface = MCP_REQUEST_GET_IFACE (self);
 
82
 
 
83
  g_return_val_if_fail (iface != NULL, NULL);
 
84
  g_return_val_if_fail (iface->get_cm_name != NULL, NULL);
 
85
  return iface->get_cm_name (self);
 
86
}
 
87
 
 
88
gint64
 
89
mcp_request_get_user_action_time (McpRequest *self)
 
90
{
 
91
  McpRequestIface *iface = MCP_REQUEST_GET_IFACE (self);
 
92
 
 
93
  g_return_val_if_fail (iface != NULL, 0);
 
94
  g_return_val_if_fail (iface->get_user_action_time != NULL, 0);
 
95
  return iface->get_user_action_time (self);
 
96
}
 
97
 
 
98
guint
 
99
mcp_request_get_n_requests (McpRequest *self)
 
100
{
 
101
  McpRequestIface *iface = MCP_REQUEST_GET_IFACE (self);
 
102
 
 
103
  g_return_val_if_fail (iface != NULL, 0);
 
104
  g_return_val_if_fail (iface->get_n_requests != NULL, 0);
 
105
  return iface->get_n_requests (self);
 
106
}
 
107
 
 
108
GHashTable *
 
109
mcp_request_ref_nth_request (McpRequest *self,
 
110
    guint n)
 
111
{
 
112
  McpRequestIface *iface = MCP_REQUEST_GET_IFACE (self);
 
113
 
 
114
  g_return_val_if_fail (iface != NULL, NULL);
 
115
  g_return_val_if_fail (iface->ref_nth_request != NULL, NULL);
 
116
  return iface->ref_nth_request (self, n);
 
117
}
 
118
 
 
119
void
 
120
mcp_request_deny (McpRequest *self,
 
121
    GQuark domain,
 
122
    gint code,
 
123
    const gchar *message)
 
124
{
 
125
  McpRequestIface *iface = MCP_REQUEST_GET_IFACE (self);
 
126
 
 
127
  g_return_if_fail (iface != NULL);
 
128
  g_return_if_fail (domain != 0);
 
129
  g_return_if_fail (message != NULL);
 
130
  g_return_if_fail (iface->deny != NULL);
 
131
 
 
132
  iface->deny (self, domain, code, message);
 
133
}
 
134
 
 
135
gboolean
 
136
mcp_request_find_request_by_type (McpRequest *self,
 
137
    guint start_from,
 
138
    GQuark channel_type,
 
139
    guint *ret_index,
 
140
    GHashTable **ret_ref_requested_properties)
 
141
{
 
142
  guint i = start_from;
 
143
 
 
144
  while (1)
 
145
    {
 
146
      GHashTable *req = mcp_request_ref_nth_request (self, i);
 
147
 
 
148
      if (req == NULL)
 
149
        return FALSE;
 
150
 
 
151
      if (channel_type == 0 ||
 
152
          channel_type == g_quark_try_string (
 
153
            tp_asv_get_string (req, TP_IFACE_CHANNEL ".ChannelType")))
 
154
        {
 
155
          if (ret_index != NULL)
 
156
            *ret_index = i;
 
157
 
 
158
          if (ret_ref_requested_properties != NULL)
 
159
            *ret_ref_requested_properties = req;
 
160
          else
 
161
            g_hash_table_unref (req);
 
162
 
 
163
          return TRUE;
 
164
        }
 
165
 
 
166
      g_hash_table_unref (req);
 
167
      i++;
 
168
    }
 
169
}