33 #include <QInputDialog> 48 QString GetPasswordHelper (
const QByteArray& key,
const ICoreProxy_ptr& proxy)
51 if (!result.isValid ())
53 qWarning () << Q_FUNC_INFO
54 <<
"invalid result for key" 59 switch (result.type ())
61 case QVariant::String:
62 return result.toString ();
64 return result.toList ().value (0).toString ();
65 case QVariant::StringList:
66 return result.toStringList ().value (0);
68 qWarning () << Q_FUNC_INFO
69 <<
"unknown result type" 79 QString
GetPassword (
const QString& key,
const QString& diaText,
84 const auto& result = GetPasswordHelper (key.toUtf8 (), proxy);
85 if (!result.isNull ())
89 const auto& result = QInputDialog::getText (
nullptr,
93 if (!result.isNull ())
100 const EitherCont<
void (),
void (QString)>& cont,
106 const auto& result = GetPasswordHelper (key.toUtf8 (), proxy);
107 if (!result.isNull ())
114 const auto dialog =
new QInputDialog;
115 dialog->setInputMode (QInputDialog::TextInput);
116 dialog->setWindowTitle (
"LeechCraft");
117 dialog->setLabelText (diaText);
118 dialog->setTextEchoMode (QLineEdit::Password);
119 dialog->setAttribute (Qt::WA_DeleteOnClose);
122 QObject::connect (depender,
123 SIGNAL (destroyed ()),
125 SLOT (deleteLater ()));
131 const auto& value = dialog->textValue ();
132 if (value.isEmpty ())
138 SIGNAL (accepted ()),
144 [cont] { cont.Left (); },
146 SIGNAL (rejected ()),
156 const auto& plugins = proxy->GetPluginsManager ()->
157 GetAllCastableTo<IPersistentStoragePlugin*> ();
158 for (
const auto plugin : plugins)
159 if (
const auto& storage = plugin->RequestStorage ())
160 storage->Set (key.toUtf8 (), password);
QString GetPassword(const QString &key, const QString &diaText, const ICoreProxy_ptr &proxy, bool useStored)
Returns password for the key, possibly asking the user.
QVariant GetPersistentData(const QByteArray &key, const ICoreProxy_ptr &proxy)
Returns persistent data stored under given key.
Executes a given functor upon a signal (or a list of signals).
A peir of two functions, typically a continuation and an error handler.
std::shared_ptr< ICoreProxy > ICoreProxy_ptr
void SavePassword(const QString &password, const QString &key, const ICoreProxy_ptr &proxy)
Saves the password to be retrieved later via GetPassword().