Blame gio/gmountoperation.c

Packit ae235b
/* GIO - GLib Input, Output and Streaming Library
Packit ae235b
 * 
Packit ae235b
 * Copyright (C) 2006-2007 Red Hat, Inc.
Packit ae235b
 *
Packit ae235b
 * This library is free software; you can redistribute it and/or
Packit ae235b
 * modify it under the terms of the GNU Lesser General Public
Packit ae235b
 * License as published by the Free Software Foundation; either
Packit ae235b
 * version 2.1 of the License, or (at your option) any later version.
Packit ae235b
 *
Packit ae235b
 * This library is distributed in the hope that it will be useful,
Packit ae235b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit ae235b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit ae235b
 * Lesser General Public License for more details.
Packit ae235b
 *
Packit ae235b
 * You should have received a copy of the GNU Lesser General
Packit ae235b
 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit ae235b
 *
Packit ae235b
 * Author: Alexander Larsson <alexl@redhat.com>
Packit ae235b
 */
Packit ae235b
Packit ae235b
#include "config.h"
Packit ae235b
Packit ae235b
#include <string.h>
Packit ae235b
Packit ae235b
#include "gmountoperation.h"
Packit ae235b
#include "gioenumtypes.h"
Packit ae235b
#include "glibintl.h"
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * SECTION:gmountoperation
Packit ae235b
 * @short_description: Object used for authentication and user interaction
Packit ae235b
 * @include: gio/gio.h
Packit ae235b
 *
Packit ae235b
 * #GMountOperation provides a mechanism for interacting with the user.
Packit ae235b
 * It can be used for authenticating mountable operations, such as loop
Packit ae235b
 * mounting files, hard drive partitions or server locations. It can
Packit ae235b
 * also be used to ask the user questions or show a list of applications
Packit ae235b
 * preventing unmount or eject operations from completing.
Packit ae235b
 *
Packit ae235b
 * Note that #GMountOperation is used for more than just #GMount
Packit ae235b
 * objects – for example it is also used in g_drive_start() and
Packit ae235b
 * g_drive_stop().
Packit ae235b
 *
Packit ae235b
 * Users should instantiate a subclass of this that implements all the
Packit ae235b
 * various callbacks to show the required dialogs, such as
Packit ae235b
 * #GtkMountOperation. If no user interaction is desired (for example
Packit ae235b
 * when automounting filesystems at login time), usually %NULL can be
Packit ae235b
 * passed, see each method taking a #GMountOperation for details.
Packit ae235b
 */
Packit ae235b
Packit ae235b
enum {
Packit ae235b
  ASK_PASSWORD,
Packit ae235b
  ASK_QUESTION,
Packit ae235b
  REPLY,
Packit ae235b
  ABORTED,
Packit ae235b
  SHOW_PROCESSES,
Packit ae235b
  SHOW_UNMOUNT_PROGRESS,
Packit ae235b
  LAST_SIGNAL
Packit ae235b
};
Packit ae235b
Packit ae235b
static guint signals[LAST_SIGNAL] = { 0 };
Packit ae235b
Packit ae235b
struct _GMountOperationPrivate {
Packit ae235b
  char *password;
Packit ae235b
  char *user;
Packit ae235b
  char *domain;
Packit ae235b
  gboolean anonymous;
Packit ae235b
  GPasswordSave password_save;
Packit ae235b
  int choice;
Packit ae235b
};
Packit ae235b
Packit ae235b
enum {
Packit ae235b
  PROP_0,
Packit ae235b
  PROP_USERNAME,
Packit ae235b
  PROP_PASSWORD,
Packit ae235b
  PROP_ANONYMOUS,
Packit ae235b
  PROP_DOMAIN,
Packit ae235b
  PROP_PASSWORD_SAVE,
Packit ae235b
  PROP_CHOICE
Packit ae235b
};
Packit ae235b
Packit ae235b
G_DEFINE_TYPE_WITH_PRIVATE (GMountOperation, g_mount_operation, G_TYPE_OBJECT)
Packit ae235b
Packit ae235b
static void 
Packit ae235b
g_mount_operation_set_property (GObject      *object,
Packit ae235b
                                guint         prop_id,
Packit ae235b
                                const GValue *value,
Packit ae235b
                                GParamSpec   *pspec)
Packit ae235b
{
Packit ae235b
  GMountOperation *operation;
Packit ae235b
Packit ae235b
  operation = G_MOUNT_OPERATION (object);
Packit ae235b
Packit ae235b
  switch (prop_id)
Packit ae235b
    {
Packit ae235b
    case PROP_USERNAME:
Packit ae235b
      g_mount_operation_set_username (operation, 
Packit ae235b
                                      g_value_get_string (value));
Packit ae235b
      break;
Packit ae235b
   
Packit ae235b
    case PROP_PASSWORD:
Packit ae235b
      g_mount_operation_set_password (operation, 
Packit ae235b
                                      g_value_get_string (value));
Packit ae235b
      break;
Packit ae235b
Packit ae235b
    case PROP_ANONYMOUS:
Packit ae235b
      g_mount_operation_set_anonymous (operation, 
Packit ae235b
                                       g_value_get_boolean (value));
Packit ae235b
      break;
Packit ae235b
Packit ae235b
    case PROP_DOMAIN:
Packit ae235b
      g_mount_operation_set_domain (operation, 
Packit ae235b
                                    g_value_get_string (value));
Packit ae235b
      break;
Packit ae235b
Packit ae235b
    case PROP_PASSWORD_SAVE:
Packit ae235b
      g_mount_operation_set_password_save (operation, 
Packit ae235b
                                           g_value_get_enum (value));
Packit ae235b
      break;
Packit ae235b
Packit ae235b
    case PROP_CHOICE:
Packit ae235b
      g_mount_operation_set_choice (operation, 
Packit ae235b
                                    g_value_get_int (value));
Packit ae235b
      break;
Packit ae235b
Packit ae235b
    default:
Packit ae235b
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
Packit ae235b
      break;
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
static void 
Packit ae235b
g_mount_operation_get_property (GObject    *object,
Packit ae235b
                                guint       prop_id,
Packit ae235b
                                GValue     *value,
Packit ae235b
                                GParamSpec *pspec)
Packit ae235b
{
Packit ae235b
  GMountOperation *operation;
Packit ae235b
  GMountOperationPrivate *priv;
Packit ae235b
Packit ae235b
  operation = G_MOUNT_OPERATION (object);
Packit ae235b
  priv = operation->priv;
Packit ae235b
  
Packit ae235b
  switch (prop_id)
Packit ae235b
    {
Packit ae235b
    case PROP_USERNAME:
Packit ae235b
      g_value_set_string (value, priv->user);
Packit ae235b
      break;
Packit ae235b
Packit ae235b
    case PROP_PASSWORD:
Packit ae235b
      g_value_set_string (value, priv->password);
Packit ae235b
      break;
Packit ae235b
Packit ae235b
    case PROP_ANONYMOUS:
Packit ae235b
      g_value_set_boolean (value, priv->anonymous);
Packit ae235b
      break;
Packit ae235b
Packit ae235b
    case PROP_DOMAIN:
Packit ae235b
      g_value_set_string (value, priv->domain);
Packit ae235b
      break;
Packit ae235b
Packit ae235b
    case PROP_PASSWORD_SAVE:
Packit ae235b
      g_value_set_enum (value, priv->password_save);
Packit ae235b
      break;
Packit ae235b
Packit ae235b
    case PROP_CHOICE:
Packit ae235b
      g_value_set_int (value, priv->choice);
Packit ae235b
      break;
Packit ae235b
Packit ae235b
    default:
Packit ae235b
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
Packit ae235b
      break;
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_mount_operation_finalize (GObject *object)
Packit ae235b
{
Packit ae235b
  GMountOperation *operation;
Packit ae235b
  GMountOperationPrivate *priv;
Packit ae235b
Packit ae235b
  operation = G_MOUNT_OPERATION (object);
Packit ae235b
Packit ae235b
  priv = operation->priv;
Packit ae235b
  
Packit ae235b
  g_free (priv->password);
Packit ae235b
  g_free (priv->user);
Packit ae235b
  g_free (priv->domain);
Packit ae235b
Packit ae235b
  G_OBJECT_CLASS (g_mount_operation_parent_class)->finalize (object);
Packit ae235b
}
Packit ae235b
Packit ae235b
static gboolean
Packit ae235b
reply_non_handled_in_idle (gpointer data)
Packit ae235b
{
Packit ae235b
  GMountOperation *op = data;
Packit ae235b
Packit ae235b
  g_mount_operation_reply (op, G_MOUNT_OPERATION_UNHANDLED);
Packit ae235b
  return G_SOURCE_REMOVE;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
ask_password (GMountOperation *op,
Packit ae235b
	      const char      *message,
Packit ae235b
	      const char      *default_user,
Packit ae235b
	      const char      *default_domain,
Packit ae235b
	      GAskPasswordFlags flags)
Packit ae235b
{
Packit ae235b
  g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
Packit ae235b
		   reply_non_handled_in_idle,
Packit ae235b
		   g_object_ref (op),
Packit ae235b
		   g_object_unref);
Packit ae235b
}
Packit ae235b
  
Packit ae235b
static void
Packit ae235b
ask_question (GMountOperation *op,
Packit ae235b
	      const char      *message,
Packit ae235b
	      const char      *choices[])
Packit ae235b
{
Packit ae235b
  g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
Packit ae235b
		   reply_non_handled_in_idle,
Packit ae235b
		   g_object_ref (op),
Packit ae235b
		   g_object_unref);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
show_processes (GMountOperation      *op,
Packit ae235b
                const gchar          *message,
Packit ae235b
                GArray               *processes,
Packit ae235b
                const gchar          *choices[])
Packit ae235b
{
Packit ae235b
  g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
Packit ae235b
		   reply_non_handled_in_idle,
Packit ae235b
		   g_object_ref (op),
Packit ae235b
		   g_object_unref);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
show_unmount_progress (GMountOperation *op,
Packit ae235b
                       const gchar     *message,
Packit ae235b
                       gint64           time_left,
Packit ae235b
                       gint64           bytes_left)
Packit ae235b
{
Packit ae235b
  /* nothing to do */
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_mount_operation_class_init (GMountOperationClass *klass)
Packit ae235b
{
Packit ae235b
  GObjectClass *object_class;
Packit ae235b
 
Packit ae235b
  object_class = G_OBJECT_CLASS (klass);
Packit ae235b
  object_class->finalize = g_mount_operation_finalize;
Packit ae235b
  object_class->get_property = g_mount_operation_get_property;
Packit ae235b
  object_class->set_property = g_mount_operation_set_property;
Packit ae235b
  
Packit ae235b
  klass->ask_password = ask_password;
Packit ae235b
  klass->ask_question = ask_question;
Packit ae235b
  klass->show_processes = show_processes;
Packit ae235b
  klass->show_unmount_progress = show_unmount_progress;
Packit ae235b
  
Packit ae235b
  /**
Packit ae235b
   * GMountOperation::ask-password:
Packit ae235b
   * @op: a #GMountOperation requesting a password.
Packit ae235b
   * @message: string containing a message to display to the user.
Packit ae235b
   * @default_user: string containing the default user name.
Packit ae235b
   * @default_domain: string containing the default domain.
Packit ae235b
   * @flags: a set of #GAskPasswordFlags.
Packit ae235b
   *
Packit ae235b
   * Emitted when a mount operation asks the user for a password.
Packit ae235b
   *
Packit ae235b
   * If the message contains a line break, the first line should be
Packit ae235b
   * presented as a heading. For example, it may be used as the
Packit ae235b
   * primary text in a #GtkMessageDialog.
Packit ae235b
   */
Packit ae235b
  signals[ASK_PASSWORD] =
Packit ae235b
    g_signal_new (I_("ask-password"),
Packit ae235b
		  G_TYPE_FROM_CLASS (object_class),
Packit ae235b
		  G_SIGNAL_RUN_LAST,
Packit ae235b
		  G_STRUCT_OFFSET (GMountOperationClass, ask_password),
Packit ae235b
		  NULL, NULL,
Packit ae235b
		  NULL,
Packit ae235b
		  G_TYPE_NONE, 4,
Packit ae235b
		  G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_ASK_PASSWORD_FLAGS);
Packit ae235b
		  
Packit ae235b
  /**
Packit ae235b
   * GMountOperation::ask-question:
Packit ae235b
   * @op: a #GMountOperation asking a question.
Packit ae235b
   * @message: string containing a message to display to the user.
Packit ae235b
   * @choices: an array of strings for each possible choice.
Packit ae235b
   *
Packit ae235b
   * Emitted when asking the user a question and gives a list of
Packit ae235b
   * choices for the user to choose from.
Packit ae235b
   *
Packit ae235b
   * If the message contains a line break, the first line should be
Packit ae235b
   * presented as a heading. For example, it may be used as the
Packit ae235b
   * primary text in a #GtkMessageDialog.
Packit ae235b
   */
Packit ae235b
  signals[ASK_QUESTION] =
Packit ae235b
    g_signal_new (I_("ask-question"),
Packit ae235b
		  G_TYPE_FROM_CLASS (object_class),
Packit ae235b
		  G_SIGNAL_RUN_LAST,
Packit ae235b
		  G_STRUCT_OFFSET (GMountOperationClass, ask_question),
Packit ae235b
		  NULL, NULL,
Packit ae235b
		  NULL,
Packit ae235b
		  G_TYPE_NONE, 2,
Packit ae235b
		  G_TYPE_STRING, G_TYPE_STRV);
Packit ae235b
		  
Packit ae235b
  /**
Packit ae235b
   * GMountOperation::reply:
Packit ae235b
   * @op: a #GMountOperation.
Packit ae235b
   * @result: a #GMountOperationResult indicating how the request was handled
Packit ae235b
   *
Packit ae235b
   * Emitted when the user has replied to the mount operation.
Packit ae235b
   */
Packit ae235b
  signals[REPLY] =
Packit ae235b
    g_signal_new (I_("reply"),
Packit ae235b
		  G_TYPE_FROM_CLASS (object_class),
Packit ae235b
		  G_SIGNAL_RUN_LAST,
Packit ae235b
		  G_STRUCT_OFFSET (GMountOperationClass, reply),
Packit ae235b
		  NULL, NULL,
Packit ae235b
		  g_cclosure_marshal_VOID__ENUM,
Packit ae235b
		  G_TYPE_NONE, 1,
Packit ae235b
		  G_TYPE_MOUNT_OPERATION_RESULT);
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GMountOperation::aborted:
Packit ae235b
   *
Packit ae235b
   * Emitted by the backend when e.g. a device becomes unavailable
Packit ae235b
   * while a mount operation is in progress.
Packit ae235b
   *
Packit ae235b
   * Implementations of GMountOperation should handle this signal
Packit ae235b
   * by dismissing open password dialogs.
Packit ae235b
   *
Packit ae235b
   * Since: 2.20
Packit ae235b
   */
Packit ae235b
  signals[ABORTED] =
Packit ae235b
    g_signal_new (I_("aborted"),
Packit ae235b
		  G_TYPE_FROM_CLASS (object_class),
Packit ae235b
		  G_SIGNAL_RUN_LAST,
Packit ae235b
		  G_STRUCT_OFFSET (GMountOperationClass, aborted),
Packit ae235b
		  NULL, NULL,
Packit ae235b
		  g_cclosure_marshal_VOID__VOID,
Packit ae235b
		  G_TYPE_NONE, 0);
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GMountOperation::show-processes:
Packit ae235b
   * @op: a #GMountOperation.
Packit ae235b
   * @message: string containing a message to display to the user.
Packit ae235b
   * @processes: (element-type GPid): an array of #GPid for processes
Packit ae235b
   *   blocking the operation.
Packit ae235b
   * @choices: an array of strings for each possible choice.
Packit ae235b
   *
Packit ae235b
   * Emitted when one or more processes are blocking an operation
Packit ae235b
   * e.g. unmounting/ejecting a #GMount or stopping a #GDrive.
Packit ae235b
   *
Packit ae235b
   * Note that this signal may be emitted several times to update the
Packit ae235b
   * list of blocking processes as processes close files. The
Packit ae235b
   * application should only respond with g_mount_operation_reply() to
Packit ae235b
   * the latest signal (setting #GMountOperation:choice to the choice
Packit ae235b
   * the user made).
Packit ae235b
   *
Packit ae235b
   * If the message contains a line break, the first line should be
Packit ae235b
   * presented as a heading. For example, it may be used as the
Packit ae235b
   * primary text in a #GtkMessageDialog.
Packit ae235b
   *
Packit ae235b
   * Since: 2.22
Packit ae235b
   */
Packit ae235b
  signals[SHOW_PROCESSES] =
Packit ae235b
    g_signal_new (I_("show-processes"),
Packit ae235b
		  G_TYPE_FROM_CLASS (object_class),
Packit ae235b
		  G_SIGNAL_RUN_LAST,
Packit ae235b
		  G_STRUCT_OFFSET (GMountOperationClass, show_processes),
Packit ae235b
		  NULL, NULL,
Packit ae235b
		  NULL,
Packit ae235b
		  G_TYPE_NONE, 3,
Packit ae235b
		  G_TYPE_STRING, G_TYPE_ARRAY, G_TYPE_STRV);
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GMountOperation::show-unmount-progress:
Packit ae235b
   * @op: a #GMountOperation:
Packit ae235b
   * @message: string containing a mesage to display to the user
Packit ae235b
   * @time_left: the estimated time left before the operation completes,
Packit ae235b
   *     in microseconds, or -1
Packit ae235b
   * @bytes_left: the amount of bytes to be written before the operation
Packit ae235b
   *     completes (or -1 if such amount is not known), or zero if the operation
Packit ae235b
   *     is completed
Packit ae235b
   *
Packit ae235b
   * Emitted when an unmount operation has been busy for more than some time
Packit ae235b
   * (typically 1.5 seconds).
Packit ae235b
   *
Packit ae235b
   * When unmounting or ejecting a volume, the kernel might need to flush
Packit ae235b
   * pending data in its buffers to the volume stable storage, and this operation
Packit ae235b
   * can take a considerable amount of time. This signal may be emitted several
Packit ae235b
   * times as long as the unmount operation is outstanding, and then one
Packit ae235b
   * last time when the operation is completed, with @bytes_left set to zero.
Packit ae235b
   *
Packit ae235b
   * Implementations of GMountOperation should handle this signal by
Packit ae235b
   * showing an UI notification, and then dismiss it, or show another notification
Packit ae235b
   * of completion, when @bytes_left reaches zero.
Packit ae235b
   *
Packit ae235b
   * If the message contains a line break, the first line should be
Packit ae235b
   * presented as a heading. For example, it may be used as the
Packit ae235b
   * primary text in a #GtkMessageDialog.
Packit ae235b
   *
Packit ae235b
   * Since: 2.34
Packit ae235b
   */
Packit ae235b
  signals[SHOW_UNMOUNT_PROGRESS] =
Packit ae235b
    g_signal_new (I_("show-unmount-progress"),
Packit ae235b
                  G_TYPE_FROM_CLASS (object_class),
Packit ae235b
                  G_SIGNAL_RUN_LAST,
Packit ae235b
                  G_STRUCT_OFFSET (GMountOperationClass, show_unmount_progress),
Packit ae235b
                  NULL, NULL, NULL,
Packit ae235b
                  G_TYPE_NONE, 3,
Packit ae235b
                  G_TYPE_STRING, G_TYPE_INT64, G_TYPE_INT64);
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GMountOperation:username:
Packit ae235b
   *
Packit ae235b
   * The user name that is used for authentication when carrying out
Packit ae235b
   * the mount operation.
Packit ae235b
   */ 
Packit ae235b
  g_object_class_install_property (object_class,
Packit ae235b
                                   PROP_USERNAME,
Packit ae235b
                                   g_param_spec_string ("username",
Packit ae235b
                                                        P_("Username"),
Packit ae235b
                                                        P_("The user name"),
Packit ae235b
                                                        NULL,
Packit ae235b
                                                        G_PARAM_READWRITE|
Packit ae235b
                                                        G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GMountOperation:password:
Packit ae235b
   *
Packit ae235b
   * The password that is used for authentication when carrying out
Packit ae235b
   * the mount operation.
Packit ae235b
   */ 
Packit ae235b
  g_object_class_install_property (object_class,
Packit ae235b
                                   PROP_PASSWORD,
Packit ae235b
                                   g_param_spec_string ("password",
Packit ae235b
                                                        P_("Password"),
Packit ae235b
                                                        P_("The password"),
Packit ae235b
                                                        NULL,
Packit ae235b
                                                        G_PARAM_READWRITE|
Packit ae235b
                                                        G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GMountOperation:anonymous:
Packit ae235b
   * 
Packit ae235b
   * Whether to use an anonymous user when authenticating.
Packit ae235b
   */
Packit ae235b
  g_object_class_install_property (object_class,
Packit ae235b
                                   PROP_ANONYMOUS,
Packit ae235b
                                   g_param_spec_boolean ("anonymous",
Packit ae235b
                                                         P_("Anonymous"),
Packit ae235b
                                                         P_("Whether to use an anonymous user"),
Packit ae235b
                                                         FALSE,
Packit ae235b
                                                         G_PARAM_READWRITE|
Packit ae235b
                                                         G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GMountOperation:domain:
Packit ae235b
   *
Packit ae235b
   * The domain to use for the mount operation.
Packit ae235b
   */ 
Packit ae235b
  g_object_class_install_property (object_class,
Packit ae235b
                                   PROP_DOMAIN,
Packit ae235b
                                   g_param_spec_string ("domain",
Packit ae235b
                                                        P_("Domain"),
Packit ae235b
                                                        P_("The domain of the mount operation"),
Packit ae235b
                                                        NULL,
Packit ae235b
                                                        G_PARAM_READWRITE|
Packit ae235b
                                                        G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GMountOperation:password-save:
Packit ae235b
   *
Packit ae235b
   * Determines if and how the password information should be saved. 
Packit ae235b
   */ 
Packit ae235b
  g_object_class_install_property (object_class,
Packit ae235b
                                   PROP_PASSWORD_SAVE,
Packit ae235b
                                   g_param_spec_enum ("password-save",
Packit ae235b
                                                      P_("Password save"),
Packit ae235b
                                                      P_("How passwords should be saved"),
Packit ae235b
                                                      G_TYPE_PASSWORD_SAVE,
Packit ae235b
                                                      G_PASSWORD_SAVE_NEVER,
Packit ae235b
                                                      G_PARAM_READWRITE|
Packit ae235b
                                                      G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GMountOperation:choice:
Packit ae235b
   *
Packit ae235b
   * The index of the user's choice when a question is asked during the 
Packit ae235b
   * mount operation. See the #GMountOperation::ask-question signal.
Packit ae235b
   */ 
Packit ae235b
  g_object_class_install_property (object_class,
Packit ae235b
                                   PROP_CHOICE,
Packit ae235b
                                   g_param_spec_int ("choice",
Packit ae235b
                                                     P_("Choice"),
Packit ae235b
                                                     P_("The users choice"),
Packit ae235b
                                                     0, G_MAXINT, 0,
Packit ae235b
                                                     G_PARAM_READWRITE|
Packit ae235b
                                                     G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_mount_operation_init (GMountOperation *operation)
Packit ae235b
{
Packit ae235b
  operation->priv = g_mount_operation_get_instance_private (operation);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_operation_new:
Packit ae235b
 * 
Packit ae235b
 * Creates a new mount operation.
Packit ae235b
 * 
Packit ae235b
 * Returns: a #GMountOperation.
Packit ae235b
 **/
Packit ae235b
GMountOperation *
Packit ae235b
g_mount_operation_new (void)
Packit ae235b
{
Packit ae235b
  return g_object_new (G_TYPE_MOUNT_OPERATION, NULL);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_operation_get_username:
Packit ae235b
 * @op: a #GMountOperation.
Packit ae235b
 * 
Packit ae235b
 * Get the user name from the mount operation.
Packit ae235b
 *
Packit ae235b
 * Returns: a string containing the user name.
Packit ae235b
 **/
Packit ae235b
const char *
Packit ae235b
g_mount_operation_get_username (GMountOperation *op)
Packit ae235b
{
Packit ae235b
  g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), NULL);
Packit ae235b
  return op->priv->user;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_operation_set_username:
Packit ae235b
 * @op: a #GMountOperation.
Packit ae235b
 * @username: input username.
Packit ae235b
 *
Packit ae235b
 * Sets the user name within @op to @username.
Packit ae235b
 **/
Packit ae235b
void
Packit ae235b
g_mount_operation_set_username (GMountOperation *op,
Packit ae235b
				const char      *username)
Packit ae235b
{
Packit ae235b
  g_return_if_fail (G_IS_MOUNT_OPERATION (op));
Packit ae235b
  g_free (op->priv->user);
Packit ae235b
  op->priv->user = g_strdup (username);
Packit ae235b
  g_object_notify (G_OBJECT (op), "username");
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_operation_get_password:
Packit ae235b
 * @op: a #GMountOperation.
Packit ae235b
 *
Packit ae235b
 * Gets a password from the mount operation. 
Packit ae235b
 *
Packit ae235b
 * Returns: a string containing the password within @op.
Packit ae235b
 **/
Packit ae235b
const char *
Packit ae235b
g_mount_operation_get_password (GMountOperation *op)
Packit ae235b
{
Packit ae235b
  g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), NULL);
Packit ae235b
  return op->priv->password;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_operation_set_password:
Packit ae235b
 * @op: a #GMountOperation.
Packit ae235b
 * @password: password to set.
Packit ae235b
 * 
Packit ae235b
 * Sets the mount operation's password to @password.  
Packit ae235b
 *
Packit ae235b
 **/
Packit ae235b
void
Packit ae235b
g_mount_operation_set_password (GMountOperation *op,
Packit ae235b
				const char      *password)
Packit ae235b
{
Packit ae235b
  g_return_if_fail (G_IS_MOUNT_OPERATION (op));
Packit ae235b
  g_free (op->priv->password);
Packit ae235b
  op->priv->password = g_strdup (password);
Packit ae235b
  g_object_notify (G_OBJECT (op), "password");
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_operation_get_anonymous:
Packit ae235b
 * @op: a #GMountOperation.
Packit ae235b
 * 
Packit ae235b
 * Check to see whether the mount operation is being used 
Packit ae235b
 * for an anonymous user.
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE if mount operation is anonymous. 
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_mount_operation_get_anonymous (GMountOperation *op)
Packit ae235b
{
Packit ae235b
  g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), FALSE);
Packit ae235b
  return op->priv->anonymous;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_operation_set_anonymous:
Packit ae235b
 * @op: a #GMountOperation.
Packit ae235b
 * @anonymous: boolean value.
Packit ae235b
 * 
Packit ae235b
 * Sets the mount operation to use an anonymous user if @anonymous is %TRUE.
Packit ae235b
 **/  
Packit ae235b
void
Packit ae235b
g_mount_operation_set_anonymous (GMountOperation *op,
Packit ae235b
				 gboolean         anonymous)
Packit ae235b
{
Packit ae235b
  GMountOperationPrivate *priv;
Packit ae235b
  g_return_if_fail (G_IS_MOUNT_OPERATION (op));
Packit ae235b
  priv = op->priv;
Packit ae235b
Packit ae235b
  if (priv->anonymous != anonymous)
Packit ae235b
    {
Packit ae235b
      priv->anonymous = anonymous;
Packit ae235b
      g_object_notify (G_OBJECT (op), "anonymous");
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_operation_get_domain:
Packit ae235b
 * @op: a #GMountOperation.
Packit ae235b
 * 
Packit ae235b
 * Gets the domain of the mount operation.
Packit ae235b
 * 
Packit ae235b
 * Returns: a string set to the domain. 
Packit ae235b
 **/
Packit ae235b
const char *
Packit ae235b
g_mount_operation_get_domain (GMountOperation *op)
Packit ae235b
{
Packit ae235b
  g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), NULL);
Packit ae235b
  return op->priv->domain;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_operation_set_domain:
Packit ae235b
 * @op: a #GMountOperation.
Packit ae235b
 * @domain: the domain to set.
Packit ae235b
 * 
Packit ae235b
 * Sets the mount operation's domain. 
Packit ae235b
 **/  
Packit ae235b
void
Packit ae235b
g_mount_operation_set_domain (GMountOperation *op,
Packit ae235b
			      const char      *domain)
Packit ae235b
{
Packit ae235b
  g_return_if_fail (G_IS_MOUNT_OPERATION (op));
Packit ae235b
  g_free (op->priv->domain);
Packit ae235b
  op->priv->domain = g_strdup (domain);
Packit ae235b
  g_object_notify (G_OBJECT (op), "domain");
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_operation_get_password_save:
Packit ae235b
 * @op: a #GMountOperation.
Packit ae235b
 * 
Packit ae235b
 * Gets the state of saving passwords for the mount operation.
Packit ae235b
 *
Packit ae235b
 * Returns: a #GPasswordSave flag. 
Packit ae235b
 **/  
Packit ae235b
Packit ae235b
GPasswordSave
Packit ae235b
g_mount_operation_get_password_save (GMountOperation *op)
Packit ae235b
{
Packit ae235b
  g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), G_PASSWORD_SAVE_NEVER);
Packit ae235b
  return op->priv->password_save;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_operation_set_password_save:
Packit ae235b
 * @op: a #GMountOperation.
Packit ae235b
 * @save: a set of #GPasswordSave flags.
Packit ae235b
 * 
Packit ae235b
 * Sets the state of saving passwords for the mount operation.
Packit ae235b
 * 
Packit ae235b
 **/   
Packit ae235b
void
Packit ae235b
g_mount_operation_set_password_save (GMountOperation *op,
Packit ae235b
				     GPasswordSave    save)
Packit ae235b
{
Packit ae235b
  GMountOperationPrivate *priv;
Packit ae235b
  g_return_if_fail (G_IS_MOUNT_OPERATION (op));
Packit ae235b
  priv = op->priv;
Packit ae235b
 
Packit ae235b
  if (priv->password_save != save)
Packit ae235b
    {
Packit ae235b
      priv->password_save = save;
Packit ae235b
      g_object_notify (G_OBJECT (op), "password-save");
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_operation_get_choice:
Packit ae235b
 * @op: a #GMountOperation.
Packit ae235b
 * 
Packit ae235b
 * Gets a choice from the mount operation.
Packit ae235b
 *
Packit ae235b
 * Returns: an integer containing an index of the user's choice from 
Packit ae235b
 * the choice's list, or %0.
Packit ae235b
 **/
Packit ae235b
int
Packit ae235b
g_mount_operation_get_choice (GMountOperation *op)
Packit ae235b
{
Packit ae235b
  g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), 0);
Packit ae235b
  return op->priv->choice;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_operation_set_choice:
Packit ae235b
 * @op: a #GMountOperation.
Packit ae235b
 * @choice: an integer.
Packit ae235b
 *
Packit ae235b
 * Sets a default choice for the mount operation.
Packit ae235b
 **/
Packit ae235b
void
Packit ae235b
g_mount_operation_set_choice (GMountOperation *op,
Packit ae235b
			      int              choice)
Packit ae235b
{
Packit ae235b
  GMountOperationPrivate *priv;
Packit ae235b
  g_return_if_fail (G_IS_MOUNT_OPERATION (op));
Packit ae235b
  priv = op->priv;
Packit ae235b
  if (priv->choice != choice)
Packit ae235b
    {
Packit ae235b
      priv->choice = choice;
Packit ae235b
      g_object_notify (G_OBJECT (op), "choice");
Packit ae235b
    }
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_mount_operation_reply:
Packit ae235b
 * @op: a #GMountOperation
Packit ae235b
 * @result: a #GMountOperationResult
Packit ae235b
 * 
Packit ae235b
 * Emits the #GMountOperation::reply signal.
Packit ae235b
 **/
Packit ae235b
void
Packit ae235b
g_mount_operation_reply (GMountOperation *op,
Packit ae235b
			 GMountOperationResult result)
Packit ae235b
{
Packit ae235b
  g_return_if_fail (G_IS_MOUNT_OPERATION (op));
Packit ae235b
  g_signal_emit (op, signals[REPLY], 0, result);
Packit ae235b
}