Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d6a2bb1

Browse files
#95=secmod_linux gui update
1 parent 30a372f commit d6a2bb1

File tree

10 files changed

+82
-32
lines changed

10 files changed

+82
-32
lines changed

keychain_linux/passentry_cmd/cmd.hpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ namespace slave {
9696
}
9797

9898
namespace master {
99-
enum struct cmds {unknown = 0, rawtrx, close, modify, length, create, unlock, check, last};
99+
enum struct cmds {unknown = 0, rawtrx, close, modify, length, create, unlock, check, focus, last};
100100

101101
struct cmd_base {
102102
cmd_base(): cmd(cmds::unknown){};
@@ -181,9 +181,22 @@ namespace master {
181181
bool res;
182182
} check_param;
183183
};
184+
185+
template<>
186+
struct cmd<cmds::focus> : cmd_base{
187+
cmd(int line): cmd_base(), focus_param(line){
188+
cmd_base::cmd = cmds::focus;
189+
params = fc_light::variant(focus_param);
190+
};
191+
struct params_t {
192+
params_t(int l): line(l) {}
193+
int line;
194+
} focus_param;
195+
};
196+
184197
}
185198

186-
FC_LIGHT_REFLECT_ENUM(master::cmds, (unknown)(rawtrx)(close)(modify)(length)(unlock)(check)(last))
199+
FC_LIGHT_REFLECT_ENUM(master::cmds, (unknown)(rawtrx)(close)(modify)(length)(unlock)(check)(focus)(last))
187200
FC_LIGHT_REFLECT(master::cmd_base, (cmd)(params))
188201
FC_LIGHT_REFLECT(master::cmd<master::cmds::rawtrx>::params_t, (rawtrx))
189202
FC_LIGHT_REFLECT(master::cmd<master::cmds::close>::params_t, (cmd))
@@ -192,6 +205,7 @@ FC_LIGHT_REFLECT(master::cmd<master::cmds::length>::params_t, (len)(line_edit))
192205
FC_LIGHT_REFLECT(master::cmd<master::cmds::create>::params_t, (keyname))
193206
FC_LIGHT_REFLECT(master::cmd<master::cmds::unlock>::params_t, (keyname)(unlock_time))
194207
FC_LIGHT_REFLECT(master::cmd<master::cmds::check>::params_t, (res))
208+
FC_LIGHT_REFLECT(master::cmd<master::cmds::focus>::params_t, (line))
195209

196210
FC_LIGHT_REFLECT_ENUM(slave::cmds, (unknown)(ok)(cancel)(focus)(last))
197211
FC_LIGHT_REFLECT(slave::cmd_common, (cmd)(params))

keychain_linux/passentry_cmd/pass_entry_term.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,13 @@ std::wstring pass_entry_term::input_password(const KeySym * map, int socket)
284284
if (ev[1].code == KEY_LEFTSHIFT || ev[1].code == KEY_RIGHTSHIFT) shift = 1;
285285
else if (ev[1].code == KEY_CAPSLOCK) capslock ^= 0x1;
286286
else if (ev[1].code == KEY_NUMLOCK) numlock ^= 0x1;
287-
else if (ev[1].code == KEY_TAB ) line_edit ^= 0x1;
287+
else if (ev[1].code == KEY_TAB )
288+
{
289+
line_edit ^= 0x1;
290+
auto a = master::cmd<master::cmds::focus>(line_edit);
291+
auto mes = fc_light::json::to_string(fc_light::variant(static_cast<const master::cmd_base&>(a)));
292+
send_gui( mes, socket );
293+
}
288294
else if (OnKey (ev[1].code, shift, capslock, numlock, password[line_edit], map))
289295
{
290296
if (password[0] == password[1])

keychain_linux/passentry_gui/include/PasswordEnterElement.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ class PasswordEnterElement : public QWidget
2626
void checkFinishedEnterance();
2727
void setFocusOnConfirm();
2828
bool validConfirm();
29-
PasswordLineEdit *value = Q_NULLPTR;
30-
PasswordLineEdit *valueConfirm = Q_NULLPTR;
31-
void focusProcess (int line);
29+
PasswordLineEdit *value = Q_NULLPTR;
30+
PasswordLineEdit *valueConfirm = Q_NULLPTR;
31+
void tabFocusByMouse (int line);
3232

3333
signals:
3434
void finishEnterPassword();

keychain_linux/passentry_gui/include/PasswordLineEdit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class PasswordLineEdit : public QLineEdit
1515
~PasswordLineEdit();
1616

1717
protected:
18-
void keyPressEvent(QKeyEvent *event) override;
18+
//void keyPressEvent(QKeyEvent *event) override;
1919
void focusInEvent(QFocusEvent *event) override;
2020

2121
signals:

keychain_linux/passentry_gui/include/cmd.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "widget.hpp"
1717

1818
namespace slave {
19-
enum struct cmds {unknown = 0, rawtrx, close, modify, length, create, unlock, check, last }; // to gui
19+
enum struct cmds {unknown = 0, rawtrx, close, modify, length, create, unlock, check, focus, last }; // to gui
2020

2121
struct cmd_common {
2222
cmd_common(cmds cmd_ = cmds::unknown): cmd(cmd_){};
@@ -72,7 +72,7 @@ namespace master
7272
};
7373
}
7474

75-
FC_LIGHT_REFLECT_ENUM(slave::cmds, (unknown)(rawtrx)(close)(modify)(length)(create)(unlock)(check)(last))
75+
FC_LIGHT_REFLECT_ENUM(slave::cmds, (unknown)(rawtrx)(close)(modify)(length)(create)(unlock)(check)(focus)(last))
7676
FC_LIGHT_REFLECT(slave::cmd_common, (cmd)(params))
7777

7878
FC_LIGHT_REFLECT_ENUM(master::cmds, (unknown)(ok)(cancel)(focus)(last))

keychain_linux/passentry_gui/include/keychain_gui_win.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ class keychain_gui_win : public QDialog
4343
void refresh(Transaction&);
4444
PasswordEnterElement * password;
4545
void send(std::string);
46-
void focus(int);
47-
46+
void setFocusByMouse(int);
47+
void setFocusByTabKey(int);
48+
void passentry (int, int);
4849
bool send_msg;
4950

5051
private:

keychain_linux/passentry_gui/src/PasswordEnterElement.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,20 @@ PasswordEnterElement::PasswordEnterElement(bool passwordCreate, QWidget * parent
4444
confirmDescription->setText("");
4545

4646
labelConfirm->setText("Confirm");
47-
connect(value, &QLineEdit::textEdited, this, &PasswordEnterElement::checkStrength);
47+
//connect(value, &QLineEdit::textEdited, this, &PasswordEnterElement::checkStrength);
4848
// connect(value, &PasswordLineEdit::finishEnter, this, &PasswordEnterElement::setFocusOnConfirm);
4949
// connect(valueConfirm, &QLineEdit::textEdited, this, &PasswordEnterElement::checkConfirm);
5050
// connect(valueConfirm, &PasswordLineEdit::finishEnter, this, &PasswordEnterElement::checkFinishedEnterance);
51-
connect(value, &PasswordLineEdit::focus, this, &PasswordEnterElement::focusProcess);
52-
connect(valueConfirm, &PasswordLineEdit::focus, this, &PasswordEnterElement::focusProcess);
51+
connect(value, &PasswordLineEdit::focus, this, &PasswordEnterElement::tabFocusByMouse);
52+
connect(valueConfirm, &PasswordLineEdit::focus, this, &PasswordEnterElement::tabFocusByMouse);
5353
}
5454
else {
55-
connect(value, &PasswordLineEdit::finishEnter, this, &PasswordEnterElement::checkFinishedEnterance);
55+
//connect(value, &PasswordLineEdit::finishEnter, this, &PasswordEnterElement::checkFinishedEnterance);
5656
}
5757
}
5858

5959

60-
void PasswordEnterElement::focusProcess(int line)
60+
void PasswordEnterElement::tabFocusByMouse(int line)
6161
{
6262
emit focus(line);
6363
}

keychain_linux/passentry_gui/src/PasswordLineEdit.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ PasswordLineEdit::~PasswordLineEdit()
1010
{
1111
}
1212

13-
void PasswordLineEdit::keyPressEvent(QKeyEvent * event)
13+
/*void PasswordLineEdit::keyPressEvent(QKeyEvent * event)
1414
{
15+
1516
if (event->key()==Qt::Key_Return) {
1617
emit finishEnter();
1718
}
@@ -20,9 +21,10 @@ void PasswordLineEdit::keyPressEvent(QKeyEvent * event)
2021
QLineEdit::keyPressEvent(event);
2122
}
2223
}
23-
24+
*/
2425

2526
void PasswordLineEdit::focusInEvent(QFocusEvent *event)
2627
{
28+
QLineEdit::focusInEvent(event);
2729
emit focus(window);
2830
}

keychain_linux/passentry_gui/src/cmd.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,7 @@ namespace slave
8484
virtual void operator()(keychain_gui_win& w, const fc_light::variant& v) const override {
8585
try {
8686
auto a = v.as<params_t>();
87-
if (a.line_edit) {
88-
w.password->valueConfirm->setFocus();
89-
w.password->valueConfirm->setText(QString(a.len, '*'));
90-
w.password->valueConfirm->setCursorPosition(a.len);
91-
}
92-
else
93-
{
94-
w.password->value->setFocus();
95-
w.password->value->setText(QString (a.len, '*'));
96-
w.password->value->setCursorPosition(a.len);
97-
}
87+
w.passentry(a.len, a.line_edit);
9888
}
9989
catch (const std::exception &e) {throw std::runtime_error(e.what());}
10090
catch (const fc_light::exception &e) {throw std::runtime_error(e.what());}
@@ -162,6 +152,24 @@ namespace slave
162152
};
163153
};
164154

155+
template<>
156+
struct cmd<cmds::focus> : cmd_base {
157+
cmd() : cmd_base(cmds::focus) {};
158+
virtual ~cmd() {};
159+
struct params {
160+
int line;
161+
};
162+
using params_t = params;
163+
virtual void operator()(keychain_gui_win& w, const fc_light::variant& v) const override {
164+
try {
165+
auto a = v.as<params_t>();
166+
w.setFocusByTabKey(a.line);
167+
}
168+
catch (const std::exception &e) {throw std::runtime_error(e.what());}
169+
catch (const fc_light::exception &e) {throw std::runtime_error(e.what());}
170+
};
171+
};
172+
165173
const cmd_list_singleton& cmd_list_singleton::instance() {
166174
static const cmd_list_singleton instance;
167175
return instance;
@@ -193,6 +201,7 @@ FC_LIGHT_REFLECT(slave::cmd<slave::cmds::length>::params_t, (len)(line_edit))
193201
FC_LIGHT_REFLECT(slave::cmd<slave::cmds::create>::params_t, (keyname))
194202
FC_LIGHT_REFLECT(slave::cmd<slave::cmds::unlock>::params_t, (keyname)(unlock_time))
195203
FC_LIGHT_REFLECT(slave::cmd<slave::cmds::check>::params_t, (res))
204+
FC_LIGHT_REFLECT(slave::cmd<slave::cmds::focus>::params_t, (line))
196205

197206

198207

keychain_linux/passentry_gui/src/keychain_gui_win.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ void keychain_gui_win::refresh(Transaction& transaction)
113113
password->move(0, endControlPosition);
114114
endControlPosition += password->GetElementHeigth();
115115
endControlPosition += 10;
116-
117116
if (element != Q_NULLPTR)
118117
headerBlock->setFixedWidth(element->GetCurrentWidth() + 20);
119118
else
@@ -166,7 +165,7 @@ void keychain_gui_win::refresh(Transaction& transaction)
166165
this->connect(OKButton, &QPushButton::released, this, &keychain_gui_win::found_pass);
167166
this->connect(OKButton, &QPushButton::released, this, &keychain_gui_win::close);
168167
this->connect(CancelButton, &QPushButton::released, this, &keychain_gui_win::close);
169-
this->connect(password, &PasswordEnterElement::focus, this, &keychain_gui_win::focus);
168+
this->connect(password, &PasswordEnterElement::focus, this, &keychain_gui_win::setFocusByMouse);
170169

171170
_roundCorners();
172171
password->setValueFocus();
@@ -285,7 +284,26 @@ void keychain_gui_win::send(std::string a)
285284
close();
286285
}
287286

288-
void keychain_gui_win::focus(int line)
287+
void keychain_gui_win::setFocusByMouse(int line)
289288
{
290289
send(fc_light::json::to_string(fc_light::variant(static_cast<master::cmd_base>(master::cmd<(master::cmds::focus)>(line)))));
291290
}
291+
292+
void keychain_gui_win::setFocusByTabKey(int line_edit)
293+
{
294+
line_edit ? password->valueConfirm->setFocus(): password->value->setFocus();
295+
}
296+
297+
void keychain_gui_win::passentry(int len, int line_edit)
298+
{
299+
if (line_edit)
300+
{
301+
password->valueConfirm->setText(QString(len, '*'));
302+
password->valueConfirm->setFocus();
303+
}
304+
else
305+
{
306+
password->value->setText(QString (len, '*'));
307+
password->value->setFocus();
308+
}
309+
}

0 commit comments

Comments
 (0)