void SharedFilesDialog::sendLinkTo() { copyLink(); /* create a message */ MessageComposer *nMsgDialog = MessageComposer::newMsg(); if (nMsgDialog == NULL) { return; } /* fill it in * files are receommended already * just need to set peers */ std::cerr << "SharedFilesDialog::sendLinkTo()" << std::endl; nMsgDialog->setTitleText(tr("RetroShare Link")); nMsgDialog->setMsgText(RSLinkClipboard::toHtml(), true); nMsgDialog->show(); /* window will destroy itself! */ }
void SharedFilesDialog::recommendFilesToMsg() { std::list<DirDetails> files_info ; model->getFileInfoFromIndexList(getSelected(),files_info); if(files_info.empty()) return ; /* create a message */ MessageComposer *nMsgDialog = MessageComposer::newMsg(); if (nMsgDialog == NULL) { return; } nMsgDialog->setFileList(files_info) ; nMsgDialog->setTitleText(tr("Recommendation(s)")); nMsgDialog->setMsgText(tr("Recommendation(s)")); nMsgDialog->show(); /* window will destroy itself! */ }
void IdDetailsDialog::sendInvite() { /* create a message */ MessageComposer *composer = MessageComposer::newMsg(); composer->setTitleText(tr("You have a friend invite")); RsPeerId ownId = rsPeers->getOwnId(); RetroShareLink link = RetroShareLink::createCertificate(ownId); RsGxsId keyId(ui->lineEdit_KeyId->text().toStdString()); QString sMsgText = inviteMessage(); sMsgText += "<br><br>"; sMsgText += tr("Respond now:") + "<br>"; sMsgText += link.toHtml() + "<br>"; sMsgText += "<br>"; sMsgText += tr("Thanks, <br>") + QString::fromUtf8(rsPeers->getGPGName(rsPeers->getGPGOwnId()).c_str()); composer->setMsgText(sMsgText); composer->addRecipient(MessageComposer::TO, RsGxsId(keyId)); composer->show(); }
/*static*/ int RetroShareLink::process(const QList<RetroShareLink> &linksIn, uint flag /* = RSLINK_PROCESS_NOTIFY_ALL*/) { QList<RetroShareLink>::const_iterator linkIt; /* filter dublicate links */ QList<RetroShareLink> links; for (linkIt = linksIn.begin(); linkIt != linksIn.end(); linkIt++) { if (links.contains(*linkIt)) { continue; } links.append(*linkIt); } if (flag & RSLINK_PROCESS_NOTIFY_ASK) { /* ask for some types of link */ QStringList fileAdd; QStringList personAdd; for (linkIt = links.begin(); linkIt != links.end(); linkIt++) { const RetroShareLink &link = *linkIt; if (link.valid() == false) { continue; } switch (link.type()) { case TYPE_UNKNOWN: case TYPE_FORUM: case TYPE_CHANNEL: case TYPE_SEARCH: case TYPE_MESSAGE: case TYPE_CERTIFICATE: // no need to ask break; case TYPE_FILE: fileAdd.append(link.name()); break; case TYPE_PERSON: personAdd.append(PeerDefs::rsid(link.name().toUtf8().constData(), link.hash().toStdString())); break; } } QString content; if (fileAdd.size()) { processList(fileAdd, QObject::tr("Add file"), QObject::tr("Add files"), content); } if (personAdd.size()) { processList(personAdd, QObject::tr("Add friend"), QObject::tr("Add friends"), content); } if (content.isEmpty() == false) { QString question = "<html><body>"; if (links.size() == 1) { question += QObject::tr("Do you want to process the link ?"); } else { question += QObject::tr("Do you want to process %1 links ?").arg(links.size()); } question += "<br><br>" + content + "</body></html>"; QMessageBox mb(QObject::tr("Confirmation"), question, QMessageBox::Question, QMessageBox::Yes,QMessageBox::No, 0); mb.setWindowIcon(QIcon(QString::fromUtf8(":/images/rstray3.png"))); if (mb.exec() == QMessageBox::No) { return 0; } } } int countInvalid = 0; int countUnknown = 0; bool needNotifySuccess = false; // file QStringList fileAdded; QStringList fileExist; // person QStringList personAdded; QStringList personExist; QStringList personFailed; QStringList personNotFound; // forum QStringList forumFound; QStringList forumMsgFound; QStringList forumUnknown; QStringList forumMsgUnknown; // forum QStringList channelFound; QStringList channelMsgFound; QStringList channelUnknown; QStringList channelMsgUnknown; // search QStringList searchStarted; // message QStringList messageStarted; QStringList messageReceipientNotAccepted; QStringList messageReceipientUnknown; // Certificate QStringList GPGBase64Strings ; QStringList SSLIds ; // summary QList<QStringList*> processedList; QList<QStringList*> errorList; processedList << &fileAdded << &personAdded << &forumFound << &channelFound << &searchStarted << &messageStarted; errorList << &fileExist << &personExist << &personFailed << &personNotFound << &forumUnknown << &forumMsgUnknown << &channelUnknown << &channelMsgUnknown << &messageReceipientNotAccepted << &messageReceipientUnknown; // not needed: forumFound, channelFound, messageStarted for (linkIt = links.begin(); linkIt != links.end(); linkIt++) { const RetroShareLink &link = *linkIt; if (link.valid() == false) { std::cerr << " RetroShareLink::process invalid request" << std::endl; countInvalid++; continue; } switch (link.type()) { case TYPE_UNKNOWN: countUnknown++; break; case TYPE_CERTIFICATE: { #ifdef DEBUG_RSLINK std::cerr << " RetroShareLink::process certificate." << std::endl; #endif needNotifySuccess = true; QString RS_Certificate ; RS_Certificate += "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" ; RS_Certificate += "Version: Retroshare Generated cert.\n" ; RS_Certificate += "\n" ; QString radix = link.GPGRadix64Key() ; while(radix.size() > 64) { RS_Certificate += radix.left(64) + "\n" ; radix = radix.right(radix.size() - 64) ; } RS_Certificate += radix.left(64) + "\n" ; RS_Certificate += "=" + link.GPGBase64CheckSum() + "\n" ; RS_Certificate += "-----END PGP PUBLIC KEY BLOCK-----\n" ; RS_Certificate += "--SSLID--" + link.SSLId() + ";--LOCATION--" + link.location() + ";\n" ; if(!link.externalIPAndPort().isNull()) RS_Certificate += "--EXT--" + link.externalIPAndPort() + ";" ; if(!link.localIPAndPort().isNull()) RS_Certificate += "--LOCAL--" + link.localIPAndPort() + ";" ; RS_Certificate += "\n" ; std::cerr << "Usign this certificate:" << std::endl; std::cerr << RS_Certificate.toStdString() << std::endl; ConnectFriendWizard connectFriendWizard; connectFriendWizard.setCertificate(RS_Certificate, (link.subType() == RSLINK_SUBTYPE_CERTIFICATE_USER_REQUEST) ? true : false); connectFriendWizard.exec(); needNotifySuccess = false; } break ; case TYPE_FILE: { #ifdef DEBUG_RSLINK std::cerr << " RetroShareLink::process FileRequest : fileName : " << link.name().toUtf8().constData() << ". fileHash : " << link.hash().toStdString() << ". fileSize : " << link.size() << std::endl; #endif needNotifySuccess = true; // Get a list of available direct sources, in case the file is browsable only. std::list<std::string> srcIds; FileInfo finfo ; rsFiles->FileDetails(link.hash().toStdString(), RS_FILE_HINTS_REMOTE, finfo) ; for(std::list<TransferInfo>::const_iterator it(finfo.peers.begin()); it!=finfo.peers.end(); ++it) { #ifdef DEBUG_RSLINK std::cerr << " adding peerid " << (*it).peerId << std::endl ; #endif srcIds.push_back((*it).peerId) ; } if (rsFiles->FileRequest(link.name().toUtf8().constData(), link.hash().toStdString(), link.size(), "", RS_FILE_HINTS_NETWORK_WIDE, srcIds)) { fileAdded.append(link.name()); } else { fileExist.append(link.name()); } break; } case TYPE_PERSON: { #ifdef DEBUG_RSLINK std::cerr << " RetroShareLink::process FriendRequest : name : " << link.name().toStdString() << ". id : " << link.hash().toStdString() << std::endl; #endif needNotifySuccess = true; RsPeerDetails detail; if (rsPeers->getPeerDetails(link.hash().toStdString(), detail)) { if (detail.gpg_id == rsPeers->getGPGOwnId()) { // it's me, do nothing break; } if (detail.accept_connection) { // peer connection is already accepted personExist.append(PeerDefs::rsid(detail)); break; } if (rsPeers->addFriend("", link.hash().toStdString())) { ConfCertDialog::loadAll(); personAdded.append(PeerDefs::rsid(detail)); break; } personFailed.append(PeerDefs::rsid(link.name().toUtf8().constData(), link.hash().toStdString())); break; } personNotFound.append(PeerDefs::rsid(link.name().toUtf8().constData(), link.hash().toStdString())); break; } case TYPE_FORUM: { #ifdef DEBUG_RSLINK std::cerr << " RetroShareLink::process ForumRequest : name : " << link.name().toStdString() << ". id : " << link.hash().toStdString() << ". msgId : " << link.msgId().toStdString() << std::endl; #endif ForumInfo fi; if (!rsForums->getForumInfo(link.id().toStdString(), fi)) { if (link.msgId().isEmpty()) { forumUnknown.append(link.name()); } else { forumMsgUnknown.append(link.name()); } break; } ForumMsgInfo msg; if (!link.msgId().isEmpty()) { if (!rsForums->getForumMessage(fi.forumId, link.msgId().toStdString(), msg)) { forumMsgUnknown.append(link.name()); break; } } MainWindow::showWindow(MainWindow::Forums); ForumsDialog *forumsDialog = dynamic_cast<ForumsDialog*>(MainWindow::getPage(MainWindow::Forums)); if (!forumsDialog) { return false; } if (forumsDialog->navigate(fi.forumId, msg.msgId)) { if (link.msgId().isEmpty()) { forumFound.append(link.name()); } else { forumMsgFound.append(link.name()); } } else { if (link.msgId().isEmpty()) { forumUnknown.append(link.name()); } else { forumMsgUnknown.append(link.name()); } } break; } case TYPE_CHANNEL: { #ifdef DEBUG_RSLINK std::cerr << " RetroShareLink::process ChannelRequest : name : " << link.name().toStdString() << ". id : " << link.hash().toStdString() << ". msgId : " << link.msgId().toStdString() << std::endl; #endif ChannelInfo ci; if (!rsChannels->getChannelInfo(link.id().toStdString(), ci)) { if (link.msgId().isEmpty()) { channelUnknown.append(link.name()); } else { channelMsgUnknown.append(link.name()); } break; } ChannelMsgInfo msg; if (!link.msgId().isEmpty()) { if (!rsChannels->getChannelMessage(ci.channelId, link.msgId().toStdString(), msg)) { channelMsgUnknown.append(link.name()); break; } } MainWindow::showWindow(MainWindow::Channels); ChannelFeed *channelFeed = dynamic_cast<ChannelFeed*>(MainWindow::getPage(MainWindow::Channels)); if (!channelFeed) { return false; } if (channelFeed->navigate(ci.channelId, msg.msgId)) { if (link.msgId().isEmpty()) { channelFound.append(link.name()); } else { channelMsgFound.append(link.name()); } } else { if (link.msgId().isEmpty()) { channelUnknown.append(link.name()); } else { channelMsgUnknown.append(link.name()); } } break; } case TYPE_SEARCH: { #ifdef DEBUG_RSLINK std::cerr << " RetroShareLink::process SearchRequest : string : " << link.name().toStdString() << std::endl; #endif MainWindow::showWindow(MainWindow::Search); SearchDialog *searchDialog = dynamic_cast<SearchDialog*>(MainWindow::getPage(MainWindow::Search)); if (!searchDialog) { break; } searchDialog->searchKeywords(link.name()); searchStarted.append(link.name()); break; } case TYPE_MESSAGE: { #ifdef DEBUG_RSLINK std::cerr << " RetroShareLink::process MessageRequest : id : " << link.hash().toStdString() << ", subject : " << link.name().toStdString() << std::endl; #endif RsPeerDetails detail; if (rsPeers->getPeerDetails(link.hash().toStdString(), detail)) { if (detail.accept_connection || detail.id == rsPeers->getOwnId() || detail.id == rsPeers->getGPGOwnId()) { MessageComposer *msg = MessageComposer::newMsg(); msg->addRecipient(MessageComposer::TO, detail.id, false); if (link.subject().isEmpty() == false) { msg->setTitleText(link.subject()); } msg->show(); messageStarted.append(PeerDefs::nameWithLocation(detail)); } else { messageReceipientNotAccepted.append(PeerDefs::nameWithLocation(detail)); } } else { messageReceipientUnknown.append(PeerDefs::rsidFromId(link.hash().toStdString())); } break; } default: std::cerr << " RetroShareLink::process unknown type: " << link.type() << std::endl; countUnknown++; } } int countProcessed = 0; int countError = 0; QList<QStringList*>::iterator listIt; for (listIt = processedList.begin(); listIt != processedList.end(); ++listIt) { countProcessed += (*listIt)->size(); } for (listIt = errorList.begin(); listIt != errorList.end(); ++listIt) { countError += (*listIt)->size(); } // success notify needed ? if (needNotifySuccess == false) { flag &= ~RSLINK_PROCESS_NOTIFY_SUCCESS; } // error notify needed ? if (countError == 0) { flag &= ~RSLINK_PROCESS_NOTIFY_ERROR; } QString result; if (flag & (RSLINK_PROCESS_NOTIFY_SUCCESS | RSLINK_PROCESS_NOTIFY_ERROR)) { result += (links.count() == 1 ? QObject::tr("%1 of %2 RetroShare link processed.") : QObject::tr("%1 of %2 RetroShare links processed.")).arg(countProcessed).arg(links.count()) + "<br><br>"; } // file if (flag & RSLINK_PROCESS_NOTIFY_SUCCESS) { if (fileAdded.size()) { processList(fileAdded, QObject::tr("File added"), QObject::tr("Files added"), result); } } if (flag & RSLINK_PROCESS_NOTIFY_ERROR) { if (fileExist.size()) { processList(fileExist, QObject::tr("File exist"), QObject::tr("Files exist"), result); } } // person if (flag & RSLINK_PROCESS_NOTIFY_SUCCESS) { if (personAdded.size()) { processList(personAdded, QObject::tr("Friend added"), QObject::tr("Friends added"), result); } } if (flag & RSLINK_PROCESS_NOTIFY_ERROR) { if (personExist.size()) { processList(personExist, QObject::tr("Friend exist"), QObject::tr("Friends exist"), result); } if (personFailed.size()) { processList(personFailed, QObject::tr("Friend not added"), QObject::tr("Friends not added"), result); } if (personNotFound.size()) { processList(personNotFound, QObject::tr("Friend not found"), QObject::tr("Friends not found"), result); } } // forum if (flag & RSLINK_PROCESS_NOTIFY_ERROR) { if (forumUnknown.size()) { processList(forumUnknown, QObject::tr("Forum not found"), QObject::tr("Forums not found"), result); } if (forumMsgUnknown.size()) { processList(forumMsgUnknown, QObject::tr("Forum message not found"), QObject::tr("Forum messages not found"), result); } } // channel if (flag & RSLINK_PROCESS_NOTIFY_ERROR) { if (channelUnknown.size()) { processList(channelUnknown, QObject::tr("Channel not found"), QObject::tr("Channels not found"), result); } if (channelMsgUnknown.size()) { processList(channelMsgUnknown, QObject::tr("Channel message not found"), QObject::tr("Channel messages not found"), result); } } // message if (flag & RSLINK_PROCESS_NOTIFY_ERROR) { if (messageReceipientNotAccepted.size()) { processList(messageReceipientNotAccepted, QObject::tr("Recipient not accepted"), QObject::tr("Recipients not accepted"), result); } if (messageReceipientUnknown.size()) { processList(messageReceipientUnknown, QObject::tr("Unkown recipient"), QObject::tr("Unkown recipients"), result); } } if (flag & RSLINK_PROCESS_NOTIFY_ERROR) { if (countUnknown) { result += QString("<br>%1: %2").arg(QObject::tr("Malformed links")).arg(countUnknown); } if (countInvalid) { result += QString("<br>%1: %2").arg(QObject::tr("Invalid links")).arg(countInvalid); } } if (result.isEmpty() == false) { QMessageBox mb(QObject::tr("Result"), "<html><body>" + result + "</body></html>", QMessageBox::Information, QMessageBox::Ok, 0, 0); mb.setWindowIcon(QIcon(QString::fromUtf8(":/images/rstray3.png"))); mb.exec(); } return 0; }