blob: 37cd13e6d4e03e73e48103b3dff1287053d43ed0 [file] [log] [blame]
Yingdi Yu847aa862013-10-09 16:35:53 -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 "contactpanel.h"
12#include "ui_contactpanel.h"
13
Yingdi Yu40eca752013-10-10 15:00:58 -070014
15#include <QStringList>
16#include <QItemSelectionModel>
17#include <QModelIndex>
Yingdi Yu3b318c12013-10-15 17:54:00 -070018#include <QDir>
Yingdi Yu40eca752013-10-10 15:00:58 -070019
Yingdi Yu3b318c12013-10-15 17:54:00 -070020#ifndef Q_MOC_RUN
21#include <boost/filesystem.hpp>
22#include "logging.h"
23#include "exception.h"
24#endif
25
26namespace fs = boost::filesystem;
27using namespace ndn;
28
29INIT_LOGGER("ContactPanel");
30
Yingdi Yu9236c432013-10-18 11:29:25 -070031ContactPanel::ContactPanel(Ptr<ContactManager> contactManager, QWidget *parent)
Yingdi Yu3b318c12013-10-15 17:54:00 -070032 : QDialog(parent)
33 , ui(new Ui::ContactPanel)
Yingdi Yu9236c432013-10-18 11:29:25 -070034 , m_contactManager(contactManager)
Yingdi Yu3b318c12013-10-15 17:54:00 -070035 , m_contactListModel(new QStringListModel)
Yingdi Yu9236c432013-10-18 11:29:25 -070036 , m_addContactPanel(new AddContactPanel(contactManager))
Yingdi Yu847aa862013-10-09 16:35:53 -070037{
Yingdi Yu3b318c12013-10-15 17:54:00 -070038
Yingdi Yu847aa862013-10-09 16:35:53 -070039 ui->setupUi(this);
Yingdi Yu40eca752013-10-10 15:00:58 -070040
Yingdi Yu3b318c12013-10-15 17:54:00 -070041 QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
42 QString path = (QDir::home().path());
43 path.append(QDir::separator()).append(".chronos").append(QDir::separator()).append("chronos.db");
44 db.setDatabaseName(path);
45 bool ok = db.open();
46
Yingdi Yu9236c432013-10-18 11:29:25 -070047 m_profileEditor = new ProfileEditor(m_contactManager->getContactStorage());
Yingdi Yu8f7325a2013-10-17 17:03:46 -070048
Yingdi Yu40eca752013-10-10 15:00:58 -070049 QStringList contactNameList;
50 contactNameList << "Alex" << "Wentao" << "Yingdi";
51
52 m_contactListModel->setStringList(contactNameList);
53 ui->ContactList->setModel(m_contactListModel);
54
55 QItemSelectionModel* selectionModel = ui->ContactList->selectionModel();
Yingdi Yu0269c872013-10-16 13:16:49 -070056
Yingdi Yu40eca752013-10-10 15:00:58 -070057 connect(selectionModel, SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
58 this, SLOT(updateSelection(const QItemSelection &, const QItemSelection &)));
Yingdi Yu3b318c12013-10-15 17:54:00 -070059 connect(ui->EditProfileButton, SIGNAL(clicked()),
60 this, SLOT(openProfileEditor()));
Yingdi Yu0269c872013-10-16 13:16:49 -070061
62 connect(ui->AddContactButton, SIGNAL(clicked()),
63 this, SLOT(openAddContactPanel()));
Yingdi Yu847aa862013-10-09 16:35:53 -070064}
65
66ContactPanel::~ContactPanel()
67{
68 delete ui;
Yingdi Yu40eca752013-10-10 15:00:58 -070069 delete m_contactListModel;
Yingdi Yu0269c872013-10-16 13:16:49 -070070 delete m_profileEditor;
71 delete m_addContactPanel;
Yingdi Yu847aa862013-10-09 16:35:53 -070072}
73
Yingdi Yu40eca752013-10-10 15:00:58 -070074void
75ContactPanel::updateSelection(const QItemSelection &selected,
76 const QItemSelection &deselected)
77{
78 QModelIndexList items = selected.indexes();
79 QString text = m_contactListModel->data(items.first(), Qt::DisplayRole).toString();
80 ui->NameData->setText(text);
81}
Yingdi Yu847aa862013-10-09 16:35:53 -070082
Yingdi Yu3b318c12013-10-15 17:54:00 -070083void
84ContactPanel::openProfileEditor()
Yingdi Yu0269c872013-10-16 13:16:49 -070085{ m_profileEditor->show(); }
Yingdi Yu3b318c12013-10-15 17:54:00 -070086
Yingdi Yu0269c872013-10-16 13:16:49 -070087void
88ContactPanel::openAddContactPanel()
89{ m_addContactPanel->show(); }
Yingdi Yu3b318c12013-10-15 17:54:00 -070090
Yingdi Yu847aa862013-10-09 16:35:53 -070091#if WAF
92#include "contactpanel.moc"
93#include "contactpanel.cpp.moc"
94#endif