123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- //
- // Created by robin on 10/1/17.
- //
-
- #include "MainWindow.h"
- #include <QMessageBox>
- #include <Core/LibNfcOperation.hxx>
-
- MainWindow::MainWindow(QWidget *parent)
- : QMainWindow(parent)
- , m_pUi(new Ui_MainWindow())
- {
- m_pUi->setupUi(this);
-
- refreshReaders();
- }
-
- bool MainWindow::initLibNfc()
- {
- if (!m_pLibNfc) {
- m_pLibNfc.reset(new LibNfcBusiness());
- auto initResult = m_pLibNfc->init();
- if (!initResult) {
- showError(initResult);
- return false;
- }
- }
- return true;
- }
-
- void MainWindow::refreshReaders()
- {
- if (!initLibNfc()) {
- return;
- }
- m_pUi->pComboReaders->clear();
-
- LibNfcOperation::runOperation<std::vector<std::shared_ptr<NfcDeviceBusiness>>>(m_pLibNfc, [](QSharedPointer<LibNfcBusiness> libNfc)
- {
- return (Result<std::vector<std::shared_ptr<NfcDeviceBusiness>>>) libNfc->getDevices();
- }, [this](Result<std::vector<std::shared_ptr<NfcDeviceBusiness>>> devicesResult)
- {
- m_devices = devicesResult.getData();
- for (auto& device : m_devices) {
- m_pUi->pComboReaders->addItem(device->getConnStr().c_str());
- }
- });
-
- // auto devicesResult = m_pLibNfc->getDevices();
- // if (!devicesResult) {
- // showError(devicesResult);
- // return;
- // }
- //
- // m_devices = devicesResult.getData();
- // for (auto& device : m_devices) {
- // m_pUi->pComboReaders->addItem(device->getConnStr().c_str());
- // }
- }
-
- template<typename T>
- void MainWindow::showError(Result<T> result)
- {
- result.print();
- QMessageBox::critical(this, "LibNfc Error", QString("LibNfc error: %1").arg(result.getError().c_str()));
- }
|