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