From d71d26f026f174045d8d7dbddf77b96426d014e8 Mon Sep 17 00:00:00 2001 From: thunder2 Date: Thu, 11 Jun 2015 08:08:10 +0000 Subject: [PATCH] Fixed crash in context menu of the id list in IdDialog when no row is active. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8410 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/gui/Identity/IdDialog.cpp | 63 ++++++++++---------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/retroshare-gui/src/gui/Identity/IdDialog.cpp b/retroshare-gui/src/gui/Identity/IdDialog.cpp index 5b0cbe484..f323198cb 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdDialog.cpp @@ -1008,46 +1008,47 @@ void IdDialog::IdListCustomPopupMenu( QPoint ) QMenu contextMnu( this ); - std::list own_identities ; - rsIdentity->getOwnIds(own_identities) ; + std::list own_identities ; + rsIdentity->getOwnIds(own_identities) ; - QTreeWidgetItem *item = ui->treeWidget_IdList->currentItem(); - uint32_t item_flags = item->data(RSID_COL_KEYID,Qt::UserRole).toUInt() ; + QTreeWidgetItem *item = ui->treeWidget_IdList->currentItem(); + if (item) { + uint32_t item_flags = item->data(RSID_COL_KEYID,Qt::UserRole).toUInt() ; - if(!(item_flags & RSID_FILTER_OWNED_BY_YOU)) - { - if(own_identities.size() <= 1) - { - QAction *action = contextMnu.addAction(QIcon(":/images/chat_24.png"), tr("Chat with this person"), this, SLOT(chatIdentity())); + if(!(item_flags & RSID_FILTER_OWNED_BY_YOU)) + { + if(own_identities.size() <= 1) + { + QAction *action = contextMnu.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 = contextMnu.addMenu(QIcon(":/images/chat_24.png"),tr("Chat with this person as...")) ; - if(own_identities.empty()) - action->setEnabled(false) ; - else - action->setData(QString::fromStdString((own_identities.front()).toStdString())) ; - } - else - { - QMenu *mnu = contextMnu.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) ; - for(std::list::const_iterator it=own_identities.begin();it!=own_identities.end();++it) - { - RsIdentityDetails idd ; - rsIdentity->getIdDetails(*it,idd) ; + QPixmap pixmap ; - QPixmap pixmap ; + if(idd.mAvatar.mSize == 0 || !pixmap.loadFromData(idd.mAvatar.mData, idd.mAvatar.mSize, "PNG")) + pixmap = QPixmap::fromImage(GxsIdDetails::makeDefaultIcon(*it)) ; - 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())) ; + } + } - 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())) ; - } - } + contextMnu.addAction(QIcon(":/images/mail_new.png"), tr("Send message to this person"), this, SLOT(sendMsg())); + } + } - contextMnu.addAction(QIcon(":/images/mail_new.png"), tr("Send message to this person"), this, SLOT(sendMsg())); - } - contextMnu.addSeparator(); contextMnu.addAction(ui->editIdentity);