blob: bfc4040bbd6ed199309d16c07ced83f7272131b1 [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 Yu348f5ea2014-03-01 14:47:25 -080014InviteListDialog::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
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 Yu348f5ea2014-03-01 14:47:25 -080037{
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