219 lines
6.6 KiB
C++
219 lines
6.6 KiB
C++
#include "qggrifodownloadentitiesform.h"
|
|
#include "ui_qggrifodownloadentitiesform.h"
|
|
|
|
#include <QStandardItemModel>
|
|
#include <QStandardItem>
|
|
|
|
#include <QProgressBar>
|
|
|
|
#include <QDropEvent>
|
|
#include <QDragEnterEvent>
|
|
#include <QMimeData>
|
|
|
|
#include "bsk_tftp_pfs.h"
|
|
|
|
#include <QHostAddress>
|
|
#include "mydebug.h"
|
|
|
|
//definition of columns for table
|
|
#define COL_TARGET 0
|
|
#define COL_ADDRESS 1
|
|
#define COL_AREA 2
|
|
#define COL_PROG 3
|
|
|
|
void QgGrifoDownloadEntitiesForm::db_add_site(QTreeWidget* root, QgGrifoDownloadSite* s)
|
|
{
|
|
QTreeWidgetItem* item=new QTreeWidgetItem(root);
|
|
bsk_download_site_t* site=&s->site;
|
|
|
|
item->setText(COL_TARGET, site->name);
|
|
item->setData(COL_TARGET, Qt::UserRole, (unsigned long long)site);
|
|
item->setToolTip(COL_TARGET, QString("%1 (%2)").arg(s->tgt->description).arg(s->tgt->archName));
|
|
item->setText(COL_ADDRESS, QString("%1@%2:%3")
|
|
.arg(site->address)
|
|
.arg(QHostAddress(site->media_address).toString())
|
|
.arg(site->media_port));
|
|
if (s->tgt)
|
|
{
|
|
item->setText(COL_AREA, QString("%1 - %2")
|
|
.arg(s->tgt->address_start_area)
|
|
.arg(s->tgt->address_stop_area));
|
|
|
|
|
|
s->tgt->wi=item;
|
|
}
|
|
|
|
if (site->partitions[0].name[0]==0)
|
|
{
|
|
item->setCheckState(COL_TARGET, Qt::Unchecked);
|
|
//item->setDisabled(true);
|
|
}
|
|
|
|
for(int i=0; i<bsk_download_site_t::k_max_partitions; ++i)
|
|
{
|
|
const bsk_download_partition_t& p=site->partitions[i];
|
|
if (p.name[0]==0)
|
|
break;
|
|
|
|
QTreeWidgetItem* partition=new QTreeWidgetItem;
|
|
item->addChild(partition);
|
|
partition->setText(COL_TARGET, p.name);
|
|
partition->setText(COL_ADDRESS, QString("%1").arg(p.subaddress));
|
|
partition->setData(COL_TARGET, Qt::UserRole, (unsigned long long)site);
|
|
partition->setData(COL_TARGET, Qt::UserRole+1, (unsigned long long)&p);
|
|
|
|
if (p.flags==bsk_download_partition_t::part_hidden)
|
|
partition->setDisabled(true);
|
|
if (p.flags==bsk_download_partition_t::part_default)
|
|
partition->setCheckState(COL_TARGET, Qt::PartiallyChecked);
|
|
}
|
|
|
|
QProgressBar* bp=new QProgressBar;
|
|
root->setItemWidget(item, COL_PROG, bp);
|
|
}
|
|
|
|
QString ShowFileInfo(const QString& fname, bool popup=true);
|
|
|
|
QgGrifoDownloadEntitiesForm::QgGrifoDownloadEntitiesForm(QWidget *parent) :
|
|
QWidget(parent),
|
|
ui(new Ui::QgGrifoDownloadEntitiesForm)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
ui->treeWidget->setColumnCount(4);
|
|
ui->treeWidget->headerItem()->setText(COL_TARGET, "Target");
|
|
ui->treeWidget->headerItem()->setText(COL_ADDRESS, "Address");
|
|
ui->treeWidget->headerItem()->setText(COL_AREA, "Flash area");
|
|
ui->treeWidget->headerItem()->setText(COL_PROG, "Upload");
|
|
ui->treeWidget->header()->setSectionResizeMode(COL_TARGET,QHeaderView::ResizeToContents);
|
|
ui->treeWidget->header()->setSectionResizeMode(COL_ADDRESS,QHeaderView::ResizeToContents);
|
|
ui->treeWidget->header()->setSectionResizeMode(COL_AREA,QHeaderView::ResizeToContents);
|
|
|
|
ui->treeWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
|
|
|
|
//ui->treeView->setC
|
|
connect(ui->treeWidget, &QTreeWidget::itemDoubleClicked, this,
|
|
[this](QTreeWidgetItem *item, int column)
|
|
{
|
|
if (column==0)
|
|
{
|
|
unsigned long long s=item->data(0, Qt::UserRole).toULongLong();
|
|
unsigned long long p=item->data(0, Qt::UserRole+1).toULongLong();
|
|
|
|
Q_EMIT itemSelected((void*)s, (void*)p);
|
|
}
|
|
else if (column==3)
|
|
{
|
|
//ShowFileInfo(item->toolTip(3));
|
|
}
|
|
});
|
|
|
|
this->setAcceptDrops(true);
|
|
}
|
|
|
|
QgGrifoDownloadEntitiesForm::~QgGrifoDownloadEntitiesForm()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
//***********************************************************************
|
|
// Add site target to send file for fpga-flash
|
|
// Input parameters: s = struct of new target
|
|
// Returns:
|
|
//***********************************************************************
|
|
void QgGrifoDownloadEntitiesForm::addSite(const QgGrifoDownloadSite *s)
|
|
{
|
|
db_add_site(ui->treeWidget, (QgGrifoDownloadSite*)s);
|
|
}
|
|
|
|
//***********************************************************************
|
|
// Clear all target from the treewidget
|
|
// Input parameters:
|
|
// Returns:
|
|
//***********************************************************************
|
|
void QgGrifoDownloadEntitiesForm::clear()
|
|
{
|
|
ui->treeWidget->clear();
|
|
}
|
|
|
|
void QgGrifoDownloadEntitiesForm::dragEnterEvent(QDragEnterEvent * event)
|
|
{
|
|
if (event->mimeData()->hasUrls())
|
|
{
|
|
QList<QUrl> lst=event->mimeData()->urls();
|
|
if ((lst.size()>0) && lst.size()<10)
|
|
{
|
|
event->acceptProposedAction();
|
|
MyDebug()<<"T Drop accepct";
|
|
}
|
|
}
|
|
}
|
|
|
|
void QgGrifoDownloadEntitiesForm::dropEvent(QDropEvent * event)
|
|
{
|
|
QList<QUrl> lst=event->mimeData()->urls();
|
|
if (lst.size()>0)
|
|
{
|
|
for(int i=0; i<lst.size(); ++i)
|
|
{
|
|
if (lst.at(i).isLocalFile())
|
|
{
|
|
MyDebug()<<"T Drop"<<lst.at(i).toLocalFile();
|
|
QPoint p=QCursor::pos();
|
|
QTreeWidgetItem* wi=ui->treeWidget->itemAt(ui->treeWidget->viewport()->mapFromGlobal(p));
|
|
if (i)
|
|
{
|
|
MyDebug()<<"I"<<wi->text(0);
|
|
}
|
|
Q_EMIT fileDroppped(wi, lst.at(i).toLocalFile());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//***********************************************************************
|
|
// Select Default Target into List of available targets
|
|
// Input parameters: _def_target = search target with this string into targetSection
|
|
//
|
|
// Returns:
|
|
//***********************************************************************
|
|
void QgGrifoDownloadEntitiesForm::setDefaultTarget(QString _def_target)
|
|
{
|
|
QTreeWidgetItemIterator it(ui->treeWidget);
|
|
|
|
while(*it)
|
|
{
|
|
QTreeWidgetItem* item = *it;
|
|
if(item && item->text(0) == _def_target)
|
|
{
|
|
item->setCheckState(COL_TARGET, Qt::Checked);
|
|
break;
|
|
}
|
|
++it;
|
|
}
|
|
}
|
|
|
|
//***********************************************************************
|
|
// Get first target are selected into treeWidget
|
|
// Input parameters:
|
|
//
|
|
// Returns: target name
|
|
//***********************************************************************
|
|
QString QgGrifoDownloadEntitiesForm::getFirstSelectedTarget()
|
|
{
|
|
QTreeWidgetItemIterator it(ui->treeWidget);
|
|
|
|
while(*it)
|
|
{
|
|
QTreeWidgetItem* item = *it;
|
|
if(item && item->checkState(COL_TARGET)==Qt::Checked)
|
|
{
|
|
return item->text(0);
|
|
break;
|
|
}
|
|
++it;
|
|
}
|
|
|
|
return 0;
|
|
}
|