mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-02 07:05:38 +08:00
refs #452 status bar for web reading
* status of load requests * is swift DB available?
This commit is contained in:
committed by
Mathew Sutcliffe
parent
fc772c6540
commit
bcd821812f
140
src/blackgui/components/infobarwebreadersstatuscomponent.cpp
Normal file
140
src/blackgui/components/infobarwebreadersstatuscomponent.cpp
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
/* Copyright (C) 2015
|
||||||
|
* swift project Community / Contributors
|
||||||
|
*
|
||||||
|
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||||
|
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||||
|
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||||
|
* contained in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "infobarwebreadersstatuscomponent.h"
|
||||||
|
#include "ui_infobarwebreadersstatuscomponent.h"
|
||||||
|
#include "blackcore/webreaderflags.h"
|
||||||
|
#include "blackmisc/icons.h"
|
||||||
|
|
||||||
|
using namespace BlackGui;
|
||||||
|
using namespace BlackMisc;
|
||||||
|
using namespace BlackCore;
|
||||||
|
using namespace BlackMisc::Network;
|
||||||
|
|
||||||
|
namespace BlackGui
|
||||||
|
{
|
||||||
|
namespace Components
|
||||||
|
{
|
||||||
|
CInfoBarWebReadersStatusComponent::CInfoBarWebReadersStatusComponent(QWidget *parent) :
|
||||||
|
QFrame(parent), ui(new Ui::CInfoBarWebReadersStatusComponent)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
this->initLeds();
|
||||||
|
connect(&m_timer, &QTimer::timeout, this, &CInfoBarWebReadersStatusComponent::ps_checkServerAndData);
|
||||||
|
m_timer.setInterval(30 * 1000);
|
||||||
|
m_timer.start();
|
||||||
|
m_timer.setObjectName("CInfoBarWebReadersStatusComponent::CheckSwiftDbTimer");
|
||||||
|
}
|
||||||
|
|
||||||
|
CInfoBarWebReadersStatusComponent::~CInfoBarWebReadersStatusComponent()
|
||||||
|
{
|
||||||
|
m_timer.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CInfoBarWebReadersStatusComponent::initLeds()
|
||||||
|
{
|
||||||
|
CLedWidget::LedShape shape = CLedWidget::Circle;
|
||||||
|
this->ui->led_DataReady->setValues(CLedWidget::Yellow, CLedWidget::Black, shape, "all data ready", "data missing", 14);
|
||||||
|
|
||||||
|
this->ui->led_IcaoAircraft->setValues(CLedWidget::Yellow, CLedWidget::Black, CLedWidget::Red, shape, "reading", "idle", "failed", 14);
|
||||||
|
this->ui->led_IcaoAirline->setValues(CLedWidget::Yellow, CLedWidget::Black, CLedWidget::Red, shape, "reading", "idle", "failed", 14);
|
||||||
|
this->ui->led_Countries->setValues(CLedWidget::Yellow, CLedWidget::Black, CLedWidget::Red, shape, "reading", "idle", "failed", 14);
|
||||||
|
|
||||||
|
this->ui->led_Models->setValues(CLedWidget::Yellow, CLedWidget::Black, CLedWidget::Red, shape, "reading", "idle", "failed", 14);
|
||||||
|
this->ui->led_Liveries->setValues(CLedWidget::Yellow, CLedWidget::Black, CLedWidget::Red, shape, "reading", "idle", "failed", 14);
|
||||||
|
this->ui->led_Distributors->setValues(CLedWidget::Yellow, CLedWidget::Black, CLedWidget::Red, shape, "reading", "idle", "failed", 14);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CInfoBarWebReadersStatusComponent::setProvider(IWebDataServicesProvider *webDataReaderProvider)
|
||||||
|
{
|
||||||
|
CWebDataServicesAware::setProvider(webDataReaderProvider);
|
||||||
|
connectSwiftDatabaseSignals(
|
||||||
|
this,
|
||||||
|
std::bind(&CInfoBarWebReadersStatusComponent::ps_dataRead, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CInfoBarWebReadersStatusComponent::ps_dataRead(CDbFlags::Entity entity, CDbFlags::ReadState readState, int count)
|
||||||
|
{
|
||||||
|
if (readState == CDbFlags::ReadFinished)
|
||||||
|
{
|
||||||
|
bool swift = CWebReaderFlags::isFromSwiftDb(entity);
|
||||||
|
if (swift && count > 0)
|
||||||
|
{
|
||||||
|
// avoids unnecessary checks
|
||||||
|
this->ui->led_SwiftDb->setOn(true);
|
||||||
|
this->m_timer.start(); // restart
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<CLedWidget *> leds = this->entityToLeds(entity);
|
||||||
|
if (!leds.isEmpty()) { this->setLedReadStates(leds, readState); }
|
||||||
|
}
|
||||||
|
|
||||||
|
void CInfoBarWebReadersStatusComponent::ps_checkServerAndData()
|
||||||
|
{
|
||||||
|
bool swift =
|
||||||
|
this->hasProvider() &&
|
||||||
|
this->canConnectSwiftDb();
|
||||||
|
this->ui->led_SwiftDb->setOn(swift);
|
||||||
|
|
||||||
|
bool allData = hasAllData();
|
||||||
|
this->ui->led_DataReady->setOn(allData);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CInfoBarWebReadersStatusComponent::setLedReadStates(const QList<CLedWidget *> &leds, CDbFlags::ReadState readState)
|
||||||
|
{
|
||||||
|
for (CLedWidget *led : leds)
|
||||||
|
{
|
||||||
|
setLedReadState(led, readState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CInfoBarWebReadersStatusComponent::setLedReadState(CLedWidget *led, CDbFlags::ReadState readState)
|
||||||
|
{
|
||||||
|
Q_ASSERT_X(led, Q_FUNC_INFO, "no LED");
|
||||||
|
int blinkTime = 2.5 * 1000;
|
||||||
|
switch (readState)
|
||||||
|
{
|
||||||
|
case CDbFlags::ReadFinished:
|
||||||
|
led->setOn(true, blinkTime);
|
||||||
|
break;
|
||||||
|
case CDbFlags::StartRead:
|
||||||
|
led->setOn(true);
|
||||||
|
break;
|
||||||
|
case CDbFlags::ReadFailed:
|
||||||
|
led->setTriState(2 * blinkTime);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<CLedWidget *> CInfoBarWebReadersStatusComponent::entityToLeds(CDbFlags::Entity entity) const
|
||||||
|
{
|
||||||
|
QList<CLedWidget *> leds;
|
||||||
|
if (entity.testFlag(CDbFlags::CountryEntity)) { leds << ui->led_Countries; }
|
||||||
|
if (entity.testFlag(CDbFlags::DistributorEntity)) { leds << ui->led_Distributors; }
|
||||||
|
if (entity.testFlag(CDbFlags::AircraftIcaoEntity)) { leds << ui->led_IcaoAircraft; }
|
||||||
|
if (entity.testFlag(CDbFlags::AirlineIcaoEntity)) { leds << ui->led_IcaoAirline; }
|
||||||
|
if (entity.testFlag(CDbFlags::LiveryEntity)) { leds << ui->led_Liveries; }
|
||||||
|
if (entity.testFlag(CDbFlags::ModelEntity)) { leds << ui->led_Models; }
|
||||||
|
return leds;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CInfoBarWebReadersStatusComponent::hasAllData() const
|
||||||
|
{
|
||||||
|
if (!hasProvider()) { return false; }
|
||||||
|
return getAirlineIcaoCodesCount() > 0 &&
|
||||||
|
getAircraftIcaoCodesCount() > 0 &&
|
||||||
|
getDistributorsCount() > 0 &&
|
||||||
|
getModelsCount() > 0 &&
|
||||||
|
getLiveriesCount() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
} // namespace
|
||||||
72
src/blackgui/components/infobarwebreadersstatuscomponent.h
Normal file
72
src/blackgui/components/infobarwebreadersstatuscomponent.h
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
/* Copyright (C) 2015
|
||||||
|
* swift project Community / Contributors
|
||||||
|
*
|
||||||
|
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||||
|
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||||
|
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||||
|
* contained in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//! \file
|
||||||
|
|
||||||
|
#ifndef BLACKGUI_INFOBARWEBREADERSSTATUSCOMPONENT_H
|
||||||
|
#define BLACKGUI_INFOBARWEBREADERSSTATUSCOMPONENT_H
|
||||||
|
|
||||||
|
#include "blackgui/blackguiexport.h"
|
||||||
|
#include "blackgui/led.h"
|
||||||
|
#include "blackmisc/network/webdataservicesprovider.h"
|
||||||
|
#include <QFrame>
|
||||||
|
#include <QScopedPointer>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
namespace Ui { class CInfoBarWebReadersStatusComponent; }
|
||||||
|
namespace BlackGui
|
||||||
|
{
|
||||||
|
namespace Components
|
||||||
|
{
|
||||||
|
//! Info bar displaying status of web readers(swift DB, ...)
|
||||||
|
class BLACKGUI_EXPORT CInfoBarWebReadersStatusComponent :
|
||||||
|
public QFrame,
|
||||||
|
public BlackMisc::Network::CWebDataServicesAware
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
//! Constructor
|
||||||
|
explicit CInfoBarWebReadersStatusComponent(QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
//!Destructor
|
||||||
|
~CInfoBarWebReadersStatusComponent();
|
||||||
|
|
||||||
|
//! Init the LEDs
|
||||||
|
void initLeds();
|
||||||
|
|
||||||
|
//! Set the provider
|
||||||
|
virtual void setProvider(BlackMisc::Network::IWebDataServicesProvider *webDataReaderProvider) override;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
//! Data have been read
|
||||||
|
void ps_dataRead(BlackMisc::Network::CDbFlags::Entity entity, BlackMisc::Network::CDbFlags::ReadState readState, int count);
|
||||||
|
|
||||||
|
//! Check server status
|
||||||
|
void ps_checkServerAndData();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QScopedPointer<Ui::CInfoBarWebReadersStatusComponent> ui;
|
||||||
|
QTimer m_timer { this };
|
||||||
|
|
||||||
|
//! Set LED states
|
||||||
|
void setLedReadStates(const QList<CLedWidget *> &leds, BlackMisc::Network::CDbFlags::ReadState readState);
|
||||||
|
|
||||||
|
//! Set the LED read state
|
||||||
|
void setLedReadState(CLedWidget *led, BlackMisc::Network::CDbFlags::ReadState readState);
|
||||||
|
|
||||||
|
//! Maps entity to its id
|
||||||
|
QList<CLedWidget *> entityToLeds(BlackMisc::Network::CDbFlags::Entity entity) const;
|
||||||
|
|
||||||
|
//! All data read
|
||||||
|
bool hasAllData() const;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif // guard
|
||||||
169
src/blackgui/components/infobarwebreadersstatuscomponent.ui
Normal file
169
src/blackgui/components/infobarwebreadersstatuscomponent.ui
Normal file
@@ -0,0 +1,169 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>CInfoBarWebReadersStatusComponent</class>
|
||||||
|
<widget class="QFrame" name="CInfoBarWebReadersStatusComponent">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>632</width>
|
||||||
|
<height>22</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Frame</string>
|
||||||
|
</property>
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::StyledPanel</enum>
|
||||||
|
</property>
|
||||||
|
<property name="frameShadow">
|
||||||
|
<enum>QFrame::Raised</enum>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="hl_InoBarWerbReaderStatusComponent">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>10</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="lbl_SwiftDb">
|
||||||
|
<property name="text">
|
||||||
|
<string>swift DB</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="BlackGui::CLedWidget" name="led_SwiftDb" native="true"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="lbl_DataReady">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Mappings ready</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>data</string>
|
||||||
|
</property>
|
||||||
|
<property name="indent">
|
||||||
|
<number>6</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="BlackGui::CLedWidget" name="led_DataReady" native="true"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="hs_Spacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeType">
|
||||||
|
<enum>QSizePolicy::Fixed</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="lbl_Loading">
|
||||||
|
<property name="text">
|
||||||
|
<string>loading:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="lbl_Models">
|
||||||
|
<property name="text">
|
||||||
|
<string>models</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="BlackGui::CLedWidget" name="led_Models" native="true"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="lbl_Liveries">
|
||||||
|
<property name="text">
|
||||||
|
<string>| liveries</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="BlackGui::CLedWidget" name="led_Liveries" native="true"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="lbl_Distributors">
|
||||||
|
<property name="text">
|
||||||
|
<string>| distributors</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="BlackGui::CLedWidget" name="led_Distributors" native="true"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="lbl_Aircraft">
|
||||||
|
<property name="text">
|
||||||
|
<string>| aircraft</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="BlackGui::CLedWidget" name="led_IcaoAircraft" native="true"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="lbl_Airlines">
|
||||||
|
<property name="text">
|
||||||
|
<string>| airlines</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="BlackGui::CLedWidget" name="led_IcaoAirline" native="true"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="lbl_Countries">
|
||||||
|
<property name="text">
|
||||||
|
<string>| countries</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="BlackGui::CLedWidget" name="led_Countries" native="true"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="hs_InfoBarWebReadersStatusComponent">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>BlackGui::CLedWidget</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>blackgui/led.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
Reference in New Issue
Block a user