summaryrefslogtreecommitdiff
path: root/src/library/OfflineSidebarEntry.vala
blob: 34c09a03a446f66dc31f3777896cfb04dfa82d2f (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
/* Copyright 2011-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 Library.OfflineSidebarEntry : Library.HideablePageEntry {
    public OfflineSidebarEntry() {
        
        foreach (MediaSourceCollection media_sources in MediaCollectionRegistry.get_instance().get_all())
            media_sources.offline_contents_altered.connect(on_offline_contents_altered);
        
        visible = (get_total_offline() != 0);
    }

    ~OfflineSidebarEntry() {
        foreach (MediaSourceCollection media_sources in MediaCollectionRegistry.get_instance().get_all())
            media_sources.trashcan_contents_altered.disconnect(on_offline_contents_altered);
    }
    
    private void on_offline_contents_altered() {
        visible = (get_total_offline() != 0);
    }
    
    private int get_total_offline() {
        int total = 0;
        foreach (MediaSourceCollection media_sources in MediaCollectionRegistry.get_instance().get_all())
            total += media_sources.get_offline_bin_contents().size;
        
        return total;
    }
    
    public override string get_sidebar_name() {
        return OfflinePage.NAME;
    }
    
    public override string? get_sidebar_icon() {
        return Resources.ICON_MISSING_FILES;
    }
    
    protected override Page create_page() {
        return new OfflinePage();
    }
}