Mengjin Yan | 391d724 | 2014-08-28 20:51:55 -0700 | [diff] [blame] | 1 | #include "send-invitation-request-dialog.hpp" |
| 2 | #include "ui_send-invitation-request-dialog.h" |
| 3 | |
| 4 | using namespace chronos; |
| 5 | |
| 6 | SendInvitationRequestDialog::SendInvitationRequestDialog(QWidget *parent) : |
| 7 | QDialog(parent), |
| 8 | ui(new Ui::SendInvitationRequestDialog), |
| 9 | m_stringListModel(new QStringListModel) |
| 10 | { |
| 11 | ui->setupUi(this); |
| 12 | ui->contactsListView->setEditTriggers(ui->contactsListView->NoEditTriggers); |
| 13 | ui->contactsListView->setModel(m_stringListModel); |
| 14 | |
| 15 | connect(ui->sendButton, SIGNAL(clicked()), |
| 16 | this, SLOT(onSendButtonClicked())); |
| 17 | connect(ui->cancelButton, SIGNAL(clicked()), |
| 18 | this, SLOT(onCancelButtonClicked())); |
| 19 | connect(ui->contactsListView, SIGNAL(clicked(QModelIndex)), |
| 20 | this, SLOT(onContactListViewClicked(QModelIndex))); |
| 21 | connect(ui->contactsListView,SIGNAL(doubleClicked(QModelIndex)), |
| 22 | this, SLOT(onContactListViewDoubleClicked(QModelIndex))); |
| 23 | } |
| 24 | |
| 25 | SendInvitationRequestDialog::~SendInvitationRequestDialog() |
| 26 | { |
| 27 | delete ui; |
| 28 | } |
| 29 | |
| 30 | void |
| 31 | SendInvitationRequestDialog::setContacts(const std::vector<ndn::Name>& contacts) |
| 32 | { |
| 33 | QStringList contactsList; |
| 34 | for(int i = 0; i < contacts.size(); i++){ |
| 35 | contactsList.append(QString::fromStdString(contacts[i].toUri())); |
| 36 | } |
| 37 | m_stringListModel->setStringList(contactsList); |
| 38 | } |
| 39 | |
| 40 | void |
| 41 | SendInvitationRequestDialog::onSendButtonClicked() |
| 42 | { |
| 43 | if(ui->contactsListView->selectionModel()->selectedRows().size() == 0){ |
| 44 | QMessageBox messageBox; |
| 45 | messageBox.addButton(QMessageBox::Ok); |
| 46 | messageBox.setIcon(QMessageBox::Information); |
| 47 | messageBox.setText("Please select a contact to send invitation request"); |
| 48 | messageBox.exec(); |
| 49 | } |
| 50 | else{ |
| 51 | //send invitation request |
| 52 | int selectedRow = ui->contactsListView->selectionModel()->selectedRows()[0].row(); |
| 53 | QString contactName = m_stringListModel->stringList()[selectedRow]; |
| 54 | qDebug() << contactName; |
| 55 | |
| 56 | QMessageBox messageBox; |
| 57 | messageBox.addButton(QMessageBox::Yes); |
| 58 | messageBox.addButton(QMessageBox::No); |
| 59 | messageBox.setIcon(QMessageBox::Question); |
| 60 | messageBox.setText("Send invitation request to "+ contactName +"?"); |
| 61 | |
| 62 | int selection = messageBox.exec(); |
| 63 | |
| 64 | if(selection == QMessageBox::Yes){ |
| 65 | //send invitation request |
| 66 | //need to have another message box when successfully send |
| 67 | //emit sendInvitationRequest(m_chatroomName, contactName); |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | |
| 73 | void |
| 74 | SendInvitationRequestDialog::onCancelButtonClicked() |
| 75 | { |
| 76 | //qDebug() << "cancel"; |
| 77 | this->close(); |
| 78 | } |
| 79 | |
| 80 | void |
| 81 | SendInvitationRequestDialog::onContactListViewClicked(QModelIndex modelIndex) |
| 82 | {} |
| 83 | |
| 84 | void |
| 85 | SendInvitationRequestDialog::onContactListViewDoubleClicked(QModelIndex modelIndex) |
| 86 | { |
| 87 | onSendButtonClicked(); |
| 88 | } |
| 89 | |
| 90 | void |
| 91 | SendInvitationRequestDialog::setChatroomName(const QString chatroomName) |
| 92 | { |
| 93 | m_chatroomName = chatroomName; |
| 94 | } |
| 95 | |
| 96 | |
| 97 | #if WAF |
| 98 | #include "send-invitation-request-dialog.moc" |
| 99 | #endif |