2018-11-13 16:02:26 -05:00
|
|
|
/*******************************************************************************
|
|
|
|
* gui/feeds/SubFileItem.cpp *
|
|
|
|
* *
|
|
|
|
* Copyright (c) 2008, Robert Fernie <retroshare.project@gmail.com> *
|
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Affero General Public License as *
|
|
|
|
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Affero General Public License *
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
2010-07-23 14:52:58 -04:00
|
|
|
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QUrl>
|
2008-06-20 08:43:23 -04:00
|
|
|
|
|
|
|
#include "SubFileItem.h"
|
|
|
|
|
2011-11-09 09:02:15 -05:00
|
|
|
#include <gui/common/RsUrlHandler.h>
|
2010-08-06 05:40:23 -04:00
|
|
|
#include <retroshare/rsfiles.h>
|
2010-10-10 12:43:37 -04:00
|
|
|
#include "util/misc.h"
|
2013-11-02 10:56:22 -04:00
|
|
|
#include "gui/RetroShareLink.h"
|
2008-07-06 12:03:16 -04:00
|
|
|
|
2014-02-01 09:16:15 -05:00
|
|
|
//#include <retroshare/rschannels.h>
|
2008-06-20 08:43:23 -04:00
|
|
|
|
2008-07-09 05:53:47 -04:00
|
|
|
/****
|
|
|
|
* #define DEBUG_ITEM 1
|
|
|
|
****/
|
2008-06-20 08:43:23 -04:00
|
|
|
|
2008-07-06 12:03:16 -04:00
|
|
|
/*******************************************************************
|
|
|
|
* SubFileItem fully controls the file transfer from the gui side
|
|
|
|
*
|
|
|
|
* Display: (In order)
|
|
|
|
*
|
|
|
|
* 1) HASHING
|
|
|
|
* 2) REMOTE / DOWNLOAD
|
|
|
|
* 3) LOCAL
|
|
|
|
* 4) LOCAL / UPLOAD
|
|
|
|
*
|
|
|
|
* Behaviours:
|
|
|
|
* a) Addition to General Dialog (1), (2), (3)
|
|
|
|
* (i) (1), request Hash -> (3).
|
|
|
|
* (ii) (2), download complete -> (3)
|
|
|
|
* (iii) (3)
|
|
|
|
*
|
|
|
|
* b) Message/Blog/Channel (2), (3)
|
|
|
|
* (i) (2), download complete -> (3)
|
|
|
|
* (ii) (3)
|
|
|
|
*
|
|
|
|
* c) Transfers (2), (4)
|
|
|
|
* (i) (2)
|
|
|
|
* (ii) (3)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-07-15 12:36:14 -04:00
|
|
|
//const uint32_t SFI_DEFAULT_PERIOD = (30 * 3600 * 24); /* 30 Days */
|
2008-07-06 12:03:16 -04:00
|
|
|
|
2008-06-20 08:43:23 -04:00
|
|
|
/** Constructor */
|
2014-03-17 16:56:06 -04:00
|
|
|
SubFileItem::SubFileItem(const RsFileHash &hash, const std::string &name, const std::string &path, uint64_t size, uint32_t flags, const RsPeerId &srcId)
|
2010-05-13 15:20:40 -04:00
|
|
|
:QWidget(NULL), mPath(path), mFileHash(hash), mFileName(name), mFileSize(size), mSrcId(srcId)
|
2008-06-20 08:43:23 -04:00
|
|
|
{
|
2008-07-06 12:03:16 -04:00
|
|
|
/* Invoke the Qt Designer generated object setup routine */
|
|
|
|
setupUi(this);
|
|
|
|
|
2010-05-04 20:05:36 -04:00
|
|
|
setAttribute ( Qt::WA_DeleteOnClose, true );
|
|
|
|
|
2008-07-06 12:03:16 -04:00
|
|
|
mMode = flags & SFI_MASK_STATE;
|
|
|
|
mType = flags & SFI_MASK_TYPE;
|
2011-07-06 19:46:16 -04:00
|
|
|
mFlag = flags & SFI_MASK_FLAG;
|
2008-07-06 12:03:16 -04:00
|
|
|
|
2008-11-09 17:21:14 -05:00
|
|
|
/**** Enable ****
|
|
|
|
*****/
|
|
|
|
|
2008-07-06 12:03:16 -04:00
|
|
|
/* all other states are possible */
|
|
|
|
|
|
|
|
if (!rsFiles)
|
|
|
|
{
|
|
|
|
mMode = SFI_STATE_ERROR;
|
|
|
|
}
|
2008-06-20 08:43:23 -04:00
|
|
|
|
2008-07-06 12:03:16 -04:00
|
|
|
Setup();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SubFileItem::Setup()
|
|
|
|
{
|
2017-05-14 15:26:45 -04:00
|
|
|
connect( playButton, SIGNAL( clicked( ) ), this, SLOT( play ( ) ) );
|
|
|
|
connect( downloadButton, SIGNAL( clicked( ) ), this, SLOT( download ( ) ) );
|
|
|
|
connect( cancelButton, SIGNAL( clicked( ) ), this, SLOT( cancel( ) ) );
|
|
|
|
connect( deleteButton, SIGNAL( clicked( ) ), this, SLOT( del( ) ) );
|
|
|
|
connect( copyLinkButton, SIGNAL( clicked( ) ), this, SLOT( copyLink ( ) ) );
|
|
|
|
connect( saveButton, SIGNAL( clicked( ) ), this, SLOT( save ( ) ) );
|
2008-07-06 12:03:16 -04:00
|
|
|
|
|
|
|
/* once off check - if remote, check if we have it
|
|
|
|
* NB: This check might be expensive - and it'll happen often!
|
|
|
|
*/
|
2008-11-30 12:15:23 -05:00
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "SubFileItem::Setup(): " << mFileName;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2008-07-06 12:03:16 -04:00
|
|
|
if (mMode == SFI_STATE_REMOTE)
|
|
|
|
{
|
|
|
|
FileInfo fi;
|
2008-06-20 08:43:23 -04:00
|
|
|
|
2008-07-06 12:03:16 -04:00
|
|
|
/* look up path */
|
2010-10-05 16:39:14 -04:00
|
|
|
if (rsFiles->alreadyHaveFile(mFileHash, fi))
|
2008-07-06 12:03:16 -04:00
|
|
|
{
|
2008-11-30 12:15:23 -05:00
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "SubFileItem::Setup() STATE=>Local Found File";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
std::cerr << "SubFileItem::Setup() path: " << fi.path;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2008-07-06 12:03:16 -04:00
|
|
|
mMode = SFI_STATE_LOCAL;
|
|
|
|
mPath = fi.path;
|
|
|
|
}
|
|
|
|
}
|
2008-06-20 08:43:23 -04:00
|
|
|
|
2017-05-14 15:41:26 -04:00
|
|
|
deleteButton->setVisible(mFlag & SFI_FLAG_ALLOW_DELETE);
|
|
|
|
downloadButton->setVisible(mMode < SFI_STATE_LOCAL);
|
|
|
|
cancelButton->setVisible(mMode < SFI_STATE_LOCAL);
|
2017-05-14 15:26:45 -04:00
|
|
|
|
2009-05-11 10:35:05 -04:00
|
|
|
smaller();
|
2008-06-20 08:43:23 -04:00
|
|
|
updateItemStatic();
|
|
|
|
updateItem();
|
2008-07-06 12:03:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-14 15:26:45 -04:00
|
|
|
void SubFileItem::del()
|
|
|
|
{
|
|
|
|
emit wantsToBeDeleted();
|
|
|
|
}
|
|
|
|
|
2008-07-06 12:03:16 -04:00
|
|
|
bool SubFileItem::done()
|
|
|
|
{
|
|
|
|
return (mMode >= SFI_STATE_LOCAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SubFileItem::ready()
|
|
|
|
{
|
|
|
|
return (mMode >= SFI_STATE_REMOTE);
|
2008-06-20 08:43:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SubFileItem::updateItemStatic()
|
|
|
|
{
|
|
|
|
/* fill in */
|
|
|
|
#ifdef DEBUG_ITEM
|
2008-11-30 12:15:23 -05:00
|
|
|
std::cerr << "SubFileItem::updateItemStatic(): " << mFileName;
|
2008-06-20 08:43:23 -04:00
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2010-10-05 16:39:14 -04:00
|
|
|
QString filename = QString::fromUtf8(mFileName.c_str());
|
2008-07-06 12:03:16 -04:00
|
|
|
mDivisor = 1;
|
2008-06-24 00:36:45 -04:00
|
|
|
|
|
|
|
if (mFileSize > 10000000) /* 10 Mb */
|
|
|
|
{
|
|
|
|
progressBar->setRange(0, mFileSize / 1000000);
|
|
|
|
progressBar->setFormat("%v MB");
|
2008-07-06 12:03:16 -04:00
|
|
|
mDivisor = 1000000;
|
2008-06-24 00:36:45 -04:00
|
|
|
}
|
|
|
|
else if (mFileSize > 10000) /* 10 Kb */
|
|
|
|
{
|
|
|
|
progressBar->setRange(0, mFileSize / 1000);
|
|
|
|
progressBar->setFormat("%v kB");
|
2008-07-06 12:03:16 -04:00
|
|
|
mDivisor = 1000;
|
2008-06-24 00:36:45 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
progressBar->setRange(0, mFileSize);
|
|
|
|
progressBar->setFormat("%v B");
|
2008-07-06 12:03:16 -04:00
|
|
|
mDivisor = 1;
|
2008-06-24 00:36:45 -04:00
|
|
|
}
|
2008-06-20 08:43:23 -04:00
|
|
|
|
2008-07-06 12:03:16 -04:00
|
|
|
/* get full path for local file */
|
2017-05-15 15:37:22 -04:00
|
|
|
if (((mMode == SFI_STATE_LOCAL) || (mMode == SFI_STATE_UPLOAD)))
|
2008-07-06 12:03:16 -04:00
|
|
|
{
|
2008-11-30 12:15:23 -05:00
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "SubFileItem::updateItemStatic() STATE=Local/Upload checking path";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2008-07-06 12:03:16 -04:00
|
|
|
if (mPath == "")
|
|
|
|
{
|
|
|
|
FileInfo fi;
|
2012-11-02 09:52:29 -04:00
|
|
|
FileSearchFlags hintflags = RS_FILE_HINTS_UPLOAD | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_SPEC_ONLY | RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_BROWSABLE;
|
2008-07-06 12:03:16 -04:00
|
|
|
|
|
|
|
/* look up path */
|
|
|
|
if (!rsFiles->FileDetails(mFileHash, hintflags, fi))
|
|
|
|
{
|
2017-05-15 15:37:22 -04:00
|
|
|
if(mFlag & SFI_FLAG_ASSUME_FILE_READY)
|
|
|
|
mMode = SFI_STATE_REMOTE;
|
|
|
|
else
|
|
|
|
mMode = SFI_STATE_ERROR;
|
2008-11-30 12:15:23 -05:00
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "SubFileItem::updateItemStatic() STATE=>Error No Details";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2008-07-06 12:03:16 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-30 12:15:23 -05:00
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "SubFileItem::updateItemStatic() Updated Path";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2008-07-06 12:03:16 -04:00
|
|
|
mPath = fi.path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* do buttons + display */
|
|
|
|
switch (mMode)
|
|
|
|
{
|
|
|
|
case SFI_STATE_ERROR:
|
|
|
|
progressBar->setRange(0, 100);
|
2011-07-06 19:46:16 -04:00
|
|
|
progressBar->setFormat(tr("ERROR"));
|
2008-07-06 12:03:16 -04:00
|
|
|
|
|
|
|
playButton->setEnabled(false);
|
|
|
|
downloadButton->setEnabled(false);
|
|
|
|
cancelButton->setEnabled(false);
|
2011-07-06 19:46:16 -04:00
|
|
|
|
2008-07-06 12:03:16 -04:00
|
|
|
progressBar->setValue(0);
|
2010-10-05 16:39:14 -04:00
|
|
|
filename = "[" + tr("ERROR") + "] " + filename;
|
2008-07-06 12:03:16 -04:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SFI_STATE_EXTRA:
|
2010-10-05 16:39:14 -04:00
|
|
|
filename = QString::fromUtf8(mPath.c_str());
|
2008-07-06 12:03:16 -04:00
|
|
|
|
|
|
|
progressBar->setRange(0, 100);
|
|
|
|
progressBar->setFormat("HASHING");
|
|
|
|
|
|
|
|
playButton->setEnabled(false);
|
|
|
|
downloadButton->setEnabled(false);
|
2011-07-06 19:46:16 -04:00
|
|
|
cancelButton->setEnabled(false);
|
2008-07-06 12:03:16 -04:00
|
|
|
|
|
|
|
progressBar->setValue(0);
|
2010-10-05 16:39:14 -04:00
|
|
|
filename = "[" + tr("EXTRA") + "] " + filename;
|
2008-07-06 12:03:16 -04:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SFI_STATE_REMOTE:
|
|
|
|
playButton->setEnabled(false);
|
|
|
|
downloadButton->setEnabled(true);
|
2017-05-15 15:37:22 -04:00
|
|
|
downloadButton->setVisible(true);
|
2008-07-06 12:03:16 -04:00
|
|
|
cancelButton->setEnabled(false);
|
|
|
|
|
|
|
|
progressBar->setValue(0);
|
2010-10-10 12:43:37 -04:00
|
|
|
filename = "[" + tr("REMOTE") + "] " + filename + " (" + misc::friendlyUnit(mFileSize) + ")";
|
2008-07-06 12:03:16 -04:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SFI_STATE_DOWNLOAD:
|
|
|
|
playButton->setEnabled(false);
|
|
|
|
downloadButton->setEnabled(false);
|
|
|
|
cancelButton->setEnabled(true);
|
2010-10-05 16:39:14 -04:00
|
|
|
filename = "[" + tr("DOWNLOAD") + "] " + filename;
|
2008-06-20 08:43:23 -04:00
|
|
|
|
2008-07-06 12:03:16 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SFI_STATE_LOCAL:
|
|
|
|
playButton->setEnabled(true);
|
|
|
|
downloadButton->setEnabled(false);
|
2011-07-06 19:46:16 -04:00
|
|
|
cancelButton->setEnabled(false);
|
2008-07-06 12:03:16 -04:00
|
|
|
|
|
|
|
progressBar->setValue(mFileSize / mDivisor);
|
2010-10-10 12:43:37 -04:00
|
|
|
filename = "[" + tr("LOCAL") + "] " + filename + " (" + misc::friendlyUnit(mFileSize) + ")";
|
2008-07-06 12:03:16 -04:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SFI_STATE_UPLOAD:
|
|
|
|
playButton->setEnabled(true);
|
|
|
|
downloadButton->setEnabled(false);
|
|
|
|
cancelButton->setEnabled(false);
|
2010-10-05 16:39:14 -04:00
|
|
|
filename = "[" + tr("UPLOAD") + "] " + filename;
|
2008-07-06 12:03:16 -04:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
saveButton->hide();
|
|
|
|
|
|
|
|
switch(mType)
|
|
|
|
{
|
|
|
|
case SFI_TYPE_CHANNEL:
|
|
|
|
{
|
|
|
|
saveButton->show();
|
|
|
|
if (mMode == SFI_STATE_LOCAL)
|
|
|
|
{
|
|
|
|
saveButton->setEnabled(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
saveButton->setEnabled(false);
|
|
|
|
}
|
2011-07-06 19:46:16 -04:00
|
|
|
if (mFlag & SFI_FLAG_CREATE) {
|
|
|
|
cancelButton->setEnabled(true); // channel files which are extra files are removed
|
|
|
|
cancelButton->setToolTip(tr("Remove Attachment"));
|
|
|
|
}
|
2008-07-06 12:03:16 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SFI_TYPE_ATTACH:
|
|
|
|
{
|
|
|
|
playButton->hide();
|
|
|
|
downloadButton->hide();
|
|
|
|
cancelButton->setEnabled(true);
|
2011-07-06 19:46:16 -04:00
|
|
|
cancelButton->setToolTip(tr("Remove Attachment"));
|
2008-07-06 12:03:16 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
fileLabel->setText(filename);
|
|
|
|
fileLabel->setToolTip(filename);
|
|
|
|
}
|
2008-06-20 08:43:23 -04:00
|
|
|
|
|
|
|
void SubFileItem::updateItem()
|
|
|
|
{
|
|
|
|
/* fill in */
|
|
|
|
#ifdef DEBUG_ITEM
|
2008-11-30 12:15:23 -05:00
|
|
|
std::cerr << "SubFileItem::updateItem():" << mFileName;
|
2008-06-20 08:43:23 -04:00
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2008-07-06 12:03:16 -04:00
|
|
|
|
|
|
|
/* Extract File Details */
|
|
|
|
/* Update State if necessary */
|
|
|
|
|
|
|
|
FileInfo fi;
|
|
|
|
bool stateChanged = false;
|
2008-06-20 08:43:23 -04:00
|
|
|
int msec_rate = 1000;
|
|
|
|
|
2008-07-06 12:03:16 -04:00
|
|
|
if ((mMode == SFI_STATE_ERROR) || (mMode == SFI_STATE_LOCAL))
|
2008-06-24 00:36:45 -04:00
|
|
|
{
|
2008-11-30 12:15:23 -05:00
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "SubFileItem::updateItem() STATE=Local/Error ignore";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2008-07-06 12:03:16 -04:00
|
|
|
/* ignore - dead file, or done */
|
2010-10-05 16:39:14 -04:00
|
|
|
|
|
|
|
if (mMode == SFI_STATE_ERROR) {
|
|
|
|
/* updateStatic once */
|
|
|
|
stateChanged = true;
|
|
|
|
}
|
2008-06-24 00:36:45 -04:00
|
|
|
}
|
2008-07-06 12:03:16 -04:00
|
|
|
else if (mMode == SFI_STATE_EXTRA)
|
|
|
|
{
|
2008-11-30 12:15:23 -05:00
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "SubFileItem::updateItem() STATE=Extra File";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2008-07-06 12:03:16 -04:00
|
|
|
/* check for file status */
|
|
|
|
if (rsFiles->ExtraFileStatus(mPath, fi))
|
|
|
|
{
|
2008-11-30 12:15:23 -05:00
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "SubFileItem::updateItem() STATE=>Local";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2008-07-06 12:03:16 -04:00
|
|
|
mMode = SFI_STATE_LOCAL;
|
|
|
|
|
|
|
|
/* fill in file details */
|
|
|
|
mFileName = fi.fname;
|
|
|
|
mFileSize = fi.size;
|
|
|
|
mFileHash = fi.hash;
|
|
|
|
|
|
|
|
/* have path already! */
|
|
|
|
|
|
|
|
stateChanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-02 09:52:29 -04:00
|
|
|
FileSearchFlags hintflags(0u) ;
|
2008-07-06 12:03:16 -04:00
|
|
|
switch(mMode)
|
|
|
|
{
|
|
|
|
case SFI_STATE_REMOTE:
|
|
|
|
hintflags = RS_FILE_HINTS_DOWNLOAD | RS_FILE_HINTS_SPEC_ONLY;
|
|
|
|
break;
|
|
|
|
case SFI_STATE_DOWNLOAD:
|
|
|
|
hintflags = RS_FILE_HINTS_DOWNLOAD | RS_FILE_HINTS_SPEC_ONLY;
|
|
|
|
break;
|
|
|
|
case SFI_STATE_UPLOAD:
|
|
|
|
hintflags = RS_FILE_HINTS_UPLOAD | RS_FILE_HINTS_SPEC_ONLY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool detailsOk = rsFiles->FileDetails(mFileHash, hintflags, fi);
|
|
|
|
|
|
|
|
/* have details - see if state has changed */
|
|
|
|
switch(mMode)
|
|
|
|
{
|
|
|
|
case SFI_STATE_REMOTE:
|
2008-11-30 12:15:23 -05:00
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "SubFileItem::updateItem() STATE=Remote";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2008-07-06 12:03:16 -04:00
|
|
|
/* is it downloading? */
|
|
|
|
if (detailsOk)
|
|
|
|
{
|
2008-11-30 12:15:23 -05:00
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "SubFileItem::updateItem() STATE=>Download";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2008-07-06 12:03:16 -04:00
|
|
|
/* downloading */
|
|
|
|
mMode = SFI_STATE_DOWNLOAD;
|
|
|
|
stateChanged = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SFI_STATE_DOWNLOAD:
|
2008-11-30 12:15:23 -05:00
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "SubFileItem::updateItem() STATE=Download";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2008-07-06 12:03:16 -04:00
|
|
|
|
|
|
|
if (!detailsOk)
|
|
|
|
{
|
2008-11-30 12:15:23 -05:00
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "SubFileItem::updateItem() STATE=>Remote";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2008-07-06 12:03:16 -04:00
|
|
|
mMode = SFI_STATE_REMOTE;
|
|
|
|
stateChanged = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* has it completed? */
|
|
|
|
if (fi.avail == mFileSize)
|
|
|
|
{
|
2008-11-30 12:15:23 -05:00
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "SubFileItem::updateItem() STATE=>Local";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2008-07-06 12:03:16 -04:00
|
|
|
/* save path */
|
|
|
|
/* update progress */
|
|
|
|
mMode = SFI_STATE_LOCAL;
|
|
|
|
mPath = fi.path;
|
|
|
|
stateChanged = true;
|
|
|
|
}
|
|
|
|
progressBar->setValue(fi.avail / mDivisor);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SFI_STATE_UPLOAD:
|
2008-11-30 12:15:23 -05:00
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "SubFileItem::updateItem() STATE=Upload";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2008-07-06 12:03:16 -04:00
|
|
|
|
|
|
|
if (detailsOk)
|
|
|
|
{
|
|
|
|
progressBar->setValue(fi.avail / mDivisor);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* update progress */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/****** update based on new state ******/
|
|
|
|
if (stateChanged)
|
2008-06-24 00:36:45 -04:00
|
|
|
{
|
2008-07-06 12:03:16 -04:00
|
|
|
updateItemStatic();
|
2008-06-24 00:36:45 -04:00
|
|
|
}
|
|
|
|
|
2008-07-06 12:03:16 -04:00
|
|
|
uint32_t repeat = 0;
|
2009-05-06 17:15:12 -04:00
|
|
|
|
2008-07-06 12:03:16 -04:00
|
|
|
switch (mMode)
|
2008-06-20 08:43:23 -04:00
|
|
|
{
|
2008-07-06 12:03:16 -04:00
|
|
|
case SFI_STATE_ERROR:
|
|
|
|
repeat = 0;
|
|
|
|
break;
|
2008-06-20 08:43:23 -04:00
|
|
|
|
2008-07-06 12:03:16 -04:00
|
|
|
case SFI_STATE_EXTRA:
|
|
|
|
repeat = 1;
|
|
|
|
msec_rate = 5000; /* slow */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SFI_STATE_REMOTE:
|
|
|
|
repeat = 1;
|
|
|
|
msec_rate = 30000; /* very slow */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SFI_STATE_DOWNLOAD:
|
|
|
|
repeat = 1;
|
|
|
|
msec_rate = 2000; /* should be download rate dependent */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SFI_STATE_LOCAL:
|
|
|
|
repeat = 0;
|
2009-05-06 17:15:12 -04:00
|
|
|
emit fileFinished(this);
|
2008-07-06 12:03:16 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SFI_STATE_UPLOAD:
|
|
|
|
repeat = 1;
|
|
|
|
msec_rate = 2000; /* should be download rate dependent */
|
|
|
|
break;
|
2008-06-20 08:43:23 -04:00
|
|
|
}
|
2008-07-06 12:03:16 -04:00
|
|
|
|
|
|
|
|
|
|
|
if (repeat)
|
2008-06-20 08:43:23 -04:00
|
|
|
{
|
2008-11-30 12:15:23 -05:00
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "SubFileItem::updateItem() callback for update!";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2008-07-06 12:03:16 -04:00
|
|
|
QTimer::singleShot( msec_rate, this, SLOT(updateItem( void ) ));
|
2008-06-20 08:43:23 -04:00
|
|
|
}
|
2008-07-06 12:03:16 -04:00
|
|
|
|
2008-06-20 08:43:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-06 12:03:16 -04:00
|
|
|
|
|
|
|
|
2009-05-11 10:35:05 -04:00
|
|
|
void SubFileItem::smaller()
|
2008-06-20 08:43:23 -04:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "SubFileItem::cancel()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
expandFrame->hide();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void SubFileItem::toggle()
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
if (expandFrame->isHidden())
|
|
|
|
{
|
|
|
|
expandFrame->show();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
expandFrame->hide();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void SubFileItem::cancel()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "SubFileItem::cancel()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2009-05-14 11:53:40 -04:00
|
|
|
//set the state to error mode
|
|
|
|
mMode = SFI_STATE_ERROR;
|
|
|
|
|
2008-07-06 12:03:16 -04:00
|
|
|
/* Only occurs - if it is downloading */
|
2011-07-06 19:46:16 -04:00
|
|
|
if (((mType == SFI_TYPE_ATTACH) || (mType == SFI_TYPE_CHANNEL)) && (mFlag & SFI_FLAG_CREATE))
|
2008-07-06 12:03:16 -04:00
|
|
|
{
|
|
|
|
hide();
|
2018-09-27 10:53:08 -04:00
|
|
|
rsFiles->ExtraFileRemove(FileHash());//, RS_FILE_REQ_ANONYMOUS_ROUTING | RS_FILE_REQ_EXTRA);
|
2010-10-31 15:29:26 -04:00
|
|
|
mPath = "";
|
2008-07-06 12:03:16 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rsFiles->FileCancel(mFileHash);
|
|
|
|
}
|
2010-10-05 16:39:14 -04:00
|
|
|
|
|
|
|
updateItem();
|
2008-06-20 08:43:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SubFileItem::play()
|
|
|
|
{
|
2010-05-08 12:21:57 -04:00
|
|
|
FileInfo info;
|
2012-11-02 09:52:29 -04:00
|
|
|
FileSearchFlags flags = RS_FILE_HINTS_DOWNLOAD | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_NETWORK_WIDE;
|
2008-11-30 12:15:23 -05:00
|
|
|
|
2010-05-08 12:21:57 -04:00
|
|
|
|
|
|
|
if (!rsFiles->FileDetails( mFileHash, flags, info))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (done()) {
|
|
|
|
|
|
|
|
/* open file with a suitable application */
|
|
|
|
QFileInfo qinfo;
|
|
|
|
qinfo.setFile(info.path.c_str());
|
|
|
|
if (qinfo.exists()) {
|
2011-11-09 09:02:15 -05:00
|
|
|
if (!RsUrlHandler::openUrl(QUrl::fromLocalFile(qinfo.absoluteFilePath()))) {
|
2010-05-08 12:21:57 -04:00
|
|
|
std::cerr << "openTransfer(): can't open file " << info.path << std::endl;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
QMessageBox::information(this, tr("Play File"),
|
|
|
|
tr("File %1 does not exist at location.").arg(info.path.c_str()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* rise a message box for incompleted download file */
|
|
|
|
QMessageBox::information(this, tr("Play File"),
|
|
|
|
tr("File %1 is not completed.").arg(info.fname.c_str()));
|
|
|
|
return;
|
|
|
|
}
|
2008-11-30 12:15:23 -05:00
|
|
|
|
2008-07-06 12:03:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SubFileItem::download()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "SubFileItem::download()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
std::list<RsPeerId> sources ;
|
2012-09-23 16:02:07 -04:00
|
|
|
|
2013-11-16 08:21:25 -05:00
|
|
|
std::string destination;
|
2014-02-01 09:16:15 -05:00
|
|
|
#if 0
|
2013-11-16 08:21:25 -05:00
|
|
|
if (!mChannelId.empty() && mType == SFI_TYPE_CHANNEL) {
|
|
|
|
ChannelInfo ci;
|
|
|
|
if (rsChannels->getChannelInfo(mChannelId, ci)) {
|
|
|
|
destination = ci.destination_directory;
|
|
|
|
}
|
|
|
|
}
|
2014-02-01 09:16:15 -05:00
|
|
|
#endif
|
|
|
|
|
2013-11-16 08:21:25 -05:00
|
|
|
|
2012-09-23 16:02:07 -04:00
|
|
|
// Add possible direct sources.
|
|
|
|
//
|
|
|
|
FileInfo finfo ;
|
|
|
|
rsFiles->FileDetails(mFileHash,RS_FILE_HINTS_REMOTE,finfo) ;
|
|
|
|
|
2018-02-04 16:56:13 -05:00
|
|
|
for(std::vector<TransferInfo>::const_iterator it(finfo.peers.begin());it!=finfo.peers.end();++it)
|
2012-09-23 16:02:07 -04:00
|
|
|
sources.push_back((*it).peerId) ;
|
2008-07-06 12:03:16 -04:00
|
|
|
|
|
|
|
// TEMP
|
2008-08-16 13:10:01 -04:00
|
|
|
std::cerr << "SubFileItem::download() Calling File Request";
|
|
|
|
std::cerr << std::endl;
|
2012-09-23 16:02:07 -04:00
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
if (!mSrcId.isNull())
|
2012-09-23 16:02:07 -04:00
|
|
|
sources.push_back(mSrcId);
|
|
|
|
|
2013-11-16 08:21:25 -05:00
|
|
|
rsFiles->FileRequest(mFileName, mFileHash, mFileSize, destination, RS_FILE_REQ_ANONYMOUS_ROUTING, sources);
|
2008-07-06 12:03:16 -04:00
|
|
|
|
2010-10-05 16:39:14 -04:00
|
|
|
downloadButton->setEnabled(false);
|
|
|
|
|
|
|
|
updateItem();
|
2008-07-06 12:03:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SubFileItem::save()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "SubFileItem::save()";
|
|
|
|
std::cerr << std::endl;
|
2008-06-20 08:43:23 -04:00
|
|
|
#endif
|
2008-11-27 16:26:52 -05:00
|
|
|
|
2010-10-31 15:29:26 -04:00
|
|
|
FileInfo fInfo;
|
|
|
|
|
2008-11-27 16:26:52 -05:00
|
|
|
if (mType == SFI_TYPE_CHANNEL)
|
|
|
|
{
|
|
|
|
/* only enable these function for Channels. */
|
|
|
|
|
|
|
|
/* find out where they want to save it */
|
|
|
|
QString startpath = "";
|
|
|
|
QString dir = QFileDialog::getExistingDirectory(this, tr("Save Channel File"),
|
|
|
|
startpath,
|
|
|
|
QFileDialog::ShowDirsOnly
|
|
|
|
| QFileDialog::DontResolveSymlinks);
|
|
|
|
|
|
|
|
std::string destpath = dir.toStdString();
|
|
|
|
|
|
|
|
if (destpath != "")
|
|
|
|
{
|
2010-10-31 15:29:26 -04:00
|
|
|
bool copied = rsFiles->ExtraFileMove(mFileName, mFileHash, mFileSize, destpath);
|
|
|
|
|
|
|
|
// may be manually downloaded channel file
|
|
|
|
if(!copied){
|
|
|
|
rsFiles->FileDetails(mFileHash, RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_EXTRA, fInfo);
|
|
|
|
|
|
|
|
if(fInfo.path != "")
|
|
|
|
{
|
|
|
|
|
|
|
|
destpath += "/" + fInfo.fname;
|
2013-06-09 09:18:31 -04:00
|
|
|
rsFiles->copyFile(fInfo.path, destpath);
|
2010-10-31 15:29:26 -04:00
|
|
|
}
|
|
|
|
}
|
2008-11-27 16:26:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
}
|
2008-06-20 08:43:23 -04:00
|
|
|
}
|
|
|
|
|
2009-05-06 17:15:12 -04:00
|
|
|
uint32_t SubFileItem::getState() {
|
|
|
|
return mMode;
|
|
|
|
}
|
2010-10-05 16:39:14 -04:00
|
|
|
|
|
|
|
bool SubFileItem::isDownloadable(bool &startable)
|
|
|
|
{
|
|
|
|
/* Check buttons. Not good, but it works. */
|
|
|
|
bool visible = downloadButton->isVisibleTo(this);
|
|
|
|
startable = visible && downloadButton->isEnabled();
|
|
|
|
|
|
|
|
return visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SubFileItem::isPlayable(bool &startable)
|
|
|
|
{
|
|
|
|
/* Check buttons. Not good, but it works. */
|
|
|
|
bool visible = playButton->isVisibleTo(this);
|
|
|
|
startable = visible && playButton->isEnabled();
|
|
|
|
|
|
|
|
return visible;
|
|
|
|
}
|
2010-10-31 15:29:26 -04:00
|
|
|
|
2013-11-02 10:56:22 -04:00
|
|
|
void SubFileItem::mediatype()
|
|
|
|
{
|
|
|
|
/* check if the file is not a media file and change text */
|
|
|
|
playButton->setText(tr("Open"));
|
|
|
|
playButton->setToolTip(tr("Open File"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SubFileItem::copyLink()
|
|
|
|
{
|
2014-03-17 16:56:06 -04:00
|
|
|
if (mFileName.empty() || mFileHash.isNull()) {
|
2013-11-02 10:56:22 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-16 07:11:47 -04:00
|
|
|
RetroShareLink link = RetroShareLink::createFile(QString::fromUtf8(mFileName.c_str()), mFileSize, QString::fromStdString(mFileHash.toStdString()));
|
|
|
|
if (link.valid()) {
|
2013-11-02 10:56:22 -04:00
|
|
|
QList<RetroShareLink> urls;
|
|
|
|
urls.push_back(link);
|
|
|
|
RSLinkClipboard::copyLinks(urls);
|
|
|
|
}
|
|
|
|
}
|