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 ())
98 void GetPassword (
const QString& key,
const QString& diaText,
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 ()));
127 new Util::SlotClosure<Util::DeleteLaterPolicy>
131 const auto& value = dialog->textValue ();
132 if (value.isEmpty ())
138 SIGNAL (accepted ()),
142 new Util::SlotClosure<Util::DeleteLaterPolicy>
144 [cont] { cont.Left (); },
146 SIGNAL (rejected ()),
153 void SavePassword (
const QString& password,
const QString& key,
157 for (
const auto plugin : plugins)
158 if (
const auto& storage = plugin->RequestStorage ())
159 storage->Set (key.toUtf8 (), password);