~noskcaj/ubuntu/vivid/thunar/1.6.4

« back to all changes in this revision

Viewing changes to thunar/thunar-size-label.c

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Le Folgoc
  • Date: 2010-12-04 16:46:20 UTC
  • mto: (2.1.3 experimental) (1.3.1)
  • mto: This revision was merged to the branch mainline in revision 69.
  • Revision ID: james.westby@ubuntu.com-20101204164620-h7p4t2e9z6hfhz6l
Tags: upstream-1.1.4
ImportĀ upstreamĀ versionĀ 1.1.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* $Id$ */
2
2
/*-
3
3
 * Copyright (c) 2006 Benedikt Meurer <benny@xfce.org>
 
4
 * Copyright (c) 2009 Jannis Pohlmann <jannis@xfce.org>
4
5
 *
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
32
33
#include <thunar/thunar-private.h>
33
34
#include <thunar/thunar-size-label.h>
34
35
#include <thunar/thunar-throbber.h>
 
36
#include <thunar/thunar-deep-count-job.h>
35
37
 
36
38
 
37
39
 
44
46
 
45
47
 
46
48
 
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,
51
51
                                                         guint                 prop_id,
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,
70
70
                                                         guint                 file_count,
71
71
                                                         guint                 directory_count,
83
83
 
84
84
struct _ThunarSizeLabel
85
85
{
86
 
  GtkHBox       __parent__;
87
 
  ThunarVfsJob *job;
88
 
 
89
 
  ThunarFile   *file;
90
 
 
91
 
  GtkWidget    *label;
92
 
  GtkWidget    *throbber;
 
86
  GtkHBox             __parent__;
 
87
 
 
88
  ThunarDeepCountJob *job;
 
89
 
 
90
  ThunarFile         *file;
 
91
 
 
92
  GtkWidget          *label;
 
93
  GtkWidget          *throbber;
93
94
 
94
95
  /* the throbber animation is started after a timeout */
95
 
  gint          animate_timer_id;
 
96
  gint                animate_timer_id;
96
97
};
97
98
 
98
99
 
99
100
 
100
 
static GObjectClass *thunar_size_label_parent_class;
101
 
 
102
 
 
103
 
 
104
 
GType
105
 
thunar_size_label_get_type (void)
106
 
{
107
 
  static GType type = G_TYPE_INVALID;
108
 
 
109
 
  if (G_UNLIKELY (type == G_TYPE_INVALID))
110
 
    {
111
 
      static const GTypeInfo info =
112
 
      {
113
 
        sizeof (ThunarSizeLabelClass),
114
 
        NULL,
115
 
        NULL,
116
 
        (GClassInitFunc) thunar_size_label_class_init,
117
 
        NULL,
118
 
        NULL,
119
 
        sizeof (ThunarSizeLabel),
120
 
        0,
121
 
        (GInstanceInitFunc) thunar_size_label_init,
122
 
        NULL,
123
 
      };
124
 
 
125
 
      type = g_type_register_static (GTK_TYPE_HBOX, I_("ThunarSizeLabel"), &info, 0);
126
 
    }
127
 
 
128
 
  return type;
129
 
}
 
101
G_DEFINE_TYPE (ThunarSizeLabel, thunar_size_label, GTK_TYPE_HBOX)
130
102
 
131
103
 
132
104
 
135
107
{
136
108
  GObjectClass *gobject_class;
137
109
 
138
 
  /* determine the parent type class */
139
 
  thunar_size_label_parent_class = g_type_class_peek_parent (klass);
140
 
 
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);
180
149
 
206
175
  if (G_UNLIKELY (size_label->job != NULL))
207
176
    {
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);
211
180
    }
212
181
 
213
182
  /* reset the file property */
284
253
      /* cancel the pending job (if any) */
285
254
      if (G_UNLIKELY (size_label->job != NULL))
286
255
        {
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;
291
260
        }
292
261
 
307
276
 
308
277
 
309
278
static gchar*
310
 
tsl_format_size_string (ThunarVfsFileSize size)
 
279
tsl_format_size_string (guint64 size)
311
280
{
312
281
  GString *result;
313
282
  gchar   *grouping;
356
325
thunar_size_label_file_changed (ThunarFile      *file,
357
326
                                ThunarSizeLabel *size_label)
358
327
{
359
 
  ThunarVfsFileSize size;
360
 
  GError           *error = NULL;
361
 
  gchar            *size_humanized;
362
 
  gchar            *size_string;
363
 
  gchar            *text;
 
328
  guint64 size;
 
329
  gchar  *size_humanized;
 
330
  gchar  *size_string;
 
331
  gchar  *text;
364
332
 
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))
375
343
    {
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;
380
348
    }
381
349
 
387
355
  if (thunar_file_is_directory (file))
388
356
    {
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))
392
 
        {
393
 
          /* display the error to the user */
394
 
          gtk_label_set_text (GTK_LABEL (size_label->label), error->message);
395
 
          g_error_free (error);
396
 
        }
397
 
      else
398
 
        {
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);
403
 
 
404
 
          /* tell the user that we started calculation */
405
 
          gtk_label_set_text (GTK_LABEL (size_label->label), _("Calculating..."));
406
 
        }
 
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);
 
362
 
 
363
      /* tell the user that we started calculation */
 
364
      gtk_label_set_text (GTK_LABEL (size_label->label), _("Calculating..."));
 
365
 
 
366
      /* launch the job */
 
367
      exo_job_launch (EXO_JOB (size_label->job));
407
368
    }
408
369
  else
409
370
    {
419
380
      if (G_LIKELY (size > 1024ul))
420
381
        {
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);
437
398
 
438
399
 
439
400
static void
440
 
thunar_size_label_error (ThunarVfsJob    *job,
 
401
thunar_size_label_error (ExoJob          *job,
441
402
                         const GError    *error,
442
403
                         ThunarSizeLabel *size_label)
443
404
{
 
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));
447
408
 
448
409
  /* setup the error text as label */
449
410
  gtk_label_set_text (GTK_LABEL (size_label->label), error->message);
452
413
 
453
414
 
454
415
static void
455
 
thunar_size_label_finished (ThunarVfsJob    *job,
 
416
thunar_size_label_finished (ExoJob          *job,
456
417
                            ThunarSizeLabel *size_label)
457
418
{
 
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));
461
422
 
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);
469
430
 
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;
474
435
}
475
436
 
476
437
 
477
438
 
478
439
static void
479
 
thunar_size_label_status_ready (ThunarVfsJob    *job,
480
 
                                guint64          total_size,
481
 
                                guint            file_count,
482
 
                                guint            directory_count,
483
 
                                guint            unreadable_directory_count,
484
 
                                ThunarSizeLabel *size_label)
 
440
thunar_size_label_status_update (ThunarDeepCountJob *job,
 
441
                                 guint64             total_size,
 
442
                                 guint               file_count,
 
443
                                 guint               directory_count,
 
444
                                 guint               unreadable_directory_count,
 
445
                                 ThunarSizeLabel    *size_label)
485
446
{
486
447
  gchar *size_string;
487
448
  gchar *text;
488
449
  guint  n;
489
450
 
 
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);
493
454
 
494
455
  /* check if the animate timer is already running */
503
464
  n = file_count + directory_count + unreadable_directory_count;
504
465
 
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);