blob: 6f62c5ad905ab91b3f05cfdde1c71c9b70a60d8e [file] [log] [blame]
Yingdi Yu348f5ea2014-03-01 14:47:25 -08001/* -*- 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 Yufa0b6a02014-04-30 14:26:42 -070014InviteListDialog::InviteListDialog(QWidget *parent)
Yingdi Yu348f5ea2014-03-01 14:47:25 -080015 :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()),
Yingdi Yufa0b6a02014-04-30 14:26:42 -070024 this, SLOT(onInviteClicked()));
Yingdi Yu348f5ea2014-03-01 14:47:25 -080025 connect(ui->cancelButton, SIGNAL(clicked()),
Yingdi Yufa0b6a02014-04-30 14:26:42 -070026 this, SLOT(onCancelClicked()));
Yingdi Yu348f5ea2014-03-01 14:47:25 -080027}
28
29InviteListDialog::~InviteListDialog()
30{
31 delete ui;
32 delete m_contactListModel;
33}
34
35void
Yingdi Yu17032f82014-03-25 15:48:23 -070036InviteListDialog::setInviteLabel(std::string label)
Yingdi Yufa0b6a02014-04-30 14:26:42 -070037{
Yingdi Yu17032f82014-03-25 15:48:23 -070038 std::string msg("invite to chatroom:\n");
Yingdi Yu348f5ea2014-03-01 14:47:25 -080039 msg += label;
40 ui->inviteLabel->setText(QString::fromStdString(msg));
41}
42
43void
44InviteListDialog::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
61void
62InviteListDialog::onCancelClicked()
63{
64 this->close();
65}
66
67void
68InviteListDialog::onContactAliasListReady(const QStringList& aliasList)
69{
70 m_contactAliasList = aliasList;
71 m_contactListModel->setStringList(m_contactAliasList);
72}
73
74void
75InviteListDialog::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