diff --git a/retroshare-gui/src/gui/Identity/IdDialog.cpp b/retroshare-gui/src/gui/Identity/IdDialog.cpp index 25db8896d..4b28a1b09 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdDialog.cpp @@ -2240,165 +2240,202 @@ void IdDialog::loadRequest(const TokenQueue * queue, const TokenRequest &req) void IdDialog::IdListCustomPopupMenu( QPoint ) { - QMenu *contextMenu = new QMenu(this); + QMenu *contextMenu = new QMenu(this); - std::list own_identities ; - rsIdentity->getOwnIds(own_identities) ; + std::list own_identities ; + rsIdentity->getOwnIds(own_identities) ; - // make some stats about what's selected. If the same value is used for all selected items, it can be switched. + // make some stats about what's selected. If the same value is used for all selected items, it can be switched. - QList selected_items = ui->idTreeWidget->selectedItems(); + QList selected_items = ui->idTreeWidget->selectedItems(); - bool root_node_present = false ; - bool one_item_owned_by_you = false ; - uint32_t n_positive_reputations = 0 ; - uint32_t n_negative_reputations = 0 ; - uint32_t n_neutral_reputations = 0 ; - uint32_t n_is_a_contact = 0 ; - uint32_t n_is_not_a_contact = 0 ; - uint32_t n_selected_items =0 ; + bool root_node_present = false ; + bool one_item_owned_by_you = false ; + uint32_t n_positive_reputations = 0 ; + uint32_t n_negative_reputations = 0 ; + uint32_t n_neutral_reputations = 0 ; + uint32_t n_is_a_contact = 0 ; + uint32_t n_is_not_a_contact = 0 ; + uint32_t n_selected_items =0 ; - for(QList::const_iterator it(selected_items.begin());it!=selected_items.end();++it) - { - if(*it == allItem || *it == contactsItem || *it == ownItem) - { - root_node_present = true ; - continue ; - } - - uint32_t item_flags = (*it)->data(RSID_COL_KEYID,Qt::UserRole).toUInt() ; - - if(item_flags & RSID_FILTER_OWNED_BY_YOU) - one_item_owned_by_you = true ; - -#ifdef ID_DEBUG - std::cerr << " item flags = " << item_flags << std::endl; -#endif - RsGxsId keyId((*it)->text(RSID_COL_KEYID).toStdString()); - - RsIdentityDetails det ; - rsIdentity->getIdDetails(keyId,det) ; - - switch(det.mReputation.mOwnOpinion) - { - case RsReputations::OPINION_NEGATIVE: ++n_negative_reputations ; - break ; - - case RsReputations::OPINION_POSITIVE: ++n_positive_reputations ; - break ; - - case RsReputations::OPINION_NEUTRAL: ++n_neutral_reputations ; - break ; - } - - ++n_selected_items ; - - if(rsIdentity->isARegularContact(keyId)) - ++n_is_a_contact ; - else - ++n_is_not_a_contact ; - } - - if(!root_node_present) // don't show menu if some of the root nodes are present + for(QList::const_iterator it(selected_items.begin());it!=selected_items.end();++it) + { + if(*it == allItem || *it == contactsItem || *it == ownItem) { - - if(!one_item_owned_by_you) - { - QWidget *widget = new QWidget(contextMenu); - widget->setStyleSheet( ".QWidget{background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,stop:0 #FEFEFE, stop:1 #E8E8E8); border: 1px solid #CCCCCC;}"); - - // create menu header - QHBoxLayout *hbox = new QHBoxLayout(widget); - hbox->setMargin(0); - hbox->setSpacing(6); - - QLabel *iconLabel = new QLabel(widget); - QPixmap pix = QPixmap(":/images/user/friends24.png").scaledToHeight(QFontMetricsF(iconLabel->font()).height()*1.5); - iconLabel->setPixmap(pix); - iconLabel->setMaximumSize(iconLabel->frameSize().height() + pix.height(), pix.width()); - hbox->addWidget(iconLabel); - - QLabel *textLabel = new QLabel("" + ui->titleBarLabel->text() + "", widget); - hbox->addWidget(textLabel); - - QSpacerItem *spacerItem = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); - hbox->addItem(spacerItem); - - widget->setLayout(hbox); - - QWidgetAction *widgetAction = new QWidgetAction(this); - widgetAction->setDefaultWidget(widget); - contextMenu->addAction(widgetAction); - - if(n_selected_items == 1) // if only one item is selected, allow to chat with this item - { - if(own_identities.size() <= 1) - { - QAction *action = contextMenu->addAction(QIcon(":/images/chat_24.png"), tr("Chat with this person"), this, SLOT(chatIdentity())); - - if(own_identities.empty()) - action->setEnabled(false) ; - else - action->setData(QString::fromStdString((own_identities.front()).toStdString())) ; - } - else - { - QMenu *mnu = contextMenu->addMenu(QIcon(":/images/chat_24.png"),tr("Chat with this person as...")) ; - - for(std::list::const_iterator it=own_identities.begin();it!=own_identities.end();++it) - { - RsIdentityDetails idd ; - rsIdentity->getIdDetails(*it,idd) ; - - QPixmap pixmap ; - - if(idd.mAvatar.mSize == 0 || !pixmap.loadFromData(idd.mAvatar.mData, idd.mAvatar.mSize, "PNG")) - pixmap = QPixmap::fromImage(GxsIdDetails::makeDefaultIcon(*it)) ; - - QAction *action = mnu->addAction(QIcon(pixmap), QString("%1 (%2)").arg(QString::fromUtf8(idd.mNickname.c_str()), QString::fromStdString((*it).toStdString())), this, SLOT(chatIdentity())); - action->setData(QString::fromStdString((*it).toStdString())) ; - } - } - } - - // always allow to send messages - contextMenu->addAction(QIcon(":/images/mail_new.png"), tr("Send message"), this, SLOT(sendMsg())); - - contextMenu->addSeparator(); - - if(n_is_a_contact == 0) - contextMenu->addAction(QIcon(), tr("Add to Contacts"), this, SLOT(addtoContacts())); - - if(n_is_not_a_contact == 0) - contextMenu->addAction(QIcon(":/images/cancel.png"), tr("Remove from Contacts"), this, SLOT(removefromContacts())); - - contextMenu->addSeparator(); - - if(n_positive_reputations == 0) // only unban when all items are banned - contextMenu->addAction(QIcon(":/icons/png/thumbs-up.png"), tr("Set positive opinion"), this, SLOT(positivePerson())); - - if(n_neutral_reputations == 0) // only unban when all items are banned - contextMenu->addAction(QIcon(":/icons/png/thumbs-neutral.png"), tr("Set neutral opinion"), this, SLOT(neutralPerson())); - - if(n_negative_reputations == 0) - contextMenu->addAction(QIcon(":/icons/png/thumbs-down.png"), tr("Set negative opinion"), this, SLOT(negativePerson())); - } - - if(one_item_owned_by_you && n_selected_items==1) - { - contextMenu->addSeparator(); - - contextMenu->addAction(ui->editIdentity); - contextMenu->addAction(ui->removeIdentity); - } - + root_node_present = true ; + continue ; } - contextMenu = ui->idTreeWidget->createStandardContextMenu(contextMenu); + uint32_t item_flags = (*it)->data(RSID_COL_KEYID,Qt::UserRole).toUInt() ; - contextMenu->exec(QCursor::pos()); - delete contextMenu; + if(item_flags & RSID_FILTER_OWNED_BY_YOU) + one_item_owned_by_you = true ; + +#ifdef ID_DEBUG + std::cerr << " item flags = " << item_flags << std::endl; +#endif + RsGxsId keyId((*it)->text(RSID_COL_KEYID).toStdString()); + + RsIdentityDetails det ; + rsIdentity->getIdDetails(keyId,det) ; + + switch(det.mReputation.mOwnOpinion) + { + case RsReputations::OPINION_NEGATIVE: ++n_negative_reputations ; + break ; + + case RsReputations::OPINION_POSITIVE: ++n_positive_reputations ; + break ; + + case RsReputations::OPINION_NEUTRAL: ++n_neutral_reputations ; + break ; + } + + ++n_selected_items ; + + if(rsIdentity->isARegularContact(keyId)) + ++n_is_a_contact ; + else + ++n_is_not_a_contact ; + } + + if(!root_node_present) // don't show menu if some of the root nodes are present + { + + if(!one_item_owned_by_you) + { + QWidget *widget = new QWidget(contextMenu); + widget->setStyleSheet( ".QWidget{background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,stop:0 #FEFEFE, stop:1 #E8E8E8); border: 1px solid #CCCCCC;}"); + + // create menu header + QHBoxLayout *hbox = new QHBoxLayout(widget); + hbox->setMargin(0); + hbox->setSpacing(6); + + QLabel *iconLabel = new QLabel(widget); + QPixmap pix = QPixmap(":/images/user/friends24.png").scaledToHeight(QFontMetricsF(iconLabel->font()).height()*1.5); + iconLabel->setPixmap(pix); + iconLabel->setMaximumSize(iconLabel->frameSize().height() + pix.height(), pix.width()); + hbox->addWidget(iconLabel); + + QLabel *textLabel = new QLabel("" + ui->titleBarLabel->text() + "", widget); + hbox->addWidget(textLabel); + + QSpacerItem *spacerItem = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); + hbox->addItem(spacerItem); + + widget->setLayout(hbox); + + QWidgetAction *widgetAction = new QWidgetAction(this); + widgetAction->setDefaultWidget(widget); + contextMenu->addAction(widgetAction); + + if(n_selected_items == 1) // if only one item is selected, allow to chat with this item + { + if(own_identities.size() <= 1) + { + QAction *action = contextMenu->addAction(QIcon(":/images/chat_24.png"), tr("Chat with this person"), this, SLOT(chatIdentity())); + + if(own_identities.empty()) + action->setEnabled(false) ; + else + action->setData(QString::fromStdString((own_identities.front()).toStdString())) ; + } + else + { + QMenu *mnu = contextMenu->addMenu(QIcon(":/images/chat_24.png"),tr("Chat with this person as...")) ; + + for(std::list::const_iterator it=own_identities.begin();it!=own_identities.end();++it) + { + RsIdentityDetails idd ; + rsIdentity->getIdDetails(*it,idd) ; + + QPixmap pixmap ; + + if(idd.mAvatar.mSize == 0 || !pixmap.loadFromData(idd.mAvatar.mData, idd.mAvatar.mSize, "PNG")) + pixmap = QPixmap::fromImage(GxsIdDetails::makeDefaultIcon(*it)) ; + + QAction *action = mnu->addAction(QIcon(pixmap), QString("%1 (%2)").arg(QString::fromUtf8(idd.mNickname.c_str()), QString::fromStdString((*it).toStdString())), this, SLOT(chatIdentity())); + action->setData(QString::fromStdString((*it).toStdString())) ; + } + } + } + + if(n_selected_items==1) + QAction *action = contextMenu->addAction(QIcon(":/images/chat_24.png"),tr("Copy retroshare link"),this,SLOT(copyRetroshareLink())) ; + + // always allow to send messages + contextMenu->addAction(QIcon(":/images/mail_new.png"), tr("Send message"), this, SLOT(sendMsg())); + + contextMenu->addSeparator(); + + if(n_is_a_contact == 0) + contextMenu->addAction(QIcon(), tr("Add to Contacts"), this, SLOT(addtoContacts())); + + if(n_is_not_a_contact == 0) + contextMenu->addAction(QIcon(":/images/cancel.png"), tr("Remove from Contacts"), this, SLOT(removefromContacts())); + + contextMenu->addSeparator(); + + if(n_positive_reputations == 0) // only unban when all items are banned + contextMenu->addAction(QIcon(":/icons/png/thumbs-up.png"), tr("Set positive opinion"), this, SLOT(positivePerson())); + + if(n_neutral_reputations == 0) // only unban when all items are banned + contextMenu->addAction(QIcon(":/icons/png/thumbs-neutral.png"), tr("Set neutral opinion"), this, SLOT(neutralPerson())); + + if(n_negative_reputations == 0) + contextMenu->addAction(QIcon(":/icons/png/thumbs-down.png"), tr("Set negative opinion"), this, SLOT(negativePerson())); + } + + if(one_item_owned_by_you && n_selected_items==1) + { + contextMenu->addSeparator(); + + contextMenu->addAction(ui->editIdentity); + contextMenu->addAction(ui->removeIdentity); + } + + } + + contextMenu = ui->idTreeWidget->createStandardContextMenu(contextMenu); + + contextMenu->exec(QCursor::pos()); + delete contextMenu; +} + +void IdDialog::copyRetroshareLink() +{ + QTreeWidgetItem *item = ui->idTreeWidget->currentItem(); + + if (!item) + { + std::cerr << "IdDialog::editIdentity() Invalid item"; + std::cerr << std::endl; + return; + } + + std::string keyId = item->text(RSID_COL_KEYID).toStdString(); + + RsIdentityDetails details ; + + if(! rsIdentity->getIdDetails(RsGxsId(keyId),details)) + return ; + + std::string radix ; + if(!rsIdentity->serialiseIdentityToMemory(details.mId,radix)) + { + std::cerr << "(EE) Cannot get radix data for key " << keyId << std::endl; + return; + } + QList urls ; + + RetroShareLink link ; + link.createIdentity(RsGxsId(keyId),QString::fromUtf8(details.mNickname.c_str()),QString::fromStdString(radix)) ; + + RSLinkClipboard::copyLinks(urls) ; + + QMessageBox::information(NULL,tr("information"),tr("This identity link was copied to your clipboard. Paste it in a mail, or a message to transmit the identity to someone.")) ; } void IdDialog::chatIdentity() diff --git a/retroshare-gui/src/gui/Identity/IdDialog.h b/retroshare-gui/src/gui/Identity/IdDialog.h index a44d83677..64ab756af 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.h +++ b/retroshare-gui/src/gui/Identity/IdDialog.h @@ -93,6 +93,7 @@ private slots: void editIdentity(); void chatIdentity(); void sendMsg(); + void copyRetroshareLink(); void on_closeInfoFrameButton_clicked(); void updateSelection(); diff --git a/retroshare-gui/src/gui/RetroShareLink.cpp b/retroshare-gui/src/gui/RetroShareLink.cpp index 957b61f7f..a2075aa24 100644 --- a/retroshare-gui/src/gui/RetroShareLink.cpp +++ b/retroshare-gui/src/gui/RetroShareLink.cpp @@ -67,7 +67,8 @@ #define HOST_SEARCH "search" #define HOST_CERTIFICATE "certificate" #define HOST_PUBLIC_MSG "public_msg" -#define HOST_REGEXP "file|extra|person|forum|channel|posted|search|message|certificate|private_chat|public_msg" +#define HOST_IDENTITY "identity" +#define HOST_REGEXP "file|extra|person|forum|channel|posted|search|message|certificate|private_chat|public_msg|identity" #define FILE_NAME "name" #define FILE_SIZE "size" @@ -89,6 +90,9 @@ #define POSTED_ID "id" #define POSTED_MSGID "msgid" +#define IDENTITY_NAME "name" +#define IDENTITY_ID "gxsid" +#define IDENTITY_GROUP "groupdata" #define MESSAGE_ID "id" #define MESSAGE_SUBJECT "subject" @@ -333,6 +337,21 @@ RetroShareLink::RetroShareLink() clear(); } +bool RetroShareLink::createIdentity(const RsGxsId& id, const QString& name, const QString& radix_data) +{ + clear(); + + _name = name; + _hash = QString::fromStdString(id.toStdString()); + _radix_group_data = radix_data ; + + _type = TYPE_IDENTITY; + + check(); + + return valid(); +} + bool RetroShareLink::createExtraFile(const QString& name, uint64_t size, const QString& hash,const QString& ssl_id) { clear(); @@ -534,6 +553,7 @@ void RetroShareLink::clear() _GPGid = "" ; _time_stamp = 0 ; _encrypted_chat_info = "" ; + _radix_group_data = "" ; } void RetroShareLink::check() @@ -565,6 +585,17 @@ void RetroShareLink::check() if(!checkPGPId(_GPGid)) _valid = false ; break ; + case TYPE_IDENTITY: + if(_name.isNull()) + _valid = false ; + + if(_radix_group_data.isNull()) + _valid = false ; + + if(_hash.isNull()) + _valid = false ; + break ; + case TYPE_PERSON: if(_size != 0) _valid = false; @@ -651,6 +682,9 @@ QString RetroShareLink::title() const return QObject::tr("%1 (%2, Extra - Source included)").arg(hash()).arg(misc::friendlyUnit(size())); case TYPE_FILE: return QString("%1 (%2)").arg(hash()).arg(misc::friendlyUnit(size())); + case TYPE_IDENTITY: + return _name ; + case TYPE_PERSON: return PeerDefs::rsidFromId(RsPgpId(hash().toStdString())); case TYPE_FORUM: @@ -711,6 +745,14 @@ QString RetroShareLink::toString() const break; + case TYPE_IDENTITY: + url.setScheme(RSLINK_SCHEME) ; + url.setHost(HOST_IDENTITY) ; + urlQuery.addQueryItem(IDENTITY_ID,_hash) ; + urlQuery.addQueryItem(IDENTITY_NAME,encodeItem(_name)) ; + urlQuery.addQueryItem(IDENTITY_GROUP,_radix_group_data) ; + break ; + case TYPE_EXTRAFILE: url.setScheme(RSLINK_SCHEME); url.setHost(HOST_EXTRAFILE); @@ -798,9 +840,11 @@ QString RetroShareLink::toString() const QString RetroShareLink::niceName() const { - if (type() == TYPE_PERSON) { + if (type() == TYPE_PERSON) return PeerDefs::rsid(name().toUtf8().constData(), RsPgpId(hash().toStdString())); - } + + if(type() == TYPE_IDENTITY) + return QObject::tr("Click this link to add this person (name=%1, ID=%2) to your People tab.").arg(_name).arg(_hash) ; if(type() == TYPE_PUBLIC_MSG) { RsPeerDetails detail; @@ -1156,6 +1200,15 @@ static void processList(const QStringList &list, const QString &textSingular, co } break ; + case TYPE_IDENTITY: + { + if(rsIdentity->deserialiseIdentityFromMemory(link.radixGroupData().toStdString())) + QMessageBox::information(NULL,QObject::tr("Identity added to People"),QObject::tr("The identity was added to people. You can now chat with it, send messages to it, etc.")) ; + else + QMessageBox::warning(NULL,QObject::tr("Identity cannot be added to People"),QObject::tr("The identity was not added to people. Some error occured. The link is probably corrupted.")) ; + } + break; + case TYPE_FILE: case TYPE_EXTRAFILE: { diff --git a/retroshare-gui/src/gui/RetroShareLink.h b/retroshare-gui/src/gui/RetroShareLink.h index d1390d18d..b272f3416 100644 --- a/retroshare-gui/src/gui/RetroShareLink.h +++ b/retroshare-gui/src/gui/RetroShareLink.h @@ -68,7 +68,8 @@ class RetroShareLink TYPE_EXTRAFILE = 0x08, TYPE_PRIVATE_CHAT = 0x09, TYPE_PUBLIC_MSG = 0x0a, - TYPE_POSTED = 0x0b + TYPE_POSTED = 0x0b, + TYPE_IDENTITY = 0x0c }; public: @@ -85,6 +86,7 @@ class RetroShareLink bool createSearch(const QString& keywords); bool createMessage(const RsPeerId &peerId, const QString& subject); bool createMessage(const RsGxsId &peerId, const QString& subject); + bool createIdentity(const RsGxsId& gxs_id,const QString& name,const QString& radix_data) ; bool createCertificate(const RsPeerId &ssl_id) ; bool createPublicMsgInvite(time_t time_stamp,const QString& pgp_id,const QString& hash) ; bool createUnknwonSslCertificate(const RsPeerId &sslId, const RsPgpId &gpgId = RsPgpId()) ; @@ -101,12 +103,13 @@ class RetroShareLink const QString& SSLId() const { return _SSLid ; } const QString& GPGId() const { return _GPGid ; } const QString& localIPAndPort() const { return _loc_ip_port ; } - const QString& externalIPAndPort() const { return _ext_ip_port ; } - const QString& dyndns() const { return _dyndns_name ; } - const QString& location() const { return _location ; } - const QString& radix() const { return _radix ; } - time_t timeStamp() const { return _time_stamp ; } - QString title() const; + const QString& externalIPAndPort() const { return _ext_ip_port ; } + const QString& dyndns() const { return _dyndns_name ; } + const QString& location() const { return _location ; } + const QString& radix() const { return _radix ; } + time_t timeStamp() const { return _time_stamp ; } + QString title() const; + QString radixGroupData() const { return _radix_group_data ;} unsigned int subType() const { return _subType; } void setSubType(unsigned int subType) { _subType = subType; } @@ -158,12 +161,13 @@ class RetroShareLink QString _GPGBase64String ; // GPG Cert QString _GPGBase64CheckSum ; // GPG Cert QString _location ; // location - QString _ext_ip_port ; - QString _loc_ip_port ; - QString _dyndns_name ; + QString _ext_ip_port ; + QString _loc_ip_port ; + QString _dyndns_name ; QString _radix ; - QString _encrypted_chat_info ; // encrypted data string for the recipient of a chat invite - time_t _time_stamp ; // time stamp at which the link will expire. + QString _encrypted_chat_info ; // encrypted data string for the recipient of a chat invite + time_t _time_stamp ; // time stamp at which the link will expire. + QString _radix_group_data; unsigned int _subType; // for general use as sub type for _type (RSLINK_SUBTYPE_...) };