Commit 218096f8 authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Add the card holder to the card labels shown for the tabs

Card, OpenPGPCard:
* Get card holder name from the card info for all types of card/apps
  (scdaemon currently only provides the card holder for the OpenPGP app)

GnuPG-bug-id: 5066
parent 214b2f48
Pipeline #37396 passed with stage
in 13 minutes and 24 seconds
......@@ -114,6 +114,11 @@ QString Card::displayCardVersion() const
return formatVersion(mCardVersion);
}
QString Card::cardHolder() const
{
return mCardHolder;
}
std::vector<Card::PinState> Card::pinStates() const
{
return mPinStates;
......@@ -191,6 +196,12 @@ bool Card::parseCardInfo(const std::string &name, const std::string &value)
} else if (name == "CARDVERSION") {
mCardVersion = parseHexEncodedVersionTuple(value);
return true;
} else if (name == "DISP-NAME") {
auto list = QString::fromUtf8(QByteArray::fromStdString(value)).
split(QStringLiteral("<<"), Qt::SkipEmptyParts);
std::reverse(list.begin(), list.end());
mCardHolder = list.join(QLatin1Char(' '));
return true;
}
return false;
......
......@@ -71,6 +71,8 @@ public:
int cardVersion() const;
QString displayCardVersion() const;
QString cardHolder() const;
std::vector<PinState> pinStates() const;
void setPinStates(const std::vector<PinState> &pinStates);
......@@ -98,6 +100,7 @@ private:
int mAppVersion = -1;
std::string mCardType;
int mCardVersion = -1;
QString mCardHolder;
std::vector<PinState> mPinStates;
QString mErrMsg;
};
......
......@@ -150,13 +150,6 @@ std::string OpenPGPCard::manufacturer() const
return mManufacturer;
}
std::string OpenPGPCard::cardHolder() const
{
auto list = QString::fromStdString(mMetaInfo.value("DISP-NAME")).split(QStringLiteral("<<"));
std::reverse(list.begin(), list.end());
return list.join(QLatin1Char(' ')).toStdString();
}
std::string OpenPGPCard::pubkeyUrl() const
{
return mMetaInfo.value("PUBKEY-URL");
......
......@@ -40,7 +40,6 @@ public:
void setManufacturer(const std::string &manufacturer);
std::string manufacturer() const;
std::string cardHolder() const;
std::string pubkeyUrl() const;
private:
QMap <std::string, std::string> mMetaInfo;
......
......@@ -221,7 +221,7 @@ void PGPCardWidget::setCard(const OpenPGPCard *card)
mSerialNumber->setText(card->displaySerialNumber());
mRealSerial = card->serialNumber();
const auto holder = QString::fromStdString(card->cardHolder());
const auto holder = card->cardHolder();
const auto url = QString::fromStdString(card->pubkeyUrl());
mCardHolderLabel->setText(holder.isEmpty() ? i18n("not set") : holder);
mUrl = url;
......
......@@ -141,6 +141,18 @@ void SmartCardWidget::Private::cardAddedOrChanged(const std::string &serialNumbe
}
}
namespace {
static QString getCardLabel(const std::shared_ptr<Card> &card) {
if (!card->cardHolder().isEmpty()) {
return i18nc("@title:tab smartcard application - name of card holder - serial number of smartcard", "%1 - %2 - %3",
displayAppName(card->appName()), card->cardHolder(), card->displaySerialNumber());
} else {
return i18nc("@title:tab smartcard application - serial number of smartcard", "%1 - %2",
displayAppName(card->appName()), card->displaySerialNumber());
}
}
}
template <typename C, typename W>
void SmartCardWidget::Private::cardAddedOrChanged(const std::string &serialNumber)
{
......@@ -154,9 +166,7 @@ void SmartCardWidget::Private::cardAddedOrChanged(const std::string &serialNumbe
if (!cardWidget) {
cardWidget = new W;
mCardWidgets.insert({serialNumber, C::AppName}, cardWidget);
const QString cardLabel = i18nc("@title:tab smartcard application - serial number of smartcard", "%1 - %2",
displayAppName(C::AppName), card->displaySerialNumber());
mTabWidget->addTab(cardWidget, cardLabel);
mTabWidget->addTab(cardWidget, getCardLabel(card));
if (mCardWidgets.size() == 1) {
mStack->setCurrentWidget(mTabWidget);
}
......
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