~ubuntuone-control-tower/ubuntuone-client/trunk

« back to all changes in this revision

Viewing changes to libsyncdaemon/syncdaemon-share-info.c

  • Committer: Tarmac
  • Author(s): Rodney Dawes
  • Date: 2013-06-06 15:46:42 UTC
  • mfrom: (1395.1.1 slay-the-C-beast)
  • Revision ID: tarmac-20130606154642-gy8yc53v4rd47z3u
Drop libsyncdaemon from the tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Syncdaemon API
3
 
 *
4
 
 * Authors: Rodrigo Moya <rodrigo.moya@canonical.com>
5
 
 *
6
 
 * Copyright 2010-2012 Canonical Ltd.
7
 
 *
8
 
 * This program is free software: you can redistribute it and/or modify it
9
 
 * under the terms of the GNU General Public License version 3, as published
10
 
 * by the Free Software Foundation.
11
 
 *
12
 
 * This program is distributed in the hope that it will be useful, but
13
 
 * WITHOUT ANY WARRANTY; without even the implied warranties of
14
 
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15
 
 * PURPOSE.  See the GNU General Public License for more details.
16
 
 *
17
 
 * You should have received a copy of the GNU General Public License along
18
 
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 
 *
20
 
 * In addition, as a special exception, the copyright holders give
21
 
 * permission to link the code of portions of this program with the
22
 
 * OpenSSL library under certain conditions as described in each
23
 
 * individual source file, and distribute linked combinations
24
 
 * including the two.
25
 
 * You must obey the GNU General Public License in all respects
26
 
 * for all of the code used other than OpenSSL.  If you modify
27
 
 * file(s) with this exception, you may extend this exception to your
28
 
 * version of the file(s), but you are not obligated to do so.  If you
29
 
 * do not wish to do so, delete this exception statement from your
30
 
 * version.  If you delete this exception statement from all source
31
 
 * files in the program, then also delete it here.
32
 
 *
33
 
 */
34
 
 
35
 
#include "syncdaemon-share-info.h"
36
 
 
37
 
G_DEFINE_TYPE(SyncdaemonShareInfo, syncdaemon_share_info, G_TYPE_OBJECT)
38
 
 
39
 
struct _SyncdaemonShareInfoPrivate {
40
 
        gchar *name;
41
 
        SyncdaemonShareInfoType type;
42
 
        gchar *path;
43
 
        gchar *username;
44
 
        gchar *user_visible_name;
45
 
        gchar *node_id;
46
 
        gchar *volume_id;
47
 
        gboolean accepted;
48
 
        gboolean allow_modifications;
49
 
};
50
 
 
51
 
static void
52
 
syncdaemon_share_info_finalize (GObject *object)
53
 
{
54
 
        SyncdaemonShareInfo *sinfo = SYNCDAEMON_SHARE_INFO (object);
55
 
 
56
 
        if (sinfo->priv != NULL) {
57
 
                if (sinfo->priv->name != NULL)
58
 
                        g_free (sinfo->priv->name);
59
 
 
60
 
                if (sinfo->priv->path != NULL)
61
 
                        g_free (sinfo->priv->path);
62
 
 
63
 
                if (sinfo->priv->username != NULL)
64
 
                        g_free (sinfo->priv->username);
65
 
 
66
 
                if (sinfo->priv->user_visible_name != NULL)
67
 
                        g_free (sinfo->priv->user_visible_name);
68
 
 
69
 
                if (sinfo->priv->node_id != NULL)
70
 
                        g_free (sinfo->priv->node_id);
71
 
 
72
 
                if (sinfo->priv->volume_id != NULL)
73
 
                        g_free (sinfo->priv->volume_id);
74
 
 
75
 
                g_free (sinfo->priv);
76
 
        }
77
 
 
78
 
        G_OBJECT_CLASS (syncdaemon_share_info_parent_class)->finalize (object);
79
 
}
80
 
 
81
 
static void
82
 
syncdaemon_share_info_class_init (SyncdaemonShareInfoClass *klass)
83
 
{
84
 
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
85
 
 
86
 
        object_class->finalize = syncdaemon_share_info_finalize;
87
 
}
88
 
 
89
 
static void
90
 
syncdaemon_share_info_init (SyncdaemonShareInfo *sinfo)
91
 
{
92
 
        sinfo->priv = g_new0 (SyncdaemonShareInfoPrivate, 1);
93
 
}
94
 
 
95
 
/**
96
 
 * syncdaemon_share_info_new:
97
 
 */
98
 
SyncdaemonShareInfo *
99
 
syncdaemon_share_info_new (void)
100
 
{
101
 
        return g_object_new (SYNCDAEMON_TYPE_SHARE_INFO, NULL);
102
 
}
103
 
 
104
 
/**
105
 
 * syncdaemon_share_info_new_from_hash_table:
106
 
 */
107
 
SyncdaemonShareInfo *
108
 
syncdaemon_share_info_new_from_hash_table (GHashTable *hash)
109
 
{
110
 
        SyncdaemonShareInfo *sinfo;
111
 
 
112
 
        sinfo = g_object_new (SYNCDAEMON_TYPE_SHARE_INFO, NULL);
113
 
        if (hash != NULL) {
114
 
                gchar *str;
115
 
 
116
 
                syncdaemon_share_info_set_name (sinfo, g_hash_table_lookup (hash, "name"));
117
 
                syncdaemon_share_info_set_path (sinfo, g_hash_table_lookup (hash, "path"));
118
 
                syncdaemon_share_info_set_username (sinfo, g_hash_table_lookup (hash, "other_username"));
119
 
                syncdaemon_share_info_set_user_visible_name (
120
 
                        sinfo,
121
 
                        g_hash_table_lookup (hash, "other_visible_name"));
122
 
                syncdaemon_share_info_set_node_id (sinfo, g_hash_table_lookup (hash, "node_id"));
123
 
                syncdaemon_share_info_set_volume_id (sinfo, g_hash_table_lookup (hash, "volume_id"));
124
 
                syncdaemon_share_info_set_accepted (
125
 
                        sinfo,
126
 
                        g_strcmp0 (g_hash_table_lookup (hash, "accepted"), "True") == 0);
127
 
                syncdaemon_share_info_set_allow_modifications (
128
 
                        sinfo,
129
 
                        g_strcmp0 (g_hash_table_lookup (hash, "access_level"), "Modify") == 0);
130
 
 
131
 
                str = g_hash_table_lookup (hash, "type");
132
 
                if (g_strcmp0 (str, "Shared") == 0)
133
 
                        syncdaemon_share_info_set_share_type (sinfo, SYNCDAEMON_SHARE_INFO_TYPE_SHARED);
134
 
                else if (g_strcmp0 (str, "Share") == 0)
135
 
                        syncdaemon_share_info_set_share_type (sinfo, SYNCDAEMON_SHARE_INFO_TYPE_SHARE);
136
 
                else
137
 
                        syncdaemon_share_info_set_share_type (sinfo, SYNCDAEMON_SHARE_INFO_TYPE_UNKNOWN);
138
 
        }
139
 
 
140
 
        return sinfo;
141
 
}
142
 
 
143
 
/**
144
 
 * syncdameon_share_info_get_name:
145
 
 */
146
 
const gchar *
147
 
syncdaemon_share_info_get_name (SyncdaemonShareInfo *sinfo)
148
 
{
149
 
        g_return_val_if_fail (SYNCDAEMON_IS_SHARE_INFO (sinfo), NULL);
150
 
 
151
 
        return (const gchar *) sinfo->priv->name;
152
 
}
153
 
 
154
 
/**
155
 
 * syncdameon_share_info_set_name:
156
 
 */
157
 
void
158
 
syncdaemon_share_info_set_name (SyncdaemonShareInfo *sinfo, const gchar *name)
159
 
{
160
 
        g_return_if_fail (SYNCDAEMON_IS_SHARE_INFO (sinfo));
161
 
 
162
 
        if (sinfo->priv->name != NULL)
163
 
                g_free (sinfo->priv->name);
164
 
 
165
 
        sinfo->priv->name = g_strdup (name);
166
 
}
167
 
 
168
 
/**
169
 
 * syncdameon_share_info_get_share_type:
170
 
 */
171
 
SyncdaemonShareInfoType
172
 
syncdaemon_share_info_get_share_type (SyncdaemonShareInfo *sinfo)
173
 
{
174
 
        g_return_val_if_fail (SYNCDAEMON_IS_SHARE_INFO (sinfo), SYNCDAEMON_SHARE_INFO_TYPE_UNKNOWN);
175
 
 
176
 
        return sinfo->priv->type;
177
 
}
178
 
 
179
 
/**
180
 
 * syncdameon_share_info_set_share_type:
181
 
 */
182
 
void
183
 
syncdaemon_share_info_set_share_type (SyncdaemonShareInfo *sinfo, SyncdaemonShareInfoType type)
184
 
{
185
 
        g_return_if_fail (SYNCDAEMON_IS_SHARE_INFO (sinfo));
186
 
 
187
 
        sinfo->priv->type = type;
188
 
}
189
 
 
190
 
/**
191
 
 * syncdameon_share_info_get_path:
192
 
 */
193
 
const gchar *
194
 
syncdaemon_share_info_get_path (SyncdaemonShareInfo *sinfo)
195
 
{
196
 
        g_return_val_if_fail (SYNCDAEMON_IS_SHARE_INFO (sinfo), NULL);
197
 
 
198
 
        return (const gchar *) sinfo->priv->path;
199
 
}
200
 
 
201
 
/**
202
 
 * syncdameon_share_info_set_path:
203
 
 */
204
 
void
205
 
syncdaemon_share_info_set_path (SyncdaemonShareInfo *sinfo, const gchar *path)
206
 
{
207
 
        g_return_if_fail (SYNCDAEMON_IS_SHARE_INFO (sinfo));
208
 
 
209
 
        if (sinfo->priv->path != NULL)
210
 
                g_free (sinfo->priv->path);
211
 
 
212
 
        sinfo->priv->path = g_strdup (path);
213
 
}
214
 
 
215
 
/**
216
 
 * syncdameon_share_info_get_username:
217
 
 */
218
 
const gchar *
219
 
syncdaemon_share_info_get_username (SyncdaemonShareInfo *sinfo)
220
 
{
221
 
        g_return_val_if_fail (SYNCDAEMON_IS_SHARE_INFO (sinfo), NULL);
222
 
 
223
 
        return (const gchar *) sinfo->priv->username;
224
 
}
225
 
 
226
 
/**
227
 
 * syncdameon_share_info_set_username:
228
 
 */
229
 
void
230
 
syncdaemon_share_info_set_username (SyncdaemonShareInfo *sinfo, const gchar *username)
231
 
{
232
 
        g_return_if_fail (SYNCDAEMON_IS_SHARE_INFO (sinfo));
233
 
 
234
 
        if (sinfo->priv->username != NULL)
235
 
                g_free (sinfo->priv->username);
236
 
 
237
 
        sinfo->priv->username = g_strdup (username);
238
 
}
239
 
 
240
 
/**
241
 
 * syncdameon_share_info_get_user_visible_name:
242
 
 */
243
 
const gchar *
244
 
syncdaemon_share_info_get_user_visible_name (SyncdaemonShareInfo *sinfo)
245
 
{
246
 
        g_return_val_if_fail (SYNCDAEMON_IS_SHARE_INFO (sinfo), NULL);
247
 
 
248
 
        return (const gchar *) sinfo->priv->user_visible_name;
249
 
}
250
 
 
251
 
/**
252
 
 * syncdameon_share_info_set_user_visible_name:
253
 
 */
254
 
void
255
 
syncdaemon_share_info_set_user_visible_name (SyncdaemonShareInfo *sinfo, const gchar *user_visible_name)
256
 
{
257
 
        g_return_if_fail (SYNCDAEMON_IS_SHARE_INFO (sinfo));
258
 
 
259
 
        if (sinfo->priv->user_visible_name != NULL)
260
 
                g_free (sinfo->priv->user_visible_name);
261
 
 
262
 
        sinfo->priv->user_visible_name = g_strdup (user_visible_name);
263
 
}
264
 
 
265
 
/**
266
 
 * syncdameon_share_info_get_node_id:
267
 
 */
268
 
const gchar *
269
 
syncdaemon_share_info_get_node_id (SyncdaemonShareInfo *sinfo)
270
 
{
271
 
        g_return_val_if_fail (SYNCDAEMON_IS_SHARE_INFO (sinfo), NULL);
272
 
 
273
 
        return (const gchar *) sinfo->priv->node_id;
274
 
}
275
 
 
276
 
/**
277
 
 * syncdameon_share_info_set_node_id:
278
 
 */
279
 
void
280
 
syncdaemon_share_info_set_node_id (SyncdaemonShareInfo *sinfo, const gchar *node_id)
281
 
{
282
 
        g_return_if_fail (SYNCDAEMON_IS_SHARE_INFO (sinfo));
283
 
 
284
 
        if (sinfo->priv->node_id != NULL)
285
 
                g_free (sinfo->priv->node_id);
286
 
 
287
 
        sinfo->priv->node_id = g_strdup (node_id);
288
 
}
289
 
 
290
 
/**
291
 
 * syncdameon_share_info_get_volume_id:
292
 
 */
293
 
const gchar *
294
 
syncdaemon_share_info_get_volume_id (SyncdaemonShareInfo *sinfo)
295
 
{
296
 
        g_return_val_if_fail (SYNCDAEMON_IS_SHARE_INFO (sinfo), NULL);
297
 
 
298
 
        return (const gchar *) sinfo->priv->volume_id;
299
 
}
300
 
 
301
 
/**
302
 
 * syncdameon_share_info_set_volume_id:
303
 
 */
304
 
void
305
 
syncdaemon_share_info_set_volume_id (SyncdaemonShareInfo *sinfo, const gchar *volume_id)
306
 
{
307
 
        g_return_if_fail (SYNCDAEMON_IS_SHARE_INFO (sinfo));
308
 
 
309
 
        if (sinfo->priv->volume_id != NULL)
310
 
                g_free (sinfo->priv->volume_id);
311
 
 
312
 
        sinfo->priv->volume_id = g_strdup (volume_id);
313
 
}
314
 
 
315
 
/**
316
 
 * syncdameon_share_info_get_accepted:
317
 
 */
318
 
gboolean
319
 
syncdaemon_share_info_get_accepted (SyncdaemonShareInfo *sinfo)
320
 
{
321
 
        g_return_val_if_fail (SYNCDAEMON_IS_SHARE_INFO (sinfo), FALSE);
322
 
 
323
 
        return sinfo->priv->accepted;
324
 
}
325
 
 
326
 
/**
327
 
 * syncdameon_share_info_set_accepted:
328
 
 */
329
 
void
330
 
syncdaemon_share_info_set_accepted (SyncdaemonShareInfo *sinfo, gboolean accepted)
331
 
{
332
 
        g_return_if_fail (SYNCDAEMON_IS_SHARE_INFO (sinfo));
333
 
 
334
 
        sinfo->priv->accepted = accepted;
335
 
}
336
 
 
337
 
/**
338
 
 * syncdameon_share_info_get_allow_modifications:
339
 
 */
340
 
gboolean
341
 
syncdaemon_share_info_get_allow_modifications (SyncdaemonShareInfo *sinfo)
342
 
{
343
 
        g_return_val_if_fail (SYNCDAEMON_IS_SHARE_INFO (sinfo), FALSE);
344
 
 
345
 
        return sinfo->priv->allow_modifications;
346
 
}
347
 
 
348
 
/**
349
 
 * syncdameon_share_info_set_allow_modifications:
350
 
 */
351
 
void
352
 
syncdaemon_share_info_set_allow_modifications (SyncdaemonShareInfo *sinfo, gboolean allow_modifications)
353
 
{
354
 
        g_return_if_fail (SYNCDAEMON_IS_SHARE_INFO (sinfo));
355
 
 
356
 
        sinfo->priv->allow_modifications = allow_modifications;
357
 
}