Purpose

reviewboardrc.cpp
1/*
2 SPDX-FileCopyrightText: 2015 Aleix Pol Gonzalez <aleixpol@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "reviewboardrc.h"
8#include <QDebug>
9#include <QFile>
10#include <QHash>
11#include <QRegularExpression>
12#include <QTextStream>
13
14ReviewboardRC::ReviewboardRC(QObject *parent)
15 : QObject(parent)
16{
17}
18
19void ReviewboardRC::setPath(const QUrl &filePath)
20{
21 if (filePath == m_path || !filePath.isLocalFile()) {
22 return;
23 }
24
25 // The .reviewboardrc files are python files, we'll read and if it doesn't work
26 // Well bad luck. See: http://www.reviewboard.org/docs/rbtools/dev/rbt/configuration/
27
28 QFile f(filePath.toLocalFile());
29 if (!f.open(QFile::ReadOnly | QFile::Text)) {
30 qWarning() << "couldn't open" << filePath;
31 return;
32 }
33
34 const QRegularExpression rx(QRegularExpression::anchoredPattern(QStringLiteral("([\\w]+) *= *[\"'](.*)[\"']")));
36 QTextStream stream(&f);
37 while (!stream.atEnd()) {
38 QRegularExpressionMatch match = rx.match(stream.readLine());
39 if (match.hasMatch()) {
40 values.insert(match.captured(1), match.captured(2));
41 }
42 }
43
44 if (values.contains(QStringLiteral("REVIEWBOARD_URL"))) {
45 m_server = QUrl(values[QStringLiteral("REVIEWBOARD_URL")]);
46 }
47 if (values.contains(QStringLiteral("REPOSITORY"))) {
48 m_repository = values[QStringLiteral("REPOSITORY")];
49 }
50 addExtraData(QStringLiteral("target_groups"), values[QStringLiteral("TARGET_GROUPS")]);
51 addExtraData(QStringLiteral("target_people"), values[QStringLiteral("TARGET_PEOPLE")]);
52 addExtraData(QStringLiteral("branch"), values[QStringLiteral("BRANCH")]);
53
54 Q_EMIT dataChanged();
55}
56
57void ReviewboardRC::addExtraData(const QString &key, const QString &value)
58{
59 if (!value.isEmpty()) {
60 m_extraData.insert(key, value);
61 }
62}
63
64#include "moc_reviewboardrc.cpp"
KCOREADDONS_EXPORT Result match(QStringView pattern, QStringView str)
bool contains(const Key &key) const const
iterator insert(const Key &key, const T &value)
iterator insert(QLatin1StringView key, const QJsonValue &value)
Q_EMITQ_EMIT
QString anchoredPattern(QStringView expression)
bool isEmpty() const const
bool isLocalFile() const const
QString toLocalFile() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:06 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.