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

« back to all changes in this revision

Viewing changes to src/client/folder-list/folder-list-folder-entry.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:
 
1
/* Copyright 2011-2012 Yorba Foundation
 
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
// A folder of any type in the folder list.
 
8
public class FolderList.FolderEntry : Object, Sidebar.Entry, Sidebar.InternalDropTargetEntry,
 
9
    Sidebar.SelectableEntry, Sidebar.EmphasizableEntry {
 
10
    public Geary.Folder folder { get; private set; }
 
11
    private bool has_new;
 
12
    private int unread_count;
 
13
    
 
14
    public FolderEntry(Geary.Folder folder) {
 
15
        this.folder = folder;
 
16
        has_new = false;
 
17
        unread_count = 0;
 
18
    }
 
19
    
 
20
    public virtual string get_sidebar_name() {
 
21
        return (unread_count == 0 ? folder.get_display_name() :
 
22
            /// This string gets the folder name and the unread messages count,
 
23
            /// e.g. All Mail (5).
 
24
            _("%s (%d)").printf(folder.get_display_name(), unread_count));
 
25
    }
 
26
    
 
27
    public string? get_sidebar_tooltip() {
 
28
        return (unread_count == 0 ? null :
 
29
            ngettext("%d unread message", "%d unread messages", unread_count).printf(unread_count));
 
30
    }
 
31
    
 
32
    public Icon? get_sidebar_icon() {
 
33
        switch (folder.get_special_folder_type()) {
 
34
            case Geary.SpecialFolderType.NONE:
 
35
                return IconFactory.instance.get_custom_icon("tag", IconFactory.ICON_SIDEBAR);
 
36
            
 
37
            case Geary.SpecialFolderType.INBOX:
 
38
                return new ThemedIcon("mail-inbox");
 
39
            
 
40
            case Geary.SpecialFolderType.DRAFTS:
 
41
                return new ThemedIcon("accessories-text-editor");
 
42
            
 
43
            case Geary.SpecialFolderType.SENT:
 
44
                return new ThemedIcon("mail-sent");
 
45
            
 
46
            case Geary.SpecialFolderType.FLAGGED:
 
47
                return new ThemedIcon("starred");
 
48
            
 
49
            case Geary.SpecialFolderType.IMPORTANT:
 
50
                return new ThemedIcon("task-due");
 
51
            
 
52
            case Geary.SpecialFolderType.ALL_MAIL:
 
53
                return IconFactory.instance.get_custom_icon("mail-archive", IconFactory.ICON_SIDEBAR);
 
54
            
 
55
            case Geary.SpecialFolderType.SPAM:
 
56
                return new ThemedIcon("mail-mark-junk");
 
57
            
 
58
            case Geary.SpecialFolderType.TRASH:
 
59
                return new ThemedIcon("user-trash");
 
60
            
 
61
            case Geary.SpecialFolderType.OUTBOX:
 
62
                return new ThemedIcon("mail-outbox");
 
63
            
 
64
            default:
 
65
                assert_not_reached();
 
66
        }
 
67
    }
 
68
    
 
69
    public virtual string to_string() {
 
70
        return "FolderEntry: " + get_sidebar_name();
 
71
    }
 
72
    
 
73
    public bool is_emphasized() {
 
74
        return has_new;
 
75
    }
 
76
    
 
77
    public void set_has_new(bool has_new) {
 
78
        if (this.has_new == has_new)
 
79
            return;
 
80
        
 
81
        this.has_new = has_new;
 
82
        is_emphasized_changed(has_new);
 
83
    }
 
84
    
 
85
    public void set_unread_count(int unread_count) {
 
86
        if (this.unread_count == unread_count)
 
87
            return;
 
88
        
 
89
        this.unread_count = unread_count;
 
90
        sidebar_name_changed(get_sidebar_name());
 
91
        sidebar_tooltip_changed(get_sidebar_tooltip());
 
92
    }
 
93
 
 
94
    public bool internal_drop_received(Gdk.DragContext context, Gtk.SelectionData data) {
 
95
        // Copy or move?
 
96
        Gdk.ModifierType mask;
 
97
        double[] axes = new double[2];
 
98
        context.get_device().get_state(context.get_dest_window(), axes, out mask);
 
99
        MainWindow main_window = GearyApplication.instance.get_main_window() as MainWindow;
 
100
        if ((mask & Gdk.ModifierType.CONTROL_MASK) != 0) {
 
101
            main_window.folder_list.copy_conversation(folder);
 
102
        } else {
 
103
            main_window.folder_list.move_conversation(folder);
 
104
        }
 
105
 
 
106
        return true;
 
107
    }
 
108
}