/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
/*
 * Copyright (c) 2013, Regents of the University of California
 *                     Yingdi Yu
 *
 * BSD license, See the LICENSE file for more information
 *
 * Author: Yingdi Yu <yingdi@cs.ucla.edu>
 */


#include "invitationdialog.h"
#include "ui_invitationdialog.h"

using namespace std;
using namespace ndn;

InvitationDialog::InvitationDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::InvitationDialog)
{
    ui->setupUi(this);
    
    connect(ui->okButton, SIGNAL(clicked()),
            this, SLOT(onOkClicked()));
    connect(ui->cancelButton, SIGNAL(clicked()),
            this, SLOT(onCancelClicked()));
}

InvitationDialog::~InvitationDialog()
{
    delete ui;
}

void
InvitationDialog::setMsg(const string& inviter, const string& chatroom)
{
  m_inviter = inviter;
  m_chatroom = chatroom;
  string msg = inviter;
  msg.append(" invites you to join the chat room: ");
  
  ui->msgLabel->setText(QString::fromUtf8(msg.c_str()));
  ui->chatroomLine->setText(QString::fromUtf8(chatroom.c_str()));
}

void
InvitationDialog::onOkClicked()
{ 
  QString inviter = QString::fromUtf8(m_inviter.c_str());
  QString chatroom = QString::fromUtf8(m_chatroom.c_str());
  emit invitationAccepted(m_interestName, *m_identityCertificate, inviter, chatroom); 
  this->close();
}
  
void
InvitationDialog::onCancelClicked()
{ 
  ui->msgLabel->clear();
  ui->chatroomLine->clear();
  m_interestName = Name();
  m_inviter.clear();
  m_chatroom.clear();
  emit invitationRejected(m_interestName); 
  this->close();
}

#if WAF
#include "invitationdialog.moc"
#include "invitationdialog.cpp.moc"
#endif
