static void
volume_mount_cb (GObject      *source_object,
		 GAsyncResult *res,
		 gpointer      user_data)
{
	PanelVolumeMountData *mount_data = user_data;
	GError *error;
	char   *primary;
	char   *name;

	error = NULL;
	if (!g_volume_mount_finish (G_VOLUME (source_object), res, &error)) {
		if (error->code != G_IO_ERROR_FAILED_HANDLED) {
			name = g_volume_get_name (G_VOLUME (source_object));
			primary = g_strdup_printf (_("Unable to mount %s"),
						   name);
			g_free (name);

			panel_error_dialog (NULL, mount_data->screen,
					    "cannot_mount_volume", TRUE,
					    primary, error->message);
			g_free (primary);
		}
		g_error_free (error);
	}
	
	//FIXME: should we activate the root of the new mount?

	g_object_unref (mount_data->mount_op);
	g_slice_free (PanelVolumeMountData, mount_data);
}
Пример #2
0
static void
eject_cb (GObject *object, GAsyncResult *result, gpointer nothing)
{
	GError *error = NULL;

	if (G_IS_VOLUME (object)) {
		GVolume *volume = G_VOLUME (object);

		rb_debug ("finishing ejection of volume");
		g_volume_eject_with_operation_finish (volume, result, &error);
	} else if (G_IS_MOUNT (object)) {
		GMount *mount = G_MOUNT (object);

		rb_debug ("finishing ejection of mount");
		g_mount_eject_with_operation_finish (mount, result, &error);
	}

	if (error != NULL) {
		if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_FAILED_HANDLED)) {
			rb_error_dialog (NULL, _("Unable to eject"), "%s", error->message);
		} else {
			rb_debug ("eject failure has already been handled");
		}
		g_error_free (error);
	}
}
Пример #3
0
static void
rb_removable_media_manager_eject_cb (GObject *object,
				     GAsyncResult *result,
				     RBRemovableMediaManager *mgr)
{
	GError *error = NULL;

	if (G_IS_VOLUME (object)) {
		GVolume *volume = G_VOLUME (object);

		rb_debug ("finishing ejection of volume");
		g_volume_eject_finish (volume, result, &error);
		if (error == NULL) {
			rb_removable_media_manager_remove_volume (mgr, volume);
		}
	} else if (G_IS_MOUNT (object)) {
		GMount *mount = G_MOUNT (object);

		rb_debug ("finishing ejection of mount");
		g_mount_eject_finish (mount, result, &error);
		if (error == NULL) {
			rb_removable_media_manager_remove_mount (mgr, mount);
		}
	}

	if (error != NULL) {
		if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_FAILED_HANDLED)) {
			rb_error_dialog (NULL, _("Unable to eject"), "%s", error->message);
		} else {
			rb_debug ("eject failure has already been handled");
		}
		g_error_free (error);
	}
	g_object_unref (mgr);
}
Пример #4
0
static gboolean fm_volume_manager_delay_init(gpointer user_data)
{
    GList* vols, *l;
    vol_mon = g_volume_monitor_get();
    if(G_UNLIKELY(!vol_mon))
        goto _end;

    g_signal_connect(vol_mon, "volume-added", G_CALLBACK(on_vol_added), NULL);

#ifdef G_ENABLE_DEBUG
    g_signal_connect(vol_mon, "volume-removed", G_CALLBACK(on_vol_removed), NULL);
    g_signal_connect(vol_mon, "volume-changed", G_CALLBACK(on_vol_changed), NULL);
#endif

    if(app_config->mount_on_startup)
    {
        /* try to automount all volumes */
        vols = g_volume_monitor_get_volumes(vol_mon);
        for(l=vols;l;l=l->next)
        {
            GVolume* vol = G_VOLUME(l->data);
            if(g_volume_should_automount(vol))
                automount_volume(vol, TRUE);
            g_object_unref(vol);
        }
        g_list_free(vols);
    }
_end:
    on_idle_handler = 0;
    return FALSE;
}
Пример #5
0
static void
volume_mount_cb (GObject      *source_object,
		 GAsyncResult *res,
		 gpointer      user_data)
{
	PanelVolumeMountData *mount_data = user_data;
	GError *error;

	error = NULL;
	if (!g_volume_mount_finish (G_VOLUME (source_object), res, &error)) {
		char *primary;
		char *name;

		if (error->code != G_IO_ERROR_FAILED_HANDLED) {
			name = g_volume_get_name (G_VOLUME (source_object));
			primary = g_strdup_printf (_("Unable to mount %s"),
						   name);
			g_free (name);

			panel_error_dialog (NULL, mount_data->screen,
					    "cannot_mount_volume", TRUE,
					    primary, error->message);
			g_free (primary);
		}
		g_error_free (error);
	} else {
		GMount *mount;
		GFile  *root;
		char   *rooturi;

		mount = g_volume_get_mount (G_VOLUME (source_object));
		root = g_mount_get_root (mount);
		rooturi = g_file_get_uri (root);
		activate_uri_on_screen (rooturi, mount_data->screen);
		g_object_unref (mount);
		g_object_unref (root);
		g_free (rooturi);
	}

	g_object_unref (mount_data->mount_op);
	g_slice_free (PanelVolumeMountData, mount_data);
}
Пример #6
0
GMount *get_mount_for_uuid(GVolumeMonitor *mon, const char *uuid)
{
    GUDisksVolumeMonitor* umon = G_UDISKS_VOLUME_MONITOR(mon);
    GList* l;
    for(l = umon->volumes; l; l=l->next)
    {
        GUDisksVolume* vol = G_UDISKS_VOLUME(l->data);
        if(g_strcmp0(vol->dev->uuid, uuid) == 0)
            return g_volume_get_mount(G_VOLUME(vol));
    }
    return NULL;
}
Пример #7
0
static void
remount_done_cb (GObject *object, GAsyncResult *result, gpointer no)
{
	gboolean ok;
	GError *error = NULL;

	ok = g_volume_mount_finish (G_VOLUME (object), result, &error);
	if (ok) {
		rb_debug ("volume remounted successfully");
	} else {
		g_warning ("Unable to remount MTP device: %s", error->message);
		g_error_free (error);
	}
	g_object_unref (object);
}
Пример #8
0
static void on_mount_action_finished(GObject* src, GAsyncResult *res, gpointer user_data)
{
    struct MountData* data = user_data;

    switch(data->action)
    {
    case MOUNT_VOLUME:
        data->ret = g_volume_mount_finish(G_VOLUME(src), res, &data->err);
        break;
    case MOUNT_GFILE:
        data->ret = g_file_mount_enclosing_volume_finish(G_FILE(src), res, &data->err);
        break;
    case UMOUNT_MOUNT:
        data->ret = g_mount_unmount_with_operation_finish(G_MOUNT(src), res, &data->err);
        break;
    case EJECT_MOUNT:
        data->ret = g_mount_eject_with_operation_finish(G_MOUNT(src), res, &data->err);
        break;
    case EJECT_VOLUME:
        data->ret = g_volume_eject_with_operation_finish(G_VOLUME(src), res, &data->err);
        break;
    }
    g_main_loop_quit(data->loop);
}
Пример #9
0
static void g_udisks_drive_eject_with_operation (GDrive* base, GMountUnmountFlags flags, GMountOperation* mount_operation, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer user_data)
{
    GUDisksDrive* drv = G_UDISKS_DRIVE(base);
    GList* vols = g_udisks_drive_get_volumes(base);
    GList* mounts = NULL;
    EjectData* data;

    /* umount all volumes/mounts first */
    if(vols)
    {
        GList* l;
        for(l = vols; l; l=l->next)
        {
            GVolume* vol = G_VOLUME(l->data);
            GMount* mnt = g_volume_get_mount(vol);
            if(mnt)
                mounts = g_list_prepend(mounts, mnt);
            g_object_unref(vol);
        }
        g_list_free(vols);
    }

    data = g_slice_new0(EjectData);
    data->drv = g_object_ref(drv);
    data->callback = callback;
    data->cancellable = cancellable ? g_object_ref(cancellable) : NULL;
    data->flags = flags;
    data->op = mount_operation ? g_object_ref(mount_operation) : NULL;
    data->user_data = user_data;

    if(cancellable)
        g_signal_connect(cancellable, "cancelled", G_CALLBACK(on_eject_cancelled), data);

    if(mounts) /* unmount all GMounts first, and do eject in ready callback */
    {
        /* NOTE: is this really needed?
         * I read the source code of UDisks and found it calling "eject"
         * command internally. According to manpage of "eject", it unmounts
         * partitions before ejecting the device. So I don't think that we
         * need to unmount ourselves. However, without this, we won't have
         * correct "mount-pre-unmount" signals. So, let's do it. */
        data->mounts = mounts;
        unmount_before_eject(data);
    }
    else /* no volume is mounted. it's safe to do eject directly. */
        do_eject(data);
}
Пример #10
0
static void
mount_with_device_file_cb (GObject *object,
                           GAsyncResult *res,
                           gpointer user_data)
{
  GVolume *volume;
  gboolean succeeded;
  GError *error = NULL;

  volume = G_VOLUME (object);

  succeeded = g_volume_mount_finish (volume, res, &error);

  if (!succeeded)
    {
      g_printerr (_("Error mounting %s: %s\n"),
                  g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE),
                  error->message);
      g_error_free (error);
      success = FALSE;
    }
  else
    {
      GMount *mount;
      GFile *root;
      char *mount_path;

      mount = g_volume_get_mount (volume);
      root = g_mount_get_root (mount);
      mount_path = g_file_get_path (root);

      g_print (_("Mounted %s at %s\n"),
               g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE),
               mount_path);

      g_object_unref (mount);
      g_object_unref (root);
      g_free (mount_path);
    }

  outstanding_mounts--;

  if (outstanding_mounts == 0)
    g_main_loop_quit (main_loop);
}
static void
xfdesktop_volume_icon_eject_finish(GObject *object,
                                   GAsyncResult *result,
                                   gpointer user_data)
{
    XfdesktopVolumeIcon *icon = XFDESKTOP_VOLUME_ICON(user_data);
    GtkWidget *icon_view = xfdesktop_icon_peek_icon_view(XFDESKTOP_ICON(icon));
    GtkWidget *toplevel = icon_view ? gtk_widget_get_toplevel(icon_view) : NULL;
    GVolume *volume = G_VOLUME(object);
    GError *error = NULL;
    gboolean eject_successful;
      
    g_return_if_fail(G_IS_VOLUME(object));
    g_return_if_fail(G_IS_ASYNC_RESULT(result));
    g_return_if_fail(XFDESKTOP_IS_VOLUME_ICON(icon));

    eject_successful = g_volume_eject_with_operation_finish(volume, result, &error);

    if(!eject_successful) {
        /* ignore GIO errors handled internally */
        if(error->domain != G_IO_ERROR || error->code != G_IO_ERROR_FAILED_HANDLED) {
            gchar *volume_name = g_volume_get_name(volume);
            gchar *primary = g_markup_printf_escaped(_("Failed to eject \"%s\""), 
                                                     volume_name);

            /* display an error dialog to inform the user */
            xfce_message_dialog(toplevel ? GTK_WINDOW(toplevel) : NULL,
                                _("Eject Failed"), GTK_STOCK_DIALOG_ERROR, 
                                primary, error->message,
                                GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL);

            g_free(primary);
            g_free(volume_name);
        }

        g_error_free(error);
    }

#ifdef HAVE_LIBNOTIFY
    xfdesktop_notify_eject_finish(volume, eject_successful);
#endif

    g_object_unref(icon);
}
Пример #12
0
static void
mount_with_device_file_cb (GObject *object,
                           GAsyncResult *res,
                           gpointer user_data)
{
  GVolume *volume;
  gboolean succeeded;
  GError *error = NULL;
  gchar *device_path = (gchar *)user_data;

  volume = G_VOLUME (object);

  succeeded = g_volume_mount_finish (volume, res, &error);

  if (!succeeded)
    {
      print_error ("%s: %s", device_path, error->message);
      g_error_free (error);
      success = FALSE;
    }
  else
    {
      GMount *mount;
      GFile *root;
      char *mount_path;

      mount = g_volume_get_mount (volume);
      root = g_mount_get_root (mount);
      mount_path = g_file_get_path (root);

      g_print (_("Mounted %s at %s\n"), device_path, mount_path);

      g_object_unref (mount);
      g_object_unref (root);
      g_free (mount_path);
    }

  g_free (device_path);

  outstanding_mounts--;

  if (outstanding_mounts == 0)
    g_main_loop_quit (main_loop);
}
Пример #13
0
static void
mount_with_device_file (const char *device_file)
{
  GVolumeMonitor *volume_monitor;
  GList *volumes;
  GList *l;

  volume_monitor = g_volume_monitor_get();

  volumes = g_volume_monitor_get_volumes (volume_monitor);
  for (l = volumes; l != NULL; l = l->next)
    {
      GVolume *volume = G_VOLUME (l->data);
      gchar *id;

      id = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
      if (g_strcmp0 (id, device_file) == 0)
        {
          GMountOperation *op;

          op = new_mount_op ();

          g_volume_mount (volume,
                          G_MOUNT_MOUNT_NONE,
                          op,
                          NULL,
                          mount_with_device_file_cb,
                          id);

          outstanding_mounts++;
        }
      else
        g_free (id);
    }
  g_list_free_full (volumes, g_object_unref);

  if (outstanding_mounts == 0)
    {
      print_error ("%s: %s", device_file, _("No volume for device file"));
      success = FALSE;
    }

  g_object_unref (volume_monitor);
}
Пример #14
0
static void
mount_with_device_file (const char *device_file)
{
  GVolumeMonitor *volume_monitor;
  GList *volumes;
  GList *l;

  volume_monitor = g_volume_monitor_get();

  volumes = g_volume_monitor_get_volumes (volume_monitor);
  for (l = volumes; l != NULL; l = l->next)
    {
      GVolume *volume = G_VOLUME (l->data);

      if (g_strcmp0 (g_volume_get_identifier (volume,
                                              G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE), device_file) == 0)
        {
          GMountOperation *op;

          op = new_mount_op ();

          g_volume_mount (volume,
                          G_MOUNT_MOUNT_NONE,
                          op,
                          NULL,
                          mount_with_device_file_cb,
                          op);

          outstanding_mounts++;
        }
    }
  g_list_foreach (volumes, (GFunc) g_object_unref, NULL);
  g_list_free (volumes);

  if (outstanding_mounts == 0)
    {
      g_print (_("No volume for device file %s\n"), device_file);
      return;
    }

  g_object_unref (volume_monitor);
}
Пример #15
0
static void
brasero_gio_operation_eject_finish (GObject *source,
				    GAsyncResult *result,
				    gpointer user_data)
{
	BraseroGioOperation *operation = user_data;

	if (G_IS_DRIVE (source))
		operation->result = g_drive_eject_with_operation_finish (G_DRIVE (source),
							  result,
							  &operation->error);
	else
		operation->result = g_volume_eject_with_operation_finish (G_VOLUME (source),
							   result,
							   &operation->error);

	if (operation->error)
		brasero_gio_operation_end (operation);
	else if (!operation->result)
		brasero_gio_operation_end (operation);
}
Пример #16
0
static void
brasero_gio_operation_mount_finish (GObject *source,
				    GAsyncResult *result,
				    gpointer user_data)
{
	BraseroGioOperation *op = user_data;

	op->result = g_volume_mount_finish (G_VOLUME (source),
					    result,
					    &op->error);

	if (op->error) {
		if (op->error->code == G_IO_ERROR_ALREADY_MOUNTED) {
			g_error_free (op->error);
			op->error = NULL;
			op->result = TRUE;
		}
	}

	brasero_gio_operation_end (op);
}
GVolume *pup_mount_get_volume(GMount *mount)
{
	PupMount *self = PUP_MOUNT(mount);

	return G_VOLUME(g_object_ref(self->holder));
}
Пример #18
0
int
main (int argc, char *argv[])
{
        int ret;
        GError *error;
        MduPool *pool;
        MduDevice *device;
        MduDevice *device_to_unmount;
        MduDevice *device_to_mount;
        MduPresentable *volume;
        gchar *volume_name;
        gchar *confirmation_secondary;
        GtkWidget *dialog;
        gint response;
        gchar *fs_type;
        gchar *fs_label;
        gboolean encrypt;
        gchar *passphrase;
        gboolean save_passphrase_in_keyring;
        gboolean save_passphrase_in_keyring_session;
        GMainLoop *loop;
        GVolumeMonitor *gvolume_monitor;
        GList *l;
        GList *gvolumes;
        GVolume *gvolume;
        GMount *gmount;
        gboolean take_ownership;
        FormatData *format_data;
        MduPresentable *toplevel;
        gchar *drive_name;
        gchar *format_desc;
        gchar *formatting_desc;
        gchar *size_str;
        gint grace_timeout_id;

        ret = 1;
        pool = NULL;
        device = NULL;
        device_to_unmount = NULL;
        device_to_mount = NULL;
        volume = NULL;
        volume_name = NULL;
        confirmation_secondary = NULL;
        dialog = NULL;
        fs_type = NULL;
        fs_label = NULL;
        passphrase = NULL;
        loop = NULL;
        volume = NULL;
        gmount = NULL;
        gvolume_monitor = NULL;
        gvolumes = NULL;
        gvolume = NULL;
        gmount = NULL;
        format_data = NULL;
        toplevel = NULL;
        drive_name = NULL;
        format_desc = NULL;
        formatting_desc = NULL;
        size_str = NULL;

#if !GLIB_CHECK_VERSION (2, 32, 0)
        g_thread_init (NULL);
#endif

        /* Initialize gettext support */
        bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
        textdomain (GETTEXT_PACKAGE);

        /*  Initialize gtk  */
        error = NULL;
        if (! gtk_init_with_args (&argc, &argv, NULL, entries, GETTEXT_PACKAGE, &error)) {
                g_printerr ("Could not parse arguments: %s\n", error->message);
                g_error_free (error);
                goto out;
        }

        loop = g_main_loop_new (NULL, FALSE);

        g_set_prgname ("mdu-format-tool");
        g_set_application_name (_("Mate Disk Utility formatting tool"));

        if (device_file == NULL) {
                g_printerr ("Incorrect usage. Try --help.\n");
                goto out;
        }

        pool = mdu_pool_new ();
        if (pool == NULL) {
                g_warning ("Unable to get device pool");
                goto out;
        }

        device = mdu_pool_get_by_device_file (pool, device_file);
        if (device == NULL) {
                g_printerr ("No device for %s\n", device_file);
                goto out;
        }

        /* if the user specified a luks device, find the slave backing device */
        if (mdu_device_is_luks_cleartext (device)) {
                const gchar *slave;
                slave = mdu_device_luks_cleartext_get_slave (device);
                g_object_ref (device);
                device = mdu_pool_get_by_object_path (pool, slave);
                /* don't support LUKS in LUKS... */
                g_assert (!mdu_device_is_luks_cleartext (device));
        }

        volume = mdu_pool_get_volume_by_device (pool, device);
        if (volume == NULL) {
                g_printerr ("%s is not a volume\n", device_file);
                goto out;
        }
        volume_name = mdu_presentable_get_name (volume);

        toplevel = mdu_presentable_get_toplevel (MDU_PRESENTABLE (volume));
        if (toplevel != NULL && MDU_IS_DRIVE (toplevel)) {
                drive_name = mdu_presentable_get_name (toplevel);
        }
        size_str = mdu_util_get_size_for_display (mdu_device_get_size (device),
                                                  FALSE,
                                                  FALSE);

        if (drive_name != NULL) {
                if (mdu_device_is_partition (device)) {
                        /* Translators: First argument is the partition number, second argument is the drive name,
                         * third argument is the size (e.g. 10 GB)
                         */
                        format_desc = g_strdup_printf (_("Format partition %d of %s (%s)"),
                                                       mdu_device_partition_get_number (device),
                                                       drive_name,
                                                       size_str);
                        /* Translators: First argument is the partition number, second argument is the drive name,
                         * third argument is the size (e.g. 10 GB)
                         */
                        formatting_desc = g_strdup_printf (_("Formatting partition %d of %s (%s)"),
                                                           mdu_device_partition_get_number (device),
                                                           drive_name,
                                                           size_str);
                } else {
                        /* Translators: First argument is the drive name, second argument is the size (e.g. 10 GB) */
                        format_desc = g_strdup_printf (_("Format %s (%s)"),
                                                       drive_name,
                                                       size_str);
                        /* Translators: First argument is the drive name, second argument is the size (e.g. 10 GB) */
                        formatting_desc = g_strdup_printf (_("Formatting %s (%s)"),
                                                           drive_name,
                                                           size_str);
                }
        } else {
                /* Translators: First argument is the size (e.g. 10 GB), second is the device (e.g. /dev/md0) */
                format_desc = g_strdup_printf (_("Format %s Volume (%s)"),
                                               size_str,
                                               mdu_device_get_device_file (device));
                /* Translators: First argument is the size (e.g. 10 GB), second is the device (e.g. /dev/md0) */
                formatting_desc = g_strdup_printf (_("Formatting %s Volume (%s)"),
                                                   size_str,
                                                   mdu_device_get_device_file (device));
        }

        dialog = mdu_format_dialog_new (NULL, /* no parent window */
                                        volume,
                                        MDU_FORMAT_DIALOG_FLAGS_SIMPLE |
                                        MDU_FORMAT_DIALOG_FLAGS_DISK_UTILITY_BUTTON);
        gtk_window_set_title (GTK_WINDOW (dialog), format_desc);
        gtk_window_set_icon_name (GTK_WINDOW (dialog), "caja-mdu");
        gtk_widget_show_all (dialog);

        response = gtk_dialog_run (GTK_DIALOG (dialog));

        switch (response) {
        case GTK_RESPONSE_OK:
                break;

        case GTK_RESPONSE_ACCEPT:
                gtk_widget_destroy (dialog);
                dialog = NULL;
                launch_mate_disk (device_file);
                goto out;

        default: /* explicit fallthrough */
        case GTK_RESPONSE_CANCEL:
                goto out;
        }

        fs_type = mdu_format_dialog_get_fs_type (MDU_FORMAT_DIALOG (dialog));
        fs_label = mdu_format_dialog_get_fs_label (MDU_FORMAT_DIALOG (dialog));
        encrypt = mdu_format_dialog_get_encrypt (MDU_FORMAT_DIALOG (dialog));
        gtk_widget_destroy (dialog);
        dialog = NULL;

        /* Ask for passphrase if needed */
        passphrase = NULL;
        save_passphrase_in_keyring = FALSE;
        save_passphrase_in_keyring_session = FALSE;
        if (encrypt) {
                passphrase = mdu_util_dialog_ask_for_new_secret (NULL,
                                                                 &save_passphrase_in_keyring,
                                                                 &save_passphrase_in_keyring_session);
                if (passphrase == NULL)
                        goto out;
        }

        take_ownership = (g_strcmp0 (fs_type, "vfat") != 0);

        format_data = g_new0 (FormatData, 1);
        format_data->loop = loop;
        format_data->error = NULL;

        dialog = mdu_format_progress_dialog_new (NULL,
                                                 device,
                                                 _("Preparing..."));
        gtk_window_set_title (GTK_WINDOW (dialog), formatting_desc);
        gtk_widget_show_all (dialog);
        g_signal_connect (dialog, "response", G_CALLBACK (on_progress_dialog_response), format_data);

        /* first a small 2.5 sec window to allow the user to cancel before initiating */
        grace_timeout_id = g_timeout_add (2500, on_grace_timeout, format_data);
        g_main_loop_run (loop);
        g_source_remove (grace_timeout_id);
        if (format_data->error != NULL &&
            format_data->error->domain == G_IO_ERROR &&
            format_data->error->code == G_IO_ERROR_CANCELLED) {
                /* cancelled already, we are done */
                goto out;
        }

        /* then unmount the mount if needed; we use GIO for this to handle tearing
         * down LUKS; first determine the device to unmount
         */
        if (mdu_device_is_luks (device)) {
                const gchar *holder;
                holder = mdu_device_luks_get_holder (device);
                device_to_unmount = mdu_pool_get_by_object_path (pool, holder);
        } else {
                device_to_unmount = g_object_ref (device);
        }
        g_assert (device_to_unmount != NULL);
        gvolume_monitor = g_volume_monitor_get ();
        gvolumes = g_volume_monitor_get_volumes (gvolume_monitor);
        for (l = gvolumes; l != NULL; l = l->next) {
                GVolume *v = G_VOLUME (l->data);
                if (g_strcmp0 (g_volume_get_identifier (v, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE),
                               mdu_device_get_device_file (device_to_unmount)) == 0) {
                        gvolume = g_object_ref (v);
                        break;
                }
        }
        if (gvolume != NULL) {
                gmount = g_volume_get_mount (gvolume);
                if (gmount != NULL) {
                        GMountOperation *mount_op;

                        mdu_format_progress_dialog_set_text (MDU_FORMAT_PROGRESS_DIALOG (dialog),
                                                             _("Unmounting..."));

                        mount_op = gtk_mount_operation_new (GTK_WINDOW (dialog));
                        g_mount_unmount_with_operation (gmount,
                                                        G_MOUNT_UNMOUNT_NONE,
                                                        mount_op,
                                                        NULL,
                                                        unmount_cb,
                                                        format_data);
                        g_object_unref (mount_op);
                        g_main_loop_run (format_data->loop);

                        if (format_data->error != NULL) {

                                if (!(format_data->error->domain == G_IO_ERROR &&
                                      format_data->error->code == G_IO_ERROR_FAILED_HANDLED)) {
                                        gchar *primary;

                                        primary = g_strdup_printf (_("Unable to format '%s'"), volume_name);
                                        show_error_dialog (NULL,
                                                           primary,
                                                           format_data->error->message);

                                        g_free (primary);
                                }
                                g_error_free (format_data->error);
                                goto out;
                        }
                }
        }

        /* and now, kick off the operation */
        mdu_format_progress_dialog_set_text (MDU_FORMAT_PROGRESS_DIALOG (dialog),
                                             _("Formatting..."));
        mdu_device_op_filesystem_create (device,
                                         fs_type,
                                         fs_label,
                                         passphrase,
                                         take_ownership,
                                         fs_create_cb,
                                         format_data);
 again:
        g_main_loop_run (loop);
        if (format_data->error != NULL) {
                gtk_widget_destroy (dialog);
                dialog = NULL;

                if (format_data->error->domain == G_IO_ERROR &&
                    format_data->error->code == G_IO_ERROR_CANCELLED) {
                        mdu_format_progress_dialog_set_text (MDU_FORMAT_PROGRESS_DIALOG (dialog),
                                                             _("Cancelling..."));

                        /* cancel the job; no callback since op_filesystem_create will return an error */
                        mdu_device_op_cancel_job (device,
                                                  NULL,
                                                  NULL);
                        goto again;

                } else {
                        show_error_dialog (NULL,
                                           _("Error formatting volume"),
                                           format_data->error->message);
                        g_error_free (format_data->error);
                }
                goto out;
        }

        /* ugh, DeviceKit-disks bug - spin around in the mainloop for some time to ensure we
         * have gotten all changes
         */
        mdu_format_progress_dialog_set_text (MDU_FORMAT_PROGRESS_DIALOG (dialog),
                                             _("Mounting volume..."));
        g_timeout_add (1500, on_hack_timeout, loop);
        g_main_loop_run (loop);

        /* OK, peachy, now mount the volume and open a window */
        if (passphrase != NULL) {
                const gchar *cleartext_objpath;

                g_assert (mdu_device_is_luks (device));
                cleartext_objpath = mdu_device_luks_get_holder (device);
                device_to_mount = mdu_pool_get_by_object_path (pool, cleartext_objpath);
        } else {
                device_to_mount = g_object_ref (device);
        }

        mdu_device_op_filesystem_mount (device_to_mount,
                                        NULL,
                                        fs_mount_cb,
                                        format_data);
        g_main_loop_run (loop);
        gtk_widget_destroy (dialog);
        dialog = NULL;
        if (format_data->error != NULL) {
                show_error_dialog (NULL,
                                   _("Error mounting device"),
                                   format_data->error->message);
                g_error_free (format_data->error);
                goto out;
        }

        /* open file manager */
        launch_file_manager (format_data->mount_point);

        g_free (format_data->mount_point);

        /* save passphrase in keyring if requested */
        if (passphrase != NULL && (save_passphrase_in_keyring || save_passphrase_in_keyring_session)) {
                if (!mdu_util_save_secret (device,
                                           passphrase,
                                           save_passphrase_in_keyring_session)) {
                        show_error_dialog (NULL,
                                           _("Error storing passphrase in keyring"),
                                           "");
                        goto out;
                }
        }

        ret = 0;

 out:
        if (toplevel != NULL)
                g_object_unref (toplevel);
        g_free (drive_name);
        g_free (size_str);
        g_free (format_desc);
        g_free (formatting_desc);
        if (gmount != NULL)
                g_object_unref (gmount);
        if (gvolume != NULL)
                g_object_unref (gvolume);
        g_list_foreach (gvolumes, (GFunc) g_object_unref, NULL);
        if (gvolume_monitor != NULL)
                g_object_unref (gvolume_monitor);
        g_free (confirmation_secondary);
        g_free (volume_name);
        g_free (passphrase);
        g_free (fs_type);
        g_free (fs_label);
        g_free (device_file);
        if (loop != NULL)
                g_main_loop_unref (loop);
        if (dialog != NULL)
                gtk_widget_destroy (dialog);
        if (volume != NULL)
                g_object_unref (volume);
        if (device != NULL)
                g_object_unref (device);
        if (device_to_unmount != NULL)
                g_object_unref (device_to_unmount);
        if (device_to_mount != NULL)
                g_object_unref (device_to_mount);
        if (pool != NULL)
                g_object_unref (pool);
        if (format_data != NULL)
                g_free (format_data);
        return ret;
}
Пример #19
0
static void init_model()
{
    if(G_UNLIKELY(!model))
    {
        GtkTreeIter it;
        PlaceItem* item;
        GList *vols, *l;
        GIcon* gicon;
        FmIcon* icon;
        GFile* gf;
        GdkPixbuf* pix;

        theme_change_handler = g_signal_connect(gtk_icon_theme_get_default(), "changed",
                                                G_CALLBACK(update_icons), NULL);

        use_trash_change_handler = g_signal_connect(fm_config, "changed::use_trash",
                                                 G_CALLBACK(on_use_trash_changed), NULL);

        pane_icon_size_change_handler = g_signal_connect(fm_config, "changed::pane_icon_size",
                                                 G_CALLBACK(on_pane_icon_size_changed), NULL);

        model = gtk_list_store_new(N_COLS, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_POINTER);
        g_object_weak_ref(G_OBJECT(model), on_model_destroy, NULL);

        item = g_slice_new0(PlaceItem);
        item->type = PLACE_PATH;
        item->path = fm_path_ref(fm_path_get_home());
        item->icon = fm_icon_from_name("user-home");
        gtk_list_store_append(model, &it);
        pix = fm_icon_get_pixbuf(item->icon, fm_config->pane_icon_size);
        gtk_list_store_set(model, &it, COL_ICON, pix, COL_LABEL, item->path->name, COL_INFO, item, -1);
        g_object_unref(pix);

        /* Only show desktop in side pane when the user has a desktop dir. */
        if(g_file_test(g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP), G_FILE_TEST_IS_DIR))
        {
            item = g_slice_new0(PlaceItem);
            item->type = PLACE_PATH;
            item->path = fm_path_ref(fm_path_get_desktop());
            item->icon = fm_icon_from_name("user-desktop");
            gtk_list_store_append(model, &it);
            pix = fm_icon_get_pixbuf(item->icon, fm_config->pane_icon_size);
            gtk_list_store_set(model, &it, COL_ICON, pix, COL_LABEL, _("Desktop"), COL_INFO, item, -1);
            g_object_unref(pix);
        }

        if(fm_config->use_trash)
            create_trash();

        item = g_slice_new0(PlaceItem);
        item->type = PLACE_PATH;
        item->path = fm_path_ref(fm_path_get_apps_menu());
        item->icon = fm_icon_from_name("system-software-install");
        gtk_list_store_append(model, &it);
        pix = fm_icon_get_pixbuf(item->icon, fm_config->pane_icon_size);
        gtk_list_store_set(model, &it, COL_ICON, pix, COL_LABEL, _("Applications"), COL_INFO, item, -1);
        g_object_unref(pix);

        /* volumes */
        vol_mon = g_volume_monitor_get();
        g_signal_connect(vol_mon, "volume-added", G_CALLBACK(on_vol_added), NULL);
        g_signal_connect(vol_mon, "volume-removed", G_CALLBACK(on_vol_removed), NULL);
        g_signal_connect(vol_mon, "volume-changed", G_CALLBACK(on_vol_changed), NULL);

        /* separator */
        gtk_list_store_append(model, &sep_it);

        vols = g_volume_monitor_get_volumes(vol_mon);
        for(l=vols;l;l=l->next)
        {
            GVolume* vol = G_VOLUME(l->data);
            add_vol(vol);
            g_object_unref(vol);
        }
        g_list_free(vols);

        bookmarks = fm_bookmarks_get(); /* bookmarks */
        g_signal_connect(bookmarks, "changed", G_CALLBACK(on_bookmarks_changed), NULL);
        add_bookmarks();
    }
    else
        g_object_ref(model);
}
Пример #20
0
static void fm_places_model_init(FmPlacesModel *self)
{
    GType types[] = {GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_POINTER};
    GtkTreeIter it;
    GtkTreePath* tp;
    FmPlaceItem* item;
    GList *vols, *l;
    GIcon* gicon;
    FmIcon* icon;
    GFile* gf;
    GdkPixbuf* pix;
    FmFileInfoJob* job = fm_file_info_job_new(NULL, FM_FILE_INFO_JOB_FOLLOW_SYMLINK);
    GtkListStore* model = GTK_LIST_STORE(self);

    gtk_list_store_set_column_types(GTK_LIST_STORE(self), FM_PLACES_MODEL_N_COLS, types);

    self->theme_change_handler = g_signal_connect_swapped(gtk_icon_theme_get_default(), "changed",
                                            G_CALLBACK(update_icons), self);

    self->use_trash_change_handler = g_signal_connect(fm_config, "changed::use_trash",
                                             G_CALLBACK(on_use_trash_changed), self);

    self->pane_icon_size_change_handler = g_signal_connect(fm_config, "changed::pane_icon_size",
                                             G_CALLBACK(on_pane_icon_size_changed), self);
    icon = fm_icon_from_name("media-eject");
    pix = fm_icon_get_pixbuf(icon, fm_config->pane_icon_size);
    fm_icon_unref(icon);
    self->eject_icon = pix;

    item = g_slice_new0(FmPlaceItem);
    item->type = FM_PLACES_ITEM_PATH;
    item->fi = fm_file_info_new();
    item->fi->path = fm_path_ref(fm_path_get_home());
    item->fi->icon = fm_icon_from_name("user-home");
    gtk_list_store_append(model, &it);
    pix = fm_icon_get_pixbuf(item->fi->icon, fm_config->pane_icon_size);
    gtk_list_store_set(model, &it, FM_PLACES_MODEL_COL_ICON, pix, FM_PLACES_MODEL_COL_LABEL, item->fi->path->name, FM_PLACES_MODEL_COL_INFO, item, -1);
    g_object_unref(pix);
    fm_file_info_job_add(job, item->fi->path);

    /* Only show desktop in side pane when the user has a desktop dir. */
    if(g_file_test(g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP), G_FILE_TEST_IS_DIR))
    {
        item = g_slice_new0(FmPlaceItem);
        item->type = FM_PLACES_ITEM_PATH;
        item->fi = fm_file_info_new();
        item->fi->path = fm_path_ref(fm_path_get_desktop());
        item->fi->icon = fm_icon_from_name("user-desktop");
        gtk_list_store_append(model, &it);
        pix = fm_icon_get_pixbuf(item->fi->icon, fm_config->pane_icon_size);
        gtk_list_store_set(model, &it, FM_PLACES_MODEL_COL_ICON, pix, FM_PLACES_MODEL_COL_LABEL, _("Desktop"), FM_PLACES_MODEL_COL_INFO, item, -1);
        g_object_unref(pix);
        fm_file_info_job_add(job, item->fi->path);
    }

    if(fm_config->use_trash)
        create_trash_item(self); /* FIXME: how to handle trash can? */

    item = g_slice_new0(FmPlaceItem);
    item->type = FM_PLACES_ITEM_PATH;
    item->fi = fm_file_info_new();
    item->fi->path = fm_path_ref(fm_path_get_apps_menu());
    item->fi->icon = fm_icon_from_name("system-software-install");
    gtk_list_store_append(model, &it);
    pix = fm_icon_get_pixbuf(item->fi->icon, fm_config->pane_icon_size);
    gtk_list_store_set(model, &it, FM_PLACES_MODEL_COL_ICON, pix, FM_PLACES_MODEL_COL_LABEL, _("Applications"), FM_PLACES_MODEL_COL_INFO, item, -1);
    g_object_unref(pix);
    /* fm_file_info_job_add(job, item->fi->path); */

    /* volumes */
    self->vol_mon = g_volume_monitor_get();
    g_signal_connect(self->vol_mon, "volume-added", G_CALLBACK(on_vol_added), self);
    g_signal_connect(self->vol_mon, "volume-removed", G_CALLBACK(on_vol_removed), self);
    g_signal_connect(self->vol_mon, "volume-changed", G_CALLBACK(on_vol_changed), self);
    g_signal_connect(self->vol_mon, "mount-added", G_CALLBACK(on_mount_added), self);

    /* separator */
    gtk_list_store_append(model, &self->sep_it);

    /* add volumes to side-pane */
    vols = g_volume_monitor_get_volumes(self->vol_mon);
    for(l=vols;l;l=l->next)
    {
        GVolume* vol = G_VOLUME(l->data);
        add_vol(self, vol, job);
        g_object_unref(vol);
    }
    g_list_free(vols);

    /* get the path of separator */
    self->sep_tp = gtk_tree_model_get_path(GTK_TREE_MODEL(self), &self->sep_it);

    self->bookmarks = fm_bookmarks_get(); /* bookmarks */
    g_signal_connect(self->bookmarks, "changed", G_CALLBACK(on_bookmarks_changed), self);

    /* add bookmarks to side pane */
    add_bookmarks(self, job);

    g_signal_connect(job, "finished", G_CALLBACK(on_file_info_job_finished), self);
    self->jobs = g_slist_prepend(self->jobs, job);
    fm_job_run_async(FM_JOB(job));
}
Пример #21
0
/**
 * rb_removable_media_manager_scan:
 * @manager: the #RBRemovableMediaManager
 *
 * Initiates a new scan of all attached media.  Newly activated plugins that use
 * the create-source-volume or create-source-mount signals should call this if
 * the 'scanned' property is %TRUE.  Otherwise, the first scan will catch any
 * existing volumes or mounts that the plugin is interested in.
 */
void
rb_removable_media_manager_scan (RBRemovableMediaManager *manager)
{
	RBRemovableMediaManagerPrivate *priv = GET_PRIVATE (manager);
	GHashTableIter iter;
	GList *list, *it;
	gpointer hkey, hvalue;

	priv->scanned = TRUE;

	/* check volumes first */
	list = g_volume_monitor_get_volumes (priv->volume_monitor);

	/* - check for volumes that have disappeared */
	g_hash_table_iter_init (&iter, priv->volume_mapping);
	while (g_hash_table_iter_next (&iter, &hkey, &hvalue)) {
		GVolume *volume = G_VOLUME (hkey);

		if (g_list_index (list, volume) == -1) {
			/* volume has vanished */
			rb_removable_media_manager_remove_volume (manager, volume);
		}
	}

	/* - check for newly added volumes */
	for (it = list; it != NULL; it = g_list_next (it)) {
		GVolume *volume = G_VOLUME (it->data);
		rb_removable_media_manager_add_volume (manager, volume);
		g_object_unref (volume);
	}
	g_list_free (list);

	/* check mounts */
	list = g_volume_monitor_get_mounts (priv->volume_monitor);

	/* - check for mounts that have disappeared */
	g_hash_table_iter_init (&iter, priv->mount_mapping);
	while (g_hash_table_iter_next (&iter, &hkey, &hvalue)) {
		GMount *mount = G_MOUNT (hkey);

		if (g_list_index (list, mount) == -1) {
			rb_removable_media_manager_remove_mount (manager, mount);
		}
	}

	/* - check for newly added mounts */
	for (it = list; it != NULL; it = g_list_next (it)) {
		GMount *mount = G_MOUNT (it->data);
		rb_removable_media_manager_add_mount (manager, mount);
		g_object_unref (mount);
	}
	g_list_free (list);

	/* - check devices */
#if defined(HAVE_GUDEV)
	list = g_udev_client_query_by_subsystem (priv->gudev_client, "usb");
	for (it = list; it != NULL; it = g_list_next (it)) {
		/* pretend the device was just added */
		uevent_cb (priv->gudev_client, "add", G_UDEV_DEVICE (it->data), manager);
	}
	g_list_free (list);
#endif
}
Пример #22
0
static gboolean g_udisks_mount_eject_with_operation_finish(GMount* base, GAsyncResult* res, GError** error)
{
    GUDisksMount* mnt = G_UDISKS_MOUNT(base);
    return g_volume_eject_with_operation_finish(G_VOLUME(mnt->vol), res, error);
}
Пример #23
0
static char* g_udisks_mount_get_uuid (GMount* base)
{
    GUDisksMount* mnt = G_UDISKS_MOUNT(base);
    return mnt->vol ? g_volume_get_uuid(G_VOLUME(mnt->vol)) : NULL;
}
static void
xfdesktop_volume_icon_mount_finish(GObject *object,
                                   GAsyncResult *result,
                                   gpointer user_data)
{
    XfdesktopVolumeIcon *icon = XFDESKTOP_VOLUME_ICON(user_data);
    GtkWidget *icon_view = xfdesktop_icon_peek_icon_view(XFDESKTOP_ICON(icon));
    GtkWidget *toplevel = gtk_widget_get_toplevel(icon_view);
    GVolume *volume = G_VOLUME(object);
    GError *error = NULL;

    if(!g_volume_mount_finish(volume, result, &error)) {
        if(error->domain != G_IO_ERROR || error->code != G_IO_ERROR_FAILED_HANDLED) {
            gchar *volume_name = g_volume_get_name(volume);
            gchar *primary = g_markup_printf_escaped(_("Failed to mount \"%s\""),
                                                     volume_name);
            xfce_message_dialog(toplevel ? GTK_WINDOW(toplevel) : NULL,
                                _("Mount Failed"), GTK_STOCK_DIALOG_ERROR, 
                                primary, error->message,
                                GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL);
            g_free(primary);
            g_free(volume_name);
        }
        
        g_error_free(error);
    } else {
        GMount *mount = g_volume_get_mount(volume);
        GFile *file = NULL;
        GFileInfo *info = NULL;

        if(mount) {
            file = g_mount_get_root(mount);
            info = g_file_query_info(file,
                                     XFDESKTOP_FILE_INFO_NAMESPACE,
                                     G_FILE_QUERY_INFO_NONE,
                                     NULL, NULL);
            g_object_unref(mount);
        }

        if(file && info) {
            gboolean activated = FALSE;

            if(icon->priv->file)
                g_object_unref(icon->priv->file);
            icon->priv->file = g_object_ref(file);

            xfdesktop_file_icon_update_file_info(XFDESKTOP_FILE_ICON(icon), info);

            activated = GPOINTER_TO_UINT(g_object_get_qdata(G_OBJECT(icon), 
                                                            xfdesktop_volume_icon_activated_quark));
            if(activated) {
                XfdesktopIcon *icon_p = XFDESKTOP_ICON(icon);
                XFDESKTOP_ICON_CLASS(xfdesktop_volume_icon_parent_class)->activated(icon_p);
            }
            g_object_set_qdata(G_OBJECT(icon), xfdesktop_volume_icon_activated_quark, NULL);
        } else {
            if(icon->priv->file)
                g_object_unref(icon->priv->file);
            icon->priv->file = NULL;

            xfdesktop_file_icon_update_file_info(XFDESKTOP_FILE_ICON(icon), NULL);
        }
            
        if(file)
            g_object_unref(file);

        if(info)
            g_object_unref(info);
    }
}
Пример #25
0
static gboolean fm_do_mount(GtkWindow* parent, GObject* obj, MountAction action, gboolean interactive)
{
    gboolean ret;
    struct MountData* data = g_new0(struct MountData, 1);
    /* bug #3615234: it seems GtkMountOperations is buggy and sometimes leaves
       parent window reference intact while destroys itself so it leads to
       severe memory corruption, therefore we pass here NULL as parent window
       to gtk_mount_operation_new() to not bind it to anything as a workaround */
    GMountOperation* op = interactive ? gtk_mount_operation_new(NULL) : NULL;
    GCancellable* cancellable = g_cancellable_new();

    data->loop = g_main_loop_new (NULL, TRUE);
    data->action = action;

    switch(data->action)
    {
    case MOUNT_VOLUME:
        g_volume_mount(G_VOLUME(obj), 0, op, cancellable, on_mount_action_finished, data);
        break;
    case MOUNT_GFILE:
        g_file_mount_enclosing_volume(G_FILE(obj), 0, op, cancellable, on_mount_action_finished, data);
        break;
    case UMOUNT_MOUNT:
        prepare_unmount(G_MOUNT(obj));
        g_mount_unmount_with_operation(G_MOUNT(obj), G_MOUNT_UNMOUNT_NONE, op, cancellable, on_mount_action_finished, data);
        break;
    case EJECT_MOUNT:
        prepare_unmount(G_MOUNT(obj));
        g_mount_eject_with_operation(G_MOUNT(obj), G_MOUNT_UNMOUNT_NONE, op, cancellable, on_mount_action_finished, data);
        break;
    case EJECT_VOLUME:
        {
            GMount* mnt = g_volume_get_mount(G_VOLUME(obj));
            if (mnt) /* it might be unmounted already */
            {
                prepare_unmount(mnt);
                g_object_unref(mnt);
            }
            g_volume_eject_with_operation(G_VOLUME(obj), G_MOUNT_UNMOUNT_NONE, op, cancellable, on_mount_action_finished, data);
        }
        break;
    }

    /* FIXME: create progress window with busy cursor */
    if (g_main_loop_is_running(data->loop))
    {
        GDK_THREADS_LEAVE();
        g_main_loop_run(data->loop);
        GDK_THREADS_ENTER();
    }

    g_main_loop_unref(data->loop);

    ret = data->ret;
    if(data->err)
    {
        if(interactive)
        {
            if(data->err->domain == G_IO_ERROR)
            {
                if(data->err->code == G_IO_ERROR_FAILED)
                {
                    /* Generate a more human-readable error message instead of using a gvfs one. */

                    /* The original error message is something like:
                     * Error unmounting: umount exited with exit code 1:
                     * helper failed with: umount: only root can unmount
                     * UUID=18cbf00c-e65f-445a-bccc-11964bdea05d from /media/sda4 */

                    /* Why they pass this back to us?
                     * This is not human-readable for the users at all. */

                    if(strstr(data->err->message, "only root can "))
                    {
                        g_debug("%s", data->err->message);
                        g_free(data->err->message);
                        data->err->message = g_strdup(_("Only system administrators have the permission to do this."));
                    }
                }
                else if(data->err->code == G_IO_ERROR_FAILED_HANDLED)
                    interactive = FALSE;
            }
            if(interactive)
                fm_show_error(parent, NULL, data->err->message);
        }
        g_error_free(data->err);
    }

    g_free(data);
    g_object_unref(cancellable);
    if(op)
        g_object_unref(op);
    return ret;
}
const gchar *pup_mount_get_sort_key(GMount *mount)
{
	PupMount *self = PUP_MOUNT(mount);

	return pup_client_volume_get_sort_key(G_VOLUME(self->holder));
}