|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2014 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to enter the data of a remote repository. |
|
8 """ |
|
9 |
|
10 from PyQt6.QtCore import pyqtSlot, Qt, QUrl |
|
11 from PyQt6.QtWidgets import QDialog |
|
12 |
|
13 from .Ui_GitRemoteCredentialsDialog import Ui_GitRemoteCredentialsDialog |
|
14 |
|
15 |
|
16 class GitRemoteCredentialsDialog(QDialog, Ui_GitRemoteCredentialsDialog): |
|
17 """ |
|
18 Class implementing a dialog to enter the data of a remote repository. |
|
19 """ |
|
20 def __init__(self, remoteName, remoteUrl, parent=None): |
|
21 """ |
|
22 Constructor |
|
23 |
|
24 @param remoteName name of the remote repository |
|
25 @type str |
|
26 @param remoteUrl URL of the remote repository |
|
27 @type str |
|
28 @param parent reference to the parent widget |
|
29 @type QWidget |
|
30 """ |
|
31 super().__init__(parent) |
|
32 self.setupUi(self) |
|
33 |
|
34 url = QUrl(remoteUrl) |
|
35 |
|
36 self.nameEdit.setText(remoteName) |
|
37 self.urlEdit.setText( |
|
38 url.toString(QUrl.UrlFormattingOption.RemoveUserInfo)) |
|
39 self.userEdit.setText(url.userName()) |
|
40 self.passwordEdit.setText(url.password()) |
|
41 |
|
42 self.userEdit.setFocus(Qt.FocusReason.OtherFocusReason) |
|
43 |
|
44 msh = self.minimumSizeHint() |
|
45 self.resize(max(self.width(), msh.width()), msh.height()) |
|
46 |
|
47 @pyqtSlot(str) |
|
48 def on_userEdit_textChanged(self, txt): |
|
49 """ |
|
50 Private slot handling changes of the entered user name. |
|
51 |
|
52 @param txt current text |
|
53 @type str |
|
54 """ |
|
55 self.passwordEdit.setEnabled(bool(txt)) |
|
56 |
|
57 def getData(self): |
|
58 """ |
|
59 Public method to get the entered data. |
|
60 |
|
61 @return tuple with name and URL of the remote repository |
|
62 @rtype tuple of (str, str) |
|
63 """ |
|
64 url = QUrl.fromUserInput(self.urlEdit.text()) |
|
65 userName = self.userEdit.text() |
|
66 if userName: |
|
67 url.setUserName(userName) |
|
68 password = self.passwordEdit.text() |
|
69 if password: |
|
70 url.setPassword(password) |
|
71 |
|
72 return self.nameEdit.text(), url.toString() |