Mengjin Yan | 391d724 | 2014-08-28 20:51:55 -0700 | [diff] [blame] | 1 | #include "chatroom-discovery-dialog.hpp" |
| 2 | #include "ui_chatroom-discovery-dialog.h" |
| 3 | |
| 4 | namespace chronos { |
| 5 | |
Mengjin Yan | 391d724 | 2014-08-28 20:51:55 -0700 | [diff] [blame] | 6 | using ndn::Name; |
| 7 | |
| 8 | ChatroomDiscoveryDialog::ChatroomDiscoveryDialog(QWidget* parent) |
| 9 | : QDialog(parent) |
| 10 | , ui(new Ui::ChatroomDiscoveryDialog) |
| 11 | , m_standardItemModel(new QStandardItemModel(0, 3, this)) |
| 12 | , m_chatroomDiscoveryViewDialog(new ChatroomDiscoveryViewDialog) |
| 13 | { |
| 14 | ui->setupUi(this); |
| 15 | |
| 16 | connect(ui->cancelButton, SIGNAL(clicked()), |
| 17 | this, SLOT(onCancelButtonClicked())); |
| 18 | connect(ui->joinButton, SIGNAL(clicked()), |
| 19 | this, SLOT(onJoinButtonClicked())); |
| 20 | connect(ui->viewButton, SIGNAL(clicked()), |
| 21 | this, SLOT(onViewButtonClicked())); |
| 22 | connect(ui->chatroomListView, SIGNAL(clicked(QModelIndex)), |
| 23 | this, SLOT(onChatroomListViewClicked(QModelIndex))); |
| 24 | connect(ui->chatroomListView, SIGNAL(doubleClicked(QModelIndex)), |
| 25 | this, SLOT(onChatroomListViewDoubleClicked(QModelIndex))); |
| 26 | |
| 27 | updateChatroomList(); |
| 28 | } |
| 29 | |
| 30 | ChatroomDiscoveryDialog::~ChatroomDiscoveryDialog() |
| 31 | { |
| 32 | delete ui; |
| 33 | } |
| 34 | |
| 35 | void |
| 36 | ChatroomDiscoveryDialog::updateChatroomList() |
| 37 | { |
| 38 | m_standardItemModel->clear(); |
| 39 | |
| 40 | m_standardItemModel |
| 41 | ->setHorizontalHeaderItem(0, new QStandardItem(QString("Chatroom Name"))); |
| 42 | m_standardItemModel |
| 43 | ->setHorizontalHeaderItem(1, new QStandardItem(QString("Chatroom Trust Model"))); |
| 44 | m_standardItemModel |
| 45 | ->setHorizontalHeaderItem(2, new QStandardItem(QString("Participants or Contacts"))); |
| 46 | |
| 47 | QHeaderView *m_headerView = ui->chatroomListView->horizontalHeader(); |
| 48 | m_headerView->setResizeMode((QHeaderView::ResizeMode)3); |
| 49 | m_headerView->setStretchLastSection(true); |
| 50 | |
| 51 | ui->chatroomListView->setModel(m_standardItemModel); |
| 52 | |
| 53 | int i = 0; |
| 54 | for (Chatrooms::const_iterator it = m_chatrooms.begin(); |
| 55 | it != m_chatrooms.end(); ++it, ++i) { |
| 56 | QStandardItem *item = new QStandardItem(QString::fromStdString(it->first.toUri())); |
| 57 | item->setEditable(false); |
| 58 | m_standardItemModel->setItem(i, 0, item); |
| 59 | |
| 60 | if (it->second.getTrustModel() == ChatroomInfo::TRUST_MODEL_WEBOFTRUST) |
| 61 | item = new QStandardItem(QString("Web of trust")); |
| 62 | else |
| 63 | item = new QStandardItem(QString("Hierarchical")); |
| 64 | item->setEditable(false); |
| 65 | m_standardItemModel->setItem(i, 1, item); |
| 66 | |
| 67 | QString content; |
| 68 | |
Qiuhan Ding | 5d98cc5 | 2014-10-30 15:17:53 -0700 | [diff] [blame] | 69 | for (std::list<Name>::const_iterator nameIt = it->second.getParticipants().begin(); |
Mengjin Yan | 391d724 | 2014-08-28 20:51:55 -0700 | [diff] [blame] | 70 | nameIt != it->second.getParticipants().end(); nameIt++) { |
| 71 | content.append(QString::fromStdString(nameIt->toUri())).append(","); |
| 72 | } |
| 73 | item = new QStandardItem(content); |
| 74 | item->setEditable(false); |
| 75 | m_standardItemModel->setItem(i, 2, item); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | void |
| 80 | ChatroomDiscoveryDialog::onDiscoverChatroomChanged(const chronos::ChatroomInfo& info, bool isAdd) |
| 81 | { |
| 82 | if (isAdd) |
| 83 | m_chatrooms[info.getName()] = info; |
| 84 | else |
| 85 | m_chatrooms.erase(info.getName()); |
| 86 | |
| 87 | updateChatroomList(); |
| 88 | } |
| 89 | |
| 90 | void |
| 91 | ChatroomDiscoveryDialog::onCancelButtonClicked() |
| 92 | { |
| 93 | this->close(); |
| 94 | } |
| 95 | |
| 96 | void |
| 97 | ChatroomDiscoveryDialog::onJoinButtonClicked() |
| 98 | { |
| 99 | if(ui->chatroomListView->selectionModel()->selectedRows().size() == 0) { |
| 100 | QMessageBox::information(this, tr("ChronoChat"), tr("Please select a chatroom to join")); |
| 101 | } |
| 102 | else { |
| 103 | m_selectedRow = ui->chatroomListView->selectionModel()->selectedRows()[0].row(); |
| 104 | QStandardItem* selectedChatroomName = m_standardItemModel->item(m_selectedRow, 0); |
| 105 | emit startChatroom(selectedChatroomName->text(), false); |
| 106 | |
| 107 | { |
| 108 | // Tmp disabled |
| 109 | // QStandardItem* selectedChatroomTrustModel = m_standardItemModel->item(m_selectedRow, 1); |
| 110 | // if(selectedChatroomTrustModel->text() == "Hierarchical") { |
| 111 | // emit startChatroom(selectedChatroomName->text(), false); |
| 112 | // } |
| 113 | // else if(selectedChatroomTrustModel->text() == "Web of trust") { |
| 114 | // ChatroomDiscoveryLogic::ChatroomList::const_iterator it; |
| 115 | // it = m_chatroomList->find(Name::Component(selectedChatroomName->text().toStdString())); |
| 116 | |
| 117 | // if(it->second.getContacts().size() == 0) { |
| 118 | // QMessageBox messageBox; |
| 119 | // messageBox.addButton(QMessageBox::Ok); |
| 120 | // messageBox.setIcon(QMessageBox::Information); |
| 121 | // messageBox.setText |
| 122 | // ("You do not have a contact in this chatroom. Please choose another chatroom to join"); |
| 123 | // messageBox.exec(); |
| 124 | // } |
| 125 | // else { |
| 126 | // m_sendInvitationRequestDialog->setChatroomName(selectedChatroomName->text()); |
| 127 | // m_sendInvitationRequestDialog->setContacts(it->second.getContacts()); |
| 128 | // m_sendInvitationRequestDialog->show(); |
| 129 | // } |
| 130 | // } |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | void |
| 136 | ChatroomDiscoveryDialog::onChatroomListViewDoubleClicked(const QModelIndex &index) |
| 137 | { |
| 138 | onJoinButtonClicked(); |
| 139 | } |
| 140 | |
| 141 | void |
| 142 | ChatroomDiscoveryDialog::onChatroomListViewClicked(const QModelIndex &index) |
| 143 | { |
| 144 | ui->chatroomListView->selectRow(index.row()); |
| 145 | m_selectedRow = index.row(); |
| 146 | } |
| 147 | |
| 148 | void |
| 149 | ChatroomDiscoveryDialog::onViewButtonClicked() |
| 150 | { |
| 151 | if(ui->chatroomListView->selectionModel()->selectedRows().size() == 0) { |
| 152 | QMessageBox messageBox; |
| 153 | messageBox.addButton(QMessageBox::Ok); |
| 154 | messageBox.setIcon(QMessageBox::Information); |
| 155 | messageBox.setText("Please select a chatroom to view"); |
| 156 | messageBox.exec(); |
| 157 | } |
| 158 | else { |
| 159 | m_selectedRow = ui->chatroomListView->selectionModel()->selectedRows()[0].row(); |
| 160 | |
| 161 | QStandardItem* selectedChatroomName = m_standardItemModel->item(m_selectedRow); |
| 162 | m_chatroomDiscoveryViewDialog->setChatroomName(selectedChatroomName->text()); |
| 163 | |
| 164 | // QStandardItem *m_selectedTrustModel = m_standardItemModel->item(m_selectedRow, 1); |
| 165 | // m_chatroomDiscoveryViewDialog->setChatroomTrustModel(m_selectedTrustModel->text()); |
| 166 | |
| 167 | //use chatroomlist as parameter to call set participants |
| 168 | //maybe for different chatroom with different trust model??? |
| 169 | //participants can be contacts |
| 170 | |
| 171 | Chatrooms::const_iterator it = |
| 172 | m_chatrooms.find(Name::Component(selectedChatroomName->text().toStdString())); |
| 173 | |
| 174 | if (it != m_chatrooms.end()) { |
| 175 | m_chatroomDiscoveryViewDialog->setChatroomParticipants(it->second.getParticipants()); |
| 176 | m_chatroomDiscoveryViewDialog->show(); |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | } // namespace chronos |
| 182 | |
| 183 | |
| 184 | #if WAF |
| 185 | #include "chatroom-discovery-dialog.moc" |
| 186 | #endif |