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

« back to all changes in this revision

Viewing changes to mission-control-plugins/account.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 - interface to an McdAccountManager for plugins
 
2
 *
 
3
 * Copyright © 2010 Nokia Corporation
 
4
 * Copyright © 2010 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
GType
 
25
mcp_account_manager_get_type (void)
 
26
{
 
27
  static gsize once = 0;
 
28
  static GType type = 0;
 
29
 
 
30
  if (g_once_init_enter (&once))
 
31
    {
 
32
      static const GTypeInfo info = {
 
33
          sizeof (McpAccountManagerIface),
 
34
          NULL, /* base_init */
 
35
          NULL, /* base_finalize */
 
36
          NULL, /* class_init */
 
37
          NULL, /* class_finalize */
 
38
          NULL, /* class_data */
 
39
          0, /* instance_size */
 
40
          0, /* n_preallocs */
 
41
          NULL, /* instance_init */
 
42
          NULL /* value_table */
 
43
      };
 
44
 
 
45
      type = g_type_register_static (G_TYPE_INTERFACE,
 
46
          "McpAccountManager", &info, 0);
 
47
      g_type_interface_add_prerequisite (type, G_TYPE_OBJECT);
 
48
      g_once_init_leave (&once, 1);
 
49
    }
 
50
 
 
51
  return type;
 
52
}
 
53
 
 
54
void
 
55
mcp_account_manager_set_value (const McpAccountManager *mcpa,
 
56
    const gchar *acct,
 
57
    const gchar *key,
 
58
    const gchar *value)
 
59
{
 
60
  McpAccountManagerIface *iface = MCP_ACCOUNT_MANAGER_GET_IFACE (mcpa);
 
61
 
 
62
  g_return_if_fail (iface != NULL);
 
63
  g_return_if_fail (iface->set_value != NULL);
 
64
 
 
65
  iface->set_value (mcpa, acct, key, value);
 
66
}
 
67
 
 
68
/**
 
69
 * mcp_account_manager_get_value:
 
70
 * @mcpa: an #McpAccountManager instance
 
71
 * @acct: the unique name of an account
 
72
 * @key: the setting whose value we want to retrieve
 
73
 *
 
74
 * Fetch a copy of the current value of an account setting held by
 
75
 * the #McdAccountManager.
 
76
 *
 
77
 * Returns: a #gchar* which should be freed when the caller is done with it.
 
78
 **/
 
79
gchar *
 
80
mcp_account_manager_get_value (const McpAccountManager *mcpa,
 
81
    const gchar *acct,
 
82
    const gchar *key)
 
83
{
 
84
  McpAccountManagerIface *iface = MCP_ACCOUNT_MANAGER_GET_IFACE (mcpa);
 
85
 
 
86
  g_return_val_if_fail (iface != NULL, NULL);
 
87
  g_return_val_if_fail (iface->set_value != NULL, NULL);
 
88
 
 
89
  return iface->get_value (mcpa, acct, key);
 
90
}
 
91
 
 
92
/**
 
93
 * mcp_account_manager_parameter_is_secret:
 
94
 * @mcpa: an #McpAccountManager instance
 
95
 * @acct: the unique name of an account
 
96
 * @key: the setting whose value we want to retrieve
 
97
 *
 
98
 * Determine whether a given account parameter is secret.
 
99
 * generally this is determined by MC and passed down to us,
 
100
 * but any #McpAccountStorage plugin may decide a setting is
 
101
 * secret, in which case the return value for this call will
 
102
 * indicate that fact.
 
103
 *
 
104
 * Returns: a #gboolean, %TRUE for secret settings, %FALSE otherwise
 
105
 **/
 
106
gboolean
 
107
mcp_account_manager_parameter_is_secret (const McpAccountManager *mcpa,
 
108
    const gchar *acct,
 
109
    const gchar *key)
 
110
{
 
111
  McpAccountManagerIface *iface = MCP_ACCOUNT_MANAGER_GET_IFACE (mcpa);
 
112
 
 
113
  g_return_val_if_fail (iface != NULL, FALSE);
 
114
  g_return_val_if_fail (iface->is_secret != NULL, FALSE);
 
115
 
 
116
  return iface->is_secret (mcpa, acct, key);
 
117
}
 
118
 
 
119
/**
 
120
 * mcp_account_manager_parameter_make_secret:
 
121
 * @mcpa: an #McpAccountManager instance
 
122
 * @acct: the unique name of an account
 
123
 * @key: the setting whose value we want to retrieve
 
124
 *
 
125
 * Flag an account setting as secret for the lifetime of this
 
126
 * #McpAccountManager and its corresponding #McdAccountManager
 
127
 **/
 
128
void
 
129
mcp_account_manager_parameter_make_secret (const McpAccountManager *mcpa,
 
130
    const gchar *acct,
 
131
    const gchar *key)
 
132
{
 
133
  McpAccountManagerIface *iface = MCP_ACCOUNT_MANAGER_GET_IFACE (mcpa);
 
134
 
 
135
  g_return_if_fail (iface != NULL);
 
136
  g_return_if_fail (iface->make_secret != NULL);
 
137
 
 
138
  g_debug ("%s.%s should be secret", acct, key);
 
139
  return iface->make_secret (mcpa, acct, key);
 
140
}
 
141
 
 
142
/**
 
143
 * mcp_account_manager_get_unique_name:
 
144
 * @mcpa: an #McpAccountManager instance
 
145
 * @manager: the name of the manager
 
146
 * @protocol: the name of the protocol
 
147
 * @params: A gchar * / GValue * hash table of account parameters.
 
148
 *
 
149
 * Generate and return the canonical unique name of this [new] account.
 
150
 * Should not be called for accounts which have already had a name
 
151
 * assigned: Intended for use when a plugin encounters an account which
 
152
 * MC has not previously seen before (ie one created by a 3rd party
 
153
 * in the back-end that the plugin in question provides an interface to).
 
154
 *
 
155
 * Returns: the newly allocated account name, which should be freed
 
156
 * once the caller is done with it.
 
157
 */
 
158
gchar *
 
159
mcp_account_manager_get_unique_name (McpAccountManager *mcpa,
 
160
    const gchar *manager,
 
161
    const gchar *protocol,
 
162
    const GHashTable *params)
 
163
{
 
164
  McpAccountManagerIface *iface = MCP_ACCOUNT_MANAGER_GET_IFACE (mcpa);
 
165
 
 
166
  g_return_val_if_fail (iface != NULL, NULL);
 
167
  g_return_val_if_fail (iface->unique_name != NULL, NULL);
 
168
 
 
169
  return iface->unique_name (mcpa, manager, protocol, params);
 
170
}