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
0eee6d7a
Commit
0eee6d7a
authored
May 09, 2012
by
Max-Wilhelm Bruker
Browse files
fixed issue #49: when editing a remote deck, be able to directly save it there
parent
f00eaa83
Changes
23
Hide whitespace changes
Inline
Side-by-side
common/decklist.h
View file @
0eee6d7a
...
...
@@ -107,44 +107,36 @@ public:
void
setName
(
const
QString
&
_name
)
{
name
=
_name
;
}
float
getPrice
()
const
{
return
price
;
}
void
setPrice
(
const
float
_price
)
{
price
=
_price
;
}
};
};
class
DeckList
:
public
QObject
{
Q_OBJECT
public:
enum
FileFormat
{
PlainTextFormat
,
CockatriceFormat
};
private:
QString
name
,
comments
;
QString
lastFileName
;
QString
deckHash
;
FileFormat
lastFileFormat
;
QMap
<
QString
,
SideboardPlan
*>
sideboardPlans
;
InnerDecklistNode
*
root
;
QString
currentElementText
;
void
getCardListHelper
(
InnerDecklistNode
*
node
,
QSet
<
QString
>
&
result
)
const
;
signals:
void
deckLoaded
();
void
deckHashChanged
();
public
slots
:
void
setName
(
const
QString
&
_name
=
QString
())
{
name
=
_name
;
}
void
setComments
(
const
QString
&
_comments
=
QString
())
{
comments
=
_comments
;
}
public:
static
const
QStringList
fileNameFilters
;
DeckList
();
DeckList
(
DeckList
*
other
);
DeckList
(
const
DeckList
&
other
);
DeckList
(
const
QString
&
nativeString
);
~
DeckList
();
QString
getName
()
const
{
return
name
;
}
QString
getComments
()
const
{
return
comments
;
}
QString
getLastFileName
()
const
{
return
lastFileName
;
}
FileFormat
getLastFileFormat
()
const
{
return
lastFileFormat
;
}
QList
<
MoveCard_ToZone
>
getCurrentSideboardPlan
();
void
setCurrentSideboardPlan
(
const
QList
<
MoveCard_ToZone
>
&
plan
);
const
QMap
<
QString
,
SideboardPlan
*>
&
getSideboardPlans
()
const
{
return
sideboardPlans
;
}
bool
readElement
(
QXmlStreamReader
*
xml
);
void
write
(
QXmlStreamWriter
*
xml
);
void
loadFromXml
(
QXmlStreamReader
*
xml
);
bool
loadFromXml
(
QXmlStreamReader
*
xml
);
bool
loadFromString_Native
(
const
QString
&
nativeString
);
QString
writeToString_Native
();
bool
loadFromFile_Native
(
QIODevice
*
device
);
bool
saveToFile_Native
(
QIODevice
*
device
);
...
...
@@ -152,9 +144,6 @@ public:
bool
loadFromFile_Plain
(
QIODevice
*
device
);
bool
saveToStream_Plain
(
QTextStream
&
stream
);
bool
saveToFile_Plain
(
QIODevice
*
device
);
bool
loadFromFile
(
const
QString
&
fileName
,
FileFormat
fmt
);
bool
saveToFile
(
const
QString
&
fileName
,
FileFormat
fmt
);
static
FileFormat
getFormatFromNameFilter
(
const
QString
&
selectedNameFilter
);
void
cleanList
();
bool
isEmpty
()
const
{
return
root
->
isEmpty
()
&&
name
.
isEmpty
()
&&
comments
.
isEmpty
()
&&
sideboardPlans
.
isEmpty
();
}
...
...
common/pb/command_deck_upload.proto
View file @
0eee6d7a
...
...
@@ -4,7 +4,7 @@ message Command_DeckUpload {
extend
SessionCommand
{
optional
Command_DeckUpload
ext
=
1013
;
}
optional
string
path
=
1
;
optional
string
deck_list
=
2
;
optional
string
path
=
1
;
// to upload a new deck
optional
uint32
deck_id
=
2
;
// to replace an existing deck
optional
string
deck_list
=
3
;
}
servatrice/src/serversocketinterface.cpp
View file @
0eee6d7a
...
...
@@ -455,13 +455,10 @@ Response::ResponseCode ServerSocketInterface::cmdDeckUpload(const Command_DeckUp
if
(
authState
!=
PasswordRight
)
return
Response
::
RespFunctionNotAllowed
;
servatrice
->
checkSql
();
if
(
!
cmd
.
has_deck_list
())
return
Response
::
RespInvalidData
;
int
folderId
=
getDeckPathId
(
QString
::
fromStdString
(
cmd
.
path
()));
if
(
folderId
==
-
1
)
return
Response
::
RespNameNotFound
;
servatrice
->
checkSql
();
QString
deckStr
=
QString
::
fromStdString
(
cmd
.
deck_list
());
DeckList
deck
(
deckStr
);
...
...
@@ -469,22 +466,48 @@ Response::ResponseCode ServerSocketInterface::cmdDeckUpload(const Command_DeckUp
QString
deckName
=
deck
.
getName
();
if
(
deckName
.
isEmpty
())
deckName
=
"Unnamed deck"
;
QMutexLocker
locker
(
&
servatrice
->
dbMutex
);
QSqlQuery
query
;
query
.
prepare
(
"insert into "
+
servatrice
->
getDbPrefix
()
+
"_decklist_files (id_folder, user, name, upload_time, content) values(:id_folder, :user, :name, NOW(), :content)"
);
query
.
bindValue
(
":id_folder"
,
folderId
);
query
.
bindValue
(
":user"
,
QString
::
fromStdString
(
userInfo
->
name
()));
query
.
bindValue
(
":name"
,
deckName
);
query
.
bindValue
(
":content"
,
deckStr
);
servatrice
->
execSqlQuery
(
query
);
Response_DeckUpload
*
re
=
new
Response_DeckUpload
;
ServerInfo_DeckStorage_TreeItem
*
fileInfo
=
re
->
mutable_new_file
();
fileInfo
->
set_id
(
query
.
lastInsertId
().
toInt
());
fileInfo
->
set_name
(
deckName
.
toStdString
());
fileInfo
->
mutable_file
()
->
set_creation_time
(
QDateTime
::
currentDateTime
().
toTime_t
());
rc
.
setResponseExtension
(
re
);
if
(
cmd
.
has_path
())
{
int
folderId
=
getDeckPathId
(
QString
::
fromStdString
(
cmd
.
path
()));
if
(
folderId
==
-
1
)
return
Response
::
RespNameNotFound
;
QMutexLocker
locker
(
&
servatrice
->
dbMutex
);
QSqlQuery
query
;
query
.
prepare
(
"insert into "
+
servatrice
->
getDbPrefix
()
+
"_decklist_files (id_folder, user, name, upload_time, content) values(:id_folder, :user, :name, NOW(), :content)"
);
query
.
bindValue
(
":id_folder"
,
folderId
);
query
.
bindValue
(
":user"
,
QString
::
fromStdString
(
userInfo
->
name
()));
query
.
bindValue
(
":name"
,
deckName
);
query
.
bindValue
(
":content"
,
deckStr
);
servatrice
->
execSqlQuery
(
query
);
Response_DeckUpload
*
re
=
new
Response_DeckUpload
;
ServerInfo_DeckStorage_TreeItem
*
fileInfo
=
re
->
mutable_new_file
();
fileInfo
->
set_id
(
query
.
lastInsertId
().
toInt
());
fileInfo
->
set_name
(
deckName
.
toStdString
());
fileInfo
->
mutable_file
()
->
set_creation_time
(
QDateTime
::
currentDateTime
().
toTime_t
());
rc
.
setResponseExtension
(
re
);
}
else
if
(
cmd
.
has_deck_id
())
{
QMutexLocker
locker
(
&
servatrice
->
dbMutex
);
QSqlQuery
query
;
query
.
prepare
(
"update "
+
servatrice
->
getDbPrefix
()
+
"_decklist_files set name=:name, upload_time=NOW(), content=:content where id = :id_deck and user = :user"
);
query
.
bindValue
(
":id_deck"
,
cmd
.
deck_id
());
query
.
bindValue
(
":user"
,
QString
::
fromStdString
(
userInfo
->
name
()));
query
.
bindValue
(
":name"
,
deckName
);
query
.
bindValue
(
":content"
,
deckStr
);
servatrice
->
execSqlQuery
(
query
);
if
(
query
.
numRowsAffected
()
==
0
)
return
Response
::
RespNameNotFound
;
Response_DeckUpload
*
re
=
new
Response_DeckUpload
;
ServerInfo_DeckStorage_TreeItem
*
fileInfo
=
re
->
mutable_new_file
();
fileInfo
->
set_id
(
cmd
.
deck_id
());
fileInfo
->
set_name
(
deckName
.
toStdString
());
fileInfo
->
mutable_file
()
->
set_creation_time
(
QDateTime
::
currentDateTime
().
toTime_t
());
rc
.
setResponseExtension
(
re
);
}
else
return
Response
::
RespInvalidData
;
return
Response
::
RespOk
;
}
...
...
Prev
1
2
Next
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