Changeset View
Changeset View
Standalone View
Standalone View
src/utils/input.cpp
| Show All 27 Lines | 1 | /* -*- mode: c++; c-basic-offset:4 -*- | |||
|---|---|---|---|---|---|
| 28 | your version of the file, but you are not obligated to do so. If | 28 | your version of the file, but you are not obligated to do so. If | ||
| 29 | you do not wish to do so, delete this exception statement from | 29 | you do not wish to do so, delete this exception statement from | ||
| 30 | your version. | 30 | your version. | ||
| 31 | */ | 31 | */ | ||
| 32 | 32 | | |||
| 33 | #include <config-kleopatra.h> | 33 | #include <config-kleopatra.h> | ||
| 34 | 34 | | |||
| 35 | #include "input.h" | 35 | #include "input.h" | ||
| 36 | #include "input_p.h" | ||||
| 36 | 37 | | |||
| 37 | #include "detail_p.h" | 38 | #include "detail_p.h" | ||
| 38 | #include "kdpipeiodevice.h" | 39 | #include "kdpipeiodevice.h" | ||
| 39 | #include "log.h" | 40 | #include "log.h" | ||
| 40 | #include "kleo_assert.h" | 41 | #include "kleo_assert.h" | ||
| 41 | #include "cached.h" | 42 | #include "cached.h" | ||
| 42 | 43 | | |||
| 43 | #include <Libkleo/Exception> | 44 | #include <Libkleo/Exception> | ||
| Show All 28 Lines | 72 | void close() override { | |||
| 72 | closeReadChannel(StandardOutput); | 73 | closeReadChannel(StandardOutput); | ||
| 73 | } | 74 | } | ||
| 74 | }; | 75 | }; | ||
| 75 | } | 76 | } | ||
| 76 | 77 | | |||
| 77 | namespace | 78 | namespace | ||
| 78 | { | 79 | { | ||
| 79 | 80 | | |||
| 80 | class InputImplBase : public Input | | |||
| 81 | { | | |||
| 82 | public: | | |||
| 83 | InputImplBase() : Input(), m_customLabel(), m_defaultLabel() {} | | |||
| 84 | | ||||
| 85 | QString label() const override | | |||
| 86 | { | | |||
| 87 | return m_customLabel.isEmpty() ? m_defaultLabel : m_customLabel; | | |||
| 88 | } | | |||
| 89 | void setDefaultLabel(const QString &l) | | |||
| 90 | { | | |||
| 91 | m_defaultLabel = l; | | |||
| 92 | } | | |||
| 93 | void setLabel(const QString &l) override { | | |||
| 94 | m_customLabel = l; | | |||
| 95 | } | | |||
| 96 | QString errorString() const override | | |||
| 97 | { | | |||
| 98 | if (m_errorString.dirty()) { | | |||
| 99 | m_errorString = doErrorString(); | | |||
| 100 | } | | |||
| 101 | return m_errorString; | | |||
| 102 | } | | |||
| 103 | | ||||
| 104 | private: | | |||
| 105 | virtual QString doErrorString() const | | |||
| 106 | { | | |||
| 107 | if (const std::shared_ptr<QIODevice> io = ioDevice()) { | | |||
| 108 | return io->errorString(); | | |||
| 109 | } else { | | |||
| 110 | return i18n("No input device"); | | |||
| 111 | } | | |||
| 112 | } | | |||
| 113 | | ||||
| 114 | private: | | |||
| 115 | QString m_customLabel; | | |||
| 116 | QString m_defaultLabel; | | |||
| 117 | mutable cached<QString> m_errorString; | | |||
| 118 | }; | | |||
| 119 | | ||||
| 120 | class PipeInput : public InputImplBase | 81 | class PipeInput : public InputImplBase | ||
| 121 | { | 82 | { | ||
| 122 | public: | 83 | public: | ||
| 123 | explicit PipeInput(assuan_fd_t fd); | 84 | explicit PipeInput(assuan_fd_t fd); | ||
| 124 | 85 | | |||
| 125 | std::shared_ptr<QIODevice> ioDevice() const override | 86 | std::shared_ptr<QIODevice> ioDevice() const override | ||
| 126 | { | 87 | { | ||
| 127 | return m_io; | 88 | return m_io; | ||
| ▲ Show 20 Lines • Show All 323 Lines • Show Last 20 Lines | |||||