12#include <QInputDialog>
25 QString GetPasswordHelper (
const QByteArray& key,
const ICoreProxy_ptr& proxy)
28 if (!result.isValid ())
30 qWarning () <<
"invalid result for key" << key;
35 [] (
const QString& str) {
return str; },
36 [] (
const QVariantList& list) {
return list.value (0).toString (); },
37 [] (
const QStringList& list) {
return list.value (0); },
40 qWarning () <<
"unknown result type" << result.metaType () << result <<
"for key" << key;
46 QString
GetPassword (
const QString& key,
const QString& diaText,
51 const auto& result = GetPasswordHelper (key.toUtf8 (), proxy);
52 if (!result.isNull ())
56 const auto& result = QInputDialog::getText (
nullptr,
57 QStringLiteral (
"LeechCraft"),
60 if (!result.isNull ())
67 const EitherCont<
void (),
void (QString)>& cont,
73 const auto& result = GetPasswordHelper (key.toUtf8 (), proxy);
74 if (!result.isNull ())
81 const auto dialog =
new QInputDialog;
82 dialog->setInputMode (QInputDialog::TextInput);
83 dialog->setWindowTitle (QStringLiteral (
"LeechCraft"));
84 dialog->setLabelText (diaText);
85 dialog->setTextEchoMode (QLineEdit::Password);
86 dialog->setAttribute (Qt::WA_DeleteOnClose);
89 QObject::connect (depender,
92 &QObject::deleteLater);
94 QObject::connect (dialog,
96 [dialog, cont] (
int r)
98 const auto& value = dialog->textValue ();
99 if (r == QDialog::Rejected || value.isEmpty ())
112 for (
const auto plugin : plugins)
113 if (
const auto& storage = plugin->RequestStorage ())
114 storage->Set (key.toUtf8 (), password);
virtual IPluginsManager * GetPluginsManager() const =0
Returns the application's plugin manager.
Interface for plugins providing persistent (and possibly secure) storage.
QList< T > GetAllCastableTo() const
Similar to GetAlLCastableRoots() and provided for convenience.
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.
auto HandleQVariant(const QVariant &variant, Fs &&... handlers)
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.