From bb30012fbbdb723779e7dca4d4c5a44f30bdd0df Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Sat, 23 May 2009 02:43:28 +0200 Subject: [PATCH] foo --- cockatrice/src/carddatabase.cpp | 21 +++++++++++---------- cockatrice/src/client.cpp | 24 ++++++++++++++++-------- cockatrice/src/counter.cpp | 6 ++---- cockatrice/src/pendingcommand.h | 5 ++--- 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/cockatrice/src/carddatabase.cpp b/cockatrice/src/carddatabase.cpp index 5d7062fe..647e1693 100644 --- a/cockatrice/src/carddatabase.cpp +++ b/cockatrice/src/carddatabase.cpp @@ -45,10 +45,11 @@ QPixmap *CardInfo::getPixmap() } qDebug(QString("CardDatabase: loading pixmap for %1").arg(getName()).toLatin1()); for (int i = 0; i < editions.size(); i++) { - /* Fire // Ice */ - if (pixmap->load(QString("../pics/%1/%2.full.jpg").arg(editions.at(i)).arg(getName().replace(" // ", "")))) + // Fire // Ice, Circle of Protection: Red + QString correctedName = getName().remove(" // ").remove(":"); + if (pixmap->load(QString("../pics/%1/%2.full.jpg").arg(editions.at(i)).arg(correctedName))) return pixmap; - if (pixmap->load(QString("../pics/%1/%2%3.full.jpg").arg(editions.at(i)).arg(getName().replace(" // ", "")).arg(1))) + if (pixmap->load(QString("../pics/%1/%2%3.full.jpg").arg(editions.at(i)).arg(correctedName).arg(1))) return pixmap; } pixmap->load("../pics/none.jpg"); @@ -172,24 +173,24 @@ int CardDatabase::loadFromFile(const QString &fileName) file.open(QIODevice::ReadOnly); QDataStream in(&file); in.setVersion(QDataStream::Qt_4_4); - + quint32 _magicNumber, _fileVersion, cardCount; in >> _magicNumber >> _fileVersion >> cardCount; - + if (_magicNumber != magicNumber) return -1; if (_fileVersion != fileVersion) return -2; - + clear(); hash.reserve(cardCount); for (unsigned int i = 0; i < cardCount; i++) { CardInfo *newCard = new CardInfo(in); hash.insert(newCard->getName(), newCard); } - + return cardCount; } @@ -199,16 +200,16 @@ bool CardDatabase::saveToFile(const QString &fileName) file.open(QIODevice::WriteOnly); QDataStream out(&file); out.setVersion(QDataStream::Qt_4_4); - + out << (quint32) magicNumber << (quint32) fileVersion << (quint32) hash.size(); - + QHashIterator i(hash); while (i.hasNext()) { i.next(); i.value()->saveToStream(out); } - + return true; } diff --git a/cockatrice/src/client.cpp b/cockatrice/src/client.cpp index a7d6b42a..fc903cbe 100644 --- a/cockatrice/src/client.cpp +++ b/cockatrice/src/client.cpp @@ -18,25 +18,29 @@ Client::Client(QObject *parent) Client::~Client() { + disconnectFromServer(); delete socket; } void Client::checkTimeout() { + bool timeout = false; QListIterator i(PendingCommands); while (i.hasNext()) { PendingCommand *c = i.next(); - c->incTime(); if (c->timeout()) { - disconnectFromServer(); - emit serverTimeout(); - return; + timeout = true; + break; } } - ping(); + if (timeout) { + disconnectFromServer(); + emit serverTimeout(); + } else + ping(); } -void Client::slotSocketError(QAbstractSocket::SocketError error) +void Client::slotSocketError(QAbstractSocket::SocketError /*error*/) { emit logSocketError(socket->errorString()); disconnectFromServer(); @@ -108,7 +112,8 @@ void Client::readLine() if (found) { PendingCommands.removeAt(PendingCommands.indexOf(c)); delete c; - } + } else + qDebug(QString("msgid unknown: %1").arg(msgid).toLatin1()); emit responseReceived(new ServerResponse(msgid, ok, message)); } else if (!(prefix.compare("list_games") @@ -179,7 +184,6 @@ void Client::msg(const QString &s) stream.setCodec("UTF-8"); stream << s << endl; stream.flush(); - socket->flush(); } int Client::cmd(const QString &s) @@ -200,7 +204,11 @@ void Client::connectToServer(const QString &hostname, unsigned int port, const Q void Client::disconnectFromServer() { timer->stop(); + + for (int i = 0; i < PendingCommands.size(); i++) + delete PendingCommands[i]; PendingCommands.clear(); + setStatus(StatusDisconnected); socket->close(); } diff --git a/cockatrice/src/counter.cpp b/cockatrice/src/counter.cpp index eb5ca676..9e460ec2 100644 --- a/cockatrice/src/counter.cpp +++ b/cockatrice/src/counter.cpp @@ -13,16 +13,14 @@ QRectF Counter::boundingRect() const return QRectF(0, 0, 40, 40); } -void Counter::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +void Counter::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) { - Q_UNUSED(option); - Q_UNUSED(widget); painter->save(); painter->setBrush(QBrush(color)); painter->drawEllipse(boundingRect()); if (value) { painter->setFont(QFont("Times", 16, QFont::Bold)); - painter->drawText(boundingRect(), Qt::AlignCenter, QString("%1").arg(value)); + painter->drawText(boundingRect(), Qt::AlignCenter, QString::number(value)); } painter->restore(); } diff --git a/cockatrice/src/pendingcommand.h b/cockatrice/src/pendingcommand.h index 212cb1ea..5c1f7ff3 100644 --- a/cockatrice/src/pendingcommand.h +++ b/cockatrice/src/pendingcommand.h @@ -11,9 +11,8 @@ private: public: int getMsgId() const { return msgid; } QString getCmd() const { return cmd; } - bool timeout() const { return time > 5; } - void incTime() { ++time; } + bool timeout() { return ++time > 5; } PendingCommand(const QString &_cmd, int _msgid) : cmd(_cmd), msgid(_msgid), time(0) { } }; - + #endif