PeersDialog/MessengerWindow:

- send recommended friend as message
- paste recommended friends as "retroshare://person|..." from clipboard

reworked retroshare link handling
- added new type -> retroshare://person|<name>|<hash>
- added processing of links to RetroShareLink and RSLinkClipboard and removed all processing in anchorClicked of QTextBrowser 
- fixed parseClipboard to handle all found links in clipboard
- disabled the processing of the clickable links (RetroShareLink::processUrl), because QUrl can't handle the RetroShare links properly

removed memory leaks of the QAction in some context menus


git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3292 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2010-07-15 11:25:34 +00:00
parent 3291e61291
commit daf0ea50ee
21 changed files with 712 additions and 525 deletions

View File

@ -53,7 +53,7 @@ AddLinksDialog::AddLinksDialog(QString url, QWidget *parent)
RetroShareLink link(url);
if(link.valid())
if(link.valid() && link.type() == RetroShareLink::TYPE_FILE)
ui.titleLineEdit->setText(link.name());
else
ui.titleLineEdit->setText("New File");

View File

@ -271,18 +271,18 @@ void ForumsDialog::forumListCustomPopupMenu( QPoint point )
{
QMenu contextMnu( this );
QAction *subForumAct = new QAction(QIcon(IMAGE_SUBSCRIBE), tr( "Subscribe to Forum" ), this );
QAction *subForumAct = new QAction(QIcon(IMAGE_SUBSCRIBE), tr( "Subscribe to Forum" ), &contextMnu );
subForumAct->setDisabled (true);
connect( subForumAct , SIGNAL( triggered() ), this, SLOT( subscribeToForum() ) );
QAction *unsubForumAct = new QAction(QIcon(IMAGE_UNSUBSCRIBE), tr( "Unsubscribe to Forum" ), this );
QAction *unsubForumAct = new QAction(QIcon(IMAGE_UNSUBSCRIBE), tr( "Unsubscribe to Forum" ), &contextMnu );
unsubForumAct->setDisabled (true);
connect( unsubForumAct , SIGNAL( triggered() ), this, SLOT( unsubscribeToForum() ) );
QAction *newForumAct = new QAction(QIcon(IMAGE_NEWFORUM), tr( "New Forum" ), this );
QAction *newForumAct = new QAction(QIcon(IMAGE_NEWFORUM), tr( "New Forum" ), &contextMnu );
connect( newForumAct , SIGNAL( triggered() ), this, SLOT( newforum() ) );
QAction *detailsForumAct = new QAction(QIcon(IMAGE_INFO), tr( "Show Forum Details" ), this );
QAction *detailsForumAct = new QAction(QIcon(IMAGE_INFO), tr( "Show Forum Details" ), &contextMnu );
detailsForumAct->setDisabled (true);
connect( detailsForumAct , SIGNAL( triggered() ), this, SLOT( showForumDetails() ) );
@ -316,22 +316,22 @@ void ForumsDialog::threadListCustomPopupMenu( QPoint point )
{
QMenu contextMnu( this );
QAction *replyAct = new QAction(QIcon(IMAGE_MESSAGEREPLY), tr( "Reply" ), this );
QAction *replyAct = new QAction(QIcon(IMAGE_MESSAGEREPLY), tr( "Reply" ), &contextMnu );
replyAct->setDisabled (true);
connect( replyAct , SIGNAL( triggered() ), this, SLOT( createmessage() ) );
QAction *newthreadAct = new QAction(QIcon(IMAGE_DOWNLOADALL), tr( "Start New Thread" ), this );
QAction *newthreadAct = new QAction(QIcon(IMAGE_DOWNLOADALL), tr( "Start New Thread" ), &contextMnu );
newthreadAct->setDisabled (true);
connect( newthreadAct , SIGNAL( triggered() ), this, SLOT( showthread() ) );
QAction *replyauthorAct = new QAction(QIcon(IMAGE_MESSAGEREPLY), tr( "Reply to Author" ), this );
QAction *replyauthorAct = new QAction(QIcon(IMAGE_MESSAGEREPLY), tr( "Reply to Author" ), &contextMnu );
replyauthorAct->setDisabled (true);
connect( replyauthorAct , SIGNAL( triggered() ), this, SLOT( replytomessage() ) );
QAction* expandAll = new QAction(tr( "Expand all" ), this );
QAction* expandAll = new QAction(tr( "Expand all" ), &contextMnu );
connect( expandAll , SIGNAL( triggered() ), ui.threadTreeWidget, SLOT (expandAll()) );
QAction* collapseAll = new QAction(tr( "Collapse all" ), this );
QAction* collapseAll = new QAction(tr( "Collapse all" ), &contextMnu );
connect( collapseAll , SIGNAL( triggered() ), ui.threadTreeWidget, SLOT(collapseAll()) );
if (!mCurrForumId.empty ()) {
@ -1396,50 +1396,10 @@ void ForumsDialog::replytomessage()
void ForumsDialog::anchorClicked (const QUrl& link )
{
#ifdef FORUM_DEBUG
std::cerr << "ForumsDialog::anchorClicked link.scheme() : " << link.scheme().toStdString() << std::endl;
std::cerr << "ForumsDialog::anchorClicked link.scheme() : " << link.scheme().toStdString() << std::endl;
#endif
if (link.scheme() == "retroshare")
{
RetroShareLink rslnk(link.toString()) ;
if(rslnk.valid())
{
std::list<std::string> srcIds;
if(rsFiles->FileRequest(rslnk.name().toStdString(), rslnk.hash().toStdString(), rslnk.size(), "", 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.setWindowIcon(QIcon(QString::fromUtf8(":/images/rstray3.png")));
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."),QMessageBox::Information,QMessageBox::Ok,0,0);
mb.setButtonText( QMessageBox::Ok, "OK" );
mb.exec();
}
}
else
{
QMessageBox mb(tr("File Request Error"), tr("The file link is malformed."),QMessageBox::Information,QMessageBox::Ok,0,0);
mb.setButtonText( QMessageBox::Ok, "OK" );
mb.setWindowIcon(QIcon(QString::fromUtf8(":/images/rstray3.png")));
mb.exec();
}
}
else if (link.scheme() == "http")
{
QDesktopServices::openUrl(link);
}
else if (link.scheme() == "")
{
//it's probably a web adress, let's add http:// at the beginning of the link
QString newAddress = link.toString();
newAddress.prepend("http://");
QDesktopServices::openUrl(QUrl(newAddress));
}
RetroShareLink::processUrl(link, NULL, RSLINK_PROCESS_NOTIFY_ALL);
}
void ForumsDialog::filterRegExpChanged()

View File

@ -138,30 +138,30 @@ void LinksDialog::linkTreeWidgetCostumPopupMenu( QPoint point )
QMenu contextMnu( this );
voteupAct = new QAction(QIcon(IMAGE_EXPORTFRIEND), tr( "Share Link Anonymously" ), this );
QAction *voteupAct = new QAction(QIcon(IMAGE_EXPORTFRIEND), tr( "Share Link Anonymously" ), &contextMnu );
connect( voteupAct , SIGNAL( triggered() ), this, SLOT( voteup_anon() ) );
QMenu *voteMenu = new QMenu( tr("Vote on Link"), this );
QMenu *voteMenu = new QMenu( tr("Vote on Link"), &contextMnu );
voteMenu->setIcon(QIcon(IMAGE_EXPORTFRIEND));
QAction *vote_p2 = new QAction( QIcon(IMAGE_GREAT), "[+2] Great", this );
QAction *vote_p2 = new QAction( QIcon(IMAGE_GREAT), "[+2] Great", &contextMnu );
connect( vote_p2 , SIGNAL( triggered() ), this, SLOT( voteup_p2() ) );
voteMenu->addAction(vote_p2);
QAction *vote_p1 = new QAction( QIcon(IMAGE_GOOD), "[+1] Good", this );
QAction *vote_p1 = new QAction( QIcon(IMAGE_GOOD), "[+1] Good", &contextMnu );
connect( vote_p1 , SIGNAL( triggered() ), this, SLOT( voteup_p1() ) );
voteMenu->addAction(vote_p1);
QAction *vote_p0 = new QAction( QIcon(IMAGE_OK), "[+0] Okay", this );
QAction *vote_p0 = new QAction( QIcon(IMAGE_OK), "[+0] Okay", &contextMnu );
connect( vote_p0 , SIGNAL( triggered() ), this, SLOT( voteup_p0() ) );
voteMenu->addAction(vote_p0);
QAction *vote_m1 = new QAction( QIcon(IMAGE_SUX), "[-1] Sux", this );
QAction *vote_m1 = new QAction( QIcon(IMAGE_SUX), "[-1] Sux", &contextMnu );
connect( vote_m1 , SIGNAL( triggered() ), this, SLOT( voteup_m1() ) );
voteMenu->addAction(vote_m1);
QAction *vote_m2 = new QAction( QIcon(IMAGE_BADLINK), "[-2] BAD LINK", this );
QAction *vote_m2 = new QAction( QIcon(IMAGE_BADLINK), "[-2] BAD LINK", &contextMnu );
connect( vote_m2 , SIGNAL( triggered() ), this, SLOT( voteup_m2() ) );
voteMenu->addAction(vote_m2);
downloadAct = new QAction(QIcon(IMAGE_DOWNLOAD), tr("Download"), this);
QAction *downloadAct = new QAction(QIcon(IMAGE_DOWNLOAD), tr("Download"), &contextMnu);
connect(downloadAct, SIGNAL(triggered()), this, SLOT(downloadSelected()));
contextMnu.addAction(voteupAct);
@ -976,7 +976,7 @@ void LinksDialog::downloadSelected()
RetroShareLink rslink(QString::fromStdWString(detail.link));
if(!rslink.valid())
if(!rslink.valid() || rslink.type() != RetroShareLink::TYPE_FILE)
{
QMessageBox::critical(NULL,"Badly formed link","This link is badly formed. Can't parse/use it. This is a bug. Please contact the developers.") ;
return ;

View File

@ -82,13 +82,6 @@ void updateComments(std::string rid, std::string pid);
/* (2) Utility Fns */
QTreeWidgetItem *getCurrentLine();
/** Define the popup menus for the Context menu */
QMenu* contextMnu;
/** Defines the actions for the context menu */
QAction* voteupAct;
QAction* votedownAct;
QAction* downloadAct;
QTreeWidget *exampletreeWidget;
/** Qt Designer generated object */

View File

@ -266,6 +266,8 @@ MessagesDialog::MessagesDialog(QWidget *parent)
connect(ui.filterColumnComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(filterColumnChanged()));
ui.msgText->setOpenLinks(false);
m_eListMode = LIST_NOTHING;
mCurrCertId = "";
@ -748,15 +750,15 @@ void MessagesDialog::messageslistWidgetCostumPopupMenu( QPoint point )
/** Defines the actions for the context menu */
QAction *replytomsgAct = new QAction(QIcon(IMAGE_MESSAGEREPLY), tr( "Reply to Message" ), this );
QAction *replytomsgAct = new QAction(QIcon(IMAGE_MESSAGEREPLY), tr( "Reply to Message" ), &contextMnu );
connect( replytomsgAct , SIGNAL( triggered() ), this, SLOT( replytomessage() ) );
contextMnu.addAction( replytomsgAct);
QAction *replyallmsgAct = new QAction(QIcon(IMAGE_MESSAGEREPLYALL), tr( "Reply to All" ), this );
QAction *replyallmsgAct = new QAction(QIcon(IMAGE_MESSAGEREPLYALL), tr( "Reply to All" ), &contextMnu );
connect( replyallmsgAct , SIGNAL( triggered() ), this, SLOT( replyallmessage() ) );
contextMnu.addAction( replyallmsgAct);
QAction *forwardmsgAct = new QAction(QIcon(IMAGE_MESSAGEFORWARD), tr( "Forward Message" ), this );
QAction *forwardmsgAct = new QAction(QIcon(IMAGE_MESSAGEFORWARD), tr( "Forward Message" ), &contextMnu );
connect( forwardmsgAct , SIGNAL( triggered() ), this, SLOT( forwardmessage() ) );
contextMnu.addAction( forwardmsgAct);
@ -764,7 +766,7 @@ void MessagesDialog::messageslistWidgetCostumPopupMenu( QPoint point )
QList<int> RowsUnread;
int nCount = getSelectedMsgCount (NULL, &RowsRead, &RowsUnread);
QAction *editAct = new QAction(tr( "Edit..." ), this );
QAction *editAct = new QAction(tr( "Edit..." ), &contextMnu );
connect(editAct, SIGNAL(triggered()), this, SLOT(editmessage()));
contextMnu.addAction(editAct);
@ -776,14 +778,14 @@ void MessagesDialog::messageslistWidgetCostumPopupMenu( QPoint point )
contextMnu.addSeparator();
QAction *markAsRead = new QAction(QIcon(":/images/message-mail-read.png"), tr( "Mark as read" ), this);
QAction *markAsRead = new QAction(QIcon(":/images/message-mail-read.png"), tr( "Mark as read" ), &contextMnu);
connect(markAsRead , SIGNAL(triggered()), this, SLOT(markAsRead()));
contextMnu.addAction(markAsRead);
if (RowsUnread.size() == 0) {
markAsRead->setDisabled(true);
}
QAction *markAsUnread = new QAction(QIcon(":/images/message-mail.png"), tr( "Mark as unread" ), this);
QAction *markAsUnread = new QAction(QIcon(":/images/message-mail.png"), tr( "Mark as unread" ), &contextMnu);
connect(markAsUnread , SIGNAL(triggered()), this, SLOT(markAsUnread()));
contextMnu.addAction(markAsUnread);
if (RowsRead.size() == 0) {
@ -798,9 +800,9 @@ void MessagesDialog::messageslistWidgetCostumPopupMenu( QPoint point )
QAction *removemsgAct;
if (nCount > 1) {
removemsgAct = new QAction(QIcon(IMAGE_MESSAGEREMOVE), tr( "Remove Messages" ), this );
removemsgAct = new QAction(QIcon(IMAGE_MESSAGEREMOVE), tr( "Remove Messages" ), &contextMnu );
} else {
removemsgAct = new QAction(QIcon(IMAGE_MESSAGEREMOVE), tr( "Remove Message" ), this );
removemsgAct = new QAction(QIcon(IMAGE_MESSAGEREMOVE), tr( "Remove Message" ), &contextMnu );
}
connect( removemsgAct , SIGNAL( triggered() ), this, SLOT( removemessage() ) );
@ -808,7 +810,7 @@ void MessagesDialog::messageslistWidgetCostumPopupMenu( QPoint point )
int listrow = ui.listWidget -> currentRow();
if (listrow == ROW_TRASHBOX) {
QAction *undeleteAct = new QAction(tr( "Undelete" ), this );
QAction *undeleteAct = new QAction(tr( "Undelete" ), &contextMnu );
connect(undeleteAct, SIGNAL(triggered()), this, SLOT(undeletemessage()));
contextMnu.addAction(undeleteAct);
@ -824,7 +826,7 @@ void MessagesDialog::messageslistWidgetCostumPopupMenu( QPoint point )
contextMnu.addAction( ui.actionPrint);
contextMnu.addSeparator();
QAction *newmsgAct = new QAction(QIcon(IMAGE_MESSAGE), tr( "New Message" ), this );
QAction *newmsgAct = new QAction(QIcon(IMAGE_MESSAGE), tr( "New Message" ), &contextMnu );
connect( newmsgAct , SIGNAL( triggered() ), this, SLOT( newmessage() ) );
contextMnu.addAction( newmsgAct);
@ -843,15 +845,12 @@ void MessagesDialog::messageslistWidgetCostumPopupMenu( QPoint point )
void MessagesDialog::msgfilelistWidgetCostumPopupMenu( QPoint point )
{
QAction* getRecAct = NULL;
// QAction* getAllRecAct = NULL;
QMenu contextMnu( this );
getRecAct = new QAction(QIcon(IMAGE_DOWNLOAD), tr( "Download" ), this );
QAction* getRecAct = new QAction(QIcon(IMAGE_DOWNLOAD), tr( "Download" ), &contextMnu );
connect( getRecAct , SIGNAL( triggered() ), this, SLOT( getcurrentrecommended() ) );
// getAllRecAct = new QAction(QIcon(IMAGE_DOWNLOADALL), tr( "Download" ), this );
// QAction* getAllRecAct = new QAction(QIcon(IMAGE_DOWNLOADALL), tr( "Download" ), &contextMnu );
// connect( getAllRecAct , SIGNAL( triggered() ), this, SLOT( getallrecommended() ) );
contextMnu.addAction( getRecAct);
@ -2004,53 +2003,9 @@ void MessagesDialog::printpreview()
void MessagesDialog::anchorClicked (const QUrl& link )
{
#ifdef FORUM_DEBUG
std::cerr << "MessagesDialog::anchorClicked link.scheme() : " << link.scheme().toStdString() << std::endl;
#endif
if (link.scheme() == "retroshare")
{
RetroShareLink rslnk(link.toString()) ;
#ifdef FORUM_DEBUG
std::cerr << "MessagesDialog::anchorClicked FileRequest : fileName : " << fileName << ". fileHash : " << fileHash << ". fileSize : " << fileSize << std::endl;
#endif
if(rslnk.valid())
{
std::list<std::string> srcIds;
if(rsFiles->FileRequest(rslnk.name().toStdString(), rslnk.hash().toStdString(), rslnk.size(), "", 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."),QMessageBox::Information,QMessageBox::Ok,0,0);
mb.setButtonText( QMessageBox::Ok, "OK" );
mb.exec();
}
}
else
{
QMessageBox mb(tr("File Request Error"), tr("The file link is malformed."),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() == "")
{
//it's probably a web adress, let's add http:// at the beginning of the link
QString newAddress = link.toString();
newAddress.prepend("http://");
QDesktopServices::openUrl(QUrl(newAddress));
}
RetroShareLink::processUrl(link, NULL, RSLINK_PROCESS_NOTIFY_ALL);
}
bool MessagesDialog::fileSave()

View File

@ -42,6 +42,7 @@
#include "settings/rsharesettings.h"
#include "gui/connect/ConnectFriendWizard.h"
#include "RetroShareLink.h"
#include "PeersDialog.h"
#include "ShareManager.h"
@ -57,6 +58,7 @@
#define IMAGE_PEERINFO ":/images/peerdetails_16x16.png"
#define IMAGE_AVAIBLE ":/images/user/identityavaiblecyan24.png"
#define IMAGE_CONNECT2 ":/images/reload24.png"
#define IMAGE_PASTELINK ":/images/pasterslink.png"
/* Images for Status icons */
#define IMAGE_ONLINE ":/images/im-user.png"
@ -257,35 +259,46 @@ void MessengerWindow::messengertreeWidgetCostumPopupMenu( QPoint point )
QMenu contextMnu( this );
QAction* expandAll = new QAction(tr( "Expand all" ), this );
QAction* expandAll = new QAction(tr( "Expand all" ), &contextMnu );
connect( expandAll , SIGNAL( triggered() ), ui.messengertreeWidget, SLOT (expandAll()) );
QAction* collapseAll = new QAction(tr( "Collapse all" ), this );
QAction* collapseAll = new QAction(tr( "Collapse all" ), &contextMnu );
connect( collapseAll , SIGNAL( triggered() ), ui.messengertreeWidget, SLOT(collapseAll()) );
chatAct = new QAction(QIcon(IMAGE_CHAT), tr( "Chat" ), this );
QAction* chatAct = new QAction(QIcon(IMAGE_CHAT), tr( "Chat" ), &contextMnu );
connect( chatAct , SIGNAL( triggered() ), this, SLOT( chatfriendproxy() ) );
sendMessageAct = new QAction(QIcon(IMAGE_MSG), tr( "Message Friend" ), this );
QAction* sendMessageAct = new QAction(QIcon(IMAGE_MSG), tr( "Message Friend" ), &contextMnu );
connect( sendMessageAct , SIGNAL( triggered() ), this, SLOT( sendMessage() ) );
connectfriendAct = new QAction(QIcon(IMAGE_CONNECT), tr( "Connect To Friend" ), this );
QAction* connectfriendAct = new QAction(QIcon(IMAGE_CONNECT), tr( "Connect To Friend" ), &contextMnu );
connect( connectfriendAct , SIGNAL( triggered() ), this, SLOT( connectfriend() ) );
configurefriendAct = new QAction(QIcon(IMAGE_PEERINFO), tr( "Peer Details" ), this );
QAction* configurefriendAct = new QAction(QIcon(IMAGE_PEERINFO), tr( "Peer Details" ), &contextMnu );
connect( configurefriendAct , SIGNAL( triggered() ), this, SLOT( configurefriend() ) );
//profileviewAct = new QAction(QIcon(IMAGE_PEERINFO), tr( "Profile View" ), this );
QAction* recommendfriendAct = new QAction(QIcon(IMAGE_EXPIORTFRIEND), tr( "Recomend this Friend to..." ), &contextMnu );
connect( recommendfriendAct , SIGNAL( triggered() ), this, SLOT( recommendfriend() ) );
QAction* pastePersonAct = new QAction(QIcon(IMAGE_PASTELINK), tr( "Paste retroshare Link" ), &contextMnu );
if(!RSLinkClipboard::empty(RetroShareLink::TYPE_PERSON)) {
connect( pastePersonAct , SIGNAL( triggered() ), this, SLOT( pastePerson() ) );
} else {
pastePersonAct->setDisabled(true);
}
//QAction* profileviewAct = new QAction(QIcon(IMAGE_PEERINFO), tr( "Profile View" ), &contextMnu );
//connect( profileviewAct , SIGNAL( triggered() ), this, SLOT( viewprofile() ) );
exportfriendAct = new QAction(QIcon(IMAGE_EXPIORTFRIEND), tr( "Export Friend" ), this );
QAction* exportfriendAct = new QAction(QIcon(IMAGE_EXPIORTFRIEND), tr( "Export Friend" ), &contextMnu );
connect( exportfriendAct , SIGNAL( triggered() ), this, SLOT( exportfriend() ) );
QAction* removefriendAct;
if (c->type() == 0) {
//this is a GPG key
removefriendAct = new QAction(QIcon(IMAGE_REMOVEFRIEND), tr( "Deny Friend" ), this );
removefriendAct = new QAction(QIcon(IMAGE_REMOVEFRIEND), tr( "Deny Friend" ), &contextMnu );
} else {
removefriendAct = new QAction(QIcon(IMAGE_REMOVEFRIEND), tr( "Remove Friend Location" ), this );
removefriendAct = new QAction(QIcon(IMAGE_REMOVEFRIEND), tr( "Remove Friend Location" ), &contextMnu );
}
connect( removefriendAct , SIGNAL( triggered() ), this, SLOT( removefriend() ) );
@ -293,25 +306,26 @@ void MessengerWindow::messengertreeWidgetCostumPopupMenu( QPoint point )
QWidget *widget = new QWidget();
widget->setStyleSheet( ".QWidget{background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,stop:0 #FEFEFE, stop:1 #E8E8E8); border: 1px solid #CCCCCC;}");
QHBoxLayout *hbox = new QHBoxLayout();
QHBoxLayout *hbox = new QHBoxLayout(&contextMnu);
hbox->setMargin(0);
hbox->setSpacing(6);
iconLabel = new QLabel( this );
QLabel *iconLabel = new QLabel(&contextMnu);
iconLabel->setPixmap(QPixmap(":/images/user/friends24.png"));
iconLabel->setMaximumSize( iconLabel->frameSize().height() + 24, 24 );
hbox->addWidget(iconLabel);
QLabel *textLabel;
if (c->type() == 0) {
//this is a GPG key
textLabel = new QLabel( tr("<strong>GPG Key</strong>"), this );
textLabel = new QLabel( tr("<strong>GPG Key</strong>"), &contextMnu );
} else {
textLabel = new QLabel( tr("<strong>RetroShare instance</strong>"), this );
textLabel = new QLabel( tr("<strong>RetroShare instance</strong>"), &contextMnu );
}
hbox->addWidget(textLabel);
spacerItem = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
QSpacerItem *spacerItem = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
hbox->addItem(spacerItem);
widget->setLayout( hbox );
@ -324,10 +338,13 @@ void MessengerWindow::messengertreeWidgetCostumPopupMenu( QPoint point )
contextMnu.addAction( sendMessageAct);
contextMnu.addAction( configurefriendAct);
//contextMnu.addAction( profileviewAct);
if (c->type() != 0) {
if (c->type() == 0) {
contextMnu.addAction( recommendfriendAct);
} else {
//this is a SSL key
contextMnu.addAction( connectfriendAct);
}
contextMnu.addAction(pastePersonAct);
contextMnu.addAction( removefriendAct);
//contextMnu.addAction( exportfriendAct);
contextMnu.addSeparator();
@ -829,6 +846,23 @@ void MessengerWindow::configurefriend()
ConfCertDialog::show(getPeersRsCertId(getCurrentPeer()));
}
void MessengerWindow::recommendfriend()
{
QTreeWidgetItem *peer = getCurrentPeer();
if (!peer)
return;
std::list <std::string> ids;
ids.push_back(peer->data(COLUMN_DATA, ROLE_ID).toString().toStdString());
MessageComposer::recommendFriend(ids);
}
void MessengerWindow::pastePerson()
{
RSLinkClipboard::process(RetroShareLink::TYPE_PERSON, RSLINK_PROCESS_NOTIFY_ERROR);
}
void MessengerWindow::updatePeersAvatar(const QString& peer_id)
{
std::cerr << "PeersDialog: Got notified of new avatar for peer " << peer_id.toStdString() << std::endl ;

View File

@ -80,6 +80,9 @@ private slots:
/** show peers details for each friend **/
void configurefriend();
void recommendfriend();
void pastePerson();
/** Open Shared Manager **/
void openShareManager();
@ -122,19 +125,6 @@ private:
void FilterItems();
bool FilterItem(QTreeWidgetItem *pItem, QString &sPattern);
class QLabel *iconLabel, *textLabel;
class QWidget *widget;
class QWidgetAction *widgetAction;
class QSpacerItem *spacerItem;
/** Defines the actions for the context menu */
QAction* chatAct;
QAction* sendMessageAct;
QAction* connectfriendAct;
QAction* configurefriendAct;
QAction* exportfriendAct;
QAction* removefriendAct;
QTreeView *messengertreeWidget;
LogoBar * _rsLogoBarmessenger;

View File

@ -234,21 +234,21 @@ void NetworkDialog::connecttreeWidgetCostumPopupMenu( QPoint point )
{
if(detail.accept_connection)
{
denyFriendAct = new QAction(QIcon(IMAGE_DENIED), tr( "Deny friend" ), this );
QAction* denyFriendAct = new QAction(QIcon(IMAGE_DENIED), tr( "Deny friend" ), &contextMnu );
connect( denyFriendAct , SIGNAL( triggered() ), this, SLOT( denyFriend() ) );
contextMnu.addAction( denyFriendAct);
}
else // not a friend
{
makefriendAct = new QAction(QIcon(IMAGE_MAKEFRIEND), tr( "Make friend" ), this );
QAction* makefriendAct = new QAction(QIcon(IMAGE_MAKEFRIEND), tr( "Make friend" ), &contextMnu );
connect( makefriendAct , SIGNAL( triggered() ), this, SLOT( makeFriend() ) );
contextMnu.addAction( makefriendAct);
#ifdef TODO
if(detail.validLvl > RS_TRUST_LVL_MARGINAL) // it's a denied old friend.
{
deleteCertAct = new QAction(QIcon(IMAGE_PEERDETAILS), tr( "Delete certificate" ), this );
QAction* deleteCertAct = new QAction(QIcon(IMAGE_PEERDETAILS), tr( "Delete certificate" ), &contextMnu );
connect( deleteCertAct, SIGNAL( triggered() ), this, SLOT( deleteCert() ) );
contextMnu.addAction( deleteCertAct );
}
@ -258,12 +258,12 @@ void NetworkDialog::connecttreeWidgetCostumPopupMenu( QPoint point )
}
if(peer_id == rsPeers->getGPGOwnId())
{
exportcertAct = new QAction(QIcon(IMAGE_EXPIORT), tr( "Export my Cert" ), this );
QAction* exportcertAct = new QAction(QIcon(IMAGE_EXPIORT), tr( "Export my Cert" ), &contextMnu );
connect( exportcertAct , SIGNAL( triggered() ), this, SLOT( on_actionExportKey_activated() ) );
contextMnu.addAction( exportcertAct);
}
peerdetailsAct = new QAction(QIcon(IMAGE_PEERDETAILS), tr( "Peer details..." ), this );
QAction* peerdetailsAct = new QAction(QIcon(IMAGE_PEERDETAILS), tr( "Peer details..." ), &contextMnu );
connect( peerdetailsAct , SIGNAL( triggered() ), this, SLOT( peerdetails() ) );
contextMnu.addAction( peerdetailsAct);

View File

@ -94,15 +94,6 @@ private slots:
private:
QTreeWidgetItem *getCurrentNeighbour();
/** Defines the actions for the context menu */
QAction* peerdetailsAct;
QAction* denyFriendAct;
QAction* deleteCertAct;
QAction* makefriendAct;
QAction* authAct;
QAction* loadcertAct;
QAction* exportcertAct;
QTreeWidget *connecttreeWidget;
class NetworkView *networkview;

View File

@ -23,7 +23,6 @@
#include <QFileInfo>
#include "common/vmessagebox.h"
#include <gui/mainpagestack.h>
#include <gui/RetroShareLink.h>
#include "rshare.h"
#include "PeersDialog.h"
@ -44,6 +43,7 @@
#include "gui/connect/ConnectFriendWizard.h"
#include "gui/forums/CreateForum.h"
#include "gui/channels/CreateChannel.h"
#include "RetroShareLink.h"
#include "MainWindow.h"
@ -70,6 +70,7 @@
#define IMAGE_AVAIBLE ":/images/user/identityavaiblecyan24.png"
#define IMAGE_UNREACHABLE ":/images/user/identityunreachable24.png"
#define IMAGE_CONNECT2 ":/images/reload24.png"
#define IMAGE_PASTELINK ":/images/pasterslink.png"
#define COLUMN_COUNT 3
#define COLUMN_NAME 0
@ -319,92 +320,106 @@ void PeersDialog::contextMenu( QPoint point )
void PeersDialog::peertreeWidgetCostumPopupMenu( QPoint point )
{
QTreeWidgetItem *c = getCurrentPeer();
if (!c) {
//no peer selected
return;
}
QTreeWidgetItem *c = getCurrentPeer();
if (!c) {
//no peer selected
return;
}
QAction* expandAll = new QAction(tr( "Expand all" ), this );
connect( expandAll , SIGNAL( triggered() ), ui.peertreeWidget, SLOT (expandAll()) );
QMenu contextMnu( this );
QAction* collapseAll = new QAction(tr( "Collapse all" ), this );
connect( collapseAll , SIGNAL( triggered() ), ui.peertreeWidget, SLOT(collapseAll()) );
QAction* expandAll = new QAction(tr( "Expand all" ), &contextMnu );
connect( expandAll , SIGNAL( triggered() ), ui.peertreeWidget, SLOT (expandAll()) );
chatAct = new QAction(QIcon(IMAGE_CHAT), tr( "Chat" ), this );
connect( chatAct , SIGNAL( triggered() ), this, SLOT( chatfriendproxy() ) );
QAction* collapseAll = new QAction(tr( "Collapse all" ), &contextMnu );
connect( collapseAll , SIGNAL( triggered() ), ui.peertreeWidget, SLOT(collapseAll()) );
msgAct = new QAction(QIcon(IMAGE_MSG), tr( "Message Friend" ), this );
connect( msgAct , SIGNAL( triggered() ), this, SLOT( msgfriend() ) );
QAction* chatAct = new QAction(QIcon(IMAGE_CHAT), tr( "Chat" ), &contextMnu );
connect( chatAct , SIGNAL( triggered() ), this, SLOT( chatfriendproxy() ) );
connectfriendAct = new QAction(QIcon(IMAGE_CONNECT), tr( "Connect To Friend" ), this );
connect( connectfriendAct , SIGNAL( triggered() ), this, SLOT( connectfriend() ) );
QAction* msgAct = new QAction(QIcon(IMAGE_MSG), tr( "Message Friend" ), &contextMnu );
connect( msgAct , SIGNAL( triggered() ), this, SLOT( msgfriend() ) );
configurefriendAct = new QAction(QIcon(IMAGE_PEERINFO), tr( "Peer Details" ), this );
connect( configurefriendAct , SIGNAL( triggered() ), this, SLOT( configurefriend() ) );
QAction* connectfriendAct = new QAction(QIcon(IMAGE_CONNECT), tr( "Connect To Friend" ), &contextMnu );
connect( connectfriendAct , SIGNAL( triggered() ), this, SLOT( connectfriend() ) );
profileviewAct = new QAction(QIcon(IMAGE_PEERINFO), tr( "Profile View" ), this );
connect( profileviewAct , SIGNAL( triggered() ), this, SLOT( viewprofile() ) );
QAction* configurefriendAct = new QAction(QIcon(IMAGE_PEERINFO), tr( "Peer Details" ), &contextMnu );
connect( configurefriendAct , SIGNAL( triggered() ), this, SLOT( configurefriend() ) );
exportfriendAct = new QAction(QIcon(IMAGE_EXPIORTFRIEND), tr( "Export Friend" ), this );
connect( exportfriendAct , SIGNAL( triggered() ), this, SLOT( exportfriend() ) );
QAction* recommendfriendAct = new QAction(QIcon(IMAGE_EXPIORTFRIEND), tr( "Recomend this Friend to..." ), &contextMnu );
connect( recommendfriendAct , SIGNAL( triggered() ), this, SLOT( recommendfriend() ) );
if (c->type() == 0) {
//this is a GPG key
removefriendAct = new QAction(QIcon(IMAGE_REMOVEFRIEND), tr( "Deny Friend" ), this );
} else {
removefriendAct = new QAction(QIcon(IMAGE_REMOVEFRIEND), tr( "Remove Friend Location" ), this );
}
connect( removefriendAct , SIGNAL( triggered() ), this, SLOT( removefriend() ) );
QAction* pastePersonAct = new QAction(QIcon(IMAGE_PASTELINK), tr( "Paste retroshare Link" ), &contextMnu );
if(!RSLinkClipboard::empty(RetroShareLink::TYPE_PERSON)) {
connect( pastePersonAct , SIGNAL( triggered() ), this, SLOT( pastePerson() ) );
} else {
pastePersonAct->setDisabled(true);
}
QAction* profileviewAct = new QAction(QIcon(IMAGE_PEERINFO), tr( "Profile View" ), &contextMnu );
connect( profileviewAct , SIGNAL( triggered() ), this, SLOT( viewprofile() ) );
QAction* exportfriendAct = new QAction(QIcon(IMAGE_EXPIORTFRIEND), tr( "Export Friend" ), &contextMnu );
connect( exportfriendAct , SIGNAL( triggered() ), this, SLOT( exportfriend() ) );
QAction* removefriendAct;
if (c->type() == 0) {
//this is a GPG key
removefriendAct = new QAction(QIcon(IMAGE_REMOVEFRIEND), tr( "Deny Friend" ), &contextMnu );
} else {
removefriendAct = new QAction(QIcon(IMAGE_REMOVEFRIEND), tr( "Remove Friend Location" ), &contextMnu );
}
connect( removefriendAct , SIGNAL( triggered() ), this, SLOT( removefriend() ) );
QWidget *widget = new QWidget();
widget->setStyleSheet( ".QWidget{background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,stop:0 #FEFEFE, stop:1 #E8E8E8); border: 1px solid #CCCCCC;}");
QHBoxLayout *hbox = new QHBoxLayout();
hbox->setMargin(0);
hbox->setSpacing(6);
QWidget *widget = new QWidget(&contextMnu);
widget->setStyleSheet( ".QWidget{background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,stop:0 #FEFEFE, stop:1 #E8E8E8); border: 1px solid #CCCCCC;}");
QHBoxLayout *hbox = new QHBoxLayout();
hbox->setMargin(0);
hbox->setSpacing(6);
iconLabel = new QLabel( this );
iconLabel->setPixmap(QPixmap(":/images/user/friends24.png"));
iconLabel->setMaximumSize( iconLabel->frameSize().height() + 24, 24 );
hbox->addWidget(iconLabel);
if (c->type() == 0) {
//this is a GPG key
textLabel = new QLabel( tr("<strong>GPG Key</strong>"), this );
} else {
textLabel = new QLabel( tr("<strong>RetroShare instance</strong>"), this );
}
iconLabel = new QLabel( this );
iconLabel->setPixmap(QPixmap(":/images/user/friends24.png"));
iconLabel->setMaximumSize( iconLabel->frameSize().height() + 24, 24 );
hbox->addWidget(iconLabel);
hbox->addWidget(textLabel);
spacerItem = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
hbox->addItem(spacerItem);
widget->setLayout( hbox );
if (c->type() == 0) {
//this is a GPG key
textLabel = new QLabel( tr("<strong>GPG Key</strong>"), widget );
} else {
textLabel = new QLabel( tr("<strong>RetroShare instance</strong>"), widget );
}
hbox->addWidget(textLabel);
spacerItem = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
hbox->addItem(spacerItem);
widget->setLayout( hbox );
QWidgetAction *widgetAction = new QWidgetAction(this);
widgetAction->setDefaultWidget(widget);
QWidgetAction *widgetAction = new QWidgetAction(this);
widgetAction->setDefaultWidget(widget);
QMenu contextMnu( this );
contextMnu.addAction( widgetAction);
contextMnu.addAction( chatAct);
contextMnu.addAction( msgAct);
contextMnu.addAction( configurefriendAct);
//contextMnu.addAction( profileviewAct);
if (c->type() == 0) {
contextMnu.addAction( recommendfriendAct);
} else {
//this is a SSL key
contextMnu.addAction( connectfriendAct);
}
contextMnu.addAction(pastePersonAct);
contextMnu.addAction( removefriendAct);
//contextMnu.addAction( exportfriendAct);
contextMnu.addSeparator();
contextMnu.addAction( expandAll);
contextMnu.addAction( collapseAll);
contextMnu.addAction( widgetAction);
contextMnu.addAction( chatAct);
contextMnu.addAction( msgAct);
contextMnu.addAction( configurefriendAct);
//contextMnu.addAction( profileviewAct);
if (c->type() != 0) {
//this is a SSL key
contextMnu.addAction( connectfriendAct);
}
contextMnu.addAction( removefriendAct);
//contextMnu.addAction( exportfriendAct);
contextMnu.addSeparator();
contextMnu.addAction( expandAll);
contextMnu.addAction( collapseAll);
contextMnu.exec(QCursor::pos());
contextMnu.exec(QCursor::pos());
}
// replaced by shortcut
@ -812,6 +827,23 @@ void PeersDialog::msgfriend()
MessageComposer::msgFriend(id);
}
void PeersDialog::recommendfriend()
{
QTreeWidgetItem *peer = getCurrentPeer();
if (!peer)
return;
std::list <std::string> ids;
ids.push_back(peer->data(COLUMN_DATA, ROLE_ID).toString().toStdString());
MessageComposer::recommendFriend(ids);
}
void PeersDialog::pastePerson()
{
RSLinkClipboard::process(RetroShareLink::TYPE_PERSON, RSLINK_PROCESS_NOTIFY_ERROR);
}
QTreeWidgetItem *PeersDialog::getCurrentPeer()
{
/* get the current, and extract the Id */
@ -1649,51 +1681,11 @@ void PeersDialog::fileHashingFinished(AttachFileItem* file) {
void PeersDialog::anchorClicked (const QUrl& link )
{
#ifdef PEERS_DEBUG
std::cerr << "PeersDialog::anchorClicked link.scheme() : " << link.scheme().toStdString() << std::endl;
#endif
if (link.scheme() == "retroshare")
{
RetroShareLink rslnk(link) ;
#ifdef PEERS_DEBUG
std::cerr << "PeersDialog::anchorClicked link.scheme() : " << link.scheme().toStdString() << std::endl;
#endif
if (rslnk.valid())
{
std::list<std::string> srcIds;
if(rsFiles->FileRequest(rslnk.name().toStdString(), rslnk.hash().toStdString(), rslnk.size(), "", 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.setWindowIcon(QIcon(QString::fromUtf8(":/images/rstray3.png")));
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."),QMessageBox::Information,QMessageBox::Ok,0,0);
mb.setButtonText( QMessageBox::Ok, "OK" );
mb.setWindowIcon(QIcon(QString::fromUtf8(":/images/rstray3.png")));
mb.exec();
}
}
else
{
QMessageBox mb(tr("File Request Error"), tr("The file link is malformed."),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() == "")
{
//it's probably a web adress, let's add http:// at the beginning of the link
QString newAddress = link.toString();
newAddress.prepend("http://");
QDesktopServices::openUrl(QUrl(newAddress));
}
RetroShareLink::processUrl(link, NULL, RSLINK_PROCESS_NOTIFY_ALL);
}
void PeersDialog::dropEvent(QDropEvent *event)

View File

@ -115,6 +115,9 @@ private slots:
void chatfriend(QTreeWidgetItem* );
void chatfriendproxy();
void msgfriend();
void recommendfriend();
void pastePerson();
void configurefriend();
void viewprofile();
@ -183,14 +186,7 @@ private:
QTreeWidgetItem *getCurrentPeer();
/** Defines the actions for the context menu */
QAction* chatAct;
QAction* pasteLinkAct;
QAction* msgAct;
QAction* connectfriendAct;
QAction* profileviewAct;
QAction* configurefriendAct;
QAction* exportfriendAct;
QAction* removefriendAct;
//QTreeWidget *peertreeWidget;

View File

@ -23,235 +23,487 @@
#include <QApplication>
#include <QMimeData>
#include <QClipboard>
#include <QDesktopServices>
#include <QMessageBox>
#include <QIcon>
#include <QObject>
#include "RetroShareLink.h"
#include "rsiface/rsfiles.h"
#include "rsiface/rspeers.h"
#define DEBUG_RSLINK 1
const QString RetroShareLink::HEADER_NAME("retroshare://file");
#define HEADER_FILE "retroshare://file"
#define HEADER_PERSON "retroshare://person"
RetroShareLink::RetroShareLink(const QUrl& url)
{
// parse
const QString stringurl = url.toString();
fromString(stringurl);
}
RetroShareLink::RetroShareLink(const QString& url)
{
fromString(url);
}
void RetroShareLink::fromString(const QString& url)
{
_valid = false;
// parse
#ifdef DEBUG_RSLINK
std::cerr << "got new RS link \"" << url.toString().toStdString() << "\"" << std::endl ;
std::cerr << "got new RS link \"" << url.toStdString() << "\"" << std::endl ;
#endif
QStringList list = url.toString().split ("|");
QStringList list = url.split ("|");
if(list.size() < 4)
goto bad_link ;
if (list.size() >= 1) {
if (list.size() == 4 && list[0] == HEADER_FILE) {
bool ok ;
bool ok ;
_type = TYPE_FILE;
_name = list[1] ;
_size = list[2].toULongLong(&ok) ;
_hash = list[3].left(40) ; // normally not necessary, but it's a security.
_name = list[1] ;
_size = list[2].toULongLong(&ok) ;
_hash = list[3].left(40) ; // normally not necessary, but it's a security.
if(!ok)
goto bad_link ;
if (ok) {
#ifdef DEBUG_RSLINK
std::cerr << "New RetroShareLink forged:" << std::endl ;
std::cerr << " name = \"" << _name.toStdString() << "\"" << std::endl ;
std::cerr << " hash = \"" << _hash.toStdString() << "\"" << std::endl ;
std::cerr << " size = " << _size << std::endl ;
std::cerr << "New RetroShareLink forged:" << std::endl ;
std::cerr << " name = \"" << _name.toStdString() << "\"" << std::endl ;
std::cerr << " hash = \"" << _hash.toStdString() << "\"" << std::endl ;
std::cerr << " size = " << _size << std::endl ;
#endif
check();
return;
}
} else if (list.size() == 3 && list[0] == HEADER_PERSON) {
_type = TYPE_PERSON;
_name = list[1] ;
_hash = list[2].left(40) ; // normally not necessary, but it's a security.
_size = 0;
check();
return;
}
check() ;
// bad link
}
return ;
bad_link:
#ifdef DEBUG_RSLINK
std::cerr << "Wrongly formed RS link. Can't process." << std::endl ;
std::cerr << "Wrongly formed RS link. Can't process." << std::endl ;
#endif
_hash = "" ;
_size = 0 ;
_name = "" ;
_type = TYPE_UNKNOWN;
_hash = "" ;
_size = 0 ;
_name = "" ;
}
RetroShareLink::RetroShareLink(const QString & name, uint64_t size, const QString & hash)
: _name(name),_size(size),_hash(hash)
: _name(name),_size(size),_hash(hash)
{
check() ;
_valid = false;
_type = TYPE_FILE;
check() ;
}
RetroShareLink::RetroShareLink(const QString & name, const QString & hash)
: _name(name),_size(0),_hash(hash)
{
_valid = false;
_type = TYPE_PERSON;
check() ;
}
void RetroShareLink::check()
{
bool valid = true ;
_valid = true;
if(_size > (((uint64_t)1)<<40)) // 1TB. Who has such large files?
valid = false ;
switch (_type) {
case TYPE_UNKNOWN:
_valid = false;
break;
case TYPE_FILE:
if(_size > (((uint64_t)1)<<40)) // 1TB. Who has such large files?
_valid = false;
if(!checkName(_name))
valid = false ;
if(!checkName(_name))
_valid = false;
if(!checkHash(_hash))
valid = false ;
if(!checkHash(_hash))
_valid = false;
break;
case TYPE_PERSON:
if(_size != 0)
_valid = false;
if(!valid) // we should throw an exception instead of this crap, but drbob doesn't like exceptions. Why ???
{
_hash = "" ;
_name = "" ;
_size = 0 ;
}
if(_name.isEmpty())
_valid = false;
if(_hash.isEmpty())
_valid = false;
break;
}
if(!_valid) // we should throw an exception instead of this crap, but drbob doesn't like exceptions. Why ???
{
_type = TYPE_UNKNOWN;
_hash = "" ;
_name = "" ;
_size = 0 ;
}
}
QString RetroShareLink::toString() const
{
return HEADER_NAME + "|" + _name + "|" + QString::number(_size) + "|" + _hash ;
switch (_type) {
case TYPE_UNKNOWN:
break;
case TYPE_FILE:
return QString(HEADER_FILE) + "|" + _name + "|" + QString::number(_size) + "|" + _hash;
case TYPE_PERSON:
return QString(HEADER_PERSON) + "|" + _name + "|" + _hash;
}
return "";
}
QString RetroShareLink::niceName() const
{
if (type() == TYPE_PERSON) {
return name() + "@" + hash();
}
return name();
}
QString RetroShareLink::toHtml() const
{
return QString("<a href='") + toString() + "'>" + name() + "</a>" ;
return QString("<a href='") + toString() + "'>" + niceName() + "</a>" ;
}
QString RetroShareLink::toHtmlFull() const
{
return QString("<a href='") + toString() + "'>" + toString() + "</a>" ;
return QString("<a href='") + toString() + "'>" + toString() + "</a>" ;
}
bool RetroShareLink::checkName(const QString& name)
{
if(name == "")
return false ;
if(name == "")
return false ;
for(int i=0;i<name.length();++i)
{
QChar::Category cat( name[i].category() ) ;
for(int i=0;i<name.length();++i)
{
QChar::Category cat( name[i].category() ) ;
if( cat == QChar::Separator_Line
|| cat == QChar::Other_NotAssigned
)
{
if( cat == QChar::Separator_Line
|| cat == QChar::Other_NotAssigned
)
{
#ifdef DEBUG_RSLINK
std::cerr <<"Unwanted category " << cat << " at place " << i << " in string \"" << name.toStdString() << "\"" << std::endl ;
std::cerr <<"Unwanted category " << cat << " at place " << i << " in string \"" << name.toStdString() << "\"" << std::endl ;
#endif
return false ;
}
}
return false ;
}
}
return true ;
return true ;
}
QUrl RetroShareLink::toUrl() const
{
return QUrl(toString()) ;
return QUrl(toString()) ;
}
bool RetroShareLink::checkHash(const QString& hash)
{
if(hash.length() != 40)
return false ;
if(hash.length() != 40)
return false ;
QByteArray qb(hash.toAscii()) ;
QByteArray qb(hash.toAscii()) ;
for(int i=0;i<qb.length();++i)
{
unsigned char b(qb[i]) ;
for(int i=0;i<qb.length();++i)
{
unsigned char b(qb[i]) ;
if(!((b>47 && b<58) || (b>96 && b<103)))
return false ;
}
if(!((b>47 && b<58) || (b>96 && b<103)))
return false ;
}
return true ;
return true ;
}
bool RetroShareLink::process(std::list<std::string> *psrcIds, int flag)
{
if (valid() == false) {
std::cerr << " RetroShareLink::process invalid request" << std::endl;
return false;
}
switch (type()) {
case TYPE_UNKNOWN:
break;
case TYPE_FILE:
{
std::cerr << " RetroShareLink::process FileRequest : fileName : " << name().toStdString() << ". fileHash : " << hash().toStdString() << ". fileSize : " << size() << std::endl;
std::list<std::string> srcIds;
if (psrcIds) {
srcIds = *psrcIds;
}
// I removed the NETWORK WIDE flag. Indeed, somebody can capture the turtle tunnel requests and ask for downloading the file while
// it's being downloaded (as partial files are always sources).
//
if (rsFiles->FileRequest(name().toStdString(), hash().toStdString(), size(), "", 0 /*RS_FILE_HINTS_NETWORK_WIDE*/, srcIds)) {
if (flag & RSLINK_PROCESS_NOTIFY_SUCCESS) {
QMessageBox mb(QObject::tr("File Request Confirmation"), QObject::tr("The file has been added to your download list."),QMessageBox::Information,QMessageBox::Ok,0,0);
mb.setButtonText( QMessageBox::Ok, "OK" );
mb.setWindowIcon(QIcon(QString::fromUtf8(":/images/rstray3.png")));
mb.exec();
}
return true;
}
if (flag & RSLINK_PROCESS_NOTIFY_ERROR) {
QMessageBox mb(QObject::tr("File Request canceled"), QObject::tr("The file has not been added to your download list, because you already have it."),QMessageBox::Critical,QMessageBox::Ok,0,0);
mb.setButtonText( QMessageBox::Ok, "OK" );
mb.setWindowIcon(QIcon(QString::fromUtf8(":/images/rstray3.png")));
mb.exec();
}
return false;
}
case TYPE_PERSON:
{
std::cerr << " RetroShareLink::process FriendRequest : name : " << name().toStdString() << ". id : " << hash().toStdString() << std::endl;
RsPeerDetails detail;
if (rsPeers->getPeerDetails(hash().toStdString(), detail)) {
if (detail.gpg_id == rsPeers->getGPGOwnId()) {
// it's me, do nothing
return true;
}
if (detail.accept_connection) {
// peer connection is already accepted
if (flag & RSLINK_PROCESS_NOTIFY_SUCCESS) {
QMessageBox mb(QObject::tr("Friend Request Confirmation"), QObject::tr("The friend is already in your list."),QMessageBox::Information,QMessageBox::Ok,0,0);
mb.setButtonText( QMessageBox::Ok, "OK" );
mb.setWindowIcon(QIcon(QString::fromUtf8(":/images/rstray3.png")));
mb.exec();
}
return true;
}
if (rsPeers->setAcceptToConnectGPGCertificate(hash().toStdString(), true)) {
if (flag & RSLINK_PROCESS_NOTIFY_SUCCESS) {
QMessageBox mb(QObject::tr("Friend Request Confirmation"), QObject::tr("The friend has been added to your list."),QMessageBox::Information,QMessageBox::Ok,0,0);
mb.setButtonText( QMessageBox::Ok, "OK" );
mb.setWindowIcon(QIcon(QString::fromUtf8(":/images/rstray3.png")));
mb.exec();
}
return true;
}
if (flag & RSLINK_PROCESS_NOTIFY_ERROR) {
QMessageBox mb(QObject::tr("Friend Request canceled"), QObject::tr("The friend could not be added to your list."),QMessageBox::Critical,QMessageBox::Ok,0,0);
mb.setButtonText( QMessageBox::Ok, "OK" );
mb.setWindowIcon(QIcon(QString::fromUtf8(":/images/rstray3.png")));
mb.exec();
}
return false;
}
if (flag & RSLINK_PROCESS_NOTIFY_ERROR) {
QMessageBox mb(QObject::tr("Friend Request canceled"), QObject::tr("The friend could not be found."),QMessageBox::Critical,QMessageBox::Ok,0,0);
mb.setButtonText( QMessageBox::Ok, "OK" );
mb.setWindowIcon(QIcon(QString::fromUtf8(":/images/rstray3.png")));
mb.exec();
}
return false;
}
}
std::cerr << " RetroShareLink::process unknown type: " << type() << std::endl;
if (flag & RSLINK_PROCESS_NOTIFY_ERROR) {
QMessageBox mb(QObject::tr("File Request Error"), QObject::tr("The file link is malformed."),QMessageBox::Critical,QMessageBox::Ok,0,0);
mb.setButtonText( QMessageBox::Ok, "OK" );
mb.setWindowIcon(QIcon(QString::fromUtf8(":/images/rstray3.png")));
mb.exec();
}
return false;
}
/*static*/ bool RetroShareLink::processUrl(const QUrl &url, std::list<std::string> *psrcIds, int flag)
{
if (url.scheme() == "http") {
QDesktopServices::openUrl(url);
return true;
}
if (url.scheme() == "retroshare") {
// QUrl can't handle the RetroShare link format properly
if (flag & RSLINK_PROCESS_NOTIFY_ERROR) {
QMessageBox mb(QObject::tr("File Request"), QObject::tr("Process of RetroShare links is not implemented. Please use copy instead."),QMessageBox::Critical,QMessageBox::Ok,0,0);
mb.setButtonText( QMessageBox::Ok, "OK" );
mb.setWindowIcon(QIcon(QString::fromUtf8(":/images/rstray3.png")));
mb.exec();
}
// RetroShareLink link(url);
//
// if (link.valid()) {
// return link.process(psrcId, flag);
// }
//
// if (flag & RSLINK_PROCESS_NOTIFY_ERROR) {
// QMessageBox mb(QObject::tr("File Request Error"), QObject::tr("The file link is malformed."),QMessageBox::Information,QMessageBox::Ok,0,0);
//second version: QMessageBox mb(QObject::tr("Badly formed RS link"), QObject::tr("This RetroShare link is malformed. This is bug. Please contact the developers.\n\nNote: this possibly comes from a bug in Qt4.6. Try to right-click + copy link location, and paste in Transfer Tab."),QMessageBox::Critical,QMessageBox::Ok,0,0);
// mb.setButtonText( QMessageBox::Ok, "OK" );
// mb.setWindowIcon(QIcon(QString::fromUtf8(":/images/rstray3.png")));
// mb.exec();
// }
return false;
}
if (url.scheme().isEmpty()) {
//it's probably a web adress, let's add http:// at the beginning of the link
QString newAddress = "http://" + url.toString();
QDesktopServices::openUrl(QUrl(newAddress));
return true;
}
return false;
}
void RSLinkClipboard::copyLinks(const std::vector<RetroShareLink>& links)
{
QString res ;
for(uint32_t i=0;i<links.size();++i)
res += links[i].toString() + "\n" ;
QString res ;
for(uint32_t i=0;i<links.size();++i)
res += links[i].toString() + "\n" ;
QApplication::clipboard()->setText(res) ;
QApplication::clipboard()->setText(res) ;
}
std::vector<RetroShareLink> RSLinkClipboard::pasteLinks()
void RSLinkClipboard::pasteLinks(std::vector<RetroShareLink> &links)
{
return parseClipboard() ;
return parseClipboard(links);
}
std::vector<RetroShareLink> RSLinkClipboard::parseClipboard()
void RSLinkClipboard::parseClipboard(std::vector<RetroShareLink> &links)
{
// parse clipboard for links.
//
std::vector<RetroShareLink> links ;
QString text = QApplication::clipboard()->text() ;
// parse clipboard for links.
//
links.clear();
QString text = QApplication::clipboard()->text() ;
std::cerr << "Parsing clipboard:" << text.toStdString() << std::endl ;
std::cerr << "Parsing clipboard:" << text.toStdString() << std::endl ;
QRegExp rx("retroshare://file") ;
rx.setPatternSyntax(QRegExp::Wildcard) ;
QRegExp rx("retroshare://(file|person)[^\r\n]+") ;
int pos = 0;
int pos = 0;
while((pos = rx.indexIn(text, pos)) != -1)
{
QString txt = text.right(text.length()-pos) ;
QStringList lst = txt.split('|') ;
while((pos = rx.indexIn(text, pos)) != -1)
{
QString url(text.mid(pos, rx.matchedLength()));
RetroShareLink link(url);
if(lst.size() < 4)
break ;
if(link.valid())
{
// check that the link is not already in the list:
bool already = false ;
for(uint32_t i=0;i<links.size();++i)
if(links[i] == link)
{
already = true ;
break ;
}
bool ok = false ;
RetroShareLink link(lst[1],lst[2].toULongLong(&ok),lst[3].left(40)) ;
if(!already)
{
links.push_back(link) ;
std::cerr << "captured link: " << link.toString().toStdString() << std::endl ;
}
}
else
std::cerr << "invalid link" << std::endl ;
if(link.valid())
{
// check that the link is not already in the list:
bool already = false ;
for(uint32_t i=0;i<links.size();++i)
if(links[i] == link)
{
already = true ;
break ;
}
if(!already)
{
links.push_back(link) ;
std::cerr << "captured link: " << link.toString().toStdString() << std::endl ;
}
}
else
std::cerr << "invalid link" << std::endl ;
pos += rx.matchedLength();
}
return links ;
pos += rx.matchedLength();
}
}
QString RSLinkClipboard::toString()
{
std::vector<RetroShareLink> links(parseClipboard()) ;
std::vector<RetroShareLink> links;
parseClipboard(links);
QString res ;
for(uint32_t i=0;i<links.size();++i)
res += links[i].toString() + "\n" ;
QString res ;
for(uint32_t i=0;i<links.size();++i)
res += links[i].toString() + "\n" ;
return res ;
return res ;
}
QString RSLinkClipboard::toHtml()
{
std::vector<RetroShareLink> links(parseClipboard()) ;
std::vector<RetroShareLink> links;
parseClipboard(links);
QString res ;
for(uint32_t i=0;i<links.size();++i)
res += links[i].toHtml() + "<br/>" ;
QString res ;
for(uint32_t i=0;i<links.size();++i)
res += links[i].toHtml() + "<br/>" ;
return res ;
return res ;
}
QString RSLinkClipboard::toHtmlFull()
{
std::vector<RetroShareLink> links(parseClipboard()) ;
std::vector<RetroShareLink> links;
parseClipboard(links);
QString res ;
for(uint32_t i=0;i<links.size();++i)
res += links[i].toHtmlFull() + "<br/>" ;
QString res ;
for(uint32_t i=0;i<links.size();++i)
res += links[i].toHtmlFull() + "<br/>" ;
return res ;
return res ;
}
bool RSLinkClipboard::empty()
bool RSLinkClipboard::empty(RetroShareLink::enumType type /*= RetroShareLink::TYPE_UNKNOWN*/)
{
return parseClipboard().empty() ;
std::vector<RetroShareLink> links;
parseClipboard(links);
if (type == RetroShareLink::TYPE_UNKNOWN) {
return links.empty();
}
for (std::vector<RetroShareLink>::iterator link = links.begin(); link != links.end(); link++) {
if (link->type() == type) {
return false;
}
}
return true;
}
/*static*/ int RSLinkClipboard::process(RetroShareLink::enumType type /*= RetroShareLink::TYPE_UNKNOWN*/, int flag /*= RSLINK_PROCESS_NOTIFY_ALL*/)
{
std::vector<RetroShareLink> links;
pasteLinks(links);
int count = 0;
for (uint32_t i = 0; i < links.size(); i++) {
if (links[i].valid() && (type == RetroShareLink::TYPE_UNKNOWN || links[i].type() == type)) {
if (links[i].process(NULL, flag)) {
count++;
}
}
}
return count;
}

View File

@ -37,38 +37,62 @@
#include <QVector>
#include <QUrl>
#define RSLINK_PROCESS_NOTIFY_SUCCESS 1 // notify on success
#define RSLINK_PROCESS_NOTIFY_ERROR 2 // notify on error
#define RSLINK_PROCESS_NOTIFY_ALL -1
class RetroShareLink
{
public:
RetroShareLink(const QUrl& url);
RetroShareLink(const QString& name, uint64_t size, const QString& hash);
enum enumType { TYPE_UNKNOWN, TYPE_FILE, TYPE_PERSON };
public:
RetroShareLink(const QUrl& url);
RetroShareLink(const QString& url);
// file
RetroShareLink(const QString& name, uint64_t size, const QString& hash);
// person
RetroShareLink(const QString& name, const QString& hash);
enumType type() const {return _type; }
uint64_t size() const { return _size ; }
const QString& name() const { return _name ; }
const QString& hash() const { return _hash ; }
// get nice name for anchor
QString niceName() const;
/// returns the string retroshare://file|name|size|hash
/// retroshare://person|name|hash
QString toString() const ;
/// returns the string <a href="retroshare://file|name|size|hash">name</a>
/// <a href="retroshare://person|name|hash">name@hash</a>
QString toHtml() const ;
/// returns the string <a href="retroshare://file|name|size|hash">retroshare://file|name|size|hash</a>
/// <a href="retroshare://person|name|hash">retroshare://person|name|hash</a>
QString toHtmlFull() const ;
QUrl toUrl() const ;
bool valid() const { return _size > 0 ; }
bool valid() const { return _valid; }
bool operator==(const RetroShareLink& l) const { return _type == l._type && _hash == l._hash ; }
bool process(std::list<std::string> *psrcIds, int flag);
static bool processUrl(const QUrl &url, std::list<std::string> *psrcIds, int flag);
bool operator==(const RetroShareLink& l) const { return _hash == l._hash ; }
private:
void fromString(const QString &url);
void check() ;
static bool checkHash(const QString& hash) ;
static bool checkName(const QString& hash) ;
static const QString HEADER_NAME;
QString _name;
bool _valid;
enumType _type;
QString _name;
uint64_t _size;
QString _hash;
QString _hash;
};
/// This class handles the copy/paste of links. Every member is static to ensure unicity.
@ -89,7 +113,7 @@ class RSLinkClipboard
// Get the liste of pasted links, either from the internal RS links, or by default
// from the clipboard.
//
static std::vector<RetroShareLink> pasteLinks() ;
static void pasteLinks(std::vector<RetroShareLink> &links) ;
// Produces a list of links with no html structure.
static QString toString() ;
@ -105,13 +129,15 @@ class RSLinkClipboard
// Returns true is no links are found to paste.
// Useful for menus.
//
static bool empty();
static bool empty(RetroShareLink::enumType type = RetroShareLink::TYPE_UNKNOWN);
// Returns the count of processed links
// Useful for menus.
//
static int process(RetroShareLink::enumType type = RetroShareLink::TYPE_UNKNOWN, int flag = RSLINK_PROCESS_NOTIFY_ALL);
private:
static std::vector<RetroShareLink> parseClipboard() ;
static void parseClipboard(std::vector<RetroShareLink> &links) ;
};
#endif

View File

@ -227,23 +227,23 @@ void SearchDialog::searchtableWidgetCostumPopupMenu( QPoint point )
// block the popup if no results available
if ((ui.searchResultWidget->selectedItems()).size() == 0) return;
downloadAct = new QAction(QIcon(IMAGE_START), tr( "Download" ), this );
QMenu contextMnu(this);
QAction* downloadAct = new QAction(QIcon(IMAGE_START), tr( "Download" ), &contextMnu );
connect( downloadAct , SIGNAL( triggered() ), this, SLOT( download() ) );
copysearchlinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Copy retroshare Link" ), this );
QAction* copysearchlinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Copy retroshare Link" ), &contextMnu );
connect( copysearchlinkAct , SIGNAL( triggered() ), this, SLOT( copysearchLink() ) );
sendrslinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Send retroshare Link" ), this );
QAction* sendrslinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Send retroshare Link" ), &contextMnu );
connect( sendrslinkAct , SIGNAL( triggered() ), this, SLOT( sendLinkTo( ) ) );
broadcastonchannelAct = new QAction( tr( "Broadcast on Channel" ), this );
QAction* broadcastonchannelAct = new QAction( tr( "Broadcast on Channel" ), &contextMnu );
connect( broadcastonchannelAct , SIGNAL( triggered() ), this, SLOT( broadcastonchannel() ) );
recommendtofriendsAct = new QAction( tr( "Recommend to Friends" ), this );
QAction* recommendtofriendsAct = new QAction( tr( "Recommend to Friends" ), &contextMnu );
connect( recommendtofriendsAct , SIGNAL( triggered() ), this, SLOT( recommendtofriends() ) );
QMenu contextMnu(this);
contextMnu.addAction( downloadAct);
contextMnu.addSeparator();
@ -377,15 +377,15 @@ void SearchDialog::searchtableWidget2CostumPopupMenu( QPoint point )
// block the popup if no results available
if ((ui.searchSummaryWidget->selectedItems()).size() == 0) return;
QMenu contextMnu(this);
// create the menu as required
searchRemoveAct = new QAction(QIcon(IMAGE_REMOVE), tr( "Remove" ), this );
QAction* searchRemoveAct = new QAction(QIcon(IMAGE_REMOVE), tr( "Remove" ), &contextMnu );
connect( searchRemoveAct , SIGNAL( triggered() ), this, SLOT( searchRemove() ) );
searchRemoveAllAct = new QAction(QIcon(IMAGE_REMOVEALL), tr( "Remove All" ), this );
QAction* searchRemoveAllAct = new QAction(QIcon(IMAGE_REMOVEALL), tr( "Remove All" ), &contextMnu );
connect( searchRemoveAllAct , SIGNAL( triggered() ), this, SLOT( searchRemoveAll() ) );
QMenu contextMnu(this);
contextMnu.addAction( searchRemoveAct);
contextMnu.addAction( searchRemoveAllAct);
@ -1201,7 +1201,7 @@ void SearchDialog::copysearchLink()
RetroShareLink link(fname, fsize, fhash);
std::cerr << "new link added to clipboard: " << link.toString().toStdString() << std::endl ;
if(link.valid())
if(link.valid() && link.type() == RetroShareLink::TYPE_FILE)
urls.push_back(link) ;
}
}

View File

@ -108,16 +108,6 @@ private:
/** the advanced search dialog instance */
AdvancedSearchDialog * advSearchDialog;
/** Defines the actions for the context menu */
QAction* downloadAct;
QAction* copysearchlinkAct;
QAction* sendrslinkAct;
QAction* broadcastonchannelAct;
QAction* recommendtofriendsAct;
QAction* searchRemoveAct;
QAction* searchRemoveAllAct;
/** Contains the mapping of filetype combobox to filetype extensions */
static const int FILETYPE_IDX_ANY;
static const int FILETYPE_IDX_ARCHIVE;

View File

@ -221,13 +221,15 @@ void SharedFilesDialog::forceCheck()
void SharedFilesDialog::shareddirtreeviewCostumPopupMenu( QPoint point )
{
downloadAct = new QAction(QIcon(IMAGE_DOWNLOAD), tr( "Download" ), this );
QMenu contextMnu( this );
QAction *downloadAct = new QAction(QIcon(IMAGE_DOWNLOAD), tr( "Download" ), &contextMnu );
connect( downloadAct , SIGNAL( triggered() ), this, SLOT( downloadRemoteSelected() ) );
copyremotelinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Copy retroshare Link" ), this );
QAction *copyremotelinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Copy retroshare Link" ), &contextMnu );
connect( copyremotelinkAct , SIGNAL( triggered() ), this, SLOT( copyLinkRemote() ) );
sendremotelinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Send retroshare Link" ), this );
QAction *sendremotelinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Send retroshare Link" ), &contextMnu );
connect( sendremotelinkAct , SIGNAL( triggered() ), this, SLOT( sendremoteLinkTo( ) ) );
@ -235,7 +237,6 @@ void SharedFilesDialog::shareddirtreeviewCostumPopupMenu( QPoint point )
// connect( addMsgAct , SIGNAL( triggered() ), this, SLOT( addMsgRemoteSelected() ) );
QMenu contextMnu( this );
contextMnu.addAction( downloadAct);
contextMnu.addSeparator();
contextMnu.addAction( copyremotelinkAct);
@ -291,7 +292,7 @@ void SharedFilesDialog::copyLink (const QModelIndexList& lst, bool remote)
RetroShareLink link(details.name.c_str(), details.count, details.hash.c_str());
if(link.valid())
if(link.valid() && link.type() == RetroShareLink::TYPE_FILE)
urls.push_back(link) ;
}
}
@ -299,7 +300,7 @@ void SharedFilesDialog::copyLink (const QModelIndexList& lst, bool remote)
{
RetroShareLink link(details.name.c_str(), details.count, details.hash.c_str());
if(link.valid())
if(link.valid() && link.type() == RetroShareLink::TYPE_FILE)
urls.push_back(link) ;
}
}

View File

@ -100,16 +100,11 @@ private:
void copyLink (const QModelIndexList& lst, bool remote);
/** Defines the actions for the context menu for QTreeView */
QAction* downloadAct;
QAction* addMsgAct;
/** Defines the actions for the context menu for QTreeWidget */
QAction* openfileAct;
QAction* openfolderAct;
QAction* copyremotelinkAct;
QAction* copylinklocalAct;
QAction* sendremotelinkAct;
QAction* sendlinkAct;
QAction* sendhtmllinkAct;
QAction* sendlinkCloudAct;

View File

@ -405,8 +405,12 @@ void TransfersDialog::downloadListCostumPopupMenu( QPoint point )
if(!items.empty())
contextMnu.addAction( copylinkAct);
if(!RSLinkClipboard::empty())
contextMnu.addAction( pastelinkAct);
if(!RSLinkClipboard::empty(RetroShareLink::TYPE_FILE)) {
pastelinkAct->setEnabled(true);
} else {
pastelinkAct->setDisabled(true);
}
contextMnu.addAction( pastelinkAct);
contextMnu.addSeparator();
@ -1123,12 +1127,7 @@ void TransfersDialog::updateDetailsDialog()
void TransfersDialog::pasteLink()
{
const std::vector<RetroShareLink>& links(RSLinkClipboard::pasteLinks()) ;
for(uint32_t i=0;i<links.size();++i)
if (links[i].valid())
if(!rsFiles->FileRequest(links[i].name().toStdString(), links[i].hash().toStdString(),links[i].size(), "", RS_FILE_HINTS_NETWORK_WIDE, std::list<std::string>()))
QMessageBox::critical(NULL,"Download refused","The file "+links[i].name()+" could not be downloaded. Do you already have it ?") ;
RSLinkClipboard::process(RetroShareLink::TYPE_FILE, RSLINK_PROCESS_NOTIFY_ERROR);
}
void TransfersDialog::getIdOfSelectedItems(std::set<QStandardItem *>& items)

View File

@ -958,46 +958,9 @@ void PopupChatDialog::anchorClicked (const QUrl& link )
std::cerr << "PopupChatDialog::anchorClicked link.scheme() : " << link.scheme().toStdString() << std::endl;
#endif
if(link.scheme() == "retroshare")
{
RetroShareLink rslink(link) ;
if(!rslink.valid())
{
QMessageBox mb(tr("Badly formed RS link"), tr("This RetroShare link is malformed. This is bug. Please contact the developers.\n\nNote: this possibly comes from a bug in Qt4.6. Try to right-click + copy link location, and paste in Transfer Tab."),QMessageBox::Information,QMessageBox::Ok,0,0);
mb.setButtonText( QMessageBox::Ok, "OK" );
mb.exec();
return ;
}
std::list<std::string> srcIds ;
srcIds.push_back(dialogId);
// I removed the NETWORK WIDE flag. Indeed, somebody can capture the turtle tunnel requests and ask for downloading the file while
// it's being downloaded (as partial files are always sources).
//
if(rsFiles->FileRequest(rslink.name().toStdString(), rslink.hash().toStdString(), rslink.size(), "", 0, 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() == "http")
QDesktopServices::openUrl(link);
else if (link.scheme() == "")
{
//it's probably a web adress, let's add http:// at the beginning of the link
QString newAddress = link.toString();
newAddress.prepend("http://");
QDesktopServices::openUrl(QUrl(newAddress));
}
std::list<std::string> srcIds;
srcIds.push_back(dialogId);
RetroShareLink::processUrl(link, &srcIds, RSLINK_PROCESS_NOTIFY_ALL);
}
void PopupChatDialog::dropEvent(QDropEvent *event)

View File

@ -181,6 +181,7 @@ MessageComposer::MessageComposer(QWidget *parent, Qt::WFlags flags)
/* Set header resize modes and initial section sizes */
ui.msgFileList->setColumnCount(5);
ui.msgFileList->setColumnHidden ( 4, true);
QHeaderView * _smheader = ui.msgFileList->header () ;
@ -206,9 +207,7 @@ MessageComposer::MessageComposer(QWidget *parent, Qt::WFlags flags)
/*static*/ void MessageComposer::msgFriend(std::string id)
{
#ifdef PEERS_DEBUG
std::cerr << "MessageComposer::msgfriend()" << std::endl;
#endif
// std::cerr << "MessageComposer::msgfriend()" << std::endl;
rsicontrol -> ClearInMsg();
rsicontrol -> SetInMsg(id, true);
@ -228,6 +227,57 @@ MessageComposer::MessageComposer(QWidget *parent, Qt::WFlags flags)
/* window will destroy itself! */
}
void MessageComposer::recommendFriend(std::list <std::string> &peerids)
{
// std::cerr << "MessageComposer::recommendFriend()" << std::endl;
if (peerids.size() == 0) {
return;
}
// rsicontrol -> ClearInMsg();
// rsicontrol -> SetInMsg(id, true);
/* create a message */
MessageComposer *pMsgDialog = new MessageComposer();
pMsgDialog->newMsg();
pMsgDialog->setWindowTitle(tr("Compose: ") + tr("Friend Recommendation")) ;
pMsgDialog->insertTitleText(tr("Friend Recommendation(s)").toStdString());
std::string sMsgText = tr("I recommend a good friend of me, you can trust him too when you trust me.").toStdString();
sMsgText += "<br><br>";
/* process peer ids */
std::list<FileInfo> files_info;
std::list <std::string>::iterator peerid;
for (peerid = peerids.begin(); peerid != peerids.end(); peerid++) {
RsPeerDetails detail;
if (rsPeers->getPeerDetails(*peerid, detail) == false) {
std::cerr << "MessageComposer::recommendFriend() Couldn't find peer id " << *peerid << std::endl;
continue;
}
RetroShareLink link(QString::fromStdString(detail.name), QString::fromStdString(detail.id));
if (link.valid() == false || link.type() != RetroShareLink::TYPE_PERSON) {
continue;
}
sMsgText += link.toHtmlFull().toStdString() + "<br>";
// FileInfo info;
// info.fname = link.name().toStdString();
// info.hash = link.hash().toStdString();
// info.inRecommend = true;
// files_info.push_back(info);
}
pMsgDialog->insertMsgText(sMsgText);
// pMsgDialog->insertFileList(files_info);
pMsgDialog->show();
/* window will destroy itself! */
}
void MessageComposer::closeEvent (QCloseEvent * event)
{
bool bClose = true;
@ -544,7 +594,6 @@ void MessageComposer::sendMessage_internal(bool bDraftbox)
rsiface->lockData(); /* Lock Interface */
// const std::list<FileInfo>& recList = rsiface->getRecommendList();
for(std::list<FileInfo>::const_iterator it(_recList.begin()); it != _recList.end(); ++it)
if (it -> inRecommend)
mi.files.push_back(*it);

View File

@ -47,6 +47,7 @@ public:
MessageComposer(QWidget *parent = 0, Qt::WFlags flags = 0);
static void msgFriend(std::string id);
static void recommendFriend(std::list <std::string> &peerids);
void newMsg(std::string msgId = "");