You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MainWindow.cpp 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // Created by robin on 10/1/17.
  3. //
  4. #include "MainWindow.h"
  5. #include <QMessageBox>
  6. #include <Core/LibNfcOperation.hxx>
  7. MainWindow::MainWindow(QWidget *parent)
  8. : QMainWindow(parent)
  9. , m_pUi(new Ui_MainWindow())
  10. {
  11. m_pUi->setupUi(this);
  12. refreshReaders();
  13. }
  14. bool MainWindow::initLibNfc()
  15. {
  16. if (!m_pLibNfc) {
  17. m_pLibNfc.reset(new LibNfcBusiness());
  18. auto initResult = m_pLibNfc->init();
  19. if (!initResult) {
  20. showError(initResult);
  21. return false;
  22. }
  23. }
  24. return true;
  25. }
  26. void MainWindow::refreshReaders()
  27. {
  28. if (!initLibNfc()) {
  29. return;
  30. }
  31. m_pUi->pComboReaders->clear();
  32. LibNfcOperation::runOperation<std::vector<std::shared_ptr<NfcDeviceBusiness>>>(m_pLibNfc, [](QSharedPointer<LibNfcBusiness> libNfc)
  33. {
  34. return (Result<std::vector<std::shared_ptr<NfcDeviceBusiness>>>) libNfc->getDevices();
  35. }, [this](Result<std::vector<std::shared_ptr<NfcDeviceBusiness>>> devicesResult)
  36. {
  37. m_devices = devicesResult.getData();
  38. for (auto& device : m_devices) {
  39. m_pUi->pComboReaders->addItem(device->getConnStr().c_str());
  40. }
  41. });
  42. // auto devicesResult = m_pLibNfc->getDevices();
  43. // if (!devicesResult) {
  44. // showError(devicesResult);
  45. // return;
  46. // }
  47. //
  48. // m_devices = devicesResult.getData();
  49. // for (auto& device : m_devices) {
  50. // m_pUi->pComboReaders->addItem(device->getConnStr().c_str());
  51. // }
  52. }
  53. template<typename T>
  54. void MainWindow::showError(Result<T> result)
  55. {
  56. result.print();
  57. QMessageBox::critical(this, "LibNfc Error", QString("LibNfc error: %1").arg(result.getError().c_str()));
  58. }