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

« back to all changes in this revision

Viewing changes to eric/VCS/vcsPySvn/SvnTagBranchListDialog.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) 2003 - 2007 Detlev Offenbach <detlev@die-offenbachs.de>
 
4
#
 
5
 
 
6
"""
 
7
Module implementing a dialog to show a list of tags or branches.
 
8
"""
 
9
 
 
10
import os
 
11
 
 
12
import pysvn
 
13
 
 
14
from PyQt4.QtCore import *
 
15
from PyQt4.QtGui import *
 
16
 
 
17
from KdeQt import KQMessageBox, KQInputDialog
 
18
 
 
19
from SvnUtilities import formatTime
 
20
 
 
21
from SvnDialogMixin import SvnDialogMixin
 
22
from Ui_SvnTagBranchListDialog import Ui_SvnTagBranchListDialog
 
23
 
 
24
class SvnTagBranchListDialog(QDialog, SvnDialogMixin, Ui_SvnTagBranchListDialog):
 
25
    """
 
26
    Module implementing a dialog to show a list of tags or branches.
 
27
    """
 
28
    def __init__(self, vcs, parent = None):
 
29
        """
 
30
        Constructor
 
31
        
 
32
        @param vcs reference to the vcs object
 
33
        @param parent parent widget (QWidget)
 
34
        """
 
35
        QDialog.__init__(self, parent)
 
36
        self.setupUi(self)
 
37
        SvnDialogMixin.__init__(self)
 
38
        
 
39
        self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
 
40
        self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
 
41
        
 
42
        self.vcs = vcs
 
43
        
 
44
        self.tagList.header().setSortIndicator(3, Qt.AscendingOrder)
 
45
        
 
46
        self.client = self.vcs.getClient()
 
47
        self.client.callback_cancel = \
 
48
            self._clientCancelCallback
 
49
        self.client.callback_get_login = \
 
50
            self._clientLoginCallback
 
51
        self.client.callback_ssl_server_trust_prompt = \
 
52
            self._clientSslServerTrustPromptCallback
 
53
        
 
54
    def start(self, path, tags = True):
 
55
        """
 
56
        Public slot to start the svn status command.
 
57
        
 
58
        @param path name of directory to be listed (string)
 
59
        @param tags flag indicating a list of tags is requested
 
60
                (False = branches, True = tags)
 
61
        """
 
62
        if not tags:
 
63
            self.setWindowTitle(self.trUtf8("Subversion Branches List"))
 
64
        self.activateWindow()
 
65
        QApplication.processEvents()
 
66
        
 
67
        dname, fname = self.vcs.splitPath(path)
 
68
        
 
69
        reposURL = self.vcs.svnGetReposName(dname)
 
70
        if reposURL is None:
 
71
            KQMessageBox.critical(None,
 
72
                self.trUtf8("Subversion Error"),
 
73
                self.trUtf8("""The URL of the project repository could not be"""
 
74
                    """ retrieved from the working copy. The list operation will"""
 
75
                    """ be aborted"""))
 
76
            self.close()
 
77
            return False
 
78
        
 
79
        if self.vcs.otherData["standardLayout"]:
 
80
            # determine the base path of the project in the repository
 
81
            rx_base = QRegExp('(.+)/(trunk|tags|branches).*')
 
82
            if not rx_base.exactMatch(reposURL):
 
83
                KQMessageBox.critical(None,
 
84
                    self.trUtf8("Subversion Error"),
 
85
                    self.trUtf8("""The URL of the project repository has an"""
 
86
                        """ invalid format. The list operation will"""
 
87
                        """ be aborted"""))
 
88
                return False
 
89
            
 
90
            reposRoot = unicode(rx_base.cap(1))
 
91
            
 
92
            if tags:
 
93
                path = "%s/tags" % reposRoot
 
94
            else:
 
95
                path = "%s/branches" % reposRoot
 
96
        else:
 
97
            reposPath, ok = KQInputDialog.getText(\
 
98
                self,
 
99
                self.trUtf8("Subversion List"),
 
100
                self.trUtf8("Enter the repository URL containing the tags or branches"),
 
101
                QLineEdit.Normal,
 
102
                self.vcs.svnNormalizeURL(reposURL))
 
103
            if not ok:
 
104
                self.close()
 
105
                return False
 
106
            if reposPath.isEmpty():
 
107
                KQMessageBox.critical(None,
 
108
                    self.trUtf8("Subversion List"),
 
109
                    self.trUtf8("""The repository URL is empty. Aborting..."""))
 
110
                self.close()
 
111
                return False
 
112
            path = unicode(reposPath)
 
113
        
 
114
        self.tagsList = QStringList()
 
115
        cwd = os.getcwd()
 
116
        os.chdir(dname)
 
117
        try:
 
118
            entries = self.client.ls(path, recurse = False)
 
119
            for entry in entries:
 
120
                name = entry["name"].replace(path+'/', "")
 
121
                self.__generateItem(entry["created_rev"].number, 
 
122
                                    entry["last_author"], 
 
123
                                    formatTime(entry["time"]), 
 
124
                                    name)
 
125
                if self.vcs.otherData["standardLayout"]:
 
126
                    self.tagsList.append(name)
 
127
                else:
 
128
                    self.tagsList.append(path + '/' + name)
 
129
                if self._clientCancelCallback():
 
130
                    break
 
131
            res = True
 
132
        except pysvn.ClientError, e:
 
133
            self.__showError(e.args[0])
 
134
            res = False
 
135
        self.__finish()
 
136
        os.chdir(cwd)
 
137
        return res
 
138
        
 
139
    def __finish(self):
 
140
        """
 
141
        Private slot called when the process finished or the user pressed the button.
 
142
        """
 
143
        self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
 
144
        self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
 
145
        self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
 
146
        
 
147
        self.tagList.doItemsLayout()
 
148
        self.__resizeColumns()
 
149
        self.__resort()
 
150
        
 
151
        self._cancel()
 
152
        
 
153
    def on_buttonBox_clicked(self, button):
 
154
        """
 
155
        Private slot called by a button of the button box clicked.
 
156
        
 
157
        @param button button that was clicked (QAbstractButton)
 
158
        """
 
159
        if button == self.buttonBox.button(QDialogButtonBox.Close):
 
160
            self.close()
 
161
        elif button == self.buttonBox.button(QDialogButtonBox.Cancel):
 
162
            self.__finish()
 
163
        
 
164
    def __showError(self, msg):
 
165
        """
 
166
        Private slot to show an error message.
 
167
        
 
168
        @param msg error message to show (string or QString)
 
169
        """
 
170
        self.errors.insertPlainText(msg)
 
171
        self.errors.ensureCursorVisible()
 
172
        
 
173
    def __resort(self):
 
174
        """
 
175
        Private method to resort the tree.
 
176
        """
 
177
        self.tagList.sortItems(self.tagList.sortColumn(), 
 
178
            self.tagList.header().sortIndicatorOrder())
 
179
        
 
180
    def __resizeColumns(self):
 
181
        """
 
182
        Private method to resize the list columns.
 
183
        """
 
184
        self.tagList.header().resizeSections(QHeaderView.ResizeToContents)
 
185
        self.tagList.header().setStretchLastSection(True)
 
186
        
 
187
    def __generateItem(self, revision, author, date, name):
 
188
        """
 
189
        Private method to generate a tag item in the taglist.
 
190
        
 
191
        @param revision revision number (integer)
 
192
        @param author author of the tag (string or QString)
 
193
        @param date date of the tag (string or QString)
 
194
        @param name name (path) of the tag (string or QString)
 
195
        """
 
196
        itm = QTreeWidgetItem(self.tagList, 
 
197
            QStringList() << "%6d" % revision << author << date << name)
 
198
        itm.setTextAlignment(0, Qt.AlignRight)
 
199
        
 
200
    def getTagList(self):
 
201
        """
 
202
        Public method to get the taglist of the last run.
 
203
        
 
204
        @return list of tags (QStringList)
 
205
        """
 
206
        return self.tagsList