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
This commit is contained in:
csoler 2011-11-09 21:26:51 +00:00
parent 072c6c7e12
commit 43cbc153ed
9 changed files with 370 additions and 28 deletions

View File

@ -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 \

View File

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

View File

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

View File

@ -30,6 +30,7 @@
#include <QFileInfo>
#include <QMessageBox>
#include <gui/common/RsUrlHandler.h>
#include <gui/common/RsCollectionFile.h>
#include <algorithm>
@ -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")) ;

View File

@ -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 <QCheckBox>
#include <QMessageBox>
#include <QDir>
#include "RsCollectionDialog.h"
#include "RsCollectionFile.h"
RsCollectionDialog::RsCollectionDialog(const QString& CollectionFileName,const std::vector<RsCollectionFile::DLinfo>& 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;i<dlinfos.size();++i)
{
_fileEntriesTW->insertRow(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<QCheckBox*>(_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<QCheckBox*>(_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:")+"<br> "+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<std::string>());
}
else
std::cerr<<"Skipping file : " << _dlinfos[i].name.toStdString() << std::endl;
close();
}

View File

@ -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<RsCollectionFile::DLinfo>& dlinfos) ;
public slots:
void download() ;
void selectAll() const ;
void deselectAll() const ;
void cancel() ;
void updateSizes() ;
private:
const std::vector<RsCollectionFile::DLinfo>& _dlinfos ;
std::vector<QCheckBox*> _cboxes ;
QString _filename ;
};

View File

@ -0,0 +1,161 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>rsCollectionDialog</class>
<widget class="QDialog" name="rsCollectionDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>434</width>
<height>310</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>File name :</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Total size :</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Selected files:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="_filename_TL">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="_totalSize_TL">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="_selectedFiles_TL">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QTableWidget" name="_fileEntriesTW">
<property name="gridStyle">
<enum>Qt::DotLine</enum>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderStretchLastSection">
<bool>false</bool>
</attribute>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="_selectAll_PB">
<property name="text">
<string>Select all</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="_deselectAll_PB">
<property name="text">
<string>Deselect all</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="_cancel_PB">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="_download_PB">
<property name="text">
<string>Download!</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -25,6 +25,7 @@
#include <retroshare/rsfiles.h>
#include "RsCollectionFile.h"
#include "RsCollectionDialog.h"
#include <QFile>
#include <QDir>
@ -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<DLinfo> dlinfos ;
recursCollectDLinfos(docElem,dlinfos,QString()) ;
QString msg(QObject::tr("About to download the following files:")+"<br><br>") ;
for(uint32_t i=0;i<dlinfos.size();++i)
msg += " "+dlinfos[i].path + "/" + dlinfos[i].name + "<br>" ;
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<dlinfos.size();++i)
{
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:")+"<br> "+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<std::string>());
}
}
RsCollectionDialog(_filename, dlinfos).exec() ;
}
void RsCollectionFile::recursCollectDLinfos(const QDomElement& e,std::vector<DLinfo>& dlinfos,const QString& current_path) const

View File

@ -65,5 +65,8 @@ class RsCollectionFile
void recursCollectDLinfos(const QDomElement&,std::vector<DLinfo>& dlinfos,const QString& current_dir) const ;
QDomDocument _xml_doc ;
QString _filename ;
friend class RsCollectionDialog ;
};