message: Fix failure to get more than 20 repositories from GitLab
diff: #include <QNetworkAccessManager>
  #include <QNetworkReply>
  #include <QNetworkRequest>
  +#include <QRegularExpression>
  #include <QUrl>
  namespace {
  @@ -31,7 +32,13 @@ GitLab::GitLab(const QString &username)
  [this](QNetworkReply *reply) {
  reply->deleteLater();
  - if (reply->error() == QNetworkReply::NoError) {
  + if (reply->error() != QNetworkReply::NoError) {
  + mError->setText(tr("Connection failed"), reply->errorString());
  + mProgress->finish();
  + return;
  + }
  +
  + // Read repositories.
  QJsonArray array = QJsonDocument::fromJson(reply->readAll()).array();
  for (int i = 0; i < array.size(); ++i) {
  QJsonObject obj = array.at(i).toObject();
  @@ -44,11 +51,33 @@ GitLab::GitLab(const QString &username)
  repo->setUrl(Repository::Https, httpUrl);
  repo->setUrl(Repository::Ssh, sshUrl);
  }
  - } else {
  - mError->setText(tr("Connection failed"), reply->errorString());
  +
  + // Check for additional pages.
  + QString link = reply->rawHeader("Link");
  + if (link.isEmpty()) {
  + mProgress->finish();
  + return;
  }
  + QMap<QString,QString> map;
  + QRegularExpression re("<(.*)>; rel=\"(\\w+)\"");
  + foreach (const QString &record, link.split(", ")) {
  + QRegularExpressionMatch match = re.match(record);
  + if (match.isValid() && match.hasMatch())
  + map.insert(match.captured(2), match.captured(1));
  + }
  +
  + QString next = map.value("next");
  + if (next.isEmpty()) {
  mProgress->finish();
  + return;
  + }
  +
  + // Request next page.
  + QNetworkRequest request(next);
  + request.setHeader(QNetworkRequest::ContentTypeHeader, kContentType);
  + mMgr.get(request);
  + startProgress();
  });
  }
  