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
df8c0199
Commit
df8c0199
authored
Oct 13, 2009
by
Max-Wilhelm Bruker
Browse files
fixed card picture download
parent
912c0bcd
Changes
2
Hide whitespace changes
Inline
Side-by-side
cockatrice/src/carddatabase.cpp
View file @
df8c0199
...
@@ -138,50 +138,10 @@ QPixmap *CardInfo::loadPixmap()
...
@@ -138,50 +138,10 @@ QPixmap *CardInfo::loadPixmap()
return
pixmap
;
return
pixmap
;
}
}
if
(
db
->
getPicDownload
())
if
(
db
->
getPicDownload
())
startDownload
();
db
->
start
Pic
Download
(
this
);
return
pixmap
;
return
pixmap
;
}
}
void
CardInfo
::
startDownload
()
{
downloadBuffer
=
new
QBuffer
(
this
);
downloadBuffer
->
open
(
QIODevice
::
ReadWrite
);
http
=
new
QHttp
(
this
);
connect
(
http
,
SIGNAL
(
requestFinished
(
int
,
bool
)),
this
,
SLOT
(
picDownloadFinished
(
int
,
bool
)));
QUrl
url
(
picURL
);
http
->
setHost
(
url
.
host
(),
url
.
port
(
80
));
dlID
=
http
->
get
(
url
.
path
(),
downloadBuffer
);
}
void
CardInfo
::
picDownloadFinished
(
int
id
,
bool
error
)
{
if
(
id
!=
dlID
)
return
;
http
->
close
();
disconnect
(
http
,
0
,
this
,
0
);
http
->
deleteLater
();
downloadBuffer
->
close
();
if
(
!
error
)
{
QString
picsPath
=
db
->
getPicsPath
();
const
QByteArray
&
picData
=
downloadBuffer
->
data
();
QPixmap
testPixmap
;
if
(
testPixmap
.
loadFromData
(
picData
))
{
if
(
!
QDir
(
QString
(
picsPath
+
"/downloadedPics/"
)).
exists
())
{
QDir
dir
(
picsPath
);
dir
.
mkdir
(
"downloadedPics"
);
}
QFile
newPic
(
picsPath
+
"/downloadedPics/"
+
getCorrectedName
()
+
".full.jpg"
);
newPic
.
open
(
QIODevice
::
WriteOnly
);
newPic
.
write
(
picData
);
newPic
.
close
();
updatePixmapCache
();
}
}
delete
downloadBuffer
;
}
QPixmap
*
CardInfo
::
getPixmap
(
QSize
size
)
QPixmap
*
CardInfo
::
getPixmap
(
QSize
size
)
{
{
qDebug
(
QString
(
"CardInfo::getPixmap(%1, %2) for %3"
).
arg
(
size
.
width
()).
arg
(
size
.
height
()).
arg
(
getName
()).
toLatin1
());
qDebug
(
QString
(
"CardInfo::getPixmap(%1, %2) for %3"
).
arg
(
size
.
width
()).
arg
(
size
.
height
()).
arg
(
getName
()).
toLatin1
());
...
@@ -266,6 +226,9 @@ QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfo *info)
...
@@ -266,6 +226,9 @@ QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfo *info)
CardDatabase
::
CardDatabase
(
QObject
*
parent
)
CardDatabase
::
CardDatabase
(
QObject
*
parent
)
:
QObject
(
parent
),
noCard
(
0
)
:
QObject
(
parent
),
noCard
(
0
)
{
{
http
=
new
QHttp
(
this
);
connect
(
http
,
SIGNAL
(
requestFinished
(
int
,
bool
)),
this
,
SLOT
(
picDownloadFinished
(
int
,
bool
)));
updateDatabasePath
();
updateDatabasePath
();
updatePicDownload
();
updatePicDownload
();
updatePicsPath
();
updatePicsPath
();
...
@@ -345,6 +308,49 @@ void CardDatabase::clearPixmapCache()
...
@@ -345,6 +308,49 @@ void CardDatabase::clearPixmapCache()
noCard
->
clearPixmapCache
();
noCard
->
clearPixmapCache
();
}
}
void
CardDatabase
::
startPicDownload
(
CardInfo
*
card
)
{
QBuffer
*
buffer
=
new
QBuffer
(
this
);
buffer
->
open
(
QIODevice
::
ReadWrite
);
QUrl
url
(
card
->
getPicURL
());
http
->
setHost
(
url
.
host
(),
url
.
port
(
80
));
int
dlID
=
http
->
get
(
url
.
path
(),
buffer
);
downloadBuffers
.
insert
(
dlID
,
QPair
<
CardInfo
*
,
QBuffer
*>
(
card
,
buffer
));
}
void
CardDatabase
::
picDownloadFinished
(
int
id
,
bool
error
)
{
if
(
!
downloadBuffers
.
contains
(
id
))
return
;
const
QPair
<
CardInfo
*
,
QBuffer
*>
&
temp
=
downloadBuffers
.
value
(
id
);
CardInfo
*
card
=
temp
.
first
;
QBuffer
*
buffer
=
temp
.
second
;
downloadBuffers
.
remove
(
id
);
buffer
->
close
();
if
(
!
error
)
{
const
QByteArray
&
picData
=
buffer
->
data
();
QPixmap
testPixmap
;
if
(
testPixmap
.
loadFromData
(
picData
))
{
if
(
!
QDir
(
QString
(
picsPath
+
"/downloadedPics/"
)).
exists
())
{
QDir
dir
(
picsPath
);
if
(
!
dir
.
exists
())
return
;
dir
.
mkdir
(
"downloadedPics"
);
}
QFile
newPic
(
picsPath
+
"/downloadedPics/"
+
card
->
getCorrectedName
()
+
".full.jpg"
);
if
(
!
newPic
.
open
(
QIODevice
::
WriteOnly
))
return
;
newPic
.
write
(
picData
);
newPic
.
close
();
card
->
updatePixmapCache
();
}
}
delete
buffer
;
}
void
CardDatabase
::
loadSetsFromXml
(
QXmlStreamReader
&
xml
)
void
CardDatabase
::
loadSetsFromXml
(
QXmlStreamReader
&
xml
)
{
{
while
(
!
xml
.
atEnd
())
{
while
(
!
xml
.
atEnd
())
{
...
...
cockatrice/src/carddatabase.h
View file @
df8c0199
...
@@ -46,14 +46,9 @@ private:
...
@@ -46,14 +46,9 @@ private:
QString
text
;
QString
text
;
QStringList
colors
;
QStringList
colors
;
QString
picURL
;
QString
picURL
;
QHttp
*
http
;
QBuffer
*
downloadBuffer
;
int
dlID
;
int
tableRow
;
int
tableRow
;
QPixmap
*
pixmap
;
QPixmap
*
pixmap
;
QMap
<
int
,
QPixmap
*>
scaledPixmapCache
;
QMap
<
int
,
QPixmap
*>
scaledPixmapCache
;
void
startDownload
();
public:
public:
CardInfo
(
CardDatabase
*
_db
,
CardInfo
(
CardDatabase
*
_db
,
const
QString
&
_name
=
QString
(),
const
QString
&
_name
=
QString
(),
...
@@ -86,8 +81,6 @@ public:
...
@@ -86,8 +81,6 @@ public:
void
clearPixmapCache
();
void
clearPixmapCache
();
void
clearPixmapCacheMiss
();
void
clearPixmapCacheMiss
();
void
updatePixmapCache
();
void
updatePixmapCache
();
private
slots
:
void
picDownloadFinished
(
int
id
,
bool
error
);
signals:
signals:
void
pixmapUpdated
();
void
pixmapUpdated
();
};
};
...
@@ -97,12 +90,14 @@ class CardDatabase : public QObject {
...
@@ -97,12 +90,14 @@ class CardDatabase : public QObject {
protected:
protected:
QHash
<
QString
,
CardInfo
*>
cardHash
;
QHash
<
QString
,
CardInfo
*>
cardHash
;
QHash
<
QString
,
CardSet
*>
setHash
;
QHash
<
QString
,
CardSet
*>
setHash
;
QMap
<
int
,
QPair
<
CardInfo
*
,
QBuffer
*>
>
downloadBuffers
;
CardInfo
*
noCard
;
CardInfo
*
noCard
;
QString
picsPath
,
cardDatabasePath
;
QString
picsPath
,
cardDatabasePath
;
private:
private:
void
loadCardsFromXml
(
QXmlStreamReader
&
xml
);
void
loadCardsFromXml
(
QXmlStreamReader
&
xml
);
void
loadSetsFromXml
(
QXmlStreamReader
&
xml
);
void
loadSetsFromXml
(
QXmlStreamReader
&
xml
);
bool
picDownload
;
bool
picDownload
;
QHttp
*
http
;
public:
public:
CardDatabase
(
QObject
*
parent
=
0
);
CardDatabase
(
QObject
*
parent
=
0
);
~
CardDatabase
();
~
CardDatabase
();
...
@@ -116,6 +111,9 @@ public:
...
@@ -116,6 +111,9 @@ public:
int
loadFromFile
(
const
QString
&
fileName
);
int
loadFromFile
(
const
QString
&
fileName
);
bool
saveToFile
(
const
QString
&
fileName
);
bool
saveToFile
(
const
QString
&
fileName
);
const
QString
&
getPicsPath
()
const
{
return
picsPath
;
}
const
QString
&
getPicsPath
()
const
{
return
picsPath
;
}
void
startPicDownload
(
CardInfo
*
card
);
private
slots
:
void
picDownloadFinished
(
int
id
,
bool
error
);
public
slots
:
public
slots
:
void
updatePicsPath
(
const
QString
&
path
=
QString
());
void
updatePicsPath
(
const
QString
&
path
=
QString
());
void
updateDatabasePath
(
const
QString
&
path
=
QString
());
void
updateDatabasePath
(
const
QString
&
path
=
QString
());
...
...
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