2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "perforcesubmiteditor.h"
|
|
|
|
|
#include "perforcesubmiteditorwidget.h"
|
|
|
|
|
#include "perforceplugin.h"
|
|
|
|
|
#include "perforceconstants.h"
|
|
|
|
|
|
2009-01-12 17:44:04 +01:00
|
|
|
#include <vcsbase/submitfilemodel.h>
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
namespace Perforce {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2009-01-12 17:44:04 +01:00
|
|
|
enum { FileSpecRole = Qt::UserRole + 1 };
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
PerforceSubmitEditor::PerforceSubmitEditor(const VcsBase::VcsBaseSubmitEditorParameters *parameters, QWidget *parent) :
|
|
|
|
|
VcsBaseSubmitEditor(parameters, new PerforceSubmitEditorWidget(parent)),
|
|
|
|
|
m_fileModel(new VcsBase::SubmitFileModel(this))
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
setDisplayName(tr("Perforce Submit"));
|
2009-01-12 17:44:04 +01:00
|
|
|
setFileModel(m_fileModel);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PerforceSubmitEditorWidget *PerforceSubmitEditor::submitEditorWidget()
|
|
|
|
|
{
|
|
|
|
|
return static_cast<PerforceSubmitEditorWidget *>(widget());
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-21 09:30:56 +00:00
|
|
|
QByteArray PerforceSubmitEditor::fileContents() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
const_cast<PerforceSubmitEditor*>(this)->updateEntries();
|
|
|
|
|
QString text;
|
|
|
|
|
QTextStream out(&text);
|
|
|
|
|
QMapIterator<QString, QString> it(m_entries);
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
|
it.next();
|
|
|
|
|
out << it.key() << ":" << it.value();
|
|
|
|
|
}
|
|
|
|
|
if (Perforce::Constants::debug)
|
|
|
|
|
qDebug() << Q_FUNC_INFO << text;
|
2011-10-21 09:30:56 +00:00
|
|
|
return text.toLocal8Bit();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PerforceSubmitEditor::setFileContents(const QString &contents)
|
|
|
|
|
{
|
|
|
|
|
if (Perforce::Constants::debug)
|
|
|
|
|
qDebug() << Q_FUNC_INFO << contents;
|
|
|
|
|
if (!parseText(contents))
|
|
|
|
|
return false;
|
|
|
|
|
updateFields();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PerforceSubmitEditor::parseText(QString text)
|
|
|
|
|
{
|
2012-04-30 12:01:15 +02:00
|
|
|
QRegExp formField(QLatin1String("^\\S+:"));
|
2008-12-02 12:01:29 +01:00
|
|
|
const QString newLine = QString(QLatin1Char('\n'));
|
|
|
|
|
|
|
|
|
|
int match;
|
|
|
|
|
int matchLen;
|
|
|
|
|
QTextStream stream(&text, QIODevice::ReadOnly);
|
|
|
|
|
QString line;
|
|
|
|
|
QString key;
|
|
|
|
|
QString value;
|
|
|
|
|
line = stream.readLine();
|
|
|
|
|
while (!stream.atEnd()) {
|
|
|
|
|
match = formField.indexIn(line);
|
|
|
|
|
if (match == 0) {
|
|
|
|
|
matchLen = formField.matchedLength();
|
|
|
|
|
key = line.left(matchLen-1);
|
|
|
|
|
value = line.mid(matchLen) + newLine;
|
|
|
|
|
while (!stream.atEnd()) {
|
|
|
|
|
line = stream.readLine();
|
|
|
|
|
if (formField.indexIn(line) != -1)
|
|
|
|
|
break;
|
|
|
|
|
value += line + newLine;
|
|
|
|
|
}
|
|
|
|
|
m_entries.insert(key, value);
|
|
|
|
|
} else {
|
|
|
|
|
line = stream.readLine();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PerforceSubmitEditor::restrictToProjectFiles(const QStringList &knownProjectFiles)
|
|
|
|
|
{
|
2013-01-02 22:19:04 +02:00
|
|
|
m_fileModel->filterFiles(knownProjectFiles);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PerforceSubmitEditor::updateFields()
|
|
|
|
|
{
|
|
|
|
|
PerforceSubmitEditorWidget *widget = submitEditorWidget();
|
|
|
|
|
widget->setData(m_entries.value(QLatin1String("Change")).trimmed(),
|
|
|
|
|
m_entries.value(QLatin1String("Client")).trimmed(),
|
|
|
|
|
m_entries.value(QLatin1String("User")).trimmed());
|
|
|
|
|
|
|
|
|
|
const QString newLine = QString(QLatin1Char('\n'));
|
|
|
|
|
QStringList lines = m_entries.value(QLatin1String("Description")).split(newLine);
|
|
|
|
|
lines.removeFirst(); // that is the line break after 'Description:'
|
|
|
|
|
lines.removeLast(); // that is the empty line at the end
|
|
|
|
|
|
|
|
|
|
const QRegExp leadingTabPattern = QRegExp(QLatin1String("^\\t"));
|
2011-07-29 12:00:11 +02:00
|
|
|
QTC_CHECK(leadingTabPattern.isValid());
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
lines.replaceInStrings(leadingTabPattern, QString());
|
|
|
|
|
widget->setDescriptionText(lines.join(newLine));
|
|
|
|
|
|
|
|
|
|
lines = m_entries.value(QLatin1String("Files")).split(newLine);
|
2009-01-12 17:44:04 +01:00
|
|
|
// split up "file#add" and store complete spec line as user data
|
|
|
|
|
foreach (const QString &specLine, lines) {
|
|
|
|
|
const QStringList list = specLine.split(QLatin1Char('#'));
|
|
|
|
|
if (list.size() == 2) {
|
|
|
|
|
const QString file = list.at(0).trimmed();
|
|
|
|
|
const QString state = list.at(1).trimmed();
|
|
|
|
|
m_fileModel->addFile(file, state).at(0)->setData(specLine, FileSpecRole);
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PerforceSubmitEditor::updateEntries()
|
|
|
|
|
{
|
|
|
|
|
const QString newLine = QString(QLatin1Char('\n'));
|
|
|
|
|
const QString tab = QString(QLatin1Char('\t'));
|
|
|
|
|
|
2009-03-20 16:02:14 +01:00
|
|
|
QStringList lines = submitEditorWidget()->descriptionText().split(newLine);
|
2009-03-20 16:52:22 +01:00
|
|
|
|
|
|
|
|
while (!lines.empty() && lines.last().isEmpty())
|
|
|
|
|
lines.removeLast();
|
2008-12-02 12:01:29 +01:00
|
|
|
// Description
|
|
|
|
|
lines.replaceInStrings(QRegExp(QLatin1String("^")), tab);
|
|
|
|
|
m_entries.insert(QLatin1String("Description"), newLine + lines.join(newLine) + QLatin1String("\n\n"));
|
|
|
|
|
QString files = newLine;
|
2009-01-12 17:44:04 +01:00
|
|
|
// Re-build the file spec '<tab>file#add' from the user data
|
|
|
|
|
const int count = m_fileModel->rowCount();
|
|
|
|
|
for (int r = 0; r < count; r++) {
|
|
|
|
|
const QStandardItem *item = m_fileModel->item(r, 0);
|
|
|
|
|
if (item->checkState() == Qt::Checked) {
|
|
|
|
|
files += item->data(FileSpecRole).toString();
|
|
|
|
|
files += newLine;
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
files += newLine;
|
|
|
|
|
m_entries.insert(QLatin1String("Files"), files);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 16:19:05 +01:00
|
|
|
} // Internal
|
|
|
|
|
} // Perforce
|