new server deck folder display
This commit is contained in:
parent
fb61b442ca
commit
bf92ef87da
6 changed files with 401 additions and 130 deletions
|
@ -31,22 +31,17 @@ DlgLoadRemoteDeck::DlgLoadRemoteDeck(Client *_client, QWidget *parent)
|
||||||
setMinimumWidth(sizeHint().width());
|
setMinimumWidth(sizeHint().width());
|
||||||
resize(300, 500);
|
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(okButton, SIGNAL(clicked()), this, SLOT(accept()));
|
||||||
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
|
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgLoadRemoteDeck::currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem * /*previous*/)
|
void DlgLoadRemoteDeck::currentItemChanged(const QModelIndex ¤t, const QModelIndex & /*previous*/)
|
||||||
{
|
{
|
||||||
if (!current)
|
okButton->setEnabled(dynamic_cast<RemoteDeckList_TreeModel::FileNode *>(dirView->getNode(current)));
|
||||||
okButton->setEnabled(false);
|
|
||||||
else if (current->type() == TWIDeckType)
|
|
||||||
okButton->setEnabled(true);
|
|
||||||
else
|
|
||||||
okButton->setEnabled(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int DlgLoadRemoteDeck::getDeckId() const
|
int DlgLoadRemoteDeck::getDeckId() const
|
||||||
{
|
{
|
||||||
return dirView->currentItem()->data(1, Qt::DisplayRole).toInt();
|
return dynamic_cast<RemoteDeckList_TreeModel::FileNode *>(dirView->getNode(dirView->selectionModel()->currentIndex()))->getId();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
|
||||||
class RemoteDeckList_TreeWidget;
|
class RemoteDeckList_TreeWidget;
|
||||||
class QTreeWidgetItem;
|
class QModelIndex;
|
||||||
class Client;
|
class Client;
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ private:
|
||||||
RemoteDeckList_TreeWidget *dirView;
|
RemoteDeckList_TreeWidget *dirView;
|
||||||
QPushButton *okButton, *cancelButton;
|
QPushButton *okButton, *cancelButton;
|
||||||
private slots:
|
private slots:
|
||||||
void currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
|
void currentItemChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||||
public:
|
public:
|
||||||
DlgLoadRemoteDeck(Client *_client, QWidget *parent = 0);
|
DlgLoadRemoteDeck(Client *_client, QWidget *parent = 0);
|
||||||
int getDeckId() const;
|
int getDeckId() const;
|
||||||
|
|
|
@ -6,7 +6,7 @@ GameView::GameView(QGraphicsScene *scene, QWidget *parent)
|
||||||
setBackgroundBrush(QBrush(QColor(0, 0, 0)));
|
setBackgroundBrush(QBrush(QColor(0, 0, 0)));
|
||||||
setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing/* | QPainter::SmoothPixmapTransform*/);
|
setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing/* | QPainter::SmoothPixmapTransform*/);
|
||||||
setDragMode(RubberBandDrag);
|
setDragMode(RubberBandDrag);
|
||||||
// setViewportUpdateMode(FullViewportUpdate);
|
setViewportUpdateMode(BoundingRectViewportUpdate);
|
||||||
|
|
||||||
connect(scene, SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(updateSceneRect(const QRectF &)));
|
connect(scene, SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(updateSceneRect(const QRectF &)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,61 +1,219 @@
|
||||||
#include <QFileIconProvider>
|
#include <QFileIconProvider>
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
|
#include <QSortFilterProxyModel>
|
||||||
#include "remotedecklist_treewidget.h"
|
#include "remotedecklist_treewidget.h"
|
||||||
#include "protocol_items.h"
|
#include "protocol_items.h"
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
|
|
||||||
RemoteDeckList_TreeWidget::RemoteDeckList_TreeWidget(Client *_client, QWidget *parent)
|
RemoteDeckList_TreeModel::DirectoryNode::DirectoryNode(const QString &_name, RemoteDeckList_TreeModel::DirectoryNode *_parent)
|
||||||
: QTreeWidget(parent), client(_client)
|
: 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"));
|
clearTree();
|
||||||
headerItem()->setText(1, tr("ID"));
|
|
||||||
headerItem()->setText(2, tr("Upload time"));
|
|
||||||
headerItem()->setTextAlignment(1, Qt::AlignRight);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteDeckList_TreeWidget::addFileToTree(DeckList_File *file, QTreeWidgetItem *parent)
|
void RemoteDeckList_TreeModel::DirectoryNode::clearTree()
|
||||||
{
|
{
|
||||||
QFileIconProvider fip;
|
for (int i = 0; i < size(); ++i)
|
||||||
QTreeWidgetItem *newDeck = new QTreeWidgetItem(TWIDeckType);
|
delete at(i);
|
||||||
newDeck->setIcon(0, fip.icon(QFileIconProvider::File));
|
clear();
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
if (parent) {
|
||||||
parent->addChild(newItem);
|
QString parentPath = parent->getPath();
|
||||||
|
if (parentPath.isEmpty())
|
||||||
QString path = parent->data(0, Qt::UserRole).toString();
|
return name;
|
||||||
if (path.isEmpty())
|
|
||||||
newItem->setData(0, Qt::UserRole, folder->getName());
|
|
||||||
else
|
else
|
||||||
newItem->setData(0, Qt::UserRole, path + "/" + folder->getName());
|
return parentPath + "/" + name;
|
||||||
} else {
|
} else
|
||||||
addTopLevelItem(newItem);
|
return name;
|
||||||
newItem->setData(0, Qt::UserRole, QString());
|
}
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
for (int i = 0; i < folderItems.size(); ++i) {
|
||||||
DeckList_Directory *subFolder = dynamic_cast<DeckList_Directory *>(folderItems[i]);
|
DeckList_Directory *subFolder = dynamic_cast<DeckList_Directory *>(folderItems[i]);
|
||||||
if (subFolder)
|
if (subFolder)
|
||||||
|
@ -63,23 +221,95 @@ void RemoteDeckList_TreeWidget::addFolderToTree(DeckList_Directory *folder, QTre
|
||||||
else
|
else
|
||||||
addFileToTree(dynamic_cast<DeckList_File *>(folderItems[i]), newItem);
|
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;
|
Command_DeckList *command = new Command_DeckList;
|
||||||
connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(deckListFinished(ProtocolResponse *)));
|
connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(deckListFinished(ProtocolResponse *)));
|
||||||
client->sendCommand(command);
|
client->sendCommand(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteDeckList_TreeWidget::deckListFinished(ProtocolResponse *r)
|
void RemoteDeckList_TreeModel::deckListFinished(ProtocolResponse *r)
|
||||||
{
|
{
|
||||||
Response_DeckList *resp = qobject_cast<Response_DeckList *>(r);
|
Response_DeckList *resp = qobject_cast<Response_DeckList *>(r);
|
||||||
if (!resp)
|
if (!resp)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
clear();
|
root->clearTree();
|
||||||
addFolderToTree(resp->getRoot(), 0);
|
reset();
|
||||||
expandAll();
|
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,26 +1,101 @@
|
||||||
#ifndef REMOTEDECKLIST_TREEWIDGET_H
|
#ifndef REMOTEDECKLIST_TREEWIDGET_H
|
||||||
#define REMOTEDECKLIST_TREEWIDGET_H
|
#define REMOTEDECKLIST_TREEWIDGET_H
|
||||||
|
|
||||||
#include <QTreeWidget>
|
#include <QAbstractItemModel>
|
||||||
|
#include <QDateTime>
|
||||||
|
#include <QTreeView>
|
||||||
|
|
||||||
class ProtocolResponse;
|
class ProtocolResponse;
|
||||||
class Client;
|
class Client;
|
||||||
|
class QSortFilterProxyModel;
|
||||||
class DeckList_File;
|
class DeckList_File;
|
||||||
class DeckList_Directory;
|
class DeckList_Directory;
|
||||||
|
class DeckList_TreeItem;
|
||||||
|
|
||||||
enum { TWIFolderType = QTreeWidgetItem::UserType + 1, TWIDeckType = QTreeWidgetItem::UserType + 2 };
|
class RemoteDeckList_TreeModel : public QAbstractItemModel {
|
||||||
|
|
||||||
class RemoteDeckList_TreeWidget : public QTreeWidget {
|
|
||||||
Q_OBJECT
|
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:
|
private:
|
||||||
Client *client;
|
Client *client;
|
||||||
|
DirectoryNode *root;
|
||||||
|
|
||||||
|
QModelIndex nodeToIndex(Node *node) const;
|
||||||
|
signals:
|
||||||
|
void treeRefreshed();
|
||||||
private slots:
|
private slots:
|
||||||
void deckListFinished(ProtocolResponse *r);
|
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:
|
public:
|
||||||
RemoteDeckList_TreeWidget(Client *_client, QWidget *parent = 0);
|
RemoteDeckList_TreeWidget(Client *_client, QWidget *parent = 0);
|
||||||
void retranslateUi();
|
RemoteDeckList_TreeModel::Node *getNode(const QModelIndex &ind) const;
|
||||||
void addFileToTree(DeckList_File *file, QTreeWidgetItem *parent);
|
RemoteDeckList_TreeModel::Node *getCurrentItem() const;
|
||||||
void addFolderToTree(DeckList_Directory *folder, QTreeWidgetItem *parent);
|
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();
|
void refreshTree();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
#include <QDebug>
|
|
||||||
#include "tab_deck_storage.h"
|
#include "tab_deck_storage.h"
|
||||||
#include "remotedecklist_treewidget.h"
|
#include "remotedecklist_treewidget.h"
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
|
@ -23,6 +22,8 @@ TabDeckStorage::TabDeckStorage(Client *_client)
|
||||||
localDirView->setRootIndex(sortFilter->mapFromSource(localDirModel->index(localDirModel->rootPath(), 0)));
|
localDirView->setRootIndex(sortFilter->mapFromSource(localDirModel->index(localDirModel->rootPath(), 0)));
|
||||||
localDirView->setSortingEnabled(true);
|
localDirView->setSortingEnabled(true);
|
||||||
localDirView->header()->setResizeMode(QHeaderView::ResizeToContents);
|
localDirView->header()->setResizeMode(QHeaderView::ResizeToContents);
|
||||||
|
sortFilter->sort(0, Qt::AscendingOrder);
|
||||||
|
localDirView->header()->setSortIndicator(0, Qt::AscendingOrder);
|
||||||
|
|
||||||
leftToolBar = new QToolBar;
|
leftToolBar = new QToolBar;
|
||||||
leftToolBar->setOrientation(Qt::Horizontal);
|
leftToolBar->setOrientation(Qt::Horizontal);
|
||||||
|
@ -89,8 +90,6 @@ void TabDeckStorage::retranslateUi()
|
||||||
aDownload->setText(tr("Download deck"));
|
aDownload->setText(tr("Download deck"));
|
||||||
aNewFolder->setText(tr("New folder"));
|
aNewFolder->setText(tr("New folder"));
|
||||||
aDelete->setText(tr("Delete"));
|
aDelete->setText(tr("Delete"));
|
||||||
|
|
||||||
serverDirView->retranslateUi();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabDeckStorage::actUpload()
|
void TabDeckStorage::actUpload()
|
||||||
|
@ -110,11 +109,12 @@ void TabDeckStorage::actUpload()
|
||||||
}
|
}
|
||||||
|
|
||||||
QString targetPath;
|
QString targetPath;
|
||||||
QTreeWidgetItem *curRight = serverDirView->currentItem();
|
RemoteDeckList_TreeModel::Node *curRight = serverDirView->getCurrentItem();
|
||||||
while ((curRight != 0) && (curRight->type() != TWIFolderType))
|
if (!curRight)
|
||||||
curRight = curRight->parent();
|
return;
|
||||||
if (curRight)
|
if (!dynamic_cast<RemoteDeckList_TreeModel::DirectoryNode *>(curRight))
|
||||||
targetPath = curRight->data(0, Qt::UserRole).toString();
|
curRight = curRight->getParent();
|
||||||
|
targetPath = dynamic_cast<RemoteDeckList_TreeModel::DirectoryNode *>(curRight)->getPath();
|
||||||
|
|
||||||
Command_DeckUpload *command = new Command_DeckUpload(deck, targetPath);
|
Command_DeckUpload *command = new Command_DeckUpload(deck, targetPath);
|
||||||
connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(uploadFinished(ProtocolResponse *)));
|
connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(uploadFinished(ProtocolResponse *)));
|
||||||
|
@ -128,14 +128,7 @@ void TabDeckStorage::uploadFinished(ProtocolResponse *r)
|
||||||
return;
|
return;
|
||||||
Command_DeckUpload *cmd = static_cast<Command_DeckUpload *>(sender());
|
Command_DeckUpload *cmd = static_cast<Command_DeckUpload *>(sender());
|
||||||
|
|
||||||
QTreeWidgetItemIterator it(serverDirView);
|
serverDirView->addFileToTree(resp->getFile(), serverDirView->getNodeByPath(cmd->getPath()));
|
||||||
while (*it) {
|
|
||||||
if ((*it)->data(0, Qt::UserRole) == cmd->getPath()) {
|
|
||||||
serverDirView->addFileToTree(resp->getFile(), *it);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabDeckStorage::actDownload()
|
void TabDeckStorage::actDownload()
|
||||||
|
@ -150,12 +143,12 @@ void TabDeckStorage::actDownload()
|
||||||
filePath = localDirModel->filePath(curLeft);
|
filePath = localDirModel->filePath(curLeft);
|
||||||
}
|
}
|
||||||
|
|
||||||
QTreeWidgetItem *curRight = serverDirView->currentItem();
|
RemoteDeckList_TreeModel::FileNode *curRight = dynamic_cast<RemoteDeckList_TreeModel::FileNode *>(serverDirView->getCurrentItem());
|
||||||
if ((!curRight) || (curRight->type() != TWIDeckType))
|
if (!curRight)
|
||||||
return;
|
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);
|
command->setExtraData(filePath);
|
||||||
connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(downloadFinished(ProtocolResponse *)));
|
connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(downloadFinished(ProtocolResponse *)));
|
||||||
client->sendCommand(command);
|
client->sendCommand(command);
|
||||||
|
@ -179,11 +172,13 @@ void TabDeckStorage::actNewFolder()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QString targetPath;
|
QString targetPath;
|
||||||
QTreeWidgetItem *curRight = serverDirView->currentItem();
|
RemoteDeckList_TreeModel::Node *curRight = serverDirView->getCurrentItem();
|
||||||
while ((curRight != 0) && (curRight->type() != TWIFolderType))
|
if (!curRight)
|
||||||
curRight = curRight->parent();
|
return;
|
||||||
if (curRight)
|
if (!dynamic_cast<RemoteDeckList_TreeModel::DirectoryNode *>(curRight))
|
||||||
targetPath = curRight->data(0, Qt::UserRole).toString();
|
curRight = curRight->getParent();
|
||||||
|
RemoteDeckList_TreeModel::DirectoryNode *dir = dynamic_cast<RemoteDeckList_TreeModel::DirectoryNode *>(curRight);
|
||||||
|
targetPath = dir->getPath();
|
||||||
|
|
||||||
Command_DeckNewDir *command = new Command_DeckNewDir(targetPath, folderName);
|
Command_DeckNewDir *command = new Command_DeckNewDir(targetPath, folderName);
|
||||||
connect(command, SIGNAL(finished(ResponseCode)), this, SLOT(newFolderFinished(ResponseCode)));
|
connect(command, SIGNAL(finished(ResponseCode)), this, SLOT(newFolderFinished(ResponseCode)));
|
||||||
|
@ -196,33 +191,23 @@ void TabDeckStorage::newFolderFinished(ResponseCode resp)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Command_DeckNewDir *cmd = static_cast<Command_DeckNewDir *>(sender());
|
Command_DeckNewDir *cmd = static_cast<Command_DeckNewDir *>(sender());
|
||||||
|
serverDirView->addFolderToTree(cmd->getDirName(), serverDirView->getNodeByPath(cmd->getPath()));
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabDeckStorage::actDelete()
|
void TabDeckStorage::actDelete()
|
||||||
{
|
{
|
||||||
Command *command;
|
Command *command;
|
||||||
QTreeWidgetItem *curRight = serverDirView->currentItem();
|
RemoteDeckList_TreeModel::Node *curRight = serverDirView->getCurrentItem();
|
||||||
if (curRight->type() == TWIFolderType) {
|
if (!curRight)
|
||||||
if (curRight->data(0, Qt::UserRole).toString().isEmpty())
|
return;
|
||||||
|
RemoteDeckList_TreeModel::DirectoryNode *dir = dynamic_cast<RemoteDeckList_TreeModel::DirectoryNode *>(curRight);
|
||||||
|
if (dir) {
|
||||||
|
QString path = dir->getPath();
|
||||||
|
if (path.isEmpty())
|
||||||
return;
|
return;
|
||||||
command = new Command_DeckDelDir(curRight->data(0, Qt::UserRole).toString());
|
command = new Command_DeckDelDir(path);
|
||||||
} else
|
} 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)));
|
connect(command, SIGNAL(finished(ResponseCode)), this, SLOT(deleteFinished(ResponseCode)));
|
||||||
client->sendCommand(command);
|
client->sendCommand(command);
|
||||||
}
|
}
|
||||||
|
@ -232,27 +217,13 @@ void TabDeckStorage::deleteFinished(ResponseCode resp)
|
||||||
if (resp != RespOk)
|
if (resp != RespOk)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QTreeWidgetItem *toDelete = 0;
|
RemoteDeckList_TreeModel::Node *toDelete = 0;
|
||||||
QTreeWidgetItemIterator it(serverDirView);
|
|
||||||
Command_DeckDelDir *cmdDelDir = qobject_cast<Command_DeckDelDir *>(sender());
|
Command_DeckDelDir *cmdDelDir = qobject_cast<Command_DeckDelDir *>(sender());
|
||||||
if (cmdDelDir) {
|
if (cmdDelDir)
|
||||||
while (*it) {
|
toDelete = serverDirView->getNodeByPath(cmdDelDir->getPath());
|
||||||
if ((*it)->data(0, Qt::UserRole).toString() == cmdDelDir->getPath()) {
|
else
|
||||||
toDelete = *it;
|
toDelete = serverDirView->getNodeById(static_cast<Command_DeckDel *>(sender())->getDeckId());
|
||||||
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 (toDelete)
|
if (toDelete)
|
||||||
delete toDelete;
|
serverDirView->removeNode(toDelete);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue