new server deck folder display

This commit is contained in:
Max-Wilhelm Bruker 2009-12-03 18:43:43 +01:00
parent fb61b442ca
commit bf92ef87da
6 changed files with 401 additions and 130 deletions

View file

@ -31,22 +31,17 @@ DlgLoadRemoteDeck::DlgLoadRemoteDeck(Client *_client, QWidget *parent)
setMinimumWidth(sizeHint().width());
resize(300, 500);
connect(dirView, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
connect(dirView->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(currentItemChanged(const QModelIndex &, const QModelIndex &)));
connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
}
void DlgLoadRemoteDeck::currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem * /*previous*/)
void DlgLoadRemoteDeck::currentItemChanged(const QModelIndex &current, const QModelIndex & /*previous*/)
{
if (!current)
okButton->setEnabled(false);
else if (current->type() == TWIDeckType)
okButton->setEnabled(true);
else
okButton->setEnabled(false);
okButton->setEnabled(dynamic_cast<RemoteDeckList_TreeModel::FileNode *>(dirView->getNode(current)));
}
int DlgLoadRemoteDeck::getDeckId() const
{
return dirView->currentItem()->data(1, Qt::DisplayRole).toInt();
return dynamic_cast<RemoteDeckList_TreeModel::FileNode *>(dirView->getNode(dirView->selectionModel()->currentIndex()))->getId();
}

View file

@ -4,7 +4,7 @@
#include <QDialog>
class RemoteDeckList_TreeWidget;
class QTreeWidgetItem;
class QModelIndex;
class Client;
class QPushButton;
@ -15,7 +15,7 @@ private:
RemoteDeckList_TreeWidget *dirView;
QPushButton *okButton, *cancelButton;
private slots:
void currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
void currentItemChanged(const QModelIndex &current, const QModelIndex &previous);
public:
DlgLoadRemoteDeck(Client *_client, QWidget *parent = 0);
int getDeckId() const;

View file

@ -6,7 +6,7 @@ GameView::GameView(QGraphicsScene *scene, QWidget *parent)
setBackgroundBrush(QBrush(QColor(0, 0, 0)));
setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing/* | QPainter::SmoothPixmapTransform*/);
setDragMode(RubberBandDrag);
// setViewportUpdateMode(FullViewportUpdate);
setViewportUpdateMode(BoundingRectViewportUpdate);
connect(scene, SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(updateSceneRect(const QRectF &)));
}

View file

@ -1,61 +1,219 @@
#include <QFileIconProvider>
#include <QHeaderView>
#include <QSortFilterProxyModel>
#include "remotedecklist_treewidget.h"
#include "protocol_items.h"
#include "client.h"
RemoteDeckList_TreeWidget::RemoteDeckList_TreeWidget(Client *_client, QWidget *parent)
: QTreeWidget(parent), client(_client)
RemoteDeckList_TreeModel::DirectoryNode::DirectoryNode(const QString &_name, RemoteDeckList_TreeModel::DirectoryNode *_parent)
: RemoteDeckList_TreeModel::Node(_name, _parent)
{
header()->setResizeMode(QHeaderView::ResizeToContents);
setColumnCount(3);
refreshTree();
retranslateUi();
}
void RemoteDeckList_TreeWidget::retranslateUi()
RemoteDeckList_TreeModel::DirectoryNode::~DirectoryNode()
{
headerItem()->setText(0, tr("Name"));
headerItem()->setText(1, tr("ID"));
headerItem()->setText(2, tr("Upload time"));
headerItem()->setTextAlignment(1, Qt::AlignRight);
clearTree();
}
void RemoteDeckList_TreeWidget::addFileToTree(DeckList_File *file, QTreeWidgetItem *parent)
void RemoteDeckList_TreeModel::DirectoryNode::clearTree()
{
QFileIconProvider fip;
QTreeWidgetItem *newDeck = new QTreeWidgetItem(TWIDeckType);
newDeck->setIcon(0, fip.icon(QFileIconProvider::File));
newDeck->setData(0, Qt::DisplayRole, file->getName());
newDeck->setData(1, Qt::DisplayRole, file->getId());
newDeck->setTextAlignment(1, Qt::AlignRight);
newDeck->setData(2, Qt::DisplayRole, file->getUploadTime());
parent->addChild(newDeck);
sortItems(0, Qt::AscendingOrder);
for (int i = 0; i < size(); ++i)
delete at(i);
clear();
}
void RemoteDeckList_TreeWidget::addFolderToTree(DeckList_Directory *folder, QTreeWidgetItem *parent)
QString RemoteDeckList_TreeModel::DirectoryNode::getPath() const
{
QFileIconProvider fip;
QTreeWidgetItem *newItem = new QTreeWidgetItem(TWIFolderType);
newItem->setIcon(0, fip.icon(QFileIconProvider::Folder));
newItem->setText(0, parent ? folder->getName() : "/");
if (parent) {
parent->addChild(newItem);
QString path = parent->data(0, Qt::UserRole).toString();
if (path.isEmpty())
newItem->setData(0, Qt::UserRole, folder->getName());
QString parentPath = parent->getPath();
if (parentPath.isEmpty())
return name;
else
newItem->setData(0, Qt::UserRole, path + "/" + folder->getName());
} else {
addTopLevelItem(newItem);
newItem->setData(0, Qt::UserRole, QString());
return parentPath + "/" + name;
} else
return name;
}
const QList<DeckList_TreeItem *> &folderItems = folder->getTreeItems();
RemoteDeckList_TreeModel::DirectoryNode *RemoteDeckList_TreeModel::DirectoryNode::getNodeByPath(QStringList path)
{
QString pathItem;
if (parent) {
if (path.isEmpty())
return this;
pathItem = path.takeFirst();
if (pathItem.isEmpty() && name.isEmpty())
return this;
}
for (int i = 0; i < size(); ++i) {
DirectoryNode *node = dynamic_cast<DirectoryNode *>(at(i));
if (!node)
continue;
if (node->getName() == pathItem)
return node->getNodeByPath(path);
}
return 0;
}
RemoteDeckList_TreeModel::FileNode *RemoteDeckList_TreeModel::DirectoryNode::getNodeById(int id) const
{
for (int i = 0; i < size(); ++i) {
DirectoryNode *node = dynamic_cast<DirectoryNode *>(at(i));
if (node) {
FileNode *result = node->getNodeById(id);
if (result)
return result;
} else {
FileNode *file = dynamic_cast<FileNode *>(at(i));
if (file->getId() == id)
return file;
}
}
return 0;
}
RemoteDeckList_TreeModel::RemoteDeckList_TreeModel(Client *_client, QObject *parent)
: QAbstractItemModel(parent), client(_client)
{
root = new DirectoryNode;
refreshTree();
}
RemoteDeckList_TreeModel::~RemoteDeckList_TreeModel()
{
delete root;
}
int RemoteDeckList_TreeModel::rowCount(const QModelIndex &parent) const
{
DirectoryNode *node = getNode<DirectoryNode *>(parent);
if (node)
return node->size();
else
return 0;
}
int RemoteDeckList_TreeModel::columnCount(const QModelIndex &/*parent*/) const
{
return 3;
}
QVariant RemoteDeckList_TreeModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (index.column() >= 3)
return QVariant();
Node *temp = static_cast<Node *>(index.internalPointer());
FileNode *file = dynamic_cast<FileNode *>(temp);
if (!file) {
DirectoryNode *node = dynamic_cast<DirectoryNode *>(temp);
switch (role) {
case Qt::DisplayRole: {
switch (index.column()) {
case 0: return node->getName();
default:
return QVariant();
}
}
case Qt::DecorationRole:
return index.column() == 0 ? QFileIconProvider().icon(QFileIconProvider::Folder) : QVariant();
default: return QVariant();
}
} else {
switch (role) {
case Qt::DisplayRole: {
switch (index.column()) {
case 0: return file->getName();
case 1: return file->getId();
case 2: return file->getUploadTime();
default:
return QVariant();
}
}
case Qt::DecorationRole:
return index.column() == 0 ? QFileIconProvider().icon(QFileIconProvider::File) : QVariant();
case Qt::TextAlignmentRole:
return index.column() == 1 ? Qt::AlignRight : Qt::AlignLeft;
default: return QVariant();
}
}
}
QVariant RemoteDeckList_TreeModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation != Qt::Horizontal)
return QVariant();
switch (role) {
case Qt::TextAlignmentRole:
return section == 1 ? Qt::AlignRight : Qt::AlignLeft;
case Qt::DisplayRole: {
switch (section) {
case 0: return tr("Name");
case 1: return tr("ID");
case 2: return tr("Upload time");
default: return QVariant();
}
}
default: return QVariant();
}
}
QModelIndex RemoteDeckList_TreeModel::index(int row, int column, const QModelIndex &parent) const
{
if (!hasIndex(row, column, parent))
return QModelIndex();
DirectoryNode *parentNode = getNode<DirectoryNode *>(parent);
if (row >= parentNode->size())
return QModelIndex();
return createIndex(row, column, parentNode->at(row));
}
QModelIndex RemoteDeckList_TreeModel::parent(const QModelIndex &ind) const
{
if (!ind.isValid())
return QModelIndex();
return nodeToIndex(static_cast<Node *>(ind.internalPointer())->getParent());
}
Qt::ItemFlags RemoteDeckList_TreeModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return 0;
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
QModelIndex RemoteDeckList_TreeModel::nodeToIndex(Node *node) const
{
if (node == root)
return QModelIndex();
return createIndex(node->getParent()->indexOf(node), 0, node);
}
void RemoteDeckList_TreeModel::addFileToTree(DeckList_File *file, DirectoryNode *parent)
{
beginInsertRows(nodeToIndex(parent), parent->size(), parent->size());
parent->append(new FileNode(file->getName(), file->getId(), file->getUploadTime(), parent));
endInsertRows();
}
void RemoteDeckList_TreeModel::addFolderToTree(DeckList_Directory *folder, DirectoryNode *parent)
{
addFolderToTree(folder->getName(), folder->getTreeItems(), parent);
}
void RemoteDeckList_TreeModel::addFolderToTree(const QString &name, const QList<DeckList_TreeItem *> &folderItems, DirectoryNode *parent)
{
DirectoryNode *newItem = new DirectoryNode(name, parent);
beginInsertRows(nodeToIndex(parent), parent->size(), parent->size());
parent->append(newItem);
endInsertRows();
for (int i = 0; i < folderItems.size(); ++i) {
DeckList_Directory *subFolder = dynamic_cast<DeckList_Directory *>(folderItems[i]);
if (subFolder)
@ -63,23 +221,95 @@ void RemoteDeckList_TreeWidget::addFolderToTree(DeckList_Directory *folder, QTre
else
addFileToTree(dynamic_cast<DeckList_File *>(folderItems[i]), newItem);
}
sortItems(0, Qt::AscendingOrder);
}
void RemoteDeckList_TreeWidget::refreshTree()
void RemoteDeckList_TreeModel::removeNode(RemoteDeckList_TreeModel::Node *node)
{
int ind = node->getParent()->indexOf(node);
beginRemoveRows(nodeToIndex(node->getParent()), ind, ind);
node->getParent()->removeAt(ind);
endRemoveRows();
delete node;
}
void RemoteDeckList_TreeModel::refreshTree()
{
Command_DeckList *command = new Command_DeckList;
connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(deckListFinished(ProtocolResponse *)));
client->sendCommand(command);
}
void RemoteDeckList_TreeWidget::deckListFinished(ProtocolResponse *r)
void RemoteDeckList_TreeModel::deckListFinished(ProtocolResponse *r)
{
Response_DeckList *resp = qobject_cast<Response_DeckList *>(r);
if (!resp)
return;
clear();
addFolderToTree(resp->getRoot(), 0);
expandAll();
root->clearTree();
reset();
addFolderToTree(resp->getRoot(), root);
emit treeRefreshed();
}
RemoteDeckList_TreeWidget::RemoteDeckList_TreeWidget(Client *_client, QWidget *parent)
: QTreeView(parent)
{
treeModel = new RemoteDeckList_TreeModel(_client, this);
proxyModel = new QSortFilterProxyModel(this);
proxyModel->setSourceModel(treeModel);
proxyModel->setDynamicSortFilter(true);
proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
setModel(proxyModel);
connect(treeModel, SIGNAL(treeRefreshed()), this, SLOT(expandAll()));
header()->setResizeMode(QHeaderView::ResizeToContents);
setSortingEnabled(true);
proxyModel->sort(0, Qt::AscendingOrder);
header()->setSortIndicator(0, Qt::AscendingOrder);
}
RemoteDeckList_TreeModel::Node *RemoteDeckList_TreeWidget::getNode(const QModelIndex &ind) const
{
return treeModel->getNode<RemoteDeckList_TreeModel::Node *>(proxyModel->mapToSource(ind));
}
RemoteDeckList_TreeModel::Node *RemoteDeckList_TreeWidget::getCurrentItem() const
{
return getNode(selectionModel()->currentIndex());
}
RemoteDeckList_TreeModel::DirectoryNode *RemoteDeckList_TreeWidget::getNodeByPath(const QString &path) const
{
return treeModel->getRoot()->getNodeByPath(path.split("/"));
}
RemoteDeckList_TreeModel::FileNode *RemoteDeckList_TreeWidget::getNodeById(int id) const
{
return treeModel->getRoot()->getNodeById(id);
}
void RemoteDeckList_TreeWidget::addFileToTree(DeckList_File *file, RemoteDeckList_TreeModel::DirectoryNode *parent)
{
treeModel->addFileToTree(file, parent);
}
void RemoteDeckList_TreeWidget::addFolderToTree(DeckList_Directory *folder, RemoteDeckList_TreeModel::DirectoryNode *parent)
{
treeModel->addFolderToTree(folder, parent);
}
void RemoteDeckList_TreeWidget::addFolderToTree(const QString &name, RemoteDeckList_TreeModel::DirectoryNode *parent)
{
treeModel->addFolderToTree(name, QList<DeckList_TreeItem *>(), parent);
}
void RemoteDeckList_TreeWidget::removeNode(RemoteDeckList_TreeModel::Node *node)
{
treeModel->removeNode(node);
}
void RemoteDeckList_TreeWidget::refreshTree()
{
treeModel->refreshTree();
}

View file

@ -1,26 +1,101 @@
#ifndef REMOTEDECKLIST_TREEWIDGET_H
#define REMOTEDECKLIST_TREEWIDGET_H
#include <QTreeWidget>
#include <QAbstractItemModel>
#include <QDateTime>
#include <QTreeView>
class ProtocolResponse;
class Client;
class QSortFilterProxyModel;
class DeckList_File;
class DeckList_Directory;
class DeckList_TreeItem;
enum { TWIFolderType = QTreeWidgetItem::UserType + 1, TWIDeckType = QTreeWidgetItem::UserType + 2 };
class RemoteDeckList_TreeWidget : public QTreeWidget {
class RemoteDeckList_TreeModel : public QAbstractItemModel {
Q_OBJECT
public:
class DirectoryNode;
class FileNode;
class Node {
protected:
DirectoryNode *parent;
QString name;
public:
Node(const QString &_name, DirectoryNode *_parent = 0)
: parent(_parent), name(_name) { }
virtual ~Node() { };
DirectoryNode *getParent() const { return parent; }
QString getName() const { return name; }
};
class DirectoryNode : public Node, public QList<Node *> {
public:
DirectoryNode(const QString &_name = QString(), DirectoryNode *_parent = 0);
~DirectoryNode();
void clearTree();
QString getPath() const;
DirectoryNode *getNodeByPath(QStringList path);
FileNode *getNodeById(int id) const;
};
class FileNode : public Node {
private:
int id;
QDateTime uploadTime;
public:
FileNode(const QString &_name, int _id, const QDateTime &_uploadTime, DirectoryNode *_parent = 0)
: Node(_name, _parent), id(_id), uploadTime(_uploadTime) { }
int getId() const { return id; }
QDateTime getUploadTime() const { return uploadTime; }
};
template<typename T> T getNode(const QModelIndex &index) const
{
if (!index.isValid())
return dynamic_cast<T>(root);
return dynamic_cast<T>(static_cast<Node *>(index.internalPointer()));
}
private:
Client *client;
DirectoryNode *root;
QModelIndex nodeToIndex(Node *node) const;
signals:
void treeRefreshed();
private slots:
void deckListFinished(ProtocolResponse *r);
public:
RemoteDeckList_TreeModel(Client *_client, QObject *parent = 0);
~RemoteDeckList_TreeModel();
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &index) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
DirectoryNode *getRoot() const { return root; }
void addFileToTree(DeckList_File *file, DirectoryNode *parent);
void addFolderToTree(DeckList_Directory *folder, DirectoryNode *parent);
void addFolderToTree(const QString &name, const QList<DeckList_TreeItem *> &folderItems, DirectoryNode *parent);
void removeNode(Node *node);
void refreshTree();
};
class RemoteDeckList_TreeWidget : public QTreeView {
private:
RemoteDeckList_TreeModel *treeModel;
QSortFilterProxyModel *proxyModel;
public:
RemoteDeckList_TreeWidget(Client *_client, QWidget *parent = 0);
void retranslateUi();
void addFileToTree(DeckList_File *file, QTreeWidgetItem *parent);
void addFolderToTree(DeckList_Directory *folder, QTreeWidgetItem *parent);
RemoteDeckList_TreeModel::Node *getNode(const QModelIndex &ind) const;
RemoteDeckList_TreeModel::Node *getCurrentItem() const;
RemoteDeckList_TreeModel::DirectoryNode *getNodeByPath(const QString &path) const;
RemoteDeckList_TreeModel::FileNode *getNodeById(int id) const;
void addFileToTree(DeckList_File *file, RemoteDeckList_TreeModel::DirectoryNode *parent);
void addFolderToTree(DeckList_Directory *folder, RemoteDeckList_TreeModel::DirectoryNode *parent);
void addFolderToTree(const QString &name, RemoteDeckList_TreeModel::DirectoryNode *parent);
void removeNode(RemoteDeckList_TreeModel::Node *node);
void refreshTree();
};

View file

@ -1,5 +1,4 @@
#include <QtGui>
#include <QDebug>
#include "tab_deck_storage.h"
#include "remotedecklist_treewidget.h"
#include "client.h"
@ -23,6 +22,8 @@ TabDeckStorage::TabDeckStorage(Client *_client)
localDirView->setRootIndex(sortFilter->mapFromSource(localDirModel->index(localDirModel->rootPath(), 0)));
localDirView->setSortingEnabled(true);
localDirView->header()->setResizeMode(QHeaderView::ResizeToContents);
sortFilter->sort(0, Qt::AscendingOrder);
localDirView->header()->setSortIndicator(0, Qt::AscendingOrder);
leftToolBar = new QToolBar;
leftToolBar->setOrientation(Qt::Horizontal);
@ -89,8 +90,6 @@ void TabDeckStorage::retranslateUi()
aDownload->setText(tr("Download deck"));
aNewFolder->setText(tr("New folder"));
aDelete->setText(tr("Delete"));
serverDirView->retranslateUi();
}
void TabDeckStorage::actUpload()
@ -110,11 +109,12 @@ void TabDeckStorage::actUpload()
}
QString targetPath;
QTreeWidgetItem *curRight = serverDirView->currentItem();
while ((curRight != 0) && (curRight->type() != TWIFolderType))
curRight = curRight->parent();
if (curRight)
targetPath = curRight->data(0, Qt::UserRole).toString();
RemoteDeckList_TreeModel::Node *curRight = serverDirView->getCurrentItem();
if (!curRight)
return;
if (!dynamic_cast<RemoteDeckList_TreeModel::DirectoryNode *>(curRight))
curRight = curRight->getParent();
targetPath = dynamic_cast<RemoteDeckList_TreeModel::DirectoryNode *>(curRight)->getPath();
Command_DeckUpload *command = new Command_DeckUpload(deck, targetPath);
connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(uploadFinished(ProtocolResponse *)));
@ -128,14 +128,7 @@ void TabDeckStorage::uploadFinished(ProtocolResponse *r)
return;
Command_DeckUpload *cmd = static_cast<Command_DeckUpload *>(sender());
QTreeWidgetItemIterator it(serverDirView);
while (*it) {
if ((*it)->data(0, Qt::UserRole) == cmd->getPath()) {
serverDirView->addFileToTree(resp->getFile(), *it);
break;
}
++it;
}
serverDirView->addFileToTree(resp->getFile(), serverDirView->getNodeByPath(cmd->getPath()));
}
void TabDeckStorage::actDownload()
@ -150,12 +143,12 @@ void TabDeckStorage::actDownload()
filePath = localDirModel->filePath(curLeft);
}
QTreeWidgetItem *curRight = serverDirView->currentItem();
if ((!curRight) || (curRight->type() != TWIDeckType))
RemoteDeckList_TreeModel::FileNode *curRight = dynamic_cast<RemoteDeckList_TreeModel::FileNode *>(serverDirView->getCurrentItem());
if (!curRight)
return;
filePath += "/" + curRight->data(1, Qt::DisplayRole).toString() + ".cod";
filePath += QString("/deck_%1.cod").arg(curRight->getId());
Command_DeckDownload *command = new Command_DeckDownload(curRight->data(1, Qt::DisplayRole).toInt());
Command_DeckDownload *command = new Command_DeckDownload(curRight->getId());
command->setExtraData(filePath);
connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(downloadFinished(ProtocolResponse *)));
client->sendCommand(command);
@ -179,11 +172,13 @@ void TabDeckStorage::actNewFolder()
return;
QString targetPath;
QTreeWidgetItem *curRight = serverDirView->currentItem();
while ((curRight != 0) && (curRight->type() != TWIFolderType))
curRight = curRight->parent();
if (curRight)
targetPath = curRight->data(0, Qt::UserRole).toString();
RemoteDeckList_TreeModel::Node *curRight = serverDirView->getCurrentItem();
if (!curRight)
return;
if (!dynamic_cast<RemoteDeckList_TreeModel::DirectoryNode *>(curRight))
curRight = curRight->getParent();
RemoteDeckList_TreeModel::DirectoryNode *dir = dynamic_cast<RemoteDeckList_TreeModel::DirectoryNode *>(curRight);
targetPath = dir->getPath();
Command_DeckNewDir *command = new Command_DeckNewDir(targetPath, folderName);
connect(command, SIGNAL(finished(ResponseCode)), this, SLOT(newFolderFinished(ResponseCode)));
@ -196,33 +191,23 @@ void TabDeckStorage::newFolderFinished(ResponseCode resp)
return;
Command_DeckNewDir *cmd = static_cast<Command_DeckNewDir *>(sender());
qDebug() << cmd->getPath() << cmd->getDirName();
QTreeWidgetItemIterator it(serverDirView);
while (*it) {
if ((*it)->data(0, Qt::UserRole) == cmd->getPath()) {
QFileIconProvider fip;
QTreeWidgetItem *newItem = new QTreeWidgetItem(TWIFolderType);
newItem->setIcon(0, fip.icon(QFileIconProvider::Folder));
newItem->setText(0, cmd->getDirName());
newItem->setData(0, Qt::UserRole, cmd->getPath() + "/" + cmd->getDirName());
(*it)->addChild(newItem);
break;
}
++it;
}
serverDirView->addFolderToTree(cmd->getDirName(), serverDirView->getNodeByPath(cmd->getPath()));
}
void TabDeckStorage::actDelete()
{
Command *command;
QTreeWidgetItem *curRight = serverDirView->currentItem();
if (curRight->type() == TWIFolderType) {
if (curRight->data(0, Qt::UserRole).toString().isEmpty())
RemoteDeckList_TreeModel::Node *curRight = serverDirView->getCurrentItem();
if (!curRight)
return;
command = new Command_DeckDelDir(curRight->data(0, Qt::UserRole).toString());
RemoteDeckList_TreeModel::DirectoryNode *dir = dynamic_cast<RemoteDeckList_TreeModel::DirectoryNode *>(curRight);
if (dir) {
QString path = dir->getPath();
if (path.isEmpty())
return;
command = new Command_DeckDelDir(path);
} else
command = new Command_DeckDel(curRight->data(1, Qt::DisplayRole).toInt());
command = new Command_DeckDel(dynamic_cast<RemoteDeckList_TreeModel::FileNode *>(curRight)->getId());
connect(command, SIGNAL(finished(ResponseCode)), this, SLOT(deleteFinished(ResponseCode)));
client->sendCommand(command);
}
@ -232,27 +217,13 @@ void TabDeckStorage::deleteFinished(ResponseCode resp)
if (resp != RespOk)
return;
QTreeWidgetItem *toDelete = 0;
QTreeWidgetItemIterator it(serverDirView);
RemoteDeckList_TreeModel::Node *toDelete = 0;
Command_DeckDelDir *cmdDelDir = qobject_cast<Command_DeckDelDir *>(sender());
if (cmdDelDir) {
while (*it) {
if ((*it)->data(0, Qt::UserRole).toString() == cmdDelDir->getPath()) {
toDelete = *it;
break;
}
++it;
}
} else {
Command_DeckDel *cmdDel = qobject_cast<Command_DeckDel *>(sender());
while (*it) {
if ((*it)->data(1, Qt::DisplayRole).toInt() == cmdDel->getDeckId()) {
toDelete = *it;
break;
}
++it;
}
}
if (cmdDelDir)
toDelete = serverDirView->getNodeByPath(cmdDelDir->getPath());
else
toDelete = serverDirView->getNodeById(static_cast<Command_DeckDel *>(sender())->getDeckId());
if (toDelete)
delete toDelete;
serverDirView->removeNode(toDelete);
}