File: authgui.py

package info (click to toggle)
synce-sync-engine 0.11.1-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 996 kB
  • ctags: 923
  • sloc: python: 8,586; xml: 949; makefile: 51; sh: 7
file content (96 lines) | stat: -rwxr-xr-x 2,552 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python
# -*- coding: utf-8 -*-
###############################################################################
# authgui.py
#
# Helper tool for authorization in sync-engine. Run as a stand-alone unit - it
# is not bound to sync-engine in case gtk is not available
#
###############################################################################

import dbus
import dbus.glib
import gtk
import sys

ODCCM_DEVICE_PASSWORD_FLAG_SET     = 1
ODCCM_DEVICE_PASSWORD_FLAG_PROVIDE = 2

# EntryDialog
#
# Password entry dialog for GUI entry of password
#

class EntryDialog(gtk.Dialog):
    def __init__(self, parent, title, text, password=False):
        gtk.Dialog.__init__(self, title, parent,
                            gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_NO_SEPARATOR,
                            (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
                            gtk.STOCK_OK, gtk.RESPONSE_ACCEPT | gtk.CAN_DEFAULT))

        self.set_default_response(gtk.RESPONSE_ACCEPT)
        label = gtk.Label(text)
        label.set_alignment(0.0, 0.5)
        self.vbox.pack_start(label, False)
        self._label = label

        entry = gtk.Entry()
        entry.set_visibility(not password)
	entry.set_activates_default(True)
        self.vbox.pack_start(entry, False, True, 5)
        self._entry = entry

        self.show_all()

    def get_text(self):
        return self._entry.get_text()

# 
# AuthGui
#
# Application class.

class AuthGui:
	
	def __init__(self,objpath):

		bus = dbus.SystemBus()
		self.deviceObject = bus.get_object("org.synce.odccm", objpath)
		self.device = dbus.Interface(self.deviceObject, "org.synce.odccm.Device")
		self.deviceName = self.device.GetName()
	
	def Authorize(self):
		
		# no need to run if for some reason we are called on a 
		# device that is not blocked
		
		flags = self.device.GetPasswordFlags()
		rc=1
		if flags & ODCCM_DEVICE_PASSWORD_FLAG_PROVIDE:
			stopAsking = False
			while not stopAsking:
				dlg = EntryDialog(None,	"SynCE: Password required to synchronize device",
							"Enter password for device '%s'" % self.deviceName,
							True)

				if dlg.run() == gtk.RESPONSE_ACCEPT:
					stopAsking = self.device.ProvidePassword(dlg.get_text())
					if stopAsking:
						rc=1
				else:
		    			stopAsking = True
					rc=0
                		dlg.destroy()
		return rc

#
# main
#
# Get the objpath from the command line, then authorize

if len(sys.argv) > 1:
	devobjpath = sys.argv[1]
	app = AuthGui(devobjpath)
	sys.exit(app.Authorize())
else:
	sys.exit(0)