File: oobs-share-smb.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 (332 lines) | stat: -rw-r--r-- 8,313 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
/* -*- 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"
#include "oobs-share-smb.h"

/**
 * SECTION:oobs-share-smb
 * @title: OobsShareSMB
 * @short_description: Object that represents SMB configuration.
 * @see_also: #OobsShare, #OobsSMBConfig
 **/

#define OOBS_SHARE_SMB_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), OOBS_TYPE_SHARE_SMB, OobsShareSMBPrivate))

typedef struct _OobsShareSMBPrivate OobsShareSMBPrivate;

struct _OobsShareSMBPrivate {
  gchar *name;
  gchar *comment;

  OobsShareSMBFlags flags;
};

static void oobs_share_smb_class_init   (OobsShareSMBClass *class);
static void oobs_share_smb_init         (OobsShareSMB      *share);
static void oobs_share_smb_finalize     (GObject          *object);

static void oobs_share_smb_set_property (GObject      *object,
					 guint         prop_id,
					 const GValue *value,
					 GParamSpec   *pspec);
static void oobs_share_smb_get_property (GObject      *object,
					 guint         prop_id,
					 GValue       *value,
					 GParamSpec   *pspec);

enum {
  PROP_0,
  PROP_NAME,
  PROP_COMMENT,
  PROP_FLAGS
};

G_DEFINE_TYPE (OobsShareSMB, oobs_share_smb, OOBS_TYPE_SHARE);

static void
oobs_share_smb_class_init (OobsShareSMBClass *class)
{
  GObjectClass  *object_class = G_OBJECT_CLASS (class);

  object_class->set_property = oobs_share_smb_set_property;
  object_class->get_property = oobs_share_smb_get_property;
  object_class->finalize     = oobs_share_smb_finalize;

  g_object_class_install_property (object_class,
				   PROP_NAME,
				   g_param_spec_string ("name",
							NULL,
							NULL,
							NULL,
							G_PARAM_CONSTRUCT | G_PARAM_READWRITE));
  g_object_class_install_property (object_class,
				   PROP_COMMENT,
				   g_param_spec_string ("comment",
							"Share comment",
							"Comment for the share",
							NULL,
							G_PARAM_CONSTRUCT | G_PARAM_READWRITE));
  g_object_class_install_property (object_class,
				   PROP_FLAGS,
				   g_param_spec_flags ("flags",
						       "Flags",
						       "Property flags for the share",
						       OOBS_TYPE_SHARE_SMB_FLAGS,
						       0,
						       G_PARAM_CONSTRUCT | G_PARAM_READWRITE));
  g_type_class_add_private (object_class,
			    sizeof (OobsShareSMBPrivate));
}

static void
oobs_share_smb_init (OobsShareSMB *share)
{
  OobsShareSMBPrivate *priv;

  g_return_if_fail (OOBS_IS_SHARE_SMB (share));
  priv = OOBS_SHARE_SMB_GET_PRIVATE (share);

  priv->name    = NULL;
  priv->comment = NULL;
  priv->flags   = 0;
  share->_priv  = priv;
}

static void
oobs_share_smb_finalize (GObject *object)
{
  OobsShareSMB        *share;
  OobsShareSMBPrivate *priv;

  g_return_if_fail (OOBS_IS_SHARE_SMB (object));

  share = OOBS_SHARE_SMB (object);
  priv  = share->_priv;

  if (priv)
    {
      g_free (priv->name);
      g_free (priv->comment);
    }

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

static void
oobs_share_smb_set_property (GObject      *object,
			     guint         prop_id,
			     const GValue *value,
			     GParamSpec   *pspec)
{
  OobsShareSMB        *share;
  OobsShareSMBPrivate *priv;

  g_return_if_fail (OOBS_IS_SHARE_SMB (object));

  share = OOBS_SHARE_SMB (object);
  priv  = share->_priv;

  switch (prop_id)
    {
    case PROP_NAME:
      priv->name    = (gchar*) g_value_dup_string (value);
      break;
    case PROP_COMMENT:
      priv->comment = (gchar*) g_value_dup_string (value);
      break;
    case PROP_FLAGS:
      priv->flags   = g_value_get_flags (value);
      break;
    }
}

static void
oobs_share_smb_get_property (GObject      *object,
			     guint         prop_id,
			     GValue       *value,
			     GParamSpec   *pspec)
{
  OobsShareSMB        *share;
  OobsShareSMBPrivate *priv;

  g_return_if_fail (OOBS_IS_SHARE_SMB (object));

  share = OOBS_SHARE_SMB (object);
  priv  = share->_priv;

  switch (prop_id)
    {
    case PROP_NAME:
      g_value_set_string (value, priv->name);
      break;
    case PROP_COMMENT:
      g_value_set_string (value, priv->comment);
      break;
    case PROP_FLAGS:
      g_value_set_flags  (value, priv->flags);
      break;
    }
}

/**
 * oobs_share_smb_get_name:
 * @share: An #OobsShareSMB.
 * 
 * Returns the share name.
 * 
 * Return Value: A pointer to the share name as a string. This
 *               string must not be freed, modified or stored.
 **/
G_CONST_RETURN gchar*
oobs_share_smb_get_name (OobsShareSMB *share)
{
  OobsShareSMBPrivate *priv;

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

  return priv->name;
}

/**
 * oobs_share_smb_set_name:
 * @share: An #OobsShareSMB.
 * @name: new name for the share.
 * 
 * Sets a new name for the share, overwriting the previous one.
 **/
void
oobs_share_smb_set_name (OobsShareSMB *share, const gchar *name)
{
  OobsShareSMBPrivate *priv;

  g_return_if_fail (OOBS_IS_SHARE_SMB (share));

  priv = share->_priv;
  priv->name = g_strdup (name);
  g_object_notify (G_OBJECT (share), "name");
}

/**
 * oobs_share_smb_get_comment:
 * @share: An #OobsShareSMB.
 * 
 * Returns the comment for the share.
 * 
 * Return Value: A pointer to the share comment as a string. This
 *               string must not be freed, modified or stored.
 **/
G_CONST_RETURN gchar*
oobs_share_smb_get_comment (OobsShareSMB *share)
{
  OobsShareSMBPrivate *priv;

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

  return priv->comment;
}

/**
 * oobs_share_smb_set_comment:
 * @share: An #OobsShareSMB.
 * @comment: new comment for the share.
 * 
 * Sets a new comment for the share, overwriting the previous one.
 **/
void
oobs_share_smb_set_comment (OobsShareSMB *share, const gchar *comment)
{
  OobsShareSMBPrivate *priv;

  g_return_if_fail (OOBS_IS_SHARE_SMB (share));

  priv = share->_priv;
  priv->comment = g_strdup (comment);
  g_object_notify (G_OBJECT (share), "comment");
}

/**
 * oobs_share_smb_get_flags:
 * @share: An #OobsShareSMB.
 * 
 * Returns the options mask of the share.
 * 
 * Return Value: #OobsShareSMBFlags mask representing the share options.
 **/
OobsShareSMBFlags
oobs_share_smb_get_flags (OobsShareSMB *share)
{
  OobsShareSMBPrivate *priv;

  g_return_val_if_fail (OOBS_IS_SHARE_SMB (share), 0);
  priv = share->_priv;

  return priv->flags;
}

/**
 * oobs_share_smb_set_flags:
 * @share: An #OobsShareSMB.
 * @flags: mask of options for the share.
 * 
 * Sets a new set of options for the share.
 **/
void
oobs_share_smb_set_flags (OobsShareSMB *share, OobsShareSMBFlags flags)
{
  OobsShareSMBPrivate *priv;

  g_return_if_fail (OOBS_IS_SHARE_SMB (share));

  priv = share->_priv;
  priv->flags = flags;
  g_object_notify (G_OBJECT (share), "flags");
}

/**
 * oobs_share_smb_new:
 * @path: folder path for the new share.
 * @name: name for the new share.
 * @comment: comment for the new share.
 * @flags: options mask for the new share.
 * 
 * Creates a new #OobsShareSMB with the given settings.
 * 
 * Return Value: a newly allocated #OobsShareSMB.
 **/
OobsShare*
oobs_share_smb_new (const gchar       *path,
		    const gchar       *name,
		    const gchar       *comment,
		    OobsShareSMBFlags  flags)
{
  g_return_val_if_fail (path != NULL && path[0] == '/', NULL);

  return g_object_new (OOBS_TYPE_SHARE_SMB,
		       "name",    name,
		       "comment", comment,
		       "flags",   flags,
		       "path",    path,
		       NULL);
}