Yingdi Yu | 847aa86 | 2013-10-09 16:35:53 -0700 | [diff] [blame] | 1 | /* -*- 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 Yu | 40eca75 | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 14 | |
| 15 | #include <QStringList> |
| 16 | #include <QItemSelectionModel> |
| 17 | #include <QModelIndex> |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame^] | 18 | #include <QDir> |
Yingdi Yu | 40eca75 | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 19 | |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame^] | 20 | #ifndef Q_MOC_RUN |
| 21 | #include <boost/filesystem.hpp> |
| 22 | #include "logging.h" |
| 23 | #include "exception.h" |
| 24 | #endif |
| 25 | |
| 26 | namespace fs = boost::filesystem; |
| 27 | using namespace ndn; |
| 28 | |
| 29 | INIT_LOGGER("ContactPanel"); |
| 30 | |
| 31 | ContactPanel::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 Yu | 847aa86 | 2013-10-09 16:35:53 -0700 | [diff] [blame] | 37 | { |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame^] | 38 | |
Yingdi Yu | 847aa86 | 2013-10-09 16:35:53 -0700 | [diff] [blame] | 39 | ui->setupUi(this); |
Yingdi Yu | 40eca75 | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 40 | |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame^] | 41 | 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 Yu | 40eca75 | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 47 | 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 Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame^] | 56 | connect(ui->EditProfileButton, SIGNAL(clicked()), |
| 57 | this, SLOT(openProfileEditor())); |
Yingdi Yu | 847aa86 | 2013-10-09 16:35:53 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | ContactPanel::~ContactPanel() |
| 61 | { |
| 62 | delete ui; |
Yingdi Yu | 40eca75 | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 63 | delete m_contactListModel; |
Yingdi Yu | 847aa86 | 2013-10-09 16:35:53 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Yingdi Yu | 40eca75 | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 66 | void |
| 67 | ContactPanel::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 Yu | 847aa86 | 2013-10-09 16:35:53 -0700 | [diff] [blame] | 74 | |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame^] | 75 | void |
| 76 | ContactPanel::openProfileEditor() |
| 77 | { |
| 78 | if(m_profileEditor == NULL) |
| 79 | m_profileEditor = new ProfileEditor(m_contactStorage); |
| 80 | |
| 81 | m_profileEditor->show(); |
| 82 | } |
| 83 | |
Yingdi Yu | 847aa86 | 2013-10-09 16:35:53 -0700 | [diff] [blame] | 84 | #if WAF |
| 85 | #include "contactpanel.moc" |
| 86 | #include "contactpanel.cpp.moc" |
| 87 | #endif |