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");
|
||||||
|
@ -172,24 +173,24 @@ int CardDatabase::loadFromFile(const QString &fileName)
|
||||||
file.open(QIODevice::ReadOnly);
|
file.open(QIODevice::ReadOnly);
|
||||||
QDataStream in(&file);
|
QDataStream in(&file);
|
||||||
in.setVersion(QDataStream::Qt_4_4);
|
in.setVersion(QDataStream::Qt_4_4);
|
||||||
|
|
||||||
quint32 _magicNumber, _fileVersion, cardCount;
|
quint32 _magicNumber, _fileVersion, cardCount;
|
||||||
in >> _magicNumber
|
in >> _magicNumber
|
||||||
>> _fileVersion
|
>> _fileVersion
|
||||||
>> cardCount;
|
>> cardCount;
|
||||||
|
|
||||||
if (_magicNumber != magicNumber)
|
if (_magicNumber != magicNumber)
|
||||||
return -1;
|
return -1;
|
||||||
if (_fileVersion != fileVersion)
|
if (_fileVersion != fileVersion)
|
||||||
return -2;
|
return -2;
|
||||||
|
|
||||||
clear();
|
clear();
|
||||||
hash.reserve(cardCount);
|
hash.reserve(cardCount);
|
||||||
for (unsigned int i = 0; i < cardCount; i++) {
|
for (unsigned int i = 0; i < cardCount; i++) {
|
||||||
CardInfo *newCard = new CardInfo(in);
|
CardInfo *newCard = new CardInfo(in);
|
||||||
hash.insert(newCard->getName(), newCard);
|
hash.insert(newCard->getName(), newCard);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cardCount;
|
return cardCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,16 +200,16 @@ bool CardDatabase::saveToFile(const QString &fileName)
|
||||||
file.open(QIODevice::WriteOnly);
|
file.open(QIODevice::WriteOnly);
|
||||||
QDataStream out(&file);
|
QDataStream out(&file);
|
||||||
out.setVersion(QDataStream::Qt_4_4);
|
out.setVersion(QDataStream::Qt_4_4);
|
||||||
|
|
||||||
out << (quint32) magicNumber
|
out << (quint32) magicNumber
|
||||||
<< (quint32) fileVersion
|
<< (quint32) fileVersion
|
||||||
<< (quint32) hash.size();
|
<< (quint32) hash.size();
|
||||||
|
|
||||||
QHashIterator<QString, CardInfo *> i(hash);
|
QHashIterator<QString, CardInfo *> i(hash);
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
i.next();
|
i.next();
|
||||||
i.value()->saveToStream(out);
|
i.value()->saveToStream(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,9 +11,8 @@ 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) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue