/* -*- 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 "invite-list-dialog.h"
#include "ui_invite-list-dialog.h"

using namespace std;

InviteListDialog::InviteListDialog(QWidget *parent) 
  :QDialog(parent)
  , ui(new Ui::InviteListDialog)
  , m_contactListModel(new QStringListModel)
{
  ui->setupUi(this);

  ui->contactListView->setModel(m_contactListModel);

  connect(ui->inviteButton, SIGNAL(clicked()),
	  this, SLOT(onInviteClicked()));
  connect(ui->cancelButton, SIGNAL(clicked()),
	  this, SLOT(onCancelClicked()));
}

InviteListDialog::~InviteListDialog()
{
  delete ui;
  delete m_contactListModel;
}

void
InviteListDialog::setInviteLabel(string label)
{ 
  string msg("invite to chatroom:\n");
  msg += label;
  ui->inviteLabel->setText(QString::fromStdString(msg));
}

void
InviteListDialog::onInviteClicked()
{
  QModelIndexList selected = ui->contactListView->selectionModel()->selectedIndexes();
  QString alias = m_contactListModel->data(selected.first(), Qt::DisplayRole).toString();

  for(int i = 0; i < m_contactAliasList.size(); i++) // TODO:: could be optimized without using for loop.
    {
      if(alias == m_contactAliasList[i])
        {
          emit sendInvitation(m_contactIdList[i]);
          break;
        }
    }

  this->close();
}

void
InviteListDialog::onCancelClicked()
{
  this->close();
}

void
InviteListDialog::onContactAliasListReady(const QStringList& aliasList)
{
  m_contactAliasList = aliasList;
  m_contactListModel->setStringList(m_contactAliasList);
}

void
InviteListDialog::onContactIdListReady(const QStringList& idList)
{
  m_contactIdList = idList;
}

#if WAF
#include "invite-list-dialog.moc"
#include "invite-list-dialog.cpp.moc"
#endif
