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
ef60ed29
Commit
ef60ed29
authored
Aug 14, 2009
by
Max-Wilhelm Bruker
Browse files
automatic picture download is now optional
parent
d653152b
Changes
4
Hide whitespace changes
Inline
Side-by-side
cockatrice/src/carddatabase.cpp
View file @
ef60ed29
...
@@ -96,6 +96,12 @@ QString CardInfo::getMainCardType() const
...
@@ -96,6 +96,12 @@ QString CardInfo::getMainCardType() const
return
result
;
return
result
;
}
}
QString
CardInfo
::
getCorrectedName
()
const
{
// Fire // Ice, Circle of Protection: Red
return
getName
().
remove
(
" // "
).
remove
(
":"
);
}
void
CardInfo
::
addToSet
(
CardSet
*
set
)
void
CardInfo
::
addToSet
(
CardSet
*
set
)
{
{
set
->
append
(
this
);
set
->
append
(
this
);
...
@@ -119,47 +125,58 @@ QPixmap *CardInfo::loadPixmap()
...
@@ -119,47 +125,58 @@ QPixmap *CardInfo::loadPixmap()
debugOutput
.
append
(
QString
(
"%1, "
).
arg
(
sets
[
i
]
->
getShortName
()));
debugOutput
.
append
(
QString
(
"%1, "
).
arg
(
sets
[
i
]
->
getShortName
()));
qDebug
(
debugOutput
.
toLatin1
());
qDebug
(
debugOutput
.
toLatin1
());
QString
correctedName
=
getCorrectedName
();
for
(
int
i
=
0
;
i
<
sets
.
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
sets
.
size
();
i
++
)
{
// Fire // Ice, Circle of Protection: Red
QString
correctedName
=
getName
().
remove
(
" // "
).
remove
(
":"
);
if
(
pixmap
->
load
(
QString
(
"%1/%2/%3.full.jpg"
).
arg
(
picsPath
).
arg
(
sets
[
i
]
->
getShortName
()).
arg
(
correctedName
)))
if
(
pixmap
->
load
(
QString
(
"%1/%2/%3.full.jpg"
).
arg
(
picsPath
).
arg
(
sets
[
i
]
->
getShortName
()).
arg
(
correctedName
)))
return
pixmap
;
return
pixmap
;
if
(
pixmap
->
load
(
QString
(
"%1/%2/%3%4.full.jpg"
).
arg
(
picsPath
).
arg
(
sets
[
i
]
->
getShortName
()).
arg
(
correctedName
).
arg
(
1
)))
if
(
pixmap
->
load
(
QString
(
"%1/%2/%3%4.full.jpg"
).
arg
(
picsPath
).
arg
(
sets
[
i
]
->
getShortName
()).
arg
(
correctedName
).
arg
(
1
)))
return
pixmap
;
return
pixmap
;
if
(
pixmap
->
load
(
QString
(
"%1/%2/%3.full.jpg"
).
arg
(
picsPath
).
arg
(
"downloadedPics"
).
arg
(
correctedName
)))
if
(
pixmap
->
load
(
QString
(
"%1/%2/%3.full.jpg"
).
arg
(
picsPath
).
arg
(
"downloadedPics"
).
arg
(
correctedName
)))
return
pixmap
;
return
pixmap
;
startDownload
(
picsPath
,
correctedName
);
}
}
if
(
db
->
getPicDownload
())
startDownload
();
return
pixmap
;
return
pixmap
;
}
}
void
CardInfo
::
startDownload
(
QString
picsPath
,
QString
cardName
)
void
CardInfo
::
startDownload
()
{
if
(
!
QDir
(
QString
(
picsPath
+
"/downloadedPics/"
)).
exists
())
{
{
downloadBuffer
=
new
QBuffer
(
this
);
QDir
dir
(
picsPath
);
downloadBuffer
->
open
(
QIODevice
::
ReadWrite
);
dir
.
mkdir
(
"downloadedPics"
);
http
=
new
QHttp
(
this
);
}
connect
(
http
,
SIGNAL
(
requestFinished
(
int
,
bool
)),
this
,
SLOT
(
picDownloadFinished
(
int
,
bool
)));
newPic
=
new
QFile
(
picsPath
+
"/downloadedPics/"
+
cardName
+
".full.jpg"
);
QUrl
url
(
picURL
);
newPic
->
open
(
QIODevice
::
WriteOnly
);
http
->
setHost
(
url
.
host
(),
url
.
port
(
80
));
connect
(
&
http
,
SIGNAL
(
requestFinished
(
int
,
bool
)),
this
,
SLOT
(
picDownloadFinished
(
int
,
bool
)));
dlID
=
http
->
get
(
url
.
path
(),
downloadBuffer
);
QUrl
url
(
picURL
);
http
.
setHost
(
url
.
host
(),
url
.
port
(
80
));
dlID
=
http
.
get
(
url
.
path
(),
newPic
);
}
}
void
CardInfo
::
picDownloadFinished
(
int
id
,
bool
result
)
void
CardInfo
::
picDownloadFinished
(
int
id
,
bool
error
)
{
{
if
(
id
==
dlID
){
if
(
id
!=
dlID
)
newPic
->
flush
();
return
;
newPic
->
close
();
http
->
close
();
http
.
close
();
disconnect
(
http
,
0
,
this
,
0
);
updatePixmapCache
();
http
->
deleteLater
();
disconnect
(
&
http
,
0
,
this
,
0
);
delete
newPic
;
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
)
...
@@ -237,6 +254,7 @@ CardDatabase::CardDatabase(QObject *parent)
...
@@ -237,6 +254,7 @@ CardDatabase::CardDatabase(QObject *parent)
:
QObject
(
parent
),
noCard
(
0
)
:
QObject
(
parent
),
noCard
(
0
)
{
{
updateDatabasePath
();
updateDatabasePath
();
updatePicDownload
();
updatePicsPath
();
updatePicsPath
();
noCard
=
new
CardInfo
(
this
);
noCard
=
new
CardInfo
(
this
);
...
@@ -424,6 +442,15 @@ bool CardDatabase::saveToFile(const QString &fileName)
...
@@ -424,6 +442,15 @@ bool CardDatabase::saveToFile(const QString &fileName)
return
true
;
return
true
;
}
}
void
CardDatabase
::
updatePicDownload
(
int
_picDownload
)
{
if
(
_picDownload
==
-
1
)
{
QSettings
settings
;
picDownload
=
settings
.
value
(
"personal/picturedownload"
,
0
).
toInt
();
}
else
picDownload
=
_picDownload
;
}
void
CardDatabase
::
updatePicsPath
(
const
QString
&
path
)
void
CardDatabase
::
updatePicsPath
(
const
QString
&
path
)
{
{
if
(
path
.
isEmpty
())
{
if
(
path
.
isEmpty
())
{
...
...
cockatrice/src/carddatabase.h
View file @
ef60ed29
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
#include
<QList>
#include
<QList>
#include
<QXmlStreamReader>
#include
<QXmlStreamReader>
#include
<QHttp>
#include
<QHttp>
#include
<Q
File
>
#include
<Q
Buffer
>
class
CardDatabase
;
class
CardDatabase
;
class
CardInfo
;
class
CardInfo
;
...
@@ -33,7 +33,7 @@ public:
...
@@ -33,7 +33,7 @@ public:
void
sortByKey
();
void
sortByKey
();
};
};
class
CardInfo
:
QObject
{
class
CardInfo
:
QObject
{
Q_OBJECT
Q_OBJECT
private:
private:
CardDatabase
*
db
;
CardDatabase
*
db
;
...
@@ -46,14 +46,14 @@ private:
...
@@ -46,14 +46,14 @@ private:
QString
text
;
QString
text
;
QStringList
colors
;
QStringList
colors
;
QString
picURL
;
QString
picURL
;
QHttp
http
;
QHttp
*
http
;
Q
File
*
newPic
;
Q
Buffer
*
downloadBuffer
;
int
dlID
;
int
dlID
;
int
tableRow
;
int
tableRow
;
QPixmap
*
pixmap
;
QPixmap
*
pixmap
;
QMap
<
int
,
QPixmap
*>
scaledPixmapCache
;
QMap
<
int
,
QPixmap
*>
scaledPixmapCache
;
void
startDownload
(
QString
,
QString
);
void
startDownload
();
public:
public:
CardInfo
(
CardDatabase
*
_db
,
CardInfo
(
CardDatabase
*
_db
,
const
QString
&
_name
=
QString
(),
const
QString
&
_name
=
QString
(),
...
@@ -75,16 +75,17 @@ public:
...
@@ -75,16 +75,17 @@ public:
QStringList
getColors
()
const
{
return
colors
;
}
QStringList
getColors
()
const
{
return
colors
;
}
QString
getPicURL
()
const
{
return
picURL
;
}
QString
getPicURL
()
const
{
return
picURL
;
}
QString
getMainCardType
()
const
;
QString
getMainCardType
()
const
;
QString
getCorrectedName
()
const
;
int
getTableRow
()
const
{
return
tableRow
;
}
int
getTableRow
()
const
{
return
tableRow
;
}
void
setTableRow
(
int
_tableRow
)
{
tableRow
=
_tableRow
;
}
void
setTableRow
(
int
_tableRow
)
{
tableRow
=
_tableRow
;
}
void
setPicURL
(
QString
_picURL
)
{
picURL
=
_picURL
;
}
void
setPicURL
(
const
QString
&
_picURL
)
{
picURL
=
_picURL
;
}
void
addToSet
(
CardSet
*
set
);
void
addToSet
(
CardSet
*
set
);
QPixmap
*
loadPixmap
();
QPixmap
*
loadPixmap
();
QPixmap
*
getPixmap
(
QSize
size
);
QPixmap
*
getPixmap
(
QSize
size
);
void
clearPixmapCache
();
void
clearPixmapCache
();
void
updatePixmapCache
();
void
updatePixmapCache
();
p
ublic
slots
:
p
rivate
slots
:
void
picDownloadFinished
(
int
,
bool
);
void
picDownloadFinished
(
int
id
,
bool
error
);
};
};
class
CardDatabase
:
public
QObject
{
class
CardDatabase
:
public
QObject
{
...
@@ -97,6 +98,7 @@ protected:
...
@@ -97,6 +98,7 @@ protected:
private:
private:
void
loadCardsFromXml
(
QXmlStreamReader
&
xml
);
void
loadCardsFromXml
(
QXmlStreamReader
&
xml
);
void
loadSetsFromXml
(
QXmlStreamReader
&
xml
);
void
loadSetsFromXml
(
QXmlStreamReader
&
xml
);
bool
picDownload
;
public:
public:
CardDatabase
(
QObject
*
parent
=
0
);
CardDatabase
(
QObject
*
parent
=
0
);
~
CardDatabase
();
~
CardDatabase
();
...
@@ -105,6 +107,7 @@ public:
...
@@ -105,6 +107,7 @@ public:
CardSet
*
getSet
(
const
QString
&
setName
);
CardSet
*
getSet
(
const
QString
&
setName
);
QList
<
CardInfo
*>
getCardList
()
const
{
return
cardHash
.
values
();
}
QList
<
CardInfo
*>
getCardList
()
const
{
return
cardHash
.
values
();
}
SetList
getSetList
()
const
;
SetList
getSetList
()
const
;
bool
getPicDownload
()
const
{
return
picDownload
;
}
void
clearPixmapCache
();
void
clearPixmapCache
();
int
loadFromFile
(
const
QString
&
fileName
);
int
loadFromFile
(
const
QString
&
fileName
);
bool
saveToFile
(
const
QString
&
fileName
);
bool
saveToFile
(
const
QString
&
fileName
);
...
@@ -112,6 +115,7 @@ public:
...
@@ -112,6 +115,7 @@ public:
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
());
void
updatePicDownload
(
int
_picDownload
=
-
1
);
};
};
#endif
#endif
cockatrice/src/dlg_settings.cpp
View file @
ef60ed29
...
@@ -8,6 +8,7 @@ GeneralSettingsPage::GeneralSettingsPage()
...
@@ -8,6 +8,7 @@ GeneralSettingsPage::GeneralSettingsPage()
QSettings
settings
;
QSettings
settings
;
personalGroupBox
=
new
QGroupBox
;
personalGroupBox
=
new
QGroupBox
;
languageLabel
=
new
QLabel
;
languageLabel
=
new
QLabel
;
languageBox
=
new
QComboBox
;
languageBox
=
new
QComboBox
;
...
@@ -20,12 +21,19 @@ GeneralSettingsPage::GeneralSettingsPage()
...
@@ -20,12 +21,19 @@ GeneralSettingsPage::GeneralSettingsPage()
if
((
qmFiles
[
i
]
==
settings
.
value
(
"lang"
).
toString
())
||
(
setLanguage
.
isEmpty
()
&&
langName
==
tr
(
"English"
)))
if
((
qmFiles
[
i
]
==
settings
.
value
(
"lang"
).
toString
())
||
(
setLanguage
.
isEmpty
()
&&
langName
==
tr
(
"English"
)))
languageBox
->
setCurrentIndex
(
i
);
languageBox
->
setCurrentIndex
(
i
);
}
}
picDownloadCheckBox
=
new
QCheckBox
;
picDownloadCheckBox
->
setChecked
(
settings
.
value
(
"picturedownload"
,
0
).
toInt
());
settings
.
endGroup
();
settings
.
endGroup
();
connect
(
languageBox
,
SIGNAL
(
currentIndexChanged
(
int
)),
this
,
SLOT
(
languageBoxChanged
(
int
)));
connect
(
languageBox
,
SIGNAL
(
currentIndexChanged
(
int
)),
this
,
SLOT
(
languageBoxChanged
(
int
)));
connect
(
picDownloadCheckBox
,
SIGNAL
(
stateChanged
(
int
)),
this
,
SLOT
(
picDownloadCheckBoxChanged
(
int
)));
QGridLayout
*
personalGrid
=
new
QGridLayout
;
QGridLayout
*
personalGrid
=
new
QGridLayout
;
personalGrid
->
addWidget
(
languageLabel
,
0
,
0
);
personalGrid
->
addWidget
(
languageLabel
,
0
,
0
);
personalGrid
->
addWidget
(
languageBox
,
0
,
1
);
personalGrid
->
addWidget
(
languageBox
,
0
,
1
);
personalGrid
->
addWidget
(
picDownloadCheckBox
,
1
,
0
,
1
,
2
);
personalGroupBox
->
setLayout
(
personalGrid
);
personalGroupBox
->
setLayout
(
personalGrid
);
pathsGroupBox
=
new
QGroupBox
;
pathsGroupBox
=
new
QGroupBox
;
...
@@ -160,10 +168,20 @@ void GeneralSettingsPage::languageBoxChanged(int index)
...
@@ -160,10 +168,20 @@ void GeneralSettingsPage::languageBoxChanged(int index)
emit
changeLanguage
(
qmFile
);
emit
changeLanguage
(
qmFile
);
}
}
void
GeneralSettingsPage
::
picDownloadCheckBoxChanged
(
int
state
)
{
QSettings
settings
;
settings
.
beginGroup
(
"personal"
);
settings
.
setValue
(
"picturedownload"
,
state
);
emit
picDownloadChanged
(
state
);
}
void
GeneralSettingsPage
::
retranslateUi
()
void
GeneralSettingsPage
::
retranslateUi
()
{
{
personalGroupBox
->
setTitle
(
tr
(
"Personal settings"
));
personalGroupBox
->
setTitle
(
tr
(
"Personal settings"
));
languageLabel
->
setText
(
tr
(
"Language:"
));
languageLabel
->
setText
(
tr
(
"Language:"
));
picDownloadCheckBox
->
setText
(
tr
(
"Download card pictures on the fly"
));
pathsGroupBox
->
setTitle
(
tr
(
"Paths"
));
pathsGroupBox
->
setTitle
(
tr
(
"Paths"
));
deckPathLabel
->
setText
(
tr
(
"Decks directory:"
));
deckPathLabel
->
setText
(
tr
(
"Decks directory:"
));
picsPathLabel
->
setText
(
tr
(
"Pictures directory:"
));
picsPathLabel
->
setText
(
tr
(
"Pictures directory:"
));
...
@@ -250,7 +268,7 @@ DlgSettings::DlgSettings(CardDatabase *_db, QTranslator *_translator, QWidget *p
...
@@ -250,7 +268,7 @@ DlgSettings::DlgSettings(CardDatabase *_db, QTranslator *_translator, QWidget *p
contentsWidget
->
setIconSize
(
QSize
(
96
,
84
));
contentsWidget
->
setIconSize
(
QSize
(
96
,
84
));
contentsWidget
->
setMovement
(
QListView
::
Static
);
contentsWidget
->
setMovement
(
QListView
::
Static
);
contentsWidget
->
setMinimumWidth
(
115
);
contentsWidget
->
setMinimumWidth
(
115
);
contentsWidget
->
setMaximumWidth
(
1
15
);
contentsWidget
->
setMaximumWidth
(
1
30
);
contentsWidget
->
setSpacing
(
12
);
contentsWidget
->
setSpacing
(
12
);
pagesWidget
=
new
QStackedWidget
;
pagesWidget
=
new
QStackedWidget
;
...
@@ -258,6 +276,7 @@ DlgSettings::DlgSettings(CardDatabase *_db, QTranslator *_translator, QWidget *p
...
@@ -258,6 +276,7 @@ DlgSettings::DlgSettings(CardDatabase *_db, QTranslator *_translator, QWidget *p
connect
(
general
,
SIGNAL
(
picsPathChanged
(
const
QString
&
)),
db
,
SLOT
(
updatePicsPath
(
const
QString
&
)));
connect
(
general
,
SIGNAL
(
picsPathChanged
(
const
QString
&
)),
db
,
SLOT
(
updatePicsPath
(
const
QString
&
)));
connect
(
general
,
SIGNAL
(
cardDatabasePathChanged
(
const
QString
&
)),
db
,
SLOT
(
updateDatabasePath
(
const
QString
&
)));
connect
(
general
,
SIGNAL
(
cardDatabasePathChanged
(
const
QString
&
)),
db
,
SLOT
(
updateDatabasePath
(
const
QString
&
)));
connect
(
general
,
SIGNAL
(
changeLanguage
(
const
QString
&
)),
this
,
SLOT
(
changeLanguage
(
const
QString
&
)));
connect
(
general
,
SIGNAL
(
changeLanguage
(
const
QString
&
)),
this
,
SLOT
(
changeLanguage
(
const
QString
&
)));
connect
(
general
,
SIGNAL
(
picDownloadChanged
(
int
)),
db
,
SLOT
(
updatePicDownload
(
int
)));
pagesWidget
->
addWidget
(
general
);
pagesWidget
->
addWidget
(
general
);
pagesWidget
->
addWidget
(
new
AppearanceSettingsPage
);
pagesWidget
->
addWidget
(
new
AppearanceSettingsPage
);
pagesWidget
->
addWidget
(
new
MessagesSettingsPage
);
pagesWidget
->
addWidget
(
new
MessagesSettingsPage
);
...
...
cockatrice/src/dlg_settings.h
View file @
ef60ed29
...
@@ -12,6 +12,7 @@ class QLineEdit;
...
@@ -12,6 +12,7 @@ class QLineEdit;
class
QPushButton
;
class
QPushButton
;
class
QComboBox
;
class
QComboBox
;
class
QGroupBox
;
class
QGroupBox
;
class
QCheckBox
;
class
QLabel
;
class
QLabel
;
class
AbstractSettingsPage
:
public
QWidget
{
class
AbstractSettingsPage
:
public
QWidget
{
...
@@ -30,17 +31,20 @@ private slots:
...
@@ -30,17 +31,20 @@ private slots:
void
cardDatabasePathButtonClicked
();
void
cardDatabasePathButtonClicked
();
void
cardBackgroundPathButtonClicked
();
void
cardBackgroundPathButtonClicked
();
void
languageBoxChanged
(
int
index
);
void
languageBoxChanged
(
int
index
);
void
picDownloadCheckBoxChanged
(
int
state
);
signals:
signals:
void
picsPathChanged
(
const
QString
&
path
);
void
picsPathChanged
(
const
QString
&
path
);
void
cardDatabasePathChanged
(
const
QString
&
path
);
void
cardDatabasePathChanged
(
const
QString
&
path
);
void
cardBackgroundPathChanged
(
const
QString
&
path
);
void
cardBackgroundPathChanged
(
const
QString
&
path
);
void
changeLanguage
(
const
QString
&
qmFile
);
void
changeLanguage
(
const
QString
&
qmFile
);
void
picDownloadChanged
(
int
state
);
private:
private:
QStringList
findQmFiles
();
QStringList
findQmFiles
();
QString
languageName
(
const
QString
&
qmFile
);
QString
languageName
(
const
QString
&
qmFile
);
QLineEdit
*
deckPathEdit
,
*
picsPathEdit
,
*
cardDatabasePathEdit
,
*
cardBackgroundPathEdit
;
QLineEdit
*
deckPathEdit
,
*
picsPathEdit
,
*
cardDatabasePathEdit
,
*
cardBackgroundPathEdit
;
QGroupBox
*
personalGroupBox
,
*
pathsGroupBox
;
QGroupBox
*
personalGroupBox
,
*
pathsGroupBox
;
QComboBox
*
languageBox
;
QComboBox
*
languageBox
;
QCheckBox
*
picDownloadCheckBox
;
QLabel
*
languageLabel
,
*
deckPathLabel
,
*
picsPathLabel
,
*
cardDatabasePathLabel
,
*
cardBackgroundPathLabel
;
QLabel
*
languageLabel
,
*
deckPathLabel
,
*
picsPathLabel
,
*
cardDatabasePathLabel
,
*
cardBackgroundPathLabel
;
};
};
...
...
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