Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -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 | |
| 11 | #include "invitelistdialog.h" |
| 12 | #include "ui_invitelistdialog.h" |
| 13 | |
| 14 | using namespace std; |
| 15 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame^] | 16 | InviteListDialog::InviteListDialog(ndn::ptr_lib::shared_ptr<ContactManager> contactManager, |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 17 | QWidget *parent) |
| 18 | :QDialog(parent) |
| 19 | , ui(new Ui::InviteListDialog) |
| 20 | , m_contactManager(contactManager) |
| 21 | , m_contactListModel(new QStringListModel) |
| 22 | { |
| 23 | ui->setupUi(this); |
| 24 | |
| 25 | refreshContactList(); |
| 26 | |
| 27 | ui->contactListView->setModel(m_contactListModel); |
| 28 | |
| 29 | connect(ui->inviteButton, SIGNAL(clicked()), |
| 30 | this, SLOT(inviteWrapper())); |
| 31 | connect(ui->cancelButton, SIGNAL(clicked()), |
| 32 | this, SLOT(onCancelClicked())); |
| 33 | } |
| 34 | |
| 35 | InviteListDialog::~InviteListDialog() |
| 36 | { |
| 37 | delete ui; |
| 38 | delete m_contactListModel; |
| 39 | } |
| 40 | |
| 41 | void |
| 42 | InviteListDialog::setInviteLabel(string label) |
| 43 | { |
| 44 | string msg("invite to chatroom:\n"); |
| 45 | msg += label; |
Yingdi Yu | e35bdb8 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 46 | ui->inviteLabel->setText(QString::fromStdString(msg)); |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 47 | refreshContactList(); |
| 48 | } |
| 49 | |
| 50 | void |
| 51 | InviteListDialog::refreshContactList() |
| 52 | { |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame^] | 53 | m_contactList.clear(); |
| 54 | m_contactManager->getContactItemList(m_contactList); |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 55 | QStringList contactNameList; |
| 56 | for(int i = 0; i < m_contactList.size(); i++) |
| 57 | { |
Yingdi Yu | e35bdb8 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 58 | contactNameList << QString::fromStdString(m_contactList[i]->getAlias()); |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | m_contactListModel->setStringList(contactNameList); |
| 62 | } |
| 63 | |
| 64 | void |
| 65 | InviteListDialog::inviteWrapper() |
| 66 | { |
| 67 | QModelIndexList selected = ui->contactListView->selectionModel()->selectedIndexes(); |
| 68 | QString text = m_contactListModel->data(selected.first(), Qt::DisplayRole).toString(); |
Yingdi Yu | e35bdb8 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 69 | string alias = text.toStdString(); |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 70 | |
| 71 | int i = 0; |
| 72 | for(; i < m_contactList.size(); i++) |
| 73 | { |
| 74 | if(alias == m_contactList[i]->getAlias()) |
| 75 | break; |
| 76 | } |
| 77 | |
Yingdi Yu | e35bdb8 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 78 | QString invitedContactNamespace = QString::fromStdString(m_contactList[i]->getNameSpace().toUri()); |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 79 | |
| 80 | bool isIntroducer = true; |
| 81 | |
| 82 | emit invitionDetermined(invitedContactNamespace, isIntroducer); |
| 83 | |
| 84 | this->close(); |
| 85 | } |
| 86 | |
| 87 | void |
| 88 | InviteListDialog::onCancelClicked() |
| 89 | { this->close(); } |
| 90 | |
| 91 | #if WAF |
| 92 | #include "invitelistdialog.moc" |
| 93 | #include "invitelistdialog.cpp.moc" |
| 94 | #endif |