blob: ea6b7907a121f678b754a73bf194008e8c79b6f4 [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
Yingdi Yu76dd8002013-12-24 11:16:32 +080016InviteListDialog::InviteListDialog(ndn::ptr_lib::shared_ptr<ContactManager> contactManager,
Yingdi Yu7989eb22013-10-31 17:38:22 -070017 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 Yue35bdb82013-11-07 11:32:40 -080046 ui->inviteLabel->setText(QString::fromStdString(msg));
Yingdi Yu7989eb22013-10-31 17:38:22 -070047 refreshContactList();
48}
49
50void
51InviteListDialog::refreshContactList()
52{
Yingdi Yu76dd8002013-12-24 11:16:32 +080053 m_contactList.clear();
54 m_contactManager->getContactItemList(m_contactList);
Yingdi Yu7989eb22013-10-31 17:38:22 -070055 QStringList contactNameList;
56 for(int i = 0; i < m_contactList.size(); i++)
57 {
Yingdi Yue35bdb82013-11-07 11:32:40 -080058 contactNameList << QString::fromStdString(m_contactList[i]->getAlias());
Yingdi Yu7989eb22013-10-31 17:38:22 -070059 }
60
61 m_contactListModel->setStringList(contactNameList);
62}
63
64void
65InviteListDialog::inviteWrapper()
66{
67 QModelIndexList selected = ui->contactListView->selectionModel()->selectedIndexes();
68 QString text = m_contactListModel->data(selected.first(), Qt::DisplayRole).toString();
Yingdi Yue35bdb82013-11-07 11:32:40 -080069 string alias = text.toStdString();
Yingdi Yu7989eb22013-10-31 17:38:22 -070070
71 int i = 0;
72 for(; i < m_contactList.size(); i++)
73 {
74 if(alias == m_contactList[i]->getAlias())
75 break;
76 }
77
Yingdi Yue35bdb82013-11-07 11:32:40 -080078 QString invitedContactNamespace = QString::fromStdString(m_contactList[i]->getNameSpace().toUri());
Yingdi Yu7989eb22013-10-31 17:38:22 -070079
80 bool isIntroducer = true;
81
82 emit invitionDetermined(invitedContactNamespace, isIntroducer);
83
84 this->close();
85}
86
87void
88InviteListDialog::onCancelClicked()
89{ this->close(); }
90
91#if WAF
92#include "invitelistdialog.moc"
93#include "invitelistdialog.cpp.moc"
94#endif