blob: 797a31223d1211f66436d6ff073a31caf69552f9 [file] [log] [blame]
Yingdi Yu7989eb22013-10-31 17:38:22 -07001/* -*- 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 "invitelistdialog.h"
12#include "ui_invitelistdialog.h"
13
14using namespace std;
15
16InviteListDialog::InviteListDialog(ndn::Ptr<ContactManager> contactManager,
17 QWidget *parent)
18 :QDialog(parent)
19 , ui(new Ui::InviteListDialog)
20 , m_contactManager(contactManager)
21 , m_contactListModel(new QStringListModel)
22{
23 ui->setupUi(this);
24
25 refreshContactList();
26
27 ui->contactListView->setModel(m_contactListModel);
28
29 connect(ui->inviteButton, SIGNAL(clicked()),
30 this, SLOT(inviteWrapper()));
31 connect(ui->cancelButton, SIGNAL(clicked()),
32 this, SLOT(onCancelClicked()));
33}
34
35InviteListDialog::~InviteListDialog()
36{
37 delete ui;
38 delete m_contactListModel;
39}
40
41void
42InviteListDialog::setInviteLabel(string label)
43{
44 string msg("invite to chatroom:\n");
45 msg += label;
46 ui->inviteLabel->setText(QString::fromUtf8(msg.c_str()));
47 refreshContactList();
48}
49
50void
51InviteListDialog::refreshContactList()
52{
53 m_contactList = m_contactManager->getContactItemList();
54 QStringList contactNameList;
55 for(int i = 0; i < m_contactList.size(); i++)
56 {
57 contactNameList << QString::fromUtf8(m_contactList[i]->getAlias().c_str());
58 }
59
60 m_contactListModel->setStringList(contactNameList);
61}
62
63void
64InviteListDialog::inviteWrapper()
65{
66 QModelIndexList selected = ui->contactListView->selectionModel()->selectedIndexes();
67 QString text = m_contactListModel->data(selected.first(), Qt::DisplayRole).toString();
68 string alias = text.toUtf8().constData();
69
70 int i = 0;
71 for(; i < m_contactList.size(); i++)
72 {
73 if(alias == m_contactList[i]->getAlias())
74 break;
75 }
76
77 QString invitedContactNamespace = QString::fromUtf8(m_contactList[i]->getNameSpace().toUri().c_str());
78
79 bool isIntroducer = true;
80
81 emit invitionDetermined(invitedContactNamespace, isIntroducer);
82
83 this->close();
84}
85
86void
87InviteListDialog::onCancelClicked()
88{ this->close(); }
89
90#if WAF
91#include "invitelistdialog.moc"
92#include "invitelistdialog.cpp.moc"
93#endif