1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-18 14:21:49 -05:00
sdrangel/sdrgui/gui/ambedevicesdialog.cpp

179 lines
5.6 KiB
C++
Raw Normal View History

2019-07-19 12:38:03 -04:00
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2019 F4EXB //
// written by Edouard Griffiths //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <QString>
2019-07-19 23:47:22 -04:00
#include <QListWidgetItem>
2019-07-19 12:38:03 -04:00
#include "ambedevicesdialog.h"
#include "ui_ambedevicesdialog.h"
2019-07-20 17:25:00 -04:00
AMBEDevicesDialog::AMBEDevicesDialog(AMBEEngine* ambeEngine, QWidget* parent) :
2019-07-19 12:38:03 -04:00
QDialog(parent),
ui(new Ui::AMBEDevicesDialog),
m_ambeEngine(ambeEngine)
{
ui->setupUi(this);
populateSerialList();
2019-07-19 23:47:22 -04:00
refreshInUseList();
2019-07-19 12:38:03 -04:00
}
AMBEDevicesDialog::~AMBEDevicesDialog()
{
delete ui;
}
void AMBEDevicesDialog::populateSerialList()
{
std::vector<QString> ambeSerialDevices;
2019-07-20 17:25:00 -04:00
m_ambeEngine->scan(ambeSerialDevices);
2019-07-19 23:47:22 -04:00
ui->ambeSerialDevices->clear();
2019-07-19 12:38:03 -04:00
std::vector<QString>::const_iterator it = ambeSerialDevices.begin();
for (; it != ambeSerialDevices.end(); ++it)
{
ui->ambeSerialDevices->addItem(QString(*it));
}
2019-07-19 23:47:22 -04:00
}
void AMBEDevicesDialog::refreshInUseList()
{
std::vector<QString> inUseDevices;
2019-07-20 17:25:00 -04:00
m_ambeEngine->getDeviceRefs(inUseDevices);
2019-07-19 23:47:22 -04:00
ui->ambeDeviceRefs->clear();
std::vector<QString>::const_iterator it = inUseDevices.begin();
for (; it != inUseDevices.end(); ++it)
{
qDebug("AMBEDevicesDialog::refreshInUseList: %s", qPrintable(*it));
ui->ambeDeviceRefs->addItem(*it);
}
}
2020-11-14 05:13:32 -05:00
void AMBEDevicesDialog::on_importSerial_clicked()
2019-07-19 23:47:22 -04:00
{
QListWidgetItem *serialItem = ui->ambeSerialDevices->currentItem();
if (!serialItem)
{
ui->statusText->setText("No selection");
return;
}
QString serialName = serialItem->text();
QList<QListWidgetItem*> foundItems = ui->ambeDeviceRefs->findItems(serialName, Qt::MatchFixedString|Qt::MatchCaseSensitive);
if (foundItems.size() == 0)
{
2019-07-20 17:25:00 -04:00
if (m_ambeEngine->registerController(serialName.toStdString()))
2019-07-19 23:47:22 -04:00
{
ui->ambeDeviceRefs->addItem(serialName);
ui->statusText->setText(tr("%1 added").arg(serialName));
}
else
{
ui->statusText->setText(tr("Cannot open %1").arg(serialName));
}
}
else
{
ui->statusText->setText("Device already in use");
}
}
2020-11-14 05:13:32 -05:00
void AMBEDevicesDialog::on_importAllSerial_clicked()
2019-07-19 23:47:22 -04:00
{
int count = 0;
for (int i = 0; i < ui->ambeSerialDevices->count(); i++)
{
const QListWidgetItem *serialItem = ui->ambeSerialDevices->item(i);
QString serialName = serialItem->text();
QList<QListWidgetItem*> foundItems = ui->ambeDeviceRefs->findItems(serialName, Qt::MatchFixedString|Qt::MatchCaseSensitive);
if (foundItems.size() == 0)
{
2019-07-20 17:25:00 -04:00
if (m_ambeEngine->registerController(serialName.toStdString()))
2019-07-19 23:47:22 -04:00
{
ui->ambeDeviceRefs->addItem(serialName);
count++;
}
}
}
ui->statusText->setText(tr("%1 devices added").arg(count));
}
2020-11-14 05:13:32 -05:00
void AMBEDevicesDialog::on_removeAmbeDevice_clicked()
2019-07-19 23:47:22 -04:00
{
QListWidgetItem *deviceItem = ui->ambeDeviceRefs->currentItem();
if (!deviceItem)
{
ui->statusText->setText("No selection");
return;
}
QString deviceName = deviceItem->text();
2019-07-20 17:25:00 -04:00
m_ambeEngine->releaseController(deviceName.toStdString());
2019-07-19 23:47:22 -04:00
ui->statusText->setText(tr("%1 removed").arg(deviceName));
refreshInUseList();
}
2020-11-14 05:13:32 -05:00
void AMBEDevicesDialog::on_refreshAmbeList_clicked()
2019-07-19 23:47:22 -04:00
{
refreshInUseList();
ui->statusText->setText("In use refreshed");
}
2020-11-14 05:13:32 -05:00
void AMBEDevicesDialog::on_clearAmbeList_clicked()
2019-07-19 23:47:22 -04:00
{
if (ui->ambeDeviceRefs->count() == 0)
{
ui->statusText->setText("No active items");
return;
}
2019-07-20 17:25:00 -04:00
m_ambeEngine->releaseAll();
2019-07-19 23:47:22 -04:00
ui->ambeDeviceRefs->clear();
ui->statusText->setText("All items released");
}
2020-11-14 05:13:32 -05:00
void AMBEDevicesDialog::on_importAddress_clicked()
2019-07-19 23:47:22 -04:00
{
QString addressAndPort = ui->ambeAddressText->text();
QList<QListWidgetItem*> foundItems = ui->ambeDeviceRefs->findItems(addressAndPort, Qt::MatchFixedString|Qt::MatchCaseSensitive);
if (foundItems.size() == 0)
{
2019-07-20 17:25:00 -04:00
if (m_ambeEngine->registerController(addressAndPort.toStdString()))
2019-07-19 23:47:22 -04:00
{
ui->ambeDeviceRefs->addItem(addressAndPort);
ui->statusText->setText(tr("%1 added").arg(addressAndPort));
}
else
{
ui->statusText->setText(tr("Cannot open %1").arg(addressAndPort));
}
}
else
{
ui->statusText->setText("Address already in use");
}
}