blob: c3d12af38f7e123096208252117c1b988ddc4342 [file] [log] [blame]
Yingdi Yu42f66462013-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;
Yingdi Yub35b8652013-11-07 11:32:40 -080046 ui->inviteLabel->setText(QString::fromStdString(msg));
Yingdi Yu42f66462013-10-31 17:38:22 -070047 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 {
Yingdi Yub35b8652013-11-07 11:32:40 -080057 contactNameList << QString::fromStdString(m_contactList[i]->getAlias());
Yingdi Yu42f66462013-10-31 17:38:22 -070058 }
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();
Yingdi Yub35b8652013-11-07 11:32:40 -080068 string alias = text.toStdString();
Yingdi Yu42f66462013-10-31 17:38:22 -070069
70 int i = 0;
71 for(; i < m_contactList.size(); i++)
72 {
73 if(alias == m_contactList[i]->getAlias())
74 break;
75 }
76
Yingdi Yub35b8652013-11-07 11:32:40 -080077 QString invitedContactNamespace = QString::fromStdString(m_contactList[i]->getNameSpace().toUri());
Yingdi Yu42f66462013-10-31 17:38:22 -070078
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