~pantheon-photos/pantheon-photos/trunk

« back to all changes in this revision

Viewing changes to src/MediaPage.vala

  • Committer: RabbitBot
  • Author(s): madelynn-r-may
  • Date: 2014-08-28 07:36:20 UTC
  • mfrom: (2600.3.1 pantheon-photos)
  • Revision ID: rabbitbot-20140828073620-72azpf8q3xnq1614
changes context menu rating stuff to a rating widget

Show diffs side-by-side

added added

removed removed

Lines of Context:
333
333
        rate_rejected.label = Resources.rating_menu (Rating.REJECTED);
334
334
        actions += rate_rejected;
335
335
 
336
 
        Gtk.ActionEntry rate_unrated = { "RateUnrated", null, TRANSLATABLE,
337
 
                                         "0", TRANSLATABLE, on_rate_unrated
338
 
                                       };
339
 
        rate_unrated.label = Resources.rating_menu (Rating.UNRATED);
340
 
        actions += rate_unrated;
341
 
 
342
 
        Gtk.ActionEntry rate_one = { "RateOne", null, TRANSLATABLE,
343
 
                                     "1", TRANSLATABLE, on_rate_one
344
 
                                   };
345
 
        rate_one.label = Resources.rating_menu (Rating.ONE);
346
 
        actions += rate_one;
347
 
 
348
 
        Gtk.ActionEntry rate_two = { "RateTwo", null, TRANSLATABLE,
349
 
                                     "2", TRANSLATABLE, on_rate_two
350
 
                                   };
351
 
        rate_two.label = Resources.rating_menu (Rating.TWO);
352
 
        actions += rate_two;
353
 
 
354
 
        Gtk.ActionEntry rate_three = { "RateThree", null, TRANSLATABLE,
355
 
                                       "3", TRANSLATABLE, on_rate_three
356
 
                                     };
357
 
        rate_three.label = Resources.rating_menu (Rating.THREE);
358
 
        actions += rate_three;
359
 
 
360
 
        Gtk.ActionEntry rate_four = { "RateFour", null, TRANSLATABLE,
361
 
                                      "4", TRANSLATABLE, on_rate_four
362
 
                                    };
363
 
        rate_four.label = Resources.rating_menu (Rating.FOUR);
364
 
        actions += rate_four;
365
 
 
366
 
        Gtk.ActionEntry rate_five = { "RateFive", null, TRANSLATABLE,
367
 
                                      "5", TRANSLATABLE, on_rate_five
368
 
                                    };
369
 
        rate_five.label = Resources.rating_menu (Rating.FIVE);
370
 
        actions += rate_five;
371
 
 
372
336
        Gtk.ActionEntry sort_photos = { "SortPhotos", null, TRANSLATABLE, null, null, null };
373
337
        sort_photos.label = _ ("Sort _Photos");
374
338
        actions += sort_photos;
523
487
        }
524
488
    }
525
489
 
526
 
    private void update_rating_sensitivities () {
527
 
        set_action_sensitive ("RateRejected", can_rate_selected (Rating.REJECTED));
528
 
        set_action_sensitive ("RateUnrated", can_rate_selected (Rating.UNRATED));
529
 
        set_action_sensitive ("RateOne", can_rate_selected (Rating.ONE));
530
 
        set_action_sensitive ("RateTwo", can_rate_selected (Rating.TWO));
531
 
        set_action_sensitive ("RateThree", can_rate_selected (Rating.THREE));
532
 
        set_action_sensitive ("RateFour", can_rate_selected (Rating.FOUR));
533
 
        set_action_sensitive ("RateFive", can_rate_selected (Rating.FIVE));
 
490
    protected void update_rating_sensitivities () {
 
491
        if (rating_menu_item != null) {
 
492
            rating_menu_item.sensitive =  can_rate_selected ();
 
493
            rating_menu_item.rating_value = Resources.int_to_rating (get_selected_rating ());
 
494
        }
534
495
        set_action_sensitive ("IncreaseRating", can_increase_selected_rating ());
535
496
        set_action_sensitive ("DecreaseRating", can_decrease_selected_rating ());
536
497
    }
537
498
 
 
499
    protected override void on_rating_widget_activate () {
 
500
        on_set_rating (Resources.int_to_rating(rating_menu_item.rating_value));
 
501
    }
 
502
 
538
503
    private void update_development_menu_item_sensitivity () {
539
504
        if (get_view ().get_selected ().size == 0) {
540
505
            set_action_sensitive ("RawDeveloper", false);
614
579
            action.set_active (display);
615
580
    }
616
581
 
617
 
    private bool can_rate_selected (Rating rating) {
 
582
    private bool can_rate_selected () {
 
583
        return get_view ().get_selected ().size > 0;
 
584
    }
 
585
 
 
586
    private Rating get_selected_rating () {
 
587
        bool init = false;
 
588
        Rating last_rating = Rating.UNRATED;
618
589
        foreach (DataView view in get_view ().get_selected ()) {
619
 
            if (((Thumbnail) view).get_media_source ().get_rating () != rating)
620
 
                return true;
 
590
            var rating = ((Thumbnail) view).get_media_source ().get_rating ();
 
591
            if (!init)
 
592
                init = true;
 
593
            else if (last_rating != rating)
 
594
                return Rating.UNRATED;
 
595
            last_rating = rating;
621
596
        }
622
 
 
623
 
        return false;
 
597
        return last_rating;
624
598
    }
625
599
 
626
600
    private bool can_increase_selected_rating () {
702
676
            activate_action ("DecreaseRating");
703
677
            break;
704
678
 
705
 
        case "KP_1":
706
 
            activate_action ("RateOne");
707
 
            break;
708
 
 
709
 
        case "KP_2":
710
 
            activate_action ("RateTwo");
711
 
            break;
712
 
 
713
 
        case "KP_3":
714
 
            activate_action ("RateThree");
715
 
            break;
716
 
 
717
 
        case "KP_4":
718
 
            activate_action ("RateFour");
719
 
            break;
720
 
 
721
 
        case "KP_5":
722
 
            activate_action ("RateFive");
723
 
            break;
724
 
 
725
 
        case "KP_0":
726
 
            activate_action ("RateUnrated");
727
 
            break;
728
 
 
729
 
        case "KP_9":
 
679
        case "1":
 
680
            on_set_rating (Rating.ONE);
 
681
            break;
 
682
 
 
683
        case "2":
 
684
            on_set_rating (Rating.TWO);
 
685
            break;
 
686
 
 
687
        case "3":
 
688
            on_set_rating (Rating.THREE);
 
689
            break;
 
690
 
 
691
        case "4":
 
692
            on_set_rating (Rating.FOUR);
 
693
            break;
 
694
 
 
695
        case "5":
 
696
            on_set_rating (Rating.FIVE);    
 
697
            break;
 
698
 
 
699
        case "0":
 
700
            on_set_rating (Rating.UNRATED);
 
701
            break;
 
702
 
 
703
        case "9":
730
704
            activate_action ("RateRejected");
731
705
            break;
732
706
 
920
894
        on_set_rating (Rating.REJECTED);
921
895
    }
922
896
 
923
 
    protected virtual void on_rate_unrated () {
924
 
        on_set_rating (Rating.UNRATED);
925
 
    }
926
 
 
927
 
    protected virtual void on_rate_one () {
928
 
        on_set_rating (Rating.ONE);
929
 
    }
930
 
 
931
 
    protected virtual void on_rate_two () {
932
 
        on_set_rating (Rating.TWO);
933
 
    }
934
 
 
935
 
    protected virtual void on_rate_three () {
936
 
        on_set_rating (Rating.THREE);
937
 
    }
938
 
 
939
 
    protected virtual void on_rate_four () {
940
 
        on_set_rating (Rating.FOUR);
941
 
    }
942
 
 
943
 
    protected virtual void on_rate_five () {
944
 
        on_set_rating (Rating.FIVE);
945
 
    }
946
 
 
947
897
    private void on_remove_from_library () {
948
898
        remove_photos_from_library ((Gee.Collection<LibraryPhoto>) get_view ().get_selected_sources ());
949
899
    }