mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-23 08:11:24 -04:00
Added new button "Open Collection" in TransfersDialog.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4691 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
031629d528
commit
bab7ebaa5b
10 changed files with 993 additions and 905 deletions
|
@ -26,33 +26,22 @@
|
|||
|
||||
#include "RsCollectionFile.h"
|
||||
#include "RsCollectionDialog.h"
|
||||
#include "util/misc.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QObject>
|
||||
#include <QMessageBox>
|
||||
#include <QTextStream>
|
||||
#include <QDomElement>
|
||||
#include <QDomDocument>
|
||||
#include <QMessageBox>
|
||||
#include <QIcon>
|
||||
|
||||
const QString RsCollectionFile::ExtensionString = QString("rscollection") ;
|
||||
|
||||
RsCollectionFile::RsCollectionFile(const QString& filename)
|
||||
: _xml_doc("RsCollection"),_filename(filename)
|
||||
RsCollectionFile::RsCollectionFile()
|
||||
: _xml_doc("RsCollection")
|
||||
{
|
||||
QFile file(filename);
|
||||
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
std::cerr << "Cannot open file " << filename.toStdString() << " !!" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
bool ok = _xml_doc.setContent(&file) ;
|
||||
file.close();
|
||||
|
||||
if(!ok)
|
||||
throw std::runtime_error("Error parsing xml file") ;
|
||||
}
|
||||
|
||||
void RsCollectionFile::downloadFiles() const
|
||||
|
@ -143,14 +132,55 @@ RsCollectionFile::RsCollectionFile(const std::vector<DirDetails>& file_infos)
|
|||
recursAddElements(_xml_doc,file_infos[i],root) ;
|
||||
}
|
||||
|
||||
void RsCollectionFile::save(const QString& filename) const
|
||||
static void showError(const QString& filename, const QString& error)
|
||||
{
|
||||
QMessageBox mb(QMessageBox::Warning, QObject::tr("Treatment of collection file has failed"), QObject::tr("The collection file %1 could not be openned.\nReported error is: %2").arg(filename).arg(error), QMessageBox::Ok);
|
||||
mb.setWindowIcon(QIcon(":/images/rstray3.png"));
|
||||
mb.exec();
|
||||
}
|
||||
|
||||
bool RsCollectionFile::load(const QString& filename)
|
||||
{
|
||||
QFile file(filename);
|
||||
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
std::cerr << "Cannot open file " << filename.toStdString() << " !!" << std::endl;
|
||||
showError(filename, QApplication::translate("RsCollectionFile", "Cannot open file %1").arg(filename));
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ok = _xml_doc.setContent(&file) ;
|
||||
file.close();
|
||||
|
||||
if (ok) {
|
||||
_filename = filename;
|
||||
} else {
|
||||
showError(filename, QApplication::translate("RsCollectionFile", "Error parsing xml file"));
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool RsCollectionFile::load()
|
||||
{
|
||||
QString filename;
|
||||
if (!misc::getOpenFileName(NULL, RshareSettings::LASTDIR_EXTRAFILE, QApplication::translate("RsCollectionFile", "Open collection file"), QApplication::translate("RsCollectionFile", "Collection files") + " (*." + RsCollectionFile::ExtensionString + ")", filename))
|
||||
return false;
|
||||
|
||||
std::cerr << "Got file name: " << filename.toStdString() << std::endl;
|
||||
|
||||
return load(filename);
|
||||
}
|
||||
|
||||
bool RsCollectionFile::save(const QString& filename) const
|
||||
{
|
||||
QFile file(filename);
|
||||
|
||||
if (!file.open(QIODevice::WriteOnly))
|
||||
{
|
||||
std::cerr << "Cannot write to file " << filename.toStdString() << " !!" << std::endl;
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
QTextStream stream(&file) ;
|
||||
|
@ -158,5 +188,20 @@ void RsCollectionFile::save(const QString& filename) const
|
|||
stream << _xml_doc.toString() ;
|
||||
|
||||
file.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RsCollectionFile::save() const
|
||||
{
|
||||
QString filename;
|
||||
if(!misc::getSaveFileName(NULL, RshareSettings::LASTDIR_EXTRAFILE, QApplication::translate("RsCollectionFile", "Create collection file"), QApplication::translate("RsCollectionFile", "Collection files") + " (*." + RsCollectionFile::ExtensionString + ")", filename))
|
||||
return false;
|
||||
|
||||
if (!filename.endsWith("." + RsCollectionFile::ExtensionString))
|
||||
filename += "." + RsCollectionFile::ExtensionString ;
|
||||
|
||||
std::cerr << "Got file name: " << filename.toStdString() << std::endl;
|
||||
|
||||
return save(filename);
|
||||
}
|
||||
|
|
|
@ -40,14 +40,18 @@ class RsCollectionFile
|
|||
public:
|
||||
static const QString ExtensionString ;
|
||||
|
||||
// Loads file from disk.
|
||||
RsCollectionFile(const QString& filename) ;
|
||||
RsCollectionFile() ;
|
||||
|
||||
// create from list of files and directories
|
||||
RsCollectionFile(const std::vector<DirDetails>& file_entries) ;
|
||||
|
||||
// Loads file from disk.
|
||||
bool load();
|
||||
bool load(const QString& filename);
|
||||
|
||||
// Save to disk
|
||||
void save(const QString& filename) const ;
|
||||
bool save() const ;
|
||||
bool save(const QString& filename) const ;
|
||||
|
||||
// Download the content.
|
||||
void downloadFiles() const ;
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
|
||||
#include <stdexcept>
|
||||
#include <QDesktopServices>
|
||||
#include <QMessageBox>
|
||||
#include <QUrl>
|
||||
#include "RsCollectionFile.h"
|
||||
#include "RsUrlHandler.h"
|
||||
|
@ -30,14 +29,9 @@ bool RsUrlHandler::openUrl(const QUrl& url)
|
|||
{
|
||||
if(url.scheme() == QString("file") && url.toLocalFile().endsWith("."+RsCollectionFile::ExtensionString))
|
||||
{
|
||||
try
|
||||
{
|
||||
RsCollectionFile(url.toLocalFile().toUtf8().constData()).downloadFiles() ;
|
||||
}
|
||||
catch(std::runtime_error& e)
|
||||
{
|
||||
QMessageBox::warning(NULL,QObject::tr("Treatment of collection file has failed."),QObject::tr("The collection file ") + url.toLocalFile() + QObject::tr(" could not be openned. Reported error is: ") + QString::fromStdString(e.what())) ;
|
||||
return false ;
|
||||
RsCollectionFile Collection;
|
||||
if (Collection.load(url.toLocalFile().toUtf8().constData())) {
|
||||
Collection.downloadFiles() ;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue