swift
usercomponent.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #include <QString>
7 #include <QTabBar>
8 
9 #include "ui_usercomponent.h"
10 
12 #include "gui/guiapplication.h"
13 #include "gui/guiutility.h"
14 #include "gui/views/clientview.h"
15 #include "gui/views/userview.h"
17 #include "misc/network/userlist.h"
18 
19 using namespace swift::misc::network;
20 using namespace swift::gui;
21 using namespace swift::gui::views;
22 using namespace swift::gui::settings;
23 using namespace swift::core;
24 using namespace swift::core::context;
25 
26 namespace swift::gui::components
27 {
28  CUserComponent::CUserComponent(QWidget *parent)
29  : QTabWidget(parent), CEnableForDockWidgetInfoArea(), ui(new Ui::CUserComponent)
30  {
31  ui->setupUi(this);
32  this->setCurrentIndex(0);
33  this->tabBar()->setExpanding(false);
34  this->tabBar()->setUsesScrollButtons(true);
35  connect(ui->tvp_AllUsers, &CUserView::modelDataChangedDigest, this, &CUserComponent::onCountChanged);
36  connect(ui->tvp_AllUsers, &CUserView::requestTextMessageWidget, this,
38  connect(ui->tvp_Clients, &CClientView::modelDataChangedDigest, this, &CUserComponent::onCountChanged);
39  connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this,
40  &CUserComponent::onConnectionStatusChanged);
41  connect(&m_updateTimer, &QTimer::timeout, this, &CUserComponent::update);
42  this->onSettingsChanged();
43  }
44 
46 
48  {
49  Q_ASSERT(ui->tvp_Clients);
50  return ui->tvp_Clients->rowCount();
51  }
52 
54  {
55  Q_ASSERT(ui->tvp_AllUsers);
56  return ui->tvp_AllUsers->rowCount();
57  }
58 
60  {
61  if (!sGui || sGui->isShuttingDown() || !sGui->getIContextNetwork()) { return; }
62  Q_ASSERT(ui->tvp_AllUsers);
63  Q_ASSERT(ui->tvp_Clients);
64 
66  {
67  bool withData = countUsers() > 0 || countClients() > 0;
68  if (withData && !isVisibleWidget())
69  {
70  // Skip update, invisible
71  return;
72  }
73 
74  // load data
75  const CUserList users = sGui->getIContextNetwork()->getUsers();
76  ui->tvp_AllUsers->updateContainer(users);
77  ui->tvp_Clients->updateContainer(sGui->getIContextNetwork()->getClientsForCallsigns(users.getCallsigns()));
78  }
79  }
80 
81  void CUserComponent::onCountChanged(int count, bool withFilter)
82  {
83  Q_UNUSED(count);
84  Q_UNUSED(withFilter);
85  int iu = this->indexOf(ui->tb_AllUsers);
86  int ic = this->indexOf(ui->tb_Clients);
87  QString u = this->tabBar()->tabText(iu);
88  QString c = this->tabBar()->tabText(ic);
91  this->tabBar()->setTabText(iu, u);
92  this->tabBar()->setTabText(ic, c);
93  }
94 
95  void CUserComponent::onConnectionStatusChanged(const CConnectionStatus &from, const CConnectionStatus &to)
96  {
97  Q_UNUSED(from);
98  if (to.isDisconnected())
99  {
100  ui->tvp_AllUsers->clear();
101  ui->tvp_Clients->clear();
102  m_updateTimer.stop();
103  }
104  else if (to.isConnected()) { m_updateTimer.start(); }
105  }
106 
107  void CUserComponent::onSettingsChanged()
108  {
109  const CViewUpdateSettings settings = m_settings.get();
110  const int ms = settings.getAtcUpdateTime().toMs();
111  m_updateTimer.setInterval(ms);
112  }
113 } // namespace swift::gui::components
const context::IContextNetwork * getIContextNetwork() const
Direct access to contexts if a CCoreFacade has been initialized.
bool isShuttingDown() const
Is application shutting down?
virtual swift::misc::network::CUserList getUsers() const =0
Get all users.
virtual swift::misc::network::CClientList getClientsForCallsigns(const swift::misc::aviation::CCallsignSet &callsigns) const =0
Clients for given callsign, e.g. to test/fetch direct aircraft model.
virtual bool isConnected() const =0
Network connected?
Helper class: If a component is residing in an dockable widget. This class provides access to its inf...
static QString replaceTabCountValue(const QString &oldName, int count)
Replace count in name such as "stations (4)".
Definition: guiutility.cpp:522
User componenet (users, clients)
Definition: usercomponent.h:29
void requestTextMessageWidget(const swift::misc::aviation::CCallsign &callsign)
Request a text message.
int countClients() const
Number of clients.
int countUsers() const
Number of users.
Settings about view update rates.
const swift::misc::physical_quantities::CTime & getAtcUpdateTime() const
Get time.
T get() const
Get a copy of the current value.
Definition: valuecache.h:408
swift::misc::aviation::CCallsignSet getCallsigns() const
All callsigns.
Value object encapsulating information about a connection status.
bool isConnected() const
Query status.
bool isDisconnected() const
Query status.
Value object encapsulating a list of voice rooms.
Definition: userlist.h:26
int toMs() const
Convenience functions when used with timers etc.
Definition: time.cpp:117
SWIFT_GUI_EXPORT swift::gui::CGuiApplication * sGui
Single instance of GUI application object.
Backend services of the swift project, like dealing with the network or the simulators.
Definition: actionbind.cpp:7
High level reusable GUI components.
Definition: aboutdialog.cpp:13
Views, mainly QTableView.
GUI related classes.