Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [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 "invite-list-dialog.h" |
| 12 | #include "ui_invite-list-dialog.h" |
| 13 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 14 | InviteListDialog::InviteListDialog(QWidget *parent) |
| 15 | :QDialog(parent) |
| 16 | , ui(new Ui::InviteListDialog) |
| 17 | , m_contactListModel(new QStringListModel) |
| 18 | { |
| 19 | ui->setupUi(this); |
| 20 | |
| 21 | ui->contactListView->setModel(m_contactListModel); |
| 22 | |
| 23 | connect(ui->inviteButton, SIGNAL(clicked()), |
| 24 | this, SLOT(onInviteClicked())); |
| 25 | connect(ui->cancelButton, SIGNAL(clicked()), |
| 26 | this, SLOT(onCancelClicked())); |
| 27 | } |
| 28 | |
| 29 | InviteListDialog::~InviteListDialog() |
| 30 | { |
| 31 | delete ui; |
| 32 | delete m_contactListModel; |
| 33 | } |
| 34 | |
| 35 | void |
Yingdi Yu | 17032f8 | 2014-03-25 15:48:23 -0700 | [diff] [blame^] | 36 | InviteListDialog::setInviteLabel(std::string label) |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 37 | { |
Yingdi Yu | 17032f8 | 2014-03-25 15:48:23 -0700 | [diff] [blame^] | 38 | std::string msg("invite to chatroom:\n"); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 39 | msg += label; |
| 40 | ui->inviteLabel->setText(QString::fromStdString(msg)); |
| 41 | } |
| 42 | |
| 43 | void |
| 44 | InviteListDialog::onInviteClicked() |
| 45 | { |
| 46 | QModelIndexList selected = ui->contactListView->selectionModel()->selectedIndexes(); |
| 47 | QString alias = m_contactListModel->data(selected.first(), Qt::DisplayRole).toString(); |
| 48 | |
| 49 | for(int i = 0; i < m_contactAliasList.size(); i++) // TODO:: could be optimized without using for loop. |
| 50 | { |
| 51 | if(alias == m_contactAliasList[i]) |
| 52 | { |
| 53 | emit sendInvitation(m_contactIdList[i]); |
| 54 | break; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | this->close(); |
| 59 | } |
| 60 | |
| 61 | void |
| 62 | InviteListDialog::onCancelClicked() |
| 63 | { |
| 64 | this->close(); |
| 65 | } |
| 66 | |
| 67 | void |
| 68 | InviteListDialog::onContactAliasListReady(const QStringList& aliasList) |
| 69 | { |
| 70 | m_contactAliasList = aliasList; |
| 71 | m_contactListModel->setStringList(m_contactAliasList); |
| 72 | } |
| 73 | |
| 74 | void |
| 75 | InviteListDialog::onContactIdListReady(const QStringList& idList) |
| 76 | { |
| 77 | m_contactIdList = idList; |
| 78 | } |
| 79 | |
| 80 | #if WAF |
| 81 | #include "invite-list-dialog.moc" |
| 82 | #include "invite-list-dialog.cpp.moc" |
| 83 | #endif |