Yingdi Yu | d59b593 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2013, Regents of the University of California |
| 4 | * Yingdi Yu |
| 5 | * |
| 6 | * BSD license, See the LICENSE file for more information |
| 7 | * |
| 8 | * Author: Yingdi Yu <yingdi@cs.ucla.edu> |
| 9 | */ |
| 10 | |
Yingdi Yu | a489875 | 2013-10-15 20:31:37 -0700 | [diff] [blame] | 11 | #include "addcontactpanel.h" |
| 12 | #include "ui_addcontactpanel.h" |
Yingdi Yu | eb98f7d | 2013-11-10 01:34:57 -0800 | [diff] [blame] | 13 | #include <QMessageBox> |
Yingdi Yu | a489875 | 2013-10-15 20:31:37 -0700 | [diff] [blame] | 14 | |
Yingdi Yu | c29fb98 | 2013-10-20 19:43:10 -0700 | [diff] [blame] | 15 | #ifndef Q_MOC_RUN |
Yingdi Yu | 6df6125 | 2014-01-21 11:05:11 -0800 | [diff] [blame^] | 16 | #include <ndn-cpp-dev/security/verifier.hpp> |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 17 | #include <boost/iostreams/stream.hpp> |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 18 | #include "endorse-collection.pb.h" |
Yingdi Yu | c29fb98 | 2013-10-20 19:43:10 -0700 | [diff] [blame] | 19 | #include "logging.h" |
| 20 | #endif |
| 21 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 22 | using namespace ndn; |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 23 | using namespace ndn::ptr_lib; |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 24 | using namespace std; |
| 25 | |
Yingdi Yu | c29fb98 | 2013-10-20 19:43:10 -0700 | [diff] [blame] | 26 | INIT_LOGGER("AddContactPanel"); |
| 27 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 28 | AddContactPanel::AddContactPanel(shared_ptr<ContactManager> contactManager, |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 29 | QWidget *parent) |
Yingdi Yu | d59b593 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 30 | : QDialog(parent) |
| 31 | , ui(new Ui::AddContactPanel) |
Yingdi Yu | 0b82a4e | 2013-10-18 11:29:25 -0700 | [diff] [blame] | 32 | , m_contactManager(contactManager) |
Yingdi Yu | c29fb98 | 2013-10-20 19:43:10 -0700 | [diff] [blame] | 33 | , m_warningDialog(new WarningDialog()) |
Yingdi Yu | a489875 | 2013-10-15 20:31:37 -0700 | [diff] [blame] | 34 | { |
Yingdi Yu | d59b593 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 35 | ui->setupUi(this); |
Yingdi Yu | c29fb98 | 2013-10-20 19:43:10 -0700 | [diff] [blame] | 36 | |
| 37 | qRegisterMetaType<ndn::Name>("NdnName"); |
| 38 | qRegisterMetaType<EndorseCertificate>("EndorseCertificate"); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 39 | qRegisterMetaType<ndn::Data>("NdnData"); |
Yingdi Yu | d59b593 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 40 | |
| 41 | connect(ui->cancelButton, SIGNAL(clicked()), |
| 42 | this, SLOT(onCancelClicked())); |
| 43 | connect(ui->searchButton, SIGNAL(clicked()), |
| 44 | this, SLOT(onSearchClicked())); |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 45 | connect(ui->addButton, SIGNAL(clicked()), |
| 46 | this, SLOT(onAddClicked())); |
| 47 | connect(&*m_contactManager, SIGNAL(contactFetched(const EndorseCertificate&)), |
| 48 | this, SLOT(selfEndorseCertificateFetched(const EndorseCertificate&))); |
Yingdi Yu | c29fb98 | 2013-10-20 19:43:10 -0700 | [diff] [blame] | 49 | connect(&*m_contactManager, SIGNAL(contactFetchFailed(const ndn::Name&)), |
| 50 | this, SLOT(selfEndorseCertificateFetchFailed(const ndn::Name&))); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 51 | connect(&*m_contactManager, SIGNAL(collectEndorseFetched(const ndn::Data&)), |
| 52 | this, SLOT(onCollectEndorseFetched(const ndn::Data&))); |
| 53 | connect(&*m_contactManager, SIGNAL(collectEndorseFetchFailed(const ndn::Name&)), |
| 54 | this, SLOT(onCollectEndorseFetchFailed(const ndn::Name&))); |
| 55 | connect(&*m_contactManager, SIGNAL(contactKeyFetched(const EndorseCertificate&)), |
| 56 | this, SLOT(onContactKeyFetched(const EndorseCertificate&))); |
| 57 | connect(&*m_contactManager, SIGNAL(contactKeyFetchFailed(const ndn::Name&)), |
| 58 | this, SLOT(onContactKeyFetchFailed(const ndn::Name&))); |
| 59 | |
| 60 | |
Yingdi Yu | a489875 | 2013-10-15 20:31:37 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | AddContactPanel::~AddContactPanel() |
| 64 | { |
| 65 | delete ui; |
Yingdi Yu | c29fb98 | 2013-10-20 19:43:10 -0700 | [diff] [blame] | 66 | delete m_warningDialog; |
Yingdi Yu | a489875 | 2013-10-15 20:31:37 -0700 | [diff] [blame] | 67 | } |
Yingdi Yu | d59b593 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 68 | |
| 69 | void |
| 70 | AddContactPanel::onCancelClicked() |
| 71 | { this->close(); } |
| 72 | |
| 73 | void |
| 74 | AddContactPanel::onSearchClicked() |
| 75 | { |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 76 | m_currentEndorseCertificateReady = false; |
| 77 | m_currentCollectEndorseReady = false; |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 78 | ui->infoView->clear(); |
| 79 | for(int i = ui->infoView->rowCount() - 1; i >= 0 ; i--) |
| 80 | ui->infoView->removeRow(i); |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 81 | QString inputIdentity = ui->contactInput->text(); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 82 | m_searchIdentity = Name(inputIdentity.toStdString()); |
Yingdi Yu | c29fb98 | 2013-10-20 19:43:10 -0700 | [diff] [blame] | 83 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 84 | if(Qt::Checked == ui->fetchBox->checkState()) |
| 85 | { |
| 86 | m_contactManager->fetchSelfEndorseCertificate(m_searchIdentity); |
| 87 | m_contactManager->fetchCollectEndorse(m_searchIdentity); |
| 88 | } |
| 89 | else |
| 90 | { |
| 91 | if(isCorrectName(m_searchIdentity)) |
| 92 | m_contactManager->fetchKey(m_searchIdentity); |
| 93 | else |
| 94 | { |
Yingdi Yu | eb98f7d | 2013-11-10 01:34:57 -0800 | [diff] [blame] | 95 | QMessageBox::information(this, tr("Chronos"), QString::fromStdString("Wrong key certificate name!")); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | bool |
| 101 | AddContactPanel::isCorrectName(const Name& name) |
| 102 | { |
| 103 | string key("KEY"); |
| 104 | string idCert("ID-CERT"); |
| 105 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 106 | if(name.get(-1).toEscapedString() != idCert) |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 107 | return false; |
| 108 | |
| 109 | int keyIndex = -1; |
| 110 | for(int i = 0; i < name.size(); i++) |
| 111 | { |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 112 | if(name.get(i).toEscapedString() == key) |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 113 | { |
| 114 | keyIndex = i; |
| 115 | break; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | if(keyIndex < 0) |
| 120 | return false; |
| 121 | else |
| 122 | return true; |
Yingdi Yu | d59b593 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | void |
| 126 | AddContactPanel::onAddClicked() |
| 127 | { |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 128 | ContactItem contactItem(*m_currentEndorseCertificate); |
Yingdi Yu | 6a5b9f6 | 2013-11-06 23:00:21 -0800 | [diff] [blame] | 129 | try{ |
| 130 | m_contactManager->getContactStorage()->addContact(contactItem); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 131 | }catch(std::exception& e){ |
Yingdi Yu | eb98f7d | 2013-11-10 01:34:57 -0800 | [diff] [blame] | 132 | QMessageBox::information(this, tr("Chronos"), QString::fromStdString(e.what())); |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 133 | _LOG_ERROR("Exception: " << e.what()); |
Yingdi Yu | 6a5b9f6 | 2013-11-06 23:00:21 -0800 | [diff] [blame] | 134 | return; |
| 135 | } |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 136 | emit newContactAdded(); |
| 137 | this->close(); |
Yingdi Yu | d59b593 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 140 | void |
Yingdi Yu | c29fb98 | 2013-10-20 19:43:10 -0700 | [diff] [blame] | 141 | AddContactPanel::selfEndorseCertificateFetched(const EndorseCertificate& endorseCertificate) |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 142 | { |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 143 | try{ |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 144 | m_currentEndorseCertificate = make_shared<EndorseCertificate>(endorseCertificate); |
| 145 | }catch(std::exception& e){ |
Yingdi Yu | eb98f7d | 2013-11-10 01:34:57 -0800 | [diff] [blame] | 146 | QMessageBox::information(this, tr("Chronos"), QString::fromStdString(e.what())); |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 147 | _LOG_ERROR("Exception: " << e.what()); |
| 148 | return; |
| 149 | } |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 150 | m_currentEndorseCertificateReady = true; |
| 151 | |
| 152 | if(m_currentCollectEndorseReady == true) |
| 153 | displayContactInfo(); |
Yingdi Yu | c29fb98 | 2013-10-20 19:43:10 -0700 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | void |
| 157 | AddContactPanel::selfEndorseCertificateFetchFailed(const Name& identity) |
| 158 | { |
Yingdi Yu | eb98f7d | 2013-11-10 01:34:57 -0800 | [diff] [blame] | 159 | QMessageBox::information(this, tr("Chronos"), QString::fromStdString("Cannot fetch contact profile")); |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 162 | void |
| 163 | AddContactPanel::onContactKeyFetched(const EndorseCertificate& endorseCertificate) |
| 164 | { |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 165 | try{ |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 166 | m_currentEndorseCertificate = make_shared<EndorseCertificate>(endorseCertificate); |
| 167 | }catch(std::exception& e){ |
Yingdi Yu | eb98f7d | 2013-11-10 01:34:57 -0800 | [diff] [blame] | 168 | QMessageBox::information(this, tr("Chronos"), QString::fromStdString(e.what())); |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 169 | _LOG_ERROR("Exception: " << e.what()); |
| 170 | return; |
| 171 | } |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 172 | |
Alexander Afanasyev | 4f04c55 | 2013-11-07 15:30:05 -0800 | [diff] [blame] | 173 | m_currentCollectEndorseReady = false; |
Yingdi Yu | e9ea5c9 | 2013-11-06 18:42:34 -0800 | [diff] [blame] | 174 | |
| 175 | displayContactInfo(); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | void |
| 179 | AddContactPanel::onContactKeyFetchFailed(const Name& identity) |
| 180 | { |
Yingdi Yu | eb98f7d | 2013-11-10 01:34:57 -0800 | [diff] [blame] | 181 | QMessageBox::information(this, tr("Chronos"), QString::fromStdString("Cannot fetch contact ksk certificate")); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | void |
| 185 | AddContactPanel::onCollectEndorseFetched(const Data& data) |
| 186 | { |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 187 | m_currentCollectEndorse = make_shared<Data>(data); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 188 | m_currentCollectEndorseReady = true; |
| 189 | |
| 190 | if(m_currentEndorseCertificateReady == true) |
| 191 | displayContactInfo(); |
| 192 | } |
| 193 | |
| 194 | void |
| 195 | AddContactPanel::onCollectEndorseFetchFailed(const Name& identity) |
| 196 | { |
Yingdi Yu | eaa84e2 | 2014-01-16 10:30:26 -0800 | [diff] [blame] | 197 | m_currentCollectEndorse = shared_ptr<Data>(); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 198 | m_currentCollectEndorseReady = true; |
| 199 | |
| 200 | if(m_currentEndorseCertificateReady == true) |
| 201 | displayContactInfo(); |
| 202 | } |
| 203 | |
| 204 | void |
| 205 | AddContactPanel::displayContactInfo() |
| 206 | { |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 207 | // _LOG_TRACE("displayContactInfo"); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 208 | const Profile& profile = m_currentEndorseCertificate->getProfileData().getProfile(); |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 209 | const Block& profileContent = m_currentEndorseCertificate->getProfileData().getContent(); |
| 210 | Buffer profileBlock(profileContent.value(), profileContent.value_size()); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 211 | |
| 212 | map<string, int> endorseCount; |
| 213 | |
Yingdi Yu | eaa84e2 | 2014-01-16 10:30:26 -0800 | [diff] [blame] | 214 | if(static_cast<bool>(m_currentCollectEndorse)) |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 215 | { |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 216 | Chronos::EndorseCollection endorseCollection; |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 217 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 218 | boost::iostreams::stream |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 219 | <boost::iostreams::array_source> is (reinterpret_cast<const char*>(m_currentCollectEndorse->getContent().value()), |
| 220 | m_currentCollectEndorse->getContent().value_size()); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 221 | |
| 222 | endorseCollection.ParseFromIstream(&is); |
| 223 | |
| 224 | for(int i = 0; i < endorseCollection.endorsement_size(); i ++) |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 225 | { |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 226 | try{ |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 227 | Data data; |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 228 | data.wireDecode(Block(reinterpret_cast<const uint8_t*>(endorseCollection.endorsement(i).blob().c_str()), |
| 229 | endorseCollection.endorsement(i).blob().size())); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 230 | EndorseCertificate endorseCert(data); |
| 231 | |
| 232 | Name signerKeyName = endorseCert.getSigner(); |
| 233 | Name signerName = signerKeyName.getPrefix(-1); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 234 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 235 | shared_ptr<ContactItem> contact = m_contactManager->getContact(signerName); |
Yingdi Yu | eaa84e2 | 2014-01-16 10:30:26 -0800 | [diff] [blame] | 236 | if(static_cast<bool>(contact)) |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 237 | continue; |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 238 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 239 | if(!contact->isIntroducer() || !contact->canBeTrustedFor(m_currentEndorseCertificate->getProfileData().getIdentityName())) |
| 240 | continue; |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 241 | |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 242 | if(!Verifier::verifySignature(data, data.getSignature(), contact->getSelfEndorseCertificate().getPublicKeyInfo())) |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 243 | continue; |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 244 | |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 245 | const Block& tmpProfileContent = endorseCert.getProfileData().getContent(); |
| 246 | Buffer tmpProfileBlock(tmpProfileContent.value(), tmpProfileContent.value_size()); |
| 247 | if(profileBlock != tmpProfileBlock) |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 248 | continue; |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 249 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 250 | const vector<string>& endorseList = endorseCert.getEndorseList(); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 251 | vector<string>::const_iterator it = endorseList.begin(); |
| 252 | for(; it != endorseList.end(); it++) |
Yingdi Yu | 6a5b9f6 | 2013-11-06 23:00:21 -0800 | [diff] [blame] | 253 | endorseCount[*it] += 1; |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 254 | }catch(std::exception& e){ |
| 255 | continue; |
| 256 | } |
| 257 | } |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 258 | } |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 259 | |
| 260 | ui->infoView->setColumnCount(3); |
| 261 | Profile::const_iterator it = profile.begin(); |
| 262 | int rowCount = 0; |
| 263 | |
| 264 | QTableWidgetItem *typeHeader = new QTableWidgetItem(QString::fromUtf8("Type")); |
| 265 | ui->infoView->setHorizontalHeaderItem(0, typeHeader); |
| 266 | QTableWidgetItem *valueHeader = new QTableWidgetItem(QString::fromUtf8("Value")); |
| 267 | ui->infoView->setHorizontalHeaderItem(1, valueHeader); |
| 268 | QTableWidgetItem *endorseHeader = new QTableWidgetItem(QString::fromUtf8("Endorse")); |
| 269 | ui->infoView->setHorizontalHeaderItem(2, endorseHeader); |
| 270 | |
| 271 | for(; it != profile.end(); it++) |
| 272 | { |
| 273 | ui->infoView->insertRow(rowCount); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 274 | QTableWidgetItem *type = new QTableWidgetItem(QString::fromStdString(it->first)); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 275 | ui->infoView->setItem(rowCount, 0, type); |
| 276 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 277 | QTableWidgetItem *value = new QTableWidgetItem(QString::fromStdString(it->second)); |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 278 | ui->infoView->setItem(rowCount, 1, value); |
| 279 | |
| 280 | map<string, int>::iterator map_it = endorseCount.find(it->first); |
| 281 | QTableWidgetItem *endorse = NULL; |
| 282 | if(map_it == endorseCount.end()) |
| 283 | endorse = new QTableWidgetItem(QString::number(0)); |
| 284 | else |
| 285 | endorse = new QTableWidgetItem(QString::number(map_it->second)); |
| 286 | ui->infoView->setItem(rowCount, 2, endorse); |
| 287 | |
| 288 | rowCount++; |
| 289 | } |
| 290 | } |
| 291 | |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 292 | // bool |
| 293 | // AddContactPanel::isSameBlob(const ndn::Blob& blobA, const ndn::Blob& blobB) |
| 294 | // { |
| 295 | // size_t size = blobA.size(); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 296 | |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 297 | // if(size != blobB.size()) |
| 298 | // return false; |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 299 | |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 300 | // const uint8_t* ap = blobA.buf(); |
| 301 | // const uint8_t* bp = blobB.buf(); |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 302 | |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 303 | // for(int i = 0; i < size; i++) |
| 304 | // { |
| 305 | // if(ap[i] != bp[i]) |
| 306 | // return false; |
| 307 | // } |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 308 | |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 309 | // return true; |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 310 | |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 311 | // } |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 312 | |
| 313 | |
Yingdi Yu | d59b593 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 314 | #if WAF |
| 315 | #include "addcontactpanel.moc" |
| 316 | #include "addcontactpanel.cpp.moc" |
| 317 | #endif |