Plugins/VcsPlugins/vcsPySvn/SvnDialogMixin.py

changeset 0
de9c2efb9d02
child 12
1d8dd9706f46
equal deleted inserted replaced
-1:000000000000 0:de9c2efb9d02
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2003 - 2009 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog mixin class providing common callback methods for
8 the pysvn client.
9 """
10
11 from PyQt4.QtGui import QApplication, QDialog, QWidget, QCursor
12
13 class SvnDialogMixin(object):
14 """
15 Class implementing a dialog mixin providing common callback methods for
16 the pysvn client.
17 """
18 def __init__(self, log = ""):
19 """
20 Constructor
21
22 @param log optional log message (string)
23 """
24 self.shouldCancel = False
25 self.logMessage = log
26
27 def _cancel(self):
28 """
29 Protected method to request a cancellation of the current action.
30 """
31 self.shouldCancel = True
32
33 def _reset(self):
34 """
35 Protected method to reset the internal state of the dialog.
36 """
37 self.shouldCancel = False
38
39 def _clientCancelCallback(self):
40 """
41 Protected method called by the client to check for cancellation.
42
43 @return flag indicating a cancellation
44 """
45 QApplication.processEvents()
46 return self.shouldCancel
47
48 def _clientLoginCallback(self, realm, username, may_save):
49 """
50 Protected method called by the client to get login information.
51
52 @param realm name of the realm of the requested credentials (string)
53 @param username username as supplied by subversion (string)
54 @param may_save flag indicating, that subversion is willing to save
55 the answers returned (boolean)
56 @return tuple of four values (retcode, username, password, save).
57 Retcode should be True, if username and password should be used
58 by subversion, username and password contain the relevant data
59 as strings and save is a flag indicating, that username and
60 password should be saved.
61 """
62 from SvnLoginDialog import SvnLoginDialog
63 cursor = QApplication.overrideCursor()
64 if cursor is not None:
65 QApplication.restoreOverrideCursor()
66 parent = isinstance(self, QWidget) and self or None
67 dlg = SvnLoginDialog(realm, username, may_save, parent)
68 res = dlg.exec_()
69 if cursor is not None:
70 QApplication.setOverrideCursor(cursor)
71 if res == QDialog.Accepted:
72 loginData = dlg.getData()
73 return (True, loginData[0], loginData[1], loginData[2])
74 else:
75 return (False, "", "", False)
76
77 def _clientSslServerTrustPromptCallback(self, trust_dict):
78 """
79 Protected method called by the client to request acceptance for a
80 ssl server certificate.
81
82 @param trust_dict dictionary containing the trust data
83 @return tuple of three values (retcode, acceptedFailures, save).
84 Retcode should be true, if the certificate should be accepted,
85 acceptedFailures should indicate the accepted certificate failures
86 and save should be True, if subversion should save the certificate.
87 """
88 from PyQt4.QtGui import QMessageBox
89
90 cursor = QCursor(QApplication.overrideCursor())
91 if cursor is not None:
92 QApplication.restoreOverrideCursor()
93 parent = isinstance(self, QWidget) and self or None
94 msgBox = QMessageBox.QMessageBox(QMessageBox.Question,
95 self.trUtf8("Subversion SSL Server Certificate"),
96 self.trUtf8("""<p>Accept the following SSL certificate?</p>"""
97 """<table>"""
98 """<tr><td>Realm:</td><td>{0}</td></tr>"""
99 """<tr><td>Hostname:</td><td>{1}</td></tr>"""
100 """<tr><td>Fingerprint:</td><td>{2}</td></tr>"""
101 """<tr><td>Valid from:</td><td>{3}</td></tr>"""
102 """<tr><td>Valid until:</td><td>{4}</td></tr>"""
103 """<tr><td>Issuer name:</td><td>{5}</td></tr>"""
104 """</table>""")\
105 .format(trust_dict["realm"],
106 trust_dict["hostname"],
107 trust_dict["finger_print"],
108 trust_dict["valid_from"],
109 trust_dict["valid_until"],
110 trust_dict["issuer_dname"]),
111 QMessageBox.StandardButtons(QMessageBox.NoButton),
112 parent)
113 permButton = msgBox.addButton(self.trUtf8("&Permanent accept"),
114 QMessageBox.AcceptRole)
115 tempButton = msgBox.addButton(self.trUtf8("&Temporary accept"),
116 QMessageBox.AcceptRole)
117 rejectButton = msgBox.addButton(self.trUtf8("&Reject"),
118 QMessageBox.RejectRole)
119 msgBox.exec_()
120 if cursor is not None:
121 QApplication.setOverrideCursor(cursor)
122 if msgBox.clickedButton() == permButton:
123 return (True, trust_dict["failures"], True)
124 elif msgBox.clickedButton() == tempButton:
125 return (True, trust_dict["failures"], False)
126 else:
127 return (False, 0, False)
128
129 def _clientLogCallback(self):
130 """
131 Protected method called by the client to request a log message.
132
133 @return a flag indicating success and the log message (string)
134 """
135 from SvnCommitDialog import SvnCommitDialog
136 if self.logMessage:
137 return True, self.logMessage
138 else:
139 # call CommitDialog and get message from there
140 dlg = SvnCommitDialog(self)
141 if dlg.exec_() == QDialog.Accepted:
142 msg = dlg.logMessage()
143 if msg:
144 return True, msg
145 else:
146 return True, "***" # always supply a valid log message
147 else:
148 return False, ""

eric ide

mercurial