mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-09 15:54:47 -07:00
Clang-format (#3028)
* 1/3 Add .clang-format file and travis compilation check * 2/3 Run clang-format * 3/3 Fix compilation problems due to include reordering * 3bis/3 AfterControlStatement: false
This commit is contained in:
parent
8dbdd24c8e
commit
b29bd9e070
272 changed files with 13378 additions and 9535 deletions
|
|
@ -1,17 +1,15 @@
|
|||
#include "tappedout_interface.h"
|
||||
#include "decklist.h"
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QRegExp>
|
||||
#include <QMessageBox>
|
||||
#include <QDesktopServices>
|
||||
#include <QMessageBox>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
#include <QRegExp>
|
||||
#include <QUrlQuery>
|
||||
|
||||
TappedOutInterface::TappedOutInterface(
|
||||
CardDatabase &_cardDatabase,
|
||||
QObject *parent
|
||||
) : QObject(parent), cardDatabase(_cardDatabase)
|
||||
TappedOutInterface::TappedOutInterface(CardDatabase &_cardDatabase, QObject *parent)
|
||||
: QObject(parent), cardDatabase(_cardDatabase)
|
||||
{
|
||||
manager = new QNetworkAccessManager(this);
|
||||
connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(queryFinished(QNetworkReply *)));
|
||||
|
|
@ -27,15 +25,14 @@ void TappedOutInterface::queryFinished(QNetworkReply *reply)
|
|||
}
|
||||
|
||||
int httpStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
if(reply->hasRawHeader("Location"))
|
||||
{
|
||||
if (reply->hasRawHeader("Location")) {
|
||||
/*
|
||||
* If the reply contains a "Location" header, a relative URL to the deck on TappedOut
|
||||
* can be extracted from the header. The http status is a 302 "redirect".
|
||||
*/
|
||||
QString deckUrl = reply->rawHeader("Location");
|
||||
qDebug() << "Tappedout: good reply, http status" << httpStatus << "location" << deckUrl;
|
||||
QDesktopServices::openUrl("http://tappedout.net" + deckUrl);
|
||||
QDesktopServices::openUrl("http://tappedout.net" + deckUrl);
|
||||
} else {
|
||||
/*
|
||||
* Otherwise, the deck has not been parsed correctly. Error messages can be extracted
|
||||
|
|
@ -43,25 +40,23 @@ void TappedOutInterface::queryFinished(QNetworkReply *reply)
|
|||
*/
|
||||
QString data(reply->readAll());
|
||||
QString errorMessage = tr("Unable to analyze the deck.");
|
||||
|
||||
|
||||
QRegExp rx("<div class=\"alert alert-danger.*<ul>(.*)</ul>");
|
||||
rx.setMinimal(true);
|
||||
int found = rx.indexIn(data);
|
||||
if (found >= 0)
|
||||
{
|
||||
if (found >= 0) {
|
||||
QString errors = rx.cap(1);
|
||||
QRegExp rx2("<li>(.*)</li>");
|
||||
rx2.setMinimal(true);
|
||||
|
||||
int captures = rx2.captureCount();
|
||||
for(int i = 1; i <= captures; i++)
|
||||
{
|
||||
for (int i = 1; i <= captures; i++) {
|
||||
errorMessage += QString("\n") + rx2.cap(i).remove(QRegExp("<[^>]*>")).simplified();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
qDebug() << "Tappedout: bad reply, http status" << httpStatus << "size" << data.size() << "message" << errorMessage;
|
||||
qDebug() << "Tappedout: bad reply, http status" << httpStatus << "size" << data.size() << "message"
|
||||
<< errorMessage;
|
||||
|
||||
QMessageBox::critical(0, tr("Error"), errorMessage);
|
||||
}
|
||||
|
|
@ -88,28 +83,29 @@ void TappedOutInterface::analyzeDeck(DeckList *deck)
|
|||
{
|
||||
QByteArray data;
|
||||
getAnalyzeRequestData(deck, &data);
|
||||
|
||||
|
||||
QNetworkRequest request(QUrl("http://tappedout.net/mtg-decks/paste/"));
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||
|
||||
|
||||
manager->post(request, data);
|
||||
}
|
||||
|
||||
struct CopyMainOrSide {
|
||||
struct CopyMainOrSide
|
||||
{
|
||||
CardDatabase &cardDatabase;
|
||||
DeckList &mainboard, &sideboard;
|
||||
|
||||
CopyMainOrSide(CardDatabase &_cardDatabase, DeckList &_mainboard, DeckList &_sideboard)
|
||||
: cardDatabase(_cardDatabase), mainboard(_mainboard), sideboard(_sideboard) {};
|
||||
: cardDatabase(_cardDatabase), mainboard(_mainboard), sideboard(_sideboard){};
|
||||
|
||||
void operator()(const InnerDecklistNode *node, const DecklistCardNode *card) const
|
||||
{
|
||||
CardInfo * dbCard = cardDatabase.getCard(card->getName());
|
||||
CardInfo *dbCard = cardDatabase.getCard(card->getName());
|
||||
if (!dbCard || dbCard->getIsToken())
|
||||
return;
|
||||
|
||||
DecklistCardNode *addedCard;
|
||||
if(node->getName() == DECK_ZONE_SIDE)
|
||||
if (node->getName() == DECK_ZONE_SIDE)
|
||||
addedCard = sideboard.addCard(card->getName(), node->getName());
|
||||
else
|
||||
addedCard = mainboard.addCard(card->getName(), node->getName());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue