12#include <QInputDialog>
24 QString GetPasswordHelper (
const QByteArray& key,
const ICoreProxy_ptr& proxy)
27 if (!result.isValid ())
29 qWarning () <<
"invalid result for key" << key;
33 switch (result.typeId ())
35 case QMetaType::QString:
36 return result.toString ();
37 case QMetaType::QVariantList:
38 return result.toList ().value (0).toString ();
39 case QMetaType::QStringList:
40 return result.toStringList ().value (0);
42 qWarning () <<
"unknown result type" << result.metaType () << result <<
"for key" << key;
48 QString
GetPassword (
const QString& key,
const QString& diaText,
53 const auto& result = GetPasswordHelper (key.toUtf8 (), proxy);
54 if (!result.isNull ())
58 const auto& result = QInputDialog::getText (
nullptr,
59 QStringLiteral (
"LeechCraft"),
62 if (!result.isNull ())
69 const EitherCont<
void (),
void (QString)>& cont,
75 const auto& result = GetPasswordHelper (key.toUtf8 (), proxy);
76 if (!result.isNull ())
83 const auto dialog =
new QInputDialog;
84 dialog->setInputMode (QInputDialog::TextInput);
85 dialog->setWindowTitle (QStringLiteral (
"LeechCraft"));
86 dialog->setLabelText (diaText);
87 dialog->setTextEchoMode (QLineEdit::Password);
88 dialog->setAttribute (Qt::WA_DeleteOnClose);
91 QObject::connect (depender,
94 &QObject::deleteLater);
96 QObject::connect (dialog,
98 [dialog, cont] (
int r)
100 const auto& value = dialog->textValue ();
101 if (r == QDialog::Rejected || value.isEmpty ())
114 for (
const auto plugin : plugins)
115 if (
const auto& storage = plugin->RequestStorage ())
116 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.
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.