|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2018 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to change the URL of a remote git repository. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtCore import pyqtSlot, Qt, QUrl |
|
13 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
|
14 |
|
15 from .Ui_GitChangeRemoteUrlDialog import Ui_GitChangeRemoteUrlDialog |
|
16 |
|
17 |
|
18 class GitChangeRemoteUrlDialog(QDialog, Ui_GitChangeRemoteUrlDialog): |
|
19 """ |
|
20 Class implementing a dialog to change the URL of a remote git repository. |
|
21 """ |
|
22 def __init__(self, remoteName, remoteUrl, parent=None): |
|
23 """ |
|
24 Constructor |
|
25 |
|
26 @param remoteName name of the remote repository |
|
27 @type str |
|
28 @param remoteUrl URL of the remote repository |
|
29 @type str |
|
30 @param parent reference to the parent widget |
|
31 @type QWidget |
|
32 """ |
|
33 super(GitChangeRemoteUrlDialog, self).__init__(parent) |
|
34 self.setupUi(self) |
|
35 |
|
36 url = QUrl(remoteUrl) |
|
37 self.__userInfo = url.userInfo() |
|
38 |
|
39 self.nameEdit.setText(remoteName) |
|
40 self.urlEdit.setText(url.toString(QUrl.RemoveUserInfo)) |
|
41 |
|
42 self.__updateOK() |
|
43 |
|
44 self.newUrlEdit.setFocus(Qt.OtherFocusReason) |
|
45 |
|
46 msh = self.minimumSizeHint() |
|
47 self.resize(max(self.width(), msh.width()), msh.height()) |
|
48 |
|
49 def __updateOK(self): |
|
50 """ |
|
51 Private method to update the status of the OK button. |
|
52 """ |
|
53 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( |
|
54 bool(self.newUrlEdit.text()) |
|
55 ) |
|
56 |
|
57 @pyqtSlot(str) |
|
58 def on_newUrlEdit_textChanged(self, txt): |
|
59 """ |
|
60 Private slot handling changes of the entered URL. |
|
61 |
|
62 @param txt current text |
|
63 @type str |
|
64 """ |
|
65 self.__updateOK() |
|
66 |
|
67 def getData(self): |
|
68 """ |
|
69 Public method to get the entered data. |
|
70 |
|
71 @return tuple with name and new URL of the remote repository |
|
72 @rtype tuple of (str, str) |
|
73 """ |
|
74 url = QUrl.fromUserInput(self.newUrlEdit.text()) |
|
75 if self.__userInfo: |
|
76 url.setUserInfo(self.__userInfo) |
|
77 |
|
78 return self.nameEdit.text(), url.toString() |