~ubuntu-branches/ubuntu/saucy/geary/saucy-updates

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Sebastien Bacher
  • Date: 2013-03-14 13:48:23 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20130314134823-gyk5av1g508zyj8a
Tags: 0.3.0~pr1-0ubuntu1
New upstream version (FFE lp: #1154316), supports multiple account as
well as full conversation views with inline replies

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 * (version 2.1 or later).  See the COPYING file in this distribution. 
5
5
 */
6
6
 
7
 
public class Geary.Imap.FolderProperties {
8
 
    // messages can be updated a variety of ways, so it's available as a public set
9
 
    public int messages { get; set; }
 
7
public class Geary.Imap.FolderProperties : Geary.FolderProperties {
 
8
    /**
 
9
     * -1 if the Folder was not opened via SELECT or EXAMINE.
 
10
     */
 
11
    public int select_examine_messages { get; private set; }
 
12
    /**
 
13
     * -1 if the FolderProperties were not obtained via a STATUS command
 
14
     */
 
15
    public int status_messages { get; private set; }
 
16
    public int unseen { get; private set; }
10
17
    public int recent { get; private set; }
11
 
    public int unseen { get; private set; }
12
18
    public UIDValidity? uid_validity { get; private set; }
13
19
    public UID? uid_next { get; private set; }
14
20
    public MailboxAttributes attrs { get; private set; }
15
 
    public Trillian supports_children { get; private set; }
16
 
    public Trillian has_children { get; private set; }
17
 
    public Trillian is_openable { get; private set; }
18
21
    
 
22
    // Note that unseen from SELECT/EXAMINE is the *position* of the first unseen message,
 
23
    // not the total unseen count, so it should not be passed in here, but rather the unseen
 
24
    // count from a STATUS command
19
25
    public FolderProperties(int messages, int recent, int unseen, UIDValidity? uid_validity,
20
26
        UID? uid_next, MailboxAttributes attrs) {
21
 
        this.messages = messages;
 
27
        base (messages, unseen, Trillian.UNKNOWN, Trillian.UNKNOWN, Trillian.UNKNOWN);
 
28
        
 
29
        select_examine_messages = messages;
 
30
        status_messages = -1;
22
31
        this.recent = recent;
23
32
        this.unseen = unseen;
24
33
        this.uid_validity = uid_validity;
29
38
    }
30
39
    
31
40
    public FolderProperties.status(StatusResults status, MailboxAttributes attrs) {
32
 
        messages = status.messages;
 
41
        base (status.messages, status.unseen, Trillian.UNKNOWN, Trillian.UNKNOWN, Trillian.UNKNOWN);
 
42
        
 
43
        select_examine_messages = -1;
 
44
        status_messages = status.messages;
33
45
        recent = status.recent;
34
46
        unseen = status.unseen;
35
47
        uid_validity = status.uid_validity;
39
51
        init_flags();
40
52
    }
41
53
    
 
54
    /**
 
55
     * Use with FolderProperties of the *same folder* seen at different times (i.e. after SELECTing
 
56
     * versus data stored locally).  Only compares fields that suggest the contents of the folder
 
57
     * have changed.
 
58
     *
 
59
     * Note that this is *not* concerned with message flags changing.
 
60
     */
 
61
    public Trillian have_contents_changed(Geary.Imap.FolderProperties other) {
 
62
        // UIDNEXT changes indicate messages have been added, but not if they've been removed
 
63
        if (uid_next != null && other.uid_next != null && !uid_next.equals(other.uid_next))
 
64
            return Trillian.TRUE;
 
65
        
 
66
        // Gmail includes Chat messages in STATUS results but not in SELECT/EXAMINE
 
67
        // results, so message count comparison has to be from the same origin ... use SELECT/EXAMINE
 
68
        // first, as it's more authoritative in many ways
 
69
        //
 
70
        // TODO: If this continues to work, it might be worthwhile to change the result of this
 
71
        // method to boolean
 
72
        if (select_examine_messages >= 0 && other.select_examine_messages >= 0
 
73
            && select_examine_messages != other.select_examine_messages) {
 
74
            return Trillian.TRUE;
 
75
        }
 
76
        
 
77
        if (status_messages >= 0 && other.status_messages >= 0 && status_messages != other.status_messages) {
 
78
            return Trillian.TRUE;
 
79
        }
 
80
        
 
81
        return Trillian.FALSE;
 
82
    }
 
83
    
42
84
    private void init_flags() {
43
85
        supports_children = Trillian.from_boolean(!attrs.contains(MailboxAttribute.NO_INFERIORS));
 
86
        
44
87
        // \HasNoChildren & \HasChildren are optional attributes (could check for CHILDREN extension,
45
88
        // but unnecessary here)
46
89
        if (attrs.contains(MailboxAttribute.HAS_NO_CHILDREN))
49
92
            has_children = Trillian.TRUE;
50
93
        else
51
94
            has_children = Trillian.UNKNOWN;
 
95
        
52
96
        is_openable = Trillian.from_boolean(!attrs.contains(MailboxAttribute.NO_SELECT));
53
97
    }
 
98
    
 
99
    public void set_status_message_count(int messages, bool force) {
 
100
        if (messages < 0)
 
101
            return;
 
102
        
 
103
        status_messages = messages;
 
104
        
 
105
        // select/examine more authoritative than status, unless the caller knows otherwise
 
106
        if (force || (select_examine_messages < 0))
 
107
            email_total = messages;
 
108
    }
 
109
    
 
110
    public void set_select_examine_message_count(int messages) {
 
111
        if (messages < 0)
 
112
            return;
 
113
        
 
114
        select_examine_messages = messages;
 
115
        
 
116
        // select/examine more authoritative than status
 
117
        email_total = messages;
 
118
    }
54
119
}
55
120