blob: 37cd13e6d4e03e73e48103b3dff1287053d43ed0 [file] [log] [blame]
/* -*- 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 "contactpanel.h"
#include "ui_contactpanel.h"
#include <QStringList>
#include <QItemSelectionModel>
#include <QModelIndex>
#include <QDir>
#ifndef Q_MOC_RUN
#include <boost/filesystem.hpp>
#include "logging.h"
#include "exception.h"
#endif
namespace fs = boost::filesystem;
using namespace ndn;
INIT_LOGGER("ContactPanel");
ContactPanel::ContactPanel(Ptr<ContactManager> contactManager, QWidget *parent)
: QDialog(parent)
, ui(new Ui::ContactPanel)
, m_contactManager(contactManager)
, m_contactListModel(new QStringListModel)
, m_addContactPanel(new AddContactPanel(contactManager))
{
ui->setupUi(this);
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
QString path = (QDir::home().path());
path.append(QDir::separator()).append(".chronos").append(QDir::separator()).append("chronos.db");
db.setDatabaseName(path);
bool ok = db.open();
m_profileEditor = new ProfileEditor(m_contactManager->getContactStorage());
QStringList contactNameList;
contactNameList << "Alex" << "Wentao" << "Yingdi";
m_contactListModel->setStringList(contactNameList);
ui->ContactList->setModel(m_contactListModel);
QItemSelectionModel* selectionModel = ui->ContactList->selectionModel();
connect(selectionModel, SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
this, SLOT(updateSelection(const QItemSelection &, const QItemSelection &)));
connect(ui->EditProfileButton, SIGNAL(clicked()),
this, SLOT(openProfileEditor()));
connect(ui->AddContactButton, SIGNAL(clicked()),
this, SLOT(openAddContactPanel()));
}
ContactPanel::~ContactPanel()
{
delete ui;
delete m_contactListModel;
delete m_profileEditor;
delete m_addContactPanel;
}
void
ContactPanel::updateSelection(const QItemSelection &selected,
const QItemSelection &deselected)
{
QModelIndexList items = selected.indexes();
QString text = m_contactListModel->data(items.first(), Qt::DisplayRole).toString();
ui->NameData->setText(text);
}
void
ContactPanel::openProfileEditor()
{ m_profileEditor->show(); }
void
ContactPanel::openAddContactPanel()
{ m_addContactPanel->show(); }
#if WAF
#include "contactpanel.moc"
#include "contactpanel.cpp.moc"
#endif