qtwaincontext_p.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * MIT License
  3. *
  4. * Copyright (c) 2020 Alexey Edelev <semlanik@gmail.com>
  5. *
  6. * This file is part of QtTWAIN project https://git.semlanik.org/semlanik/QtTWAIN
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy of this
  9. * software and associated documentation files (the "Software"), to deal in the Software
  10. * without restriction, including without limitation the rights to use, copy, modify,
  11. * merge, publish, distribute, sublicense, and/or sell copies of the Software, and
  12. * to permit persons to whom the Software is furnished to do so, subject to the following
  13. * conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in all copies
  16. * or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  19. * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  20. * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  21. * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  22. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. */
  25. #pragma once
  26. #include <QHash>
  27. #include <qwindowdefs.h>
  28. #include <memory>
  29. #include "qtwain_p.h"
  30. #include "qtwaineventfilter_p.h"
  31. #include "dsm/qdsminterface.h"
  32. #include <type_traits>
  33. namespace QtTWAIN {
  34. class QTWAINScanner;
  35. class QTWAINEventFilter;
  36. class QTWAINContext {
  37. public:
  38. static QTWAINContext *instance() {
  39. static QTWAINContext ctx;
  40. return &ctx;
  41. }
  42. void openDSM(const WId winId);
  43. void closeDSM();
  44. void fetchScannerList();
  45. void userSelectScanner();
  46. QList<QString> scannerList() const {
  47. return m_scannerList.keys();
  48. }
  49. QtTWAIN::QTWAINScanner *scanner(const QString& name) const {
  50. return m_scannerList.value(name, std::shared_ptr<QtTWAIN::QTWAINScanner>(nullptr)).get();
  51. }
  52. bool openDS(TW_IDENTITY *dataSource);
  53. void closeDS(TW_IDENTITY *dataSource);
  54. bool enableDS(TW_IDENTITY *dataSource);
  55. bool disableDS(TW_IDENTITY *dataSource);
  56. bool imageInfo(TW_IMAGEINFO *info, TW_IDENTITY *dataSource);
  57. bool processEvent(TW_EVENT *event, TW_IDENTITY *dataSource);
  58. quint16 imageNativeTransfer(TW_HANDLE *imgHandle, TW_IDENTITY *dataSource);
  59. bool endTransfer(TW_PENDINGXFERS *pendingTransfers, TW_IDENTITY *dataSource);
  60. void updateStatus(TW_IDENTITY *dataSource = nullptr);
  61. private:
  62. QTWAINContext();
  63. ~QTWAINContext();
  64. Q_DISABLE_COPY_MOVE(QTWAINContext)
  65. enum States {
  66. Initial,
  67. DSMOpen,
  68. };
  69. QDSMInterface *m_dsm;
  70. States m_state;
  71. TW_MEMREF m_windowHandle;
  72. TW_IDENTITY m_appIdentity; /**< current application identity */
  73. TW_STATUS m_status;
  74. QHash<QString, std::shared_ptr<QtTWAIN::QTWAINScanner>> m_scannerList;
  75. };
  76. }