12#include <QInputDialog>
24 QString GetPasswordHelper (
const QByteArray& key,
const ICoreProxy_ptr& proxy)
27 if (!result.isValid ())
29 qWarning () << Q_FUNC_INFO
30 <<
"invalid result for key"
35 switch (result.type ())
37 case QVariant::String:
38 return result.toString ();
40 return result.toList ().value (0).toString ();
41 case QVariant::StringList:
42 return result.toStringList ().value (0);
44 qWarning () << Q_FUNC_INFO
45 <<
"unknown result type"
55 QString
GetPassword (
const QString& key,
const QString& diaText,
60 const auto& result = GetPasswordHelper (key.toUtf8 (), proxy);
61 if (!result.isNull ())
65 const auto& result = QInputDialog::getText (
nullptr,
66 QStringLiteral (
"LeechCraft"),
69 if (!result.isNull ())
76 const EitherCont<
void (),
void (QString)>& cont,
82 const auto& result = GetPasswordHelper (key.toUtf8 (), proxy);
83 if (!result.isNull ())
90 const auto dialog =
new QInputDialog;
91 dialog->setInputMode (QInputDialog::TextInput);
92 dialog->setWindowTitle (QStringLiteral (
"LeechCraft"));
93 dialog->setLabelText (diaText);
94 dialog->setTextEchoMode (QLineEdit::Password);
95 dialog->setAttribute (Qt::WA_DeleteOnClose);
98 QObject::connect (depender,
101 &QObject::deleteLater);
103 QObject::connect (dialog,
105 [dialog, cont] (
int r)
107 const auto& value = dialog->textValue ();
108 if (r == QDialog::Rejected || value.isEmpty ())
121 for (
const auto plugin : plugins)
122 if (
const auto& storage = plugin->RequestStorage ())
123 storage->Set (key.toUtf8 (), password);
Interface for plugins providing persistent (and possibly secure) storage.
A peir of two functions, typically a continuation and an error handler.
std::shared_ptr< ICoreProxy > ICoreProxy_ptr
QVariant GetPersistentData(const QByteArray &key, const ICoreProxy_ptr &proxy)
Returns persistent data stored under given key.
void SavePassword(const QString &password, const QString &key, const ICoreProxy_ptr &proxy)
Saves the password to be retrieved later via GetPassword().
QString GetPassword(const QString &key, const QString &diaText, const ICoreProxy_ptr &proxy, bool useStored)
Returns password for the key, possibly asking the user.