blob: 5dea76c5eb0706c80b421e5ca5d58e8149014bbb [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)
36 , m_profileEditor(NULL)
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 Yu01a942b2013-10-10 15:00:58 -070047 QStringList contactNameList;
48 contactNameList << "Alex" << "Wentao" << "Yingdi";
49
50 m_contactListModel->setStringList(contactNameList);
51 ui->ContactList->setModel(m_contactListModel);
52
53 QItemSelectionModel* selectionModel = ui->ContactList->selectionModel();
54 connect(selectionModel, SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
55 this, SLOT(updateSelection(const QItemSelection &, const QItemSelection &)));
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070056 connect(ui->EditProfileButton, SIGNAL(clicked()),
57 this, SLOT(openProfileEditor()));
Yingdi Yudef90612013-10-09 22:34:42 -070058}
59
60ContactPanel::~ContactPanel()
61{
62 delete ui;
Yingdi Yu01a942b2013-10-10 15:00:58 -070063 delete m_contactListModel;
Yingdi Yudef90612013-10-09 22:34:42 -070064}
Yingdi Yu9e0dc292013-10-10 11:39:45 -070065
Yingdi Yu01a942b2013-10-10 15:00:58 -070066void
67ContactPanel::updateSelection(const QItemSelection &selected,
68 const QItemSelection &deselected)
69{
70 QModelIndexList items = selected.indexes();
71 QString text = m_contactListModel->data(items.first(), Qt::DisplayRole).toString();
72 ui->NameData->setText(text);
73}
Yingdi Yu9e0dc292013-10-10 11:39:45 -070074
Yingdi Yu0a6b6c52013-10-15 17:54:00 -070075void
76ContactPanel::openProfileEditor()
77{
78 if(m_profileEditor == NULL)
79 m_profileEditor = new ProfileEditor(m_contactStorage);
80
81 m_profileEditor->show();
82}
83
Yingdi Yu9e0dc292013-10-10 11:39:45 -070084#if WAF
85#include "contactpanel.moc"
86#include "contactpanel.cpp.moc"
87#endif