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 | |
Yingdi Yu | 9236c43 | 2013-10-18 11:29:25 -0700 | [diff] [blame^] | 31 | ContactPanel::ContactPanel(Ptr<ContactManager> contactManager, QWidget *parent) |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 32 | : QDialog(parent) |
| 33 | , ui(new Ui::ContactPanel) |
Yingdi Yu | 9236c43 | 2013-10-18 11:29:25 -0700 | [diff] [blame^] | 34 | , m_contactManager(contactManager) |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 35 | , m_contactListModel(new QStringListModel) |
Yingdi Yu | 9236c43 | 2013-10-18 11:29:25 -0700 | [diff] [blame^] | 36 | , m_addContactPanel(new AddContactPanel(contactManager)) |
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 | 9236c43 | 2013-10-18 11:29:25 -0700 | [diff] [blame^] | 47 | m_profileEditor = new ProfileEditor(m_contactManager->getContactStorage()); |
Yingdi Yu | 8f7325a | 2013-10-17 17:03:46 -0700 | [diff] [blame] | 48 | |
Yingdi Yu | 40eca75 | 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 | 0269c87 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 56 | |
Yingdi Yu | 40eca75 | 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 | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 59 | connect(ui->EditProfileButton, SIGNAL(clicked()), |
| 60 | this, SLOT(openProfileEditor())); |
Yingdi Yu | 0269c87 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 61 | |
| 62 | connect(ui->AddContactButton, SIGNAL(clicked()), |
| 63 | this, SLOT(openAddContactPanel())); |
Yingdi Yu | 847aa86 | 2013-10-09 16:35:53 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | ContactPanel::~ContactPanel() |
| 67 | { |
| 68 | delete ui; |
Yingdi Yu | 40eca75 | 2013-10-10 15:00:58 -0700 | [diff] [blame] | 69 | delete m_contactListModel; |
Yingdi Yu | 0269c87 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 70 | delete m_profileEditor; |
| 71 | delete m_addContactPanel; |
Yingdi Yu | 847aa86 | 2013-10-09 16:35:53 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Yingdi Yu | 40eca75 | 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 | 847aa86 | 2013-10-09 16:35:53 -0700 | [diff] [blame] | 82 | |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 83 | void |
| 84 | ContactPanel::openProfileEditor() |
Yingdi Yu | 0269c87 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 85 | { m_profileEditor->show(); } |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 86 | |
Yingdi Yu | 0269c87 | 2013-10-16 13:16:49 -0700 | [diff] [blame] | 87 | void |
| 88 | ContactPanel::openAddContactPanel() |
| 89 | { m_addContactPanel->show(); } |
Yingdi Yu | 3b318c1 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 90 | |
Yingdi Yu | 847aa86 | 2013-10-09 16:35:53 -0700 | [diff] [blame] | 91 | #if WAF |
| 92 | #include "contactpanel.moc" |
| 93 | #include "contactpanel.cpp.moc" |
| 94 | #endif |