blob: 985d0a83e18e4674c92c5d4b1dbc2dcc97224cc5 [file] [log] [blame]
Yingdi Yu9e0dc292013-10-10 11:39:45 -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
Yingdi Yudef90612013-10-09 22:34:42 -070011#include "contactpanel.h"
12#include "ui_contactpanel.h"
13
Yingdi Yu01a942b2013-10-10 15:00:58 -070014
15#include <QStringList>
16#include <QItemSelectionModel>
17#include <QModelIndex>
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070018#include <QDir>
Yingdi Yu01a942b2013-10-10 15:00:58 -070019
Yingdi Yu0a6b6c52013-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
31ContactPanel::ContactPanel(Ptr<ContactStorage> contactStorage, QWidget *parent)
32 : QDialog(parent)
33 , ui(new Ui::ContactPanel)
34 , m_contactStorage(contactStorage)
35 , m_contactListModel(new QStringListModel)
Yingdi Yud59b5932013-10-16 13:16:49 -070036 , m_addContactPanel(new AddContactPanel())
Yingdi Yudef90612013-10-09 22:34:42 -070037{
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070038
Yingdi Yudef90612013-10-09 22:34:42 -070039 ui->setupUi(this);
Yingdi Yu01a942b2013-10-10 15:00:58 -070040
Yingdi Yu0a6b6c52013-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 Yuc26af3c2013-10-17 17:03:46 -070047 m_profileEditor = new ProfileEditor(m_contactStorage);
48
Yingdi Yu01a942b2013-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 Yud59b5932013-10-16 13:16:49 -070056
Yingdi Yu01a942b2013-10-10 15:00:58 -070057 connect(selectionModel, SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
58 this, SLOT(updateSelection(const QItemSelection &, const QItemSelection &)));
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070059 connect(ui->EditProfileButton, SIGNAL(clicked()),
60 this, SLOT(openProfileEditor()));
Yingdi Yud59b5932013-10-16 13:16:49 -070061
62 connect(ui->AddContactButton, SIGNAL(clicked()),
63 this, SLOT(openAddContactPanel()));
Yingdi Yudef90612013-10-09 22:34:42 -070064}
65
66ContactPanel::~ContactPanel()
67{
68 delete ui;
Yingdi Yu01a942b2013-10-10 15:00:58 -070069 delete m_contactListModel;
Yingdi Yud59b5932013-10-16 13:16:49 -070070 delete m_profileEditor;
71 delete m_addContactPanel;
Yingdi Yudef90612013-10-09 22:34:42 -070072}
Yingdi Yu9e0dc292013-10-10 11:39:45 -070073
Yingdi Yu01a942b2013-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 Yu9e0dc292013-10-10 11:39:45 -070082
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070083void
84ContactPanel::openProfileEditor()
Yingdi Yud59b5932013-10-16 13:16:49 -070085{ m_profileEditor->show(); }
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070086
Yingdi Yud59b5932013-10-16 13:16:49 -070087void
88ContactPanel::openAddContactPanel()
89{ m_addContactPanel->show(); }
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070090
Yingdi Yu9e0dc292013-10-10 11:39:45 -070091#if WAF
92#include "contactpanel.moc"
93#include "contactpanel.cpp.moc"
94#endif