gmountoperation.c 29.1 KB
Newer Older
1 2 3 4 5 6 7
/* GIO - GLib Input, Output and Streaming Library
 * 
 * Copyright (C) 2006-2007 Red Hat, Inc.
 *
 * This library 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
8
 * version 2.1 of the License, or (at your option) any later version.
9 10 11 12 13 14 15
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General
16
 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 18 19 20
 *
 * Author: Alexander Larsson <alexl@redhat.com>
 */

21
#include "config.h"
22 23 24 25

#include <string.h>

#include "gmountoperation.h"
Matthias Clasen's avatar
Matthias Clasen committed
26
#include "gioenumtypes.h"
27 28
#include "glibintl.h"

29

30
/**
31
 * SECTION:gmountoperation
32
 * @short_description: Object used for authentication and user interaction
Matthias Clasen's avatar
Matthias Clasen committed
33
 * @include: gio/gio.h
34
 *
35 36 37 38 39
 * #GMountOperation provides a mechanism for interacting with the user.
 * It can be used for authenticating mountable operations, such as loop
 * mounting files, hard drive partitions or server locations. It can
 * also be used to ask the user questions or show a list of applications
 * preventing unmount or eject operations from completing.
40
 *
41 42 43
 * Note that #GMountOperation is used for more than just #GMount
 * objects – for example it is also used in g_drive_start() and
 * g_drive_stop().
44
 *
45 46 47 48 49
 * Users should instantiate a subclass of this that implements all the
 * various callbacks to show the required dialogs, such as
 * #GtkMountOperation. If no user interaction is desired (for example
 * when automounting filesystems at login time), usually %NULL can be
 * passed, see each method taking a #GMountOperation for details.
50 51 52 53 54 55
 *
 * The term ‘TCRYPT’ is used to mean ‘compatible with TrueCrypt and VeraCrypt’.
 * [TrueCrypt](https://en.wikipedia.org/wiki/TrueCrypt) is a discontinued system for
 * encrypting file containers, partitions or whole disks, typically used with Windows.
 * [VeraCrypt](https://www.veracrypt.fr/) is a maintained fork of TrueCrypt with various
 * improvements and auditing fixes.
56
 */
57

58 59 60 61
enum {
  ASK_PASSWORD,
  ASK_QUESTION,
  REPLY,
62
  ABORTED,
63
  SHOW_PROCESSES,
64
  SHOW_UNMOUNT_PROGRESS,
65 66 67 68 69 70 71 72 73 74 75 76
  LAST_SIGNAL
};

static guint signals[LAST_SIGNAL] = { 0 };

struct _GMountOperationPrivate {
  char *password;
  char *user;
  char *domain;
  gboolean anonymous;
  GPasswordSave password_save;
  int choice;
77 78 79
  gboolean hidden_volume;
  gboolean system_volume;
  guint pim;
80 81
};

Matthias Clasen's avatar
Matthias Clasen committed
82 83 84 85 86 87 88
enum {
  PROP_0,
  PROP_USERNAME,
  PROP_PASSWORD,
  PROP_ANONYMOUS,
  PROP_DOMAIN,
  PROP_PASSWORD_SAVE,
89 90 91 92
  PROP_CHOICE,
  PROP_IS_TCRYPT_HIDDEN_VOLUME,
  PROP_IS_TCRYPT_SYSTEM_VOLUME,
  PROP_PIM
Matthias Clasen's avatar
Matthias Clasen committed
93 94
};

95 96
G_DEFINE_TYPE_WITH_PRIVATE (GMountOperation, g_mount_operation, G_TYPE_OBJECT)

Matthias Clasen's avatar
Matthias Clasen committed
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
static void 
g_mount_operation_set_property (GObject      *object,
                                guint         prop_id,
                                const GValue *value,
                                GParamSpec   *pspec)
{
  GMountOperation *operation;

  operation = G_MOUNT_OPERATION (object);

  switch (prop_id)
    {
    case PROP_USERNAME:
      g_mount_operation_set_username (operation, 
                                      g_value_get_string (value));
      break;
   
    case PROP_PASSWORD:
      g_mount_operation_set_password (operation, 
                                      g_value_get_string (value));
      break;

    case PROP_ANONYMOUS:
      g_mount_operation_set_anonymous (operation, 
                                       g_value_get_boolean (value));
      break;

    case PROP_DOMAIN:
      g_mount_operation_set_domain (operation, 
                                    g_value_get_string (value));
      break;

    case PROP_PASSWORD_SAVE:
      g_mount_operation_set_password_save (operation, 
                                           g_value_get_enum (value));
      break;

    case PROP_CHOICE:
      g_mount_operation_set_choice (operation, 
                                    g_value_get_int (value));
      break;

139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
    case PROP_IS_TCRYPT_HIDDEN_VOLUME:
      g_mount_operation_set_is_tcrypt_hidden_volume (operation,
                                                     g_value_get_boolean (value));
      break;

    case PROP_IS_TCRYPT_SYSTEM_VOLUME:
      g_mount_operation_set_is_tcrypt_system_volume (operation,
                                                     g_value_get_boolean (value));
      break;

    case PROP_PIM:
        g_mount_operation_set_pim (operation,
                                   g_value_get_uint (value));
        break;

Matthias Clasen's avatar
Matthias Clasen committed
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
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}


static void 
g_mount_operation_get_property (GObject    *object,
                                guint       prop_id,
                                GValue     *value,
                                GParamSpec *pspec)
{
  GMountOperation *operation;
  GMountOperationPrivate *priv;

  operation = G_MOUNT_OPERATION (object);
  priv = operation->priv;
  
  switch (prop_id)
    {
    case PROP_USERNAME:
      g_value_set_string (value, priv->user);
      break;

    case PROP_PASSWORD:
      g_value_set_string (value, priv->password);
      break;

    case PROP_ANONYMOUS:
      g_value_set_boolean (value, priv->anonymous);
      break;

    case PROP_DOMAIN:
      g_value_set_string (value, priv->domain);
      break;

    case PROP_PASSWORD_SAVE:
      g_value_set_enum (value, priv->password_save);
      break;

    case PROP_CHOICE:
      g_value_set_int (value, priv->choice);
      break;

199 200 201 202 203 204 205 206 207 208 209 210
    case PROP_IS_TCRYPT_HIDDEN_VOLUME:
      g_value_set_boolean (value, priv->hidden_volume);
      break;

    case PROP_IS_TCRYPT_SYSTEM_VOLUME:
      g_value_set_boolean (value, priv->system_volume);
      break;

    case PROP_PIM:
      g_value_set_uint (value, priv->pim);
      break;

Matthias Clasen's avatar
Matthias Clasen committed
211 212 213 214 215 216 217
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}


218 219 220 221 222 223 224 225 226 227 228 229 230
static void
g_mount_operation_finalize (GObject *object)
{
  GMountOperation *operation;
  GMountOperationPrivate *priv;

  operation = G_MOUNT_OPERATION (object);

  priv = operation->priv;
  
  g_free (priv->password);
  g_free (priv->user);
  g_free (priv->domain);
231 232

  G_OBJECT_CLASS (g_mount_operation_parent_class)->finalize (object);
233 234 235
}

static gboolean
236
reply_non_handled_in_idle (gpointer data)
237
{
238 239 240
  GMountOperation *op = data;

  g_mount_operation_reply (op, G_MOUNT_OPERATION_UNHANDLED);
241
  return G_SOURCE_REMOVE;
242 243
}

244
static void
245 246 247 248
ask_password (GMountOperation *op,
	      const char      *message,
	      const char      *default_user,
	      const char      *default_domain,
249
	      GAskPasswordFlags flags)
250
{
251 252 253 254
  g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
		   reply_non_handled_in_idle,
		   g_object_ref (op),
		   g_object_unref);
255 256
}
  
257
static void
258 259 260 261
ask_question (GMountOperation *op,
	      const char      *message,
	      const char      *choices[])
{
262 263 264 265
  g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
		   reply_non_handled_in_idle,
		   g_object_ref (op),
		   g_object_unref);
266 267
}

268 269 270 271 272 273 274 275 276 277 278 279
static void
show_processes (GMountOperation      *op,
                const gchar          *message,
                GArray               *processes,
                const gchar          *choices[])
{
  g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
		   reply_non_handled_in_idle,
		   g_object_ref (op),
		   g_object_unref);
}

280 281 282
static void
show_unmount_progress (GMountOperation *op,
                       const gchar     *message,
283 284
                       gint64           time_left,
                       gint64           bytes_left)
285 286 287 288
{
  /* nothing to do */
}

289 290 291
static void
g_mount_operation_class_init (GMountOperationClass *klass)
{
Matthias Clasen's avatar
Matthias Clasen committed
292 293 294 295 296 297
  GObjectClass *object_class;
 
  object_class = G_OBJECT_CLASS (klass);
  object_class->finalize = g_mount_operation_finalize;
  object_class->get_property = g_mount_operation_get_property;
  object_class->set_property = g_mount_operation_set_property;
298 299 300
  
  klass->ask_password = ask_password;
  klass->ask_question = ask_question;
301
  klass->show_processes = show_processes;
302
  klass->show_unmount_progress = show_unmount_progress;
303
  
304 305 306 307 308 309
  /**
   * GMountOperation::ask-password:
   * @op: a #GMountOperation requesting a password.
   * @message: string containing a message to display to the user.
   * @default_user: string containing the default user name.
   * @default_domain: string containing the default domain.
310
   * @flags: a set of #GAskPasswordFlags.
Matthias Clasen's avatar
Matthias Clasen committed
311
   *
312
   * Emitted when a mount operation asks the user for a password.
Matthias Clasen's avatar
Matthias Clasen committed
313 314 315 316
   *
   * If the message contains a line break, the first line should be
   * presented as a heading. For example, it may be used as the
   * primary text in a #GtkMessageDialog.
317
   */
318
  signals[ASK_PASSWORD] =
319
    g_signal_new (I_("ask-password"),
Matthias Clasen's avatar
Matthias Clasen committed
320
		  G_TYPE_FROM_CLASS (object_class),
321 322
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GMountOperationClass, ask_password),
323
		  NULL, NULL,
324
		  NULL,
325
		  G_TYPE_NONE, 4,
326
		  G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_ASK_PASSWORD_FLAGS);
327 328 329 330 331 332
		  
  /**
   * GMountOperation::ask-question:
   * @op: a #GMountOperation asking a question.
   * @message: string containing a message to display to the user.
   * @choices: an array of strings for each possible choice.
Matthias Clasen's avatar
Matthias Clasen committed
333 334 335 336 337 338 339
   *
   * Emitted when asking the user a question and gives a list of
   * choices for the user to choose from.
   *
   * If the message contains a line break, the first line should be
   * presented as a heading. For example, it may be used as the
   * primary text in a #GtkMessageDialog.
340
   */
341
  signals[ASK_QUESTION] =
342
    g_signal_new (I_("ask-question"),
Matthias Clasen's avatar
Matthias Clasen committed
343
		  G_TYPE_FROM_CLASS (object_class),
344 345
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GMountOperationClass, ask_question),
346
		  NULL, NULL,
347
		  NULL,
348
		  G_TYPE_NONE, 2,
349
		  G_TYPE_STRING, G_TYPE_STRV);
350 351 352 353
		  
  /**
   * GMountOperation::reply:
   * @op: a #GMountOperation.
Matthias Clasen's avatar
Matthias Clasen committed
354
   * @result: a #GMountOperationResult indicating how the request was handled
Matthias Clasen's avatar
Matthias Clasen committed
355
   *
356 357
   * Emitted when the user has replied to the mount operation.
   */
358 359
  signals[REPLY] =
    g_signal_new (I_("reply"),
Matthias Clasen's avatar
Matthias Clasen committed
360
		  G_TYPE_FROM_CLASS (object_class),
361 362 363
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GMountOperationClass, reply),
		  NULL, NULL,
364
		  g_cclosure_marshal_VOID__ENUM,
365
		  G_TYPE_NONE, 1,
366
		  G_TYPE_MOUNT_OPERATION_RESULT);
Matthias Clasen's avatar
Matthias Clasen committed
367

368 369 370 371
  /**
   * GMountOperation::aborted:
   *
   * Emitted by the backend when e.g. a device becomes unavailable
Matthias Clasen's avatar
Matthias Clasen committed
372
   * while a mount operation is in progress.
373 374 375 376 377 378
   *
   * Implementations of GMountOperation should handle this signal
   * by dismissing open password dialogs.
   *
   * Since: 2.20
   */
Matthias Clasen's avatar
Matthias Clasen committed
379
  signals[ABORTED] =
380 381 382 383 384 385 386 387
    g_signal_new (I_("aborted"),
		  G_TYPE_FROM_CLASS (object_class),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GMountOperationClass, aborted),
		  NULL, NULL,
		  g_cclosure_marshal_VOID__VOID,
		  G_TYPE_NONE, 0);

388 389 390 391
  /**
   * GMountOperation::show-processes:
   * @op: a #GMountOperation.
   * @message: string containing a message to display to the user.
392 393
   * @processes: (element-type GPid): an array of #GPid for processes
   *   blocking the operation.
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
   * @choices: an array of strings for each possible choice.
   *
   * Emitted when one or more processes are blocking an operation
   * e.g. unmounting/ejecting a #GMount or stopping a #GDrive.
   *
   * Note that this signal may be emitted several times to update the
   * list of blocking processes as processes close files. The
   * application should only respond with g_mount_operation_reply() to
   * the latest signal (setting #GMountOperation:choice to the choice
   * the user made).
   *
   * If the message contains a line break, the first line should be
   * presented as a heading. For example, it may be used as the
   * primary text in a #GtkMessageDialog.
   *
   * Since: 2.22
   */
  signals[SHOW_PROCESSES] =
    g_signal_new (I_("show-processes"),
		  G_TYPE_FROM_CLASS (object_class),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GMountOperationClass, show_processes),
		  NULL, NULL,
417
		  NULL,
418 419 420
		  G_TYPE_NONE, 3,
		  G_TYPE_STRING, G_TYPE_ARRAY, G_TYPE_STRV);

421 422 423 424
  /**
   * GMountOperation::show-unmount-progress:
   * @op: a #GMountOperation:
   * @message: string containing a mesage to display to the user
425 426
   * @time_left: the estimated time left before the operation completes,
   *     in microseconds, or -1
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
   * @bytes_left: the amount of bytes to be written before the operation
   *     completes (or -1 if such amount is not known), or zero if the operation
   *     is completed
   *
   * Emitted when an unmount operation has been busy for more than some time
   * (typically 1.5 seconds).
   *
   * When unmounting or ejecting a volume, the kernel might need to flush
   * pending data in its buffers to the volume stable storage, and this operation
   * can take a considerable amount of time. This signal may be emitted several
   * times as long as the unmount operation is outstanding, and then one
   * last time when the operation is completed, with @bytes_left set to zero.
   *
   * Implementations of GMountOperation should handle this signal by
   * showing an UI notification, and then dismiss it, or show another notification
   * of completion, when @bytes_left reaches zero.
   *
   * If the message contains a line break, the first line should be
   * presented as a heading. For example, it may be used as the
   * primary text in a #GtkMessageDialog.
447 448
   *
   * Since: 2.34
449 450 451 452 453 454 455 456
   */
  signals[SHOW_UNMOUNT_PROGRESS] =
    g_signal_new (I_("show-unmount-progress"),
                  G_TYPE_FROM_CLASS (object_class),
                  G_SIGNAL_RUN_LAST,
                  G_STRUCT_OFFSET (GMountOperationClass, show_unmount_progress),
                  NULL, NULL, NULL,
                  G_TYPE_NONE, 3,
457
                  G_TYPE_STRING, G_TYPE_INT64, G_TYPE_INT64);
458

Matthias Clasen's avatar
Matthias Clasen committed
459 460 461 462 463 464 465 466 467 468 469 470
  /**
   * GMountOperation:username:
   *
   * The user name that is used for authentication when carrying out
   * the mount operation.
   */ 
  g_object_class_install_property (object_class,
                                   PROP_USERNAME,
                                   g_param_spec_string ("username",
                                                        P_("Username"),
                                                        P_("The user name"),
                                                        NULL,
471 472
                                                        G_PARAM_READWRITE|
                                                        G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
Matthias Clasen's avatar
Matthias Clasen committed
473 474 475 476 477 478 479 480 481 482 483 484 485

  /**
   * GMountOperation:password:
   *
   * The password that is used for authentication when carrying out
   * the mount operation.
   */ 
  g_object_class_install_property (object_class,
                                   PROP_PASSWORD,
                                   g_param_spec_string ("password",
                                                        P_("Password"),
                                                        P_("The password"),
                                                        NULL,
486 487
                                                        G_PARAM_READWRITE|
                                                        G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
Matthias Clasen's avatar
Matthias Clasen committed
488 489 490 491 492 493 494 495 496 497 498 499

  /**
   * GMountOperation:anonymous:
   * 
   * Whether to use an anonymous user when authenticating.
   */
  g_object_class_install_property (object_class,
                                   PROP_ANONYMOUS,
                                   g_param_spec_boolean ("anonymous",
                                                         P_("Anonymous"),
                                                         P_("Whether to use an anonymous user"),
                                                         FALSE,
500 501
                                                         G_PARAM_READWRITE|
                                                         G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
Matthias Clasen's avatar
Matthias Clasen committed
502 503 504 505 506 507 508 509 510 511 512 513

  /**
   * GMountOperation:domain:
   *
   * The domain to use for the mount operation.
   */ 
  g_object_class_install_property (object_class,
                                   PROP_DOMAIN,
                                   g_param_spec_string ("domain",
                                                        P_("Domain"),
                                                        P_("The domain of the mount operation"),
                                                        NULL,
514 515
                                                        G_PARAM_READWRITE|
                                                        G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
Matthias Clasen's avatar
Matthias Clasen committed
516 517 518 519 520 521 522 523 524 525 526 527 528

  /**
   * GMountOperation:password-save:
   *
   * Determines if and how the password information should be saved. 
   */ 
  g_object_class_install_property (object_class,
                                   PROP_PASSWORD_SAVE,
                                   g_param_spec_enum ("password-save",
                                                      P_("Password save"),
                                                      P_("How passwords should be saved"),
                                                      G_TYPE_PASSWORD_SAVE,
                                                      G_PASSWORD_SAVE_NEVER,
529 530
                                                      G_PARAM_READWRITE|
                                                      G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
Matthias Clasen's avatar
Matthias Clasen committed
531 532 533 534 535 536 537 538 539 540 541 542 543

  /**
   * GMountOperation:choice:
   *
   * The index of the user's choice when a question is asked during the 
   * mount operation. See the #GMountOperation::ask-question signal.
   */ 
  g_object_class_install_property (object_class,
                                   PROP_CHOICE,
                                   g_param_spec_int ("choice",
                                                     P_("Choice"),
                                                     P_("The users choice"),
                                                     0, G_MAXINT, 0,
544 545
                                                     G_PARAM_READWRITE|
                                                     G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
546 547 548 549 550

  /**
   * GMountOperation:is-tcrypt-hidden-volume:
   *
   * Whether the device to be unlocked is a TCRYPT hidden volume.
551
   * See [the VeraCrypt documentation](https://www.veracrypt.fr/en/Hidden%20Volume.html).
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570
   *
   * Since: 2.58
   */
  g_object_class_install_property (object_class,
                                   PROP_IS_TCRYPT_HIDDEN_VOLUME,
                                   g_param_spec_boolean ("is-tcrypt-hidden-volume",
                                                         P_("TCRYPT Hidden Volume"),
                                                         P_("Whether to unlock a TCRYPT hidden volume. See https://www.veracrypt.fr/en/Hidden%20Volume.html."),
                                                         FALSE,
                                                         G_PARAM_READWRITE|
                                                         G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));

  /**
  * GMountOperation:is-tcrypt-system-volume:
  *
  * Whether the device to be unlocked is a TCRYPT system volume.
  * In this context, a system volume is a volume with a bootloader
  * and operating system installed. This is only supported for Windows
  * operating systems. For further documentation, see
571
  * [the VeraCrypt documentation](https://www.veracrypt.fr/en/System%20Encryption.html).
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587
  *
  * Since: 2.58
  */
  g_object_class_install_property (object_class,
                                   PROP_IS_TCRYPT_SYSTEM_VOLUME,
                                   g_param_spec_boolean ("is-tcrypt-system-volume",
                                                         P_("TCRYPT System Volume"),
                                                         P_("Whether to unlock a TCRYPT system volume. Only supported for unlocking Windows system volumes. See https://www.veracrypt.fr/en/System%20Encryption.html."),
                                                         FALSE,
                                                         G_PARAM_READWRITE|
                                                         G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));

  /**
  * GMountOperation:pim:
  *
  * The VeraCrypt PIM value, when unlocking a VeraCrypt volume. See
588
  * [the VeraCrypt documentation](https://www.veracrypt.fr/en/Personal%20Iterations%20Multiplier%20(PIM).html).
589 590 591 592 593 594 595 596 597 598 599
  *
  * Since: 2.58
  */
  g_object_class_install_property (object_class,
                                   PROP_PIM,
                                   g_param_spec_uint ("pim",
                                                      P_("PIM"),
                                                      P_("The VeraCrypt PIM value"),
                                                      0, G_MAXUINT, 0,
                                                      G_PARAM_READWRITE|
                                                      G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
600 601 602 603 604
}

static void
g_mount_operation_init (GMountOperation *operation)
{
605
  operation->priv = g_mount_operation_get_instance_private (operation);
606 607 608 609 610
}

/**
 * g_mount_operation_new:
 * 
611 612 613
 * Creates a new mount operation.
 * 
 * Returns: a #GMountOperation.
614 615 616 617 618 619 620 621
 **/
GMountOperation *
g_mount_operation_new (void)
{
  return g_object_new (G_TYPE_MOUNT_OPERATION, NULL);
}

/**
622
 * g_mount_operation_get_username:
623
 * @op: a #GMountOperation.
624
 * 
625 626 627
 * Get the user name from the mount operation.
 *
 * Returns: a string containing the user name.
628 629 630 631 632 633 634 635 636 637
 **/
const char *
g_mount_operation_get_username (GMountOperation *op)
{
  g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), NULL);
  return op->priv->user;
}

/**
 * g_mount_operation_set_username:
638
 * @op: a #GMountOperation.
639
 * @username: input username.
640 641
 *
 * Sets the user name within @op to @username.
642 643 644 645 646 647 648 649
 **/
void
g_mount_operation_set_username (GMountOperation *op,
				const char      *username)
{
  g_return_if_fail (G_IS_MOUNT_OPERATION (op));
  g_free (op->priv->user);
  op->priv->user = g_strdup (username);
Matthias Clasen's avatar
Matthias Clasen committed
650
  g_object_notify (G_OBJECT (op), "username");
651 652 653 654
}

/**
 * g_mount_operation_get_password:
655 656 657 658 659
 * @op: a #GMountOperation.
 *
 * Gets a password from the mount operation. 
 *
 * Returns: a string containing the password within @op.
660 661 662 663 664 665 666 667 668 669
 **/
const char *
g_mount_operation_get_password (GMountOperation *op)
{
  g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), NULL);
  return op->priv->password;
}

/**
 * g_mount_operation_set_password:
670
 * @op: a #GMountOperation.
671 672 673 674 675 676 677 678 679 680 681 682
 * @password: password to set.
 * 
 * Sets the mount operation's password to @password.  
 *
 **/
void
g_mount_operation_set_password (GMountOperation *op,
				const char      *password)
{
  g_return_if_fail (G_IS_MOUNT_OPERATION (op));
  g_free (op->priv->password);
  op->priv->password = g_strdup (password);
Matthias Clasen's avatar
Matthias Clasen committed
683
  g_object_notify (G_OBJECT (op), "password");
684 685 686 687
}

/**
 * g_mount_operation_get_anonymous:
688 689 690 691
 * @op: a #GMountOperation.
 * 
 * Check to see whether the mount operation is being used 
 * for an anonymous user.
692 693 694 695 696 697 698 699 700 701 702 703
 * 
 * Returns: %TRUE if mount operation is anonymous. 
 **/
gboolean
g_mount_operation_get_anonymous (GMountOperation *op)
{
  g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), FALSE);
  return op->priv->anonymous;
}

/**
 * g_mount_operation_set_anonymous:
704
 * @op: a #GMountOperation.
705 706
 * @anonymous: boolean value.
 * 
707
 * Sets the mount operation to use an anonymous user if @anonymous is %TRUE.
708 709 710 711 712
 **/  
void
g_mount_operation_set_anonymous (GMountOperation *op,
				 gboolean         anonymous)
{
Matthias Clasen's avatar
Matthias Clasen committed
713
  GMountOperationPrivate *priv;
714
  g_return_if_fail (G_IS_MOUNT_OPERATION (op));
Matthias Clasen's avatar
Matthias Clasen committed
715 716 717 718 719 720 721
  priv = op->priv;

  if (priv->anonymous != anonymous)
    {
      priv->anonymous = anonymous;
      g_object_notify (G_OBJECT (op), "anonymous");
    }
722 723 724 725
}

/**
 * g_mount_operation_get_domain:
726 727 728
 * @op: a #GMountOperation.
 * 
 * Gets the domain of the mount operation.
729
 * 
730
 * Returns: a string set to the domain. 
731 732 733 734 735 736 737 738 739 740
 **/
const char *
g_mount_operation_get_domain (GMountOperation *op)
{
  g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), NULL);
  return op->priv->domain;
}

/**
 * g_mount_operation_set_domain:
741
 * @op: a #GMountOperation.
742 743 744 745 746 747 748 749 750 751 752
 * @domain: the domain to set.
 * 
 * Sets the mount operation's domain. 
 **/  
void
g_mount_operation_set_domain (GMountOperation *op,
			      const char      *domain)
{
  g_return_if_fail (G_IS_MOUNT_OPERATION (op));
  g_free (op->priv->domain);
  op->priv->domain = g_strdup (domain);
Matthias Clasen's avatar
Matthias Clasen committed
753
  g_object_notify (G_OBJECT (op), "domain");
754 755 756 757
}

/**
 * g_mount_operation_get_password_save:
758 759 760
 * @op: a #GMountOperation.
 * 
 * Gets the state of saving passwords for the mount operation.
761
 *
762
 * Returns: a #GPasswordSave flag. 
763 764 765 766 767 768 769 770 771 772
 **/  

GPasswordSave
g_mount_operation_get_password_save (GMountOperation *op)
{
  g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), G_PASSWORD_SAVE_NEVER);
  return op->priv->password_save;
}

/**
773 774 775 776 777
 * g_mount_operation_set_password_save:
 * @op: a #GMountOperation.
 * @save: a set of #GPasswordSave flags.
 * 
 * Sets the state of saving passwords for the mount operation.
778 779 780 781 782 783
 * 
 **/   
void
g_mount_operation_set_password_save (GMountOperation *op,
				     GPasswordSave    save)
{
Matthias Clasen's avatar
Matthias Clasen committed
784
  GMountOperationPrivate *priv;
785
  g_return_if_fail (G_IS_MOUNT_OPERATION (op));
Matthias Clasen's avatar
Matthias Clasen committed
786 787 788 789 790 791 792
  priv = op->priv;
 
  if (priv->password_save != save)
    {
      priv->password_save = save;
      g_object_notify (G_OBJECT (op), "password-save");
    }
793 794 795 796
}

/**
 * g_mount_operation_get_choice:
797
 * @op: a #GMountOperation.
798
 * 
799 800 801
 * Gets a choice from the mount operation.
 *
 * Returns: an integer containing an index of the user's choice from 
802
 * the choice's list, or `0`.
803 804 805 806 807 808 809 810 811 812
 **/
int
g_mount_operation_get_choice (GMountOperation *op)
{
  g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), 0);
  return op->priv->choice;
}

/**
 * g_mount_operation_set_choice:
813 814 815 816
 * @op: a #GMountOperation.
 * @choice: an integer.
 *
 * Sets a default choice for the mount operation.
817 818 819
 **/
void
g_mount_operation_set_choice (GMountOperation *op,
820
			      int              choice)
821
{
Matthias Clasen's avatar
Matthias Clasen committed
822
  GMountOperationPrivate *priv;
823
  g_return_if_fail (G_IS_MOUNT_OPERATION (op));
Matthias Clasen's avatar
Matthias Clasen committed
824 825 826 827 828 829
  priv = op->priv;
  if (priv->choice != choice)
    {
      priv->choice = choice;
      g_object_notify (G_OBJECT (op), "choice");
    }
830 831
}

832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955
/**
 * g_mount_operation_get_is_tcrypt_hidden_volume:
 * @op: a #GMountOperation.
 *
 * Check to see whether the mount operation is being used
 * for a TCRYPT hidden volume.
 *
 * Returns: %TRUE if mount operation is for hidden volume.
 *
 * Since: 2.58
 **/
gboolean
g_mount_operation_get_is_tcrypt_hidden_volume (GMountOperation *op)
{
  g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), FALSE);
  return op->priv->hidden_volume;
}

/**
 * g_mount_operation_set_is_tcrypt_hidden_volume:
 * @op: a #GMountOperation.
 * @hidden_volume: boolean value.
 *
 * Sets the mount operation to use a hidden volume if @hidden_volume is %TRUE.
 *
 * Since: 2.58
 **/
void
g_mount_operation_set_is_tcrypt_hidden_volume (GMountOperation *op,
                                               gboolean hidden_volume)
{
  GMountOperationPrivate *priv;
  g_return_if_fail (G_IS_MOUNT_OPERATION (op));
  priv = op->priv;

  if (priv->hidden_volume != hidden_volume)
    {
      priv->hidden_volume = hidden_volume;
      g_object_notify (G_OBJECT (op), "is-tcrypt-hidden-volume");
    }
}

/**
 * g_mount_operation_get_is_tcrypt_system_volume:
 * @op: a #GMountOperation.
 *
 * Check to see whether the mount operation is being used
 * for a TCRYPT system volume.
 *
 * Returns: %TRUE if mount operation is for system volume.
 *
 * Since: 2.58
 **/
gboolean
g_mount_operation_get_is_tcrypt_system_volume (GMountOperation *op)
{
  g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), FALSE);
  return op->priv->system_volume;
}

/**
 * g_mount_operation_set_is_tcrypt_system_volume:
 * @op: a #GMountOperation.
 * @system_volume: boolean value.
 *
 * Sets the mount operation to use a system volume if @system_volume is %TRUE.
 *
 * Since: 2.58
 **/
void
g_mount_operation_set_is_tcrypt_system_volume (GMountOperation *op,
                                               gboolean system_volume)
{
  GMountOperationPrivate *priv;
  g_return_if_fail (G_IS_MOUNT_OPERATION (op));
  priv = op->priv;

  if (priv->system_volume != system_volume)
    {
      priv->system_volume = system_volume;
      g_object_notify (G_OBJECT (op), "is-tcrypt-system-volume");
    }
}

/**
 * g_mount_operation_get_pim:
 * @op: a #GMountOperation.
 *
 * Gets a PIM from the mount operation.
 *
 * Returns: The VeraCrypt PIM within @op.
 *
 * Since: 2.58
 **/
guint
g_mount_operation_get_pim (GMountOperation *op)
{
  g_return_val_if_fail (G_IS_MOUNT_OPERATION (op), 0);
  return op->priv->pim;
}

/**
 * g_mount_operation_set_pim:
 * @op: a #GMountOperation.
 * @pim: an unsigned integer.
 *
 * Sets the mount operation's PIM to @pim.
 *
 * Since: 2.58
 **/
void
g_mount_operation_set_pim (GMountOperation *op,
                           guint pim)
{
  GMountOperationPrivate *priv;
  g_return_if_fail (G_IS_MOUNT_OPERATION (op));
  priv = op->priv;
  if (priv->pim != pim)
    {
      priv->pim = pim;
      g_object_notify (G_OBJECT (op), "pim");
    }
}

956 957
/**
 * g_mount_operation_reply:
Matthias Clasen's avatar
Matthias Clasen committed
958 959
 * @op: a #GMountOperation
 * @result: a #GMountOperationResult
960
 * 
961
 * Emits the #GMountOperation::reply signal.
962 963 964
 **/
void
g_mount_operation_reply (GMountOperation *op,
965
			 GMountOperationResult result)
966 967
{
  g_return_if_fail (G_IS_MOUNT_OPERATION (op));
968
  g_signal_emit (op, signals[REPLY], 0, result);
969
}