~qbzr-dev/qbzr/0.21

« back to all changes in this revision

Viewing changes to log.py

  • Committer: Lukas Lalinsky
  • Date: 2007-03-09 10:52:10 UTC
  • Revision ID: lalinsky@gmail.com-20070309105210-4cfmz39cnsvshr62
Add Windows installer.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
from bzrlib.errors import NotVersionedError, BzrCommandError, NoSuchFile
29
29
from bzrlib.log import get_view_revisions, _enumerate_history
30
30
from bzrlib.plugins.qbzr.diff import DiffWindow
 
31
from bzrlib.plugins.qbzr.util import QBzrWindow
31
32
 
32
33
 
33
34
class CustomFunctionThread(QtCore.QThread):
41
42
        self.target(*self.args)
42
43
 
43
44
 
44
 
class LogWindow(QtGui.QMainWindow):
 
45
class LogWindow(QBzrWindow):
45
46
 
46
47
    def __init__(self, branch, location, specific_fileid, replace=None, parent=None):
47
 
        QtGui.QMainWindow.__init__(self, parent)
 
48
        title = ["Log"]
 
49
        if location:
 
50
            title.append(location)
 
51
        QBzrWindow.__init__(self, title, (710, 580), parent)
48
52
        self.specific_fileid = specific_fileid
49
53
 
50
54
        self.replace = replace
51
55
 
52
 
        if location:
53
 
            self.setWindowTitle(u"QBzr - Log - %s" % location)
54
 
        else:
55
 
            self.setWindowTitle(u"QBzr - Log")
56
 
        icon = QtGui.QIcon()
57
 
        icon.addFile(":/bzr-16.png", QtCore.QSize(16, 16))
58
 
        icon.addFile(":/bzr-48.png", QtCore.QSize(48, 48))
59
 
        self.setWindowIcon(icon)
60
 
        self.resize(QtCore.QSize(710, 580).expandedTo(self.minimumSizeHint()))
61
 
 
62
 
        self.centralWidget = QtGui.QWidget(self)
63
 
        self.setCentralWidget(self.centralWidget)
64
 
        self.vboxlayout = QtGui.QVBoxLayout(self.centralWidget)
65
 
 
66
56
        splitter = QtGui.QSplitter(QtCore.Qt.Vertical)
67
57
 
68
58
        groupBox = QtGui.QGroupBox(u"Log", splitter)
118
108
        gridLayout.addWidget(QtGui.QLabel(u"Message:", groupBox), 2, 0)
119
109
        self.message = QtGui.QTextDocument()
120
110
        self.message_browser = QtGui.QTextBrowser(groupBox)
121
 
        if hasattr(self.message_browser, "setOpenExternalLinks"):
122
 
            self.message_browser.setOpenExternalLinks(True)
 
111
        self.message_browser.setOpenExternalLinks(True)
123
112
        self.message_browser.setDocument(self.message)
124
113
        gridLayout.addWidget(self.message_browser, 2, 1)
125
114
 
126
115
        self.fileList = QtGui.QListWidget(groupBox)
127
116
        gridLayout.addWidget(self.fileList, 0, 2, 3, 1)
128
 
        
129
 
        self.vboxlayout.addWidget(splitter)
130
 
        
131
 
        self.hboxlayout = QtGui.QHBoxLayout()
132
 
        self.hboxlayout.addStretch()
133
 
 
134
 
        self.closeButton = QtGui.QPushButton(u"&Close", self)
135
 
        self.hboxlayout.addWidget(self.closeButton)
136
 
 
137
 
        self.vboxlayout.addLayout(self.hboxlayout)
138
 
        
139
 
        self.connect(self.closeButton, QtCore.SIGNAL("clicked()"), self.close)
 
117
 
 
118
        buttonbox = QtGui.QDialogButtonBox(
 
119
            QtGui.QDialogButtonBox.StandardButtons(
 
120
                QtGui.QDialogButtonBox.Close),
 
121
            QtCore.Qt.Horizontal,
 
122
            self.centralwidget)
 
123
        self.connect(buttonbox, QtCore.SIGNAL("rejected()"), self.close)
 
124
 
 
125
        vbox = QtGui.QVBoxLayout(self.centralwidget)
 
126
        vbox.addWidget(splitter)
 
127
        vbox.addWidget(buttonbox)
140
128
        self.windows = []
141
129
 
142
130
    def closeEvent(self, event):
156
144
        message = re.sub(r"([\s>])(https?)://([^\s<>{}()]+[^\s.,<>{}()])", "\\1<a href=\"\\2://\\3\">\\2://\\3</a>", message)
157
145
        message = re.sub(r"(\s)www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[^ <>{}()\n\r]*[^., <>{}()\n\r]?)?)", "\\1<a href=\"http://www.\\2.\\3\\4\">www.\\2.\\3\\4</a>", message)
158
146
        message = re.sub(r"([a-z0-9_\-.]+@[a-z0-9_\-.]+)", '<a href="mailto:\\1">\\1</a>', message)
159
 
        for search, replace in self.replace:
160
 
            message = re.sub(search, replace, message)
 
147
        if self.replace:
 
148
            for search, replace in self.replace:
 
149
                message = re.sub(search, replace, message)
161
150
 
162
151
        self.message.setHtml(message)
163
152
 
282
271
             izip(view_revisions, iter_revisions()): 
283
272
            self.log_queue.put((revno, rev, delta, merge_depth))
284
273
            self.emit(QtCore.SIGNAL("log_entry_loaded()"))
285
 
 
286
 
 
287
 
class cmd_qlog(Command):
288
 
    """Show log of a branch, file, or directory in a Qt window.
289
 
 
290
 
    By default show the log of the branch containing the working directory."""
291
 
 
292
 
    takes_args = ['location?']
293
 
    takes_options = []
294
 
 
295
 
    def run(self, location=None):
296
 
        file_id = None
297
 
        if location:
298
 
            dir, path = BzrDir.open_containing(location)
299
 
            branch = dir.open_branch()
300
 
            if path:
301
 
                try:
302
 
                    inv = dir.open_workingtree().inventory
303
 
                except (errors.NotBranchError, errors.NotLocalUrl):
304
 
                    inv = branch.basis_tree().inventory
305
 
                file_id = inv.path2id(path)
306
 
        else:
307
 
            dir, path = BzrDir.open_containing('.')
308
 
            branch = dir.open_branch()
309
 
 
310
 
        config = branch.get_config()
311
 
        replace = config.get_user_option("qlog_replace")
312
 
        if replace:
313
 
            replace = replace.split("\n")
314
 
            replace = [tuple(replace[2*i:2*i+2])
315
 
                       for i in range(len(replace) // 2)]
316
 
 
317
 
        app = QtGui.QApplication(sys.argv)
318
 
        window = LogWindow(branch, location, file_id, replace)
319
 
        window.show()
320
 
        app.exec_()
321
 
 
322
 
 
323
 
register_command(cmd_qlog)