blob: 50fa50f0e7e8341833d65aa400e6719deb04658e [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;
Yingdi Yufa4ce792014-02-06 18:09:22 -080015using namespace chronos;
Yingdi Yu7989eb22013-10-31 17:38:22 -070016
Yingdi Yufa4ce792014-02-06 18:09:22 -080017InviteListDialog::InviteListDialog(ndn::shared_ptr<ContactManager> contactManager,
Yingdi Yu7989eb22013-10-31 17:38:22 -070018 QWidget *parent)
19 :QDialog(parent)
20 , ui(new Ui::InviteListDialog)
21 , m_contactManager(contactManager)
22 , m_contactListModel(new QStringListModel)
23{
24 ui->setupUi(this);
25
26 refreshContactList();
27
28 ui->contactListView->setModel(m_contactListModel);
29
30 connect(ui->inviteButton, SIGNAL(clicked()),
31 this, SLOT(inviteWrapper()));
32 connect(ui->cancelButton, SIGNAL(clicked()),
33 this, SLOT(onCancelClicked()));
34}
35
36InviteListDialog::~InviteListDialog()
37{
38 delete ui;
39 delete m_contactListModel;
40}
41
42void
43InviteListDialog::setInviteLabel(string label)
44{
45 string msg("invite to chatroom:\n");
46 msg += label;
Yingdi Yue35bdb82013-11-07 11:32:40 -080047 ui->inviteLabel->setText(QString::fromStdString(msg));
Yingdi Yu7989eb22013-10-31 17:38:22 -070048 refreshContactList();
49}
50
51void
52InviteListDialog::refreshContactList()
53{
Yingdi Yu76dd8002013-12-24 11:16:32 +080054 m_contactList.clear();
55 m_contactManager->getContactItemList(m_contactList);
Yingdi Yu7989eb22013-10-31 17:38:22 -070056 QStringList contactNameList;
57 for(int i = 0; i < m_contactList.size(); i++)
58 {
Yingdi Yue35bdb82013-11-07 11:32:40 -080059 contactNameList << QString::fromStdString(m_contactList[i]->getAlias());
Yingdi Yu7989eb22013-10-31 17:38:22 -070060 }
61
62 m_contactListModel->setStringList(contactNameList);
63}
64
65void
66InviteListDialog::inviteWrapper()
67{
68 QModelIndexList selected = ui->contactListView->selectionModel()->selectedIndexes();
69 QString text = m_contactListModel->data(selected.first(), Qt::DisplayRole).toString();
Yingdi Yue35bdb82013-11-07 11:32:40 -080070 string alias = text.toStdString();
Yingdi Yu7989eb22013-10-31 17:38:22 -070071
72 int i = 0;
73 for(; i < m_contactList.size(); i++)
74 {
75 if(alias == m_contactList[i]->getAlias())
76 break;
77 }
78
Yingdi Yue35bdb82013-11-07 11:32:40 -080079 QString invitedContactNamespace = QString::fromStdString(m_contactList[i]->getNameSpace().toUri());
Yingdi Yu7989eb22013-10-31 17:38:22 -070080
81 bool isIntroducer = true;
82
83 emit invitionDetermined(invitedContactNamespace, isIntroducer);
84
85 this->close();
86}
87
88void
89InviteListDialog::onCancelClicked()
90{ this->close(); }
91
92#if WAF
93#include "invitelistdialog.moc"
94#include "invitelistdialog.cpp.moc"
95#endif