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