Skip to content

Commit caaf240

Browse files
task update
1 parent 22c7d7c commit caaf240

File tree

7 files changed

+20
-141
lines changed

7 files changed

+20
-141
lines changed

keychain_linux/passentry_gui/include/cmd.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <boost/hana/range.hpp>
1414
#include <boost/hana/for_each.hpp>
1515
#include <boost/hana/size.hpp>
16-
#include "keychain_gui_win.h"
16+
#include "widget.hpp"
1717

1818
namespace slave {
1919
enum struct cmds {unknown = 0, rawtrx, close, modify, length, last }; // to gui
@@ -26,7 +26,7 @@ namespace slave {
2626
struct cmd_base {
2727
cmd_base(cmds cmd_) : cmd(cmd_) {};
2828
cmds cmd;
29-
virtual void operator()(keychain_gui_win* w, const fc_light::variant&) const = 0;
29+
virtual void operator()(Widget* w, const fc_light::variant&) const = 0;
3030
virtual ~cmd_base() {};
3131
};
3232
struct cmd_list_singletone

keychain_linux/passentry_gui/include/keychain_gui_win.h

+1-12
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
#include "KeychainWarningMessage.h"
2626
#include "RawHashWidget.h"
2727

28-
#include <QThread>
29-
#include "polling.hpp"
3028

3129
using namespace keychain_app;
3230
using secmod_commands::secmod_parser_f;
@@ -39,9 +37,8 @@ class keychain_gui_win : public QDialog
3937
Ui::keychain_gui_winClass ui;
4038

4139
public:
42-
QThread pollingThread;
40+
4341
keychain_gui_win(Transaction &transaction, QWidget *parent = Q_NULLPTR);
44-
~keychain_gui_win();
4542
PopupWindow * popupWindow;
4643

4744
private:
@@ -61,11 +58,9 @@ class keychain_gui_win : public QDialog
6158
PasswordEnterElement * password;
6259
KeychainServiceExchange * serviceExchange =NULL;
6360

64-
bool passClearOnExit;
6561
private:
6662
void _roundCorners();
6763
void _disableSignButton();
68-
void parse(const std::string);
6964

7065
protected:
7166
void keyPressEvent(QKeyEvent *event) override;
@@ -79,10 +74,4 @@ public slots:
7974
void transaction_sign();
8075
void cancel_sign();
8176
void set_sign_focus();
82-
83-
void found_pass();
84-
void send(std::string);
85-
signals:
86-
void poll();
87-
8877
};

keychain_linux/passentry_gui/src/widget.hpp__ renamed to keychain_linux/passentry_gui/include/widget.hpp

-4
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ class Widget : public QWidget
1515
public:
1616
Widget(QWidget *parent = 0);
1717
~Widget();
18-
QLineEdit *ple;
19-
QTextEdit *pte;
20-
QLabel *caps, *num, *shift;
2118
private:
22-
void interior();
2319
void closeEvent(QCloseEvent *);
2420
void parse(const std::string);
2521
bool passClearOnExit;

keychain_linux/passentry_gui/src/cmd.cpp

+11-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// Created by user on 23.06.18.
33
//
44
#include "cmd.hpp"
5+
#include "Transaction.h"
6+
#include "keychain_gui_win.h"
7+
58
Q_DECLARE_METATYPE(std::string)
69

710
namespace hana = boost::hana;
@@ -11,7 +14,7 @@ namespace slave
1114
struct cmd : cmd_base {
1215
cmd() : cmd_base(cmd_) {};
1316
virtual ~cmd() {};
14-
virtual void operator()(keychain_gui_win* w, const fc_light::variant& v) const override {
17+
virtual void operator()(Widget* w, const fc_light::variant& v) const override {
1518
throw std::runtime_error("operation is not implemented");
1619
};
1720
using params_t = void;
@@ -24,10 +27,13 @@ namespace slave
2427
virtual ~cmd() {};
2528
struct params {std::string rawtrx;};
2629
using params_t = params;
27-
virtual void operator()(keychain_gui_win * w, const fc_light::variant& v) const override {
30+
virtual void operator()(Widget * w, const fc_light::variant& v) const override {
2831
try {
2932
auto a = v.as<params_t>();
3033
// w->pte->setText(QString(a.rawtrx.c_str()));
34+
QString value(a.rawtrx.c_str());
35+
Transaction trans(value);
36+
keychain_gui_win w(trans);
3137
}
3238
catch (const std::exception &e) {throw std::runtime_error(e.what());}
3339
catch (const fc_light::exception &e) {throw std::runtime_error(e.what());}
@@ -39,7 +45,7 @@ namespace slave
3945
cmd() : cmd_base(cmds::close) {};
4046
virtual ~cmd() {};
4147
using params_t = void;
42-
virtual void operator()(keychain_gui_win* w, const fc_light::variant& v) const override {
48+
virtual void operator()(Widget* w, const fc_light::variant& v) const override {
4349
try { w->close(); }
4450
catch (const std::exception &e) {throw std::runtime_error(e.what());}
4551
catch (const fc_light::exception &e) {throw std::runtime_error(e.what());}
@@ -52,7 +58,7 @@ namespace slave
5258
virtual ~cmd() {};
5359
struct params { bool caps, num, shift; };
5460
using params_t = params;
55-
virtual void operator()(keychain_gui_win* w, const fc_light::variant& v) const override {
61+
virtual void operator()(Widget* w, const fc_light::variant& v) const override {
5662
try {
5763
auto a = v.as<params_t>();
5864
//a.caps ? w->caps->setText("caps: on") : w->caps->setText("caps: off");
@@ -70,7 +76,7 @@ namespace slave
7076
virtual ~cmd() {};
7177
struct params {int len;};
7278
using params_t = params;
73-
virtual void operator()(keychain_gui_win* w, const fc_light::variant& v) const override {
79+
virtual void operator()(Widget* w, const fc_light::variant& v) const override {
7480
try {
7581
auto a = v.as<params_t>();
7682
// w->ple->setText(QString (a.len, '*'));

keychain_linux/passentry_gui/src/keychain_gui_win.cpp

-57
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
#include "keychain_gui_win.h"
22

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-
123
keychain_gui_win::keychain_gui_win(Transaction &transaction, QWidget *parent)
134
: QDialog(parent)
145
{
@@ -171,20 +162,6 @@ keychain_gui_win::keychain_gui_win(Transaction &transaction, QWidget *parent)
171162
connect(password, &PasswordEnterElement::finishEnterPassword, this, &keychain_gui_win::transaction_sign);
172163
if (transaction.isCreatePassword())
173164
connect(password, &PasswordEnterElement::changePassword, this, &keychain_gui_win::_disableSignButton);
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-
188165
}
189166

190167
void keychain_gui_win::transaction_sign() {
@@ -268,45 +245,11 @@ void keychain_gui_win::keyPressEvent(QKeyEvent *event)
268245
}
269246
}
270247

271-
void keychain_gui_win::parse(const std::string s)
272-
{
273-
auto a = fc_light::json::from_string(s);
274-
using namespace slave;
275-
try {
276-
auto cmd = a.as<slave::cmd_common>();
277-
auto cmd_map = slave::cmd_list_singletone::instance();
278-
auto p_func = cmd_map[cmd.cmd];
279-
(*p_func)(this, cmd.params);
280-
}
281-
catch (const std::exception &e) {throw std::runtime_error(e.what());}
282-
catch (const fc_light::exception &e) {throw std::runtime_error(e.what());}
283-
}
284-
285248

286249
void keychain_gui_win::closeEvent(QCloseEvent * event)
287250
{
288-
// passClearOnExit ?
289-
// send(fc_light::json::to_string(fc_light::variant( master::cmd<( master::cmds::cancel)>().base))) :
290-
// send(fc_light::json::to_string(fc_light::variant( master::cmd<( master::cmds::ok)>().base)));
291-
// event->accept();
292251
serviceExchange->EncodeCancel();
293252
this->close();
294253
}
295254

296-
void keychain_gui_win::found_pass()
297-
{
298-
passClearOnExit = false;
299-
}
300-
301-
void keychain_gui_win::send(std::string a)
302-
{
303-
if ( write(STDIN_FILENO, a.c_str(), a.length() ) != a.length() )
304-
close();
305-
}
306-
307-
keychain_gui_win::~keychain_gui_win()
308-
{
309-
pollingThread.quit();
310-
pollingThread.wait();
311-
}
312255

keychain_linux/passentry_gui/src/main.cpp

+4-16
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,18 @@
1-
#include "keychain_gui_win.h"
2-
3-
//#include "widget.hpp"
1+
#include "widget.hpp"
42
#include <QApplication>
53
#include <QDesktopWidget>
64
#include <stdlib.h>
75
#include <iostream>
86

9-
Q_DECLARE_METATYPE(std::string)
107

118
int main(int argc, char *argv[])
129
{
1310
QApplication a(argc, argv);
14-
// Widget w;
15-
16-
QString srcTrans;
17-
Transaction trans(srcTrans);
18-
19-
keychain_gui_win w(trans);
20-
21-
const QRect sz = QApplication::desktop()->availableGeometry(&w);
22-
w.resize(sz.width() / 6, sz.height() * 1 / 6);
23-
w.move((sz.width() - w.width()) / 2,
24-
(sz.height() - w.height()) / 2);
25-
11+
Widget w;
2612
w.show();
13+
2714
return a.exec();
15+
2816
}
2917

3018

keychain_linux/passentry_gui/src/widget.cpp_ renamed to keychain_linux/passentry_gui/src/widget.cpp

+2-45
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ int id = qRegisterMetaType<std::string>();
1717
Widget::Widget(QWidget *parent)
1818
:QWidget(parent)
1919
{
20-
setWindowTitle(tr("Promt for password"));
21-
interior();
2220

2321
Polling *polling = new Polling;
2422
polling->moveToThread(&pollingThread);
@@ -40,56 +38,15 @@ Widget::~Widget()
4038
pollingThread.wait();
4139
}
4240

43-
void Widget::interior()
44-
{
45-
QGridLayout * grid = new QGridLayout(this);
46-
{
47-
QLabel *plb = new QLabel(tr("password"), this);
48-
grid->addWidget(plb, 0, 0);
49-
}
50-
51-
ple = new QLineEdit(this);
52-
ple->setEchoMode(QLineEdit::Password);
53-
54-
grid->addWidget(ple, 0, 1, 1, 3);
55-
{
56-
QLabel *plb = new QLabel(tr("Raw Tx"), this);
57-
grid->addWidget(plb, 1, 0);
58-
}
59-
60-
pte = new QTextEdit(this);
61-
grid->addWidget(pte, 1, 1, 1, 3);
62-
pte->setText("");
63-
pte->setReadOnly(true);
64-
65-
caps = new QLabel(tr(""), this);
66-
grid->addWidget(caps, 2, 0);
67-
68-
num = new QLabel(tr(""), this);
69-
grid->addWidget(num, 2, 1);
70-
71-
shift = new QLabel(tr(""), this);
72-
grid->addWidget(shift, 2, 2);
73-
74-
{
75-
QPushButton *plb = new QPushButton("Ok", this);
76-
grid->addWidget(plb, 3, 1);
77-
connect(plb, SIGNAL(clicked()), this, SLOT(found_pass()));
78-
connect(plb, SIGNAL(clicked()), this, SLOT(close()));
79-
}
80-
{
81-
QPushButton * ppb = new QPushButton("Cancel", this);
82-
grid->addWidget(ppb, 3, 2);
83-
connect(ppb, SIGNAL(clicked()), this, SLOT(close()));
84-
}
85-
}
8641

8742
void Widget::send(std::string a)
8843
{
8944
if ( write(STDIN_FILENO, a.c_str(), a.length() ) != a.length() )
9045
close();
9146
}
9247

48+
49+
9350
void Widget::found_pass()
9451
{
9552
passClearOnExit = false;

0 commit comments

Comments
 (0)