eric6/Plugins/VcsPlugins/vcsPySvn/SvnDialogMixin.py

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

eric ide

mercurial