Browse Source

re enabled gui

develop
Robin Thoni 6 years ago
parent
commit
2d90aa11b2

+ 1
- 1
CMakeLists.txt View File

@@ -31,7 +31,7 @@ endif()
31 31
 
32 32
 add_subdirectory(libnfc_cpptools)
33 33
 add_subdirectory(cli)
34
-#add_subdirectory(gui)
34
+add_subdirectory(gui)
35 35
 
36 36
 find_package(GTest)
37 37
 if (GTEST_FOUND)

+ 3
- 2
gui/CMakeLists.txt View File

@@ -1,5 +1,6 @@
1
-include_directories(.)
2
-include_directories(. ../libnfc_cpptools)
1
+include_directories(
2
+        ${LIBNFC_CPPTOOLS_INCLUDE_PATH}
3
+)
3 4
 
4 5
 # Find includes in corresponding build directories
5 6
 set(CMAKE_INCLUDE_CURRENT_DIR ON)

+ 2
- 2
gui/Core/LibNfcOperation.cpp View File

@@ -4,8 +4,8 @@
4 4
 
5 5
 #include "LibNfcOperation.h"
6 6
 
7
-LibNfcOperation::LibNfcOperation(QSharedPointer<LibNfcBusiness>& libNfc,
8
-                                 std::function<void(QSharedPointer<LibNfcBusiness>)> operation)
7
+LibNfcOperation::LibNfcOperation(QSharedPointer<LibNfc::Core::LibNfcContext>& libNfc,
8
+                                 std::function<void(QSharedPointer<LibNfc::Core::LibNfcContext>)> operation)
9 9
         : m_pLibNfc(libNfc)
10 10
         , m_operation(operation)
11 11
 {

+ 8
- 8
gui/Core/LibNfcOperation.h View File

@@ -9,16 +9,16 @@
9 9
 #include <QtCore/QThread>
10 10
 #include <QtCore/QSharedPointer>
11 11
 
12
-#include <Business/LibNfcBusiness.h>
12
+#include <libnfc_cpptools/LibNfcContext.h>
13 13
 
14 14
 class LibNfcOperation : public QThread
15 15
 {
16 16
     Q_OBJECT
17 17
 public:
18 18
     template<typename T>
19
-    static void runOperation(QSharedPointer<LibNfcBusiness> libNfc,
20
-                    std::function<Result<T>(QSharedPointer<LibNfcBusiness>)> operation,
21
-                    std::function<void(Result<T>)> callback);
19
+    static void runOperation(QSharedPointer<LibNfc::Core::LibNfcContext> libNfc,
20
+                    std::function<LibNfc::Utils::Result<T>(QSharedPointer<LibNfc::Core::LibNfcContext>)> operation,
21
+                    std::function<void(LibNfc::Utils::Result<T>)> callback);
22 22
 
23 23
 protected:
24 24
     void run() override;
@@ -27,12 +27,12 @@ protected:
27 27
 //    void operationFinished(Result<T> result);
28 28
 
29 29
 private:
30
-    explicit LibNfcOperation(QSharedPointer<LibNfcBusiness>& libNfc,
31
-                             std::function<void(QSharedPointer<LibNfcBusiness>)> operation);
30
+    explicit LibNfcOperation(QSharedPointer<LibNfc::Core::LibNfcContext>& libNfc,
31
+                             std::function<void(QSharedPointer<LibNfc::Core::LibNfcContext>)> operation);
32 32
 
33
-    QSharedPointer<LibNfcBusiness> m_pLibNfc;
33
+    QSharedPointer<LibNfc::Core::LibNfcContext> m_pLibNfc;
34 34
 
35
-    std::function<void(QSharedPointer<LibNfcBusiness>)> m_operation;
35
+    std::function<void(QSharedPointer<LibNfc::Core::LibNfcContext>)> m_operation;
36 36
 };
37 37
 
38 38
 #endif //MIFARE_TOOLS_LIBNFCOPERATION_H

+ 7
- 7
gui/Core/LibNfcOperation.hxx View File

@@ -8,17 +8,17 @@
8 8
 #include "LibNfcOperation.h"
9 9
 
10 10
 template<typename T>
11
-void LibNfcOperation::runOperation(QSharedPointer<LibNfcBusiness> libNfc,
12
-                          std::function<Result<T>(QSharedPointer<LibNfcBusiness>)> operation,
13
-                          std::function<void(Result<T>)> callback)
11
+void LibNfcOperation::runOperation(QSharedPointer<LibNfc::Core::LibNfcContext> libNfc,
12
+                          std::function<LibNfc::Utils::Result<T>(QSharedPointer<LibNfc::Core::LibNfcContext>)> operation,
13
+                          std::function<void(LibNfc::Utils::Result<T>)> callback)
14 14
 {
15
-    Result<T>* result = new Result<T>();
16
-    auto nfcOperation = new LibNfcOperation(libNfc, [result, operation](QSharedPointer<LibNfcBusiness> libNfc)
15
+    LibNfc::Utils::Result<T>* result = nullptr;
16
+    auto nfcOperation = new LibNfcOperation(libNfc, [&result, operation](QSharedPointer<LibNfc::Core::LibNfcContext> libNfc)
17 17
     {
18 18
         auto res = operation(libNfc);
19
-        *result = res;
19
+        result = new LibNfc::Utils::Result<T>(res);
20 20
     });
21
-    connect(nfcOperation, &LibNfcOperation::finished, [result, nfcOperation, callback]()
21
+    connect(nfcOperation, &LibNfcOperation::finished, [&result, nfcOperation, callback]()
22 22
     {
23 23
         nfcOperation->deleteLater();
24 24
         callback(*result);

+ 5
- 5
gui/UI/MainWindow.cpp View File

@@ -18,7 +18,7 @@ MainWindow::MainWindow(QWidget *parent)
18 18
 bool MainWindow::initLibNfc()
19 19
 {
20 20
     if (!m_pLibNfc) {
21
-        m_pLibNfc.reset(new LibNfcBusiness());
21
+        m_pLibNfc.reset(new LibNfc::Core::LibNfcContext());
22 22
         auto initResult = m_pLibNfc->init();
23 23
         if (!initResult) {
24 24
             showError(initResult);
@@ -35,10 +35,10 @@ void MainWindow::refreshReaders()
35 35
     }
36 36
     m_pUi->pComboReaders->clear();
37 37
 
38
-    LibNfcOperation::runOperation<std::vector<std::shared_ptr<NfcDeviceBusiness>>>(m_pLibNfc, [](QSharedPointer<LibNfcBusiness> libNfc)
38
+    LibNfcOperation::runOperation<std::vector<std::shared_ptr<LibNfc::Core::NfcDevice>>>(m_pLibNfc, [](QSharedPointer<LibNfc::Core::LibNfcContext> libNfc)
39 39
                          {
40
-                             return (Result<std::vector<std::shared_ptr<NfcDeviceBusiness>>>) libNfc->getDevices();
41
-                         }, [this](Result<std::vector<std::shared_ptr<NfcDeviceBusiness>>> devicesResult)
40
+                             return (LibNfc::Utils::Result<std::vector<std::shared_ptr<LibNfc::Core::NfcDevice>>>) libNfc->getDevices();
41
+                         }, [this](LibNfc::Utils::Result<std::vector<std::shared_ptr<LibNfc::Core::NfcDevice>>> devicesResult)
42 42
     {
43 43
         m_devices = devicesResult.getData();
44 44
         for (auto& device : m_devices) {
@@ -59,7 +59,7 @@ void MainWindow::refreshReaders()
59 59
 }
60 60
 
61 61
 template<typename T>
62
-void MainWindow::showError(Result<T> result)
62
+void MainWindow::showError(LibNfc::Utils::Result<T> result)
63 63
 {
64 64
     result.print();
65 65
     QMessageBox::critical(this, "LibNfc Error", QString("LibNfc error: %1").arg(result.getError().c_str()));

+ 4
- 4
gui/UI/MainWindow.h View File

@@ -7,7 +7,7 @@
7 7
 
8 8
 
9 9
 #include <QtWidgets/QMainWindow>
10
-#include <Business/LibNfcBusiness.h>
10
+#include <libnfc_cpptools/LibNfcContext.h>
11 11
 
12 12
 #include "ui_MainWindow.h"
13 13
 
@@ -22,14 +22,14 @@ public:
22 22
 
23 23
     void refreshReaders();
24 24
 
25
-    template<typename T> void showError(Result<T> result);
25
+    template<typename T> void showError(LibNfc::Utils::Result<T> result);
26 26
 
27 27
 private:
28 28
     QScopedPointer<Ui_MainWindow> m_pUi;
29 29
 
30
-    QSharedPointer<LibNfcBusiness> m_pLibNfc;
30
+    QSharedPointer<LibNfc::Core::LibNfcContext> m_pLibNfc;
31 31
 
32
-    std::vector<std::shared_ptr<NfcDeviceBusiness>> m_devices;
32
+    std::vector<std::shared_ptr<LibNfc::Core::NfcDevice>> m_devices;
33 33
 };
34 34
 
35 35
 

+ 4
- 1
gui/UI/MainWindow.ui View File

@@ -11,7 +11,7 @@
11 11
    </rect>
12 12
   </property>
13 13
   <property name="windowTitle">
14
-   <string>MainWindow</string>
14
+   <string>LibNFC_cppTools</string>
15 15
   </property>
16 16
   <widget class="QWidget" name="centralwidget">
17 17
    <layout class="QVBoxLayout" name="verticalLayout">
@@ -39,6 +39,9 @@
39 39
            <verstretch>0</verstretch>
40 40
           </sizepolicy>
41 41
          </property>
42
+         <property name="sizeAdjustPolicy">
43
+          <enum>QComboBox::AdjustToContents</enum>
44
+         </property>
42 45
         </widget>
43 46
        </item>
44 47
        <item>

Loading…
Cancel
Save