~jeremywootten/pantheon-files/fix-1604300-merge-find-functionalities-part1

« back to all changes in this revision

Viewing changes to src/View/Widgets/PermissionButton.vala

  • Committer: Jeremy Wootten
  • Date: 2017-01-13 13:31:06 UTC
  • mfrom: (2412.1.32 pantheon-files)
  • Revision ID: jeremy@elementaryos.org-20170113133106-v9l164ms13lh3p0a
Merge trunk to r2444 and resolve conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
* Copyright (c) 2016 elementary LLC. (http://launchpad.net/pantheon-files)
 
2
* Copyright (c) 2016-2017 elementary LLC. (http://launchpad.net/pantheon-files)
3
3
*
4
4
* This program is free software; you can redistribute it and/or
5
5
* modify it under the terms of the GNU General Public
17
17
* Boston, MA 02111-1307, USA.
18
18
*/
19
19
 
20
 
public class PermissionButton : Gtk.Box {
 
20
public class PermissionButton : Gtk.Grid {
21
21
    public Gtk.ToggleButton btn_read;
22
22
    public Gtk.ToggleButton btn_write;
23
23
    public Gtk.ToggleButton btn_exe;
24
24
 
25
 
    public Marlin.View.PropertiesWindow.PermissionType permission_type { get; construct; }
26
 
 
27
 
    public enum Value {
28
 
        READ,
29
 
        WRITE,
30
 
        EXE
31
 
    }
32
 
 
33
 
    public PermissionButton (Marlin.View.PropertiesWindow.PermissionType permission_type) {
 
25
    public Permissions.Type permission_type { get; construct; }
 
26
 
 
27
    private Posix.mode_t[,] vfs_perms = {
 
28
        { Posix.S_IRUSR, Posix.S_IWUSR, Posix.S_IXUSR },
 
29
        { Posix.S_IRGRP, Posix.S_IWGRP, Posix.S_IXGRP },
 
30
        { Posix.S_IROTH, Posix.S_IWOTH, Posix.S_IXOTH }
 
31
    };
 
32
 
 
33
    public PermissionButton (Permissions.Type permission_type) {
34
34
        Object (permission_type: permission_type);
35
35
    }
36
36
 
37
37
    construct {
38
38
        btn_read = new Gtk.ToggleButton.with_label (_("Read"));
39
39
        btn_read.set_data ("permissiontype", permission_type);
40
 
        btn_read.set_data ("permissionvalue", Value.READ);
 
40
        btn_read.set_data ("permissionvalue", Permissions.Value.READ);
41
41
 
42
42
        btn_write = new Gtk.ToggleButton.with_label (_("Write"));
43
43
        btn_write.set_data ("permissiontype", permission_type);
44
 
        btn_write.set_data ("permissionvalue", Value.WRITE);
 
44
        btn_write.set_data ("permissionvalue", Permissions.Value.WRITE);
45
45
 
46
46
        btn_exe = new Gtk.ToggleButton.with_label (_("Execute"));
47
47
        btn_exe.set_data ("permissiontype", permission_type);
48
 
        btn_exe.set_data ("permissionvalue", Value.EXE);
 
48
        btn_exe.set_data ("permissionvalue", Permissions.Value.EXE);
49
49
 
50
 
        homogeneous = true;
 
50
        column_homogeneous = true;
51
51
        get_style_context ().add_class (Gtk.STYLE_CLASS_LINKED);
52
52
        add (btn_read);
53
53
        add (btn_write);
54
54
        add (btn_exe);
55
55
    }
 
56
 
 
57
    public void update_buttons (uint32 permissions) {
 
58
        if ((permissions & vfs_perms[permission_type, 0]) != 0) {
 
59
            btn_read.active = true;
 
60
        } else {
 
61
            btn_read.active = false;
 
62
        }
 
63
 
 
64
        if ((permissions & vfs_perms[permission_type, 1]) != 0) {
 
65
            btn_write.active = true;
 
66
        } else {
 
67
            btn_write.active = false;
 
68
        }
 
69
 
 
70
        if ((permissions & vfs_perms[permission_type, 2]) != 0) {
 
71
            btn_exe.active = true;
 
72
        } else {
 
73
            btn_exe.active = false;
 
74
        }
 
75
    }
56
76
}