summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2007-11-16 11:09:08 +0000
committerAlexander Larsson <alexl@src.gnome.org>2007-11-16 11:09:08 +0000
commit144c3c5f701650cf9ddeff8de9431155954a48df (patch)
tree019ad305c7e69c4ed3188f16832edb19bd1dc163
parent3be2ddd91ebf4d9dffdf8ee44b89e82f06783012 (diff)
downloadnautilus-144c3c5f701650cf9ddeff8de9431155954a48df.tar.gz
Added NautilusProgressInfo class
2007-11-16 Alexander Larsson <alexl@redhat.com> * libnautilus-private/Makefile.am: * libnautilus-private/nautilus-progress-info.[ch]: Added NautilusProgressInfo class * libnautilus-private/nautilus-file-operations.c: * src/file-manager/fm-tree-view.c: * src/nautilus-places-sidebar.c: Update to new gio API svn path=/branches/gio-branch/; revision=13422
-rw-r--r--ChangeLog11
-rw-r--r--libnautilus-private/Makefile.am2
-rw-r--r--libnautilus-private/nautilus-file-operations.c1
-rw-r--r--libnautilus-private/nautilus-progress-info.c386
-rw-r--r--libnautilus-private/nautilus-progress-info.h72
-rw-r--r--src/file-manager/fm-tree-view.c4
-rw-r--r--src/nautilus-places-sidebar.c18
7 files changed, 485 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 5b2e9966c..3db49f191 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2007-11-16 Alexander Larsson <alexl@redhat.com>
+
+ * libnautilus-private/Makefile.am:
+ * libnautilus-private/nautilus-progress-info.[ch]:
+ Added NautilusProgressInfo class
+
+ * libnautilus-private/nautilus-file-operations.c:
+ * src/file-manager/fm-tree-view.c:
+ * src/nautilus-places-sidebar.c:
+ Update to new gio API
+
2007-11-13 Alexander Larsson <alexl@redhat.com>
* src/file-manager/fm-error-reporting.c:
diff --git a/libnautilus-private/Makefile.am b/libnautilus-private/Makefile.am
index 646f82ac0..bd7d8764f 100644
--- a/libnautilus-private/Makefile.am
+++ b/libnautilus-private/Makefile.am
@@ -154,6 +154,8 @@ libnautilus_private_la_SOURCES = \
nautilus-monitor.h \
nautilus-open-with-dialog.c \
nautilus-open-with-dialog.h \
+ nautilus-progress-info.c \
+ nautilus-progress-info.h \
nautilus-program-choosing.c \
nautilus-program-choosing.h \
nautilus-recent.c \
diff --git a/libnautilus-private/nautilus-file-operations.c b/libnautilus-private/nautilus-file-operations.c
index aa7a3155e..e28d22993 100644
--- a/libnautilus-private/nautilus-file-operations.c
+++ b/libnautilus-private/nautilus-file-operations.c
@@ -3689,6 +3689,7 @@ nautilus_file_operations_unmount_volume (GtkWindow *parent_
data->callback = callback;
data->user_data = user_data;
g_volume_unmount (volume,
+ NULL,
unmount_volume_callback,
data);
}
diff --git a/libnautilus-private/nautilus-progress-info.c b/libnautilus-private/nautilus-progress-info.c
new file mode 100644
index 000000000..c7daf64c0
--- /dev/null
+++ b/libnautilus-private/nautilus-progress-info.c
@@ -0,0 +1,386 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
+
+ nautilus-progress-info.h: file operation progress info.
+
+ Copyright (C) 2007 Red Hat, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with this program; if not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Alexander Larsson <alexl@redhat.com>
+*/
+
+#include <config.h>
+#include <math.h>
+#include <glib/gi18n.h>
+#include <eel/eel-string.h>
+#include "nautilus-progress-info.h"
+
+enum {
+ CHANGED,
+ PROGRESS_CHANGED,
+ STARTED,
+ FINISHED,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+struct _NautilusProgressInfo
+{
+ GObject parent_instance;
+
+ GCancellable *cancellable;
+
+ char *status;
+ char *details;
+ double progress;
+ gboolean activity_mode;
+ gboolean started;
+ gboolean finished;
+
+ guint idle_tag;
+
+ gboolean start_at_idle;
+ gboolean finish_at_idle;
+ gboolean changed_at_idle;
+ gboolean progress_at_idle;
+};
+
+struct _NautilusProgressInfoClass
+{
+ GObjectClass parent_class;
+};
+
+
+G_LOCK_DEFINE_STATIC(progress_info);
+
+G_DEFINE_TYPE (NautilusProgressInfo, nautilus_progress_info, G_TYPE_OBJECT)
+
+static void
+nautilus_progress_info_finalize (GObject *object)
+{
+ NautilusProgressInfo *info;
+
+ info = NAUTILUS_PROGRESS_INFO (object);
+
+ g_free (info->status);
+ g_free (info->details);
+ g_object_unref (info->cancellable);
+
+ /* idle refs info, so should never be outstanding at this point */
+ g_assert (info->idle_tag == 0);
+
+ if (G_OBJECT_CLASS (nautilus_progress_info_parent_class)->finalize)
+ (*G_OBJECT_CLASS (nautilus_progress_info_parent_class)->finalize) (object);
+}
+
+static void
+nautilus_progress_info_class_init (NautilusProgressInfoClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->finalize = nautilus_progress_info_finalize;
+
+ signals[CHANGED] =
+ g_signal_new ("changed",
+ NAUTILUS_TYPE_PROGRESS_INFO,
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ signals[PROGRESS_CHANGED] =
+ g_signal_new ("progress-changed",
+ NAUTILUS_TYPE_PROGRESS_INFO,
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ signals[STARTED] =
+ g_signal_new ("started",
+ NAUTILUS_TYPE_PROGRESS_INFO,
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ signals[FINISHED] =
+ g_signal_new ("finished",
+ NAUTILUS_TYPE_PROGRESS_INFO,
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+}
+
+static void
+nautilus_progress_info_init (NautilusProgressInfo *info)
+{
+ info->cancellable = g_cancellable_new ();
+}
+
+NautilusProgressInfo *
+nautilus_progress_info_new (void)
+{
+ NautilusProgressInfo *info;
+
+ info = g_object_new (NAUTILUS_TYPE_PROGRESS_INFO, NULL);
+
+ return info;
+}
+
+char *
+nautilus_progress_info_get_status (NautilusProgressInfo *info)
+{
+ char *res;
+
+ G_LOCK (progress_info);
+
+ if (info->status)
+ res = g_strdup (info->status);
+ else
+ res = g_strdup (_("Preparing"));
+
+ G_UNLOCK (progress_info);
+
+ return res;
+}
+
+char *
+nautilus_progress_info_get_details (NautilusProgressInfo *info)
+{
+ char *res;
+
+ G_LOCK (progress_info);
+
+ if (info->details)
+ res = g_strdup (info->details);
+ else
+ res = g_strdup (_("Preparing"));
+
+ G_UNLOCK (progress_info);
+
+ return res;
+}
+
+double
+nautilus_progress_info_get_progress (NautilusProgressInfo *info)
+{
+ double res;
+
+ G_LOCK (progress_info);
+
+ res = info->progress;
+
+ G_UNLOCK (progress_info);
+
+ return res;
+}
+
+GCancellable *
+nautilus_progress_info_get_cancellable (NautilusProgressInfo *info)
+{
+ GCancellable *c;
+
+ G_LOCK (progress_info);
+
+ c = g_object_ref (info->cancellable);
+
+ G_UNLOCK (progress_info);
+
+ return c;
+}
+
+gboolean
+nautilus_progress_info_get_is_started (NautilusProgressInfo *info)
+{
+ gboolean res;
+
+ G_LOCK (progress_info);
+
+ res = info->started;
+
+ G_UNLOCK (progress_info);
+
+ return res;
+}
+
+gboolean
+nautilus_progress_info_get_is_finished (NautilusProgressInfo *info)
+{
+ gboolean res;
+
+ G_LOCK (progress_info);
+
+ res = info->finished;
+
+ G_UNLOCK (progress_info);
+
+ return res;
+}
+
+static gboolean
+idle_callback (gpointer data)
+{
+ NautilusProgressInfo *info = data;
+ gboolean start_at_idle;
+ gboolean finish_at_idle;
+ gboolean changed_at_idle;
+ gboolean progress_at_idle;
+
+ G_LOCK (progress_info);
+
+ info->idle_tag = 0;
+
+ start_at_idle = info->start_at_idle;
+ finish_at_idle = info->finish_at_idle;
+ changed_at_idle = info->changed_at_idle;
+ progress_at_idle = info->progress_at_idle;
+
+ info->start_at_idle = FALSE;
+ info->finish_at_idle = FALSE;
+ info->changed_at_idle = FALSE;
+ info->progress_at_idle = FALSE;
+
+ G_UNLOCK (progress_info);
+
+ if (start_at_idle)
+ g_signal_emit (info,
+ STARTED,
+ 0);
+
+ if (changed_at_idle)
+ g_signal_emit (info,
+ CHANGED,
+ 0);
+
+ if (progress_at_idle)
+ g_signal_emit (info,
+ PROGRESS_CHANGED,
+ 0);
+
+ if (finish_at_idle)
+ g_signal_emit (info,
+ FINISHED,
+ 0);
+
+ g_object_unref (info);
+
+ return FALSE;
+}
+
+/* Called with lock held */
+static void
+queue_idle (NautilusProgressInfo *info)
+{
+ if (info->idle_tag != 0)
+ info->idle_tag = g_idle_add (idle_callback, g_object_ref (info));
+}
+
+void
+nautilus_progress_info_start (NautilusProgressInfo *info)
+{
+ G_LOCK (progress_info);
+
+ if (!info->started)
+ {
+ info->started = TRUE;
+
+ info->start_at_idle = TRUE;
+ queue_idle (info);
+ }
+
+ G_UNLOCK (progress_info);
+}
+
+void
+nautilus_progress_info_finish (NautilusProgressInfo *info)
+{
+ G_LOCK (progress_info);
+
+ if (!info->finished)
+ {
+ info->finished = TRUE;
+
+ info->finish_at_idle = TRUE;
+ queue_idle (info);
+ }
+
+ G_UNLOCK (progress_info);
+}
+
+void
+nautilus_progress_info_set_status (NautilusProgressInfo *info,
+ const char *status)
+{
+ G_LOCK (progress_info);
+
+ if (eel_strcmp (info->status, status) != 0)
+ {
+ g_free (info->status);
+ info->status = g_strdup (status);
+
+ info->changed_at_idle = TRUE;
+ queue_idle (info);
+ }
+
+ G_UNLOCK (progress_info);
+}
+
+void
+nautilus_progress_info_set_details (NautilusProgressInfo *info,
+ const char *details)
+{
+ G_LOCK (progress_info);
+
+ if (eel_strcmp (info->details, details) != 0)
+ {
+ g_free (info->details);
+ info->details = g_strdup (details);
+
+ info->changed_at_idle = TRUE;
+ queue_idle (info);
+ }
+
+ G_UNLOCK (progress_info);
+}
+
+void
+nautilus_progress_info_set_progress (NautilusProgressInfo *info,
+ gboolean activity_mode,
+ double current_percent)
+{
+ G_LOCK (progress_info);
+
+ if (activity_mode || /* Always pulse if activity mode */
+ info->activity_mode || /* emit on switch from activity mode */
+ fabs (current_percent - info->progress) > 0.1 /* Emit on change of 0.1 percent */
+ )
+ {
+ info->progress = current_percent;
+
+ info->progress_at_idle = TRUE;
+ queue_idle (info);
+ }
+
+ G_UNLOCK (progress_info);
+}
diff --git a/libnautilus-private/nautilus-progress-info.h b/libnautilus-private/nautilus-progress-info.h
new file mode 100644
index 000000000..dd90f5da1
--- /dev/null
+++ b/libnautilus-private/nautilus-progress-info.h
@@ -0,0 +1,72 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
+
+ nautilus-progress-info.h: file operation progress info.
+
+ Copyright (C) 2007 Red Hat, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with this program; if not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Alexander Larsson <alexl@redhat.com>
+*/
+
+#ifndef NAUTILUS_PROGRESS_INFO_H
+#define NAUTILUS_PROGRESS_INFO_H
+
+#include <glib-object.h>
+#include <gio/gcancellable.h>
+
+#define NAUTILUS_TYPE_PROGRESS_INFO (nautilus_progress_info_get_type ())
+#define NAUTILUS_PROGRESS_INFO(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), NAUTILUS_TYPE_PROGRESS_INFO, NautilusProgressInfo))
+#define NAUTILUS_PROGRESS_INFO_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), NAUTILUS_TYPE_PROGRESS_INFO, NautilusProgressInfoClass))
+#define NAUTILUS_IS_PROGRESS_INFO(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), NAUTILUS_TYPE_PROGRESS_INFO))
+#define NAUTILUS_IS_PROGRESS_INFO_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), NAUTILUS_TYPE_PROGRESS_INFO))
+#define NAUTILUS_PROGRESS_INFO_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), NAUTILUS_TYPE_PROGRESS_INFO, NautilusProgressInfoClass))
+
+typedef struct _NautilusProgressInfo NautilusProgressInfo;
+typedef struct _NautilusProgressInfoClass NautilusProgressInfoClass;
+
+GType nautilus_progress_info_get_type (void) G_GNUC_CONST;
+
+/* Signals:
+ "changed" - status or details changed
+ "progress-changed" - the percentage progress changed (or we pulsed if in activity_mode
+ "started" - emited on job start
+ "finished" - emitted when job is done
+
+ All signals are emitted from idles in main loop.
+ All methods are threadsafe.
+ */
+
+NautilusProgressInfo *nautilus_progress_info_new (void);
+
+char * nautilus_progress_info_get_status (NautilusProgressInfo *info);
+char * nautilus_progress_info_get_details (NautilusProgressInfo *info);
+double nautilus_progress_info_get_progress (NautilusProgressInfo *info);
+GCancellable *nautilus_progress_info_get_cancellable (NautilusProgressInfo *info);
+gboolean nautilus_progress_info_get_is_started (NautilusProgressInfo *info);
+gboolean nautilus_progress_info_get_is_finished (NautilusProgressInfo *info);
+
+void nautilus_progress_info_start (NautilusProgressInfo *info);
+void nautilus_progress_info_finish (NautilusProgressInfo *info);
+void nautilus_progress_info_set_status (NautilusProgressInfo *info,
+ const char *status);
+void nautilus_progress_info_set_details (NautilusProgressInfo *info,
+ const char *details);
+void nautilus_progress_info_set_progress (NautilusProgressInfo *info,
+ gboolean activity_mode,
+ double current_percent);
+
+#endif /* NAUTILUS_PROGRESS_INFO_H */
diff --git a/src/file-manager/fm-tree-view.c b/src/file-manager/fm-tree-view.c
index d88937e44..ec045aaa6 100644
--- a/src/file-manager/fm-tree-view.c
+++ b/src/file-manager/fm-tree-view.c
@@ -1098,10 +1098,10 @@ fm_tree_view_unmount_cb (GtkWidget *menu_item,
if (volume != NULL) {
if (g_volume_can_eject (volume)) {
/* TODO-gio: Handle callbacks */
- g_volume_eject (volume, NULL, NULL);
+ g_volume_eject (volume, NULL, NULL, NULL);
} else {
/* TODO-gio: Handle callbacks */
- g_volume_unmount (volume, NULL, NULL);
+ g_volume_unmount (volume, NULL, NULL, NULL);
}
}
}
diff --git a/src/nautilus-places-sidebar.c b/src/nautilus-places-sidebar.c
index cd1f90ca3..6d88d3f1e 100644
--- a/src/nautilus-places-sidebar.c
+++ b/src/nautilus-places-sidebar.c
@@ -1202,7 +1202,7 @@ open_selected_bookmark (NautilusPlacesSidebar *sidebar,
gtk_tree_model_get (model, &iter, PLACES_SIDEBAR_COLUMN_DRIVE, &drive, -1);
if (drive != NULL) {
/* TODO-gio: Handle callbacks etc */
- g_drive_mount (drive, NULL, NULL, sidebar);
+ g_drive_mount (drive, NULL, NULL, NULL, sidebar);
g_object_unref (drive);
}
}
@@ -1318,7 +1318,7 @@ mount_shortcut_cb (GtkMenuItem *item,
if (drive != NULL) {
/* TODO-gio: Handle callbacks etc */
- g_drive_mount (drive, NULL, NULL, sidebar);
+ g_drive_mount (drive, NULL, NULL, NULL, sidebar);
g_object_unref (drive);
}
}
@@ -1348,9 +1348,13 @@ unmount_shortcut_cb (GtkMenuItem *item,
nautilus_file_operations_unmount_volume (GTK_WINDOW (toplevel),
volume, NULL, sidebar);
- }
- g_object_unref (volume);
- g_object_unref (drive);
+ }
+ if (volume != NULL) {
+ g_object_unref (volume);
+ }
+ if (drive != NULL) {
+ g_object_unref (drive);
+ }
}
static void
@@ -1372,10 +1376,10 @@ eject_shortcut_cb (GtkMenuItem *item,
if (volume != NULL) {
/* TODO-gio: Handle callbacks etc */
- g_volume_eject (volume, NULL, sidebar);
+ g_volume_eject (volume, NULL, NULL, sidebar);
} else if (drive != NULL) {
/* TODO-gio: Handle callbacks etc */
- g_drive_eject (drive, NULL, sidebar);
+ g_drive_eject (drive, NULL, NULL, sidebar);
}
g_object_unref (volume);
g_object_unref (drive);