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
73e5e12c
Commit
73e5e12c
authored
Jul 08, 2014
by
Gavin Bisesi
Browse files
Merge pull request #199 from arxanas/remember-game-filter-preferences
Fix #137: Game filter preferences are saved.
parents
7f770824
1217689e
Changes
3
Hide whitespace changes
Inline
Side-by-side
cockatrice/src/dlg_filter_games.cpp
View file @
73e5e12c
...
@@ -9,26 +9,53 @@
...
@@ -9,26 +9,53 @@
#include
<QVBoxLayout>
#include
<QVBoxLayout>
#include
<QGridLayout>
#include
<QGridLayout>
#include
<QDialogButtonBox>
#include
<QDialogButtonBox>
#include
<QSettings>
#include
<QCryptographicHash>
DlgFilterGames
::
DlgFilterGames
(
const
QMap
<
int
,
QString
>
&
allGameTypes
,
QWidget
*
parent
)
DlgFilterGames
::
DlgFilterGames
(
const
QMap
<
int
,
QString
>
&
_allGameTypes
,
QWidget
*
parent
)
:
QDialog
(
parent
)
:
QDialog
(
parent
),
allGameTypes
(
_allGameTypes
)
{
{
QSettings
settings
;
settings
.
beginGroup
(
"filter_games"
);
unavailableGamesVisibleCheckBox
=
new
QCheckBox
(
tr
(
"Show &unavailable games"
));
unavailableGamesVisibleCheckBox
=
new
QCheckBox
(
tr
(
"Show &unavailable games"
));
unavailableGamesVisibleCheckBox
->
setChecked
(
settings
.
value
(
"unavailable_games_visible"
,
false
).
toBool
()
);
passwordProtectedGamesVisibleCheckBox
=
new
QCheckBox
(
tr
(
"Show &password protected games"
));
passwordProtectedGamesVisibleCheckBox
=
new
QCheckBox
(
tr
(
"Show &password protected games"
));
passwordProtectedGamesVisibleCheckBox
->
setChecked
(
settings
.
value
(
"password_protected_games_visible"
,
false
).
toBool
()
);
QLabel
*
gameNameFilterLabel
=
new
QLabel
(
tr
(
"Game &description:"
));
gameNameFilterEdit
=
new
QLineEdit
;
gameNameFilterEdit
=
new
QLineEdit
;
gameNameFilterEdit
->
setText
(
settings
.
value
(
"game_name_filter"
,
""
).
toString
()
);
QLabel
*
gameNameFilterLabel
=
new
QLabel
(
tr
(
"Game &description:"
));
gameNameFilterLabel
->
setBuddy
(
gameNameFilterEdit
);
gameNameFilterLabel
->
setBuddy
(
gameNameFilterEdit
);
QLabel
*
creatorNameFilterLabel
=
new
QLabel
(
tr
(
"&Creator name:"
));
creatorNameFilterEdit
=
new
QLineEdit
;
creatorNameFilterEdit
=
new
QLineEdit
;
creatorNameFilterEdit
->
setText
(
settings
.
value
(
"creator_name_filter"
,
""
).
toString
()
);
QLabel
*
creatorNameFilterLabel
=
new
QLabel
(
tr
(
"&Creator name:"
));
creatorNameFilterLabel
->
setBuddy
(
creatorNameFilterEdit
);
creatorNameFilterLabel
->
setBuddy
(
creatorNameFilterEdit
);
QVBoxLayout
*
gameTypeFilterLayout
=
new
QVBoxLayout
;
QVBoxLayout
*
gameTypeFilterLayout
=
new
QVBoxLayout
;
QMapIterator
<
int
,
QString
>
gameTypesIterator
(
allGameTypes
);
QMapIterator
<
int
,
QString
>
gameTypesIterator
(
allGameTypes
);
while
(
gameTypesIterator
.
hasNext
())
{
while
(
gameTypesIterator
.
hasNext
())
{
gameTypesIterator
.
next
();
gameTypesIterator
.
next
();
QCheckBox
*
temp
=
new
QCheckBox
(
gameTypesIterator
.
value
());
QCheckBox
*
temp
=
new
QCheckBox
(
gameTypesIterator
.
value
());
temp
->
setChecked
(
settings
.
value
(
"game_type/"
+
hashGameType
(
gameTypesIterator
.
value
()),
false
).
toBool
()
);
gameTypeFilterCheckBoxes
.
insert
(
gameTypesIterator
.
key
(),
temp
);
gameTypeFilterCheckBoxes
.
insert
(
gameTypesIterator
.
key
(),
temp
);
gameTypeFilterLayout
->
addWidget
(
temp
);
gameTypeFilterLayout
->
addWidget
(
temp
);
}
}
...
@@ -43,14 +70,18 @@ DlgFilterGames::DlgFilterGames(const QMap<int, QString> &allGameTypes, QWidget *
...
@@ -43,14 +70,18 @@ DlgFilterGames::DlgFilterGames(const QMap<int, QString> &allGameTypes, QWidget *
maxPlayersFilterMinSpinBox
=
new
QSpinBox
;
maxPlayersFilterMinSpinBox
=
new
QSpinBox
;
maxPlayersFilterMinSpinBox
->
setMinimum
(
1
);
maxPlayersFilterMinSpinBox
->
setMinimum
(
1
);
maxPlayersFilterMinSpinBox
->
setMaximum
(
99
);
maxPlayersFilterMinSpinBox
->
setMaximum
(
99
);
maxPlayersFilterMinSpinBox
->
setValue
(
1
);
maxPlayersFilterMinSpinBox
->
setValue
(
settings
.
value
(
"min_players"
,
1
).
toInt
()
);
maxPlayersFilterMinLabel
->
setBuddy
(
maxPlayersFilterMinSpinBox
);
maxPlayersFilterMinLabel
->
setBuddy
(
maxPlayersFilterMinSpinBox
);
QLabel
*
maxPlayersFilterMaxLabel
=
new
QLabel
(
tr
(
"at &most:"
));
QLabel
*
maxPlayersFilterMaxLabel
=
new
QLabel
(
tr
(
"at &most:"
));
maxPlayersFilterMaxSpinBox
=
new
QSpinBox
;
maxPlayersFilterMaxSpinBox
=
new
QSpinBox
;
maxPlayersFilterMaxSpinBox
->
setMinimum
(
1
);
maxPlayersFilterMaxSpinBox
->
setMinimum
(
1
);
maxPlayersFilterMaxSpinBox
->
setMaximum
(
99
);
maxPlayersFilterMaxSpinBox
->
setMaximum
(
99
);
maxPlayersFilterMaxSpinBox
->
setValue
(
99
);
maxPlayersFilterMaxSpinBox
->
setValue
(
settings
.
value
(
"max_players"
,
99
).
toInt
()
);
maxPlayersFilterMaxLabel
->
setBuddy
(
maxPlayersFilterMaxSpinBox
);
maxPlayersFilterMaxLabel
->
setBuddy
(
maxPlayersFilterMaxSpinBox
);
QGridLayout
*
maxPlayersFilterLayout
=
new
QGridLayout
;
QGridLayout
*
maxPlayersFilterLayout
=
new
QGridLayout
;
...
@@ -83,7 +114,7 @@ DlgFilterGames::DlgFilterGames(const QMap<int, QString> &allGameTypes, QWidget *
...
@@ -83,7 +114,7 @@ DlgFilterGames::DlgFilterGames(const QMap<int, QString> &allGameTypes, QWidget *
hbox
->
addLayout
(
rightColumn
);
hbox
->
addLayout
(
rightColumn
);
QDialogButtonBox
*
buttonBox
=
new
QDialogButtonBox
(
QDialogButtonBox
::
Ok
|
QDialogButtonBox
::
Cancel
);
QDialogButtonBox
*
buttonBox
=
new
QDialogButtonBox
(
QDialogButtonBox
::
Ok
|
QDialogButtonBox
::
Cancel
);
connect
(
buttonBox
,
SIGNAL
(
accepted
()),
this
,
SLOT
(
ac
cept
()));
connect
(
buttonBox
,
SIGNAL
(
accepted
()),
this
,
SLOT
(
ac
tOk
()));
connect
(
buttonBox
,
SIGNAL
(
rejected
()),
this
,
SLOT
(
reject
()));
connect
(
buttonBox
,
SIGNAL
(
rejected
()),
this
,
SLOT
(
reject
()));
QVBoxLayout
*
mainLayout
=
new
QVBoxLayout
;
QVBoxLayout
*
mainLayout
=
new
QVBoxLayout
;
...
@@ -94,6 +125,42 @@ DlgFilterGames::DlgFilterGames(const QMap<int, QString> &allGameTypes, QWidget *
...
@@ -94,6 +125,42 @@ DlgFilterGames::DlgFilterGames(const QMap<int, QString> &allGameTypes, QWidget *
setWindowTitle
(
tr
(
"Filter games"
));
setWindowTitle
(
tr
(
"Filter games"
));
}
}
void
DlgFilterGames
::
actOk
()
{
QSettings
settings
;
settings
.
beginGroup
(
"filter_games"
);
settings
.
setValue
(
"unavailable_games_visible"
,
unavailableGamesVisibleCheckBox
->
isChecked
()
);
settings
.
setValue
(
"password_protected_games_visible"
,
passwordProtectedGamesVisibleCheckBox
->
isChecked
()
);
settings
.
setValue
(
"game_name_filter"
,
gameNameFilterEdit
->
text
());
settings
.
setValue
(
"creator_name_filter"
,
creatorNameFilterEdit
->
text
());
QMapIterator
<
int
,
QString
>
gameTypeIterator
(
allGameTypes
);
QMapIterator
<
int
,
QCheckBox
*>
checkboxIterator
(
gameTypeFilterCheckBoxes
);
while
(
gameTypeIterator
.
hasNext
())
{
gameTypeIterator
.
next
();
checkboxIterator
.
next
();
settings
.
setValue
(
"game_type/"
+
hashGameType
(
gameTypeIterator
.
value
()),
checkboxIterator
.
value
()
->
isChecked
()
);
}
settings
.
setValue
(
"min_players"
,
maxPlayersFilterMinSpinBox
->
value
());
settings
.
setValue
(
"max_players"
,
maxPlayersFilterMaxSpinBox
->
value
());
accept
();
}
QString
DlgFilterGames
::
hashGameType
(
const
QString
&
gameType
)
const
{
return
QCryptographicHash
::
hash
(
gameType
.
toUtf8
(),
QCryptographicHash
::
Md5
).
toHex
();
}
bool
DlgFilterGames
::
getUnavailableGamesVisible
()
const
bool
DlgFilterGames
::
getUnavailableGamesVisible
()
const
{
{
return
unavailableGamesVisibleCheckBox
->
isChecked
();
return
unavailableGamesVisibleCheckBox
->
isChecked
();
...
...
cockatrice/src/dlg_filter_games.h
View file @
73e5e12c
...
@@ -19,6 +19,16 @@ private:
...
@@ -19,6 +19,16 @@ private:
QMap
<
int
,
QCheckBox
*>
gameTypeFilterCheckBoxes
;
QMap
<
int
,
QCheckBox
*>
gameTypeFilterCheckBoxes
;
QSpinBox
*
maxPlayersFilterMinSpinBox
;
QSpinBox
*
maxPlayersFilterMinSpinBox
;
QSpinBox
*
maxPlayersFilterMaxSpinBox
;
QSpinBox
*
maxPlayersFilterMaxSpinBox
;
const
QMap
<
int
,
QString
>
&
allGameTypes
;
/*
* The game type might contain special characters, so to use it in
* QSettings we just hash it.
*/
QString
hashGameType
(
const
QString
&
gameType
)
const
;
private
slots
:
void
actOk
();
public:
public:
DlgFilterGames
(
const
QMap
<
int
,
QString
>
&
allGameTypes
,
QWidget
*
parent
=
0
);
DlgFilterGames
(
const
QMap
<
int
,
QString
>
&
allGameTypes
,
QWidget
*
parent
=
0
);
...
...
cockatrice/src/gameselector.cpp
View file @
73e5e12c
...
@@ -81,12 +81,6 @@ void GameSelector::actSetFilter()
...
@@ -81,12 +81,6 @@ void GameSelector::actSetFilter()
if
(
room
)
if
(
room
)
gameTypeMap
=
gameListModel
->
getGameTypes
().
value
(
room
->
getRoomId
());
gameTypeMap
=
gameListModel
->
getGameTypes
().
value
(
room
->
getRoomId
());
DlgFilterGames
dlg
(
gameTypeMap
,
this
);
DlgFilterGames
dlg
(
gameTypeMap
,
this
);
dlg
.
setUnavailableGamesVisible
(
gameListProxyModel
->
getUnavailableGamesVisible
());
dlg
.
setPasswordProtectedGamesVisible
(
gameListProxyModel
->
getPasswordProtectedGamesVisible
());
dlg
.
setGameNameFilter
(
gameListProxyModel
->
getGameNameFilter
());
dlg
.
setCreatorNameFilter
(
gameListProxyModel
->
getCreatorNameFilter
());
dlg
.
setGameTypeFilter
(
gameListProxyModel
->
getGameTypeFilter
());
dlg
.
setMaxPlayersFilter
(
gameListProxyModel
->
getMaxPlayersFilterMin
(),
gameListProxyModel
->
getMaxPlayersFilterMax
());
if
(
!
dlg
.
exec
())
if
(
!
dlg
.
exec
())
return
;
return
;
...
...
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