mirror of
https://github.com/eosswedenorg/antelope-keygen
synced 2026-07-02 11:43:40 +02:00
gui/SearchWindow: implement dictionary language
This commit is contained in:
parent
3b1ada9cb7
commit
1f8fbfc8ca
2 changed files with 47 additions and 0 deletions
|
|
@ -30,12 +30,15 @@
|
||||||
#include <libeosio/WIF.h>
|
#include <libeosio/WIF.h>
|
||||||
#include <eoskeygen/core/leet.h>
|
#include <eoskeygen/core/leet.h>
|
||||||
#include <eoskeygen/core/string.h>
|
#include <eoskeygen/core/string.h>
|
||||||
|
#include "config.h"
|
||||||
|
#include "helpers.h"
|
||||||
#include "SearchWindow.h"
|
#include "SearchWindow.h"
|
||||||
|
|
||||||
SearchWindow::SearchWindow(QWidget *parent, Qt::WindowFlags flags) :
|
SearchWindow::SearchWindow(QWidget *parent, Qt::WindowFlags flags) :
|
||||||
QWidget (parent, flags),
|
QWidget (parent, flags),
|
||||||
m_status ("status"),
|
m_status ("status"),
|
||||||
m_leet_cb ("L33t"),
|
m_leet_cb ("L33t"),
|
||||||
|
m_dict_lang ("Dictionary Language"),
|
||||||
m_btn_exec ("Search"),
|
m_btn_exec ("Search"),
|
||||||
m_btn_clear ("Clear")
|
m_btn_clear ("Clear")
|
||||||
{
|
{
|
||||||
|
|
@ -54,6 +57,9 @@ m_btn_clear ("Clear")
|
||||||
m_layout.setColumnStretch(0, 10);
|
m_layout.setColumnStretch(0, 10);
|
||||||
|
|
||||||
// First row.
|
// First row.
|
||||||
|
m_dict_lang.addItems(get_files(CONFIG_DICT_FULL_PATH));
|
||||||
|
m_layout.addWidget(&m_dict_lang, 0, 0);
|
||||||
|
|
||||||
m_layout.addWidget(&m_leet_cb, 0, 1);
|
m_layout.addWidget(&m_leet_cb, 0, 1);
|
||||||
|
|
||||||
m_num_threads.setValue((int) eoskeygen::KeySearch::max_threads());
|
m_num_threads.setValue((int) eoskeygen::KeySearch::max_threads());
|
||||||
|
|
@ -98,6 +104,8 @@ void SearchWindow::initSignals()
|
||||||
connect(&m_worker, SIGNAL(finished()), this, SLOT(searchFinished()));
|
connect(&m_worker, SIGNAL(finished()), this, SLOT(searchFinished()));
|
||||||
|
|
||||||
connect(this, SIGNAL(addOutput(QString)), this, SLOT(output(QString)));
|
connect(this, SIGNAL(addOutput(QString)), this, SLOT(output(QString)));
|
||||||
|
|
||||||
|
connect(&m_dict_lang, SIGNAL(selectionChanged(QStringList)), this, SLOT(langSelected(QStringList)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchWindow::onResult(const struct libeosio::ec_keypair* key, const struct eoskeygen::KeySearch::result& result)
|
void SearchWindow::onResult(const struct libeosio::ec_keypair* key, const struct eoskeygen::KeySearch::result& result)
|
||||||
|
|
@ -108,6 +116,7 @@ void SearchWindow::onResult(const struct libeosio::ec_keypair* key, const struct
|
||||||
QString mid = pub.mid(pos, len);
|
QString mid = pub.mid(pos, len);
|
||||||
QString left = pub.left(pos);
|
QString left = pub.left(pos);
|
||||||
QString right = pub.mid(pos + len, pub.size() - pos);
|
QString right = pub.mid(pos + len, pub.size() - pos);
|
||||||
|
eoskeygen::Dictionary::search_result_t dict_res = m_dict.search(pub.toStdString());
|
||||||
|
|
||||||
QString out = "Public: " + pub.left(3);
|
QString out = "Public: " + pub.left(3);
|
||||||
for(int i = 3; i < pub.length(); ) {
|
for(int i = 3; i < pub.length(); ) {
|
||||||
|
|
@ -118,6 +127,16 @@ void SearchWindow::onResult(const struct libeosio::ec_keypair* key, const struct
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Look in the dictionary.
|
||||||
|
auto dp = dict_res.find(i);
|
||||||
|
if (dp != dict_res.end()) {
|
||||||
|
int p = (int) dp->first;
|
||||||
|
int l = (int) dp->second;
|
||||||
|
out += "<font color=blue>" + pub.mid(p, l) + "</font>";
|
||||||
|
i += l;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
out += pub[i++];
|
out += pub[i++];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -181,10 +200,29 @@ void SearchWindow::output(const QString& html)
|
||||||
m_output.verticalScrollBar()->setValue(m_output.verticalScrollBar()->maximum());
|
m_output.verticalScrollBar()->setValue(m_output.verticalScrollBar()->maximum());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SearchWindow::langSelected(QStringList selected)
|
||||||
|
{
|
||||||
|
std::string base_path(CONFIG_DICT_FULL_PATH);
|
||||||
|
|
||||||
|
// Clear dictionary first.
|
||||||
|
m_dict.clear();
|
||||||
|
|
||||||
|
// Go through all selected languages.
|
||||||
|
for(QStringList::const_iterator it = selected.cbegin(); it != selected.cend(); it++) {
|
||||||
|
|
||||||
|
// Load and add them to dictionary.
|
||||||
|
eoskeygen::Dictionary dict;
|
||||||
|
dict.loadFromFile(base_path + "/" + it->toStdString());
|
||||||
|
|
||||||
|
m_dict.add(dict);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SearchWindow::searchStarted()
|
void SearchWindow::searchStarted()
|
||||||
{
|
{
|
||||||
m_txt_search.setEnabled(false);
|
m_txt_search.setEnabled(false);
|
||||||
m_txt_search.setHidden(true);
|
m_txt_search.setHidden(true);
|
||||||
|
m_dict_lang.setEnabled(false);
|
||||||
m_btn_exec.setEnabled(false);
|
m_btn_exec.setEnabled(false);
|
||||||
m_btn_clear.setEnabled(false);
|
m_btn_clear.setEnabled(false);
|
||||||
m_num_threads.setEnabled(false);
|
m_num_threads.setEnabled(false);
|
||||||
|
|
@ -195,6 +233,7 @@ void SearchWindow::searchFinished()
|
||||||
{
|
{
|
||||||
m_txt_search.setEnabled(true);
|
m_txt_search.setEnabled(true);
|
||||||
m_txt_search.setHidden(false);
|
m_txt_search.setHidden(false);
|
||||||
|
m_dict_lang.setEnabled(true);
|
||||||
m_btn_exec.setEnabled(true);
|
m_btn_exec.setEnabled(true);
|
||||||
m_btn_clear.setEnabled(true);
|
m_btn_clear.setEnabled(true);
|
||||||
m_num_threads.setEnabled(true);
|
m_num_threads.setEnabled(true);
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <eoskeygen/key_search_result.h>
|
#include <eoskeygen/key_search_result.h>
|
||||||
#include <eoskeygen/key_search.h>
|
#include <eoskeygen/key_search.h>
|
||||||
|
#include "MultiSelect.h"
|
||||||
|
|
||||||
class SearchWindow : public QWidget, public eoskeygen::IKeySearchResult
|
class SearchWindow : public QWidget, public eoskeygen::IKeySearchResult
|
||||||
{
|
{
|
||||||
|
|
@ -62,6 +63,9 @@ private slots:
|
||||||
// Called when a search is done.
|
// Called when a search is done.
|
||||||
void searchFinished();
|
void searchFinished();
|
||||||
|
|
||||||
|
// Called when dictionary language(s) are selected.
|
||||||
|
void langSelected(QStringList selected);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void addOutput(const QString& line);
|
void addOutput(const QString& line);
|
||||||
|
|
||||||
|
|
@ -72,6 +76,8 @@ private:
|
||||||
|
|
||||||
eoskeygen::KeySearch m_ksearch;
|
eoskeygen::KeySearch m_ksearch;
|
||||||
|
|
||||||
|
eoskeygen::Dictionary m_dict;
|
||||||
|
|
||||||
// Widgets
|
// Widgets
|
||||||
// ----------------
|
// ----------------
|
||||||
|
|
||||||
|
|
@ -89,6 +95,8 @@ private:
|
||||||
|
|
||||||
QCheckBox m_leet_cb;
|
QCheckBox m_leet_cb;
|
||||||
|
|
||||||
|
MultiSelect m_dict_lang;
|
||||||
|
|
||||||
// Buttons
|
// Buttons
|
||||||
QPushButton m_btn_exec;
|
QPushButton m_btn_exec;
|
||||||
QPushButton m_btn_clear;
|
QPushButton m_btn_clear;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue