Skip to content

Commit 5167005

Browse files
1 parent 65945ab commit 5167005

18 files changed

+92
-52
lines changed

src/sokit/baseform.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include <QMutex>
55
#include "logger.h"
6+
#include <QToolButton>
7+
#include <QComboBox>
68

79
class QLabel;
810
class QListWidget;
@@ -35,7 +37,7 @@ class BaseForm : public QWidget
3537
virtual bool initHotkeys() =0;
3638
virtual void initConfig() =0;
3739
virtual void saveConfig() =0;
38-
virtual void kill(QStringList& list) {};
40+
virtual void kill(QStringList& /*list*/) {};
3941
virtual void send(const QString& data, const QString& dir) =0;
4042

4143
signals:

src/sokit/clientform.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#define SET_KEY_CMBIP "/ip"
1010
#define SET_KEY_CMBPT "/port"
1111

12-
#define SET_VAL_LGCLT "./log_client"
12+
#define SET_VAL_LGCLT "log_client"
1313

1414
ClientForm::ClientForm(QWidget* p, Qt::WFlags f)
1515
:BaseForm(p, f),m_client(0)

src/sokit/clientform.ui

+2-8
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,13 @@
165165
</property>
166166
<property name="minimumSize">
167167
<size>
168-
<width>60</width>
168+
<width>75</width>
169169
<height>24</height>
170170
</size>
171171
</property>
172172
<property name="maximumSize">
173173
<size>
174-
<width>60</width>
174+
<width>75</width>
175175
<height>24</height>
176176
</size>
177177
</property>
@@ -589,12 +589,6 @@
589589
<attribute name="headerStretchLastSection">
590590
<bool>true</bool>
591591
</attribute>
592-
<attribute name="headerVisible">
593-
<bool>false</bool>
594-
</attribute>
595-
<attribute name="headerStretchLastSection">
596-
<bool>true</bool>
597-
</attribute>
598592
<column>
599593
<property name="text">
600594
<string notr="true">1</string>

src/sokit/helpform.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "toolkit.h"
1+
#include "toolkit.h"
22
#include "setting.h"
33
#include "helpform.h"
44

src/sokit/helpform.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#ifndef __HELPFORM_H__
1+
#ifndef __HELPFORM_H__
22
#define __HELPFORM_H__
33

44
#include "ui_helpform.h"

src/sokit/helpform.ui

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ p, li { white-space: pre-wrap; }
5353
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-weight:400; font-style:normal;&quot;&gt;
5454
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;sokit&lt;/span&gt;&lt;/p&gt;
5555
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; &quot;&gt;&lt;/p&gt;
56-
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; &quot;&gt;freeware version: 1.0 (GPLv3)&lt;/span&gt;&lt;/p&gt;
56+
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; &quot;&gt;freeware version: 1.2 (GPLv3)&lt;/span&gt;&lt;/p&gt;
5757
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; &quot;&gt;website: http://code.google.com/p/sokit/&lt;/span&gt;&lt;/p&gt;
5858
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; &quot;&gt;email: [email protected]&lt;/span&gt;&lt;/p&gt;
5959
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; &quot;&gt;&lt;/p&gt;

src/sokit/logger.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#define SET_MAX_LOGTRM 30
1515

1616
Logger::Logger(QObject *parent)
17-
: QObject(parent),m_treeOut(0),m_textOut(0),m_chkWrite(0)
17+
: QObject(parent),m_chkWrite(0),m_treeOut(0),m_textOut(0)
1818
{
1919
}
2020

@@ -56,7 +56,7 @@ void Logger::init(QTreeWidget* o, QCheckBox* w, QPlainTextEdit* d)
5656

5757
QAction* all = new QAction(tr("Select All"), this);
5858
all->setShortcuts(QKeySequence::SelectAll);
59-
connect(all, SIGNAL(triggered()), m_textOut, SIGNAL(selectAll()));
59+
connect(all, SIGNAL(triggered()), m_textOut, SLOT(selectAll()));
6060

6161
m_cmlog.addAction(copy);
6262
m_cmlog.addSeparator();
@@ -124,7 +124,7 @@ const QString Logger::getLogFileName()
124124
}
125125
}
126126

127-
m_dir = property(SET_SEC_DIR).toString();
127+
m_dir = Setting::path() + "/" + property(SET_SEC_DIR).toString();
128128
}
129129

130130
return (i==2) ? QString() : m_dir + QDir::separator() +
@@ -246,4 +246,4 @@ void Logger::output(const QString& title, const char* buf, quint32 len)
246246
out << '\n' << hex << '\n' << '\n';
247247

248248
writeLogFile(lab);
249-
}
249+
}

src/sokit/main.cpp

+26-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <QTabWidget>
1+
#include <QTabWidget>
22
#include <QShortcut>
33
#include <QFontDatabase>
44

@@ -56,6 +56,29 @@ void Sokit::initDefaultActionsName()
5656
translate("QTextControl", "Select All");
5757
}
5858

59+
bool Sokit::initTranslator()
60+
{
61+
QString file = Setting::get(SET_SEC_CFG, SET_KEY_LANG, SET_VAL_LANG);
62+
63+
QStringList paths;
64+
paths << "."
65+
<< "../share/" SET_APP_NAME
66+
<< "../share/apps/" SET_APP_NAME
67+
<< Setting::path();
68+
69+
foreach (QString p, paths)
70+
{
71+
if (m_trans.load(file, p, "", SET_VAL_LANX))
72+
{
73+
installTranslator(&m_trans);
74+
Setting::set(SET_SEC_CFG, SET_KEY_LANG, file);
75+
break;
76+
}
77+
}
78+
79+
return true;
80+
}
81+
5982
void Sokit::initFont()
6083
{
6184
QFontDatabase db;
@@ -111,21 +134,14 @@ void Sokit::initFont()
111134

112135
bool Sokit::initUI()
113136
{
114-
QString file = Setting::get(SET_SEC_CFG, SET_KEY_LANG, SET_VAL_LANG);
115-
116-
if (m_trans.load(file, ".", "", SET_VAL_LANX))
117-
{
118-
installTranslator(&m_trans);
119-
Setting::set(SET_SEC_CFG, SET_KEY_LANG, file);
120-
}
121-
137+
initTranslator();
122138
initFont();
123139

124140
HelpForm* h = new HelpForm(&m_wnd, Qt::WindowCloseButtonHint);
125141

126142
QShortcut* k = new QShortcut(QKeySequence(Qt::Key_F1), &m_wnd);
127143
QShortcut* t = new QShortcut(QKeySequence(Qt::Key_F10), &m_wnd);
128-
connect(k, SIGNAL(activated()), h, SLOT(open()));
144+
connect(k, SIGNAL(activated()), h, SLOT(exec()));
129145
connect(t, SIGNAL(activated()), this, SLOT(ontop()));
130146

131147
m_wnd.setWindowTitle(translate("Sokit", "sokit -- F1 for help"));

src/sokit/main.h

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class Sokit :public QApplication
1313
Sokit(int& argc, char** argv);
1414
~Sokit();
1515

16+
bool initTranslator();
1617
bool initUI();
1718
void show();
1819
void close();

src/sokit/notepadform.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <QShortcut>
99
#include <QTabWidget>
1010

11-
#define SET_NP_FILE "./sokit.txt"
11+
#define SET_NP_FILE "sokit.txt"
1212

1313
NotepadForm::NotepadForm(QWidget* p, Qt::WFlags f)
1414
:QWidget(p, f)
@@ -53,7 +53,7 @@ void NotepadForm::setupUi()
5353

5454
bool NotepadForm::init()
5555
{
56-
QFile file(SET_NP_FILE);
56+
QFile file(Setting::path() + "/" + SET_NP_FILE);
5757

5858
if (file.open(QIODevice::ReadOnly|QIODevice::Text))
5959
{
@@ -68,7 +68,7 @@ bool NotepadForm::init()
6868

6969
void NotepadForm::uninit()
7070
{
71-
QFile file(SET_NP_FILE);
71+
QFile file(Setting::path() + "/" + SET_NP_FILE);
7272

7373
if (file.open(QIODevice::WriteOnly|QIODevice::Text|QIODevice::Truncate))
7474
{

src/sokit/serverform.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#define SET_KEY_CMBTP "/tport"
1313
#define SET_KEY_CMBUP "/uport"
1414

15-
#define SET_VAL_LGSVR "./log_server"
15+
#define SET_VAL_LGSVR "log_server"
1616

1717
ServerForm::ServerForm(QWidget *parent, Qt::WFlags flags)
1818
: BaseForm(parent, flags)

src/sokit/serverform.ui

+6-6
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
</property>
111111
<property name="minimumSize">
112112
<size>
113-
<width>62</width>
113+
<width>70</width>
114114
<height>0</height>
115115
</size>
116116
</property>
@@ -169,13 +169,13 @@
169169
</property>
170170
<property name="minimumSize">
171171
<size>
172-
<width>60</width>
172+
<width>75</width>
173173
<height>24</height>
174174
</size>
175175
</property>
176176
<property name="maximumSize">
177177
<size>
178-
<width>60</width>
178+
<width>75</width>
179179
<height>24</height>
180180
</size>
181181
</property>
@@ -197,7 +197,7 @@
197197
</property>
198198
<property name="minimumSize">
199199
<size>
200-
<width>62</width>
200+
<width>70</width>
201201
<height>0</height>
202202
</size>
203203
</property>
@@ -272,13 +272,13 @@
272272
</property>
273273
<property name="minimumSize">
274274
<size>
275-
<width>60</width>
275+
<width>75</width>
276276
<height>24</height>
277277
</size>
278278
</property>
279279
<property name="maximumSize">
280280
<size>
281-
<width>60</width>
281+
<width>75</width>
282282
<height>24</height>
283283
</size>
284284
</property>

src/sokit/setting.cpp

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,37 @@
11
#include <QComboBox>
22
#include <QSettings>
3+
#include <QFileInfo>
4+
#include <QDir>
35

46
#include "setting.h"
57

8+
Setting::Setting()
9+
{
10+
QString path(QDir::currentPath());
11+
if (!QFileInfo(path).isWritable() ||
12+
path == QDir::homePath ())
13+
{
14+
QDir dir(QDir::home());
15+
dir.mkdir("." SET_APP_NAME);
16+
if (dir.cd("." SET_APP_NAME))
17+
path = dir.absolutePath();
18+
}
19+
20+
QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, path);
21+
}
22+
623
QSettings& Setting::storage()
724
{
8-
static QSettings g_settings(SET_CONF_FILE, QSettings::IniFormat);
25+
static Setting dummy; // to ensure call QSettings::setPath before create the g_settings
26+
static QSettings g_settings(QSettings::IniFormat, QSettings::UserScope, SET_APP_NAME);
927
return g_settings;
1028
}
1129

30+
QString Setting::path()
31+
{
32+
return QFileInfo(storage().fileName()).dir().absolutePath();
33+
}
34+
1235
void Setting::flush()
1336
{
1437
storage().sync();

src/sokit/setting.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef __SETTING_H__
22
#define __SETTING_H__
33

4-
#define SET_CONF_FILE "./sokit.ini"
4+
#define SET_APP_NAME "sokit"
55

66
#define SET_MAX_CMBITM 10
77
#define SET_PFX_CMBITM "item"
@@ -19,12 +19,14 @@ class Setting
1919
static void set(const QString& section, const QString& key, const QString& val);
2020
static QString get(const QString& section, const QString& key, const QString& def);
2121

22+
static QString path();
2223
static void save(const QString& section, const QString& prefix, const QComboBox& cmb, bool all=true);
2324
static void lord(const QString& section, const QString& prefix, QComboBox& cmb, bool all=true);
2425

2526
static void flush();
26-
27+
2728
private:
29+
Setting();
2830
static QSettings& storage();
2931
};
3032

src/sokit/sokit.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ p, li { white-space: pre-wrap; }
102102
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-weight:400; font-style:normal;&quot;&gt;
103103
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;sokit&lt;/span&gt;&lt;/p&gt;
104104
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; &quot;&gt;&lt;/p&gt;
105-
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; &quot;&gt;freeware version: 1.0 (GPLv3)&lt;/span&gt;&lt;/p&gt;
105+
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; &quot;&gt;freeware version: 1.2 (GPLv3)&lt;/span&gt;&lt;/p&gt;
106106
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; &quot;&gt;website: http://code.google.com/p/sokit/&lt;/span&gt;&lt;/p&gt;
107107
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; &quot;&gt;email: [email protected]&lt;/span&gt;&lt;/p&gt;
108108
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; &quot;&gt;&lt;/p&gt;
@@ -164,7 +164,7 @@ p, li { white-space: pre-wrap; }
164164
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; ; font-weight:400; font-style:normal;&quot;&gt;
165165
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;sokit&lt;/span&gt;&lt;/p&gt;
166166
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;/p&gt;
167-
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;freeware version: 1.0 (GPLv3)&lt;/p&gt;
167+
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;freeware version: 1.2 (GPLv3)&lt;/p&gt;
168168
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;website: http://code.google.com/p/sokit/&lt;/p&gt;
169169
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;email: [email protected]&lt;/p&gt;
170170
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;/p&gt;
@@ -429,12 +429,12 @@ p, li { white-space: pre-wrap; }
429429
<context>
430430
<name>Sokit</name>
431431
<message>
432-
<location filename="main.cpp" line="73"/>
432+
<location filename="main.cpp" line="96"/>
433433
<source>font</source>
434-
<translation type="unfinished">Microsoft YaHei,10;微软雅黑,10;宋体,9;SimSun,9</translation>
434+
<translation type="unfinished">Microsoft YaHei,10;微软雅黑,10;WenQuanYi Micro Hei,11;文泉驿微米黑,11;DejaVu Sans,11;WenQuanYi Zen Hei,10;文泉驿正黑,10;宋体,9;SimSun,9;FangSong,11.5;AR PL UMing CN,10.5;</translation>
435435
</message>
436436
<message>
437-
<location filename="main.cpp" line="131"/>
437+
<location filename="main.cpp" line="147"/>
438438
<source>sokit -- F1 for help</source>
439439
<translation type="unfinished">sokit -- F1获取帮助</translation>
440440
</message>

src/sokit/toolkit.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ QString TK::ascii2hex(const QString& src, QVector<uint>& posmap, uint& count)
120120
case OUT: status = OUT2IN; break;
121121
case OUT2IN: status = OUT; break;
122122
case IN: status = ERR; break;
123+
case ERR: break;
123124
}
124125

125126
if (OUT2IN == status)
@@ -306,6 +307,7 @@ bool TK::ascii2bin(const QString& src, QByteArray& dst, QString& err)
306307
case OUT: status = OUT2IN; break;
307308
case OUT2IN: status = OUT; break;
308309
case IN: status = ERR; break;
310+
case ERR: break;
309311
}
310312

311313
if (OUT2IN == status)

src/sokit/transferform.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#define SET_KEY_CMBSP "/srcport"
1313
#define SET_KEY_CMBDP "/dstport"
1414

15-
#define SET_VAL_LGTAN "./log_transf"
15+
#define SET_VAL_LGTAN "log_transf"
1616

1717
#define PROP_EDIT "edit"
1818
#define PROP_DIRT "dirt"

0 commit comments

Comments
 (0)