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
33
34
class CustomFunctionThread(QtCore.QThread):
41
42
self.target(*self.args)
44
class LogWindow(QtGui.QMainWindow):
45
class LogWindow(QBzrWindow):
46
47
def __init__(self, branch, location, specific_fileid, replace=None, parent=None):
47
QtGui.QMainWindow.__init__(self, parent)
50
title.append(location)
51
QBzrWindow.__init__(self, title, (710, 580), parent)
48
52
self.specific_fileid = specific_fileid
50
54
self.replace = replace
53
self.setWindowTitle(u"QBzr - Log - %s" % location)
55
self.setWindowTitle(u"QBzr - Log")
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()))
62
self.centralWidget = QtGui.QWidget(self)
63
self.setCentralWidget(self.centralWidget)
64
self.vboxlayout = QtGui.QVBoxLayout(self.centralWidget)
66
56
splitter = QtGui.QSplitter(QtCore.Qt.Vertical)
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)
126
115
self.fileList = QtGui.QListWidget(groupBox)
127
116
gridLayout.addWidget(self.fileList, 0, 2, 3, 1)
129
self.vboxlayout.addWidget(splitter)
131
self.hboxlayout = QtGui.QHBoxLayout()
132
self.hboxlayout.addStretch()
134
self.closeButton = QtGui.QPushButton(u"&Close", self)
135
self.hboxlayout.addWidget(self.closeButton)
137
self.vboxlayout.addLayout(self.hboxlayout)
139
self.connect(self.closeButton, QtCore.SIGNAL("clicked()"), self.close)
118
buttonbox = QtGui.QDialogButtonBox(
119
QtGui.QDialogButtonBox.StandardButtons(
120
QtGui.QDialogButtonBox.Close),
121
QtCore.Qt.Horizontal,
123
self.connect(buttonbox, QtCore.SIGNAL("rejected()"), self.close)
125
vbox = QtGui.QVBoxLayout(self.centralwidget)
126
vbox.addWidget(splitter)
127
vbox.addWidget(buttonbox)
140
128
self.windows = []
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)
148
for search, replace in self.replace:
149
message = re.sub(search, replace, message)
162
151
self.message.setHtml(message)
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()"))
287
class cmd_qlog(Command):
288
"""Show log of a branch, file, or directory in a Qt window.
290
By default show the log of the branch containing the working directory."""
292
takes_args = ['location?']
295
def run(self, location=None):
298
dir, path = BzrDir.open_containing(location)
299
branch = dir.open_branch()
302
inv = dir.open_workingtree().inventory
303
except (errors.NotBranchError, errors.NotLocalUrl):
304
inv = branch.basis_tree().inventory
305
file_id = inv.path2id(path)
307
dir, path = BzrDir.open_containing('.')
308
branch = dir.open_branch()
310
config = branch.get_config()
311
replace = config.get_user_option("qlog_replace")
313
replace = replace.split("\n")
314
replace = [tuple(replace[2*i:2*i+2])
315
for i in range(len(replace) // 2)]
317
app = QtGui.QApplication(sys.argv)
318
window = LogWindow(branch, location, file_id, replace)
323
register_command(cmd_qlog)