4
* Authors: Rodrigo Moya <rodrigo.moya@canonical.com>
6
* Copyright 2010-2012 Canonical Ltd.
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.
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.
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/>.
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
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.
35
#include "syncdaemon-transfer-info.h"
39
G_DEFINE_TYPE(SyncdaemonTransferInfo, syncdaemon_transfer_info, G_TYPE_OBJECT)
41
struct _SyncdaemonTransferInfoPrivate {
45
glong bytes_transferred;
50
syncdaemon_transfer_info_finalize (GObject *object)
52
SyncdaemonTransferInfo *tinfo = SYNCDAEMON_TRANSFER_INFO (object);
54
if (tinfo->priv != NULL) {
55
if (tinfo->priv->path != NULL)
56
g_free (tinfo->priv->path);
58
if (tinfo->priv->share_id != NULL)
59
g_free (tinfo->priv->share_id);
61
if (tinfo->priv->node_id != NULL)
62
g_free (tinfo->priv->node_id);
67
G_OBJECT_CLASS (syncdaemon_transfer_info_parent_class)->finalize (object);
71
syncdaemon_transfer_info_class_init (SyncdaemonTransferInfoClass *klass)
73
GObjectClass *object_class = G_OBJECT_CLASS (klass);
75
object_class->finalize = syncdaemon_transfer_info_finalize;
79
syncdaemon_transfer_info_init (SyncdaemonTransferInfo *tinfo)
81
tinfo->priv = g_new0 (SyncdaemonTransferInfoPrivate, 1);
85
* syncdaemon_transfer_info_new:
86
* @path: Local path of the file being transferred.
88
* Return value: A new #SyncdaemonTransferInfo object.
90
SyncdaemonTransferInfo *
91
syncdaemon_transfer_info_new (const gchar *path)
93
SyncdaemonTransferInfo *tinfo;
95
tinfo = g_object_new (SYNCDAEMON_TYPE_TRANSFER_INFO, NULL);
97
syncdaemon_transfer_info_set_path (tinfo, path);
103
* syncdaemon_transfer_info_new_from_hash_table:
105
SyncdaemonTransferInfo *
106
syncdaemon_transfer_info_new_from_hash_table (GHashTable *hash)
108
SyncdaemonTransferInfo *tinfo;
110
tinfo = g_object_new (SYNCDAEMON_TYPE_TRANSFER_INFO, NULL);
114
syncdaemon_transfer_info_set_path (tinfo, g_hash_table_lookup (hash, "path"));
115
syncdaemon_transfer_info_set_share_id (tinfo, g_hash_table_lookup (hash, "share_id"));
116
syncdaemon_transfer_info_set_node_id (tinfo, g_hash_table_lookup (hash, "node_id"));
118
str = g_hash_table_lookup (hash, "n_bytes_read");
120
syncdaemon_transfer_info_set_bytes_transferred (tinfo, atol (str));
122
str = g_hash_table_lookup (hash, "deflated_size");
124
syncdaemon_transfer_info_set_total_size (tinfo, atol (str));
131
* syncdaemon_transfer_info_get_path:
134
syncdaemon_transfer_info_get_path (SyncdaemonTransferInfo *tinfo)
136
g_return_val_if_fail (SYNCDAEMON_IS_TRANSFER_INFO (tinfo), NULL);
138
return (const gchar *) tinfo->priv->path;
142
* syncdaemon_transfer_info_set_path:
145
syncdaemon_transfer_info_set_path (SyncdaemonTransferInfo *tinfo, const gchar *path)
147
g_return_if_fail (SYNCDAEMON_IS_TRANSFER_INFO (tinfo));
149
if (tinfo->priv->path != NULL)
150
g_free (tinfo->priv->path);
152
tinfo->priv->path = g_strdup (path);
156
* syncdaemon_transfer_info_get_share_id:
159
syncdaemon_transfer_info_get_share_id (SyncdaemonTransferInfo *tinfo)
161
g_return_val_if_fail (SYNCDAEMON_IS_TRANSFER_INFO (tinfo), NULL);
163
return (const gchar *) tinfo->priv->share_id;
167
* syncdaemon_transfer_info_set_share_id:
170
syncdaemon_transfer_info_set_share_id (SyncdaemonTransferInfo *tinfo, const gchar *share_id)
172
g_return_if_fail (SYNCDAEMON_IS_TRANSFER_INFO (tinfo));
174
if (tinfo->priv->share_id != NULL)
175
g_free (tinfo->priv->share_id);
177
tinfo->priv->share_id = g_strdup (share_id);
181
* syncdaemon_transfer_info_get_path:
184
syncdaemon_transfer_info_get_node_id (SyncdaemonTransferInfo *tinfo)
186
g_return_val_if_fail (SYNCDAEMON_IS_TRANSFER_INFO (tinfo), NULL);
188
return (const gchar *) tinfo->priv->node_id;
192
* syncdaemon_transfer_info_set_node_id:
195
syncdaemon_transfer_info_set_node_id (SyncdaemonTransferInfo *tinfo, const gchar *node_id)
197
g_return_if_fail (SYNCDAEMON_IS_TRANSFER_INFO (tinfo));
199
if (tinfo->priv->node_id != NULL)
200
g_free (tinfo->priv->node_id);
202
tinfo->priv->node_id = g_strdup (node_id);
206
* syncdaemon_transfer_info_get_bytes_transferred:
209
syncdaemon_transfer_info_get_bytes_transferred (SyncdaemonTransferInfo *tinfo)
211
g_return_val_if_fail (SYNCDAEMON_IS_TRANSFER_INFO (tinfo), 0);
213
return tinfo->priv->bytes_transferred;
217
* syncdaemon_transfer_info_set_bytes_transferred:
220
syncdaemon_transfer_info_set_bytes_transferred (SyncdaemonTransferInfo *tinfo, glong bytes)
222
g_return_if_fail (SYNCDAEMON_IS_TRANSFER_INFO (tinfo));
224
tinfo->priv->bytes_transferred = bytes;
228
* syncdaemon_transfer_info_get_total_size:
231
syncdaemon_transfer_info_get_total_size (SyncdaemonTransferInfo *tinfo)
233
g_return_val_if_fail (SYNCDAEMON_IS_TRANSFER_INFO (tinfo), 0);
235
return tinfo->priv->total_size;
239
* syncdaemon_transfer_info_set_total_size:
242
syncdaemon_transfer_info_set_total_size (SyncdaemonTransferInfo *tinfo, glong bytes)
244
g_return_if_fail (SYNCDAEMON_IS_TRANSFER_INFO (tinfo));
246
tinfo->priv->total_size = bytes;