Yingdi Yu | 9e0dc29 | 2013-10-10 11:39:45 -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 | |
Yingdi Yu | def9061 | 2013-10-09 22:34:42 -0700 | [diff] [blame] | 11 | #include "contactpanel.h" |
| 12 | #include "ui_contactpanel.h" |
| 13 | |
Yingdi Yu | 01a942b | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 14 | |
| 15 | #include <QStringList> |
| 16 | #include <QItemSelectionModel> |
| 17 | #include <QModelIndex> |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 18 | #include <QDir> |
Yingdi Yu | 01a942b | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 19 | |
Yingdi Yu | 0a6b6c5 | 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) |
Yingdi Yu | d59b593 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 36 | , m_addContactPanel(new AddContactPanel()) |
Yingdi Yu | def9061 | 2013-10-09 22:34:42 -0700 | [diff] [blame] | 37 | { |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 38 | |
Yingdi Yu | def9061 | 2013-10-09 22:34:42 -0700 | [diff] [blame] | 39 | ui->setupUi(this); |
Yingdi Yu | 01a942b | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 40 | |
Yingdi Yu | 0a6b6c5 | 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 | c26af3c | 2013-10-17 17:03:46 -0700 | [diff] [blame^] | 47 | m_profileEditor = new ProfileEditor(m_contactStorage); |
| 48 | |
Yingdi Yu | 01a942b | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 49 | 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 Yu | d59b593 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 56 | |
Yingdi Yu | 01a942b | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 57 | connect(selectionModel, SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), |
| 58 | this, SLOT(updateSelection(const QItemSelection &, const QItemSelection &))); |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 59 | connect(ui->EditProfileButton, SIGNAL(clicked()), |
| 60 | this, SLOT(openProfileEditor())); |
Yingdi Yu | d59b593 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 61 | |
| 62 | connect(ui->AddContactButton, SIGNAL(clicked()), |
| 63 | this, SLOT(openAddContactPanel())); |
Yingdi Yu | def9061 | 2013-10-09 22:34:42 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | ContactPanel::~ContactPanel() |
| 67 | { |
| 68 | delete ui; |
Yingdi Yu | 01a942b | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 69 | delete m_contactListModel; |
Yingdi Yu | d59b593 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 70 | delete m_profileEditor; |
| 71 | delete m_addContactPanel; |
Yingdi Yu | def9061 | 2013-10-09 22:34:42 -0700 | [diff] [blame] | 72 | } |
Yingdi Yu | 9e0dc29 | 2013-10-10 11:39:45 -0700 | [diff] [blame] | 73 | |
Yingdi Yu | 01a942b | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 74 | void |
| 75 | ContactPanel::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 Yu | 9e0dc29 | 2013-10-10 11:39:45 -0700 | [diff] [blame] | 82 | |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 83 | void |
| 84 | ContactPanel::openProfileEditor() |
Yingdi Yu | d59b593 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 85 | { m_profileEditor->show(); } |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 86 | |
Yingdi Yu | d59b593 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 87 | void |
| 88 | ContactPanel::openAddContactPanel() |
| 89 | { m_addContactPanel->show(); } |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 90 | |
Yingdi Yu | 9e0dc29 | 2013-10-10 11:39:45 -0700 | [diff] [blame] | 91 | #if WAF |
| 92 | #include "contactpanel.moc" |
| 93 | #include "contactpanel.cpp.moc" |
| 94 | #endif |