|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2012 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to browse the change lists. |
|
8 """ |
|
9 |
|
10 import os |
|
11 |
|
12 import pysvn |
|
13 |
|
14 from PyQt4.QtCore import pyqtSlot, Qt, QMutexLocker |
|
15 from PyQt4.QtGui import QDialog, QDialogButtonBox, QListWidgetItem, QApplication, \ |
|
16 QCursor |
|
17 |
|
18 from .SvnDialogMixin import SvnDialogMixin |
|
19 |
|
20 from .Ui_SvnChangeListsDialog import Ui_SvnChangeListsDialog |
|
21 |
|
22 |
|
23 class SvnChangeListsDialog(QDialog, SvnDialogMixin, Ui_SvnChangeListsDialog): |
|
24 """ |
|
25 Class implementing a dialog to browse the change lists. |
|
26 """ |
|
27 def __init__(self, vcs, parent=None): |
|
28 """ |
|
29 Constructor |
|
30 |
|
31 @param vcs reference to the vcs object |
|
32 @param parent parent widget (QWidget) |
|
33 """ |
|
34 super().__init__(parent) |
|
35 self.setupUi(self) |
|
36 SvnDialogMixin.__init__(self) |
|
37 |
|
38 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) |
|
39 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) |
|
40 |
|
41 self.vcs = vcs |
|
42 |
|
43 self.client = self.vcs.getClient() |
|
44 self.client.callback_cancel = \ |
|
45 self._clientCancelCallback |
|
46 self.client.callback_get_login = \ |
|
47 self._clientLoginCallback |
|
48 self.client.callback_ssl_server_trust_prompt = \ |
|
49 self._clientSslServerTrustPromptCallback |
|
50 |
|
51 @pyqtSlot(QListWidgetItem, QListWidgetItem) |
|
52 def on_changeLists_currentItemChanged(self, current, previous): |
|
53 """ |
|
54 Private slot to handle the selection of a new item. |
|
55 |
|
56 @param current current item (QListWidgetItem) |
|
57 @param previous previous current item (QListWidgetItem) |
|
58 """ |
|
59 self.filesList.clear() |
|
60 if current is not None: |
|
61 changelist = current.text() |
|
62 if changelist in self.changeListsDict: |
|
63 self.filesList.addItems(sorted(self.changeListsDict[changelist])) |
|
64 |
|
65 def start(self, path): |
|
66 """ |
|
67 Public slot to populate the data. |
|
68 |
|
69 @param path directory name to show change lists for (string) |
|
70 """ |
|
71 self.changeListsDict = {} |
|
72 self.cancelled = False |
|
73 |
|
74 self.filesLabel.setText(self.trUtf8("Files (relative to {0}):").format(path)) |
|
75 |
|
76 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) |
|
77 QApplication.processEvents() |
|
78 |
|
79 locker = QMutexLocker(self.vcs.vcsExecutionMutex) |
|
80 try: |
|
81 entries = self.client.get_changelist(path, depth=pysvn.depth.infinity) |
|
82 for entry in entries: |
|
83 file = entry[0] |
|
84 changelist = entry[1] |
|
85 if changelist not in self.changeListsDict: |
|
86 self.changeListsDict[changelist] = [] |
|
87 filename = file.replace(path + os.sep, "") |
|
88 if filename not in self.changeListsDict[changelist]: |
|
89 self.changeListsDict[changelist].append(filename) |
|
90 except pysvn.ClientError as e: |
|
91 locker.unlock() |
|
92 self.__showError(e.args[0]) |
|
93 self.__finish() |
|
94 |
|
95 def __finish(self): |
|
96 """ |
|
97 Private slot called when the user pressed the button. |
|
98 """ |
|
99 self.changeLists.addItems(sorted(self.changeListsDict.keys())) |
|
100 QApplication.restoreOverrideCursor() |
|
101 |
|
102 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
|
103 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) |
|
104 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
|
105 |
|
106 if len(self.changeListsDict) == 0: |
|
107 self.changeLists.addItem(self.trUtf8("No changelists found")) |
|
108 self.buttonBox.button(QDialogButtonBox.Close).setFocus(Qt.OtherFocusReason) |
|
109 else: |
|
110 self.changeLists.setCurrentRow(0) |
|
111 self.changeLists.setFocus(Qt.OtherFocusReason) |
|
112 |
|
113 def on_buttonBox_clicked(self, button): |
|
114 """ |
|
115 Private slot called by a button of the button box clicked. |
|
116 |
|
117 @param button button that was clicked (QAbstractButton) |
|
118 """ |
|
119 if button == self.buttonBox.button(QDialogButtonBox.Close): |
|
120 self.close() |
|
121 elif button == self.buttonBox.button(QDialogButtonBox.Cancel): |
|
122 self.cancelled = True |
|
123 self.__finish() |