blob: fbfe1054edbb01e1b0020a04eeeabcf738a2577a [file] [log] [blame]
Yingdi Yu348f5ea2014-03-01 14:47:25 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
Varun Patila24bd3e2020-11-24 10:08:33 +05303 * Copyright (c) 2020, Regents of the University of California
Yingdi Yu348f5ea2014-03-01 14:47:25 -08004 * 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
Yingdi Yueb692ac2015-02-10 18:46:18 -080017namespace chronochat {
Yingdi Yu348f5ea2014-03-01 14:47:25 -080018
Yingdi Yufa0b6a02014-04-30 14:26:42 -070019ProfileEditor::ProfileEditor(QWidget *parent)
Yingdi Yu348f5ea2014-03-01 14:47:25 -080020 : QDialog(parent)
21 , ui(new Ui::ProfileEditor)
22 , m_tableModel(new QSqlTableModel())
23{
24 ui->setupUi(this);
25
26 connect(ui->addRowButton, SIGNAL(clicked()),
27 this, SLOT(onAddClicked()));
28 connect(ui->deleteRowButton, SIGNAL(clicked()),
29 this, SLOT(onDeleteClicked()));
30 connect(ui->okButton, SIGNAL(clicked()),
31 this, SLOT(onOkClicked()));
32}
33
34ProfileEditor::~ProfileEditor()
35{
36 delete ui;
Varun Patila24bd3e2020-11-24 10:08:33 +053037 delete m_tableModel;
Yingdi Yu348f5ea2014-03-01 14:47:25 -080038}
39
40void
41ProfileEditor::onCloseDBModule()
42{
Yingdi Yu0b0a7362014-08-05 16:31:30 -070043 if (m_tableModel) {
44 delete m_tableModel;
Varun Patil3d850902020-11-23 12:19:14 +053045 m_tableModel = 0;
Yingdi Yu0b0a7362014-08-05 16:31:30 -070046 }
Yingdi Yu348f5ea2014-03-01 14:47:25 -080047}
48
49void
50ProfileEditor::onIdentityUpdated(const QString& identity)
51{
Yingdi Yu348f5ea2014-03-01 14:47:25 -080052 m_identity = identity;
53 ui->identityInput->setText(identity);
Varun Patil3d850902020-11-23 12:19:14 +053054}
55
56void
57ProfileEditor::resetPanel()
58{
59 m_tableModel = new QSqlTableModel();
Yingdi Yufa0b6a02014-04-30 14:26:42 -070060
Yingdi Yu348f5ea2014-03-01 14:47:25 -080061 m_tableModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
62 m_tableModel->setTable("SelfProfile");
63 m_tableModel->select();
64 m_tableModel->setHeaderData(0, Qt::Horizontal, QObject::tr("Type"));
65 m_tableModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Value"));
66
67 ui->profileTable->setModel(m_tableModel);
68 ui->profileTable->show();
69}
70
71void
72ProfileEditor::onAddClicked()
73{
74 int rowCount = m_tableModel->rowCount();
75 QSqlRecord record;
76 m_tableModel->insertRow(rowCount);
77 m_tableModel->setRecord(rowCount, record);
78}
79
80void
81ProfileEditor::onDeleteClicked()
82{
83 QItemSelectionModel* selectionModel = ui->profileTable->selectionModel();
84 QModelIndexList indexList = selectionModel->selectedIndexes();
85
Yingdi Yu0b0a7362014-08-05 16:31:30 -070086 for (int i = indexList.size() - 1; i >= 0; i--)
Yingdi Yu348f5ea2014-03-01 14:47:25 -080087 m_tableModel->removeRow(indexList[i].row());
Yingdi Yufa0b6a02014-04-30 14:26:42 -070088
Yingdi Yu348f5ea2014-03-01 14:47:25 -080089 m_tableModel->submitAll();
90}
91
92void
93ProfileEditor::onOkClicked()
94{
95 m_tableModel->submitAll();
96 emit updateProfile();
97 this->hide();
98}
99
Yingdi Yueb692ac2015-02-10 18:46:18 -0800100} // namespace chronochat
Yingdi Yu0b0a7362014-08-05 16:31:30 -0700101
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800102#if WAF
103#include "profile-editor.moc"
Yingdi Yu348f5ea2014-03-01 14:47:25 -0800104#endif