Add gitlab settings
offlate/ui/gitlabedit.py unknown status 1
1 | + | # Copyright (c) 2018 Julien Lepiller <julien@lepiller.eu> | |
2 | + | # | |
3 | + | # This program is free software: you can redistribute it and/or modify | |
4 | + | # it under the terms of the GNU Affero General Public License as | |
5 | + | # published by the Free Software Foundation, either version 3 of the | |
6 | + | # License, or (at your option) any later version. | |
7 | + | # | |
8 | + | # This program is distributed in the hope that it will be useful, | |
9 | + | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | + | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | + | # GNU Affero General Public License for more details. | |
12 | + | # | |
13 | + | # You should have received a copy of the GNU Affero General Public License | |
14 | + | # along with this program. If not, see <https://www.gnu.org/licenses/>. | |
15 | + | #### | |
16 | + | ||
17 | + | from PyQt5.QtWidgets import * | |
18 | + | from PyQt5.QtGui import * | |
19 | + | from PyQt5.QtCore import * | |
20 | + | ||
21 | + | class GitlabEdit(QWidget): | |
22 | + | textChanged = pyqtSignal() | |
23 | + | ||
24 | + | def __init__(self, parent = None): | |
25 | + | super(GitlabEdit, self).__init__(parent) | |
26 | + | self.initUI() | |
27 | + | ||
28 | + | def addLine(self, server, token): | |
29 | + | items = [QTreeWidgetItem([server, token])] | |
30 | + | self.treeWidget.addTopLevelItems(items) | |
31 | + | ||
32 | + | def addLineSlot(self): | |
33 | + | server = self.serverEdit.text() | |
34 | + | token = self.tokenEdit.text() | |
35 | + | items = [QTreeWidgetItem([server, token])] | |
36 | + | self.treeWidget.addTopLevelItems(items) | |
37 | + | self.textChanged.emit() | |
38 | + | ||
39 | + | def deleteLineSlot(self): | |
40 | + | self.treeWidget.takeTopLevelItem(self.treeWidget.currentIndex().row()) | |
41 | + | self.textChanged.emit() | |
42 | + | ||
43 | + | def content(self): | |
44 | + | number = self.treeWidget.topLevelItemCount() | |
45 | + | items = [] | |
46 | + | for i in range(0, number): | |
47 | + | item = self.treeWidget.topLevelItem(i) | |
48 | + | items.append({"server": item.text(0), "token": item.text(1)}) | |
49 | + | return items | |
50 | + | ||
51 | + | def initUI(self): | |
52 | + | vbox = QVBoxLayout() | |
53 | + | hbox = QHBoxLayout() | |
54 | + | self.setLayout(vbox) | |
55 | + | self.treeWidget = QTreeWidget() | |
56 | + | self.treeWidget.setColumnCount(2) | |
57 | + | vbox.addWidget(self.treeWidget) | |
58 | + | self.serverEdit = QLineEdit() | |
59 | + | self.serverEdit.setPlaceholderText(self.tr("server")) | |
60 | + | self.tokenEdit = QLineEdit() | |
61 | + | self.tokenEdit.setPlaceholderText(self.tr("token")) | |
62 | + | addbutton = QPushButton(self.tr("Add")) | |
63 | + | addbutton.clicked.connect(self.addLineSlot) | |
64 | + | removebutton = QPushButton(self.tr("Remove")) | |
65 | + | removebutton.clicked.connect(self.deleteLineSlot) | |
66 | + | hbox.addWidget(self.serverEdit) | |
67 | + | hbox.addWidget(self.tokenEdit) | |
68 | + | hbox.addWidget(addbutton) | |
69 | + | hbox.addWidget(removebutton) | |
70 | + | vbox.addLayout(hbox) |
offlate/ui/settings.py
18 | 18 | from PyQt5.QtGui import * | |
19 | 19 | from PyQt5.QtCore import * | |
20 | 20 | ||
21 | + | from .gitlabedit import GitlabEdit | |
22 | + | ||
21 | 23 | class SettingsWindow(QDialog): | |
22 | 24 | def __init__(self, preferences, parent = None): | |
23 | 25 | super().__init__(parent) | |
… | |||
31 | 33 | tab = QTabWidget() | |
32 | 34 | self.addTPTab(tab) | |
33 | 35 | self.addTransifexTab(tab) | |
36 | + | self.addGitlabTab(tab) | |
34 | 37 | ||
35 | 38 | buttonbox = QHBoxLayout() | |
36 | 39 | cancel = QPushButton(self.tr("Cancel")) | |
… | |||
59 | 62 | self.TransifexToken.textChanged.connect(self.updateTransifex) | |
60 | 63 | label = QLabel(self.tr("You can get a token from <a href=\"#\">https://www.transifex.com/user/settings/api/</a>")) | |
61 | 64 | label.linkActivated.connect(self.openTransifex) | |
65 | + | label.setWordWrap(True) | |
62 | 66 | ||
63 | 67 | formLayout.addRow(QLabel(self.tr("Token:")), self.TransifexToken) | |
64 | 68 | formLayout.addRow(label) | |
… | |||
117 | 121 | def ok(self): | |
118 | 122 | self.done = True | |
119 | 123 | self.close() | |
124 | + | ||
125 | + | def addGitlabTab(self, tab): | |
126 | + | formBox = QGroupBox(self.tr("Gitlab")) | |
127 | + | formLayout = QVBoxLayout() | |
128 | + | label = QLabel(self.tr("Add your gitlab account tokens below. You need \ | |
129 | + | to create a token for every gitlab server you have an account on. You can create \ | |
130 | + | a token by logging into your account, going to your settings and in the Access \ | |
131 | + | Token page.")) | |
132 | + | label.setWordWrap(True) | |
133 | + | formLayout.addWidget(label) | |
134 | + | ||
135 | + | if not "Gitlab" in self.data: | |
136 | + | self.data["Gitlab"] = {} | |
137 | + | ||
138 | + | self.gitlabEdit = GitlabEdit() | |
139 | + | for server in self.data["Gitlab"]["servers"]: | |
140 | + | self.gitlabEdit.addLine(server["server"], server["token"]) | |
141 | + | ||
142 | + | formLayout.addSpacing(8) | |
143 | + | formLayout.addWidget(self.gitlabEdit) | |
144 | + | self.gitlabEdit.textChanged.connect(self.updateGitlab) | |
145 | + | ||
146 | + | formBox.setLayout(formLayout) | |
147 | + | tab.addTab(formBox, "Gitlab") | |
148 | + | ||
149 | + | def updateGitlab(self): | |
150 | + | if not "Gitlab" in self.data: | |
151 | + | self.data["Gitlab"] = {} | |
152 | + | self.data["Gitlab"]["servers"] = self.gitlabEdit.content() |