forked from qt-creator/qt-creator
Gerrit: Allow custom query
Change-Id: I8ee0967a8f0013c785bc4d6e98ff7b634f488e97 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
This commit is contained in:
committed by
Friedemann Kleint
parent
a8debd265f
commit
cb8c8ca19e
@@ -410,7 +410,7 @@ int GerritModel::indexOf(int gerritNumber) const
|
||||
return -1;
|
||||
}
|
||||
|
||||
void GerritModel::refresh()
|
||||
void GerritModel::refresh(const QString &query)
|
||||
{
|
||||
if (m_query) {
|
||||
qWarning("%s: Another query is still running", Q_FUNC_INFO);
|
||||
@@ -419,22 +419,27 @@ void GerritModel::refresh()
|
||||
clearData();
|
||||
|
||||
// Assemble list of queries
|
||||
const QString statusOpenQuery = QLatin1String("status:open");
|
||||
|
||||
QStringList queries;
|
||||
if (m_parameters->user.isEmpty()) {
|
||||
queries.push_back(statusOpenQuery);
|
||||
} else {
|
||||
// Owned by:
|
||||
queries.push_back(statusOpenQuery + QLatin1String(" owner:") + m_parameters->user);
|
||||
// For Review by:
|
||||
queries.push_back(statusOpenQuery + QLatin1String(" reviewer:") + m_parameters->user);
|
||||
}
|
||||
// Any custom queries?
|
||||
if (!m_parameters->additionalQueries.isEmpty()) {
|
||||
foreach (const QString &customQuery, m_parameters->additionalQueries.split(QString::SkipEmptyParts)) {
|
||||
if (!customQuery.trimmed().isEmpty())
|
||||
queries.push_back(customQuery);
|
||||
if (!query.trimmed().isEmpty())
|
||||
queries.push_back(query);
|
||||
else
|
||||
{
|
||||
const QString statusOpenQuery = QLatin1String("status:open");
|
||||
if (m_parameters->user.isEmpty()) {
|
||||
queries.push_back(statusOpenQuery);
|
||||
} else {
|
||||
// Owned by:
|
||||
queries.push_back(statusOpenQuery + QLatin1String(" owner:") + m_parameters->user);
|
||||
// For Review by:
|
||||
queries.push_back(statusOpenQuery + QLatin1String(" reviewer:") + m_parameters->user);
|
||||
}
|
||||
// Any custom queries?
|
||||
if (!m_parameters->additionalQueries.isEmpty()) {
|
||||
foreach (const QString &customQuery, m_parameters->additionalQueries.split(QString::SkipEmptyParts)) {
|
||||
if (!customQuery.trimmed().isEmpty())
|
||||
queries.push_back(customQuery);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -473,8 +478,9 @@ void GerritModel::clearData()
|
||||
|
||||
#if QT_VERSION >= 0x050000
|
||||
// Qt 5 using the QJsonDocument classes.
|
||||
static QList<GerritChangePtr> parseOutput(const QSharedPointer<GerritParameters> ¶meters,
|
||||
const QByteArray &output)
|
||||
static bool parseOutput(const QSharedPointer<GerritParameters> ¶meters,
|
||||
const QByteArray &output,
|
||||
QList<GerritChangePtr> &result)
|
||||
{
|
||||
// The output consists of separate lines containing a document each
|
||||
const QString typeKey = QLatin1String("type");
|
||||
@@ -498,7 +504,8 @@ static QList<GerritChangePtr> parseOutput(const QSharedPointer<GerritParameters>
|
||||
const QString approvalsTypeKey = QLatin1String("type");
|
||||
const QString approvalsDescriptionKey = QLatin1String("description");
|
||||
|
||||
QList<GerritChangePtr> result;
|
||||
bool res = true;
|
||||
result.clear();
|
||||
result.reserve(lines.size());
|
||||
|
||||
foreach (const QByteArray &line, lines) {
|
||||
@@ -507,8 +514,12 @@ static QList<GerritChangePtr> parseOutput(const QSharedPointer<GerritParameters>
|
||||
QJsonParseError error;
|
||||
const QJsonDocument doc = QJsonDocument::fromJson(line, &error);
|
||||
if (doc.isNull()) {
|
||||
qWarning("Parse error: '%s' -> %s", line.constData(),
|
||||
qPrintable(error.errorString()));
|
||||
QString errorMessage = GerritModel::tr("Parse error: '%1' -> %2")
|
||||
.arg(QString::fromLocal8Bit(line))
|
||||
.arg(error.errorString());
|
||||
qWarning() << errorMessage;
|
||||
VcsBase::VcsBaseOutputWindow::instance()->appendError(errorMessage);
|
||||
res = false;
|
||||
continue;
|
||||
}
|
||||
GerritChangePtr change(new GerritChange);
|
||||
@@ -554,10 +565,14 @@ static QList<GerritChangePtr> parseOutput(const QSharedPointer<GerritParameters>
|
||||
if (change->isValid()) {
|
||||
result.push_back(change);
|
||||
} else {
|
||||
qWarning("%s: Parse error in line '%s'.", Q_FUNC_INFO, line.constData());
|
||||
qWarning("%s: Parse error: '%s'.", Q_FUNC_INFO, line.constData());
|
||||
VcsBase::VcsBaseOutputWindow::instance()
|
||||
->appendError(GerritModel::tr("Parse error: '%1'")
|
||||
.arg(QString::fromLocal8Bit(line)));
|
||||
res = false;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return res;
|
||||
}
|
||||
#else // QT_VERSION >= 0x050000
|
||||
// Qt 4.8 using the Json classes from utils.
|
||||
@@ -588,8 +603,9 @@ static inline QString jsonStringMember(Utils::JsonObjectValue *object,
|
||||
return QString();
|
||||
}
|
||||
|
||||
static QList<GerritChangePtr> parseOutput(const QSharedPointer<GerritParameters> ¶meters,
|
||||
const QByteArray &output)
|
||||
static bool parseOutput(const QSharedPointer<GerritParameters> ¶meters,
|
||||
const QByteArray &output,
|
||||
QList<GerritChangePtr> &result)
|
||||
{
|
||||
// The output consists of separate lines containing a document each
|
||||
const QList<QByteArray> lines = output.split('\n');
|
||||
@@ -612,7 +628,8 @@ static QList<GerritChangePtr> parseOutput(const QSharedPointer<GerritParameters>
|
||||
const QString approvalsTypeKey = QLatin1String("type");
|
||||
const QString approvalsDescriptionKey = QLatin1String("description");
|
||||
const QString lastUpdatedKey = QLatin1String("lastUpdated");
|
||||
QList<GerritChangePtr> result;
|
||||
bool res = true;
|
||||
result.clear();
|
||||
result.reserve(lines.size());
|
||||
|
||||
foreach (const QByteArray &line, lines) {
|
||||
@@ -620,7 +637,11 @@ static QList<GerritChangePtr> parseOutput(const QSharedPointer<GerritParameters>
|
||||
continue;
|
||||
QScopedPointer<Utils::JsonValue> objectValue(Utils::JsonValue::create(QString::fromUtf8(line)));
|
||||
if (objectValue.isNull()) {
|
||||
qWarning("Parse error: '%s'", line.constData());
|
||||
QString errorMessage = GerritModel::tr("Parse error: '%1'")
|
||||
.arg(QString::fromLocal8Bit(line));
|
||||
qWarning() << errorMessage;
|
||||
VcsBase::VcsBaseOutputWindow::instance()->appendError(errorMessage);
|
||||
res = false;
|
||||
continue;
|
||||
}
|
||||
Utils::JsonObjectValue *object = objectValue->toObject();
|
||||
@@ -687,7 +708,11 @@ static QList<GerritChangePtr> parseOutput(const QSharedPointer<GerritParameters>
|
||||
if (change->isValid()) {
|
||||
result.push_back(change);
|
||||
} else {
|
||||
QString errorMessage = GerritModel::tr("Parse error in line '%1'")
|
||||
.arg(QString::fromLocal8Bit(line));
|
||||
VcsBase::VcsBaseOutputWindow::instance()->appendError(errorMessage);
|
||||
qWarning("%s: Parse error in line '%s'.", Q_FUNC_INFO, line.constData());
|
||||
res = false;
|
||||
}
|
||||
}
|
||||
if (debug) {
|
||||
@@ -695,7 +720,7 @@ static QList<GerritChangePtr> parseOutput(const QSharedPointer<GerritParameters>
|
||||
foreach (const GerritChangePtr &p, result)
|
||||
qDebug() << *p;
|
||||
}
|
||||
return result;
|
||||
return res;
|
||||
}
|
||||
#endif // QT_VERSION < 0x050000
|
||||
|
||||
@@ -707,7 +732,9 @@ bool changeDateLessThan(const GerritChangePtr &c1, const GerritChangePtr &c2)
|
||||
void GerritModel::queryFinished(const QByteArray &output)
|
||||
{
|
||||
const QDate today = QDate::currentDate();
|
||||
QList<GerritChangePtr> changes = parseOutput(m_parameters, output);
|
||||
QList<GerritChangePtr> changes;
|
||||
if (!parseOutput(m_parameters, output, changes))
|
||||
emit queryError();
|
||||
qStableSort(changes.begin(), changes.end(), changeDateLessThan);
|
||||
foreach (const GerritChangePtr &c, changes) {
|
||||
// Avoid duplicate entries for example in the (unlikely)
|
||||
@@ -744,15 +771,11 @@ void GerritModel::queryFinished(const QByteArray &output)
|
||||
row[ApprovalsColumn]->setText(c->currentPatchSet.approvalsColumn());
|
||||
// Mark changes awaiting action using a bold font.
|
||||
bool bold = false;
|
||||
switch (m_query->currentQuery()) {
|
||||
case 0: { // Owned changes: Review != 0,1. Submit or amend.
|
||||
if (c->owner == m_userName) { // Owned changes: Review != 0,1. Submit or amend.
|
||||
const int level = c->currentPatchSet.approvalLevel();
|
||||
bold = level != 0 && level != 1;
|
||||
}
|
||||
break;
|
||||
case 1: // Changes pending for review: No review yet.
|
||||
} else if (m_query->currentQuery() == 1) { // Changes pending for review: No review yet.
|
||||
bold = !m_userName.isEmpty() && !c->currentPatchSet.hasApproval(m_userName);
|
||||
break;
|
||||
}
|
||||
if (bold) {
|
||||
QFont font = row.first()->font();
|
||||
|
Reference in New Issue
Block a user