|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2010 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to enter data needed for the initial creation |
|
8 of a repository configuration file (hgrc). |
|
9 """ |
|
10 |
|
11 from __future__ import unicode_literals |
|
12 |
|
13 from PyQt5.QtCore import pyqtSlot, QUrl |
|
14 from PyQt5.QtWidgets import QDialog, QLineEdit |
|
15 |
|
16 from .Ui_HgRepoConfigDataDialog import Ui_HgRepoConfigDataDialog |
|
17 |
|
18 import UI.PixmapCache |
|
19 |
|
20 from .LargefilesExtension import getDefaults as getLargefilesDefaults |
|
21 |
|
22 |
|
23 class HgRepoConfigDataDialog(QDialog, Ui_HgRepoConfigDataDialog): |
|
24 """ |
|
25 Class implementing a dialog to enter data needed for the initial creation |
|
26 of a repository configuration file (hgrc). |
|
27 """ |
|
28 def __init__(self, withLargefiles=False, largefilesData=None, parent=None): |
|
29 """ |
|
30 Constructor |
|
31 |
|
32 @param withLargefiles flag indicating to configure the largefiles |
|
33 section (boolean) |
|
34 @param largefilesData dictionary with data for the largefiles |
|
35 section (dict) |
|
36 @param parent reference to the parent widget (QWidget) |
|
37 """ |
|
38 super(HgRepoConfigDataDialog, self).__init__(parent) |
|
39 self.setupUi(self) |
|
40 |
|
41 self.defaultShowPasswordButton.setIcon( |
|
42 UI.PixmapCache.getIcon("showPassword.png")) |
|
43 self.defaultPushShowPasswordButton.setIcon( |
|
44 UI.PixmapCache.getIcon("showPassword.png")) |
|
45 |
|
46 self.__withLargefiles = withLargefiles |
|
47 if withLargefiles: |
|
48 if largefilesData is None: |
|
49 largefilesData = getLargefilesDefaults() |
|
50 self.lfFileSizeSpinBox.setValue(largefilesData["minsize"]) |
|
51 self.lfFilePatternsEdit.setText( |
|
52 " ".join(largefilesData["pattern"])) |
|
53 else: |
|
54 self.largefilesGroup.setVisible(False) |
|
55 |
|
56 self.resize(self.width(), self.minimumSizeHint().height()) |
|
57 |
|
58 @pyqtSlot(bool) |
|
59 def on_defaultShowPasswordButton_clicked(self, checked): |
|
60 """ |
|
61 Private slot to switch the default password visibility |
|
62 of the default password. |
|
63 |
|
64 @param checked state of the push button (boolean) |
|
65 """ |
|
66 if checked: |
|
67 self.defaultPasswordEdit.setEchoMode(QLineEdit.Normal) |
|
68 else: |
|
69 self.defaultPasswordEdit.setEchoMode(QLineEdit.Password) |
|
70 |
|
71 @pyqtSlot(bool) |
|
72 def on_defaultPushShowPasswordButton_clicked(self, checked): |
|
73 """ |
|
74 Private slot to switch the default password visibility |
|
75 of the default push password. |
|
76 |
|
77 @param checked state of the push button (boolean) |
|
78 """ |
|
79 if checked: |
|
80 self.defaultPushPasswordEdit.setEchoMode(QLineEdit.Normal) |
|
81 else: |
|
82 self.defaultPushPasswordEdit.setEchoMode(QLineEdit.Password) |
|
83 |
|
84 def getData(self): |
|
85 """ |
|
86 Public method to get the data entered into the dialog. |
|
87 |
|
88 @return tuple giving the default and default push URLs (tuple of |
|
89 two strings) |
|
90 """ |
|
91 defaultUrl = QUrl.fromUserInput(self.defaultUrlEdit.text()) |
|
92 username = self.defaultUserEdit.text() |
|
93 password = self.defaultPasswordEdit.text() |
|
94 if username: |
|
95 defaultUrl.setUserName(username) |
|
96 if password: |
|
97 defaultUrl.setPassword(password) |
|
98 if not defaultUrl.isValid(): |
|
99 defaultUrl = "" |
|
100 else: |
|
101 defaultUrl = defaultUrl.toString() |
|
102 |
|
103 defaultPushUrl = QUrl.fromUserInput(self.defaultPushUrlEdit.text()) |
|
104 username = self.defaultPushUserEdit.text() |
|
105 password = self.defaultPushPasswordEdit.text() |
|
106 if username: |
|
107 defaultPushUrl.setUserName(username) |
|
108 if password: |
|
109 defaultPushUrl.setPassword(password) |
|
110 if not defaultPushUrl.isValid(): |
|
111 defaultPushUrl = "" |
|
112 else: |
|
113 defaultPushUrl = defaultPushUrl.toString() |
|
114 |
|
115 return defaultUrl, defaultPushUrl |
|
116 |
|
117 def getLargefilesData(self): |
|
118 """ |
|
119 Public method to get the data for the largefiles extension. |
|
120 |
|
121 @return tuple with the minimum file size (integer) and file patterns |
|
122 (list of string). None as value denote to use the default value. |
|
123 """ |
|
124 if self.__withLargefiles: |
|
125 lfDefaults = getLargefilesDefaults() |
|
126 if self.lfFileSizeSpinBox.value() == lfDefaults["minsize"]: |
|
127 minsize = None |
|
128 else: |
|
129 minsize = self.lfFileSizeSpinBox.value() |
|
130 patterns = self.lfFilePatternsEdit.text().split() |
|
131 if set(patterns) == set(lfDefaults["pattern"]): |
|
132 patterns = None |
|
133 |
|
134 return minsize, patterns |
|
135 else: |
|
136 return None, None |