Changeset View
Changeset View
Standalone View
Standalone View
src/plugins/reviewboard/quick/reviewboardrc.cpp
Show All 12 Lines | |||||
13 | * | 13 | * | ||
14 | * You should have received a copy of the GNU General Public | 14 | * You should have received a copy of the GNU General Public | ||
15 | * License along with this program; if not, write to the | 15 | * License along with this program; if not, write to the | ||
16 | * Free Software Foundation, Inc., | 16 | * Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "reviewboardrc.h" | 20 | #include "reviewboardrc.h" | ||
21 | #include <QRegExp> | 21 | #include <QRegularExpression> | ||
22 | #include <QFile> | 22 | #include <QFile> | ||
23 | #include <QHash> | 23 | #include <QHash> | ||
24 | #include <QTextStream> | 24 | #include <QTextStream> | ||
25 | #include <QDebug> | 25 | #include <QDebug> | ||
26 | 26 | | |||
27 | ReviewboardRC::ReviewboardRC(QObject* parent) | 27 | ReviewboardRC::ReviewboardRC(QObject* parent) | ||
28 | : QObject(parent) | 28 | : QObject(parent) | ||
29 | {} | 29 | {} | ||
30 | 30 | | |||
31 | void ReviewboardRC::setPath(const QUrl &filePath) | 31 | void ReviewboardRC::setPath(const QUrl &filePath) | ||
32 | { | 32 | { | ||
33 | if (filePath == m_path || !filePath.isLocalFile()) | 33 | if (filePath == m_path || !filePath.isLocalFile()) | ||
34 | return; | 34 | return; | ||
35 | 35 | | |||
36 | //The .reviewboardrc files are python files, we'll read and if it doesn't work | 36 | //The .reviewboardrc files are python files, we'll read and if it doesn't work | ||
37 | //Well bad luck. See: http://www.reviewboard.org/docs/rbtools/dev/rbt/configuration/ | 37 | //Well bad luck. See: http://www.reviewboard.org/docs/rbtools/dev/rbt/configuration/ | ||
38 | 38 | | |||
39 | QRegExp rx(QStringLiteral("([\\w_]+) *= *[\"'](.*)[\"']")); | | |||
40 | QFile f(filePath.toLocalFile()); | 39 | QFile f(filePath.toLocalFile()); | ||
41 | if(!f.open(QFile::ReadOnly | QFile::Text)) { | 40 | if(!f.open(QFile::ReadOnly | QFile::Text)) { | ||
42 | qWarning() << "couldn't open" << filePath; | 41 | qWarning() << "couldn't open" << filePath; | ||
43 | return; | 42 | return; | ||
44 | } | 43 | } | ||
45 | 44 | | |||
45 | const QRegularExpression rx(QRegularExpression::anchoredPattern(QStringLiteral("([\\w]+) *= *[\"'](.*)[\"']"))); | ||||
46 | QHash<QString, QString> values; | 46 | QHash<QString, QString> values; | ||
47 | QTextStream stream(&f); | 47 | QTextStream stream(&f); | ||
48 | for(; !stream.atEnd(); ) { | 48 | for(; !stream.atEnd(); ) { | ||
49 | if(rx.exactMatch(stream.readLine())) { | 49 | QRegularExpressionMatch match = rx.match(stream.readLine()); | ||
50 | values.insert(rx.cap(1), rx.cap(2)); | 50 | if(match.hasMatch()) { | ||
51 | values.insert(match.captured(1), match.captured(2)); | ||||
51 | } | 52 | } | ||
52 | } | 53 | } | ||
53 | 54 | | |||
54 | if(values.contains(QStringLiteral("REVIEWBOARD_URL"))) | 55 | if(values.contains(QStringLiteral("REVIEWBOARD_URL"))) | ||
55 | m_server = QUrl(values[QStringLiteral("REVIEWBOARD_URL")]); | 56 | m_server = QUrl(values[QStringLiteral("REVIEWBOARD_URL")]); | ||
56 | if(values.contains(QStringLiteral("REPOSITORY"))) | 57 | if(values.contains(QStringLiteral("REPOSITORY"))) | ||
57 | m_repository = values[QStringLiteral("REPOSITORY")]; | 58 | m_repository = values[QStringLiteral("REPOSITORY")]; | ||
58 | addExtraData(QStringLiteral("target_groups"), values[QStringLiteral("TARGET_GROUPS")]); | 59 | addExtraData(QStringLiteral("target_groups"), values[QStringLiteral("TARGET_GROUPS")]); | ||
Show All 11 Lines |