Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Cockatrice
Commits
4444a0c1
Commit
4444a0c1
authored
Jun 16, 2011
by
Max-Wilhelm Bruker
Browse files
extra files
parent
6226e381
Changes
3
Show whitespace changes
Inline
Side-by-side
cockatrice/resources/icon_update.png
0 → 100644
View file @
4444a0c1
7.09 KB
cockatrice/src/priceupdater.cpp
0 → 100644
View file @
4444a0c1
/**
* @author Marcio Ribeiro <mmr@b1n.org>
* @version 1.0
*/
#include
<QNetworkAccessManager>
#include
<QNetworkReply>
#include
<QScriptEngine>
#include
<QScriptValueIterator>
#include
"priceupdater.h"
/**
* Constructor.
*
* @param _deck deck.
*/
PriceUpdater
::
PriceUpdater
(
const
DeckList
*
_deck
)
{
nam
=
new
QNetworkAccessManager
(
this
);
deck
=
_deck
;
}
/**
* Update the prices of the cards in deckList.
*/
void
PriceUpdater
::
updatePrices
()
{
QString
q
=
"http://blacklotusproject.com/json/?cards="
;
QStringList
cards
=
deck
->
getCardList
();
for
(
int
i
=
0
;
i
<
cards
.
size
();
++
i
)
{
q
+=
cards
[
i
]
+
"|"
;
}
QUrl
url
(
q
.
replace
(
' '
,
'+'
));
QNetworkReply
*
reply
=
nam
->
get
(
QNetworkRequest
(
url
));
connect
(
reply
,
SIGNAL
(
finished
()),
this
,
SLOT
(
downloadFinished
()));
}
/**
* Called when the download of the json file with the prices is finished.
*/
void
PriceUpdater
::
downloadFinished
()
{
QMap
<
QString
,
DecklistCardNode
*>
cmap
;
InnerDecklistNode
*
listRoot
=
deck
->
getRoot
();
for
(
int
i
=
0
;
i
<
listRoot
->
size
();
i
++
)
{
InnerDecklistNode
*
currentZone
=
dynamic_cast
<
InnerDecklistNode
*>
(
listRoot
->
at
(
i
));
for
(
int
j
=
0
;
j
<
currentZone
->
size
();
j
++
)
{
DecklistCardNode
*
currentCard
=
dynamic_cast
<
DecklistCardNode
*>
(
currentZone
->
at
(
j
));
if
(
!
currentCard
)
continue
;
cmap
.
insert
(
currentCard
->
getName
().
toLower
(),
currentCard
);
currentCard
->
setPrice
(
0
);
}
}
QNetworkReply
*
reply
=
static_cast
<
QNetworkReply
*>
(
sender
());
QByteArray
result
=
reply
->
readAll
();
QScriptValue
sc
;
QScriptEngine
engine
;
sc
=
engine
.
evaluate
(
"value = "
+
result
);
if
(
sc
.
property
(
"cards"
).
isArray
())
{
QScriptValueIterator
it
(
sc
.
property
(
"cards"
));
while
(
it
.
hasNext
())
{
it
.
next
();
QString
name
=
it
.
value
().
property
(
"name"
).
toString
().
toLower
();
float
price
=
it
.
value
().
property
(
"average"
).
toString
().
toFloat
();
DecklistCardNode
*
c
=
cmap
[
name
];
if
(
!
c
)
continue
;
if
(
c
->
getPrice
()
==
0
||
c
->
getPrice
()
>
price
)
{
c
->
setPrice
(
price
);
}
}
}
reply
->
deleteLater
();
deleteLater
();
emit
finishedUpdate
();
}
cockatrice/src/priceupdater.h
0 → 100644
View file @
4444a0c1
#ifndef PRICEUPDATER_H
#define PRICEUPDATER_H
#include
<QNetworkReply>
#include
"decklist.h"
class
QNetworkAccessManager
;
/**
* Price Updater.
*
* @author Marcio Ribeiro <mmr@b1n.org>
*/
class
PriceUpdater
:
public
QObject
{
Q_OBJECT
private:
const
DeckList
*
deck
;
QNetworkAccessManager
*
nam
;
signals:
void
finishedUpdate
();
private
slots
:
void
downloadFinished
();
public:
PriceUpdater
(
const
DeckList
*
deck
);
void
updatePrices
();
};
#endif
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment