mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-09 03:18:41 -05:00
- fixed copy/paste of RS links in public and private chat
- cleaned the code for anchorClick() in private chat - added return false for FileRequest of already have files - suppressed sources when the file is complete, in TransfersDialog. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5.0@2574 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
e9c7570009
commit
8305fe0bf7
@ -930,6 +930,11 @@ bool ftController::FileRequest(std::string fname, std::string hash,
|
||||
uint64_t size, std::string dest, uint32_t flags,
|
||||
std::list<std::string> &srcIds)
|
||||
{
|
||||
/* check if we have the file */
|
||||
|
||||
if(alreadyHaveFile(hash))
|
||||
return false ;
|
||||
|
||||
if(size == 0) // we treat this special case because
|
||||
{
|
||||
/* if no destpath - send to download directory */
|
||||
@ -968,11 +973,6 @@ bool ftController::FileRequest(std::string fname, std::string hash,
|
||||
}
|
||||
}
|
||||
|
||||
/* check if we have the file */
|
||||
|
||||
if(alreadyHaveFile(hash))
|
||||
return true ;
|
||||
|
||||
FileInfo info;
|
||||
std::list<std::string>::iterator it;
|
||||
std::list<TransferInfo>::iterator pit;
|
||||
|
@ -142,8 +142,12 @@ PeersDialog::PeersDialog(QWidget *parent)
|
||||
connect(ui.Sendbtn, SIGNAL(clicked()), this, SLOT(sendMsg()));
|
||||
connect(ui.emoticonBtn, SIGNAL(clicked()), this, SLOT(smileyWidgetgroupchat()));
|
||||
|
||||
ui.lineEdit->setContextMenuPolicy(Qt::CustomContextMenu) ;
|
||||
connect(ui.lineEdit,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(contextMenu(QPoint)));
|
||||
|
||||
pasteLinkAct = new QAction(QIcon(":/images/pasterslink.png"), tr( "Paste retroshare Link" ), this );
|
||||
connect( pasteLinkAct , SIGNAL( triggered() ), this, SLOT( pasteLink() ) );
|
||||
|
||||
//connect( ui.msgSendList, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( msgSendListCostumPopupMenu( QPoint ) ) );
|
||||
connect( ui.msgText, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayInfoChatMenu(const QPoint&)));
|
||||
|
||||
connect(ui.textboldChatButton, SIGNAL(clicked()), this, SLOT(setFont()));
|
||||
@ -211,6 +215,23 @@ PeersDialog::PeersDialog(QWidget *parent)
|
||||
#endif
|
||||
}
|
||||
|
||||
void PeersDialog::pasteLink()
|
||||
{
|
||||
ui.lineEdit->insertHtml(RSLinkClipboard::toHtml()) ;
|
||||
}
|
||||
|
||||
void PeersDialog::contextMenu( QPoint point )
|
||||
{
|
||||
if(RSLinkClipboard::empty())
|
||||
return ;
|
||||
|
||||
QMenu contextMnu(this);
|
||||
contextMnu.addAction( pasteLinkAct);
|
||||
|
||||
QMouseEvent mevent(QEvent::MouseButtonPress, point, Qt::RightButton, Qt::RightButton, Qt::NoModifier);
|
||||
contextMnu.exec( mevent.globalPos() );
|
||||
}
|
||||
|
||||
void PeersDialog::peertreeWidgetCostumPopupMenu( QPoint point )
|
||||
{
|
||||
QTreeWidgetItem *c = getCurrentPeer();
|
||||
@ -300,8 +321,6 @@ void PeersDialog::peertreeWidgetCostumPopupMenu( QPoint point )
|
||||
contextMnu.addAction( expandAll);
|
||||
contextMnu.addAction( collapseAll);
|
||||
contextMnu.exec( mevent->globalPos() );
|
||||
|
||||
|
||||
}
|
||||
|
||||
void PeersDialog::keyPressEvent(QKeyEvent *e)
|
||||
@ -1600,11 +1619,15 @@ void PeersDialog::fileHashingFinished(AttachFileItem* file) {
|
||||
sprintf(fileSizeChar, "%lld", file->FileSize());
|
||||
std::string fileSize = *(&fileSizeChar);
|
||||
|
||||
std::string mesgString = "<a href='retroshare://file|" + (file->FileName()) + "|" + fileSize + "|" + (file->FileHash()) + "'>"
|
||||
+ "retroshare://file|" + (file->FileName()) + "|" + fileSize + "|" + (file->FileHash()) + "</a>";
|
||||
#ifdef PEERS_DEBUG
|
||||
std::cerr << "PeersDialog::fileHashingFinished mesgString : " << mesgString << std::endl;
|
||||
#endif
|
||||
std::string mesgString = RetroShareLink(QString::fromStdString(file->FileName()),
|
||||
file->FileSize(),
|
||||
QString::fromStdString(file->FileHash())).toHtml().toStdString() ;
|
||||
|
||||
// std::string mesgString = "<a href='retroshare://file|" + (file->FileName()) + "|" + fileSize + "|" + (file->FileHash()) + "'>"
|
||||
// + "retroshare://file|" + (file->FileName()) + "|" + fileSize + "|" + (file->FileHash()) + "</a>";
|
||||
#ifdef PEERS_DEBUG
|
||||
std::cerr << "PeersDialog::fileHashingFinished mesgString : " << mesgString << std::endl;
|
||||
#endif
|
||||
|
||||
const char * messageString = mesgString.c_str ();
|
||||
|
||||
|
@ -86,6 +86,8 @@ protected:
|
||||
virtual void dropEvent(QDropEvent *event);
|
||||
|
||||
private slots:
|
||||
void pasteLink() ;
|
||||
void contextMenu(QPoint) ;
|
||||
|
||||
/** Create the context popup menu and it's submenus */
|
||||
void peertreeWidgetCostumPopupMenu( QPoint point );
|
||||
@ -157,6 +159,7 @@ private:
|
||||
QMenu* contextMnu;
|
||||
/** Defines the actions for the context menu */
|
||||
QAction* chatAct;
|
||||
QAction* pasteLinkAct;
|
||||
QAction* msgAct;
|
||||
QAction* connectfriendAct;
|
||||
QAction* profileviewAct;
|
||||
|
@ -98,7 +98,7 @@ QString RetroShareLink::toString() const
|
||||
}
|
||||
QString RetroShareLink::toHtml() const
|
||||
{
|
||||
return QString("<a href='") + toString() + "'>" + toString() + "</a>" ;
|
||||
return QString("<a href='") + toString() + "'>" + name() + "</a>" ;
|
||||
}
|
||||
|
||||
bool RetroShareLink::checkName(const QString& name)
|
||||
|
@ -739,48 +739,49 @@ void TransfersDialog::insertTransfers()
|
||||
|
||||
std::set<int> used_rows ;
|
||||
|
||||
for (pit = info.peers.begin(); pit != info.peers.end(); pit++)
|
||||
{
|
||||
QString peerName = getPeerName(pit->peerId);
|
||||
//unique combination: fileHash + peerId, variant: hash + peerName (too long)
|
||||
QString hashFileAndPeerId = fileHash + QString::fromStdString(pit->peerId);
|
||||
QString version;
|
||||
if (retv && versions.end() != (vit = versions.find(pit->peerId))) {
|
||||
version = tr("version: ") + QString::fromStdString(vit->second);
|
||||
if(info.downloadStatus != FT_STATE_COMPLETE)
|
||||
for (pit = info.peers.begin(); pit != info.peers.end(); pit++)
|
||||
{
|
||||
QString peerName = getPeerName(pit->peerId);
|
||||
//unique combination: fileHash + peerId, variant: hash + peerName (too long)
|
||||
QString hashFileAndPeerId = fileHash + QString::fromStdString(pit->peerId);
|
||||
QString version;
|
||||
if (retv && versions.end() != (vit = versions.find(pit->peerId))) {
|
||||
version = tr("version: ") + QString::fromStdString(vit->second);
|
||||
}
|
||||
|
||||
QString status;
|
||||
switch (pit->status) {
|
||||
case FT_STATE_FAILED: status = tr("Failed"); break;
|
||||
case FT_STATE_OKAY: status = tr("Okay"); break;
|
||||
case FT_STATE_WAITING: status = tr(""); break;
|
||||
case FT_STATE_DOWNLOADING: status = tr("Downloading"); break;
|
||||
case FT_STATE_COMPLETE: status = tr("Complete"); break;
|
||||
default: status = tr(""); break;
|
||||
}
|
||||
double peerDlspeed = 0;
|
||||
if ((uint32_t)pit->status == FT_STATE_DOWNLOADING && info.downloadStatus != FT_STATE_PAUSED && info.downloadStatus != FT_STATE_COMPLETE)
|
||||
peerDlspeed = pit->tfRate * 1024.0;
|
||||
|
||||
FileProgressInfo peerpinfo ;
|
||||
peerpinfo.cmap = fcinfo.compressed_peer_availability_maps[pit->peerId];
|
||||
peerpinfo.type = FileProgressInfo::DOWNLOAD_SOURCE ;
|
||||
peerpinfo.progress = 0.0 ; // we don't display completion for sources.
|
||||
peerpinfo.nb_chunks = peerpinfo.cmap._map.empty()?0:fcinfo.chunks.size();
|
||||
|
||||
// std::cerr << std::endl ;
|
||||
// std::cerr << "Source " << pit->peerId << " as map " << peerpinfo.cmap._map.size() << " compressed chunks" << std::endl ;
|
||||
// for(uint j=0;j<peerpinfo.cmap._map.size();++j)
|
||||
// std::cerr << peerpinfo.cmap._map[j] ;
|
||||
// std::cerr << std::endl ;
|
||||
// std::cerr << std::endl ;
|
||||
|
||||
std::cout << "adding peer " << peerName.toStdString() << " to row " << addedRow << ", hashfile and peerid=" << hashFileAndPeerId.toStdString() << std::endl ;
|
||||
int row_id = addPeerToItem(addedRow, peerName, hashFileAndPeerId, peerDlspeed, status, peerpinfo);
|
||||
|
||||
used_rows.insert(row_id) ;
|
||||
}
|
||||
|
||||
QString status;
|
||||
switch (pit->status) {
|
||||
case FT_STATE_FAILED: status = tr("Failed"); break;
|
||||
case FT_STATE_OKAY: status = tr("Okay"); break;
|
||||
case FT_STATE_WAITING: status = tr(""); break;
|
||||
case FT_STATE_DOWNLOADING: status = tr("Downloading"); break;
|
||||
case FT_STATE_COMPLETE: status = tr("Complete"); break;
|
||||
default: status = tr(""); break;
|
||||
}
|
||||
double peerDlspeed = 0;
|
||||
if ((uint32_t)pit->status == FT_STATE_DOWNLOADING && info.downloadStatus != FT_STATE_PAUSED)
|
||||
peerDlspeed = pit->tfRate * 1024.0;
|
||||
|
||||
FileProgressInfo peerpinfo ;
|
||||
peerpinfo.cmap = fcinfo.compressed_peer_availability_maps[pit->peerId];
|
||||
peerpinfo.type = FileProgressInfo::DOWNLOAD_SOURCE ;
|
||||
peerpinfo.progress = 0.0 ; // we don't display completion for sources.
|
||||
peerpinfo.nb_chunks = peerpinfo.cmap._map.empty()?0:fcinfo.chunks.size();
|
||||
|
||||
// std::cerr << std::endl ;
|
||||
// std::cerr << "Source " << pit->peerId << " as map " << peerpinfo.cmap._map.size() << " compressed chunks" << std::endl ;
|
||||
// for(uint j=0;j<peerpinfo.cmap._map.size();++j)
|
||||
// std::cerr << peerpinfo.cmap._map[j] ;
|
||||
// std::cerr << std::endl ;
|
||||
// std::cerr << std::endl ;
|
||||
|
||||
std::cout << "adding peer " << peerName.toStdString() << " to row " << addedRow << ", hashfile and peerid=" << hashFileAndPeerId.toStdString() << std::endl ;
|
||||
int row_id = addPeerToItem(addedRow, peerName, hashFileAndPeerId, peerDlspeed, status, peerpinfo);
|
||||
|
||||
used_rows.insert(row_id) ;
|
||||
}
|
||||
|
||||
QStandardItem *dlItem = DLListModel->item(addedRow);
|
||||
|
||||
// This is not optimal, but we deal with a small number of elements. The reverse order is really important,
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "PopupChatDialog.h"
|
||||
#include <gui/RetroShareLink.h>
|
||||
|
||||
#include <QTextCodec>
|
||||
#include <QTextEdit>
|
||||
@ -53,6 +54,7 @@
|
||||
/*****
|
||||
* #define CHAT_DEBUG 1
|
||||
*****/
|
||||
#define CHAT_DEBUG 1
|
||||
|
||||
/** Default constructor */
|
||||
PopupChatDialog::PopupChatDialog(std::string id, std::string name,
|
||||
@ -96,6 +98,10 @@ PopupChatDialog::PopupChatDialog(std::string id, std::string name,
|
||||
|
||||
connect(ui.textBrowser, SIGNAL(anchorClicked(const QUrl &)), SLOT(anchorClicked(const QUrl &)));
|
||||
|
||||
std::cerr << "Connecting custom context menu" << std::endl;
|
||||
ui.chattextEdit->setContextMenuPolicy(Qt::CustomContextMenu) ;
|
||||
connect(ui.chattextEdit,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(contextMenu(QPoint)));
|
||||
|
||||
// Create the status bar
|
||||
resetStatusBar() ;
|
||||
|
||||
@ -136,10 +142,32 @@ PopupChatDialog::PopupChatDialog(std::string id, std::string name,
|
||||
colorChanged(mCurrentColor);
|
||||
setFont();
|
||||
|
||||
pasteLinkAct = new QAction(QIcon(":/images/pasterslink.png"), tr( "Paste retroshare Link" ), this );
|
||||
connect( pasteLinkAct , SIGNAL( triggered() ), this, SLOT( pasteLink() ) );
|
||||
|
||||
updateAvatar() ;
|
||||
updatePeerAvatar(id) ;
|
||||
}
|
||||
|
||||
void PopupChatDialog::pasteLink()
|
||||
{
|
||||
std::cerr << "In paste link" << std::endl ;
|
||||
ui.chattextEdit->insertHtml(RSLinkClipboard::toHtml()) ;
|
||||
}
|
||||
|
||||
void PopupChatDialog::contextMenu( QPoint point )
|
||||
{
|
||||
std::cerr << "In context menu" << std::endl ;
|
||||
if(RSLinkClipboard::empty())
|
||||
return ;
|
||||
|
||||
QMenu contextMnu(this);
|
||||
contextMnu.addAction( pasteLinkAct);
|
||||
|
||||
QMouseEvent mevent(QEvent::MouseButtonPress, point, Qt::RightButton, Qt::RightButton, Qt::NoModifier);
|
||||
contextMnu.exec( mevent.globalPos() );
|
||||
}
|
||||
|
||||
void PopupChatDialog::resetStatusBar()
|
||||
{
|
||||
statusBar()->showMessage(tr("Chatting with ") + QString::fromStdString(dialogName)) ;
|
||||
@ -732,7 +760,8 @@ void PopupChatDialog::addExtraFile()
|
||||
}
|
||||
}
|
||||
|
||||
void PopupChatDialog::addAttachment(std::string filePath) {
|
||||
void PopupChatDialog::addAttachment(std::string filePath)
|
||||
{
|
||||
/* add a AttachFileItem to the attachment section */
|
||||
std::cerr << "PopupChatDialog::addExtraFile() hashing file.";
|
||||
std::cerr << std::endl;
|
||||
@ -751,7 +780,8 @@ void PopupChatDialog::addAttachment(std::string filePath) {
|
||||
}
|
||||
}
|
||||
|
||||
void PopupChatDialog::fileHashingFinished(AttachFileItem* file) {
|
||||
void PopupChatDialog::fileHashingFinished(AttachFileItem* file)
|
||||
{
|
||||
std::cerr << "PopupChatDialog::fileHashingFinished() started.";
|
||||
std::cerr << std::endl;
|
||||
|
||||
@ -781,7 +811,10 @@ void PopupChatDialog::fileHashingFinished(AttachFileItem* file) {
|
||||
sprintf(fileSizeChar, "%lld", file->FileSize());
|
||||
std::string fileSize = *(&fileSizeChar);
|
||||
|
||||
std::string mesgString = "<a href='file:?fileHash=" + (file->FileHash()) + "&fileName=" + (file->FileName()) + "&fileSize=" + fileSize + "'>" + (file->FileName()) + "</a>";
|
||||
// std::string mesgString = "<a href='file:?fileHash=" + (file->FileHash()) + "&fileName=" + (file->FileName()) + "&fileSize=" + fileSize + "'>" + (file->FileName()) + "</a>";
|
||||
|
||||
std::string mesgString = RetroShareLink(QString::fromStdString(file->FileName()),file->FileSize(),QString::fromStdString(file->FileHash())).toHtml().toStdString() ;
|
||||
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "PopupChatDialog::anchorClicked mesgString : " << mesgString << std::endl;
|
||||
#endif
|
||||
@ -813,44 +846,38 @@ void PopupChatDialog::fileHashingFinished(AttachFileItem* file) {
|
||||
rsMsgs -> ChatSend(ci);
|
||||
}
|
||||
|
||||
void PopupChatDialog::anchorClicked (const QUrl& link ) {
|
||||
void PopupChatDialog::anchorClicked (const QUrl& link )
|
||||
{
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "PopupChatDialog::anchorClicked link.scheme() : " << link.scheme().toStdString() << std::endl;
|
||||
#endif
|
||||
if (link.scheme() == "file") {
|
||||
std::string fileName = link.queryItemValue(QString("fileName")).toStdString();
|
||||
std::string fileHash = link.queryItemValue(QString("fileHash")).toStdString();
|
||||
uint32_t fileSize = link.queryItemValue(QString("fileSize")).toInt();
|
||||
#ifdef CHAT_DEBUG
|
||||
std::cerr << "PopupChatDialog::anchorClicked FileRequest : fileName : " << fileName << ". fileHash : " << fileHash << ". fileSize : " << fileSize;
|
||||
std::cerr << ". source id : " << dialogId << std::endl;
|
||||
#endif
|
||||
if (fileName != "" &&
|
||||
fileHash != "") {
|
||||
std::list<std::string> srcIds;
|
||||
srcIds.push_front(dialogId);
|
||||
|
||||
if(rsFiles->FileRequest(fileName, fileHash, fileSize, "", RS_FILE_HINTS_NETWORK_WIDE, srcIds))
|
||||
{
|
||||
QMessageBox mb(tr("File Request Confirmation"), tr("The file has been added to your download list."),QMessageBox::Information,QMessageBox::Ok,0,0);
|
||||
mb.setButtonText( QMessageBox::Ok, "OK" );
|
||||
mb.exec();
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox mb(tr("File Request canceled"), tr("The file has not been added to your download list, because you already have it, or you're already downloading it."),QMessageBox::Information,QMessageBox::Ok,0,0);
|
||||
mb.setButtonText( QMessageBox::Ok, "OK" );
|
||||
mb.exec();
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
if(link.scheme() == "retroshare")
|
||||
{
|
||||
RetroShareLink rslink(link) ;
|
||||
|
||||
if(!rslink.valid())
|
||||
{
|
||||
QMessageBox mb(tr("File Request Error"), tr("The file link is malformed."),QMessageBox::Information,QMessageBox::Ok,0,0);
|
||||
QMessageBox mb(tr("Badly formed RS link"), tr("This RetroShare link is malformed. This is bug. Please contact the developers."),QMessageBox::Information,QMessageBox::Ok,0,0);
|
||||
mb.setButtonText( QMessageBox::Ok, "OK" );
|
||||
mb.exec();
|
||||
return ;
|
||||
}
|
||||
|
||||
if(rsFiles->FileRequest(rslink.name().toStdString(), rslink.hash().toStdString(), rslink.size(), "", RS_FILE_HINTS_NETWORK_WIDE, std::list<std::string>()))
|
||||
{
|
||||
QMessageBox mb(tr("File Request Confirmation"), tr("The file has been added to your download list."),QMessageBox::Information,QMessageBox::Ok,0,0);
|
||||
mb.setButtonText( QMessageBox::Ok, "OK" );
|
||||
mb.exec();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox mb(tr("File Request canceled"), tr("The file has not been added to your download list, because you already have it, or you're already downloading it."),QMessageBox::Information,QMessageBox::Ok,0,0);
|
||||
mb.setButtonText( QMessageBox::Ok, "OK" );
|
||||
mb.exec();
|
||||
}
|
||||
}
|
||||
else if (link.scheme() == "http")
|
||||
QDesktopServices::openUrl(link);
|
||||
else if (link.scheme() == "")
|
||||
@ -860,7 +887,6 @@ void PopupChatDialog::anchorClicked (const QUrl& link ) {
|
||||
newAddress.prepend("http://");
|
||||
QDesktopServices::openUrl(QUrl(newAddress));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PopupChatDialog::dropEvent(QDropEvent *event)
|
||||
|
@ -72,6 +72,8 @@ public slots:
|
||||
|
||||
void getfocus();
|
||||
void flash();
|
||||
void pasteLink() ;
|
||||
void contextMenu(QPoint) ;
|
||||
|
||||
void smileyWidget();
|
||||
void addSmiley();
|
||||
@ -115,6 +117,7 @@ private:
|
||||
QAction *actionTextBold;
|
||||
QAction *actionTextUnderline;
|
||||
QAction *actionTextItalic;
|
||||
QAction *pasteLinkAct ;
|
||||
|
||||
std::string dialogId, dialogName;
|
||||
unsigned int lastChatTime;
|
||||
|
Loading…
x
Reference in New Issue
Block a user