blob: f0b067d14846c993bf473168da3dbec87bd98b21 [file] [log] [blame]
Yingdi Yu348f5ea2014-03-01 14:47:25 -08001/* -*- 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 Yu0b0a7362014-08-05 16:31:30 -070011#include "profile-editor.hpp"
Yingdi Yu348f5ea2014-03-01 14:47:25 -080012#include "ui_profile-editor.h"
13#include <QtSql/QSqlRecord>
14#include <QtSql/QSqlField>
15#include <QtSql/QSqlError>
16
17#ifndef Q_MOC_RUN
18#include "logging.h"
19#endif
20
Yingdi Yu0b0a7362014-08-05 16:31:30 -070021// INIT_LOGGER("ProfileEditor")
22
Yingdi Yueb692ac2015-02-10 18:46:18 -080023namespace chronochat {
Yingdi Yu348f5ea2014-03-01 14:47:25 -080024
Yingdi Yufa0b6a02014-04-30 14:26:42 -070025ProfileEditor::ProfileEditor(QWidget *parent)
Yingdi Yu348f5ea2014-03-01 14:47:25 -080026 : QDialog(parent)
27 , ui(new Ui::ProfileEditor)
28 , m_tableModel(new QSqlTableModel())
29{
30 ui->setupUi(this);
31
32 connect(ui->addRowButton, SIGNAL(clicked()),
33 this, SLOT(onAddClicked()));
34 connect(ui->deleteRowButton, SIGNAL(clicked()),
35 this, SLOT(onDeleteClicked()));
36 connect(ui->okButton, SIGNAL(clicked()),
37 this, SLOT(onOkClicked()));
38}
39
40ProfileEditor::~ProfileEditor()
41{
42 delete ui;
Varun Patil3d850902020-11-23 12:19:14 +053043
44 if (m_tableModel)
45 delete m_tableModel;
Yingdi Yu348f5ea2014-03-01 14:47:25 -080046}
47
48void
49ProfileEditor::onCloseDBModule()
50{
Yingdi Yu0b0a7362014-08-05 16:31:30 -070051 if (m_tableModel) {
52 delete m_tableModel;
Varun Patil3d850902020-11-23 12:19:14 +053053 m_tableModel = 0;
Yingdi Yu0b0a7362014-08-05 16:31:30 -070054 }
Yingdi Yu348f5ea2014-03-01 14:47:25 -080055}
56
57void
58ProfileEditor::onIdentityUpdated(const QString& identity)
59{
Yingdi Yu348f5ea2014-03-01 14:47:25 -080060 m_identity = identity;
61 ui->identityInput->setText(identity);
Varun Patil3d850902020-11-23 12:19:14 +053062}
63
64void
65ProfileEditor::resetPanel()
66{
67 m_tableModel = new QSqlTableModel();
Yingdi Yufa0b6a02014-04-30 14:26:42 -070068
Yingdi Yu348f5ea2014-03-01 14:47:25 -080069 m_tableModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
70 m_tableModel->setTable("SelfProfile");
71 m_tableModel->select();
72 m_tableModel->setHeaderData(0, Qt::Horizontal, QObject::tr("Type"));
73 m_tableModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Value"));
74
75 ui->profileTable->setModel(m_tableModel);
76 ui->profileTable->show();
77}
78
79void
80ProfileEditor::onAddClicked()
81{
82 int rowCount = m_tableModel->rowCount();
83 QSqlRecord record;
84 m_tableModel->insertRow(rowCount);
85 m_tableModel->setRecord(rowCount, record);
86}
87
88void
89ProfileEditor::onDeleteClicked()
90{
91 QItemSelectionModel* selectionModel = ui->profileTable->selectionModel();
92 QModelIndexList indexList = selectionModel->selectedIndexes();
93
Yingdi Yu0b0a7362014-08-05 16:31:30 -070094 for (int i = indexList.size() - 1; i >= 0; i--)
Yingdi Yu348f5ea2014-03-01 14:47:25 -080095 m_tableModel->removeRow(indexList[i].row());
Yingdi Yufa0b6a02014-04-30 14:26:42 -070096
Yingdi Yu348f5ea2014-03-01 14:47:25 -080097 m_tableModel->submitAll();
98}
99
100void
101ProfileEditor::onOkClicked()
102{
103 m_tableModel->submitAll();
104 emit updateProfile();
105 this->hide();
106}
107
Yingdi Yueb692ac2015-02-10 18:46:18 -0800108} // namespace chronochat
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700109
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800110#if WAF
111#include "profile-editor.moc"
Yingdi Yu42125862014-08-07 17:04:28 -0700112// #include "profile-editor.cpp.moc"
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800113#endif