foo
This commit is contained in:
parent
175512a2ad
commit
bb30012fbb
4 changed files with 31 additions and 25 deletions
|
@ -45,10 +45,11 @@ QPixmap *CardInfo::getPixmap()
|
||||||
}
|
}
|
||||||
qDebug(QString("CardDatabase: loading pixmap for %1").arg(getName()).toLatin1());
|
qDebug(QString("CardDatabase: loading pixmap for %1").arg(getName()).toLatin1());
|
||||||
for (int i = 0; i < editions.size(); i++) {
|
for (int i = 0; i < editions.size(); i++) {
|
||||||
/* Fire // Ice */
|
// Fire // Ice, Circle of Protection: Red
|
||||||
if (pixmap->load(QString("../pics/%1/%2.full.jpg").arg(editions.at(i)).arg(getName().replace(" // ", ""))))
|
QString correctedName = getName().remove(" // ").remove(":");
|
||||||
|
if (pixmap->load(QString("../pics/%1/%2.full.jpg").arg(editions.at(i)).arg(correctedName)))
|
||||||
return pixmap;
|
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;
|
return pixmap;
|
||||||
}
|
}
|
||||||
pixmap->load("../pics/none.jpg");
|
pixmap->load("../pics/none.jpg");
|
||||||
|
|
|
@ -18,25 +18,29 @@ Client::Client(QObject *parent)
|
||||||
|
|
||||||
Client::~Client()
|
Client::~Client()
|
||||||
{
|
{
|
||||||
|
disconnectFromServer();
|
||||||
delete socket;
|
delete socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::checkTimeout()
|
void Client::checkTimeout()
|
||||||
{
|
{
|
||||||
|
bool timeout = false;
|
||||||
QListIterator<PendingCommand *> i(PendingCommands);
|
QListIterator<PendingCommand *> i(PendingCommands);
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
PendingCommand *c = i.next();
|
PendingCommand *c = i.next();
|
||||||
c->incTime();
|
|
||||||
if (c->timeout()) {
|
if (c->timeout()) {
|
||||||
disconnectFromServer();
|
timeout = true;
|
||||||
emit serverTimeout();
|
break;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ping();
|
if (timeout) {
|
||||||
|
disconnectFromServer();
|
||||||
|
emit serverTimeout();
|
||||||
|
} else
|
||||||
|
ping();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::slotSocketError(QAbstractSocket::SocketError error)
|
void Client::slotSocketError(QAbstractSocket::SocketError /*error*/)
|
||||||
{
|
{
|
||||||
emit logSocketError(socket->errorString());
|
emit logSocketError(socket->errorString());
|
||||||
disconnectFromServer();
|
disconnectFromServer();
|
||||||
|
@ -108,7 +112,8 @@ void Client::readLine()
|
||||||
if (found) {
|
if (found) {
|
||||||
PendingCommands.removeAt(PendingCommands.indexOf(c));
|
PendingCommands.removeAt(PendingCommands.indexOf(c));
|
||||||
delete c;
|
delete c;
|
||||||
}
|
} else
|
||||||
|
qDebug(QString("msgid unknown: %1").arg(msgid).toLatin1());
|
||||||
|
|
||||||
emit responseReceived(new ServerResponse(msgid, ok, message));
|
emit responseReceived(new ServerResponse(msgid, ok, message));
|
||||||
} else if (!(prefix.compare("list_games")
|
} else if (!(prefix.compare("list_games")
|
||||||
|
@ -179,7 +184,6 @@ void Client::msg(const QString &s)
|
||||||
stream.setCodec("UTF-8");
|
stream.setCodec("UTF-8");
|
||||||
stream << s << endl;
|
stream << s << endl;
|
||||||
stream.flush();
|
stream.flush();
|
||||||
socket->flush();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Client::cmd(const QString &s)
|
int Client::cmd(const QString &s)
|
||||||
|
@ -200,7 +204,11 @@ void Client::connectToServer(const QString &hostname, unsigned int port, const Q
|
||||||
void Client::disconnectFromServer()
|
void Client::disconnectFromServer()
|
||||||
{
|
{
|
||||||
timer->stop();
|
timer->stop();
|
||||||
|
|
||||||
|
for (int i = 0; i < PendingCommands.size(); i++)
|
||||||
|
delete PendingCommands[i];
|
||||||
PendingCommands.clear();
|
PendingCommands.clear();
|
||||||
|
|
||||||
setStatus(StatusDisconnected);
|
setStatus(StatusDisconnected);
|
||||||
socket->close();
|
socket->close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,16 +13,14 @@ QRectF Counter::boundingRect() const
|
||||||
return QRectF(0, 0, 40, 40);
|
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->save();
|
||||||
painter->setBrush(QBrush(color));
|
painter->setBrush(QBrush(color));
|
||||||
painter->drawEllipse(boundingRect());
|
painter->drawEllipse(boundingRect());
|
||||||
if (value) {
|
if (value) {
|
||||||
painter->setFont(QFont("Times", 16, QFont::Bold));
|
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();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,7 @@ private:
|
||||||
public:
|
public:
|
||||||
int getMsgId() const { return msgid; }
|
int getMsgId() const { return msgid; }
|
||||||
QString getCmd() const { return cmd; }
|
QString getCmd() const { return cmd; }
|
||||||
bool timeout() const { return time > 5; }
|
bool timeout() { return ++time > 5; }
|
||||||
void incTime() { ++time; }
|
|
||||||
PendingCommand(const QString &_cmd, int _msgid) : cmd(_cmd), msgid(_msgid), time(0) { }
|
PendingCommand(const QString &_cmd, int _msgid) : cmd(_cmd), msgid(_msgid), time(0) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue