mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-01 11:03:54 -07:00
Support multi-select for remote decks in deck storage tab (#5315)
* enable multiselection * support multi open deck * support multi download * support multi delete
This commit is contained in:
parent
a40d8092ce
commit
6e470d788e
4 changed files with 65 additions and 41 deletions
|
|
@ -264,18 +264,19 @@ void TabDeckStorage::actDeleteLocalDeck()
|
||||||
|
|
||||||
void TabDeckStorage::actOpenRemoteDeck()
|
void TabDeckStorage::actOpenRemoteDeck()
|
||||||
{
|
{
|
||||||
RemoteDeckList_TreeModel::FileNode *curRight =
|
for (const auto &curRight : serverDirView->getCurrentSelection()) {
|
||||||
dynamic_cast<RemoteDeckList_TreeModel::FileNode *>(serverDirView->getCurrentItem());
|
RemoteDeckList_TreeModel::FileNode *node = dynamic_cast<RemoteDeckList_TreeModel::FileNode *>(curRight);
|
||||||
if (!curRight)
|
if (!node)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Command_DeckDownload cmd;
|
Command_DeckDownload cmd;
|
||||||
cmd.set_deck_id(curRight->getId());
|
cmd.set_deck_id(node->getId());
|
||||||
|
|
||||||
PendingCommand *pend = client->prepareSessionCommand(cmd);
|
PendingCommand *pend = client->prepareSessionCommand(cmd);
|
||||||
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
|
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
|
||||||
SLOT(openRemoteDeckFinished(Response, CommandContainer)));
|
SLOT(openRemoteDeckFinished(Response, CommandContainer)));
|
||||||
client->sendCommand(pend);
|
client->sendCommand(pend);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabDeckStorage::openRemoteDeckFinished(const Response &r, const CommandContainer &commandContainer)
|
void TabDeckStorage::openRemoteDeckFinished(const Response &r, const CommandContainer &commandContainer)
|
||||||
|
|
@ -295,30 +296,32 @@ void TabDeckStorage::openRemoteDeckFinished(const Response &r, const CommandCont
|
||||||
|
|
||||||
void TabDeckStorage::actDownload()
|
void TabDeckStorage::actDownload()
|
||||||
{
|
{
|
||||||
QString filePath;
|
QString dirPath;
|
||||||
QModelIndex curLeft = localDirView->selectionModel()->currentIndex();
|
QModelIndex curLeft = localDirView->selectionModel()->currentIndex();
|
||||||
if (!curLeft.isValid())
|
if (!curLeft.isValid())
|
||||||
filePath = localDirModel->rootPath();
|
dirPath = localDirModel->rootPath();
|
||||||
else {
|
else {
|
||||||
while (!localDirModel->isDir(curLeft))
|
while (!localDirModel->isDir(curLeft))
|
||||||
curLeft = curLeft.parent();
|
curLeft = curLeft.parent();
|
||||||
filePath = localDirModel->filePath(curLeft);
|
dirPath = localDirModel->filePath(curLeft);
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteDeckList_TreeModel::FileNode *curRight =
|
for (const auto &curRight : serverDirView->getCurrentSelection()) {
|
||||||
dynamic_cast<RemoteDeckList_TreeModel::FileNode *>(serverDirView->getCurrentItem());
|
RemoteDeckList_TreeModel::FileNode *node = dynamic_cast<RemoteDeckList_TreeModel::FileNode *>(curRight);
|
||||||
if (!curRight)
|
if (!node)
|
||||||
return;
|
return;
|
||||||
filePath += QString("/deck_%1.cod").arg(curRight->getId());
|
|
||||||
|
|
||||||
Command_DeckDownload cmd;
|
QString filePath = dirPath + QString("/deck_%1.cod").arg(node->getId());
|
||||||
cmd.set_deck_id(curRight->getId());
|
|
||||||
|
|
||||||
PendingCommand *pend = client->prepareSessionCommand(cmd);
|
Command_DeckDownload cmd;
|
||||||
pend->setExtraData(filePath);
|
cmd.set_deck_id(node->getId());
|
||||||
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
|
|
||||||
SLOT(downloadFinished(Response, CommandContainer, QVariant)));
|
PendingCommand *pend = client->prepareSessionCommand(cmd);
|
||||||
client->sendCommand(pend);
|
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,
|
void TabDeckStorage::downloadFinished(const Response &r,
|
||||||
|
|
@ -374,12 +377,30 @@ void TabDeckStorage::newFolderFinished(const Response &response, const CommandCo
|
||||||
|
|
||||||
void TabDeckStorage::actDeleteRemoteDeck()
|
void TabDeckStorage::actDeleteRemoteDeck()
|
||||||
{
|
{
|
||||||
PendingCommand *pend;
|
auto curRights = serverDirView->getCurrentSelection();
|
||||||
RemoteDeckList_TreeModel::Node *curRight = serverDirView->getCurrentItem();
|
|
||||||
if (!curRight)
|
if (curRights.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
RemoteDeckList_TreeModel::DirectoryNode *dir = dynamic_cast<RemoteDeckList_TreeModel::DirectoryNode *>(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<const RemoteDeckList_TreeModel::DirectoryNode *>(curRight)) {
|
||||||
QString targetPath = dir->getPath();
|
QString targetPath = dir->getPath();
|
||||||
if (targetPath.isEmpty())
|
if (targetPath.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
@ -387,22 +408,13 @@ void TabDeckStorage::actDeleteRemoteDeck()
|
||||||
qCritical() << "target path to delete is too long" << targetPath;
|
qCritical() << "target path to delete is too long" << targetPath;
|
||||||
return;
|
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;
|
Command_DeckDelDir cmd;
|
||||||
cmd.set_path(targetPath.toStdString());
|
cmd.set_path(targetPath.toStdString());
|
||||||
pend = client->prepareSessionCommand(cmd);
|
pend = client->prepareSessionCommand(cmd);
|
||||||
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
|
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
|
||||||
SLOT(deleteFolderFinished(Response, CommandContainer)));
|
SLOT(deleteFolderFinished(Response, CommandContainer)));
|
||||||
} else {
|
} else {
|
||||||
RemoteDeckList_TreeModel::FileNode *deckNode = dynamic_cast<RemoteDeckList_TreeModel::FileNode *>(curRight);
|
const auto *deckNode = dynamic_cast<const RemoteDeckList_TreeModel::FileNode *>(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;
|
|
||||||
|
|
||||||
Command_DeckDel cmd;
|
Command_DeckDel cmd;
|
||||||
cmd.set_deck_id(deckNode->getId());
|
cmd.set_deck_id(deckNode->getId());
|
||||||
pend = client->prepareSessionCommand(cmd);
|
pend = client->prepareSessionCommand(cmd);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef TAB_DECK_STORAGE_H
|
#ifndef TAB_DECK_STORAGE_H
|
||||||
#define TAB_DECK_STORAGE_H
|
#define TAB_DECK_STORAGE_H
|
||||||
|
|
||||||
|
#include "../../server/remote/remote_decklist_tree_widget.h"
|
||||||
#include "tab.h"
|
#include "tab.h"
|
||||||
|
|
||||||
class AbstractClient;
|
class AbstractClient;
|
||||||
|
|
@ -10,7 +11,6 @@ class QToolBar;
|
||||||
class QTreeWidget;
|
class QTreeWidget;
|
||||||
class QTreeWidgetItem;
|
class QTreeWidgetItem;
|
||||||
class QGroupBox;
|
class QGroupBox;
|
||||||
class RemoteDeckList_TreeWidget;
|
|
||||||
class CommandContainer;
|
class CommandContainer;
|
||||||
class Response;
|
class Response;
|
||||||
class DeckLoader;
|
class DeckLoader;
|
||||||
|
|
@ -30,6 +30,7 @@ private:
|
||||||
QString getTargetPath() const;
|
QString getTargetPath() const;
|
||||||
|
|
||||||
void uploadDeck(const QString &filePath, const QString &targetPath);
|
void uploadDeck(const QString &filePath, const QString &targetPath);
|
||||||
|
void deleteRemoteDeck(const RemoteDeckList_TreeModel::Node *node);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void actOpenLocalDeck();
|
void actOpenLocalDeck();
|
||||||
|
|
|
||||||
|
|
@ -300,6 +300,7 @@ RemoteDeckList_TreeWidget::RemoteDeckList_TreeWidget(AbstractClient *_client, QW
|
||||||
|
|
||||||
header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||||
setUniformRowHeights(true);
|
setUniformRowHeights(true);
|
||||||
|
setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||||
setSortingEnabled(true);
|
setSortingEnabled(true);
|
||||||
proxyModel->sort(0, Qt::AscendingOrder);
|
proxyModel->sort(0, Qt::AscendingOrder);
|
||||||
header()->setSortIndicator(0, Qt::AscendingOrder);
|
header()->setSortIndicator(0, Qt::AscendingOrder);
|
||||||
|
|
@ -315,6 +316,15 @@ RemoteDeckList_TreeModel::Node *RemoteDeckList_TreeWidget::getCurrentItem() cons
|
||||||
return getNode(selectionModel()->currentIndex());
|
return getNode(selectionModel()->currentIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<RemoteDeckList_TreeModel::Node *> RemoteDeckList_TreeWidget::getCurrentSelection() const
|
||||||
|
{
|
||||||
|
auto list = QList<RemoteDeckList_TreeModel::Node *>();
|
||||||
|
for (const auto &row : selectionModel()->selectedRows()) {
|
||||||
|
list << getNode(row);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
RemoteDeckList_TreeModel::DirectoryNode *RemoteDeckList_TreeWidget::getNodeByPath(const QString &path) const
|
RemoteDeckList_TreeModel::DirectoryNode *RemoteDeckList_TreeWidget::getNodeByPath(const QString &path) const
|
||||||
{
|
{
|
||||||
return treeModel->getRoot()->getNodeByPath(path.split("/"));
|
return treeModel->getRoot()->getNodeByPath(path.split("/"));
|
||||||
|
|
|
||||||
|
|
@ -118,6 +118,7 @@ public:
|
||||||
RemoteDeckList_TreeWidget(AbstractClient *_client, QWidget *parent = nullptr);
|
RemoteDeckList_TreeWidget(AbstractClient *_client, QWidget *parent = nullptr);
|
||||||
RemoteDeckList_TreeModel::Node *getNode(const QModelIndex &ind) const;
|
RemoteDeckList_TreeModel::Node *getNode(const QModelIndex &ind) const;
|
||||||
RemoteDeckList_TreeModel::Node *getCurrentItem() const;
|
RemoteDeckList_TreeModel::Node *getCurrentItem() const;
|
||||||
|
QList<RemoteDeckList_TreeModel::Node *> getCurrentSelection() const;
|
||||||
RemoteDeckList_TreeModel::DirectoryNode *getNodeByPath(const QString &path) const;
|
RemoteDeckList_TreeModel::DirectoryNode *getNodeByPath(const QString &path) const;
|
||||||
RemoteDeckList_TreeModel::FileNode *getNodeById(int id) const;
|
RemoteDeckList_TreeModel::FileNode *getNodeById(int id) const;
|
||||||
void addFileToTree(const ServerInfo_DeckStorage_TreeItem &file, RemoteDeckList_TreeModel::DirectoryNode *parent);
|
void addFileToTree(const ServerInfo_DeckStorage_TreeItem &file, RemoteDeckList_TreeModel::DirectoryNode *parent);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue