11#include <config-libkleo.h> 
   13#include "readerportselection.h" 
   15#include <libkleo/scdaemon.h> 
   17#include <libkleo_debug.h> 
   19#include <KLocalizedString> 
   21#if __has_include(<QGpgME/Debug>) 
   22#include <QGpgME/Debug> 
   29#include <gpgme++/error.h> 
   33class ReaderPortSelection::Private
 
   36    Private(ReaderPortSelection *q);
 
   38    void setValue(
const QString &value);
 
   39    QString value() 
const;
 
   42    void onCurrentIndexChanged(
int);
 
   43    void onEditTextChanged(
const QString &);
 
   46    ReaderPortSelection *
const q = 
nullptr;
 
   47    QComboBox *
const mComboBox = 
nullptr;
 
   50ReaderPortSelection::Private::Private(Kleo::ReaderPortSelection *qq)
 
   56    layout->addWidget(mComboBox);
 
   58    mComboBox->addItem(
i18nc(
"@item:inlistbox", 
"Default reader"), {});
 
   63        qCWarning(LIBKLEO_LOG) << 
"Getting available smart card readers failed:" << err;
 
   65        std::for_each(std::begin(readers), std::end(readers), [
this](
const auto &reader) {
 
   67            mComboBox->addItem(readerId, readerId);
 
   71    mComboBox->addItem(
QString{}, {});
 
   72    mComboBox->setToolTip(
xi18nc(
"@info:tooltip",
 
   73                                 "<para>Select the smart card reader that GnuPG shall use.<list>" 
   74                                 "<item>The first item will make GnuPG use the first reader that is found.</item>" 
   75                                 "<item>The last item allows you to enter a custom reader ID or reader port number.</item>" 
   76                                 "<item>All other items represent readers that were found by GnuPG.</item>" 
   80        onCurrentIndexChanged(index);
 
   81        Q_EMIT q->valueChanged(q->value());
 
   84        onEditTextChanged(text);
 
   85        Q_EMIT q->valueChanged(q->value());
 
   89void ReaderPortSelection::Private::setValue(
const QString &value)
 
   91    if (value.isEmpty()) {
 
   92        mComboBox->setCurrentIndex(0);
 
   95    const int indexOfValue = mComboBox->findData(value);
 
   96    if (indexOfValue != -1) {
 
   97        mComboBox->setCurrentIndex(indexOfValue);
 
   99        mComboBox->setCurrentIndex(mComboBox->count() - 1);
 
  100        mComboBox->setEditText(value);
 
  104QString ReaderPortSelection::Private::value()
 const 
  106    return mComboBox->currentData().toString();
 
  109void ReaderPortSelection::Private::onCurrentIndexChanged(
int index)
 
  112    mComboBox->setEditable(index == mComboBox->count() - 1);
 
  113    if (mComboBox->lineEdit()) {
 
  114        mComboBox->lineEdit()->setPlaceholderText(
i18nc(
"@item:inlistbox", 
"Custom reader ID or port number"));
 
  118void ReaderPortSelection::Private::onEditTextChanged(
const QString &text)
 
  120    const int lastIndex = mComboBox->count() - 1;
 
  122    if (mComboBox->currentIndex() == lastIndex) {
 
  123        mComboBox->setItemText(lastIndex, text);
 
  124        mComboBox->setItemData(lastIndex, text);
 
  130    , d{new Private{this}}
 
  134ReaderPortSelection::~ReaderPortSelection() = 
default;
 
  136void ReaderPortSelection::setValue(
const QString &value)
 
  141QString ReaderPortSelection::value()
 const 
  146#include "moc_readerportselection.cpp" 
QString xi18nc(const char *context, const char *text, const TYPE &arg...)
 
QString i18nc(const char *context, const char *text, const TYPE &arg...)
 
KLEO_EXPORT std::vector< std::string > getReaders(GpgME::Error &err)
Returns the list of available smart card readers.
 
void currentIndexChanged(int index)
 
void editTextChanged(const QString &text)
 
void setContentsMargins(const QMargins &margins)
 
QObject * parent() const const
 
QString fromStdString(const std::string &str)
 
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)