blob: 5dea76c5eb0706c80b421e5ca5d58e8149014bbb [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
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 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 Yu40eca752013-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 Yu3b318c12013-10-15 17:54:00 -070056 connect(ui->EditProfileButton, SIGNAL(clicked()),
57 this, SLOT(openProfileEditor()));
Yingdi Yu847aa862013-10-09 16:35:53 -070058}
59
60ContactPanel::~ContactPanel()
61{
62 delete ui;
Yingdi Yu40eca752013-10-10 15:00:58 -070063 delete m_contactListModel;
Yingdi Yu847aa862013-10-09 16:35:53 -070064}
65
Yingdi Yu40eca752013-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 Yu847aa862013-10-09 16:35:53 -070074
Yingdi Yu3b318c12013-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 Yu847aa862013-10-09 16:35:53 -070084#if WAF
85#include "contactpanel.moc"
86#include "contactpanel.cpp.moc"
87#endif