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:
RickyRister 2024-12-23 21:05:49 -08:00 committed by GitHub
parent a40d8092ce
commit 6e470d788e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 65 additions and 41 deletions

View file

@ -264,18 +264,19 @@ void TabDeckStorage::actDeleteLocalDeck()
void TabDeckStorage::actOpenRemoteDeck()
{
RemoteDeckList_TreeModel::FileNode *curRight =
dynamic_cast<RemoteDeckList_TreeModel::FileNode *>(serverDirView->getCurrentItem());
if (!curRight)
return;
for (const auto &curRight : serverDirView->getCurrentSelection()) {
RemoteDeckList_TreeModel::FileNode *node = dynamic_cast<RemoteDeckList_TreeModel::FileNode *>(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<RemoteDeckList_TreeModel::FileNode *>(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<RemoteDeckList_TreeModel::FileNode *>(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<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();
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<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;
const auto *deckNode = dynamic_cast<const RemoteDeckList_TreeModel::FileNode *>(curRight);
Command_DeckDel cmd;
cmd.set_deck_id(deckNode->getId());
pend = client->prepareSessionCommand(cmd);

View file

@ -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();

View file

@ -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_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
{
return treeModel->getRoot()->getNodeByPath(path.split("/"));

View file

@ -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<RemoteDeckList_TreeModel::Node *> 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);