Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/bin
/out
/tmp
/.vs
CMakePresets.json
34 changes: 34 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
cmake_minimum_required(VERSION 3.12)

project(sokit LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(Qt6 REQUIRED COMPONENTS Widgets Network)
find_package(Qt6LinguistTools)

file(GLOB SRC_FILES "src/sokit/*.cpp" "src/sokit/*.qrc" "src/sokit/*.rc" "src/sokit/*.ui")
file(GLOB HEAD_FILES "src/sokit/*.h")

if(CMAKE_HOST_WIN32)
enable_language("RC")
if(CMAKE_BUILD_TYPE STREQUAL "Release")
add_executable(${PROJECT_NAME} WIN32 ${SRC_FILES} ${HEAD_FILES} )
else()
add_executable(${PROJECT_NAME} ${SRC_FILES} ${HEAD_FILES} )
endif()
else()
add_executable(${PROJECT_NAME} ${SRC_FILES} ${HEAD_FILES} "qml.qrc" )
endif()

qt_add_translations(${PROJECT_NAME} TS_FILES "src/sokit/sokit.ts")

target_link_libraries(${PROJECT_NAME} PRIVATE Qt6::Widgets Qt6::Network )

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin/${CMAKE_BUILD_TYPE}/)
54 changes: 27 additions & 27 deletions src/sokit/baseform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#define PROP_TARG "targ"

BaseForm::BaseForm(QWidget* p, Qt::WindowFlags f)
:QWidget(p, f),m_cntRecv(0),m_cntSend(0),m_labRecv(0),m_labSend(0),m_cnlist(0)
: QWidget(p, f), m_cntRecv(0), m_cntSend(0), m_labRecv(nullptr), m_labSend(nullptr), m_cnlist(nullptr)
{
}

Expand Down Expand Up @@ -52,26 +52,27 @@ void BaseForm::initLogger(QCheckBox* w, QToolButton* c, QTreeWidget* o, QPlainTe

bindFocus(o, Qt::Key_F3);

QShortcut* wr = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this);
QShortcut* cl = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_D), this);
QShortcut* sl = new QShortcut(QKeySequence(Qt::Key_F4), this);
auto wr = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_W), this);
auto cl = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_D), this);
auto sl = new QShortcut(QKeySequence(Qt::Key_F4), this);

sl->setProperty(PROP_TARG, qVariantFromValue((void*)d));
sl->setProperty(PROP_TARG, QVariant::fromValue(static_cast<void*>(d)));

connect(wr, SIGNAL(activated()), w, SLOT(click()));
connect(sl, SIGNAL(activated()), this, SLOT(hotOutput()));
connect(cl, SIGNAL(activated()), this, SLOT(clear()));

connect(this, SIGNAL(output(const QString&)), &m_logger, SLOT(output(const QString&)));
connect(this, SIGNAL(output(const QString&, const char*, quint32)), &m_logger, SLOT(output(const QString&, const char*, quint32)));
connect(this, SIGNAL(output(const QString&, const char*, quint32)), &m_logger,
SLOT(output(const QString&, const char*, quint32)));
}

void BaseForm::initLister(QToolButton* a, QToolButton* k, QListWidget* l)
{
m_cnlist = l;

QShortcut* sk = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_K), this);
QShortcut* sa = new QShortcut(QKeySequence(Qt::ALT + Qt::Key_A), this);
auto sk = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_K), this);
auto sa = new QShortcut(QKeySequence(Qt::ALT | Qt::Key_A), this);

connect(sk, SIGNAL(activated()), this, SLOT(kill()));
connect(sa, SIGNAL(activated()), m_cnlist, SLOT(selectAll()));
Expand All @@ -84,47 +85,47 @@ void BaseForm::initLister(QToolButton* a, QToolButton* k, QListWidget* l)

void BaseForm::bindBuffer(qint32 id, QLineEdit* e, QToolButton* s, QComboBox* d)
{
s->setProperty(PROP_EDIT, qVariantFromValue((void*)e));
s->setProperty(PROP_DIRT, qVariantFromValue((void*)d));
s->setProperty(PROP_EDIT, QVariant::fromValue(static_cast<void*>(e)));
s->setProperty(PROP_DIRT, QVariant::fromValue(static_cast<void*>(d)));

connect(s, SIGNAL(released()), this, SLOT(send()));

bindClick(s, Qt::Key_0 + id + Qt::CTRL);
bindFocus(e, Qt::Key_0 + id + Qt::ALT);
bindFocus(d, Qt::Key_0 + id + Qt::CTRL + Qt::SHIFT);
bindClick(s, Qt::Key_0 + id | Qt::CTRL);
bindFocus(e, Qt::Key_0 + id | Qt::ALT);
bindFocus(d, Qt::Key_0 + id | Qt::CTRL | Qt::SHIFT);
}

void BaseForm::bindFocus(QWidget* w, qint32 k)
{
QShortcut* s = new QShortcut(QKeySequence(k), this);
s->setProperty(PROP_TARG, qVariantFromValue((void*)w));
auto s = new QShortcut(QKeySequence(k), this);
s->setProperty(PROP_TARG, QVariant::fromValue(static_cast<void*>(w)));
connect(s, SIGNAL(activated()), this, SLOT(focus()));
}

void BaseForm::bindClick(QAbstractButton* b, qint32 k)
{
QShortcut* s = new QShortcut(QKeySequence(k), this);
auto s = new QShortcut(QKeySequence(k), this);
connect(s, SIGNAL(activated()), b, SLOT(click()));
}

void BaseForm::bindSelect(QComboBox* b, qint32 i, qint32 k)
{
QShortcut* s = new QShortcut(QKeySequence(k), this);
s->setProperty(PROP_TARG, qVariantFromValue((void*)b));
auto s = new QShortcut(QKeySequence(k), this);
s->setProperty(PROP_TARG, QVariant::fromValue(static_cast<void*>(b)));
s->setObjectName(QString::number(i));

connect(s, SIGNAL(activated()), this, SLOT(select()));
}

void BaseForm::focus()
{
QWidget* w = (QWidget*)sender()->property(PROP_TARG).value<void*>();
auto w = static_cast<QWidget*>(sender()->property(PROP_TARG).value<void*>());
if (w) w->setFocus(Qt::TabFocusReason);
}

void BaseForm::hotOutput()
{
QPlainTextEdit* t = (QPlainTextEdit*)sender()->property(PROP_TARG).value<void*>();
auto t = static_cast<QPlainTextEdit*>(sender()->property(PROP_TARG).value<void*>());
if (t)
{
t->setFocus(Qt::TabFocusReason);
Expand All @@ -134,7 +135,7 @@ void BaseForm::hotOutput()

void BaseForm::select()
{
QComboBox* b = (QComboBox*)sender()->property(PROP_TARG).value<void*>();
auto b = static_cast<QComboBox*>(sender()->property(PROP_TARG).value<void*>());
if (b && b->isEnabled())
{
qint32 i = sender()->objectName().toInt();
Expand All @@ -153,7 +154,7 @@ void BaseForm::countRecv(qint32 bytes)
if (bytes < 0)
m_cntRecv = 0;
else
m_cntRecv += bytes;
m_cntRecv += bytes;

m_labRecv->setText(QString::number(m_cntRecv));
}
Expand All @@ -170,10 +171,10 @@ void BaseForm::countSend(qint32 bytes)

void BaseForm::send()
{
QLineEdit* e = (QLineEdit*)sender()->property(PROP_EDIT).value<void*>();
QComboBox* d = (QComboBox*)sender()->property(PROP_DIRT).value<void*>();
auto e = static_cast<QLineEdit*>(sender()->property(PROP_EDIT).value<void*>());
auto d = static_cast<QComboBox*>(sender()->property(PROP_DIRT).value<void*>());
if (e)
send(e->text(), (d?d->currentText():""));
send(e->text(), (d ? d->currentText() : ""));
}

void BaseForm::clear()
Expand Down Expand Up @@ -222,8 +223,7 @@ void BaseForm::listerRemove(const QString& caption)
while (i--)
{
QListWidgetItem* itm = m_cnlist->item(i);
if (itm && itm->text()==caption)
if (itm && itm->text() == caption)
delete m_cnlist->takeItem(i);
}
}

18 changes: 12 additions & 6 deletions src/sokit/baseform.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,23 @@

class QLabel;
class QListWidget;

class BaseForm : public QWidget
{
Q_OBJECT

public:
BaseForm(QWidget* p=0, Qt::WindowFlags f=0);
virtual ~BaseForm();
BaseForm(QWidget* p = nullptr, Qt::WindowFlags f = Qt::WindowFlags(0));
~BaseForm() override;

bool init();

protected:
bool lock() { m_door.lock(); return true; };
bool lock()
{
m_door.lock();
return true;
};
bool lock(qint32 w) { return m_door.tryLock(w); };
void unlock() { m_door.unlock(); };

Expand All @@ -37,7 +42,10 @@ class BaseForm : public QWidget
virtual bool initHotkeys() =0;
virtual void initConfig() =0;
virtual void saveConfig() =0;
virtual void kill(QStringList& /*list*/) {};

virtual void kill(QStringList& /*list*/)
{
};
virtual void send(const QString& data, const QString& dir) =0;

signals:
Expand Down Expand Up @@ -72,5 +80,3 @@ protected slots:
};

#endif // __BASEFORM_H__


55 changes: 28 additions & 27 deletions src/sokit/clientform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#define SET_VAL_LGCLT "log_client"

ClientForm::ClientForm(QWidget* p, Qt::WindowFlags f)
:BaseForm(p, f),m_client(0)
: BaseForm(p, f), m_client(nullptr)
{
m_ui.setupUi(this);
}
Expand All @@ -28,10 +28,10 @@ bool ClientForm::initForm()
initCounter(m_ui.labRecv, m_ui.labSend);
initLogger(m_ui.chkLog, m_ui.btnClear, m_ui.treeOutput, m_ui.txtOutput);

bindBuffer(0, m_ui.edtBuf0, m_ui.btnSend0, 0);
bindBuffer(1, m_ui.edtBuf1, m_ui.btnSend1, 0);
bindBuffer(2, m_ui.edtBuf2, m_ui.btnSend2, 0);
bindBuffer(3, m_ui.edtBuf3, m_ui.btnSend3, 0);
bindBuffer(0, m_ui.edtBuf0, m_ui.btnSend0, nullptr);
bindBuffer(1, m_ui.edtBuf1, m_ui.btnSend1, nullptr);
bindBuffer(2, m_ui.edtBuf2, m_ui.btnSend2, nullptr);
bindBuffer(3, m_ui.edtBuf3, m_ui.btnSend3, nullptr);

connect(m_ui.btnTcp, SIGNAL(clicked(bool)), this, SLOT(trigger(bool)));
connect(m_ui.btnUdp, SIGNAL(clicked(bool)), this, SLOT(trigger(bool)));
Expand All @@ -42,10 +42,11 @@ bool ClientForm::initForm()
void ClientForm::initConfig()
{
QString ssc(SET_SEC_CLT);
Setting::lord(ssc+SET_KEY_CMBIP, SET_PFX_CMBITM, *m_ui.cmbAddr);
Setting::lord(ssc+SET_KEY_CMBPT, SET_PFX_CMBITM, *m_ui.cmbPort);
Setting::lord(ssc + SET_KEY_CMBIP, SET_PFX_CMBITM, *m_ui.cmbAddr);
Setting::lord(ssc + SET_KEY_CMBPT, SET_PFX_CMBITM, *m_ui.cmbPort);

QString skl(SET_SEC_DIR); skl += SET_KEY_LOG;
QString skl(SET_SEC_DIR);
skl += SET_KEY_LOG;
skl = Setting::get(skl, SET_KEY_CLT, SET_VAL_LGCLT);
setProperty(SET_SEC_DIR, skl);

Expand All @@ -55,29 +56,30 @@ void ClientForm::initConfig()
void ClientForm::saveConfig()
{
QString ssc(SET_SEC_CLT);
Setting::save(ssc+SET_KEY_CMBIP, SET_PFX_CMBITM, *m_ui.cmbAddr);
Setting::save(ssc+SET_KEY_CMBPT, SET_PFX_CMBITM, *m_ui.cmbPort);
Setting::save(ssc + SET_KEY_CMBIP, SET_PFX_CMBITM, *m_ui.cmbAddr);
Setting::save(ssc + SET_KEY_CMBPT, SET_PFX_CMBITM, *m_ui.cmbPort);

QString skl(SET_SEC_DIR); skl += SET_KEY_LOG;
QString skl(SET_SEC_DIR);
skl += SET_KEY_LOG;
Setting::set(skl, SET_KEY_CLT, property(SET_SEC_DIR).toString());
}

bool ClientForm::initHotkeys()
{
bindFocus(m_ui.cmbAddr, Qt::Key_Escape);
bindClick(m_ui.btnTcp, Qt::CTRL + Qt::Key_T);
bindClick(m_ui.btnUdp, Qt::CTRL + Qt::Key_U);
bindClick(m_ui.btnTcp, Qt::CTRL | Qt::Key_T);
bindClick(m_ui.btnUdp, Qt::CTRL | Qt::Key_U);
return true;
}

void ClientForm::unplug()
{
ClientSkt* client = 0;
ClientSkt* client = nullptr;

if (lock())
{
client = m_client;
m_client = NULL;
m_client = nullptr;
unlock();
}

Expand All @@ -87,13 +89,13 @@ void ClientForm::unplug()

void ClientForm::unpluged()
{
ClientSkt* c = qobject_cast<ClientSkt*>(sender());
auto c = qobject_cast<ClientSkt*>(sender());
if (!c) return;

if (lock())
{
if (c==m_client)
m_client = NULL;
if (c == m_client)
m_client = nullptr;

unlock();
}
Expand All @@ -114,26 +116,26 @@ void ClientForm::trigger(bool checked)
m_ui.cmbAddr->setDisabled(checked);
m_ui.cmbPort->setDisabled(checked);

QToolButton* btn = qobject_cast<QToolButton*>(sender());
if (checked && !plug(btn==m_ui.btnTcp))
auto btn = qobject_cast<QToolButton*>(sender());
if (checked && !plug(btn == m_ui.btnTcp))
btn->click();
}

bool ClientForm::plug(bool istcp)
{
ClientSkt* skt = 0;
ClientSkt* skt = nullptr;

lock();

if (m_client)
{
m_client->disconnect(this);
m_client->deleteLater();
m_client = NULL;
m_client = nullptr;
}

IPAddr addr;
bool res = TK::popIPAddr(m_ui.cmbAddr, m_ui.cmbPort, addr);
bool res = TK::popIPAddr(m_ui.cmbAddr, m_ui.cmbPort, addr);

if (res)
{
Expand All @@ -150,10 +152,11 @@ bool ClientForm::plug(bool istcp)
{
connect(m_client, SIGNAL(unpluged()), this, SLOT(unpluged()));
connect(m_client, SIGNAL(message(const QString&)), this, SIGNAL(output(const QString&)));
connect(m_client, SIGNAL(dumpbin(const QString&,const char*,quint32)), this, SIGNAL(output(const QString&,const char*,quint32)));
connect(m_client, SIGNAL(dumpbin(const QString&,const char*,quint32)), this,
SIGNAL(output(const QString&,const char*,quint32)));
connect(m_client, SIGNAL(countRecv(qint32)), this, SLOT(countRecv(qint32)));
connect(m_client, SIGNAL(countSend(qint32)), this, SLOT(countSend(qint32)));

skt = m_client;
}
}
Expand All @@ -179,5 +182,3 @@ void ClientForm::send(const QString& data, const QString&)
unlock();
}
}


Loading