File: oobs-share.c

package info (click to toggle)
liboobs 3.0.0-4.4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,284 kB
  • sloc: sh: 10,131; ansic: 9,920; makefile: 176; xml: 1
file content (188 lines) | stat: -rw-r--r-- 4,654 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */
/* Copyright (C) 2005 Carlos Garnacho
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 *
 * Authors: Carlos Garnacho Parro  <carlosg@gnome.org>
 */

#include <glib-object.h>
#include "oobs-share.h"

/**
 * SECTION:oobs-share
 * @title: OobsShare
 * @short_description: Base object for shared folders
 * @see_also: #OobsShareNFS, #OobsShareSMB
 **/

#define OOBS_SHARE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), OOBS_TYPE_SHARE, OobsSharePrivate))

typedef struct _OobsSharePrivate OobsSharePrivate;

struct _OobsSharePrivate {
  gchar *path;
};

static void oobs_share_class_init   (OobsShareClass *class);
static void oobs_share_init         (OobsShare *share);
static void oobs_share_finalize     (GObject  *object);

static void oobs_share_set_property (GObject      *object,
				     guint         prop_id,
				     const GValue *value,
				     GParamSpec   *pspec);
static void oobs_share_get_property (GObject      *object,
				     guint         prop_id,
				     GValue       *value,
				     GParamSpec   *pspec);
enum
{
  PROP_0,
  PROP_PATH
};

G_DEFINE_ABSTRACT_TYPE (OobsShare, oobs_share, G_TYPE_OBJECT);

static void
oobs_share_class_init (OobsShareClass *class)
{
  GObjectClass *object_class = G_OBJECT_CLASS (class);

  object_class->set_property = oobs_share_set_property;
  object_class->get_property = oobs_share_get_property;
  object_class->finalize     = oobs_share_finalize;

  g_object_class_install_property (object_class,
				   PROP_PATH,
				   g_param_spec_string ("path",
							"Share path",
							"Path for the share",
							NULL,
							G_PARAM_READWRITE));
  g_type_class_add_private (object_class,
			    sizeof (OobsSharePrivate));
}

static void
oobs_share_init (OobsShare *share)
{
  OobsSharePrivate *priv;
  
  g_return_if_fail (OOBS_IS_SHARE (share));
  priv = OOBS_SHARE_GET_PRIVATE (share);
  
  priv->path = NULL;
  share->_priv = priv;
}

static void
oobs_share_finalize (GObject *object)
{
  OobsShare        *share;
  OobsSharePrivate *priv;

  g_return_if_fail (OOBS_IS_SHARE (object));
  share = OOBS_SHARE (object);
  priv  = share->_priv;

  if (priv)
    g_free (priv->path);

  if (G_OBJECT_CLASS (oobs_share_parent_class)->finalize)
    (* G_OBJECT_CLASS (oobs_share_parent_class)->finalize) (object);
}

static void
oobs_share_set_property (GObject      *object,
			 guint         prop_id,
			 const GValue *value,
			 GParamSpec   *pspec)
{
  OobsShare        *share;
  OobsSharePrivate *priv;

  g_return_if_fail (OOBS_IS_SHARE (object));
  share = OOBS_SHARE (object);
  priv  = share->_priv;

  switch (prop_id)
    {
    case PROP_PATH:
      g_free (priv->path);
      priv->path = (gchar*) g_value_dup_string (value);
      break;
    }
}

static void
oobs_share_get_property (GObject      *object,
			 guint         prop_id,
			 GValue       *value,
			 GParamSpec   *pspec)
{
  OobsShare        *share;
  OobsSharePrivate *priv;

  g_return_if_fail (OOBS_IS_SHARE (object));
  share = OOBS_SHARE (object);
  priv  = share->_priv;

  switch (prop_id)
    {
    case PROP_PATH:
      g_value_set_string (value, priv->path);
      break;
    }
}

/**
 * oobs_share_get_path:
 * @share: An #OobsShare.
 * 
 * Returns the path that #share shares.
 * 
 * Return Value: A pointer to the shared path as a string.
 *               This string must not be freed, modified or stored.
 **/
G_CONST_RETURN gchar*
oobs_share_get_path (OobsShare *share)
{
  OobsSharePrivate *priv;

  g_return_val_if_fail (OOBS_IS_SHARE (share), NULL);
  priv = share->_priv;

  return priv->path;
}

/**
 * oobs_share_set_path:
 * @share: An #OobsShare.
 * @path: A new shared path for #share.
 *
 * Sets the shared path of #share to be #path,
 * overwriting the previous one.
 **/
void
oobs_share_set_path (OobsShare *share, const gchar *path)
{
  OobsSharePrivate *priv;

  g_return_if_fail (OOBS_IS_SHARE (share));

  priv = share->_priv;
  priv->path = g_strdup (path);
}