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 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 11 | #include "invite-list-dialog.hpp" |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 12 | #include "ui_invite-list-dialog.h" |
| 13 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 14 | namespace chronochat { |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 15 | |
| 16 | InviteListDialog::InviteListDialog(QWidget* parent) |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 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()), |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 26 | this, SLOT(onInviteClicked())); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 27 | connect(ui->cancelButton, SIGNAL(clicked()), |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 28 | this, SLOT(onCancelClicked())); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | InviteListDialog::~InviteListDialog() |
| 32 | { |
| 33 | delete ui; |
| 34 | delete m_contactListModel; |
| 35 | } |
| 36 | |
| 37 | void |
Yingdi Yu | 17032f8 | 2014-03-25 15:48:23 -0700 | [diff] [blame] | 38 | InviteListDialog::setInviteLabel(std::string label) |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 39 | { |
Yingdi Yu | 17032f8 | 2014-03-25 15:48:23 -0700 | [diff] [blame] | 40 | std::string msg("invite to chatroom:\n"); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 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 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 51 | // TODO:: could be optimized without using for loop. |
| 52 | for (int i = 0; i < m_contactAliasList.size(); i++) { |
| 53 | if (alias == m_contactAliasList[i]) { |
| 54 | emit sendInvitation(m_contactIdList[i]); |
| 55 | break; |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 56 | } |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 57 | } |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 58 | |
| 59 | this->close(); |
| 60 | } |
| 61 | |
| 62 | void |
| 63 | InviteListDialog::onCancelClicked() |
| 64 | { |
| 65 | this->close(); |
| 66 | } |
| 67 | |
| 68 | void |
| 69 | InviteListDialog::onContactAliasListReady(const QStringList& aliasList) |
| 70 | { |
| 71 | m_contactAliasList = aliasList; |
| 72 | m_contactListModel->setStringList(m_contactAliasList); |
| 73 | } |
| 74 | |
| 75 | void |
| 76 | InviteListDialog::onContactIdListReady(const QStringList& idList) |
| 77 | { |
| 78 | m_contactIdList = idList; |
| 79 | } |
| 80 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 81 | } // namespace chronochat |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 82 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 83 | #if WAF |
| 84 | #include "invite-list-dialog.moc" |
Yingdi Yu | 4212586 | 2014-08-07 17:04:28 -0700 | [diff] [blame] | 85 | // #include "invite-list-dialog.cpp.moc" |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 86 | #endif |