|
1 | 1 | #include "keychain_gui_win.h"
|
2 | 2 |
|
| 3 | +#include <fc_light/io/json.hpp> |
| 4 | +#include "cmd.hpp" |
| 5 | + |
| 6 | +#include <fc_light/reflect/reflect.hpp> |
| 7 | +#include <fc_light/variant.hpp> |
| 8 | + |
| 9 | +Q_DECLARE_METATYPE(std::string) |
| 10 | +int id1 = qRegisterMetaType<std::string>(); |
| 11 | + |
3 | 12 | keychain_gui_win::keychain_gui_win(Transaction &transaction, QWidget *parent)
|
4 | 13 | : QDialog(parent)
|
5 | 14 | {
|
@@ -160,9 +169,22 @@ keychain_gui_win::keychain_gui_win(Transaction &transaction, QWidget *parent)
|
160 | 169 | _roundCorners();
|
161 | 170 | password->setValueFocus();
|
162 | 171 | connect(password, &PasswordEnterElement::finishEnterPassword, this, &keychain_gui_win::transaction_sign);
|
163 |
| - if (transaction.isCreatePassword()) { |
| 172 | + if (transaction.isCreatePassword()) |
164 | 173 | connect(password, &PasswordEnterElement::changePassword, this, &keychain_gui_win::_disableSignButton);
|
165 |
| - } |
| 174 | + |
| 175 | + Polling *polling = new Polling; |
| 176 | + polling->moveToThread(&pollingThread); |
| 177 | + connect(&pollingThread, &QThread::finished, polling, &QObject::deleteLater); |
| 178 | + |
| 179 | + connect(this, &keychain_gui_win::poll, polling, &Polling::Select, Qt::QueuedConnection); |
| 180 | + connect(polling, &Polling::poll, polling, &Polling::Select, Qt::QueuedConnection); |
| 181 | + connect(polling, &Polling::rx, this, &keychain_gui_win::parse); |
| 182 | + connect(polling, &Polling::err, this, &keychain_gui_win::close); |
| 183 | + |
| 184 | + pollingThread.start(); |
| 185 | + passClearOnExit = true; |
| 186 | + emit keychain_gui_win::poll(); |
| 187 | + |
166 | 188 | }
|
167 | 189 |
|
168 | 190 | void keychain_gui_win::transaction_sign() {
|
@@ -246,11 +268,44 @@ void keychain_gui_win::keyPressEvent(QKeyEvent *event)
|
246 | 268 | }
|
247 | 269 | }
|
248 | 270 |
|
| 271 | +void keychain_gui_win::parse(const std::string s) |
| 272 | +{ |
| 273 | + auto a = fc_light::json::from_string(s); |
| 274 | + try { |
| 275 | + auto cmd = a.as<slave::cmd_common>(); |
| 276 | + auto cmd_map = slave::cmd_list_singletone::instance(); |
| 277 | + auto p_func = cmd_map[cmd.cmd]; |
| 278 | +// (*p_func)(this, cmd.params); |
| 279 | + } |
| 280 | + catch (const std::exception &e) {throw std::runtime_error(e.what());} |
| 281 | + catch (const fc_light::exception &e) {throw std::runtime_error(e.what());} |
| 282 | +} |
| 283 | + |
| 284 | + |
249 | 285 | void keychain_gui_win::closeEvent(QCloseEvent * event)
|
250 | 286 | {
|
| 287 | +// passClearOnExit ? |
| 288 | +// send(fc_light::json::to_string(fc_light::variant( master::cmd<( master::cmds::cancel)>().base))) : |
| 289 | +// send(fc_light::json::to_string(fc_light::variant( master::cmd<( master::cmds::ok)>().base))); |
| 290 | +// event->accept(); |
251 | 291 | serviceExchange->EncodeCancel();
|
252 | 292 | this->close();
|
253 | 293 | }
|
254 | 294 |
|
| 295 | +void keychain_gui_win::found_pass() |
| 296 | +{ |
| 297 | + passClearOnExit = false; |
| 298 | +} |
| 299 | + |
| 300 | +void keychain_gui_win::send(std::string a) |
| 301 | +{ |
| 302 | + if ( write(STDIN_FILENO, a.c_str(), a.length() ) != a.length() ) |
| 303 | + close(); |
| 304 | +} |
255 | 305 |
|
| 306 | +keychain_gui_win::~keychain_gui_win() |
| 307 | +{ |
| 308 | + pollingThread.quit(); |
| 309 | + pollingThread.wait(); |
| 310 | +} |
256 | 311 |
|
0 commit comments