diff --git a/cockatrice/src/client/tabs/tab_deck_storage.cpp b/cockatrice/src/client/tabs/tab_deck_storage.cpp index 96c7b2d3f..accc9793b 100644 --- a/cockatrice/src/client/tabs/tab_deck_storage.cpp +++ b/cockatrice/src/client/tabs/tab_deck_storage.cpp @@ -264,18 +264,19 @@ void TabDeckStorage::actDeleteLocalDeck() void TabDeckStorage::actOpenRemoteDeck() { - RemoteDeckList_TreeModel::FileNode *curRight = - dynamic_cast(serverDirView->getCurrentItem()); - if (!curRight) - return; + for (const auto &curRight : serverDirView->getCurrentSelection()) { + RemoteDeckList_TreeModel::FileNode *node = dynamic_cast(curRight); + if (!node) + return; - Command_DeckDownload cmd; - cmd.set_deck_id(curRight->getId()); + Command_DeckDownload cmd; + cmd.set_deck_id(node->getId()); - PendingCommand *pend = client->prepareSessionCommand(cmd); - connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, - SLOT(openRemoteDeckFinished(Response, CommandContainer))); - client->sendCommand(pend); + PendingCommand *pend = client->prepareSessionCommand(cmd); + connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, + SLOT(openRemoteDeckFinished(Response, CommandContainer))); + client->sendCommand(pend); + } } void TabDeckStorage::openRemoteDeckFinished(const Response &r, const CommandContainer &commandContainer) @@ -295,30 +296,32 @@ void TabDeckStorage::openRemoteDeckFinished(const Response &r, const CommandCont void TabDeckStorage::actDownload() { - QString filePath; + QString dirPath; QModelIndex curLeft = localDirView->selectionModel()->currentIndex(); if (!curLeft.isValid()) - filePath = localDirModel->rootPath(); + dirPath = localDirModel->rootPath(); else { while (!localDirModel->isDir(curLeft)) curLeft = curLeft.parent(); - filePath = localDirModel->filePath(curLeft); + dirPath = localDirModel->filePath(curLeft); } - RemoteDeckList_TreeModel::FileNode *curRight = - dynamic_cast(serverDirView->getCurrentItem()); - if (!curRight) - return; - filePath += QString("/deck_%1.cod").arg(curRight->getId()); + for (const auto &curRight : serverDirView->getCurrentSelection()) { + RemoteDeckList_TreeModel::FileNode *node = dynamic_cast(curRight); + if (!node) + return; - Command_DeckDownload cmd; - cmd.set_deck_id(curRight->getId()); + QString filePath = dirPath + QString("/deck_%1.cod").arg(node->getId()); - PendingCommand *pend = client->prepareSessionCommand(cmd); - pend->setExtraData(filePath); - connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, - SLOT(downloadFinished(Response, CommandContainer, QVariant))); - client->sendCommand(pend); + Command_DeckDownload cmd; + cmd.set_deck_id(node->getId()); + + PendingCommand *pend = client->prepareSessionCommand(cmd); + pend->setExtraData(filePath); + connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, + SLOT(downloadFinished(Response, CommandContainer, QVariant))); + client->sendCommand(pend); + } } void TabDeckStorage::downloadFinished(const Response &r, @@ -374,12 +377,30 @@ void TabDeckStorage::newFolderFinished(const Response &response, const CommandCo void TabDeckStorage::actDeleteRemoteDeck() { - PendingCommand *pend; - RemoteDeckList_TreeModel::Node *curRight = serverDirView->getCurrentItem(); - if (!curRight) + auto curRights = serverDirView->getCurrentSelection(); + + if (curRights.isEmpty()) { return; - RemoteDeckList_TreeModel::DirectoryNode *dir = dynamic_cast(curRight); - if (dir) { + } + + if (QMessageBox::warning(this, tr("Delete remote decks"), tr("Are you sure you want to delete the selected decks?"), + QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) { + return; + } + + for (const auto &curRight : curRights) { + deleteRemoteDeck(curRight); + } +} + +void TabDeckStorage::deleteRemoteDeck(const RemoteDeckList_TreeModel::Node *curRight) +{ + if (!curRight) { + return; + } + + PendingCommand *pend; + if (const auto *dir = dynamic_cast(curRight)) { QString targetPath = dir->getPath(); if (targetPath.isEmpty()) return; @@ -387,22 +408,13 @@ void TabDeckStorage::actDeleteRemoteDeck() qCritical() << "target path to delete is too long" << targetPath; return; } - if (QMessageBox::warning(this, tr("Delete remote folder"), - tr("Are you sure you want to delete \"%1\"?").arg(targetPath), - QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) - return; Command_DeckDelDir cmd; cmd.set_path(targetPath.toStdString()); pend = client->prepareSessionCommand(cmd); connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(deleteFolderFinished(Response, CommandContainer))); } else { - RemoteDeckList_TreeModel::FileNode *deckNode = dynamic_cast(curRight); - if (QMessageBox::warning(this, tr("Delete remote deck"), - tr("Are you sure you want to delete \"%1\"?").arg(deckNode->getName()), - QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) - return; - + const auto *deckNode = dynamic_cast(curRight); Command_DeckDel cmd; cmd.set_deck_id(deckNode->getId()); pend = client->prepareSessionCommand(cmd); diff --git a/cockatrice/src/client/tabs/tab_deck_storage.h b/cockatrice/src/client/tabs/tab_deck_storage.h index 1a69a621d..fd893646b 100644 --- a/cockatrice/src/client/tabs/tab_deck_storage.h +++ b/cockatrice/src/client/tabs/tab_deck_storage.h @@ -1,6 +1,7 @@ #ifndef TAB_DECK_STORAGE_H #define TAB_DECK_STORAGE_H +#include "../../server/remote/remote_decklist_tree_widget.h" #include "tab.h" class AbstractClient; @@ -10,7 +11,6 @@ class QToolBar; class QTreeWidget; class QTreeWidgetItem; class QGroupBox; -class RemoteDeckList_TreeWidget; class CommandContainer; class Response; class DeckLoader; @@ -30,6 +30,7 @@ private: QString getTargetPath() const; void uploadDeck(const QString &filePath, const QString &targetPath); + void deleteRemoteDeck(const RemoteDeckList_TreeModel::Node *node); private slots: void actOpenLocalDeck(); diff --git a/cockatrice/src/server/remote/remote_decklist_tree_widget.cpp b/cockatrice/src/server/remote/remote_decklist_tree_widget.cpp index 63b6a1ad8..314d7687b 100644 --- a/cockatrice/src/server/remote/remote_decklist_tree_widget.cpp +++ b/cockatrice/src/server/remote/remote_decklist_tree_widget.cpp @@ -300,6 +300,7 @@ RemoteDeckList_TreeWidget::RemoteDeckList_TreeWidget(AbstractClient *_client, QW header()->setSectionResizeMode(QHeaderView::ResizeToContents); setUniformRowHeights(true); + setSelectionMode(QAbstractItemView::ExtendedSelection); setSortingEnabled(true); proxyModel->sort(0, Qt::AscendingOrder); header()->setSortIndicator(0, Qt::AscendingOrder); @@ -315,6 +316,15 @@ RemoteDeckList_TreeModel::Node *RemoteDeckList_TreeWidget::getCurrentItem() cons return getNode(selectionModel()->currentIndex()); } +QList RemoteDeckList_TreeWidget::getCurrentSelection() const +{ + auto list = QList(); + for (const auto &row : selectionModel()->selectedRows()) { + list << getNode(row); + } + return list; +} + RemoteDeckList_TreeModel::DirectoryNode *RemoteDeckList_TreeWidget::getNodeByPath(const QString &path) const { return treeModel->getRoot()->getNodeByPath(path.split("/")); diff --git a/cockatrice/src/server/remote/remote_decklist_tree_widget.h b/cockatrice/src/server/remote/remote_decklist_tree_widget.h index dae77b0d6..59a3e4950 100644 --- a/cockatrice/src/server/remote/remote_decklist_tree_widget.h +++ b/cockatrice/src/server/remote/remote_decklist_tree_widget.h @@ -118,6 +118,7 @@ public: RemoteDeckList_TreeWidget(AbstractClient *_client, QWidget *parent = nullptr); RemoteDeckList_TreeModel::Node *getNode(const QModelIndex &ind) const; RemoteDeckList_TreeModel::Node *getCurrentItem() const; + QList getCurrentSelection() const; RemoteDeckList_TreeModel::DirectoryNode *getNodeByPath(const QString &path) const; RemoteDeckList_TreeModel::FileNode *getNodeById(int id) const; void addFileToTree(const ServerInfo_DeckStorage_TreeItem &file, RemoteDeckList_TreeModel::DirectoryNode *parent);