<commit_before>/* 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
 * version 2 of the License, or (at your option) any later version.
 *
 * 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
 * Public License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 * Author: <NAME> <<EMAIL>>
 */

#include <config.h>

#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>

#include <glib.h>
#include <glib/gi18n.h>
#include "gvfsjobunmount.h"

G_DEFINE_TYPE (GVfsJobUnmount, g_vfs_job_unmount, G_VFS_TYPE_JOB_DBUS)

static void     run        (GVfsJob *job);
static gboolean try        (GVfsJob *job);
static void     send_reply (GVfsJob *job);
static void     create_reply (GVfsJob               *job,
                              GVfsDBusMount         *object,
                              GDBusMethodInvocation *invocation);

static void
g_vfs_job_unmount_finalize (GObject *object)
{
  GVfsJobUnmount *job;

   job = G_VFS_JOB_UNMOUNT (object);

  if (job->mount_source)
    g_object_unref (job->mount_source);

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

static void
g_vfs_job_unmount_class_init (GVfsJobUnmountClass *klass)
{
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
  GVfsJobClass *job_class = G_VFS_JOB_CLASS (klass);
  GVfsJobDBusClass *job_dbus_class = G_VFS_JOB_DBUS_CLASS (klass);
  
  gobject_class->finalize = g_vfs_job_unmount_finalize;
  job_class->run = run;
  job_class->try = try;
  job_class->send_reply = send_reply;

  job_dbus_class->create_reply = create_reply;
}

static void
g_vfs_job_unmount_init (GVfsJobUnmount *job)
{
}

gboolean
g_vfs_job_unmount_new_handle (GVfsDBusMount *object,
                              GDBusMethodInvocation *invocation,
                              const gchar *arg_dbus_id,
                              const gchar *arg_obj_path,
                              guint arg_flags,
                              GVfsBackend *backend)
{
  GVfsJobUnmount *job;

  if (g_vfs_backend_invocation_first_handler (object, invocation, backend))
    return TRUE;

  g_debug ("g_vfs_job_unmount_new request: %p\n", invocation);

  job = g_object_new (G_VFS_TYPE_JOB_UNMOUNT,
                      "object", object,
                      "invocation", invocation,
                      NULL);

  job->backend = backend;
  job->flags = arg_flags;
  job->mount_source = g_mount_source_new (arg_dbus_id, arg_obj_path);
  
  g_vfs_job_source_new_job (G_VFS_JOB_SOURCE (backend), G_VFS_JOB (job));
  g_object_unref (job);

  return TRUE;
}

static void
unmount_progress_clear (GVfsJobUnmount *op_job)
{
  gchar *message;

  if (op_job->unmount_progress_id > 0)
    {
      g_source_remove (op_job->unmount_progress_id);
      op_job->unmount_progress_id = 0;
    }

  if (!op_job->unmount_progress_fired)
    return;

  g_debug ("gvfsjobunmount progress clear");

  message = g_strdup_printf (_("%s has been unmounted\n"),
                             g_vfs_backend_get_display_name (op_job->backend));
  g_mount_source_show_unmount_progress (op_job->mount_source,
                                        message, 0, 0);
  g_free (message);
}

static gboolean
unmount_progress_timeout (gpointer user_data)
{
  GVfsJobUnmount *op_job = user_data;
  gchar *message;

  op_job->unmount_progress_id = 0;
  op_job->unmount_progress_fired = TRUE;

  g_debug ("gvfsjobunmount progress timeout reached");

  message = g_strdup_printf (_("Unmounting %s\nPlease wait"),
                             g_vfs_backend_get_display_name (op_job->backend));
  /* TODO: report estimated bytes and time left */
  g_mount_source_show_unmount_progress (op_job->mount_source,
                                        message, -1, -1);
  g_free (message);

  return FALSE;
}

static void
unmount_progress_start (GVfsJobUnmount *op_job)
{
  if (op_job->unmount_progress_id > 0)
    return;

  g_debug ("gvfsjobunmount progress timeout start");
  op_job->unmount_progress_id = g_timeout_add (1500, unmount_progress_timeout, op_job);
}

static void
run (GVfsJob *job)
{
  GVfsJobUnmount *op_job = G_VFS_JOB_UNMOUNT (job);
  GVfsBackendClass *class = G_VFS_BACKEND_GET_CLASS (op_job->backend);

  if (class->unmount == NULL)
    return;<commit_msg>GVfsJobUnmount: Fix debug messages line endings<commit_after>/* 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
 * version 2 of the License, or (at your option) any later version.
 *
 * 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
 * Public License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 * Author: <NAME> <<EMAIL>>
 */

#include <config.h>

#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>

#include <glib.h>
#include <glib/gi18n.h>
#include "gvfsjobunmount.h"

G_DEFINE_TYPE (GVfsJobUnmount, g_vfs_job_unmount, G_VFS_TYPE_JOB_DBUS)

static void     run        (GVfsJob *job);
static gboolean try        (GVfsJob *job);
static void     send_reply (GVfsJob *job);
static void     create_reply (GVfsJob               *job,
                              GVfsDBusMount         *object,
                              GDBusMethodInvocation *invocation);

static void
g_vfs_job_unmount_finalize (GObject *object)
{
  GVfsJobUnmount *job;

   job = G_VFS_JOB_UNMOUNT (object);

  if (job->mount_source)
    g_object_unref (job->mount_source);

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

static void
g_vfs_job_unmount_class_init (GVfsJobUnmountClass *klass)
{
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
  GVfsJobClass *job_class = G_VFS_JOB_CLASS (klass);
  GVfsJobDBusClass *job_dbus_class = G_VFS_JOB_DBUS_CLASS (klass);
  
  gobject_class->finalize = g_vfs_job_unmount_finalize;
  job_class->run = run;
  job_class->try = try;
  job_class->send_reply = send_reply;

  job_dbus_class->create_reply = create_reply;
}

static void
g_vfs_job_unmount_init (GVfsJobUnmount *job)
{
}

gboolean
g_vfs_job_unmount_new_handle (GVfsDBusMount *object,
                              GDBusMethodInvocation *invocation,
                              const gchar *arg_dbus_id,
                              const gchar *arg_obj_path,
                              guint arg_flags,
                              GVfsBackend *backend)
{
  GVfsJobUnmount *job;

  if (g_vfs_backend_invocation_first_handler (object, invocation, backend))
    return TRUE;

  g_debug ("g_vfs_job_unmount_new request: %p\n", invocation);

  job = g_object_new (G_VFS_TYPE_JOB_UNMOUNT,
                      "object", object,
                      "invocation", invocation,
                      NULL);

  job->backend = backend;
  job->flags = arg_flags;
  job->mount_source = g_mount_source_new (arg_dbus_id, arg_obj_path);
  
  g_vfs_job_source_new_job (G_VFS_JOB_SOURCE (backend), G_VFS_JOB (job));
  g_object_unref (job);

  return TRUE;
}

static void
unmount_progress_clear (GVfsJobUnmount *op_job)
{
  gchar *message;

  if (op_job->unmount_progress_id > 0)
    {
      g_source_remove (op_job->unmount_progress_id);
      op_job->unmount_progress_id = 0;
    }

  if (!op_job->unmount_progress_fired)
    return;

  g_debug ("gvfsjobunmount progress clear\n");

  message = g_strdup_printf (_("%s has been unmounted\n"),
                             g_vfs_backend_get_display_name (op_job->backend));
  g_mount_source_show_unmount_progress (op_job->mount_source,
                                        message, 0, 0);
  g_free (message);
}

static gboolean
unmount_progress_timeout (gpointer user_data)
{
  GVfsJobUnmount *op_job = user_data;
  gchar *message;

  op_job->unmount_progress_id = 0;
  op_job->unmount_progress_fired = TRUE;

  g_debug ("gvfsjobunmount progress timeout reached\n");

  message = g_strdup_printf (_("Unmounting %s\nPlease wait"),
                             g_vfs_backend_get_display_name (op_job->backend));
  /* TODO: report estimated bytes and time left */
  g_mount_source_show_unmount_progress (op_job->mount_source,
                                        message, -1, -1);
  g_free (message);

  return FALSE;
}

static void
unmount_progress_start (GVfsJobUnmount *op_job)
{
  if (op_job->unmount_progress_id > 0)
    return;

  g_debug ("gvfsjobunmount progress timeout start\n");
  op_job->unmount_progress_id = g_timeout_add (1500, unmount_progress_timeout, op_job);
}

static void
run (GVfsJob *job)
{
  GVfsJobUnmount *op_job = G_VFS_JOB_UNMOUNT (job);
  GVfsBackendClass *class = G_VFS_BACKEND_GET_CLASS (op_job->backend);

  if (class->unmount == NULL)
    return;
{'fraction_non_alphanumeric': 0.08941272099166836, 'fraction_numerical': 0.006909164803901646, 'mean_word_length': 3.1689961880559085, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2723130', 'n_tokens_mistral': 3467, 'n_tokens_neox': 3321, 'n_words': 800}