blob: f103100e7cd9fcccb2808d87d065a1252f387de3 [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_profileEditor(new ProfileEditor(m_contactStorage))
37 , m_addContactPanel(new AddContactPanel())
Yingdi Yudef90612013-10-09 22:34:42 -070038{
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070039
Yingdi Yudef90612013-10-09 22:34:42 -070040 ui->setupUi(this);
Yingdi Yu01a942b2013-10-10 15:00:58 -070041
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070042 QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
43 QString path = (QDir::home().path());
44 path.append(QDir::separator()).append(".chronos").append(QDir::separator()).append("chronos.db");
45 db.setDatabaseName(path);
46 bool ok = db.open();
47
Yingdi Yu01a942b2013-10-10 15:00:58 -070048 QStringList contactNameList;
49 contactNameList << "Alex" << "Wentao" << "Yingdi";
50
51 m_contactListModel->setStringList(contactNameList);
52 ui->ContactList->setModel(m_contactListModel);
53
54 QItemSelectionModel* selectionModel = ui->ContactList->selectionModel();
Yingdi Yud59b5932013-10-16 13:16:49 -070055
Yingdi Yu01a942b2013-10-10 15:00:58 -070056 connect(selectionModel, SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
57 this, SLOT(updateSelection(const QItemSelection &, const QItemSelection &)));
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070058 connect(ui->EditProfileButton, SIGNAL(clicked()),
59 this, SLOT(openProfileEditor()));
Yingdi Yud59b5932013-10-16 13:16:49 -070060
61 connect(ui->AddContactButton, SIGNAL(clicked()),
62 this, SLOT(openAddContactPanel()));
Yingdi Yudef90612013-10-09 22:34:42 -070063}
64
65ContactPanel::~ContactPanel()
66{
67 delete ui;
Yingdi Yu01a942b2013-10-10 15:00:58 -070068 delete m_contactListModel;
Yingdi Yud59b5932013-10-16 13:16:49 -070069 delete m_profileEditor;
70 delete m_addContactPanel;
Yingdi Yudef90612013-10-09 22:34:42 -070071}
Yingdi Yu9e0dc292013-10-10 11:39:45 -070072
Yingdi Yu01a942b2013-10-10 15:00:58 -070073void
74ContactPanel::updateSelection(const QItemSelection &selected,
75 const QItemSelection &deselected)
76{
77 QModelIndexList items = selected.indexes();
78 QString text = m_contactListModel->data(items.first(), Qt::DisplayRole).toString();
79 ui->NameData->setText(text);
80}
Yingdi Yu9e0dc292013-10-10 11:39:45 -070081
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070082void
83ContactPanel::openProfileEditor()
Yingdi Yud59b5932013-10-16 13:16:49 -070084{ m_profileEditor->show(); }
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070085
Yingdi Yud59b5932013-10-16 13:16:49 -070086void
87ContactPanel::openAddContactPanel()
88{ m_addContactPanel->show(); }
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070089
Yingdi Yu9e0dc292013-10-10 11:39:45 -070090#if WAF
91#include "contactpanel.moc"
92#include "contactpanel.cpp.moc"
93#endif