mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-25 23:49:35 -05:00
Improvements to make more complete Feed System Demo.
* Major Work on SubFileItem to display possible attachment/file states. * Added Download / Save buttons to SubFileItem. * Enabled Correct Name / Transfer state display in SubFileItem. * Disabled 'Local' Checks temporarily in SubFileItem. (for demo) * Disabled 'Remote' Drops temporarily in GeneralMsgDialog. (for demo) * Added File Details to TransferFeed. * Add 'Online' List to PeersFeed. * extended Msg Attachments to handle local/remote, and check for attachment errors. * enabled Attachment removal. * Updated RS Interface files. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@637 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
9629c6923c
commit
2ba752fbfb
@ -36,7 +36,7 @@
|
||||
|
||||
/** Constructor */
|
||||
GeneralMsgDialog::GeneralMsgDialog(QWidget *parent, uint32_t type)
|
||||
: QDialog (parent)
|
||||
: QDialog (parent), mCheckAttachment(true)
|
||||
{
|
||||
/* Invoke the Qt Designer generated object setup routine */
|
||||
setupUi(this);
|
||||
@ -234,12 +234,12 @@ void GeneralMsgDialog::parseRsFileListAttachments(std::string attachList)
|
||||
std::cerr << "Item Ok" << std::endl;
|
||||
if (source == "Local")
|
||||
{
|
||||
addAttachment(hash, fname, size);
|
||||
addAttachment(hash, fname, size, true, "");
|
||||
}
|
||||
else
|
||||
{
|
||||
// TEMP NOT ALLOWED UNTIL FT WORKING.
|
||||
//addAttachment(hash, fname, size);
|
||||
addAttachment(hash, fname, size, false, source);
|
||||
}
|
||||
|
||||
}
|
||||
@ -252,21 +252,38 @@ void GeneralMsgDialog::parseRsFileListAttachments(std::string attachList)
|
||||
}
|
||||
|
||||
|
||||
void GeneralMsgDialog::addAttachment(std::string hash, std::string fname, uint64_t size)
|
||||
void GeneralMsgDialog::addAttachment(std::string hash, std::string fname, uint64_t size, bool local, std::string srcId)
|
||||
{
|
||||
/* add a SubFileItem to the attachment section */
|
||||
std::cerr << "GeneralMsgDialog::addAttachment()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
/* add widget in for new destination */
|
||||
SubFileItem *file = new SubFileItem(hash, fname, size);
|
||||
|
||||
uint32_t flags = SFI_TYPE_ATTACH;
|
||||
if (local)
|
||||
{
|
||||
flags |= SFI_STATE_LOCAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
flags |= SFI_STATE_REMOTE;
|
||||
// TMP REMOVED REMOTE ADD FOR DEMONSTRATOR
|
||||
return;
|
||||
}
|
||||
|
||||
SubFileItem *file = new SubFileItem(hash, fname, size, flags, srcId);
|
||||
|
||||
mAttachments.push_back(file);
|
||||
QLayout *layout = fileFrame->layout();
|
||||
layout->addWidget(file);
|
||||
|
||||
return;
|
||||
if (mCheckAttachment)
|
||||
{
|
||||
checkAttachmentReady();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -277,16 +294,54 @@ void GeneralMsgDialog::addAttachment(std::string path)
|
||||
std::cerr << std::endl;
|
||||
|
||||
/* add widget in for new destination */
|
||||
SubFileItem *file = new SubFileItem("unknownHash", path, 12000);
|
||||
SubFileItem *file = new SubFileItem(path);
|
||||
|
||||
mAttachments.push_back(file);
|
||||
QLayout *layout = fileFrame->layout();
|
||||
layout->addWidget(file);
|
||||
|
||||
if (mCheckAttachment)
|
||||
{
|
||||
checkAttachmentReady();
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
void GeneralMsgDialog::checkAttachmentReady()
|
||||
{
|
||||
std::list<SubFileItem *>::iterator fit;
|
||||
|
||||
mCheckAttachment = false;
|
||||
|
||||
for(fit = mAttachments.begin(); fit != mAttachments.end(); fit++)
|
||||
{
|
||||
if (!(*fit)->isHidden())
|
||||
{
|
||||
if (!(*fit)->ready())
|
||||
{
|
||||
/*
|
||||
*/
|
||||
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
||||
break;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fit == mAttachments.end())
|
||||
{
|
||||
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
|
||||
}
|
||||
|
||||
/* repeat... */
|
||||
int msec_rate = 1000;
|
||||
QTimer::singleShot( msec_rate, this, SLOT(checkAttachmentReady(void)));
|
||||
}
|
||||
|
||||
|
||||
void GeneralMsgDialog::cancelMsg()
|
||||
{
|
||||
@ -475,6 +530,16 @@ void GeneralMsgDialog::sendMsg()
|
||||
fi.size = (*fit)->FileSize();
|
||||
|
||||
files.push_back(fi);
|
||||
|
||||
/* commence downloads - if we don't have the file */
|
||||
if (!(*fit)->done())
|
||||
{
|
||||
if ((*fit)->ready())
|
||||
{
|
||||
(*fit)->download();
|
||||
}
|
||||
// Skips unhashed files.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,8 @@ public:
|
||||
/** Default Destructor */
|
||||
|
||||
void addAttachment(std::string path);
|
||||
void addAttachment(std::string hash, std::string fname, uint64_t size);
|
||||
void addAttachment(std::string hash, std::string fname, uint64_t size,
|
||||
bool local, std::string srcId);
|
||||
|
||||
void addDestination(uint32_t type, std::string grpId, std::string inReplyTo);
|
||||
void setMsgType(uint32_t type);
|
||||
@ -53,6 +54,7 @@ virtual void dragEnterEvent(QDragEnterEvent *event);
|
||||
virtual void dropEvent(QDropEvent *event);
|
||||
|
||||
private slots:
|
||||
void checkAttachmentReady();
|
||||
void updateGroupId();
|
||||
void newDestination();
|
||||
void cancelMsg();
|
||||
@ -69,6 +71,8 @@ void sendMessage(uint32_t type, std::string grpId, std::string inReplyTo,
|
||||
/* maps of files and destinations */
|
||||
std::list<SubDestItem *> mDestinations;
|
||||
std::list<SubFileItem *> mAttachments;
|
||||
|
||||
bool mCheckAttachment;
|
||||
};
|
||||
|
||||
|
||||
|
@ -30,8 +30,9 @@
|
||||
#include "GeneralMsgDialog.h"
|
||||
|
||||
const uint32_t PEERSFEED_MODE_FRIENDS = 0x0000;
|
||||
const uint32_t PEERSFEED_MODE_FOF = 0x0001;
|
||||
const uint32_t PEERSFEED_MODE_ALL = 0x0002;
|
||||
const uint32_t PEERSFEED_MODE_ONLINE = 0x0001;
|
||||
const uint32_t PEERSFEED_MODE_FOF = 0x0002;
|
||||
const uint32_t PEERSFEED_MODE_ALL = 0x0003;
|
||||
|
||||
/** Constructor */
|
||||
PeersFeed::PeersFeed(QWidget *parent)
|
||||
@ -127,6 +128,10 @@ void PeersFeed::updatePeers()
|
||||
{
|
||||
rsPeers->getFriendList(peers);
|
||||
}
|
||||
else if (mMode == PEERSFEED_MODE_ONLINE)
|
||||
{
|
||||
rsPeers->getOnlineList(peers);
|
||||
}
|
||||
else if (mMode == PEERSFEED_MODE_ALL)
|
||||
{
|
||||
rsPeers->getOthersList(peers);
|
||||
|
@ -60,7 +60,12 @@
|
||||
</property>
|
||||
<item>
|
||||
<property name="text" >
|
||||
<string>Friends Only</string>
|
||||
<string>Friends</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text" >
|
||||
<string>Online Friends</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
|
@ -202,9 +202,17 @@ void TransferFeed::updateDownloads()
|
||||
/* add in new ones */
|
||||
for(it = toAdd.begin(); it != toAdd.end(); it++)
|
||||
{
|
||||
SubFileItem *fi = new SubFileItem(*it, "FileName", 123498);
|
||||
mDownloads[*it] = fi;
|
||||
mDownloadsLayout->addWidget(fi);
|
||||
FileInfo fi;
|
||||
uint32_t hintflags = RS_FILE_HINTS_DOWNLOAD
|
||||
| RS_FILE_HINTS_SPEC_ONLY;
|
||||
|
||||
if (rsFiles->FileDetails(*it, hintflags, fi))
|
||||
{
|
||||
SubFileItem *sfi = new SubFileItem(*it, fi.fname,
|
||||
fi.size, SFI_STATE_DOWNLOAD, fi.source);
|
||||
mDownloads[*it] = sfi;
|
||||
mDownloadsLayout->addWidget(sfi);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -284,9 +292,17 @@ void TransferFeed::updateUploads()
|
||||
/* add in new ones */
|
||||
for(it = toAdd.begin(); it != toAdd.end(); it++)
|
||||
{
|
||||
SubFileItem *fi = new SubFileItem(*it, "FileName", 123498);
|
||||
mUploads[*it] = fi;
|
||||
mUploadsLayout->addWidget(fi);
|
||||
FileInfo fi;
|
||||
uint32_t hintflags = RS_FILE_HINTS_UPLOAD
|
||||
| RS_FILE_HINTS_SPEC_ONLY;
|
||||
|
||||
if (rsFiles->FileDetails(*it, hintflags, fi))
|
||||
{
|
||||
SubFileItem *sfi = new SubFileItem(*it, fi.fname,
|
||||
fi.size, SFI_STATE_UPLOAD, fi.source);
|
||||
mUploads[*it] = sfi;
|
||||
mUploadsLayout->addWidget(sfi);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,9 +59,9 @@ void BlogMsgItem::updateItemStatic()
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
msgLabel->setText("FFFFFFFFFFF AAAAAAAAAAAAAAA \n HHHHHHHHHHH HHHHHHHHHHHHHHHHH");
|
||||
titleLabel->setText("Channel Feed: Best Channel Ever");
|
||||
subjectLabel->setText("Brand new exciting Ever");
|
||||
msgLabel->setText("What did you expect? \nThe Blogs will be up and running shortly!");
|
||||
titleLabel->setText("Blog Feed: Jacki @ Friday");
|
||||
subjectLabel->setText("Brand new exciting Blog stuff");
|
||||
|
||||
/* add Files */
|
||||
int total = (int) (10.0 * (rand() / (RAND_MAX + 1.0)));
|
||||
@ -70,7 +70,7 @@ void BlogMsgItem::updateItemStatic()
|
||||
for(i = 0; i < total; i++)
|
||||
{
|
||||
/* add file */
|
||||
SubFileItem *fi = new SubFileItem("dummyHash", "dummyFileName", 1283918);
|
||||
SubFileItem *fi = new SubFileItem("dummyHash", "dummy_File", 1283918, SFI_STATE_REMOTE, mPeerId);
|
||||
mFileItems.push_back(fi);
|
||||
|
||||
QLayout *layout = expandFrame->layout();
|
||||
|
@ -94,7 +94,8 @@ void ChanMsgItem::updateItemStatic()
|
||||
for(it = cmi.files.begin(); it != cmi.files.end(); it++)
|
||||
{
|
||||
/* add file */
|
||||
SubFileItem *fi = new SubFileItem(it->hash, it->fname, it->size);
|
||||
SubFileItem *fi = new SubFileItem(it->hash, it->fname, it->size,
|
||||
SFI_STATE_REMOTE | SFI_TYPE_CHANNEL, "");
|
||||
mFileItems.push_back(fi);
|
||||
|
||||
QLayout *layout = expandFrame->layout();
|
||||
|
@ -125,7 +125,7 @@ void MsgItem::updateItemStatic()
|
||||
for(it = mi.files.begin(); it != mi.files.end(); it++)
|
||||
{
|
||||
/* add file */
|
||||
SubFileItem *fi = new SubFileItem(it->hash, it->fname, it->size);
|
||||
SubFileItem *fi = new SubFileItem(it->hash, it->fname, it->size, SFI_STATE_REMOTE, mi.srcId);
|
||||
mFileItems.push_back(fi);
|
||||
|
||||
QLayout *layout = expandFrame->layout();
|
||||
|
@ -22,26 +22,129 @@
|
||||
|
||||
#include "SubFileItem.h"
|
||||
|
||||
#include "rsiface/rsfiles.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#define DEBUG_ITEM 1
|
||||
|
||||
/*******************************************************************
|
||||
* 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)
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
const uint32_t SFI_DEFAULT_PERIOD = (30 * 3600 * 24); /* 30 Days */
|
||||
|
||||
/** Constructor */
|
||||
SubFileItem::SubFileItem(std::string hash, std::string name, uint64_t size)
|
||||
:QWidget(NULL), mFileHash(hash), mFileName(name), mFileSize(size)
|
||||
SubFileItem::SubFileItem(std::string hash, std::string name, uint64_t size,
|
||||
uint32_t flags, std::string srcId)
|
||||
:QWidget(NULL), mFileHash(hash), mFileName(name), mFileSize(size), mSrcId(srcId)
|
||||
{
|
||||
/* Invoke the Qt Designer generated object setup routine */
|
||||
setupUi(this);
|
||||
/* Invoke the Qt Designer generated object setup routine */
|
||||
setupUi(this);
|
||||
|
||||
mMode = flags & SFI_MASK_STATE;
|
||||
mType = flags & SFI_MASK_TYPE;
|
||||
|
||||
if (mMode == SFI_STATE_EXTRA)
|
||||
{
|
||||
mMode = SFI_STATE_ERROR;
|
||||
}
|
||||
/* all other states are possible */
|
||||
|
||||
if (!rsFiles)
|
||||
{
|
||||
mMode = SFI_STATE_ERROR;
|
||||
}
|
||||
|
||||
Setup();
|
||||
}
|
||||
|
||||
/** Constructor */
|
||||
SubFileItem::SubFileItem(std::string path)
|
||||
:QWidget(NULL), mPath(path), mFileSize(0)
|
||||
{
|
||||
/* Invoke the Qt Designer generated object setup routine */
|
||||
setupUi(this);
|
||||
|
||||
mMode = SFI_STATE_EXTRA;
|
||||
mType = SFI_TYPE_ATTACH;
|
||||
|
||||
/* ask for Files to hash/prepare it for us */
|
||||
if ((!rsFiles) || (rsFiles->ExtraFileHash(path, SFI_DEFAULT_PERIOD, 0)))
|
||||
{
|
||||
mMode = SFI_STATE_ERROR;
|
||||
}
|
||||
|
||||
Setup();
|
||||
}
|
||||
|
||||
|
||||
void SubFileItem::Setup()
|
||||
{
|
||||
connect( expandButton, SIGNAL( clicked( void ) ), this, SLOT( toggle ( void ) ) );
|
||||
connect( cancelButton, SIGNAL( clicked( void ) ), this, SLOT( cancel ( void ) ) );
|
||||
connect( playButton, SIGNAL( clicked( void ) ), this, SLOT( play ( void ) ) );
|
||||
connect( downloadButton, SIGNAL( clicked( void ) ), this, SLOT( download ( void ) ) );
|
||||
connect( cancelButton, SIGNAL( clicked( void ) ), this, SLOT( cancel ( void ) ) );
|
||||
connect( saveButton, SIGNAL( clicked( void ) ), this, SLOT( save ( void ) ) );
|
||||
|
||||
amountDone = 1000;
|
||||
/* once off check - if remote, check if we have it
|
||||
* NB: This check might be expensive - and it'll happen often!
|
||||
*/
|
||||
if (mMode == SFI_STATE_REMOTE)
|
||||
{
|
||||
FileInfo fi;
|
||||
uint32_t hintflags = RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_LOCAL
|
||||
| RS_FILE_HINTS_SPEC_ONLY;
|
||||
|
||||
/* look up path */
|
||||
if (rsFiles->FileDetails(mFileHash, hintflags, fi))
|
||||
{
|
||||
mMode = SFI_STATE_LOCAL;
|
||||
mPath = fi.path;
|
||||
}
|
||||
}
|
||||
|
||||
small();
|
||||
updateItemStatic();
|
||||
updateItem();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool SubFileItem::done()
|
||||
{
|
||||
return (mMode >= SFI_STATE_LOCAL);
|
||||
}
|
||||
|
||||
bool SubFileItem::ready()
|
||||
{
|
||||
return (mMode >= SFI_STATE_REMOTE);
|
||||
}
|
||||
|
||||
void SubFileItem::updateItemStatic()
|
||||
@ -52,34 +155,162 @@ void SubFileItem::updateItemStatic()
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
QString filename = "Biggest_File.txt";
|
||||
fileLabel->setText(filename);
|
||||
fileLabel->setToolTip(filename);
|
||||
|
||||
playButton->setEnabled(false);
|
||||
QString filename = QString::fromStdString(mFileName);
|
||||
mDivisor = 1;
|
||||
|
||||
if (mFileSize > 10000000) /* 10 Mb */
|
||||
{
|
||||
progressBar->setRange(0, mFileSize / 1000000);
|
||||
progressBar->setFormat("%v MB");
|
||||
mDivisor = 1000000;
|
||||
}
|
||||
else if (mFileSize > 10000) /* 10 Kb */
|
||||
{
|
||||
progressBar->setRange(0, mFileSize / 1000);
|
||||
progressBar->setFormat("%v kB");
|
||||
mDivisor = 1000;
|
||||
}
|
||||
else
|
||||
{
|
||||
progressBar->setRange(0, mFileSize);
|
||||
progressBar->setFormat("%v B");
|
||||
mDivisor = 1;
|
||||
}
|
||||
}
|
||||
|
||||
bool SubFileItem::done()
|
||||
{
|
||||
return (amountDone >= mFileSize);
|
||||
}
|
||||
/* get full path for local file */
|
||||
// TMP DISABLED FOR DEMONSTRATOR.... XXX
|
||||
#if 0
|
||||
if ((mMode == SFI_STATE_LOCAL) || (mMode == SFI_STATE_UPLOAD))
|
||||
{
|
||||
if (mPath == "")
|
||||
{
|
||||
FileInfo fi;
|
||||
uint32_t hintflags = RS_FILE_HINTS_UPLOAD | RS_FILE_HINTS_LOCAL
|
||||
| RS_FILE_HINTS_SPEC_ONLY;
|
||||
|
||||
/* look up path */
|
||||
if (!rsFiles->FileDetails(mFileHash, hintflags, fi))
|
||||
{
|
||||
mMode = SFI_STATE_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
// XXX CHECK VALID PATH!
|
||||
mPath = fi.path;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* do buttons + display */
|
||||
switch (mMode)
|
||||
{
|
||||
case SFI_STATE_ERROR:
|
||||
progressBar->setRange(0, 100);
|
||||
progressBar->setFormat("ERROR");
|
||||
|
||||
playButton->setEnabled(false);
|
||||
downloadButton->setEnabled(false);
|
||||
cancelButton->setEnabled(false);
|
||||
expandButton->setEnabled(false);
|
||||
|
||||
progressBar->setValue(0);
|
||||
filename = "[ERROR] " + filename;
|
||||
|
||||
break;
|
||||
|
||||
case SFI_STATE_EXTRA:
|
||||
filename = QString::fromStdString(mPath);
|
||||
|
||||
progressBar->setRange(0, 100);
|
||||
progressBar->setFormat("HASHING");
|
||||
|
||||
playButton->setEnabled(false);
|
||||
downloadButton->setEnabled(false);
|
||||
cancelButton->setEnabled(false);
|
||||
expandButton->setEnabled(false);
|
||||
|
||||
progressBar->setValue(0);
|
||||
filename = "[EXTRA] " + filename;
|
||||
|
||||
break;
|
||||
|
||||
case SFI_STATE_REMOTE:
|
||||
playButton->setEnabled(false);
|
||||
downloadButton->setEnabled(true);
|
||||
cancelButton->setEnabled(false);
|
||||
expandButton->setEnabled(false);
|
||||
|
||||
progressBar->setValue(0);
|
||||
filename = "[REMOTE] " + filename;
|
||||
|
||||
break;
|
||||
|
||||
case SFI_STATE_DOWNLOAD:
|
||||
playButton->setEnabled(false);
|
||||
downloadButton->setEnabled(false);
|
||||
cancelButton->setEnabled(true);
|
||||
expandButton->setEnabled(true);
|
||||
filename = "[DOWNLOAD] " + filename;
|
||||
|
||||
break;
|
||||
|
||||
case SFI_STATE_LOCAL:
|
||||
playButton->setEnabled(true);
|
||||
downloadButton->setEnabled(false);
|
||||
cancelButton->setEnabled(false);
|
||||
expandButton->setEnabled(false);
|
||||
|
||||
progressBar->setValue(mFileSize / mDivisor);
|
||||
filename = "[LOCAL] " + filename;
|
||||
|
||||
break;
|
||||
|
||||
case SFI_STATE_UPLOAD:
|
||||
playButton->setEnabled(true);
|
||||
downloadButton->setEnabled(false);
|
||||
cancelButton->setEnabled(false);
|
||||
expandButton->setEnabled(true);
|
||||
filename = "[UPLOAD] " + filename;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
saveButton->hide();
|
||||
|
||||
switch(mType)
|
||||
{
|
||||
case SFI_TYPE_CHANNEL:
|
||||
{
|
||||
saveButton->show();
|
||||
if (mMode == SFI_STATE_LOCAL)
|
||||
{
|
||||
saveButton->setEnabled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
saveButton->setEnabled(false);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SFI_TYPE_ATTACH:
|
||||
{
|
||||
playButton->hide();
|
||||
downloadButton->hide();
|
||||
cancelButton->setEnabled(true);
|
||||
cancelButton->setToolTip("Remove Attachment");
|
||||
expandButton->hide();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
fileLabel->setText(filename);
|
||||
fileLabel->setToolTip(filename);
|
||||
|
||||
}
|
||||
|
||||
void SubFileItem::updateItem()
|
||||
{
|
||||
@ -88,36 +319,148 @@ void SubFileItem::updateItem()
|
||||
std::cerr << "SubFileItem::updateItem()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
/* Extract File Details */
|
||||
/* Update State if necessary */
|
||||
|
||||
FileInfo fi;
|
||||
bool stateChanged = false;
|
||||
int msec_rate = 1000;
|
||||
|
||||
uint64_t divisor = 1;
|
||||
if (mFileSize > 10000000) /* 10 Mb */
|
||||
if ((mMode == SFI_STATE_ERROR) || (mMode == SFI_STATE_LOCAL))
|
||||
{
|
||||
divisor = 1000000;
|
||||
/* ignore - dead file, or done */
|
||||
}
|
||||
else if (mFileSize > 10000) /* 10 Kb */
|
||||
else if (mMode == SFI_STATE_EXTRA)
|
||||
{
|
||||
divisor = 1000;
|
||||
}
|
||||
/* check for file status */
|
||||
if (rsFiles->ExtraFileStatus(mPath, fi))
|
||||
{
|
||||
mMode = SFI_STATE_LOCAL;
|
||||
|
||||
if (amountDone < mFileSize)
|
||||
{
|
||||
amountDone *= 1.1;
|
||||
/* fill in file details */
|
||||
mFileName = fi.fname;
|
||||
mFileSize = fi.size;
|
||||
mFileHash = fi.hash;
|
||||
|
||||
progressBar->setValue(amountDone / divisor);
|
||||
QTimer::singleShot( msec_rate, this, SLOT(updateItem( void ) ));
|
||||
/* have path already! */
|
||||
|
||||
stateChanged = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* complete! */
|
||||
amountDone = mFileSize + 1;
|
||||
progressBar->setValue(mFileSize / divisor);
|
||||
playButton->setEnabled(true);
|
||||
uint32_t hintflags = 0;
|
||||
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:
|
||||
/* is it downloading? */
|
||||
if (detailsOk)
|
||||
{
|
||||
/* downloading */
|
||||
mMode = SFI_STATE_DOWNLOAD;
|
||||
stateChanged = true;
|
||||
}
|
||||
break;
|
||||
case SFI_STATE_DOWNLOAD:
|
||||
|
||||
if (!detailsOk)
|
||||
{
|
||||
mMode = SFI_STATE_REMOTE;
|
||||
stateChanged = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* has it completed? */
|
||||
if (fi.avail == mFileSize)
|
||||
{
|
||||
/* save path */
|
||||
/* update progress */
|
||||
mMode = SFI_STATE_LOCAL;
|
||||
mPath = fi.path;
|
||||
stateChanged = true;
|
||||
}
|
||||
progressBar->setValue(fi.avail / mDivisor);
|
||||
}
|
||||
break;
|
||||
case SFI_STATE_UPLOAD:
|
||||
|
||||
if (detailsOk)
|
||||
{
|
||||
progressBar->setValue(fi.avail / mDivisor);
|
||||
}
|
||||
|
||||
/* update progress */
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/****** update based on new state ******/
|
||||
if (stateChanged)
|
||||
{
|
||||
updateItemStatic();
|
||||
}
|
||||
|
||||
uint32_t repeat = 0;
|
||||
switch (mMode)
|
||||
{
|
||||
case SFI_STATE_ERROR:
|
||||
repeat = 0;
|
||||
break;
|
||||
|
||||
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;
|
||||
break;
|
||||
|
||||
case SFI_STATE_UPLOAD:
|
||||
repeat = 1;
|
||||
msec_rate = 2000; /* should be download rate dependent */
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (repeat)
|
||||
{
|
||||
QTimer::singleShot( msec_rate, this, SLOT(updateItem( void ) ));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void SubFileItem::small()
|
||||
{
|
||||
#ifdef DEBUG_ITEM
|
||||
@ -150,6 +493,15 @@ void SubFileItem::cancel()
|
||||
std::cerr << "SubFileItem::cancel()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
/* Only occurs - if it is downloading */
|
||||
if (mType == SFI_TYPE_ATTACH)
|
||||
{
|
||||
hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
rsFiles->FileCancel(mFileHash);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -158,6 +510,40 @@ void SubFileItem::play()
|
||||
#ifdef DEBUG_ITEM
|
||||
std::cerr << "SubFileItem::play()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
/* Only occurs - if it is local / uploading (have mPath set) */
|
||||
rsFiles->FileCancel(mFileHash);
|
||||
}
|
||||
|
||||
void SubFileItem::download()
|
||||
{
|
||||
#ifdef DEBUG_ITEM
|
||||
std::cerr << "SubFileItem::download()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
if (mType == SFI_TYPE_CHANNEL)
|
||||
{
|
||||
/* send request via rsChannels -> as it knows how to do it properly */
|
||||
//std::string grpId = mSrcId;
|
||||
//rsChannels->FileRequest(mFileName, mFileHash, mFileSize, grpId);
|
||||
}
|
||||
else
|
||||
{
|
||||
//rsFile->FileRequest(mFileName, mFileHash, mFileSize, "", 0, mSrcId);
|
||||
}
|
||||
|
||||
// TEMP
|
||||
rsFiles->FileRequest(mFileName, mFileHash, mFileSize, "", 0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SubFileItem::save()
|
||||
{
|
||||
#ifdef DEBUG_ITEM
|
||||
std::cerr << "SubFileItem::save()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -26,37 +26,70 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
const uint32_t SFI_MASK_STATE = 0x000f;
|
||||
const uint32_t SFI_MASK_TYPE = 0x00f0;
|
||||
const uint32_t SFI_MASK_FT = 0x0f00;
|
||||
|
||||
const uint32_t SFI_STATE_ERROR = 0x0001;
|
||||
const uint32_t SFI_STATE_EXTRA = 0x0002;
|
||||
const uint32_t SFI_STATE_REMOTE = 0x0003;
|
||||
const uint32_t SFI_STATE_DOWNLOAD = 0x0004;
|
||||
const uint32_t SFI_STATE_LOCAL = 0x0005;
|
||||
const uint32_t SFI_STATE_UPLOAD = 0x0006;
|
||||
|
||||
const uint32_t SFI_TYPE_CHANNEL = 0x0010;
|
||||
const uint32_t SFI_TYPE_ATTACH = 0x0020;
|
||||
|
||||
class SubFileItem : public QWidget, private Ui::SubFileItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/** Default Constructor */
|
||||
SubFileItem(std::string hash, std::string name, uint64_t size);
|
||||
SubFileItem(std::string localpath);
|
||||
SubFileItem(std::string hash, std::string name, uint64_t size,
|
||||
uint32_t flags, std::string srcId);
|
||||
|
||||
/** Default Destructor */
|
||||
|
||||
void small();
|
||||
bool done();
|
||||
|
||||
std::string FileHash() { return mFileHash; }
|
||||
std::string FileName() { return mFileName; }
|
||||
uint64_t FileSize() { return mFileSize; }
|
||||
std::string FilePath() { return mPath; }
|
||||
|
||||
void updateItemStatic();
|
||||
void updateItemStatic();
|
||||
|
||||
bool done();
|
||||
bool ready();
|
||||
|
||||
public slots:
|
||||
void download();
|
||||
|
||||
private slots:
|
||||
/* default stuff */
|
||||
void toggle();
|
||||
|
||||
void cancel();
|
||||
void play();
|
||||
void toggle();
|
||||
void save();
|
||||
|
||||
void updateItem();
|
||||
|
||||
private:
|
||||
|
||||
void Setup();
|
||||
|
||||
|
||||
std::string mPath;
|
||||
std::string mFileHash;
|
||||
std::string mFileName;
|
||||
uint64_t mFileSize;
|
||||
std::string mSrcId;
|
||||
|
||||
uint32_t mMode;
|
||||
uint32_t mType;
|
||||
uint64_t mDivisor;
|
||||
|
||||
/* for display purposes */
|
||||
float amountDone;
|
||||
|
@ -144,25 +144,6 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="cancelButton" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip" >
|
||||
<string>Delete FeedItem</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon" >
|
||||
<iconset resource="images.qrc" >:/images/close-down.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="expandButton" >
|
||||
<property name="sizePolicy" >
|
||||
@ -182,6 +163,63 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="saveButton" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip" >
|
||||
<string>Save File</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon" >
|
||||
<iconset resource="images.qrc" >:/images/save24.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="cancelButton" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip" >
|
||||
<string>Cancel Download</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon" >
|
||||
<iconset resource="images.qrc" >:/images/delete.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="downloadButton" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip" >
|
||||
<string>Download File</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon" >
|
||||
<iconset resource="images.qrc" >:/images/download.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="playButton" >
|
||||
<property name="sizePolicy" >
|
||||
@ -191,7 +229,7 @@
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip" >
|
||||
<string>Delete FeedItem</string>
|
||||
<string>Play File</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string/>
|
||||
|
@ -49,6 +49,23 @@ const uint32_t RS_FILE_CTRL_STREAM_AUDIO = 0x0005;
|
||||
const uint32_t RS_FILE_CTRL_STREAM_VIDEO = 0x0006;
|
||||
|
||||
|
||||
/************************************
|
||||
* Used To indicate where to search.
|
||||
*/
|
||||
|
||||
const uint32_t RS_FILE_HINTS_MASK = 0x00ff;
|
||||
|
||||
const uint32_t RS_FILE_HINTS_CACHE = 0x0001;
|
||||
const uint32_t RS_FILE_HINTS_EXTRA = 0x0002;
|
||||
const uint32_t RS_FILE_HINTS_LOCAL = 0x0004;
|
||||
const uint32_t RS_FILE_HINTS_REMOTE = 0x0008;
|
||||
const uint32_t RS_FILE_HINTS_DOWNLOAD = 0x0010;
|
||||
const uint32_t RS_FILE_HINTS_UPLOAD = 0x0020;
|
||||
|
||||
const uint32_t RS_FILE_HINTS_SPEC_ONLY = 0x1000;
|
||||
|
||||
|
||||
|
||||
const uint32_t RS_FILE_EXTRA_DELETE = 0x0010;
|
||||
|
||||
|
||||
|
@ -83,6 +83,20 @@ static const int kRsFiStatusDone = 2;
|
||||
double tfRate; /* kbytes */
|
||||
bool download;
|
||||
int downloadStatus; /* 0 = Err, 1 = Ok, 2 = Done */
|
||||
|
||||
/* ENTRIES USED BY SFI ***
|
||||
*
|
||||
* path,
|
||||
* fname,
|
||||
* hash,
|
||||
* size,
|
||||
* avail,
|
||||
*
|
||||
* source?
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
};
|
||||
|
||||
class FileTransferInfo: public FileInfo
|
||||
|
Loading…
Reference in New Issue
Block a user