diff --git a/src/blackgui/components/dblogincomponent.ui b/src/blackgui/components/dblogincomponent.ui index d67b14d1a..47fc0c17c 100644 --- a/src/blackgui/components/dblogincomponent.ui +++ b/src/blackgui/components/dblogincomponent.ui @@ -2,39 +2,58 @@ CDbLoginComponent - - - 0 - 0 - 333 - 299 - - - - - 300 - 0 - - DB login - QFrame::StyledPanel + QFrame::NoFrame - QFrame::Raised + QFrame::Plain - + + + 4 + + + 4 + + + 4 + + + 4 + + + + 16777215 + 60 + + QFrame::StyledPanel QFrame::Raised - + + + 4 + + + 0 + + + 0 + + + 0 + + + 0 + @@ -75,7 +94,22 @@ QFrame::Raised - + + + 0 + + + 0 + + + 0 + + + 0 + + + 4 + @@ -123,18 +157,55 @@ + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 75 + 10 + + + + + + + 16777215 + 125 + + QFrame::StyledPanel QFrame::Raised - + + + 0 + + + 0 + + + 0 + + + 0 + + + 4 + @@ -174,12 +245,6 @@ 40 - - - 16777215 - 40 - - User roles @@ -188,9 +253,38 @@ + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 75 + 10 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + diff --git a/src/blackgui/components/dbmappingcomponent.cpp b/src/blackgui/components/dbmappingcomponent.cpp index a6eac0a7d..b4cd7f2ee 100644 --- a/src/blackgui/components/dbmappingcomponent.cpp +++ b/src/blackgui/components/dbmappingcomponent.cpp @@ -32,8 +32,6 @@ namespace BlackGui COverlayMessagesFrame(parent), ui(new Ui::CDbMappingComponent) { - m_authenticationService = new CDatabaseAuthenticationService(this); - ui->setupUi(this); this->ui->tvp_AircraftModelsForVPilot->setAircraftModelMode(CAircraftModelListModel::VPilotRuleModel); connect(ui->editor_Model, &CModelMappingForm::requestSave, this, &CDbMappingComponent::save); @@ -47,7 +45,7 @@ namespace BlackGui ui->editor_Distributor->setMappingMode(); ui->editor_Livery->setMappingMode(); - initVPilotLoading(); + this->initVPilotLoading(); } CDbMappingComponent::~CDbMappingComponent() @@ -57,24 +55,31 @@ namespace BlackGui void CDbMappingComponent::initVPilotLoading() { - if (m_authenticationService->getUser().isAdmin() && - CProject::isRunningOnWindowsNtPlatform() && - CProject::isCompiledWithMsFlightSimulatorSupport()) + bool canUseVPilot = CProject::isRunningOnWindowsNtPlatform() && CProject::isCompiledWithMsFlightSimulatorSupport(); + bool withVPilotRights = canUseVPilot && this->m_user.get().isMappingAdmin(); + this->m_withVPilot = withVPilotRights; + static const QString tabName(this->ui->tw_ModelsToBeMapped->tabText(1)); + + if (this->m_vPilot1stInit && canUseVPilot) { - this->m_withVPilot = true; - this->ui->tvp_AircraftModelsForVPilot->setCustomMenu(new CMappingVPilotMenu(this)); - this->ui->tvp_AircraftModelsForVPilot->setDisplayAutomatically(true); connect(ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected); connect(ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::rowCountChanged, this, &CDbMappingComponent::ps_onVPilotCountChanged); connect(&m_vPilotReader, &CVPilotRulesReader::readFinished, this, &CDbMappingComponent::ps_onLoadVPilotDataFinished); + this->ui->tvp_AircraftModelsForVPilot->setCustomMenu(new CMappingVPilotMenu(this)); + this->ui->tvp_AircraftModelsForVPilot->setDisplayAutomatically(true); + } + this->m_vPilot1stInit = false; + + this->ui->tab_VPilot->setEnabled(withVPilotRights); + this->ui->tab_VPilot->setVisible(withVPilotRights); + if (withVPilotRights) + { + this->ui->tw_ModelsToBeMapped->addTab(this->ui->tab_VPilot, tabName); } else { - this->m_withVPilot = false; + this->ui->tw_ModelsToBeMapped->removeTab(1); } - this->ui->tab_VPilot->setEnabled(m_withVPilot); - this->ui->tab_VPilot->setVisible(m_withVPilot); - this->ui->tw_ModelsToBeMapped->removeTab(1); } bool CDbMappingComponent::initModelLoader(const CSimulatorInfo &simInfo) @@ -114,7 +119,6 @@ namespace BlackGui this->disconnect(); CWebDataServicesAware::gracefulShutdown(); this->m_vPilotReader.gracefulShutdown(); - this->m_authenticationService->gracefulShutdown(); if (this->m_modelLoader) { this->m_modelLoader->gracefulShutdown(); } } @@ -250,6 +254,11 @@ namespace BlackGui this->ps_loadInstalledModels(sim); } + void CDbMappingComponent::ps_userChanged() + { + this->initVPilotLoading(); + } + void CDbMappingComponent::ps_onModelRowSelected(const QModelIndex &index) { QObject *sender = QObject::sender(); @@ -371,7 +380,8 @@ namespace BlackGui CDbMappingComponent *mapComp = qobject_cast(this->parent()); Q_ASSERT_X(mapComp, Q_FUNC_INFO, "Cannot access parent"); - if (this->mappingComponent()->m_authenticationService->getUser().isAdmin()) + bool canUseVPilot = mappingComponent()->withVPilot(); + if (canUseVPilot) { menu.addAction(CIcons::appMappings16(), "Load vPilot Rules", mapComp, SLOT(ps_loadVPilotData())); menu.addSeparator(); diff --git a/src/blackgui/components/dbmappingcomponent.h b/src/blackgui/components/dbmappingcomponent.h index 38e7a2c03..0416cb7f5 100644 --- a/src/blackgui/components/dbmappingcomponent.h +++ b/src/blackgui/components/dbmappingcomponent.h @@ -12,7 +12,7 @@ #ifndef BLACKGUI_COMPONENTS_DBMAPPINGCOMPONENT_H #define BLACKGUI_COMPONENTS_DBMAPPINGCOMPONENT_H -#include "blackcore/databaseauthentication.h" +#include "blackcore/data/authenticateduser.h" #include "blackgui/blackguiexport.h" #include "blackgui/overlaymessagesframe.h" #include "blackgui/menudelegate.h" @@ -55,6 +55,9 @@ namespace BlackGui //! Graceful shutdown void gracefulShutdown(); + //! With vPilot rules + bool withVPilot() const { return m_withVPilot; } + signals: //! Request to filter by livery void filterByLivery(const BlackMisc::Aviation::CLivery &livery); @@ -103,17 +106,21 @@ namespace BlackGui //! Request simulator models void ps_requestSimulatorModels(); + //! User object changed + void ps_userChanged(); + private: QScopedPointer ui; - BlackMisc::Simulation::FsCommon::CVPilotRulesReader m_vPilotReader; - std::unique_ptr m_modelLoader; - BlackCore::CDatabaseAuthenticationService *m_authenticationService = nullptr; - bool m_withVPilot = false; + BlackMisc::Simulation::FsCommon::CVPilotRulesReader m_vPilotReader; + std::unique_ptr m_modelLoader; + BlackCore::CData m_user {this, &CDbMappingComponent::ps_userChanged}; + bool m_vPilot1stInit = true; + bool m_withVPilot = false; //! Consolidated aircraft model BlackMisc::Simulation::CAircraftModel getAircraftModel() const; - //! Init vPilot loading is suitable + //! Init vPilot if rights and suitable void initVPilotLoading(); //! Init model loader