qrcodewindow.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #include "qrcodewindow.h"
  2. #include "ECSDKToolKit.h"
  3. QRCodeWindow::QRCodeWindow(QWidget *parent) : QWidget(parent)
  4. {
  5. printf("%s:%s:%d\r\n",__FILE__,__func__,__LINE__);
  6. QPalette pal(this->palette());
  7. pal.setColor(QPalette::Background, Qt::white);
  8. this->setAutoFillBackground(true);
  9. this->setPalette(pal);
  10. int screen_width = 1920;
  11. int screen_height = 720;
  12. setGeometry(0, 0, screen_width, screen_height);
  13. m_IosQRCode = new QPushButton(QString("IOS"), this);
  14. m_IosQRCode->setGeometry(width() / 4 * 3, 0, width() / 4, height()/2);
  15. QObject::connect(m_IosQRCode, SIGNAL(clicked()), this, SLOT(onClicked()));
  16. printf("%s:%s:%d\r\n",__FILE__,__func__,__LINE__);
  17. m_AndroidQRCode = new QPushButton(QString("Android"), this);
  18. m_AndroidQRCode->setGeometry(width() / 4 * 3, height() / 2 * 1, width() / 4, height()/2);
  19. QObject::connect(m_AndroidQRCode, SIGNAL(clicked()), this, SLOT(onClicked()));
  20. printf("%s:%s:%d\r\n",__FILE__,__func__,__LINE__);
  21. m_Close = new QPushButton(QString("Close"), this);
  22. m_Close->setGeometry(width() / 4 * 2, height(), width() / 4, height());
  23. QObject::connect(m_Close, SIGNAL(clicked()), this, SLOT(onClicked()));
  24. m_Label = new QLabel(QString(""),this);
  25. m_Label->setGeometry(width() / 4 * 0, 0, 3* width() / 4, height());
  26. m_Label->setText("select phone type,please scan code!");
  27. m_Label->show();
  28. //p2p
  29. /*
  30. system("insmod /lib/modules/4.19.192/kernel/drivers/net/wireless/realtek/rtl8821cs/rtl8821cs.ko");
  31. system("ifconfig wlan1 up");
  32. system("ifconfig wlan1 192.168.2.1");
  33. system("udhcpd /etc/udhcpd_p2p.conf");
  34. system("wpa_supplicant -Dnl80211 -iwlan1 -c /etc/p2p_supplicant.conf -B");
  35. system("wpa_cli -i wlan1 p2p_group_add persistent");
  36. system("wpa_cli -i wlan1 wps_pbc");
  37. printf("width = %d, height = %d\r\n",width(), height());
  38. */
  39. }
  40. void QRCodeWindow::resizeEvent(QResizeEvent *event)
  41. {
  42. printf("%s:%s:%d\r\n",__FILE__,__func__,__LINE__);
  43. resize(1920, 720);
  44. }
  45. void QRCodeWindow::onQrcodeInfo(char *qrcode)
  46. {
  47. printf("%s:%s:%d\r\n",__FILE__,__func__,__LINE__);
  48. string str = qrcode;
  49. m_Label->setPixmap(createQRCode(str));
  50. }
  51. void QRCodeWindow::getPlayer(IUserLinkPlayer *player)
  52. {
  53. mPlayer = player;
  54. }
  55. void QRCodeWindow::onUIChanged(bool visible)
  56. {
  57. if(visible){
  58. }
  59. else{
  60. }
  61. }
  62. QPixmap QRCodeWindow::createQRCode(string str)
  63. {
  64. #ifdef SCAN_QRCODE
  65. int margin = 2;
  66. if (str.length() == 0)
  67. return QPixmap();
  68. QRcode *qrcode = QRcode_encodeString(str.c_str(), 2, QR_ECLEVEL_L, QR_MODE_8, 0);
  69. if (qrcode == NULL) {
  70. return QPixmap();
  71. }
  72. unsigned char *p, *q;
  73. p = NULL;
  74. q = NULL;
  75. int x, y, bit;
  76. int realwidth;
  77. realwidth = qrcode->width;
  78. QImage image = QImage(realwidth, realwidth, QImage::Format_Indexed8);
  79. QRgb value;
  80. value = qRgb(255, 255, 255);
  81. image.setColor(0, value);
  82. value = qRgb(0, 0, 0);
  83. image.setColor(1, value);
  84. image.setColor(2, value);
  85. image.fill(0);
  86. p = qrcode->data;
  87. for (y = 0; y<qrcode->width; y++) {
  88. bit = 7;
  89. q += margin / 8;
  90. bit = 7 - (margin % 8);
  91. for (x = 0; x<qrcode->width; x++) {
  92. if ((*p & 1) << bit)
  93. image.setPixel(x, y, 1);
  94. else
  95. image.setPixel(x, y, 0);
  96. bit--;
  97. if (bit < 0)
  98. {
  99. q++;
  100. bit = 7;
  101. }
  102. p++;
  103. }
  104. }
  105. return QPixmap::fromImage(image.scaledToWidth(200));
  106. #endif
  107. }
  108. void QRCodeWindow::onClicked()
  109. {
  110. const QPushButton* const ptr = static_cast<const QPushButton* const >(sender());
  111. printf("%s:%s:%d\r\n",__FILE__,__func__,__LINE__);
  112. if (ptr == m_IosQRCode) {
  113. printf("%s:%s:%d\r\n",__FILE__,__func__,__LINE__);
  114. #ifdef SCAN_QRCODE
  115. ECQRInfo info;
  116. info.ssid = "ark169_wifi";
  117. info.pwd = "12345678";
  118. info.action = EC_QR_ACTION_WIFI_AP_MODE_CUSTOMIZED;
  119. info.auth = "WPA-PSK";
  120. info.name = "ark169_wifi";
  121. info.mac = "34:72:4a:00:1a:e9";
  122. ECSDKToolKit::getInstance()->generateQRCodeUrl(info);
  123. //mPlayer->RequestStatus(QUERYQRCODE);
  124. #endif
  125. } else if (ptr == m_AndroidQRCode) {
  126. #ifdef SCAN_QRCODE
  127. ECQRInfo info ;
  128. info.ssid = "";
  129. info.pwd = "";
  130. info.action = EC_QR_ACTION_WIFI_P2P_MODE;
  131. info.auth = "";
  132. info.name = "ark169_wifi";
  133. info.mac = "36:72:4A:00:1A:E9";
  134. ECSDKToolKit::getInstance()->generateQRCodeUrl(info);
  135. #endif
  136. printf("%s:%s:%d\r\n",__FILE__,__func__,__LINE__);
  137. }
  138. else if(ptr == m_Close){
  139. close();
  140. }
  141. }