/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to seahorse.py

  • Committer: Gary van der Merwe
  • Date: 2007-08-10 10:45:06 UTC
  • mto: This revision was merged to the branch mainline in revision 256.
  • Revision ID: garyvdm@gmail.com-20070810104506-wo2mp9zfkh338axe
Make icon locations consistant between source and installed version. Let glade nkow where to find the icons with a project file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# This program is free software; you can redistribute it and/or modify
2
 
# it under the terms of the GNU General Public License as published by
3
 
# the Free Software Foundation; either version 2 of the License, or
4
 
# (at your option) any later version.
5
 
 
6
 
# This program is distributed in the hope that it will be useful,
7
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
8
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9
 
# GNU General Public License for more details.
10
 
 
11
 
# You should have received a copy of the GNU General Public License
12
 
# along with this program; if not, write to the Free Software
13
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
14
 
 
15
 
__copyright__ = 'Copyright (C) 2008 Daniel Schierbeck'
16
 
__author__ = 'Daniel Schierbeck <daniel.schierbeck@gmail.com>'
17
 
 
18
 
import dbus
19
 
 
20
 
BUS_NAME = 'org.gnome.seahorse'
21
 
 
22
 
CRYPTO_INTERFACE = 'org.gnome.seahorse.CryptoService'
23
 
CRYPTO_PATH = '/org/gnome/seahorse/crypto'
24
 
 
25
 
OPENPGP_INTERFACE = 'org.gnome.seahorse.Keys'
26
 
OPENPGP_PATH = '/org/gnome/seahorse/keys/openpgp'
27
 
 
28
 
KEY_TYPE_OPENPGP = 'openpgp'
29
 
KEY_TYPE_SSH = 'ssh'
30
 
 
31
 
try:
32
 
    bus = dbus.SessionBus()
33
 
except dbus.exceptions.DBusException, e:
34
 
    get_name = getattr(e, 'get_dbus_name', None)
35
 
    if get_name is not None:
36
 
        name = get_name()
37
 
    else:
38
 
        name = getattr(e, '_dbus_error_name', None)
39
 
    # DBus sometimes fails like this, just treat it as if seahorse is not
40
 
    # available rather than crashing.
41
 
    if name == "org.freedesktop.DBus.Error.Spawn.ExecFailed":
42
 
        raise ImportError
43
 
    else:
44
 
        raise
45
 
 
46
 
if hasattr(bus, 'list_activatable_names'):
47
 
    bus_names = bus.list_activatable_names()
48
 
else:
49
 
    bus_object = bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus')
50
 
    bus_names = bus_object.ListNames(dbus_interface='org.freedesktop.DBus')
51
 
 
52
 
if BUS_NAME not in bus_names:
53
 
    raise ImportError
54
 
 
55
 
crypto = dbus.Interface(bus.get_object(BUS_NAME, CRYPTO_PATH), 
56
 
                        CRYPTO_INTERFACE)
57
 
openpgp = dbus.Interface(bus.get_object(BUS_NAME, OPENPGP_PATH),
58
 
                         OPENPGP_INTERFACE)
59
 
 
60
 
FLAG_VALID = 0x0001
61
 
FLAG_CAN_ENCRYPT = 0x0002
62
 
FLAG_CAN_SIGN = 0x0004
63
 
FLAG_EXPIRED = 0x0100
64
 
FLAG_REVOKED = 0x0200
65
 
FLAG_DISABLED = 0x0400
66
 
FLAG_TRUSTED = 0x1000
67
 
 
68
 
TRUST_NEVER = -1
69
 
TRUST_UNKNOWN = 0
70
 
TRUST_MARGINAL = 1
71
 
TRUST_FULL = 5
72
 
TRUST_ULTIMATE = 10
73
 
 
74
 
LOCATION_MISSING = 10
75
 
LOCATION_SEARCHING = 20
76
 
LOCATION_REMOTE = 50
77
 
LOCATION_LOCAL = 100
78
 
 
79
 
keyset = dict()
80
 
 
81
 
def verify(crypttext):
82
 
    (cleartext, key) = crypto.VerifyText(KEY_TYPE_OPENPGP, 1, crypttext)
83
 
 
84
 
    if key != "":
85
 
        if key not in keyset:
86
 
            keyset[key] = Key(key)
87
 
 
88
 
        return (cleartext, keyset[key])
89
 
 
90
 
    return (cleartext, None)
91
 
 
92
 
 
93
 
class Key:
94
 
 
95
 
    def __init__(self, key):
96
 
        self.key = key
97
 
 
98
 
        (keys, unmatched) = openpgp.MatchKeys([self.get_id()], 0x00000010)
99
 
        self.available = (key in keys)
100
 
 
101
 
        if self.available:
102
 
            fields = openpgp.GetKeyFields(key, ['fingerprint', 'trust', 'flags', 'display-name', 'location'])
103
 
        else:
104
 
            fields = dict()
105
 
 
106
 
        self.fingerprint = fields.get('fingerprint', 'N/A')
107
 
        self.trust = fields.get('trust', TRUST_UNKNOWN)
108
 
        self.flags = fields.get('flags', 0)
109
 
        self.display_name = fields.get('display-name', '')
110
 
        self.location = fields.get('location', LOCATION_MISSING)
111
 
    
112
 
    def get_flags(self):
113
 
        return self.flags
114
 
 
115
 
    def get_display_name(self):
116
 
        return self.display_name
117
 
 
118
 
    def get_id(self):
119
 
        return self.key.split(':')[1][8:]
120
 
 
121
 
    def get_fingerprint(self):
122
 
        return self.fingerprint
123
 
 
124
 
    def get_trust(self):
125
 
        return self.trust
126
 
 
127
 
    def get_location(self):
128
 
        return self.location
129
 
 
130
 
    def is_available(self):
131
 
        return self.available
132
 
 
133
 
    def is_trusted(self):
134
 
        return self.flags & FLAG_TRUSTED != 0