AusweisApp2
RemoteDeviceModel.h
gehe zur Dokumentation dieser Datei
1 
7 #pragma once
8 
9 #include "GlobalStatus.h"
10 #include "IfdDescriptor.h"
11 #include "IfdDispatcher.h"
12 #include "IfdList.h"
14 #include "RemoteServiceSettings.h"
15 
16 #include <QAbstractTableModel>
17 #include <QSet>
18 #include <QSslCertificate>
19 #include <QVector>
20 
21 class test_RemoteDeviceModel;
22 
23 namespace governikus
24 {
25 
27 {
28  friend class ::test_RemoteDeviceModel;
29 
30  private:
31  QString mDeviceName;
32  QString mId;
33  bool mPaired;
34  bool mNetworkVisible;
35  bool mConnected;
36  bool mSupported;
37  QDateTime mLastConnected;
38  QSharedPointer<IfdListEntry> mRemoteDeviceListEntry;
39 
40  public:
41  RemoteDeviceModelEntry(const QString& pDeviceNameEscaped,
42  const QString& mId,
43  const QSharedPointer<IfdListEntry>& pRemoteDeviceListEntry);
44  RemoteDeviceModelEntry(const QString& pDeviceNameEscaped,
45  const QString& mId,
46  bool pNetworkVisible,
47  bool pConnected,
48  bool pSupported,
49  const QDateTime& pLastConnected,
50  const QSharedPointer<IfdListEntry>& pRemoteDeviceListEntry);
51  explicit RemoteDeviceModelEntry(const QString& pDeviceNameEscaped = QStringLiteral("UnknownReader"));
52 
53  [[nodiscard]] bool isPaired() const;
54  void setPaired(bool pPaired);
55  [[nodiscard]] const QString& getId() const;
56  void setId(const QString& pId);
57  [[nodiscard]] bool isNetworkVisible() const;
58  [[nodiscard]] int getLinkQuality() const;
59  [[nodiscard]] bool isSupported() const;
60  void setNetworkVisible(bool pNetworkVisible);
61  [[nodiscard]] const QDateTime& getLastConnected() const;
62  void setLastConnected(const QDateTime& pLastConnected);
63  bool operator==(const RemoteDeviceModelEntry& pOther) const;
64 
65  [[nodiscard]] const QSharedPointer<IfdListEntry>& getRemoteDeviceListEntry() const;
66  [[nodiscard]] QString getDeviceNameEscaped() const;
67 
68 };
69 
71  : public QAbstractListModel
72 {
73  Q_OBJECT
75  friend class ::test_RemoteDeviceModel;
76 
77  private:
78  QMap<QString, RemoteServiceSettings::RemoteInfo> mPairedReaders;
79  QVector<RemoteDeviceModelEntry> mAllRemoteReaders;
80  const bool mShowPairedReaders;
81  const bool mShowUnpairedReaders;
82  QTimer mTimer;
83  bool mIsDetectingRemoteDevices;
84 #if defined(Q_OS_IOS)
85  bool mRemoteDetectionWasRunning;
86 #endif
87 
88  [[nodiscard]] bool indexIsValid(const QModelIndex& pIndex) const;
89  [[nodiscard]] QString getStatus(const RemoteDeviceModelEntry& pRemoteDeviceModelEntry) const;
90  void updatePairedReaders();
91  void updateUnpairedReaders();
92  void removeVanishedReaders();
93  [[nodiscard]] QVector<RemoteDeviceModelEntry> presentReaders() const;
94  bool addOrUpdateReader(const RemoteDeviceModelEntry& pModelEntry);
95 
96  private Q_SLOTS:
97  void onApplicationStateChanged(bool pIsAppInForeground);
98  void onUpdateReaderList();
99 
100  public Q_SLOTS:
101  void onTranslationChanged();
102 
103  public:
105  {
106  REMOTE_DEVICE_NAME = Qt::UserRole + 1,
114  };
115 
116  RemoteDeviceModel(QObject* pParent = nullptr, bool pShowPairedReaders = true, bool pShowUnpairedReaders = true);
117 
118  [[nodiscard]] int rowCount(const QModelIndex& pParent = QModelIndex()) const override;
119  [[nodiscard]] QVariant data(const QModelIndex& pIndex, int pRole = Qt::DisplayRole) const override;
120  [[nodiscard]] QHash<int, QByteArray> roleNames() const override;
121 
122  [[nodiscard]] QSharedPointer<IfdListEntry> getRemoteDeviceListEntry(const QModelIndex& pIndex) const;
123  [[nodiscard]] QSharedPointer<IfdListEntry> getRemoteDeviceListEntry(const QString& pDeviceId) const;
124  [[nodiscard]] bool isPaired(const QModelIndex& pIndex) const;
125  [[nodiscard]] bool isSupported(const QModelIndex& pIndex) const;
126  void forgetDevice(const QModelIndex& pIndex);
127  void forgetDevice(const QString& pDeviceId);
128 
129  [[nodiscard]] QString getEmptyListDescriptionString() const;
130 
131  public Q_SLOTS:
132  void setDetectRemoteDevices(bool pNewStatus);
134  void onDeviceDisconnected(GlobalStatus::Code pCloseCode, const QString& pId);
135 
136  Q_SIGNALS:
138 };
139 
140 
141 } // namespace governikus
Code
Definition: GlobalStatus.h:26
Definition: RemoteDeviceModel.h:27
bool operator==(const RemoteDeviceModelEntry &pOther) const
Definition: RemoteDeviceModel.cpp:151
void setPaired(bool pPaired)
Definition: RemoteDeviceModel.cpp:87
RemoteDeviceModelEntry(const QString &pDeviceNameEscaped, const QString &mId, const QSharedPointer< IfdListEntry > &pRemoteDeviceListEntry)
Definition: RemoteDeviceModel.cpp:19
bool isSupported() const
Definition: RemoteDeviceModel.cpp:127
void setLastConnected(const QDateTime &pLastConnected)
Definition: RemoteDeviceModel.cpp:145
const QSharedPointer< IfdListEntry > & getRemoteDeviceListEntry() const
Definition: RemoteDeviceModel.cpp:69
void setId(const QString &pId)
Definition: RemoteDeviceModel.cpp:99
void setNetworkVisible(bool pNetworkVisible)
Definition: RemoteDeviceModel.cpp:133
const QString & getId() const
Definition: RemoteDeviceModel.cpp:93
QString getDeviceNameEscaped() const
Definition: RemoteDeviceModel.cpp:75
const QDateTime & getLastConnected() const
Definition: RemoteDeviceModel.cpp:139
bool isPaired() const
Definition: RemoteDeviceModel.cpp:81
bool isNetworkVisible() const
Definition: RemoteDeviceModel.cpp:105
int getLinkQuality() const
Definition: RemoteDeviceModel.cpp:111
Definition: RemoteDeviceModel.h:72
void forgetDevice(const QModelIndex &pIndex)
Definition: RemoteDeviceModel.cpp:555
QString getEmptyListDescriptionString() const
Definition: RemoteDeviceModel.cpp:577
RemoteDeviceModel(QObject *pParent=nullptr, bool pShowPairedReaders=true, bool pShowUnpairedReaders=true)
Definition: RemoteDeviceModel.cpp:157
void onTranslationChanged()
Definition: RemoteDeviceModel.cpp:549
SettingsRemoteRoles
Definition: RemoteDeviceModel.h:105
@ IS_NETWORK_VISIBLE
Definition: RemoteDeviceModel.h:110
@ LAST_CONNECTED
Definition: RemoteDeviceModel.h:108
@ IS_SUPPORTED
Definition: RemoteDeviceModel.h:111
@ DEVICE_ID
Definition: RemoteDeviceModel.h:109
@ REMOTE_DEVICE_STATUS
Definition: RemoteDeviceModel.h:107
@ IS_PAIRED
Definition: RemoteDeviceModel.h:112
@ LINK_QUALITY
Definition: RemoteDeviceModel.h:113
@ REMOTE_DEVICE_NAME
Definition: RemoteDeviceModel.h:106
QHash< int, QByteArray > roleNames() const override
Definition: RemoteDeviceModel.cpp:184
bool isPaired(const QModelIndex &pIndex) const
Definition: RemoteDeviceModel.cpp:443
void onDeviceDisconnected(GlobalStatus::Code pCloseCode, const QString &pId)
Definition: RemoteDeviceModel.cpp:588
int rowCount(const QModelIndex &pParent=QModelIndex()) const override
Definition: RemoteDeviceModel.cpp:369
void onKnownRemoteReadersChanged()
Definition: RemoteDeviceModel.cpp:489
void setDetectRemoteDevices(bool pNewStatus)
Definition: RemoteDeviceModel.cpp:465
QVariant data(const QModelIndex &pIndex, int pRole=Qt::DisplayRole) const override
Definition: RemoteDeviceModel.cpp:375
bool isSupported(const QModelIndex &pIndex) const
Definition: RemoteDeviceModel.cpp:454
QSharedPointer< IfdListEntry > getRemoteDeviceListEntry(const QModelIndex &pIndex) const
Definition: RemoteDeviceModel.cpp:418
QString emptyListDescriptionString
Definition: RemoteDeviceModel.h:74
Definition: RemoteServiceSettings.h:29
A simple template renderer.
Definition: ActivationContext.h:15