~ubuntu-branches/ubuntu/karmic/eric/karmic

« back to all changes in this revision

Viewing changes to eric/VCS/vcsCVS/CvsHistoryDialog.py

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2008-01-28 18:02:25 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080128180225-6nrox6yrworh2c4v
Tags: 4.0.4-1ubuntu1
* Add python-qt3 to build-depends becuase that's where Ubuntu puts 
  pyqtconfig
* Change maintainer to MOTU

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
 
3
# Copyright (c) 2002 - 2007 Detlev Offenbach <detlev@die-offenbachs.de>
 
4
#
 
5
#
 
6
# It is inspired by the cvs history form code found in LinCVS
 
7
#
 
8
 
 
9
"""
 
10
Module implementing a dialog to show the output of the cvs history command process.
 
11
"""
 
12
 
 
13
import os
 
14
 
 
15
from PyQt4.QtCore import *
 
16
from PyQt4.QtGui import *
 
17
 
 
18
from Ui_CvsHistoryDialog import Ui_CvsHistoryDialog
 
19
 
 
20
class CvsHistoryDialog(QWidget, Ui_CvsHistoryDialog):
 
21
    """
 
22
    Module implementing a dialog to show the output of the cvs history command process.
 
23
    """
 
24
    def __init__(self, vcs, parent = None):
 
25
        """
 
26
        Constructor
 
27
        
 
28
        @param vcs reference to the vcs object
 
29
        @param parent parent widget (QWidget)
 
30
        """
 
31
        QWidget.__init__(self, parent)
 
32
        self.setupUi(self)
 
33
        
 
34
        self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
 
35
        self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
 
36
        
 
37
        self.process = QProcess()
 
38
        self.vcs = vcs
 
39
        self.index = 0
 
40
        
 
41
        self.connect(self.process, SIGNAL('finished(int, QProcess::ExitStatus)'),
 
42
            self.__procFinished)
 
43
        self.connect(self.process, SIGNAL('readyReadStandardOutput()'),
 
44
            self.__readStdout)
 
45
        self.connect(self.process, SIGNAL('readyReadStandardError()'),
 
46
            self.__readStderr)
 
47
        
 
48
    def __resort(self):
 
49
        """
 
50
        Private method to resort the tree.
 
51
        """
 
52
        self.historyList.sortItems(self.historyList.sortColumn(), 
 
53
            self.historyList.header().sortIndicatorOrder())
 
54
        
 
55
    def __resizeColumns(self):
 
56
        """
 
57
        Private method to resize the list columns.
 
58
        """
 
59
        self.historyList.header().resizeSections(QHeaderView.ResizeToContents)
 
60
        self.historyList.header().setStretchLastSection(True)
 
61
        
 
62
    def __generateItem(self, index, date, time, timezone, event, author, revision,
 
63
                       file, path):
 
64
        """
 
65
        Private method to generate a status item in the status list.
 
66
        
 
67
        @param index index number of the history entry (integer)
 
68
        @param date date of the entry (string or QString)
 
69
        @param time time of the entry (string or QString)
 
70
        @param timezone timezone of the entry (string or QString)
 
71
        @param event event type (string or QString)
 
72
        @param author author (string or QString)
 
73
        @param revision revision number (string or QString)
 
74
        @param file file name (string or QString)
 
75
        @param path path of the file (string or QString)
 
76
        """
 
77
        itm = QTreeWidgetItem(self.historyList, 
 
78
            QStringList() \
 
79
            << '%05d' % index \
 
80
            << ' %s %s %s ' % (unicode(date), unicode(time), unicode(timezone)) \
 
81
            << event \
 
82
            << author \
 
83
            << revision \
 
84
            << file \
 
85
            << path
 
86
        )
 
87
        
 
88
    def closeEvent(self, e):
 
89
        """
 
90
        Private slot implementing a close event handler.
 
91
        
 
92
        @param e close event (QCloseEvent)
 
93
        """
 
94
        if self.process is not None and \
 
95
           self.process.state() != QProcess.NotRunning:
 
96
            self.process.terminate()
 
97
            QTimer.singleShot(2000, self.process, SLOT('kill()'))
 
98
            self.process.waitForFinished(3000)
 
99
        
 
100
        e.accept()
 
101
        
 
102
    def start(self, fn):
 
103
        """
 
104
        Public slot to start the cvs history command.
 
105
        
 
106
        @param fn filename (string)
 
107
        """
 
108
        self.setWindowTitle(self.trUtf8('CVS History %1').arg(fn))
 
109
        QApplication.processEvents()
 
110
        
 
111
        self.intercept = False
 
112
        self.filename = fn
 
113
        self.dname, self.fname = self.vcs.splitPath(fn)
 
114
        
 
115
        self.process.kill()
 
116
        
 
117
        args = QStringList()
 
118
        self.vcs.addArguments(args, self.vcs.options['global'])
 
119
        args.append('history')
 
120
        self.vcs.addArguments(args, self.vcs.options['history'])
 
121
        args.append(self.fname)
 
122
        
 
123
        self.process.setWorkingDirectory(self.dname)
 
124
        
 
125
        self.process.start('cvs', args)
 
126
        
 
127
    def __finish(self):
 
128
        """
 
129
        Private slot called when the process finished or the user pressed the button.
 
130
        """
 
131
        if self.process is not None and \
 
132
           self.process.state() != QProcess.NotRunning:
 
133
            self.process.terminate()
 
134
            QTimer.singleShot(2000, self.process, SLOT('kill()'))
 
135
            self.process.waitForFinished(3000)
 
136
        
 
137
        self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
 
138
        self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
 
139
        self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
 
140
        
 
141
        self.inputGroup.setEnabled(False)
 
142
        
 
143
        self.process = None
 
144
        
 
145
        self.historyList.doItemsLayout()
 
146
        self.__resizeColumns()
 
147
        self.__resort()
 
148
        
 
149
    def on_buttonBox_clicked(self, button):
 
150
        """
 
151
        Private slot called by a button of the button box clicked.
 
152
        
 
153
        @param button button that was clicked (QAbstractButton)
 
154
        """
 
155
        if button == self.buttonBox.button(QDialogButtonBox.Close):
 
156
            self.close()
 
157
        elif button == self.buttonBox.button(QDialogButtonBox.Cancel):
 
158
            self.__finish()
 
159
        
 
160
    def __procFinished(self, exitCode, exitStatus):
 
161
        """
 
162
        Private slot connected to the finished signal.
 
163
        
 
164
        @param exitCode exit code of the process (integer)
 
165
        @param exitStatus exit status of the process (QProcess.ExitStatus)
 
166
        """
 
167
        self.__finish()
 
168
        
 
169
    def __readStdout(self):
 
170
        """
 
171
        Private slot to handle the readyReadStdout signal.
 
172
        
 
173
        It reads the output of the process, formats it and inserts it into
 
174
        the contents pane.
 
175
        """
 
176
        self.process.setReadChannel(QProcess.StandardOutput)
 
177
        
 
178
        while self.process.canReadLine():
 
179
            s = QString(self.process.readLine())
 
180
            
 
181
            if s.isEmpty():
 
182
                continue
 
183
            
 
184
            list = s.split(' ', QString.SkipEmptyParts)
 
185
            cmd = str(list[0])
 
186
            if len(cmd) != 1:
 
187
                continue    # we got something 
 
188
            
 
189
            if cmd in ['O', 'F', 'E']:
 
190
                if list.count() != 8:
 
191
                    continue # we got some bad output
 
192
                ncol = 8
 
193
                if unicode(self.fname) != '.':
 
194
                    continue
 
195
            else:
 
196
                if list.count() != 10:
 
197
                    continue # we got some bad output
 
198
                ncol = 10
 
199
                dir = unicode(list[7])
 
200
                if unicode(self.dname)[-len(dir):] != dir:
 
201
                    continue
 
202
            
 
203
            if cmd == 'O':
 
204
                event = self.trUtf8('Checkout ')
 
205
            elif cmd == 'T':
 
206
                event = self.trUtf8('Tag ')
 
207
            elif cmd == 'F':
 
208
                event = self.trUtf8('Release ')
 
209
            elif cmd == 'E':
 
210
                event = self.trUtf8('Export ')
 
211
                
 
212
            elif cmd == 'W':
 
213
                event = self.trUtf8('Update, Deleted ')
 
214
            elif cmd == 'U':
 
215
                event = self.trUtf8('Update, Copied ')
 
216
            elif cmd == 'G':
 
217
                event = self.trUtf8('Update, Merged ')
 
218
            elif cmd == 'C':
 
219
                event = self.trUtf8('Update, Conflict ')
 
220
            elif cmd == 'P':
 
221
                event = self.trUtf8('Update, Patched')
 
222
                
 
223
            elif cmd == 'M':
 
224
                event = self.trUtf8('Commit, Modified ')
 
225
            elif cmd == 'A':
 
226
                event = self.trUtf8('Commit, Added ')
 
227
            elif cmd == 'R':
 
228
                event = self.trUtf8('Commit, Removed ')
 
229
            else:
 
230
                event = self.trUtf8('Unknown (%1)').arg(cmd)
 
231
            
 
232
            if ncol == 10:
 
233
                self.__generateItem(self.index, list[1], list[2], list[3], event, 
 
234
                    list[4], list[5], list[6], list[7])
 
235
            else:
 
236
                self.__generateItem(self.index, list[1], list[2], list[3], event, 
 
237
                    list[4], '', '', list[5])
 
238
            
 
239
            self.index += 1
 
240
        
 
241
    def __readStderr(self):
 
242
        """
 
243
        Private slot to handle the readyReadStderr signal. 
 
244
        
 
245
        It reads the error output of the process and inserts it into the
 
246
        error pane.
 
247
        """
 
248
        if self.process is not None:
 
249
            s = QString(self.process.readAllStandardError())
 
250
            self.errors.insertPlainText(s)
 
251
            self.errors.ensureCursorVisible()
 
252
        
 
253
    def on_passwordCheckBox_toggled(self, isOn):
 
254
        """
 
255
        Private slot to handle the password checkbox toggled.
 
256
        
 
257
        @param isOn flag indicating the status of the check box (boolean)
 
258
        """
 
259
        if isOn:
 
260
            self.input.setEchoMode(QLineEdit.Password)
 
261
        else:
 
262
            self.input.setEchoMode(QLineEdit.Normal)
 
263
        
 
264
    @pyqtSignature("")
 
265
    def on_sendButton_clicked(self):
 
266
        """
 
267
        Private slot to send the input to the subversion process.
 
268
        """
 
269
        input = self.input.text()
 
270
        input.append(os.linesep)
 
271
        
 
272
        if self.passwordCheckBox.isChecked():
 
273
            self.errors.insertPlainText(os.linesep)
 
274
            self.errors.ensureCursorVisible()
 
275
        else:
 
276
            self.errors.insertPlainText(input)
 
277
            self.errors.ensureCursorVisible()
 
278
        
 
279
        self.proc.write(input.toLocal8Bit())
 
280
        
 
281
        self.passwordCheckBox.setChecked(False)
 
282
        self.input.clear()
 
283
        
 
284
    def on_input_returnPressed(self):
 
285
        """
 
286
        Private slot to handle the press of the return key in the input field.
 
287
        """
 
288
        self.intercept = True
 
289
        self.on_sendButton_clicked()
 
290
        
 
291
    def keyPressEvent(self, evt):
 
292
        """
 
293
        Protected slot to handle a key press event.
 
294
        
 
295
        @param evt the key press event (QKeyEvent)
 
296
        """
 
297
        if self.intercept:
 
298
            self.intercept = False
 
299
            evt.accept()
 
300
            return
 
301
        QWidget.keyPressEvent(self, evt)