This commit is contained in:
Max-Wilhelm Bruker 2009-05-23 02:43:28 +02:00
parent 175512a2ad
commit bb30012fbb
4 changed files with 31 additions and 25 deletions

View file

@ -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");

View file

@ -18,25 +18,29 @@ Client::Client(QObject *parent)
Client::~Client()
{
disconnectFromServer();
delete socket;
}
void Client::checkTimeout()
{
bool timeout = false;
QListIterator<PendingCommand *> 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();
}

View file

@ -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();
}

View file

@ -11,8 +11,7 @@ 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) { }
};