mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-25 07:29:33 -05:00
started adapting RsCollectionDialog to the new API of RsCollection
This commit is contained in:
parent
206da93d99
commit
5071656209
@ -30,7 +30,7 @@
|
||||
#include "gui/RetroShareLink.h"
|
||||
#include "retroshare-gui/RsAutoUpdatePage.h"
|
||||
#include "gui/msgs/MessageComposer.h"
|
||||
#include "gui/common/RsCollection.h"
|
||||
#include "gui/common/RsCollectionDialog.h"
|
||||
#include "gui/common/FilesDefs.h"
|
||||
#include "gui/common/RsUrlHandler.h"
|
||||
#include "gui/settings/rsharesettings.h"
|
||||
@ -542,12 +542,8 @@ void SearchDialog::collModif()
|
||||
/* open file with a suitable application */
|
||||
QFileInfo qinfo;
|
||||
qinfo.setFile(QString::fromUtf8(path.c_str()));
|
||||
if (qinfo.exists()) {
|
||||
if (qinfo.absoluteFilePath().endsWith(RsCollection::ExtensionString)) {
|
||||
RsCollection collection;
|
||||
collection.openColl(qinfo.absoluteFilePath());
|
||||
}//if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString))
|
||||
}//if (qinfo.exists())
|
||||
if (qinfo.exists() && qinfo.absoluteFilePath().endsWith(RsCollection::ExtensionString))
|
||||
RsCollectionDialog::openExistingCollection(qinfo.absoluteFilePath());
|
||||
}
|
||||
|
||||
void SearchDialog::collView()
|
||||
@ -574,12 +570,8 @@ void SearchDialog::collView()
|
||||
/* open file with a suitable application */
|
||||
QFileInfo qinfo;
|
||||
qinfo.setFile(QString::fromUtf8(path.c_str()));
|
||||
if (qinfo.exists()) {
|
||||
if (qinfo.absoluteFilePath().endsWith(RsCollection::ExtensionString)) {
|
||||
RsCollection collection;
|
||||
collection.openColl(qinfo.absoluteFilePath(), true);
|
||||
}//if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString))
|
||||
}//if (qinfo.exists())
|
||||
if (qinfo.exists() && qinfo.absoluteFilePath().endsWith(RsCollection::ExtensionString))
|
||||
RsCollectionDialog::openExistingCollection(qinfo.absoluteFilePath(), true);
|
||||
}
|
||||
|
||||
void SearchDialog::collOpen()
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include "gui/RetroShareLink.h"
|
||||
#include "gui/ShareManager.h"
|
||||
#include "gui/common/PeerDefs.h"
|
||||
#include "gui/common/RsCollection.h"
|
||||
#include "gui/common/RsCollectionDialog.h"
|
||||
#include "gui/msgs/MessageComposer.h"
|
||||
#include "gui/gxschannels/GxsChannelDialog.h"
|
||||
#include "gui/gxsforums/GxsForumsDialog.h"
|
||||
@ -759,12 +759,8 @@ void SharedFilesDialog::collModif()
|
||||
/* open file with a suitable application */
|
||||
QFileInfo qinfo;
|
||||
qinfo.setFile(QString::fromUtf8(path.c_str()));
|
||||
if (qinfo.exists()) {
|
||||
if (qinfo.absoluteFilePath().endsWith(RsCollection::ExtensionString)) {
|
||||
RsCollection collection;
|
||||
collection.openColl(qinfo.absoluteFilePath());
|
||||
}
|
||||
}
|
||||
if (qinfo.exists() && qinfo.absoluteFilePath().endsWith(RsCollection::ExtensionString))
|
||||
RsCollectionDialog::openExistingCollection(qinfo.absoluteFilePath());
|
||||
}
|
||||
|
||||
void SharedFilesDialog::collView()
|
||||
@ -789,12 +785,8 @@ void SharedFilesDialog::collView()
|
||||
/* open file with a suitable application */
|
||||
QFileInfo qinfo;
|
||||
qinfo.setFile(QString::fromUtf8(path.c_str()));
|
||||
if (qinfo.exists()) {
|
||||
if (qinfo.absoluteFilePath().endsWith(RsCollection::ExtensionString)) {
|
||||
RsCollection collection;
|
||||
collection.openColl(qinfo.absoluteFilePath(), true);
|
||||
}
|
||||
}
|
||||
if (qinfo.exists() && qinfo.absoluteFilePath().endsWith(RsCollection::ExtensionString))
|
||||
RsCollectionDialog::openExistingCollection(qinfo.absoluteFilePath(), true);
|
||||
}
|
||||
|
||||
void SharedFilesDialog::collOpen()
|
||||
|
@ -24,7 +24,7 @@
|
||||
#include "gui/SoundManager.h"
|
||||
#include "gui/RetroShareLink.h"
|
||||
#include "gui/common/FilesDefs.h"
|
||||
#include "gui/common/RsCollection.h"
|
||||
#include "gui/common/RsCollectionDialog.h"
|
||||
#include "gui/common/RSTreeView.h"
|
||||
#include "gui/common/RsUrlHandler.h"
|
||||
#include "gui/FileTransfer/DetailsDialog.h"
|
||||
@ -2466,21 +2466,17 @@ void TransfersDialog::collCreate()
|
||||
std::set<RsFileHash>::iterator it ;
|
||||
getDLSelectedItems(&items, NULL);
|
||||
|
||||
RsFileTree tree;
|
||||
|
||||
for (it = items.begin(); it != items.end(); ++it)
|
||||
{
|
||||
FileInfo info;
|
||||
if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_DOWNLOAD, info)) continue;
|
||||
|
||||
DirDetails details;
|
||||
details.name = info.fname;
|
||||
details.hash = info.hash;
|
||||
details.size = info.size;
|
||||
details.type = DIR_TYPE_FILE;
|
||||
|
||||
dirVec.push_back(details);
|
||||
tree.addFile(tree.root(),info.fname,info.hash,info.size);
|
||||
}
|
||||
|
||||
RsCollection(dirVec,RS_FILE_HINTS_LOCAL).openNewColl(this);
|
||||
RsCollectionDialog::openNewCollection(tree);
|
||||
}
|
||||
|
||||
void TransfersDialog::collModif()
|
||||
@ -2504,12 +2500,8 @@ void TransfersDialog::collModif()
|
||||
/* open collection */
|
||||
QFileInfo qinfo;
|
||||
qinfo.setFile(QString::fromUtf8(path.c_str()));
|
||||
if (qinfo.exists()) {
|
||||
if (qinfo.absoluteFilePath().endsWith(RsCollection::ExtensionString)) {
|
||||
RsCollection collection;
|
||||
collection.openColl(qinfo.absoluteFilePath());
|
||||
}
|
||||
}
|
||||
if (qinfo.exists() && qinfo.absoluteFilePath().endsWith(RsCollection::ExtensionString))
|
||||
RsCollectionDialog::openExistingCollection(qinfo.absoluteFilePath());
|
||||
}
|
||||
}
|
||||
|
||||
@ -2534,12 +2526,8 @@ void TransfersDialog::collView()
|
||||
/* open collection */
|
||||
QFileInfo qinfo;
|
||||
qinfo.setFile(QString::fromUtf8(path.c_str()));
|
||||
if (qinfo.exists()) {
|
||||
if (qinfo.absoluteFilePath().endsWith(RsCollection::ExtensionString)) {
|
||||
RsCollection collection;
|
||||
collection.openColl(qinfo.absoluteFilePath(), true);
|
||||
}
|
||||
}
|
||||
if (qinfo.exists() && qinfo.absoluteFilePath().endsWith(RsCollection::ExtensionString))
|
||||
RsCollectionDialog::openExistingCollection(qinfo.absoluteFilePath(), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -119,7 +119,7 @@
|
||||
#include "gui/statistics/StatisticsWindow.h"
|
||||
|
||||
#include "gui/connect/ConnectFriendWizard.h"
|
||||
#include "gui/common/RsCollection.h"
|
||||
#include "gui/common/RsCollectionDialog.h"
|
||||
#include "settings/rsettingswin.h"
|
||||
#include "settings/rsharesettings.h"
|
||||
#include "common/StatusDefs.h"
|
||||
@ -1623,12 +1623,8 @@ void MainWindow::retroshareLinkActivated(const QUrl &url)
|
||||
void MainWindow::openRsCollection(const QString &filename)
|
||||
{
|
||||
QFileInfo qinfo(filename);
|
||||
if (qinfo.exists()) {
|
||||
if (qinfo.absoluteFilePath().endsWith(RsCollection::ExtensionString)) {
|
||||
RsCollection collection;
|
||||
collection.openColl(qinfo.absoluteFilePath());
|
||||
}
|
||||
}
|
||||
if (qinfo.exists() && qinfo.absoluteFilePath().endsWith(RsCollection::ExtensionString))
|
||||
RsCollectionDialog::openExistingCollection(qinfo.absoluteFilePath());
|
||||
}
|
||||
|
||||
void MainWindow::processLastArgs()
|
||||
|
@ -615,89 +615,7 @@ bool RsCollection::save(QWidget *parent) const
|
||||
}
|
||||
|
||||
|
||||
bool RsCollection::openNewColl(QWidget *parent, QString fileName)
|
||||
{
|
||||
if(!misc::getSaveFileName(parent, RshareSettings::LASTDIR_EXTRAFILE
|
||||
, QApplication::translate("RsCollectionFile", "Create collection file")
|
||||
, QApplication::translate("RsCollectionFile", "Collection files") + " (*." + RsCollection::ExtensionString + ")"
|
||||
, fileName,0, QFileDialog::DontConfirmOverwrite))
|
||||
return false;
|
||||
|
||||
if (!fileName.endsWith("." + RsCollection::ExtensionString))
|
||||
fileName += "." + RsCollection::ExtensionString ;
|
||||
|
||||
std::cerr << "Got file name: " << fileName.toStdString() << std::endl;
|
||||
|
||||
QFile file(fileName) ;
|
||||
|
||||
if(file.exists())
|
||||
{
|
||||
if (!checkFile(fileName,true)) return false;
|
||||
|
||||
QMessageBox mb;
|
||||
mb.setText(tr("Save Collection File."));
|
||||
mb.setInformativeText(tr("File already exists.")+"\n"+tr("What do you want to do?"));
|
||||
QAbstractButton *btnOwerWrite = mb.addButton(tr("Overwrite"), QMessageBox::YesRole);
|
||||
QAbstractButton *btnMerge = mb.addButton(tr("Merge"), QMessageBox::NoRole);
|
||||
QAbstractButton *btnCancel = mb.addButton(tr("Cancel"), QMessageBox::ResetRole);
|
||||
mb.setIcon(QMessageBox::Question);
|
||||
mb.exec();
|
||||
|
||||
if (mb.clickedButton()==btnOwerWrite) {
|
||||
//Nothing to do _xml_doc already up to date
|
||||
} else if (mb.clickedButton()==btnMerge) {
|
||||
//Open old file to merge it with _xml_doc
|
||||
QDomDocument qddOldFile("RsCollection");
|
||||
if (qddOldFile.setContent(&file)) {
|
||||
QDomElement docOldElem = qddOldFile.elementsByTagName("RsCollection").at(0).toElement();
|
||||
std::vector<ColFileInfo> colOldFileInfos;
|
||||
recursCollectColFileInfos(docOldElem,colOldFileInfos,QString(),false);
|
||||
|
||||
QDomElement root = _xml_doc.elementsByTagName("RsCollection").at(0).toElement();
|
||||
for(uint32_t i = 0;i<colOldFileInfos.size();++i){
|
||||
recursAddElements(_xml_doc,colOldFileInfos[i],root) ;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (mb.clickedButton()==btnCancel) {
|
||||
return false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}//if(file.exists())
|
||||
|
||||
_fileName=fileName;
|
||||
std::vector<ColFileInfo> colFileInfos ;
|
||||
|
||||
recursCollectColFileInfos(_xml_doc.documentElement(),colFileInfos,QString(),false) ;
|
||||
|
||||
RsCollectionDialog* rcd = new RsCollectionDialog(fileName, colFileInfos,true);
|
||||
connect(rcd,SIGNAL(saveColl(std::vector<ColFileInfo>, QString)),this,SLOT(saveColl(std::vector<ColFileInfo>, QString))) ;
|
||||
_saved=false;
|
||||
rcd->exec() ;
|
||||
delete rcd;
|
||||
|
||||
return _saved;
|
||||
}
|
||||
|
||||
bool RsCollection::openColl(const QString& fileName, bool readOnly /* = false */, bool showError /* = true*/)
|
||||
{
|
||||
if (load(fileName, showError)) {
|
||||
std::vector<ColFileInfo> colFileInfos ;
|
||||
|
||||
recursCollectColFileInfos(_xml_doc.documentElement(),colFileInfos,QString(),false) ;
|
||||
|
||||
RsCollectionDialog* rcd = new RsCollectionDialog(fileName, colFileInfos, true, readOnly);
|
||||
connect(rcd,SIGNAL(saveColl(std::vector<ColFileInfo>, QString)),this,SLOT(saveColl(std::vector<ColFileInfo>, QString))) ;
|
||||
_saved=false;
|
||||
rcd->exec() ;
|
||||
delete rcd;
|
||||
|
||||
return _saved;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
qulonglong RsCollection::size()
|
||||
|
@ -89,10 +89,8 @@ public:
|
||||
// Save to disk
|
||||
bool save(const QString& fileName) const ;
|
||||
|
||||
// Open new collection
|
||||
bool openNewColl(QWidget *parent, QString fileName = "");
|
||||
// Open existing collection
|
||||
bool openColl(const QString& fileName, bool readOnly = false, bool showError = true);
|
||||
// returns the file tree
|
||||
const RsFileTree& fileTree() const { return mFileTree; }
|
||||
|
||||
// Download the content.
|
||||
void downloadFiles() const ;
|
||||
|
@ -693,12 +693,10 @@ void RsCollectionDialog::changeFileName()
|
||||
std::cerr << "Got file name: " << fileName.toStdString() << std::endl;
|
||||
|
||||
QFile file(fileName) ;
|
||||
RsCollection::RsCollectionErrorCode err;
|
||||
|
||||
if(file.exists())
|
||||
if(file.exists() && RsCollection::checkFile(fileName,err))
|
||||
{
|
||||
RsCollection collFile;
|
||||
if (!collFile.checkFile(fileName,true)) return;
|
||||
|
||||
QMessageBox mb;
|
||||
mb.setText(tr("Save Collection File."));
|
||||
mb.setInformativeText(tr("File already exists.")+"\n"+tr("What do you want to do?"));
|
||||
@ -710,19 +708,20 @@ void RsCollectionDialog::changeFileName()
|
||||
|
||||
if (mb.clickedButton()==btnOwerWrite) {
|
||||
//Nothing to do
|
||||
} else if (mb.clickedButton()==btnMerge) {
|
||||
}
|
||||
else if(mb.clickedButton()==btnMerge)
|
||||
{
|
||||
//Open old file to merge it with RsCollection
|
||||
QDomDocument qddOldFile("RsCollection");
|
||||
if (qddOldFile.setContent(&file)) {
|
||||
QDomElement docOldElem = qddOldFile.elementsByTagName("RsCollection").at(0).toElement();
|
||||
collFile.recursCollectColFileInfos(docOldElem,_newColFileInfos,QString(),false);
|
||||
}
|
||||
|
||||
} else if (mb.clickedButton()==btnCancel) {
|
||||
return;
|
||||
} else {
|
||||
return;
|
||||
RsCollection qddOldFileCollection(fileName,err);
|
||||
|
||||
if(err != RsCollection::RsCollectionErrorCode::NO_ERROR)
|
||||
_collection.merge_in(qddOldFileCollection.fileTree());
|
||||
}
|
||||
else if(mb.clickedButton()==btnCancel)
|
||||
return;
|
||||
else
|
||||
return;
|
||||
|
||||
} else {//if(file.exists())
|
||||
//create a new empty file to check if name if good.
|
||||
@ -1444,3 +1443,98 @@ void RsCollectionDialog::saveChild(QTreeWidgetItem *parentItem, ColFileInfo *par
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool RsCollectionDialog::openExistingCollection(const QString& fileName, bool readOnly /* = false */, bool showError /* = true*/)
|
||||
{
|
||||
#ifdef TODO
|
||||
RsCollection::RsCollectionErrorCode err;
|
||||
RsCollection col(fileName,err);
|
||||
|
||||
if(err != RsCollection::RsCollectionErrorCode::NO_ERROR)
|
||||
{
|
||||
RsCollectionDialog rcd = new RsCollectionDialog(col, true, readOnly);
|
||||
return rcd.exec() ;
|
||||
}
|
||||
|
||||
if(showError)
|
||||
QMessageBox::information(nullptr,tr("Error openning RsCollection"),RsCollection::errorString(err));
|
||||
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RsCollectionDialog::openNewCollection(const RsFileTree& tree,const QString& proposed_file_name)
|
||||
{
|
||||
#ifdef TODO
|
||||
QString fileName = proposed_file_name;
|
||||
|
||||
if(!misc::getSaveFileName(nullptr, RshareSettings::LASTDIR_EXTRAFILE
|
||||
, QApplication::translate("RsCollectionFile", "Create collection file")
|
||||
, QApplication::translate("RsCollectionFile", "Collection files") + " (*." + RsCollection::ExtensionString + ")"
|
||||
, fileName,0, QFileDialog::DontConfirmOverwrite))
|
||||
return false;
|
||||
|
||||
if (!fileName.endsWith("." + RsCollection::ExtensionString))
|
||||
fileName += "." + RsCollection::ExtensionString ;
|
||||
|
||||
std::cerr << "Got file name: " << fileName.toStdString() << std::endl;
|
||||
|
||||
QFile file(fileName) ;
|
||||
|
||||
if(file.exists())
|
||||
{
|
||||
RsCollection::RsCollectionErrorCode err;
|
||||
if (!RsCollection::checkFile(fileName,err))
|
||||
{
|
||||
QMessageBox::information(nullptr,tr("Error openning collection"),RsCollection::errorString(err));
|
||||
return false;
|
||||
}
|
||||
|
||||
QMessageBox mb;
|
||||
mb.setText(tr("Save Collection File."));
|
||||
mb.setInformativeText(tr("File already exists.")+"\n"+tr("What do you want to do?"));
|
||||
QAbstractButton *btnOwerWrite = mb.addButton(tr("Overwrite"), QMessageBox::YesRole);
|
||||
QAbstractButton *btnMerge = mb.addButton(tr("Merge"), QMessageBox::NoRole);
|
||||
QAbstractButton *btnCancel = mb.addButton(tr("Cancel"), QMessageBox::ResetRole);
|
||||
mb.setIcon(QMessageBox::Question);
|
||||
mb.exec();
|
||||
|
||||
if (mb.clickedButton()==btnOwerWrite) {
|
||||
//Nothing to do _xml_doc already up to date
|
||||
} else if (mb.clickedButton()==btnMerge) {
|
||||
//Open old file to merge it with _xml_doc
|
||||
QDomDocument qddOldFile("RsCollection");
|
||||
if (qddOldFile.setContent(&file)) {
|
||||
QDomElement docOldElem = qddOldFile.elementsByTagName("RsCollection").at(0).toElement();
|
||||
std::vector<ColFileInfo> colOldFileInfos;
|
||||
recursCollectColFileInfos(docOldElem,colOldFileInfos,QString(),false);
|
||||
|
||||
QDomElement root = _xml_doc.elementsByTagName("RsCollection").at(0).toElement();
|
||||
for(uint32_t i = 0;i<colOldFileInfos.size();++i){
|
||||
recursAddElements(_xml_doc,colOldFileInfos[i],root) ;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (mb.clickedButton()==btnCancel) {
|
||||
return false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}//if(file.exists())
|
||||
|
||||
_fileName=fileName;
|
||||
std::vector<ColFileInfo> colFileInfos ;
|
||||
|
||||
recursCollectColFileInfos(_xml_doc.documentElement(),colFileInfos,QString(),false) ;
|
||||
|
||||
RsCollectionDialog* rcd = new RsCollectionDialog(fileName, colFileInfos,true);
|
||||
connect(rcd,SIGNAL(saveColl(std::vector<ColFileInfo>, QString)),this,SLOT(saveColl(std::vector<ColFileInfo>, QString))) ;
|
||||
_saved=false;
|
||||
rcd->exec() ;
|
||||
delete rcd;
|
||||
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -30,15 +30,20 @@ class RsCollectionDialog: public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
RsCollectionDialog(const QString& filename
|
||||
, const std::vector<ColFileInfo> &colFileInfos
|
||||
, const bool& creation
|
||||
, const bool& readOnly = false) ;
|
||||
virtual ~RsCollectionDialog();
|
||||
|
||||
// Open new collection
|
||||
static bool openNewCollection(const RsFileTree &tree, const QString &proposed_file_name = QString());
|
||||
|
||||
// Open existing collection
|
||||
static bool openExistingCollection(const QString& fileName, bool readOnly = false, bool showError = true);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *ev);
|
||||
|
||||
RsCollectionDialog(const QString& filename, const std::vector<ColFileInfo> &colFileInfos, const bool& creation,
|
||||
const bool& readOnly = false) ;
|
||||
|
||||
private slots:
|
||||
void directoryLoaded(QString dirLoaded);
|
||||
void updateSizes() ;
|
||||
@ -88,4 +93,6 @@ private:
|
||||
QItemSelectionModel *_selectionProxy;
|
||||
bool _dirLoaded;
|
||||
QHash<QString,QString> _listOfFilesAddedInDir;
|
||||
|
||||
RsCollection _collection;
|
||||
};
|
||||
|
0
retroshare-gui/src/gui/common/RsCollectionModel.cpp
Normal file
0
retroshare-gui/src/gui/common/RsCollectionModel.cpp
Normal file
0
retroshare-gui/src/gui/common/RsCollectionModel.h
Normal file
0
retroshare-gui/src/gui/common/RsCollectionModel.h
Normal file
@ -28,12 +28,9 @@ bool RsUrlHandler::openUrl(const QUrl& url)
|
||||
{
|
||||
if(url.scheme() == QString("file") && url.toLocalFile().endsWith("."+RsCollection::ExtensionString))
|
||||
{
|
||||
RsCollection collection ;
|
||||
if(collection.load(url.toLocalFile()))
|
||||
{
|
||||
collection.downloadFiles() ;
|
||||
RsCollection::RsCollectionErrorCode err;
|
||||
RsCollection(url.toLocalFile(),err).downloadFiles() ;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return QDesktopServices::openUrl(url) ;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user