3
3
* Copyright (c) 2006 Benedikt Meurer <benny@xfce.org>
4
* Copyright (c) 2009 Jannis Pohlmann <jannis@xfce.org>
5
6
* This program is free software; you can redistribute it and/or modify it
6
7
* under the terms of the GNU General Public License as published by the Free
47
static void thunar_size_label_class_init (ThunarSizeLabelClass *klass);
48
static void thunar_size_label_init (ThunarSizeLabel *size_label);
49
49
static void thunar_size_label_finalize (GObject *object);
50
50
static void thunar_size_label_get_property (GObject *object,
60
60
ThunarSizeLabel *size_label);
61
61
static void thunar_size_label_file_changed (ThunarFile *file,
62
62
ThunarSizeLabel *size_label);
63
static void thunar_size_label_error (ThunarVfsJob *job,
63
static void thunar_size_label_error (ExoJob *job,
64
64
const GError *error,
65
65
ThunarSizeLabel *size_label);
66
static void thunar_size_label_finished (ThunarVfsJob *job,
66
static void thunar_size_label_finished (ExoJob *job,
67
67
ThunarSizeLabel *size_label);
68
static void thunar_size_label_status_ready (ThunarVfsJob *job,
68
static void thunar_size_label_status_update (ThunarDeepCountJob *job,
69
69
guint64 total_size,
71
71
guint directory_count,
84
84
struct _ThunarSizeLabel
88
ThunarDeepCountJob *job;
94
95
/* the throbber animation is started after a timeout */
95
gint animate_timer_id;
96
gint animate_timer_id;
100
static GObjectClass *thunar_size_label_parent_class;
105
thunar_size_label_get_type (void)
107
static GType type = G_TYPE_INVALID;
109
if (G_UNLIKELY (type == G_TYPE_INVALID))
111
static const GTypeInfo info =
113
sizeof (ThunarSizeLabelClass),
116
(GClassInitFunc) thunar_size_label_class_init,
119
sizeof (ThunarSizeLabel),
121
(GInstanceInitFunc) thunar_size_label_init,
125
type = g_type_register_static (GTK_TYPE_HBOX, I_("ThunarSizeLabel"), &info, 0);
101
G_DEFINE_TYPE (ThunarSizeLabel, thunar_size_label, GTK_TYPE_HBOX)
136
108
GObjectClass *gobject_class;
138
/* determine the parent type class */
139
thunar_size_label_parent_class = g_type_class_peek_parent (klass);
141
110
gobject_class = G_OBJECT_CLASS (klass);
142
111
gobject_class->finalize = thunar_size_label_finalize;
143
112
gobject_class->get_property = thunar_size_label_get_property;
174
143
ebox = gtk_event_box_new ();
175
144
gtk_event_box_set_visible_window (GTK_EVENT_BOX (ebox), FALSE);
176
145
g_signal_connect (G_OBJECT (ebox), "button-press-event", G_CALLBACK (thunar_size_label_button_press_event), size_label);
177
thunar_gtk_widget_set_tooltip (ebox, _("Click here to stop calculating the total size of the folder."));
146
gtk_widget_set_tooltip_text (ebox, _("Click here to stop calculating the total size of the folder."));
178
147
gtk_box_pack_start (GTK_BOX (size_label), ebox, FALSE, FALSE, 0);
179
148
gtk_widget_show (ebox);
206
175
if (G_UNLIKELY (size_label->job != NULL))
208
177
g_signal_handlers_disconnect_matched (G_OBJECT (size_label->job), G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, size_label);
209
thunar_vfs_job_cancel (THUNAR_VFS_JOB (size_label->job));
210
g_object_unref (G_OBJECT (size_label->job));
178
exo_job_cancel (EXO_JOB (size_label->job));
179
g_object_unref (size_label->job);
213
182
/* reset the file property */
284
253
/* cancel the pending job (if any) */
285
254
if (G_UNLIKELY (size_label->job != NULL))
287
g_signal_handlers_disconnect_matched (G_OBJECT (size_label->job), G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, size_label);
288
thunar_vfs_job_cancel (THUNAR_VFS_JOB (size_label->job));
289
g_object_unref (G_OBJECT (size_label->job));
256
g_signal_handlers_disconnect_matched (size_label->job, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, size_label);
257
exo_job_cancel (EXO_JOB (size_label->job));
258
g_object_unref (size_label->job);
290
259
size_label->job = NULL;
356
325
thunar_size_label_file_changed (ThunarFile *file,
357
326
ThunarSizeLabel *size_label)
359
ThunarVfsFileSize size;
360
GError *error = NULL;
361
gchar *size_humanized;
329
gchar *size_humanized;
365
333
_thunar_return_if_fail (THUNAR_IS_SIZE_LABEL (size_label));
366
334
_thunar_return_if_fail (size_label->file == file);
373
341
/* cancel the pending job (if any) */
374
342
if (G_UNLIKELY (size_label->job != NULL))
376
g_signal_handlers_disconnect_matched (G_OBJECT (size_label->job), G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, size_label);
377
thunar_vfs_job_cancel (THUNAR_VFS_JOB (size_label->job));
378
g_object_unref (G_OBJECT (size_label->job));
344
g_signal_handlers_disconnect_matched (size_label->job, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, size_label);
345
exo_job_cancel (EXO_JOB (size_label->job));
346
g_object_unref (size_label->job);
379
347
size_label->job = NULL;
387
355
if (thunar_file_is_directory (file))
389
357
/* schedule a new job to determine the total size of the directory (not following symlinks) */
390
size_label->job = thunar_vfs_deep_count (thunar_file_get_path (file), THUNAR_VFS_DEEP_COUNT_FLAGS_NONE, &error);
391
if (G_UNLIKELY (size_label->job == NULL))
393
/* display the error to the user */
394
gtk_label_set_text (GTK_LABEL (size_label->label), error->message);
395
g_error_free (error);
399
/* connect to the job */
400
g_signal_connect (G_OBJECT (size_label->job), "error", G_CALLBACK (thunar_size_label_error), size_label);
401
g_signal_connect (G_OBJECT (size_label->job), "finished", G_CALLBACK (thunar_size_label_finished), size_label);
402
g_signal_connect (G_OBJECT (size_label->job), "status-ready", G_CALLBACK (thunar_size_label_status_ready), size_label);
404
/* tell the user that we started calculation */
405
gtk_label_set_text (GTK_LABEL (size_label->label), _("Calculating..."));
358
size_label->job = thunar_deep_count_job_new (thunar_file_get_file (file), G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS);
359
g_signal_connect (size_label->job, "error", G_CALLBACK (thunar_size_label_error), size_label);
360
g_signal_connect (size_label->job, "finished", G_CALLBACK (thunar_size_label_finished), size_label);
361
g_signal_connect (size_label->job, "status-update", G_CALLBACK (thunar_size_label_status_update), size_label);
363
/* tell the user that we started calculation */
364
gtk_label_set_text (GTK_LABEL (size_label->label), _("Calculating..."));
367
exo_job_launch (EXO_JOB (size_label->job));
419
380
if (G_LIKELY (size > 1024ul))
421
382
/* prepend the humanized size */
422
size_humanized = thunar_vfs_humanize_size (size, NULL, 0);
383
size_humanized = g_format_size_for_display (size);
423
384
text = g_strdup_printf ("%s (%s)", size_humanized, size_string);
424
385
g_free (size_humanized);
425
386
g_free (size_string);
440
thunar_size_label_error (ThunarVfsJob *job,
401
thunar_size_label_error (ExoJob *job,
441
402
const GError *error,
442
403
ThunarSizeLabel *size_label)
405
_thunar_return_if_fail (THUNAR_IS_JOB (job));
444
406
_thunar_return_if_fail (THUNAR_IS_SIZE_LABEL (size_label));
445
_thunar_return_if_fail (THUNAR_VFS_IS_JOB (job));
446
_thunar_return_if_fail (size_label->job == job);
407
_thunar_return_if_fail (size_label->job == THUNAR_DEEP_COUNT_JOB (job));
448
409
/* setup the error text as label */
449
410
gtk_label_set_text (GTK_LABEL (size_label->label), error->message);
455
thunar_size_label_finished (ThunarVfsJob *job,
416
thunar_size_label_finished (ExoJob *job,
456
417
ThunarSizeLabel *size_label)
419
_thunar_return_if_fail (THUNAR_IS_JOB (job));
458
420
_thunar_return_if_fail (THUNAR_IS_SIZE_LABEL (size_label));
459
_thunar_return_if_fail (THUNAR_VFS_IS_JOB (job));
460
_thunar_return_if_fail (size_label->job == job);
421
_thunar_return_if_fail (size_label->job == THUNAR_DEEP_COUNT_JOB (job));
462
423
/* be sure to cancel the animate timer */
463
424
if (G_UNLIKELY (size_label->animate_timer_id >= 0))
468
429
gtk_widget_hide (size_label->throbber);
470
431
/* disconnect from the job */
471
g_signal_handlers_disconnect_matched (G_OBJECT (size_label->job), G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, size_label);
472
g_object_unref (G_OBJECT (size_label->job));
432
g_signal_handlers_disconnect_matched (size_label->job, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, size_label);
433
g_object_unref (size_label->job);
473
434
size_label->job = NULL;
479
thunar_size_label_status_ready (ThunarVfsJob *job,
482
guint directory_count,
483
guint unreadable_directory_count,
484
ThunarSizeLabel *size_label)
440
thunar_size_label_status_update (ThunarDeepCountJob *job,
443
guint directory_count,
444
guint unreadable_directory_count,
445
ThunarSizeLabel *size_label)
486
447
gchar *size_string;
451
_thunar_return_if_fail (THUNAR_IS_DEEP_COUNT_JOB (job));
490
452
_thunar_return_if_fail (THUNAR_IS_SIZE_LABEL (size_label));
491
_thunar_return_if_fail (THUNAR_VFS_IS_JOB (job));
492
453
_thunar_return_if_fail (size_label->job == job);
494
455
/* check if the animate timer is already running */
503
464
n = file_count + directory_count + unreadable_directory_count;
505
466
/* update the label */
506
size_string = thunar_vfs_humanize_size (total_size, NULL, 0);
467
size_string = g_format_size_for_display (total_size);
507
468
text = g_strdup_printf (ngettext ("%u item, totalling %s", "%u items, totalling %s", n), n, size_string);
508
469
gtk_label_set_text (GTK_LABEL (size_label->label), text);
509
470
g_free (size_string);