1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2006-2007 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: Alexander Larsson <alexl@redhat.com>
27 #include "gmountoperation.h"
28 #include "gio-marshal.h"
31 G_DEFINE_TYPE (GMountOperation, g_mount_operation, G_TYPE_OBJECT);
40 static guint signals[LAST_SIGNAL] = { 0 };
42 struct _GMountOperationPrivate {
47 GPasswordSave password_save;
52 g_mount_operation_finalize (GObject *object)
54 GMountOperation *operation;
55 GMountOperationPrivate *priv;
57 operation = G_MOUNT_OPERATION (object);
59 priv = operation->priv;
61 g_free (priv->password);
63 g_free (priv->domain);
65 if (G_OBJECT_CLASS (g_mount_operation_parent_class)->finalize)
66 (*G_OBJECT_CLASS (g_mount_operation_parent_class)->finalize) (object);
70 boolean_handled_accumulator (GSignalInvocationHint *ihint,
72 const GValue *handler_return,
75 gboolean continue_emission;
76 gboolean signal_handled;
78 signal_handled = g_value_get_boolean (handler_return);
79 g_value_set_boolean (return_accu, signal_handled);
80 continue_emission = !signal_handled;
82 return continue_emission;
86 ask_password (GMountOperation *op,
88 const char *default_user,
89 const char *default_domain,
96 ask_question (GMountOperation *op,
98 const char *choices[])
104 g_mount_operation_class_init (GMountOperationClass *klass)
106 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
108 g_type_class_add_private (klass, sizeof (GMountOperationPrivate));
110 gobject_class->finalize = g_mount_operation_finalize;
112 klass->ask_password = ask_password;
113 klass->ask_question = ask_question;
115 signals[ASK_PASSWORD] =
116 g_signal_new (I_("ask_password"),
117 G_TYPE_FROM_CLASS (gobject_class),
119 G_STRUCT_OFFSET (GMountOperationClass, ask_password),
120 boolean_handled_accumulator, NULL,
121 _gio_marshal_BOOLEAN__STRING_STRING_STRING_INT,
123 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT);
125 signals[ASK_QUESTION] =
126 g_signal_new (I_("ask_question"),
127 G_TYPE_FROM_CLASS (gobject_class),
129 G_STRUCT_OFFSET (GMountOperationClass, ask_question),
130 boolean_handled_accumulator, NULL,
131 _gio_marshal_BOOLEAN__STRING_POINTER,
133 G_TYPE_STRING, G_TYPE_POINTER);
136 g_signal_new (I_("reply"),
137 G_TYPE_FROM_CLASS (gobject_class),
139 G_STRUCT_OFFSET (GMountOperationClass, reply),
141 g_cclosure_marshal_VOID__BOOLEAN,
147 g_mount_operation_init (GMountOperation *operation)
149 operation->priv = G_TYPE_INSTANCE_GET_PRIVATE (operation,
150 G_TYPE_MOUNT_OPERATION,
151 GMountOperationPrivate);
155 * g_mount_operation_new:
157 * Returns: a new #GMountOperation.
160 g_mount_operation_new (void)
162 return g_object_new (G_TYPE_MOUNT_OPERATION, NULL);
166 * g_mount_operation_get_username
172 g_mount_operation_get_username (GMountOperation *op)
174 g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), NULL);
175 return op->priv->user;
179 * g_mount_operation_set_username:
181 * @username: input username.
185 g_mount_operation_set_username (GMountOperation *op,
186 const char *username)
188 g_return_if_fail (G_IS_MOUNT_OPERATION (op));
189 g_free (op->priv->user);
190 op->priv->user = g_strdup (username);
194 * g_mount_operation_get_password:
200 g_mount_operation_get_password (GMountOperation *op)
202 g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), NULL);
203 return op->priv->password;
207 * g_mount_operation_set_password:
208 * @op: the given #GMountOperation.
209 * @password: password to set.
211 * Sets the mount operation's password to @password.
215 g_mount_operation_set_password (GMountOperation *op,
216 const char *password)
218 g_return_if_fail (G_IS_MOUNT_OPERATION (op));
219 g_free (op->priv->password);
220 op->priv->password = g_strdup (password);
224 * g_mount_operation_get_anonymous:
227 * Returns: %TRUE if mount operation is anonymous.
230 g_mount_operation_get_anonymous (GMountOperation *op)
232 g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), FALSE);
233 return op->priv->anonymous;
237 * g_mount_operation_set_anonymous:
238 * @op: the given #GMountOperation.
239 * @anonymous: boolean value.
243 g_mount_operation_set_anonymous (GMountOperation *op,
246 g_return_if_fail (G_IS_MOUNT_OPERATION (op));
247 op->priv->anonymous = anonymous;
251 * g_mount_operation_get_domain:
254 * Returns: a const string set to the domain.
257 g_mount_operation_get_domain (GMountOperation *op)
259 g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), NULL);
260 return op->priv->domain;
264 * g_mount_operation_set_domain:
265 * @op: the given #GMountOperation.
266 * @domain: the domain to set.
268 * Sets the mount operation's domain.
271 g_mount_operation_set_domain (GMountOperation *op,
274 g_return_if_fail (G_IS_MOUNT_OPERATION (op));
275 g_free (op->priv->domain);
276 op->priv->domain = g_strdup (domain);
280 * g_mount_operation_get_password_save:
281 * @op: the given #GMountOperation.
283 * Returns: #GPasswordSave.
287 g_mount_operation_get_password_save (GMountOperation *op)
289 g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), G_PASSWORD_SAVE_NEVER);
290 return op->priv->password_save;
294 * g_mount_operation_set_password_save
296 * @save: #GPasswordSave
300 g_mount_operation_set_password_save (GMountOperation *op,
303 g_return_if_fail (G_IS_MOUNT_OPERATION (op));
304 op->priv->password_save = save;
308 * g_mount_operation_get_choice:
314 g_mount_operation_get_choice (GMountOperation *op)
316 g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), 0);
317 return op->priv->choice;
321 * g_mount_operation_set_choice:
327 g_mount_operation_set_choice (GMountOperation *op,
330 g_return_if_fail (G_IS_MOUNT_OPERATION (op));
331 op->priv->choice = choice;
335 * g_mount_operation_reply:
336 * @op: #GMountOperation.
339 * Emits the #GMountOperation::Reply signal with the abort flag set to
343 g_mount_operation_reply (GMountOperation *op,
346 g_return_if_fail (G_IS_MOUNT_OPERATION (op));
347 g_signal_emit (op, signals[REPLY], 0, abort);