/*************************************************************************************** * * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. * * By downloading, copying, installing or using the software you agree to this license. * If you do not agree to this license, do not download, install, * copy or use the software. * * Copyright (C) 2014-2022, Happytimesoft Corporation, all rights reserved. * * Redistribution and use in binary forms, with or without modification, are permitted. * * Unless required by applicable law or agreed to in writing, software distributed * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific * language governing permissions and limitations under the License. * ****************************************************************************************/ #include "ChannelSetting.h" #include "utils.h" /**************************************************************************************/ ChannelSetting::ChannelSetting(QWidget *parent) : QDialog(parent), ui(new Ui::ChannelSetting) { ui->setupUi(this); initDialog(); connSignalSlot(); showMaximized(); } ChannelSetting::~ChannelSetting() { delete ui; } void ChannelSetting::initDialog() { int i; QStringList header; header << tr("Channel Id") << tr("Channel Name"); for (i = 0; i < header.count(); i++) { ui->tabChannel->insertColumn(i); } ui->tabChannel->setHorizontalHeaderLabels(header); QList channels; if (!getChannels(channels) || channels.size() == 0) { // add default channel GBCHANNEL channel; strcpy(channel.cid, "34020000001310000001"); strcpy(channel.cname, "channel1"); channels.append(channel); } for (i = 0; i < channels.size(); i++) { int row = ui->tabChannel->rowCount(); ui->tabChannel->insertRow(row); QTableWidgetItem * item = new QTableWidgetItem(); item->setText(channels[i].cid); ui->tabChannel->setItem(row, 0, item); item = new QTableWidgetItem(); item->setText(channels[i].cname); ui->tabChannel->setItem(row, 1, item); } ui->tabChannel->setColumnWidth(0, 170); } void ChannelSetting::connSignalSlot() { connect(ui->btnAddChannel, SIGNAL(clicked()), this, SLOT(slotAddChannel())); connect(ui->btnModifyChannel, SIGNAL(clicked()), this, SLOT(slotModifyChannel())); connect(ui->btnRemoveChannel, SIGNAL(clicked()), this, SLOT(slotRemoveChannel())); connect(ui->btnCancel, SIGNAL(clicked()), this, SLOT(close())); connect(ui->btnConfirm, SIGNAL(clicked()), this, SLOT(slotConfirm())); } void ChannelSetting::slotAddChannel() { int row = ui->tabChannel->rowCount(); QString cid; if (row > 0) { cid = ui->tabChannel->item(row-1, 0)->text(); if (cid.size() > 4) { QString r = cid.right(4); QString l = cid.left(cid.size()-4); cid = l + QString("%1").arg(r.toInt()+1, 4, 10, QChar('0')); } else { cid = "34020000001310000001"; } } else { cid = "34020000001310000001"; } ui->tabChannel->insertRow(row); QTableWidgetItem * item = new QTableWidgetItem(); item->setText(cid); ui->tabChannel->setItem(row, 0, item); item = new QTableWidgetItem(); item->setText(QString("channel%1").arg(row+1)); ui->tabChannel->setItem(row, 1, item); } void ChannelSetting::slotModifyChannel() { ui->tabChannel->editItem(ui->tabChannel->currentItem()); } void ChannelSetting::slotRemoveChannel() { int row = ui->tabChannel->currentRow(); if (row >= 0) { ui->tabChannel->removeRow(row); } } void ChannelSetting::slotConfirm() { int i; QString value; QList channels; for (i = 0; i < ui->tabChannel->rowCount() && channels.size() < MAX_CH_NUMS; i++) { GBCHANNEL channel; value = ui->tabChannel->item(i, 0)->text(); if (value.isEmpty()) { continue; } strncpy(channel.cid, value.toStdString().c_str(), sizeof(channel.cid)-1); value = ui->tabChannel->item(i, 1)->text(); strncpy(channel.cname, value.toStdString().c_str(), sizeof(channel.cname)-1); channels.append(channel); } saveChannels(channels); accept(); }