From 43cbc153edddb67f346b8ecf0c829a9b4961c462 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 9 Nov 2011 21:26:51 +0000 Subject: [PATCH] added dialog to select files to DL from collection files git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4667 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/RetroShare.pro | 3 + retroshare-gui/src/gui/RemoteDirModel.cpp | 2 +- retroshare-gui/src/gui/SearchDialog.cpp | 3 +- retroshare-gui/src/gui/TransfersDialog.cpp | 3 +- .../src/gui/common/RsCollectionDialog.cpp | 147 ++++++++++++++++ .../src/gui/common/RsCollectionDialog.h | 48 ++++++ .../src/gui/common/RsCollectionDialog.ui | 161 ++++++++++++++++++ .../src/gui/common/RsCollectionFile.cpp | 28 +-- .../src/gui/common/RsCollectionFile.h | 3 + 9 files changed, 370 insertions(+), 28 deletions(-) create mode 100644 retroshare-gui/src/gui/common/RsCollectionDialog.cpp create mode 100644 retroshare-gui/src/gui/common/RsCollectionDialog.h create mode 100644 retroshare-gui/src/gui/common/RsCollectionDialog.ui diff --git a/retroshare-gui/src/RetroShare.pro b/retroshare-gui/src/RetroShare.pro index 2c21a9f29..212417c8e 100644 --- a/retroshare-gui/src/RetroShare.pro +++ b/retroshare-gui/src/RetroShare.pro @@ -312,6 +312,7 @@ HEADERS += rshare.h \ gui/common/vmessagebox.h \ gui/common/RsUrlHandler.h \ gui/common/RsCollectionFile.h \ + gui/common/RsCollectionDialog.h \ gui/common/rwindow.h \ gui/common/html.h \ gui/common/AvatarDefs.h \ @@ -447,6 +448,7 @@ FORMS += gui/StartDialog.ui \ gui/common/GroupTreeWidget.ui \ gui/common/AvatarWidget.ui \ gui/common/FriendList.ui \ + gui/common/RsCollectionDialog.ui \ gui/style/StyleDialog.ui \ gui/dht/DhtWindow.ui \ gui/GetStartedDialog.ui @@ -534,6 +536,7 @@ SOURCES += main.cpp \ gui/msgs/TagsMenu.cpp \ gui/common/vmessagebox.cpp \ gui/common/RsCollectionFile.cpp \ + gui/common/RsCollectionDialog.cpp \ gui/common/RsUrlHandler.cpp \ gui/common/rwindow.cpp \ gui/common/html.cpp \ diff --git a/retroshare-gui/src/gui/RemoteDirModel.cpp b/retroshare-gui/src/gui/RemoteDirModel.cpp index 78a40f7e7..439fdc1b9 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.cpp +++ b/retroshare-gui/src/gui/RemoteDirModel.cpp @@ -303,7 +303,7 @@ QVariant RetroshareDirModel::decorationRole(const DirDetails& details,int coln) return QIcon(":/images/FileTypeDocument.png"); else if (ext == "html" || ext == "htm" || ext == "php") return QIcon(":/images/FileTypeDocument.png"); - else if (ext == "rscollection") + else if (ext == RsCollectionFile::ExtensionString) return QIcon(":/images/mimetypes/rscollection-16.png"); else return QIcon(":/images/FileTypeAny.png"); diff --git a/retroshare-gui/src/gui/SearchDialog.cpp b/retroshare-gui/src/gui/SearchDialog.cpp index 2dbacb2f0..79414f6f8 100644 --- a/retroshare-gui/src/gui/SearchDialog.cpp +++ b/retroshare-gui/src/gui/SearchDialog.cpp @@ -29,6 +29,7 @@ #include "msgs/MessageComposer.h" #include "gui/RSHumanReadableDelegate.h" #include "gui/RsAutoUpdatePage.h" +#include "gui/common/RsCollectionFile.h" #include "settings/rsharesettings.h" #include "advsearch/advancedsearchdialog.h" @@ -1282,7 +1283,7 @@ void SearchDialog::setIconAndType(QTreeWidgetItem *item, QString ext) item->setIcon(SR_NAME_COL, QIcon(":/images/FileTypeDocument.png")); item->setText(SR_TYPE_COL, QString::fromUtf8("Document")); } - else if (ext == "rscollection") + else if (ext == RsCollectionFile::ExtensionString) { item->setIcon(SR_NAME_COL, QIcon(":/images/library.png")); item->setText(SR_TYPE_COL, QString::fromUtf8("RetroShare collection file")); diff --git a/retroshare-gui/src/gui/TransfersDialog.cpp b/retroshare-gui/src/gui/TransfersDialog.cpp index 3cea09618..b6aaacdb1 100644 --- a/retroshare-gui/src/gui/TransfersDialog.cpp +++ b/retroshare-gui/src/gui/TransfersDialog.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include @@ -655,7 +656,7 @@ QIcon TransfersDialog::getIconFromExtension(QString ext) return QIcon(QString::fromUtf8(":/images/FileTypeDocument.png")) ; else if (ext == "html" || ext == "htm" || ext == "php") return QIcon(QString::fromUtf8(":/images/FileTypeDocument.png")) ; - else if (ext == "rscollection") + else if (ext == RsCollectionFile::ExtensionString) return QIcon(QString::fromUtf8(":/images/mimetypes/rscollection-16.png")) ; else return QIcon(QString::fromUtf8(":/images/FileTypeAny.png")) ; diff --git a/retroshare-gui/src/gui/common/RsCollectionDialog.cpp b/retroshare-gui/src/gui/common/RsCollectionDialog.cpp new file mode 100644 index 000000000..a37add0e8 --- /dev/null +++ b/retroshare-gui/src/gui/common/RsCollectionDialog.cpp @@ -0,0 +1,147 @@ +/**************************************************************** + * RetroShare is distributed under the following license: + * + * Copyright (C) 2011 - 2011 RetroShare Team + * + * Cyril Soler (csoler@users.sourceforge.net) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + ****************************************************************/ + +#include +#include +#include +#include "RsCollectionDialog.h" +#include "RsCollectionFile.h" + +RsCollectionDialog::RsCollectionDialog(const QString& CollectionFileName,const std::vector& dlinfos) + : _dlinfos(dlinfos),_filename(CollectionFileName) +{ + setupUi(this) ; + + setWindowTitle(CollectionFileName) ; + // 1 - add all elements to the list. + + int row = 0; + _fileEntriesTW->setColumnCount(4) ; + + _fileEntriesTW->setHorizontalHeaderItem(0,new QTableWidgetItem(QString())) ; + _fileEntriesTW->setHorizontalHeaderItem(1,new QTableWidgetItem(tr("File"))) ; + _fileEntriesTW->setHorizontalHeaderItem(2,new QTableWidgetItem(tr("Size"))) ; + _fileEntriesTW->setHorizontalHeaderItem(3,new QTableWidgetItem(tr("Hash"))) ; + + _cboxes.clear() ; + _cboxes.resize(dlinfos.size(),NULL) ; + uint64_t total_size ; + uint32_t total_files ; + + for(uint32_t i=0;iinsertRow(row) ; + + QCheckBox *cb = new QCheckBox ; + cb->setChecked(true) ; + + connect(cb,SIGNAL(toggled(bool)),this,SLOT(updateSizes())) ; + + _cboxes[i] = cb ; + + _fileEntriesTW->setCellWidget(row,0,cb) ; + _fileEntriesTW->setItem(row,1,new QTableWidgetItem(dlinfos[i].path + "/" + dlinfos[i].name)) ; + _fileEntriesTW->setItem(row,2,new QTableWidgetItem(QString::number(dlinfos[i].size))) ; + _fileEntriesTW->setItem(row,3,new QTableWidgetItem(dlinfos[i].hash)) ; + + total_size += dlinfos[i].size ; + total_files++ ; + + ++row ; + } + + _filename_TL->setText(_filename) ; + _fileEntriesTW->resizeColumnsToContents() ; + + updateSizes() ; + + // 2 - connect necessary signals/slots + + connect(_selectAll_PB,SIGNAL(clicked()),this,SLOT(selectAll())) ; + connect(_deselectAll_PB,SIGNAL(clicked()),this,SLOT(deselectAll())) ; + connect(_cancel_PB,SIGNAL(clicked()),this,SLOT(cancel())) ; + connect(_download_PB,SIGNAL(clicked()),this,SLOT(download())) ; +} + +void RsCollectionDialog::updateSizes() +{ + uint64_t total_size = 0 ; + uint32_t total_files = 0 ; + + for(int i=0;i<_dlinfos.size();++i) + if(_cboxes[i]->isChecked()) + { + total_size += _dlinfos[i].size ; + ++total_files ; + } + _selectedFiles_TL->setText(QString::number(total_files)) ; + _totalSize_TL->setText(QString::number(total_size)) ; +} + +void RsCollectionDialog::selectAll() const +{ + std::cerr << "Selecting all !" << std::endl; + for(int i=0;i<_dlinfos.size();++i) + dynamic_cast(_fileEntriesTW->cellWidget(i,0))->setChecked(true) ; +} + +void RsCollectionDialog::deselectAll() const +{ + std::cerr << "Deselecting all !" << std::endl; + for(int i=0;i<_dlinfos.size();++i) + dynamic_cast(_fileEntriesTW->cellWidget(i,0))->setChecked(false) ; +} + +void RsCollectionDialog::cancel() +{ + std::cerr << "Canceling!" << std::endl; + close() ; +} + +void RsCollectionDialog::download() +{ + std::cerr << "Downloading!" << std::endl; + + QString dldir = QString::fromUtf8(rsFiles->getDownloadDirectory().c_str()) ; + + std::cerr << "downloading all these files:" << std::endl; + + for(uint32_t i=0;i<_dlinfos.size();++i) + if(_cboxes[i]->isChecked()) + { + std::cerr << _dlinfos[i].name.toStdString() << " " << _dlinfos[i].hash.toStdString() << " " << _dlinfos[i].size << " " << _dlinfos[i].path.toStdString() << std::endl; + QString cleanPath = dldir + _dlinfos[i].path ; + std::cerr << "making directory " << cleanPath.toStdString() << std::endl; + + if(!QDir(cleanPath).mkpath(cleanPath)) + QMessageBox::warning(NULL,QObject::tr("Unable to make path"),QObject::tr("Unable to make path:")+"
"+cleanPath) ; + + rsFiles->FileRequest(_dlinfos[i].name.toUtf8().constData(), _dlinfos[i].hash.toUtf8().constData(), _dlinfos[i].size, cleanPath.toUtf8().constData(), RS_FILE_HINTS_NETWORK_WIDE, std::list()); + } + else + std::cerr<<"Skipping file : " << _dlinfos[i].name.toStdString() << std::endl; + + close(); +} + + diff --git a/retroshare-gui/src/gui/common/RsCollectionDialog.h b/retroshare-gui/src/gui/common/RsCollectionDialog.h new file mode 100644 index 000000000..12304c4da --- /dev/null +++ b/retroshare-gui/src/gui/common/RsCollectionDialog.h @@ -0,0 +1,48 @@ +/*************************************:*************************** + * RetroShare is distributed under the following license: + * + * Copyright (C) 2011 - 2011 RetroShare Team + * + * Cyril Soler (csoler@users.sourceforge.net) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + ****************************************************************/ + +#include "ui_RsCollectionDialog.h" +#include "RsCollectionFile.h" + +class QCheckBox ; + +class RsCollectionDialog: public QDialog, public Ui::rsCollectionDialog +{ + Q_OBJECT + + public: + RsCollectionDialog(const QString& filename,const std::vector& dlinfos) ; + + public slots: + void download() ; + void selectAll() const ; + void deselectAll() const ; + void cancel() ; + void updateSizes() ; + + private: + const std::vector& _dlinfos ; + std::vector _cboxes ; + QString _filename ; +}; + diff --git a/retroshare-gui/src/gui/common/RsCollectionDialog.ui b/retroshare-gui/src/gui/common/RsCollectionDialog.ui new file mode 100644 index 000000000..460638abf --- /dev/null +++ b/retroshare-gui/src/gui/common/RsCollectionDialog.ui @@ -0,0 +1,161 @@ + + + rsCollectionDialog + + + + 0 + 0 + 434 + 310 + + + + Dialog + + + + + + + + + + File name : + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Total size : + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Selected files: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + TextLabel + + + + + + + TextLabel + + + + + + + TextLabel + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::DotLine + + + true + + + true + + + false + + + false + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Select all + + + + + + + Deselect all + + + + + + + Cancel + + + + + + + Download! + + + + + + + + + + diff --git a/retroshare-gui/src/gui/common/RsCollectionFile.cpp b/retroshare-gui/src/gui/common/RsCollectionFile.cpp index ff5a6aef2..b2b95c730 100644 --- a/retroshare-gui/src/gui/common/RsCollectionFile.cpp +++ b/retroshare-gui/src/gui/common/RsCollectionFile.cpp @@ -25,6 +25,7 @@ #include #include "RsCollectionFile.h" +#include "RsCollectionDialog.h" #include #include @@ -37,7 +38,7 @@ const QString RsCollectionFile::ExtensionString = QString("rscollection") ; RsCollectionFile::RsCollectionFile(const QString& filename) - : _xml_doc("RsCollection") + : _xml_doc("RsCollection"),_filename(filename) { QFile file(filename); @@ -54,7 +55,6 @@ RsCollectionFile::RsCollectionFile(const QString& filename) throw std::runtime_error("Error parsing xml file") ; } - void RsCollectionFile::downloadFiles() const { // print out the element names of all elements that are direct children @@ -64,29 +64,7 @@ void RsCollectionFile::downloadFiles() const std::vector dlinfos ; recursCollectDLinfos(docElem,dlinfos,QString()) ; - QString msg(QObject::tr("About to download the following files:")+"

") ; - - for(uint32_t i=0;i" ; - - QString dldir = QString::fromUtf8(rsFiles->getDownloadDirectory().c_str()) ; - - if(QMessageBox::Ok == QMessageBox::critical(NULL,QObject::tr("About to download these files"),msg) ) - { - std::cerr << "downloading all these files:" << std::endl; - - for(uint32_t i=0;i "+cleanPath) ; - - rsFiles->FileRequest(dlinfos[i].name.toUtf8().constData(), dlinfos[i].hash.toUtf8().constData(), dlinfos[i].size, cleanPath.toUtf8().constData(), RS_FILE_HINTS_NETWORK_WIDE, std::list()); - } - } + RsCollectionDialog(_filename, dlinfos).exec() ; } void RsCollectionFile::recursCollectDLinfos(const QDomElement& e,std::vector& dlinfos,const QString& current_path) const diff --git a/retroshare-gui/src/gui/common/RsCollectionFile.h b/retroshare-gui/src/gui/common/RsCollectionFile.h index 16843f70f..2923ef6f6 100644 --- a/retroshare-gui/src/gui/common/RsCollectionFile.h +++ b/retroshare-gui/src/gui/common/RsCollectionFile.h @@ -65,5 +65,8 @@ class RsCollectionFile void recursCollectDLinfos(const QDomElement&,std::vector& dlinfos,const QString& current_dir) const ; QDomDocument _xml_doc ; + QString _filename ; + + friend class RsCollectionDialog ; };