-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
sinpowei
committed
Nov 18, 2010
0 parents
commit f13bf86
Showing
41 changed files
with
9,028 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
2010-11-17 sinpowei<sinpowei@gmail.com> | ||
first release version 1.0 | ||
build with QT v4.7.1 | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
sokit.lan is language file, if rename or delete it, then use default english UI | ||
|
||
F1 for more help or go http://code.google.com/p/sokit/ for sourcecode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 10.00 | ||
# Visual Studio 2008 | ||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sokit", "src\sokit\sokit.vcproj", "{862C1969-890A-44AA-BF6D-831EAA8ADD66}" | ||
EndProject | ||
Global | ||
GlobalSection(SubversionScc) = preSolution | ||
Svn-Managed = True | ||
Manager = AnkhSVN - Subversion Support for Visual Studio | ||
EndGlobalSection | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
debug|Win32 = debug|Win32 | ||
release|Win32 = release|Win32 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{862C1969-890A-44AA-BF6D-831EAA8ADD66}.debug|Win32.ActiveCfg = debug|Win32 | ||
{862C1969-890A-44AA-BF6D-831EAA8ADD66}.debug|Win32.Build.0 = debug|Win32 | ||
{862C1969-890A-44AA-BF6D-831EAA8ADD66}.release|Win32.ActiveCfg = release|Win32 | ||
{862C1969-890A-44AA-BF6D-831EAA8ADD66}.release|Win32.Build.0 = release|Win32 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
#include "toolkit.h" | ||
#include "setting.h" | ||
#include "baseform.h" | ||
|
||
#include <QShortcut> | ||
#include <QWidget> | ||
#include <QLabel> | ||
#include <QToolButton> | ||
#include <QLineEdit> | ||
#include <QTreeWidget> | ||
#include <QComboBox> | ||
#include <QListWidget> | ||
#include <QPlainTextEdit> | ||
|
||
#define PROP_EDIT "edit" | ||
#define PROP_DIRT "dirt" | ||
#define PROP_TARG "targ" | ||
|
||
BaseForm::BaseForm(QWidget* p, Qt::WFlags f) | ||
:QWidget(p, f),m_cntRecv(0),m_cntSend(0),m_cnlist(0) | ||
{ | ||
} | ||
|
||
BaseForm::~BaseForm() | ||
{ | ||
} | ||
|
||
bool BaseForm::init() | ||
{ | ||
if (!initForm() || !initHotkeys()) | ||
return false; | ||
|
||
initConfig(); | ||
|
||
m_logger.setProperty(SET_SEC_DIR, property(SET_SEC_DIR).toString()); | ||
|
||
return true; | ||
} | ||
|
||
void BaseForm::initCounter(QLabel* r, QLabel* s) | ||
{ | ||
m_cntRecv = r; | ||
m_cntSend = s; | ||
} | ||
|
||
void BaseForm::initLogger(QCheckBox* w, QToolButton* c, QTreeWidget* o, QPlainTextEdit* d) | ||
{ | ||
m_logger.init(o, w, d); | ||
|
||
connect(c, SIGNAL(released()), this, SLOT(clear())); | ||
connect(&m_logger, SIGNAL(clearLog()), this, SLOT(clear())); | ||
|
||
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); | ||
|
||
sl->setProperty(PROP_TARG, qVariantFromValue((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))); | ||
} | ||
|
||
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); | ||
|
||
connect(sk, SIGNAL(activated()), this, SLOT(kill())); | ||
connect(sa, SIGNAL(activated()), m_cnlist, SLOT(selectAll())); | ||
|
||
connect(k, SIGNAL(released()), this, SLOT(kill())); | ||
connect(a, SIGNAL(released()), m_cnlist, SLOT(selectAll())); | ||
|
||
bindFocus(m_cnlist, Qt::Key_F2); | ||
} | ||
|
||
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)); | ||
|
||
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); | ||
} | ||
|
||
void BaseForm::bindFocus(QWidget* w, qint32 k) | ||
{ | ||
QShortcut* s = new QShortcut(QKeySequence(k), this); | ||
s->setProperty(PROP_TARG, qVariantFromValue((void*)w)); | ||
connect(s, SIGNAL(activated()), this, SLOT(focus())); | ||
} | ||
|
||
void BaseForm::bindClick(QAbstractButton* b, qint32 k) | ||
{ | ||
QShortcut* 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)); | ||
s->setObjectName(QString::number(i)); | ||
|
||
connect(s, SIGNAL(activated()), this, SLOT(select())); | ||
} | ||
|
||
void BaseForm::focus() | ||
{ | ||
QWidget* w = (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*>(); | ||
if (t) | ||
{ | ||
t->setFocus(Qt::TabFocusReason); | ||
t->selectAll(); | ||
} | ||
} | ||
|
||
void BaseForm::select() | ||
{ | ||
QComboBox* b = (QComboBox*)sender()->property(PROP_TARG).value<void*>(); | ||
if (b && b->isEnabled()) | ||
{ | ||
qint32 i = sender()->objectName().toInt(); | ||
if (i < 0) | ||
{ | ||
i = b->currentIndex() + 1; | ||
if (i >= b->count()) i = 0; | ||
} | ||
|
||
b->setCurrentIndex(i); | ||
} | ||
} | ||
|
||
void BaseForm::countRecv(quint32 bytes) | ||
{ | ||
m_cntRecv->setText(QString::number(bytes)); | ||
} | ||
|
||
void BaseForm::countSend(quint32 bytes) | ||
{ | ||
m_cntSend->setText(QString::number(bytes)); | ||
} | ||
|
||
void BaseForm::send() | ||
{ | ||
QLineEdit* e = (QLineEdit*)sender()->property(PROP_EDIT).value<void*>(); | ||
QComboBox* d = (QComboBox*)sender()->property(PROP_DIRT).value<void*>(); | ||
if (e) | ||
send(e->text(), (d?d->currentText():"")); | ||
} | ||
|
||
void BaseForm::clear() | ||
{ | ||
m_logger.clear(); | ||
|
||
lock(); | ||
m_cntRecv->setText("0"); | ||
m_cntSend->setText("0"); | ||
unlock(); | ||
} | ||
|
||
void BaseForm::kill() | ||
{ | ||
if (lock(1000)) | ||
{ | ||
QStringList list; | ||
|
||
listerSelected(list); | ||
kill(list); | ||
|
||
unlock(); | ||
} | ||
} | ||
|
||
void BaseForm::listerSelected(QStringList& output) | ||
{ | ||
qint32 i = m_cnlist->count(); | ||
while (i--) | ||
{ | ||
QListWidgetItem* itm = m_cnlist->item(i); | ||
if (itm && itm->isSelected()) | ||
output << itm->text(); | ||
} | ||
} | ||
|
||
void BaseForm::listerAdd(const QString& caption) | ||
{ | ||
listerRemove(caption); | ||
m_cnlist->addItem(caption); | ||
} | ||
|
||
void BaseForm::listerRemove(const QString& caption) | ||
{ | ||
qint32 i = m_cnlist->count(); | ||
while (i--) | ||
{ | ||
QListWidgetItem* itm = m_cnlist->item(i); | ||
if (itm && itm->text()==caption) | ||
delete m_cnlist->takeItem(i); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#ifndef __BASEFORM_H__ | ||
#define __BASEFORM_H__ | ||
|
||
#include <QMutex> | ||
#include "logger.h" | ||
|
||
class QLabel; | ||
class QListWidget; | ||
class BaseForm : public QWidget | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
BaseForm(QWidget* p=0, Qt::WFlags f=0); | ||
virtual ~BaseForm(); | ||
|
||
bool init(); | ||
|
||
protected: | ||
bool lock() { m_door.lock(); return true; }; | ||
bool lock(qint32 w) { return m_door.tryLock(w); }; | ||
void unlock() { m_door.unlock(); }; | ||
|
||
void initCounter(QLabel* r, QLabel* s); | ||
void initLogger(QCheckBox* w, QToolButton* c, QTreeWidget* o, QPlainTextEdit* d); | ||
void initLister(QToolButton* a, QToolButton* k, QListWidget* l); | ||
void bindBuffer(qint32 id, QLineEdit* e, QToolButton* s, QComboBox* d); | ||
void bindFocus(QWidget* w, qint32 k); | ||
void bindClick(QAbstractButton* b, qint32 k); | ||
void bindSelect(QComboBox* b, qint32 i, qint32 k); | ||
|
||
void listerSelected(QStringList& output); | ||
|
||
virtual bool initForm() =0; | ||
virtual bool initHotkeys() =0; | ||
virtual void initConfig() =0; | ||
virtual void saveConfig() =0; | ||
virtual void kill(QStringList& list) {}; | ||
virtual void send(const QString& data, const QString& dir) =0; | ||
|
||
signals: | ||
void output(const QString& info); | ||
void output(const QString& title, const char* buf, quint32 len); | ||
|
||
protected slots: | ||
void send(); | ||
void kill(); | ||
void clear(); | ||
void focus(); | ||
void select(); | ||
void hotOutput(); | ||
|
||
void countRecv(quint32 bytes); | ||
void countSend(quint32 bytes); | ||
|
||
void listerAdd(const QString& caption); | ||
void listerRemove(const QString& caption); | ||
|
||
private: | ||
QMutex m_door; | ||
Logger m_logger; | ||
|
||
QLabel* m_cntRecv; | ||
QLabel* m_cntSend; | ||
|
||
QListWidget* m_cnlist; | ||
}; | ||
|
||
#endif // __BASEFORM_H__ | ||
|
||
|
Oops, something went wrong.