~hkdb/geary/disco-3.34.1

« back to all changes in this revision

Viewing changes to src/engine/api/geary-aggregated-folder-properties.vala

  • Committer: hkdb
  • Date: 2019-10-08 10:54:21 UTC
  • Revision ID: hkdb@3df.io-20191008105421-3dkwnpnhcamm77to
Tags: upstream-3.34.1-disco
ImportĀ upstreamĀ versionĀ 3.34.1-disco

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2016 Software Freedom Conservancy Inc.
 
2
 *
 
3
 * This software is licensed under the GNU Lesser General Public License
 
4
 * (version 2.1 or later).  See the COPYING file in this distribution.
 
5
 */
 
6
 
 
7
/**
 
8
 * Aggregates multiple FolderProperties into one.  This way a Geary.Folder can
 
9
 * present one stable FolderProperties object that the client can register
 
10
 * change listeners on, etc. despite most Geary.Folders having both a local
 
11
 * and remote version of FolderProperties.
 
12
 *
 
13
 * The class relies on GObject bindings and the fact that FolderProperties
 
14
 * contains only propertiess.
 
15
 */
 
16
private class Geary.AggregatedFolderProperties : Geary.FolderProperties {
 
17
    // Map of child FolderProperties to their bindings.
 
18
    private Gee.Map<FolderProperties, Gee.List<Binding>> child_bindings
 
19
        = new Gee.HashMap<FolderProperties, Gee.List<Binding>>();
 
20
 
 
21
    /**
 
22
     * Creates an aggregate FolderProperties.
 
23
     */
 
24
    public AggregatedFolderProperties(bool is_local_only, bool is_virtual) {
 
25
        // Set defaults.
 
26
        base(0, 0, Trillian.UNKNOWN, Trillian.UNKNOWN, Trillian.UNKNOWN, is_local_only, is_virtual, false);
 
27
    }
 
28
 
 
29
    /**
 
30
     * Adds a child FolderProperties.  The child's property values will overwrite
 
31
     * this class's property values.
 
32
     */
 
33
    public void add(FolderProperties child) {
 
34
        // Create a binding for all properties.
 
35
        Gee.List<Binding>? bindings = Geary.ObjectUtils.mirror_properties(child, this);
 
36
        assert(bindings != null);
 
37
        child_bindings.set(child, bindings);
 
38
    }
 
39
 
 
40
    /**
 
41
     * Removes a child FolderProperties.
 
42
     */
 
43
    public bool remove(FolderProperties child) {
 
44
        Gee.List<Binding> bindings;
 
45
        if (child_bindings.unset(child, out bindings)) {
 
46
            Geary.ObjectUtils.unmirror_properties(bindings);
 
47
 
 
48
            return true;
 
49
        }
 
50
 
 
51
        return false;
 
52
    }
 
53
}
 
54