~mrooney/ecryptfs/nautilus-integration

« back to all changes in this revision

Viewing changes to src/python/nautilus/storage.py

  • Committer: Michael Rooney
  • Date: 2009-05-28 10:40:56 UTC
  • Revision ID: mrooney@ubuntu.com-20090528104056-mqirt68bbs3quj5t
reflect api changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
from threading import Thread
33
33
import nautilus_api as nautilus
34
34
 
35
 
from ecryptfs import ecryptapi
 
35
from ecryptfs import ecryptapi, ecryptui
 
36
 
 
37
LOCK_SECURE_SMALL = os.path.join(os.getcwd(), "ecryptfs/nautilus/lock-secure-small.png")
 
38
LOCK_INSECURE_SMALL = os.path.join(os.getcwd(), "ecryptfs/nautilus/lock-insecure-small.png")
36
39
 
37
40
class StorageBar(gtk.HBox):
38
41
    """The storage bar widget."""
40
43
    def __init__(self, path, *args, **kw):
41
44
        """Initialize the widget."""
42
45
        super(StorageBar, self).__init__(*args, **kw)
 
46
        self.__path = path
 
47
        self.__mounted = None
 
48
        # Create the left-side label text.
43
49
        self.__label = gtk.Label()
44
50
        self.__label.set_markup("These are files in an encrypted directory")
45
51
        self.__label.set_alignment(0.0, 0.5)
46
52
        self.__label.show()
47
 
        self.add(self.__label)
 
53
        # Initialize the lock/unlock button and image.
48
54
        self.__button = gtk.Button()
 
55
        self.__button.set_property("image-position", gtk.POS_LEFT)
49
56
        self.__button.connect("clicked", self.__toggle_state)
50
57
        self.__button.show()
51
 
        self.pack_end(self.__button, expand=False, fill=False)
52
 
        self.__path = path
53
 
        self.__mounted = None
 
58
        self.__button_image = gtk.Image()
 
59
        # Initialize the configure button.
 
60
        self.__button_settings = gtk.Button("Configure")
 
61
        self.__button_settings.connect("clicked", self.__onclick_configure)
 
62
        self.__button_settings.show()
 
63
        # Layout everything
 
64
        self.add(self.__label)
 
65
        self.pack_start(self.__button, expand=False, fill=False)
 
66
        self.pack_end(self.__button_settings, expand=False, fill=False)
 
67
        # Update the status appropriately.
54
68
        self.__update_status()
55
69
 
56
70
    def __toggle_state(self, button):
57
71
        """Toggle the connectivity state."""
58
72
        if self.__mounted:
59
 
            ecryptapi.setMounted(False)
 
73
            ecryptapi.set_mounted(False)
60
74
        else:
61
 
            ecryptapi.setMounted(True)
 
75
            ecryptapi.set_mounted(True)
62
76
 
63
77
        self.__update_status()
 
78
        
 
79
    def __onclick_configure(self, button):
 
80
        ecryptui.main()
64
81
 
65
82
    def __update_status(self):
66
83
        """Update the label, and button when connection status changes."""
67
 
        self.__mounted = ecryptapi.getMounted()
 
84
        self.__mounted = ecryptapi.get_mounted()
68
85
        if self.__mounted:
69
 
            self.__button.set_label("Lock directory")
 
86
            label = "Lock directory"
 
87
            img = LOCK_SECURE_SMALL
70
88
        else:
71
 
            self.__button.set_label("Unlock directory")
 
89
            label = "Unlock directory"
 
90
            img = LOCK_INSECURE_SMALL
 
91
 
 
92
        self.__button_image.set_from_file(img)
 
93
        self.__button.set_image(self.__button_image)
 
94
        self.__button.set_label(label)
72
95
 
73
96
 
74
97
def is_storagefs(path):
84
107
    else:
85
108
        return False
86
109
 
87
 
class StorageBarProvider(nautilus.LocationWidgetProvider):
 
110
class EcryptfsBarProvider(nautilus.LocationWidgetProvider):
88
111
    """An extension class providing a location widget for storage
89
112
    directories.
90
113