mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-24 15:43:54 -07:00
Support folder download in deck storage tab (#5356)
* refactor * support folder download
This commit is contained in:
parent
3452cb01d0
commit
4c7796537f
2 changed files with 29 additions and 13 deletions
|
|
@ -376,25 +376,38 @@ void TabDeckStorage::openRemoteDeckFinished(const Response &r, const CommandCont
|
||||||
|
|
||||||
void TabDeckStorage::actDownload()
|
void TabDeckStorage::actDownload()
|
||||||
{
|
{
|
||||||
QString dirPath;
|
|
||||||
QModelIndex curLeft = localDirView->selectionModel()->currentIndex();
|
QModelIndex curLeft = localDirView->selectionModel()->currentIndex();
|
||||||
if (!curLeft.isValid())
|
while (!localDirModel->isDir(curLeft)) {
|
||||||
dirPath = localDirModel->rootPath();
|
curLeft = curLeft.parent();
|
||||||
else {
|
|
||||||
while (!localDirModel->isDir(curLeft))
|
|
||||||
curLeft = curLeft.parent();
|
|
||||||
dirPath = localDirModel->filePath(curLeft);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto &curRight : serverDirView->getCurrentSelection()) {
|
for (const auto curRight : serverDirView->selectionModel()->selectedRows()) {
|
||||||
RemoteDeckList_TreeModel::FileNode *node = dynamic_cast<RemoteDeckList_TreeModel::FileNode *>(curRight);
|
downloadNodeAtIndex(curLeft, curRight);
|
||||||
if (!node)
|
}
|
||||||
continue;
|
}
|
||||||
|
|
||||||
QString filePath = dirPath + QString("/deck_%1.cod").arg(node->getId());
|
void TabDeckStorage::downloadNodeAtIndex(const QModelIndex &curLeft, const QModelIndex &curRight)
|
||||||
|
{
|
||||||
|
auto node = serverDirView->getNode(curRight);
|
||||||
|
if (const auto dirNode = dynamic_cast<RemoteDeckList_TreeModel::DirectoryNode *>(node)) {
|
||||||
|
// node at index is a folder
|
||||||
|
const QString name = dirNode->getName();
|
||||||
|
|
||||||
|
const auto dirIndex = curLeft.isValid() ? curLeft : localDirModel->index(localDirModel->rootPath());
|
||||||
|
const auto newDirIndex = localDirModel->mkdir(dirIndex, name);
|
||||||
|
|
||||||
|
int rows = serverDirView->model()->rowCount(curRight);
|
||||||
|
for (int i = 0; i < rows; i++) {
|
||||||
|
const auto childIndex = serverDirView->model()->index(i, 0, curRight);
|
||||||
|
downloadNodeAtIndex(newDirIndex, childIndex);
|
||||||
|
}
|
||||||
|
} else if (const auto fileNode = dynamic_cast<RemoteDeckList_TreeModel::FileNode *>(node)) {
|
||||||
|
// node at index is a deck
|
||||||
|
const QString dirPath = curLeft.isValid() ? localDirModel->filePath(curLeft) : localDirModel->rootPath();
|
||||||
|
const QString filePath = dirPath + QString("/deck_%1.cod").arg(fileNode->getId());
|
||||||
|
|
||||||
Command_DeckDownload cmd;
|
Command_DeckDownload cmd;
|
||||||
cmd.set_deck_id(node->getId());
|
cmd.set_deck_id(fileNode->getId());
|
||||||
|
|
||||||
PendingCommand *pend = client->prepareSessionCommand(cmd);
|
PendingCommand *pend = client->prepareSessionCommand(cmd);
|
||||||
pend->setExtraData(filePath);
|
pend->setExtraData(filePath);
|
||||||
|
|
@ -402,6 +415,7 @@ void TabDeckStorage::actDownload()
|
||||||
SLOT(downloadFinished(Response, CommandContainer, QVariant)));
|
SLOT(downloadFinished(Response, CommandContainer, QVariant)));
|
||||||
client->sendCommand(pend);
|
client->sendCommand(pend);
|
||||||
}
|
}
|
||||||
|
// node at index is invalid
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabDeckStorage::downloadFinished(const Response &r,
|
void TabDeckStorage::downloadFinished(const Response &r,
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,8 @@ private:
|
||||||
void uploadDeck(const QString &filePath, const QString &targetPath);
|
void uploadDeck(const QString &filePath, const QString &targetPath);
|
||||||
void deleteRemoteDeck(const RemoteDeckList_TreeModel::Node *node);
|
void deleteRemoteDeck(const RemoteDeckList_TreeModel::Node *node);
|
||||||
|
|
||||||
|
void downloadNodeAtIndex(const QModelIndex &curLeft, const QModelIndex &curRight);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void actLocalDoubleClick(const QModelIndex &curLeft);
|
void actLocalDoubleClick(const QModelIndex &curLeft);
|
||||||
void actOpenLocalDeck();
|
void actOpenLocalDeck();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue