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
648c5c48
Commit
648c5c48
authored
Feb 19, 2015
by
Gavin Bisesi
Browse files
Merge pull request #751 from ctrlaltca/img_loading
Avoid loading the same card's picture twice; Fix #745
parents
9d9ffd8a
70b047ad
Changes
2
Hide whitespace changes
Inline
Side-by-side
cockatrice/src/carddatabase.cpp
View file @
648c5c48
...
@@ -142,11 +142,11 @@ void PictureLoader::processLoadQueue()
...
@@ -142,11 +142,11 @@ void PictureLoader::processLoadQueue()
loadQueueRunning
=
false
;
loadQueueRunning
=
false
;
return
;
return
;
}
}
PictureToLoad
ptl
=
loadQueue
.
takeFirst
();
cardBeingLoaded
=
loadQueue
.
takeFirst
();
mutex
.
unlock
();
mutex
.
unlock
();
QString
setName
=
ptl
.
getSetName
();
QString
setName
=
cardBeingLoaded
.
getSetName
();
QString
correctedCardname
=
ptl
.
getCard
()
->
getCorrectedName
();
QString
correctedCardname
=
cardBeingLoaded
.
getCard
()
->
getCorrectedName
();
qDebug
()
<<
"Trying to load picture (set: "
<<
setName
<<
" card: "
<<
correctedCardname
<<
")"
;
qDebug
()
<<
"Trying to load picture (set: "
<<
setName
<<
" card: "
<<
correctedCardname
<<
")"
;
//The list of paths to the folders in which to search for images
//The list of paths to the folders in which to search for images
...
@@ -168,14 +168,14 @@ void PictureLoader::processLoadQueue()
...
@@ -168,14 +168,14 @@ void PictureLoader::processLoadQueue()
imgReader
.
setFileName
(
picsPaths
.
at
(
i
));
imgReader
.
setFileName
(
picsPaths
.
at
(
i
));
if
(
imgReader
.
read
(
&
image
))
{
if
(
imgReader
.
read
(
&
image
))
{
qDebug
()
<<
"Picture found on disk (set: "
<<
setName
<<
" card: "
<<
correctedCardname
<<
")"
;
qDebug
()
<<
"Picture found on disk (set: "
<<
setName
<<
" card: "
<<
correctedCardname
<<
")"
;
emit
imageLoaded
(
ptl
.
getCard
(),
image
);
emit
imageLoaded
(
cardBeingLoaded
.
getCard
(),
image
);
found
=
true
;
found
=
true
;
break
;
break
;
}
}
imgReader
.
setFileName
(
picsPaths
.
at
(
i
)
+
".full"
);
imgReader
.
setFileName
(
picsPaths
.
at
(
i
)
+
".full"
);
if
(
imgReader
.
read
(
&
image
))
{
if
(
imgReader
.
read
(
&
image
))
{
qDebug
()
<<
"Picture.full found on disk (set: "
<<
setName
<<
" card: "
<<
correctedCardname
<<
")"
;
qDebug
()
<<
"Picture.full found on disk (set: "
<<
setName
<<
" card: "
<<
correctedCardname
<<
")"
;
emit
imageLoaded
(
ptl
.
getCard
(),
image
);
emit
imageLoaded
(
cardBeingLoaded
.
getCard
(),
image
);
found
=
true
;
found
=
true
;
}
}
}
}
...
@@ -183,19 +183,21 @@ void PictureLoader::processLoadQueue()
...
@@ -183,19 +183,21 @@ void PictureLoader::processLoadQueue()
if
(
!
found
)
{
if
(
!
found
)
{
if
(
picDownload
)
{
if
(
picDownload
)
{
qDebug
()
<<
"Picture NOT found, trying to download (set: "
<<
setName
<<
" card: "
<<
correctedCardname
<<
")"
;
qDebug
()
<<
"Picture NOT found, trying to download (set: "
<<
setName
<<
" card: "
<<
correctedCardname
<<
")"
;
cardsToDownload
.
append
(
ptl
);
cardsToDownload
.
append
(
cardBeingLoaded
);
cardBeingLoaded
=
0
;
if
(
!
downloadRunning
)
if
(
!
downloadRunning
)
startNextPicDownload
();
startNextPicDownload
();
}
else
{
}
else
{
if
(
ptl
.
nextSet
())
if
(
cardBeingLoaded
.
nextSet
())
{
{
qDebug
()
<<
"Picture NOT found and download disabled, moving to next set (newset: "
<<
setName
<<
" card: "
<<
correctedCardname
<<
")"
;
qDebug
()
<<
"Picture NOT found and download disabled, moving to next set (newset: "
<<
setName
<<
" card: "
<<
correctedCardname
<<
")"
;
mutex
.
lock
();
mutex
.
lock
();
loadQueue
.
prepend
(
ptl
);
loadQueue
.
prepend
(
cardBeingLoaded
);
cardBeingLoaded
=
0
;
mutex
.
unlock
();
mutex
.
unlock
();
}
else
{
}
else
{
qDebug
()
<<
"Picture NOT found, download disabled, no more sets to try: BAILING OUT (oldset: "
<<
setName
<<
" card: "
<<
correctedCardname
<<
")"
;
qDebug
()
<<
"Picture NOT found, download disabled, no more sets to try: BAILING OUT (oldset: "
<<
setName
<<
" card: "
<<
correctedCardname
<<
")"
;
emit
imageLoaded
(
ptl
.
getCard
(),
QImage
());
emit
imageLoaded
(
cardBeingLoaded
.
getCard
(),
QImage
());
}
}
}
}
}
}
...
@@ -339,6 +341,16 @@ void PictureLoader::loadImage(CardInfo *card)
...
@@ -339,6 +341,16 @@ void PictureLoader::loadImage(CardInfo *card)
{
{
QMutexLocker
locker
(
&
mutex
);
QMutexLocker
locker
(
&
mutex
);
// avoid queueing the same card more than once
if
(
card
==
cardBeingLoaded
.
getCard
()
||
card
==
cardBeingDownloaded
.
getCard
())
return
;
foreach
(
PictureToLoad
pic
,
loadQueue
)
{
if
(
pic
.
getCard
()
==
card
)
return
;
}
loadQueue
.
append
(
PictureToLoad
(
card
));
loadQueue
.
append
(
PictureToLoad
(
card
));
emit
startLoadQueue
();
emit
startLoadQueue
();
}
}
...
...
cockatrice/src/carddatabase.h
View file @
648c5c48
...
@@ -74,6 +74,7 @@ private:
...
@@ -74,6 +74,7 @@ private:
QMutex
mutex
;
QMutex
mutex
;
QNetworkAccessManager
*
networkManager
;
QNetworkAccessManager
*
networkManager
;
QList
<
PictureToLoad
>
cardsToDownload
;
QList
<
PictureToLoad
>
cardsToDownload
;
PictureToLoad
cardBeingLoaded
;
PictureToLoad
cardBeingDownloaded
;
PictureToLoad
cardBeingDownloaded
;
bool
picDownload
,
picDownloadHq
,
downloadRunning
,
loadQueueRunning
;
bool
picDownload
,
picDownloadHq
,
downloadRunning
,
loadQueueRunning
;
void
startNextPicDownload
();
void
startNextPicDownload
();
...
...
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