Commit 6eac9b66 authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Track first card with Null PIN instead of general "any card has Null PIN"

This makes it easier to handle multiple cards.

GnuPG-bug-id: 5066
parent 32c6f48b
......@@ -95,11 +95,11 @@ public:
KDAB_SET_OBJECT_NAME(readerStatus);
#ifndef QT_NO_SYSTEMTRAYICON
sysTray = new SysTrayIcon();
sysTray->setAnyCardHasNullPin(readerStatus.anyCardHasNullPin());
sysTray->setFirstCardWithNullPin(readerStatus.firstCardWithNullPin());
sysTray->setAnyCardCanLearnKeys(readerStatus.anyCardCanLearnKeys());
connect(&readerStatus, &SmartCard::ReaderStatus::anyCardHasNullPinChanged,
sysTray, &SysTrayIcon::setAnyCardHasNullPin);
connect(&readerStatus, &SmartCard::ReaderStatus::firstCardWithNullPinChanged,
sysTray, &SysTrayIcon::setFirstCardWithNullPin);
connect(&readerStatus, &SmartCard::ReaderStatus::anyCardCanLearnKeysChanged,
sysTray, &SysTrayIcon::setAnyCardCanLearnKeys);
#endif
......
......@@ -557,7 +557,7 @@ public:
}
Q_SIGNALS:
void anyCardHasNullPinChanged(bool);
void firstCardWithNullPinChanged(const std::string &serialNumber);
void anyCardCanLearnKeysChanged(bool);
void cardChanged(unsigned int);
void oneTransactionFinished(const GpgME::Error &err);
......@@ -652,7 +652,7 @@ private:
unsigned int idx = 0;
bool anyLC = false;
bool anyNP = false;
std::string firstCardWithNullPin;
bool anyError = false;
while (nit != nend && oit != oend) {
const auto optr = (*oit).get();
......@@ -664,8 +664,8 @@ private:
if ((*nit)->canLearnKeys()) {
anyLC = true;
}
if ((*nit)->hasNullPin()) {
anyNP = true;
if ((*nit)->hasNullPin() && firstCardWithNullPin.empty()) {
firstCardWithNullPin = (*nit)->serialNumber();
}
if ((*nit)->status() == Card::CardError) {
anyError = true;
......@@ -675,7 +675,7 @@ private:
++idx;
}
Q_EMIT anyCardHasNullPinChanged(anyNP);
Q_EMIT firstCardWithNullPinChanged(firstCardWithNullPin);
Q_EMIT anyCardCanLearnKeysChanged(anyLC);
if (anyError) {
......@@ -730,8 +730,8 @@ public:
connect(this, &::ReaderStatusThread::cardChanged,
q, &ReaderStatus::cardChanged);
connect(this, &::ReaderStatusThread::anyCardHasNullPinChanged,
q, &ReaderStatus::anyCardHasNullPinChanged);
connect(this, &::ReaderStatusThread::firstCardWithNullPinChanged,
q, &ReaderStatus::firstCardWithNullPinChanged);
connect(this, &::ReaderStatusThread::anyCardCanLearnKeysChanged,
q, &ReaderStatus::anyCardCanLearnKeysChanged);
......@@ -748,11 +748,12 @@ public:
}
private:
bool anyCardHasNullPinImpl() const
std::string firstCardWithNullPinImpl() const
{
const auto cis = cardInfos();
return std::any_of(cis.cbegin(), cis.cend(),
[](const std::shared_ptr<Card> &ci) { return ci->hasNullPin(); });
const auto firstWithNullPin = std::find_if(cis.cbegin(), cis.cend(),
[](const std::shared_ptr<Card> &ci) { return ci->hasNullPin(); });
return firstWithNullPin != cis.cend() ? (*firstWithNullPin)->serialNumber() : std::string();
}
bool anyCardCanLearnKeysImpl() const
......@@ -770,6 +771,8 @@ ReaderStatus::ReaderStatus(QObject *parent)
: QObject(parent), d(new Private(this))
{
self = this;
qRegisterMetaType<std::string>("std::string");
}
ReaderStatus::~ReaderStatus()
......@@ -800,9 +803,9 @@ Card::Status ReaderStatus::cardStatus(unsigned int slot) const
return d->cardStatus(slot);
}
bool ReaderStatus::anyCardHasNullPin() const
std::string ReaderStatus::firstCardWithNullPin() const
{
return d->anyCardHasNullPinImpl();
return d->firstCardWithNullPinImpl();
}
bool ReaderStatus::anyCardCanLearnKeys() const
......
......@@ -44,7 +44,7 @@ public:
void startTransaction(const QByteArray &cmd, QObject *receiver, const char *slot, std::unique_ptr<GpgME::AssuanTransaction> transaction);
Card::Status cardStatus(unsigned int slot) const;
bool anyCardHasNullPin() const;
std::string firstCardWithNullPin() const;
bool anyCardCanLearnKeys() const;
std::vector<Card::PinState> pinStates(unsigned int slot) const;
......@@ -69,7 +69,7 @@ public Q_SLOTS:
void startMonitoring();
Q_SIGNALS:
void anyCardHasNullPinChanged(bool);
void firstCardWithNullPinChanged(const std::string &serialNumber);
void anyCardCanLearnKeysChanged(bool);
void cardChanged(unsigned int slot);
......
......@@ -75,10 +75,10 @@ private:
//triggering slotEnableDisableActions again
const QSignalBlocker blocker(QApplication::clipboard());
openCertificateManagerAction.setEnabled(!q->mainWindow() || !q->mainWindow()->isVisible());
setInitialPinAction.setEnabled(anyCardHasNullPin);
setInitialPinAction.setEnabled(!firstCardWithNullPin.empty());
learnCertificatesAction.setEnabled(anyCardCanLearnKeys);
q->setAttentionWanted((anyCardHasNullPin || anyCardCanLearnKeys) && !q->attentionWindow());
q->setAttentionWanted((!firstCardWithNullPin.empty() || anyCardCanLearnKeys) && !q->attentionWindow());
}
void slotSetInitialPin()
......@@ -102,9 +102,9 @@ private:
}
private:
bool anyCardHasNullPin;
bool anyCardCanLearnKeys;
bool learningInProgress;
std::string firstCardWithNullPin;
bool anyCardCanLearnKeys = false;
bool learningInProgress = false;
QMenu menu;
QAction openCertificateManagerAction;
......@@ -125,8 +125,6 @@ private:
SysTrayIcon::Private::Private(SysTrayIcon *qq)
: q(qq),
anyCardHasNullPin(false),
anyCardCanLearnKeys(false),
menu(),
openCertificateManagerAction(i18n("&Open Certificate Manager..."), q),
configureAction(QIcon::fromTheme(QStringLiteral("configure")), i18n("&Configure %1...", KAboutData::applicationData().componentName()), q),
......@@ -208,7 +206,7 @@ void SysTrayIcon::doActivated()
if (aw->isVisible()) {
return; // ignore clicks while an attention window is open.
}
if (d->anyCardHasNullPin) {
if (!d->firstCardWithNullPin.empty()) {
d->slotSetInitialPin();
} else if (d->anyCardCanLearnKeys) {
d->slotLearnCertificates();
......@@ -218,12 +216,12 @@ void SysTrayIcon::doActivated()
}
}
void SysTrayIcon::setAnyCardHasNullPin(bool on)
void SysTrayIcon::setFirstCardWithNullPin(const std::string &serialNumber)
{
if (d->anyCardHasNullPin == on) {
if (d->firstCardWithNullPin == serialNumber) {
return;
}
d->anyCardHasNullPin = on;
d->firstCardWithNullPin = serialNumber;
slotEnableDisableActions();
}
......
......@@ -31,7 +31,7 @@ public:
void setLearningInProgress(bool value);
public Q_SLOTS:
void setAnyCardHasNullPin(bool);
void setFirstCardWithNullPin(const std::string &serialNumber);
void setAnyCardCanLearnKeys(bool);
private:
......
......@@ -738,7 +738,7 @@ Command::Restrictions KeyListController::Private::calculateRestrictionsMask(cons
result |= find_root_restrictions(keys);
if (const ReaderStatus *rs = ReaderStatus::instance()) {
if (rs->anyCardHasNullPin()) {
if (!rs->firstCardWithNullPin().empty()) {
result |= Command::AnyCardHasNullPin;
}
if (rs->anyCardCanLearnKeys()) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment