summaryrefslogtreecommitdiff
path: root/src/library/LastImportPage.vala
blob: ea9045cd67ca7095c7b53e53e0f75a1cd6a1d918 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* Copyright 2010-2015 Yorba Foundation
 *
 * This software is licensed under the GNU Lesser General Public License
 * (version 2.1 or later).  See the COPYING file in this distribution.
 */

public class LastImportPage : CollectionPage {
    public const string NAME = _("Last Import");
    
    private class LastImportViewManager : CollectionViewManager {
        private ImportID import_id;
        
        public LastImportViewManager(LastImportPage owner, ImportID import_id) {
            base (owner);
            
            this.import_id = import_id;
        }
        
        public override bool include_in_view(DataSource source) {
            return ((MediaSource) source).get_import_id().id == import_id.id;
        }
    }
    
    private ImportID last_import_id = ImportID();
    private Alteration last_import_alteration = new Alteration("metadata", "import-id");
    
    public LastImportPage() {
        base (NAME);
        
        // be notified when the import rolls change
        foreach (MediaSourceCollection col in MediaCollectionRegistry.get_instance().get_all()) {
            col.import_roll_altered.connect(on_import_rolls_altered);
        }
        
        // set up view manager for the last import roll
        on_import_rolls_altered();
    }
    
    ~LastImportPage() {
        foreach (MediaSourceCollection col in MediaCollectionRegistry.get_instance().get_all()) {
            col.import_roll_altered.disconnect(on_import_rolls_altered);
        }
    }
    
    private void on_import_rolls_altered() {
        // see if there's a new last ImportID, or no last import at all
        ImportID? current_last_import_id =
            MediaCollectionRegistry.get_instance().get_last_import_id();

        if (current_last_import_id == null) {
            get_view().halt_all_monitoring();
            get_view().clear();
            
            return;
        }
        
        if (current_last_import_id.id == last_import_id.id)
            return;
        
        last_import_id = current_last_import_id;
        
        get_view().halt_all_monitoring();
        get_view().clear();
        
        foreach (MediaSourceCollection col in MediaCollectionRegistry.get_instance().get_all()) {
            get_view().monitor_source_collection(col, new LastImportViewManager(this,
                last_import_id), last_import_alteration);
        }
    }
    
    protected override void get_config_photos_sort(out bool sort_order, out int sort_by) {
        Config.Facade.get_instance().get_library_photos_sort(out sort_order, out sort_by);
    }
    
    protected override void set_config_photos_sort(bool sort_order, int sort_by) {
        Config.Facade.get_instance().set_library_photos_sort(sort_order, sort_by);
    }
}