~ubuntu-branches/ubuntu/trusty/unity-place-files/trusty

« back to all changes in this revision

Viewing changes to src/utils.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2010-08-26 18:52:52 UTC
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20100826185252-rtxst6inf3chd7po
Tags: upstream-0.5.18
ImportĀ upstreamĀ versionĀ 0.5.18

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* utils.c generated by valac 0.9.6, the Vala compiler
 
1
/* utils.c generated by valac 0.9.7, the Vala compiler
2
2
 * generated from utils.vala, do not modify */
3
3
 
4
4
/*
25
25
#include <stdlib.h>
26
26
#include <string.h>
27
27
#include <gio/gio.h>
 
28
#include <glib/gi18n-lib.h>
28
29
#include <zeitgeist.h>
29
30
#include <dee.h>
30
31
#include <gee.h>
112
113
static gboolean unity_files_place_utils_get_icon_for_uri_async_co (UnityFilesPlaceUtilsGetIconForUriAsyncData* data);
113
114
gint unity_files_place_utils_cmp_file_info_by_mtime (GFileInfo* info1, GFileInfo* info2);
114
115
char* unity_files_place_utils_get_month_name (GDateMonth month);
115
 
guint unity_files_place_utils_get_time_group (ZeitgeistEvent* event, DeeModel* groups_model);
 
116
char* unity_files_place_utils_get_day_name (GDateWeekday weekday);
 
117
guint unity_files_place_utils_get_time_group (ZeitgeistEvent* event, DeeModel* groups_model, char** comment);
116
118
GType unity_files_place_group_get_type (void) G_GNUC_CONST;
117
119
static void _g_slist_free_g_object_unref (GSList* self);
118
120
static void unity_files_place_utils_list_dir_data_free (gpointer _data);
353
355
        switch (month) {
354
356
                case G_DATE_BAD_MONTH:
355
357
                {
356
 
                        result = g_strdup ("Invalid Month");
 
358
                        result = g_strdup (_ ("Invalid Month"));
357
359
                        return result;
358
360
                }
359
361
                case G_DATE_JANUARY:
360
362
                {
361
 
                        result = g_strdup ("January");
 
363
                        result = g_strdup (_ ("January"));
362
364
                        return result;
363
365
                }
364
366
                case G_DATE_FEBRUARY:
365
367
                {
366
 
                        result = g_strdup ("February");
 
368
                        result = g_strdup (_ ("February"));
367
369
                        return result;
368
370
                }
369
371
                case G_DATE_MARCH:
370
372
                {
371
 
                        result = g_strdup ("March");
 
373
                        result = g_strdup (_ ("March"));
372
374
                        return result;
373
375
                }
374
376
                case G_DATE_APRIL:
375
377
                {
376
 
                        result = g_strdup ("April");
 
378
                        result = g_strdup (_ ("April"));
377
379
                        return result;
378
380
                }
379
381
                case G_DATE_MAY:
380
382
                {
381
 
                        result = g_strdup ("May");
 
383
                        result = g_strdup (_ ("May"));
382
384
                        return result;
383
385
                }
384
386
                case G_DATE_JUNE:
385
387
                {
386
 
                        result = g_strdup ("June");
 
388
                        result = g_strdup (_ ("June"));
387
389
                        return result;
388
390
                }
389
391
                case G_DATE_JULY:
390
392
                {
391
 
                        result = g_strdup ("July");
 
393
                        result = g_strdup (_ ("July"));
392
394
                        return result;
393
395
                }
394
396
                case G_DATE_AUGUST:
395
397
                {
396
 
                        result = g_strdup ("August");
 
398
                        result = g_strdup (_ ("August"));
397
399
                        return result;
398
400
                }
399
401
                case G_DATE_SEPTEMBER:
400
402
                {
401
 
                        result = g_strdup ("September");
 
403
                        result = g_strdup (_ ("September"));
402
404
                        return result;
403
405
                }
404
406
                case G_DATE_OCTOBER:
405
407
                {
406
 
                        result = g_strdup ("October");
 
408
                        result = g_strdup (_ ("October"));
407
409
                        return result;
408
410
                }
409
411
                case G_DATE_NOVEMBER:
410
412
                {
411
 
                        result = g_strdup ("November");
 
413
                        result = g_strdup (_ ("November"));
412
414
                        return result;
413
415
                }
414
416
                case G_DATE_DECEMBER:
415
417
                {
416
 
                        result = g_strdup ("December");
 
418
                        result = g_strdup (_ ("December"));
417
419
                        return result;
418
420
                }
419
421
        }
422
424
}
423
425
 
424
426
 
425
 
guint unity_files_place_utils_get_time_group (ZeitgeistEvent* event, DeeModel* groups_model) {
 
427
char* unity_files_place_utils_get_day_name (GDateWeekday weekday) {
 
428
        char* result = NULL;
 
429
        switch (weekday) {
 
430
                case G_DATE_MONDAY:
 
431
                {
 
432
                        result = g_strdup (_ ("Monday"));
 
433
                        return result;
 
434
                }
 
435
                case G_DATE_TUESDAY:
 
436
                {
 
437
                        result = g_strdup (_ ("Tuesday"));
 
438
                        return result;
 
439
                }
 
440
                case G_DATE_WEDNESDAY:
 
441
                {
 
442
                        result = g_strdup (_ ("Wednesday"));
 
443
                        return result;
 
444
                }
 
445
                case G_DATE_THURSDAY:
 
446
                {
 
447
                        result = g_strdup (_ ("Thursday"));
 
448
                        return result;
 
449
                }
 
450
                case G_DATE_FRIDAY:
 
451
                {
 
452
                        result = g_strdup (_ ("Friday"));
 
453
                        return result;
 
454
                }
 
455
                case G_DATE_SATURDAY:
 
456
                {
 
457
                        result = g_strdup (_ ("Saturday"));
 
458
                        return result;
 
459
                }
 
460
                case G_DATE_SUNDAY:
 
461
                {
 
462
                        result = g_strdup (_ ("Sunday"));
 
463
                        return result;
 
464
                }
 
465
                default:
 
466
                {
 
467
                        result = g_strdup ("Internal Error");
 
468
                        return result;
 
469
                }
 
470
        }
 
471
}
 
472
 
 
473
 
 
474
guint unity_files_place_utils_get_time_group (ZeitgeistEvent* event, DeeModel* groups_model, char** comment) {
426
475
        guint result = 0U;
427
476
        gint64 t;
428
477
        gint64 now;
 
478
        gint64 delta;
 
479
        char* _tmp0_;
 
480
        char* _tmp1_;
 
481
        char* _tmp2_;
 
482
        char* _tmp3_;
429
483
        gint64 limit;
430
484
        GDate date = {0};
 
485
        GDate datethen = {0};
 
486
        char* _tmp12_;
 
487
        char* _tmp15_;
431
488
        g_return_val_if_fail (event != NULL, 0U);
432
489
        g_return_val_if_fail (groups_model != NULL, 0U);
 
490
        if (comment != NULL) {
 
491
                *comment = NULL;
 
492
        }
433
493
        t = zeitgeist_event_get_timestamp (event);
434
494
        now = zeitgeist_timestamp_for_now ();
 
495
        delta = now - t;
 
496
        g_debug ("utils.vala:169: %s", _tmp3_ = g_strconcat ("DELTA: ", _tmp0_ = g_strdup_printf ("%" G_GINT64_FORMAT, now), " - ", _tmp1_ = g_strdup_printf ("%" G_GINT64_FORMAT, t), " = ", _tmp2_ = g_strdup_printf ("%" G_GINT64_FORMAT, delta), NULL));
 
497
        _g_free0 (_tmp3_);
 
498
        _g_free0 (_tmp2_);
 
499
        _g_free0 (_tmp1_);
 
500
        _g_free0 (_tmp0_);
435
501
        limit = zeitgeist_timestamp_prev_midnight (now);
436
502
        if (t > limit) {
 
503
                gint64 hour;
 
504
                hour = ZEITGEIST_TIMESTAMP_HOUR;
 
505
                if (delta > (hour * 7)) {
 
506
                        char* _tmp4_;
 
507
                        *comment = (_tmp4_ = g_strdup (_ ("Earlier today")), _g_free0 (*comment), _tmp4_);
 
508
                } else {
 
509
                        if (delta > (hour * 6)) {
 
510
                                char* _tmp5_;
 
511
                                *comment = (_tmp5_ = g_strdup (_ ("Five hours ago")), _g_free0 (*comment), _tmp5_);
 
512
                        } else {
 
513
                                if (delta > (hour * 5)) {
 
514
                                        char* _tmp6_;
 
515
                                        *comment = (_tmp6_ = g_strdup (_ ("Four hours ago")), _g_free0 (*comment), _tmp6_);
 
516
                                } else {
 
517
                                        if (delta > (hour * 4)) {
 
518
                                                char* _tmp7_;
 
519
                                                *comment = (_tmp7_ = g_strdup (_ ("Three hours ago")), _g_free0 (*comment), _tmp7_);
 
520
                                        } else {
 
521
                                                if (delta > (hour * 3)) {
 
522
                                                        char* _tmp8_;
 
523
                                                        *comment = (_tmp8_ = g_strdup (_ ("Two hours ago")), _g_free0 (*comment), _tmp8_);
 
524
                                                } else {
 
525
                                                        if (delta > (hour * 2)) {
 
526
                                                                char* _tmp9_;
 
527
                                                                *comment = (_tmp9_ = g_strdup (_ ("1 hour ago")), _g_free0 (*comment), _tmp9_);
 
528
                                                        } else {
 
529
                                                                char* _tmp10_;
 
530
                                                                *comment = (_tmp10_ = g_strdup (_ ("Past hour")), _g_free0 (*comment), _tmp10_);
 
531
                                                        }
 
532
                                                }
 
533
                                        }
 
534
                                }
 
535
                        }
 
536
                }
437
537
                result = (guint) UNITY_FILES_PLACE_GROUP_TODAY;
438
538
                return result;
439
539
        } else {
440
540
                if (t > (limit - ZEITGEIST_TIMESTAMP_DAY)) {
 
541
                        char* _tmp11_;
 
542
                        *comment = (_tmp11_ = g_strdup (_ ("Yesterday")), _g_free0 (*comment), _tmp11_);
441
543
                        result = (guint) UNITY_FILES_PLACE_GROUP_YESTERDAY;
442
544
                        return result;
443
545
                }
445
547
        memset (&date, 0, sizeof (GDate));
446
548
        zeitgeist_timestamp_to_date (now, &date);
447
549
        limit = limit - ((g_date_get_weekday (&date) - 1) * ZEITGEIST_TIMESTAMP_DAY);
 
550
        memset (&datethen, 0, sizeof (GDate));
 
551
        zeitgeist_timestamp_to_date (t, &datethen);
 
552
        *comment = (_tmp12_ = unity_files_place_utils_get_day_name (g_date_get_weekday (&datethen)), _g_free0 (*comment), _tmp12_);
448
553
        if (t > limit) {
449
554
                result = (guint) UNITY_FILES_PLACE_GROUP_THIS_WEEK;
450
555
                return result;
457
562
        g_date_set_day (&date, (GDateDay) 1);
458
563
        limit = zeitgeist_timestamp_from_date (&date);
459
564
        if (t > limit) {
 
565
                gint days;
 
566
                days = g_date_days_between (&datethen, &date);
 
567
                if (days < (7 * 3)) {
 
568
                        char* _tmp13_;
 
569
                        *comment = (_tmp13_ = g_strdup (_ ("Three weeks ago")), _g_free0 (*comment), _tmp13_);
 
570
                } else {
 
571
                        if (days < (7 * 4)) {
 
572
                                char* _tmp14_;
 
573
                                *comment = (_tmp14_ = g_strdup (_ ("A month ago")), _g_free0 (*comment), _tmp14_);
 
574
                        }
 
575
                }
460
576
                result = (guint) UNITY_FILES_PLACE_GROUP_THIS_MONTH;
461
577
                return result;
462
578
        }
 
579
        *comment = (_tmp15_ = unity_files_place_utils_get_month_name (g_date_get_month (&datethen)), _g_free0 (*comment), _tmp15_);
463
580
        g_date_subtract_months (&date, (guint) 1);
464
581
        limit = zeitgeist_timestamp_from_date (&date);
465
582
        if (t > (now - ((6 * 30) * ZEITGEIST_TIMESTAMP_DAY))) {
655
772
                        if (!gee_collection_contains ((GeeCollection*) valid_uris, uri)) {
656
773
                                dee_model_remove (model, row);
657
774
                                n_removed++;
658
 
                                g_debug ("utils.vala:230: Removed: %s", uri);
 
775
                                g_debug ("utils.vala:303: Removed: %s", uri);
659
776
                        }
660
777
                }
661
778
                _g_object_unref0 (_row_it);
662
779
        }
663
780
        if (n_removed > 0) {
664
 
                g_debug ("utils.vala:235: Removed %u rows from result set", n_removed);
 
781
                g_debug ("utils.vala:308: Removed %u rows from result set", n_removed);
665
782
        }
666
783
        _g_free0 (uri);
667
784
        _g_object_unref0 (model);