blob: 435e2f60e6d48228409ec956190ac41d15ab6449 [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
Yingdi Yu0b0a7362014-08-05 16:31:30 -070011#include "invite-list-dialog.hpp"
Yingdi Yu348f5ea2014-03-01 14:47:25 -080012#include "ui_invite-list-dialog.h"
13
Yingdi Yueb692ac2015-02-10 18:46:18 -080014namespace chronochat {
Yingdi Yu0b0a7362014-08-05 16:31:30 -070015
16InviteListDialog::InviteListDialog(QWidget* parent)
Yingdi Yu348f5ea2014-03-01 14:47:25 -080017 :QDialog(parent)
18 , ui(new Ui::InviteListDialog)
19 , m_contactListModel(new QStringListModel)
20{
21 ui->setupUi(this);
22
23 ui->contactListView->setModel(m_contactListModel);
24
25 connect(ui->inviteButton, SIGNAL(clicked()),
Yingdi Yufa0b6a02014-04-30 14:26:42 -070026 this, SLOT(onInviteClicked()));
Yingdi Yu348f5ea2014-03-01 14:47:25 -080027 connect(ui->cancelButton, SIGNAL(clicked()),
Yingdi Yufa0b6a02014-04-30 14:26:42 -070028 this, SLOT(onCancelClicked()));
Yingdi Yu348f5ea2014-03-01 14:47:25 -080029}
30
31InviteListDialog::~InviteListDialog()
32{
33 delete ui;
34 delete m_contactListModel;
35}
36
37void
Yingdi Yu17032f82014-03-25 15:48:23 -070038InviteListDialog::setInviteLabel(std::string label)
Yingdi Yufa0b6a02014-04-30 14:26:42 -070039{
Yingdi Yu17032f82014-03-25 15:48:23 -070040 std::string msg("invite to chatroom:\n");
Yingdi Yu348f5ea2014-03-01 14:47:25 -080041 msg += label;
42 ui->inviteLabel->setText(QString::fromStdString(msg));
43}
44
45void
46InviteListDialog::onInviteClicked()
47{
48 QModelIndexList selected = ui->contactListView->selectionModel()->selectedIndexes();
49 QString alias = m_contactListModel->data(selected.first(), Qt::DisplayRole).toString();
50
Yingdi Yu0b0a7362014-08-05 16:31:30 -070051 // TODO:: could be optimized without using for loop.
52 for (int i = 0; i < m_contactAliasList.size(); i++) {
53 if (alias == m_contactAliasList[i]) {
54 emit sendInvitation(m_contactIdList[i]);
55 break;
Yingdi Yu348f5ea2014-03-01 14:47:25 -080056 }
Yingdi Yu0b0a7362014-08-05 16:31:30 -070057 }
Yingdi Yu348f5ea2014-03-01 14:47:25 -080058
59 this->close();
60}
61
62void
63InviteListDialog::onCancelClicked()
64{
65 this->close();
66}
67
68void
69InviteListDialog::onContactAliasListReady(const QStringList& aliasList)
70{
71 m_contactAliasList = aliasList;
72 m_contactListModel->setStringList(m_contactAliasList);
73}
74
75void
76InviteListDialog::onContactIdListReady(const QStringList& idList)
77{
78 m_contactIdList = idList;
79}
80
Yingdi Yueb692ac2015-02-10 18:46:18 -080081} // namespace chronochat
Yingdi Yu0b0a7362014-08-05 16:31:30 -070082
Yingdi Yu348f5ea2014-03-01 14:47:25 -080083#if WAF
84#include "invite-list-dialog.moc"
Yingdi Yu42125862014-08-07 17:04:28 -070085// #include "invite-list-dialog.cpp.moc"
Yingdi Yu348f5ea2014-03-01 14:47:25 -080086#endif