1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
/*
* Copyright (C) 1999-2002 Bernd Gehrmann
* bernd@physik.hu-berlin.de
* Copyright (c) 2003-2007 Christian Loose <christian.loose@kdemail.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "protocolview.h"
#include "protocolviewadaptor.h"
#include <QAction>
#include <QContextMenuEvent>
#include <QMenu>
#include <KLocalizedString>
#include <kmessagebox.h>
#include "cervisiapart.h"
#include "cervisiasettings.h"
#include "cvsjobinterface.h"
#include "debug.h"
ProtocolView::ProtocolView(const QString &appId, QWidget *parent)
: QTextEdit(parent)
, job(0)
, m_isUpdateJob(false)
{
new ProtocolviewAdaptor(this);
QDBusConnection::sessionBus().registerObject("/ProtocolView", this);
setReadOnly(true);
setUndoRedoEnabled(false);
setTabChangesFocus(true);
// qCDebug(log_cervisia) << "protocol view appId :" << appId;
job = new OrgKdeCervisia5CvsserviceCvsjobInterface(appId, "/NonConcurrentJob", QDBusConnection::sessionBus(), this);
QDBusConnection::sessionBus()
.connect(QString(), "/NonConcurrentJob", "org.kde.cervisia5.cvsservice.cvsjob", "jobExited", this, SLOT(slotJobExited(bool, int)));
QDBusConnection::sessionBus()
.connect(QString(), "/NonConcurrentJob", "org.kde.cervisia5.cvsservice.cvsjob", "receivedStdout", this, SLOT(slotReceivedOutput(QString)));
QDBusConnection::sessionBus()
.connect(QString(), "/NonConcurrentJob", "org.kde.cervisia5.cvsservice.cvsjob", "receivedStderr", this, SLOT(slotReceivedOutput(QString)));
configChanged();
connect(CervisiaSettings::self(), SIGNAL(configChanged()), this, SLOT(configChanged()));
}
ProtocolView::~ProtocolView()
{
delete job;
}
bool ProtocolView::startJob(bool isUpdateJob)
{
m_isUpdateJob = isUpdateJob;
// get command line and add it to output buffer
QString cmdLine = job->cvsCommand();
buf += cmdLine;
buf += '\n';
processOutput();
// disconnect 3rd party slots from our signals
disconnect(SIGNAL(receivedLine(QString)));
disconnect(SIGNAL(jobFinished(bool, int)));
return job->execute();
}
void ProtocolView::contextMenuEvent(QContextMenuEvent *event)
{
QMenu *menu = QTextEdit::createStandardContextMenu();
QAction *clearAction = menu->addAction(i18n("Clear"), this, SLOT(clear()));
if (document()->isEmpty())
clearAction->setEnabled(false);
menu->exec(event->globalPos());
delete menu;
}
void ProtocolView::cancelJob()
{
qCDebug(log_cervisia);
job->cancel();
}
void ProtocolView::configChanged()
{
conflictColor = CervisiaSettings::conflictColor();
localChangeColor = CervisiaSettings::localChangeColor();
remoteChangeColor = CervisiaSettings::remoteChangeColor();
setFont(CervisiaSettings::protocolFont());
}
void ProtocolView::slotReceivedOutput(QString buffer)
{
buf += buffer;
processOutput();
}
void ProtocolView::slotJobExited(bool normalExit, int exitStatus)
{
qCDebug(log_cervisia);
QString msg;
if (normalExit) {
if (exitStatus)
msg = i18n("[Exited with status %1]\n", exitStatus);
else
msg = i18n("[Finished]\n");
} else
msg = i18n("[Aborted]\n");
buf += '\n';
buf += msg;
processOutput();
Q_EMIT jobFinished(normalExit, exitStatus);
}
void ProtocolView::processOutput()
{
int pos;
while ((pos = buf.indexOf('\n')) != -1) {
QString line = buf.left(pos);
if (!line.isEmpty()) {
appendLine(line);
Q_EMIT receivedLine(line);
}
buf = buf.right(buf.length() - pos - 1);
}
}
void ProtocolView::appendLine(const QString &line)
{
// Escape output line, so that html tags in commit
// messages aren't interpreted
const QString escapedLine = line.toHtmlEscaped();
// When we don't get the output from an update job then
// just add it to the text edit.
if (!m_isUpdateJob) {
appendHtml(escapedLine);
return;
}
QColor color;
// Colors are the same as in UpdateViewItem::paintCell()
if (line.startsWith(QLatin1String("C ")))
color = conflictColor;
else if (line.startsWith(QLatin1String("M ")) || line.startsWith(QLatin1String("A ")) || line.startsWith(QLatin1String("R ")))
color = localChangeColor;
else if (line.startsWith(QLatin1String("P ")) || line.startsWith(QLatin1String("U ")))
color = remoteChangeColor;
appendHtml(color.isValid() ? QString("<font color=\"%1\"><b>%2</b></font>").arg(color.name()).arg(escapedLine) : escapedLine);
}
void ProtocolView::appendHtml(const QString &html)
{
QTextCursor cursor(textCursor());
cursor.insertHtml(html);
cursor.insertBlock();
ensureCursorVisible();
}
// Local Variables:
// c-basic-offset: 4
// End:
|