├── Console ├── Console.cpp ├── Console.h ├── console.ui ├── pty.cpp ├── pty.h ├── winpty.h └── winpty_constants.h ├── KConfig ├── QKconfig.cpp ├── QKconfig.h ├── confdata.c ├── expr.c ├── expr.h ├── images.c ├── list.h ├── lkc.h ├── lkc_proto.h ├── menu.c ├── qconf.cpp ├── qconf.h ├── symbol.c ├── util.c ├── zconf.hash.c ├── zconf.lex.c └── zconf.tab.c ├── Modem ├── Modem.cpp ├── Modem.h ├── Ymodem.cpp ├── Ymodem.h ├── crc.h ├── crc16.c └── modem.ui ├── NetAssist ├── NetAssist.cpp ├── NetAssist.h └── NetAssist.ui ├── NewSession ├── KconfigSetting.cpp ├── KconfigSetting.h ├── KconfigSetting.ui ├── NetAssistSetting.cpp ├── NetAssistSetting.h ├── NetAssistSetting.ui ├── NewSession.cpp ├── NewSession.h ├── NewSession.ui ├── SerialSetting.cpp ├── SerialSetting.h ├── SerialSetting.ui ├── SessionWindow.cpp ├── SessionWindow.h ├── Setting.cpp ├── Setting.h ├── TelnetSetting.cpp ├── TelnetSetting.h ├── TelnetSetting.ui └── nstypes.h ├── QSuperTerm.pro ├── QTermWidget ├── QTermScreen.cpp ├── QTermScreen.h ├── QTermWidget.cpp └── QTermWidget.h ├── README.md ├── SendSave ├── SSWorker.cpp ├── SSWorker.h ├── SendSave.cpp ├── SendSave.h └── SendSave.ui ├── Serial ├── SerialTerm.cpp ├── SerialTerm.h └── SerialTerm.ui ├── SuperTerm ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── projectfile.cpp └── projectfile.h ├── Telnet ├── TelnetTerm.cpp ├── TelnetTerm.h ├── TelnetTerm.ui ├── qttelnet.cpp └── qttelnet.h ├── images ├── application-exit.png ├── clear.png ├── connect.png ├── disconnect.png └── settings.png ├── simple.pro ├── simple ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── settingsdialog.cpp ├── settingsdialog.h ├── settingsdialog.ui └── terminal.qrc ├── test ├── dialog.cpp ├── dialog.h ├── dialog.ui ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui └── test.pro ├── winpty-agent.exe └── winpty.dll /Console/Console.cpp: -------------------------------------------------------------------------------- 1 | #include "Console.h" 2 | #include "ui_console.h" 3 | 4 | #include "QTermWidget/QTermWidget.h" 5 | #include 6 | #include 7 | 8 | #include "pty.h" 9 | 10 | Console::Console(QWidget *parent) : 11 | QMainWindow(parent), 12 | ui(new Ui::Console), 13 | pty(NULL) 14 | { 15 | ui->setupUi(this); 16 | 17 | term = new QTermWidget; 18 | setCentralWidget(term); 19 | 20 | connect(term, SIGNAL(outData(QByteArray)), 21 | this, SLOT(writePty(QByteArray))); 22 | } 23 | 24 | Console::~Console() 25 | { 26 | delete ui; 27 | delete pty; 28 | } 29 | 30 | void Console::writePty(const QByteArray &data) 31 | { 32 | if (pty) 33 | { 34 | pty->write(data); 35 | } 36 | } 37 | 38 | void Console::readPty() 39 | { 40 | QByteArray buf; 41 | 42 | buf = pty->readAll(); 43 | 44 | term->putData(buf); 45 | } 46 | 47 | void Console::setSettings(SesParam &parm, QString id) 48 | { 49 | QString sh = getenv("ComSpec"); 50 | 51 | startShell(sh); 52 | } 53 | 54 | void Console::startShell(QString fullpath, QString arg) 55 | { 56 | if (pty == NULL) 57 | { 58 | pty = new Pty; 59 | 60 | connect(pty, SIGNAL(readyRead()), 61 | this, SLOT(readPty())); 62 | 63 | pty->start(fullpath, arg); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Console/Console.h: -------------------------------------------------------------------------------- 1 | #ifndef CONSOLE_H 2 | #define CONSOLE_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class Console; 8 | } 9 | 10 | class QTermWidget; 11 | class QProcess; 12 | class Pty; 13 | 14 | #include "NewSession/Setting.h" 15 | 16 | class Console : public QMainWindow 17 | { 18 | Q_OBJECT 19 | 20 | public: 21 | explicit Console(QWidget *parent = 0); 22 | ~Console(); 23 | 24 | void setSettings(SesParam &parm, QString id); 25 | 26 | private slots: 27 | void readPty(); 28 | void writePty(const QByteArray &data); 29 | 30 | private: 31 | void startShell(QString fullpath, QString arg = ""); 32 | 33 | private: 34 | Ui::Console *ui; 35 | QTermWidget *term; 36 | QProcess *child; 37 | Pty *pty; 38 | }; 39 | 40 | #endif // CONSOLE_H 41 | -------------------------------------------------------------------------------- /Console/console.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Console 6 | 7 | 8 | 9 | 0 10 | 0 11 | 800 12 | 600 13 | 14 | 15 | 16 | MainWindow 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Console/pty.cpp: -------------------------------------------------------------------------------- 1 | #include "pty.h" 2 | #include 3 | 4 | Pty::Pty(QObject *parent) : QObject(parent) 5 | { 6 | wpty = NULL; 7 | memset(&rov, 0, sizeof(rov)); 8 | connect(this, &_queRR, this, &pendRR, 9 | Qt::QueuedConnection); 10 | } 11 | 12 | Pty::~Pty() 13 | { 14 | winpty_free(wpty); 15 | } 16 | 17 | bool Pty::start(QString name, QString args = "") 18 | { 19 | std::wstring program, cmdline; 20 | 21 | program = name.toStdWString(); 22 | cmdline = args.toStdWString(); 23 | 24 | auto agentCfg = winpty_config_new(0, nullptr); 25 | 26 | wpty = winpty_open(agentCfg, nullptr); 27 | 28 | winpty_config_free(agentCfg); 29 | 30 | conin = CreateFileW(winpty_conin_name(wpty), GENERIC_WRITE, 31 | 0, nullptr, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, nullptr); 32 | conout = CreateFileW(winpty_conout_name(wpty), GENERIC_READ, 33 | 0, nullptr, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, nullptr); 34 | 35 | auto spawnCfg = winpty_spawn_config_new( 36 | WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN, 37 | program.data(), 38 | cmdline.data(), 39 | nullptr, nullptr, nullptr); 40 | 41 | BOOL spawnSuccess = winpty_spawn( 42 | wpty, spawnCfg, nullptr, nullptr, nullptr, nullptr); 43 | 44 | inbuf.reserve(256); 45 | rov.Pointer = this; 46 | ReadFileEx(conout, inbuf.data(), 256, &rov, (LPOVERLAPPED_COMPLETION_ROUTINE)readFileComp); 47 | 48 | return (bool)spawnSuccess; 49 | } 50 | 51 | void Pty::readFileComp(DWORD err, DWORD len, OVERLAPPED *ov) 52 | { 53 | Pty *self = (Pty*)ov->Pointer; 54 | 55 | self->rxsize = len; 56 | emit self->_queRR(); 57 | } 58 | 59 | int Pty::write(const QByteArray &buf) 60 | { 61 | DWORD len = 0; 62 | 63 | WriteFile(conin, buf.data(), buf.size(), &len, NULL); 64 | 65 | return len; 66 | } 67 | 68 | void Pty::pendRR() 69 | { 70 | emit readyRead(); 71 | } 72 | 73 | QByteArray Pty::readAll() 74 | { 75 | QByteArray ret; 76 | 77 | ret.resize(rxsize); 78 | memcpy(ret.data(), inbuf.data(), rxsize); 79 | 80 | memset(&rov, 0, sizeof(rov)); 81 | rov.Pointer = this; 82 | ReadFileEx(conout, inbuf.data(), 256, &rov, readFileComp); 83 | 84 | return ret; 85 | } 86 | 87 | -------------------------------------------------------------------------------- /Console/pty.h: -------------------------------------------------------------------------------- 1 | #ifndef PTY_H 2 | #define PTY_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "winpty.h" 9 | 10 | class Pty : public QObject 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit Pty(QObject *parent = 0); 16 | ~Pty(); 17 | 18 | bool start(QString name, QString args); 19 | QByteArray readAll(); 20 | int write(const QByteArray &buf); 21 | 22 | signals: 23 | void readyRead(); 24 | void _queRR(); 25 | 26 | private: 27 | static void __stdcall readFileComp(DWORD err, DWORD len, OVERLAPPED *ov); 28 | void pendRR(); 29 | 30 | private: 31 | winpty_t *wpty; 32 | HANDLE conin; 33 | HANDLE conout; 34 | HANDLE conerr; 35 | OVERLAPPED rov; 36 | QByteArray inbuf; 37 | DWORD rxsize; 38 | }; 39 | 40 | #endif // PTY_H 41 | -------------------------------------------------------------------------------- /Console/winpty_constants.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Ryan Prichard 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to 6 | * deal in the Software without restriction, including without limitation the 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 8 | * sell copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20 | * IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef WINPTY_CONSTANTS_H 24 | #define WINPTY_CONSTANTS_H 25 | 26 | /* 27 | * You may want to include winpty.h instead, which includes this header. 28 | * 29 | * This file is split out from winpty.h so that the agent can access the 30 | * winpty flags without also declaring the libwinpty APIs. 31 | */ 32 | 33 | /***************************************************************************** 34 | * Error codes. */ 35 | 36 | #define WINPTY_ERROR_SUCCESS 0 37 | #define WINPTY_ERROR_OUT_OF_MEMORY 1 38 | #define WINPTY_ERROR_SPAWN_CREATE_PROCESS_FAILED 2 39 | #define WINPTY_ERROR_LOST_CONNECTION 3 40 | #define WINPTY_ERROR_AGENT_EXE_MISSING 4 41 | #define WINPTY_ERROR_UNSPECIFIED 5 42 | #define WINPTY_ERROR_AGENT_DIED 6 43 | #define WINPTY_ERROR_AGENT_TIMEOUT 7 44 | #define WINPTY_ERROR_AGENT_CREATION_FAILED 8 45 | 46 | 47 | 48 | /***************************************************************************** 49 | * Configuration of a new agent. */ 50 | 51 | /* Create a new screen buffer (connected to the "conerr" terminal pipe) and 52 | * pass it to child processes as the STDERR handle. This flag also prevents 53 | * the agent from reopening CONOUT$ when it polls -- regardless of whether the 54 | * active screen buffer changes, winpty continues to monitor the original 55 | * primary screen buffer. */ 56 | #define WINPTY_FLAG_CONERR 0x1ull 57 | 58 | /* Don't output escape sequences. */ 59 | #define WINPTY_FLAG_PLAIN_OUTPUT 0x2ull 60 | 61 | /* Do output color escape sequences. These escapes are output by default, but 62 | * are suppressed with WINPTY_FLAG_PLAIN_OUTPUT. Use this flag to reenable 63 | * them. */ 64 | #define WINPTY_FLAG_COLOR_ESCAPES 0x4ull 65 | 66 | /* On XP and Vista, winpty needs to put the hidden console on a desktop in a 67 | * service window station so that its polling does not interfere with other 68 | * (visible) console windows. To create this desktop, it must change the 69 | * process' window station (i.e. SetProcessWindowStation) for the duration of 70 | * the winpty_open call. In theory, this change could interfere with the 71 | * winpty client (e.g. other threads, spawning children), so winpty by default 72 | * spawns a special agent process to create the hidden desktop. Spawning 73 | * processes on Windows is slow, though, so if 74 | * WINPTY_FLAG_ALLOW_CURPROC_DESKTOP_CREATION is set, winpty changes this 75 | * process' window station instead. 76 | * See https://github.com/rprichard/winpty/issues/58. */ 77 | #define WINPTY_FLAG_ALLOW_CURPROC_DESKTOP_CREATION 0x8ull 78 | 79 | #define WINPTY_FLAG_MASK (0ull \ 80 | | WINPTY_FLAG_CONERR \ 81 | | WINPTY_FLAG_PLAIN_OUTPUT \ 82 | | WINPTY_FLAG_COLOR_ESCAPES \ 83 | | WINPTY_FLAG_ALLOW_CURPROC_DESKTOP_CREATION \ 84 | ) 85 | 86 | /* QuickEdit mode is initially disabled, and the agent does not send mouse 87 | * mode sequences to the terminal. If it receives mouse input, though, it 88 | * still writes MOUSE_EVENT_RECORD values into CONIN. */ 89 | #define WINPTY_MOUSE_MODE_NONE 0 90 | 91 | /* QuickEdit mode is initially enabled. As CONIN enters or leaves mouse 92 | * input mode (i.e. where ENABLE_MOUSE_INPUT is on and ENABLE_QUICK_EDIT_MODE 93 | * is off), the agent enables or disables mouse input on the terminal. 94 | * 95 | * This is the default mode. */ 96 | #define WINPTY_MOUSE_MODE_AUTO 1 97 | 98 | /* QuickEdit mode is initially disabled, and the agent enables the terminal's 99 | * mouse input mode. It does not disable terminal mouse mode (until exit). */ 100 | #define WINPTY_MOUSE_MODE_FORCE 2 101 | 102 | 103 | 104 | /***************************************************************************** 105 | * winpty agent RPC call: process creation. */ 106 | 107 | /* If the spawn is marked "auto-shutdown", then the agent shuts down console 108 | * output once the process exits. The agent stops polling for new console 109 | * output, and once all pending data has been written to the output pipe, the 110 | * agent closes the pipe. (At that point, the pipe may still have data in it, 111 | * which the client may read. Once all the data has been read, further reads 112 | * return EOF.) */ 113 | #define WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN 1ull 114 | 115 | /* After the agent shuts down output, and after all output has been written 116 | * into the pipe(s), exit the agent by closing the console. If there any 117 | * surviving processes still attached to the console, they are killed. 118 | * 119 | * Note: With this flag, an RPC call (e.g. winpty_set_size) issued after the 120 | * agent exits will fail with an I/O or dead-agent error. */ 121 | #define WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN 2ull 122 | 123 | /* All the spawn flags. */ 124 | #define WINPTY_SPAWN_FLAG_MASK (0ull \ 125 | | WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN \ 126 | | WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN \ 127 | ) 128 | 129 | 130 | 131 | #endif /* WINPTY_CONSTANTS_H */ 132 | -------------------------------------------------------------------------------- /KConfig/QKconfig.cpp: -------------------------------------------------------------------------------- 1 | #include "QKconfig.h" 2 | 3 | void fixup_rootmenu(struct menu *menu, int *menu_cnt) 4 | { 5 | struct menu *child; 6 | 7 | *menu_cnt ++; 8 | menu->flags |= MENU_ROOT; 9 | for (child = menu->list; child; child = child->next) 10 | { 11 | if (child->prompt && child->prompt->type == P_MENU) 12 | { 13 | fixup_rootmenu(child, menu_cnt); 14 | } 15 | else if (!menu_cnt) 16 | fixup_rootmenu(child, menu_cnt); 17 | } 18 | 19 | *menu_cnt --; 20 | } 21 | 22 | static void msgRecv_cb(struct msg_out *mo, int type, const char *fmt, va_list ap) 23 | { 24 | QKconfig *c = (QKconfig *)mo->obj; 25 | QString str; 26 | 27 | str = str.vsprintf(fmt, ap); 28 | emit c->msgOut(str); 29 | } 30 | 31 | QKconfig::QKconfig(QObject *parent) : QObject(parent) 32 | { 33 | memset(&kcm, 0, sizeof(kcm)); 34 | 35 | moveToThread(&worker); 36 | 37 | connect(this, SIGNAL(parseReq(QString)), this, SLOT(parseDo(QString)), 38 | Qt::QueuedConnection); 39 | 40 | worker.start(); 41 | 42 | kcm.msgout.print = msgRecv_cb; 43 | kcm.msgout.obj = this; 44 | } 45 | 46 | void QKconfig::parseDo(QString name) 47 | { 48 | int err; 49 | 50 | err = conf_parse(name.toStdString().c_str(), &kcm); 51 | 52 | conf_read(NULL, &kcm); 53 | 54 | emit parseDone(err); 55 | } 56 | 57 | kcmenu_t* QKconfig::getMenu() 58 | { 59 | return &kcm; 60 | } 61 | 62 | bool QKconfig::writeConfig(QString name) 63 | { 64 | return conf_write(name.toStdString().c_str(), &kcm) == 0; 65 | } 66 | 67 | void QKconfig::putEnv(QString &env) 68 | { 69 | QStringList list; 70 | 71 | list = env.split(","); 72 | for (int i = 0; i < list.size(); i ++) 73 | { 74 | putenv(list.at(i).toStdString().c_str()); 75 | } 76 | } 77 | 78 | bool QKconfig::isChanged() 79 | { 80 | return conf_get_changed(&kcm); 81 | } 82 | -------------------------------------------------------------------------------- /KConfig/QKconfig.h: -------------------------------------------------------------------------------- 1 | #ifndef QKCONFIG_H 2 | #define QKCONFIG_H 3 | 4 | #include 5 | #include 6 | #include "lkc.h" 7 | 8 | class QKconfig : public QObject 9 | { 10 | Q_OBJECT 11 | 12 | public: 13 | explicit QKconfig(QObject *parent = 0); 14 | 15 | kcmenu_t* getMenu(); 16 | 17 | bool writeConfig(QString name = ""); 18 | bool isChanged(); 19 | void putEnv(QString &env); 20 | 21 | signals: 22 | void parseReq(QString name); 23 | 24 | signals: 25 | void parseDone(int err); 26 | void msgOut(QString str); 27 | 28 | public slots: 29 | void parseDo(QString name); 30 | 31 | private: 32 | QThread worker; 33 | kcmenu_t kcm; 34 | }; 35 | 36 | #endif // QKCONFIG_H 37 | -------------------------------------------------------------------------------- /KConfig/expr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2002 Roman Zippel 3 | * Released under the terms of the GNU GPL v2.0. 4 | */ 5 | 6 | #ifndef EXPR_H 7 | #define EXPR_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | #include 14 | #include 15 | #include "list.h" 16 | #ifndef __cplusplus 17 | #include 18 | #endif 19 | 20 | struct file { 21 | struct file *next; 22 | struct file *parent; 23 | const char *name; 24 | int lineno; 25 | }; 26 | 27 | typedef enum tristate { 28 | no, mod, yes 29 | } tristate; 30 | 31 | enum expr_type { 32 | E_NONE, E_OR, E_AND, E_NOT, 33 | E_EQUAL, E_UNEQUAL, E_LTH, E_LEQ, E_GTH, E_GEQ, 34 | E_LIST, E_SYMBOL, E_RANGE 35 | }; 36 | 37 | union expr_data { 38 | struct expr *expr; 39 | struct symbol *sym; 40 | }; 41 | 42 | struct expr { 43 | enum expr_type type; 44 | union expr_data left, right; 45 | }; 46 | 47 | #define EXPR_OR(dep1, dep2) (((dep1)>(dep2))?(dep1):(dep2)) 48 | #define EXPR_AND(dep1, dep2) (((dep1)<(dep2))?(dep1):(dep2)) 49 | #define EXPR_NOT(dep) (2-(dep)) 50 | 51 | #define expr_list_for_each_sym(l, e, s) \ 52 | for (e = (l); e && (s = e->right.sym); e = e->left.expr) 53 | 54 | struct expr_value { 55 | struct expr *expr; 56 | tristate tri; 57 | }; 58 | 59 | struct symbol_value { 60 | void *val; 61 | tristate tri; 62 | }; 63 | 64 | enum symbol_type { 65 | S_UNKNOWN, S_BOOLEAN, S_TRISTATE, S_INT, S_HEX, S_STRING, S_OTHER 66 | }; 67 | 68 | /* enum values are used as index to symbol.def[] */ 69 | enum { 70 | S_DEF_USER, /* main user value */ 71 | S_DEF_AUTO, /* values read from auto.conf */ 72 | S_DEF_DEF3, /* Reserved for UI usage */ 73 | S_DEF_DEF4, /* Reserved for UI usage */ 74 | S_DEF_COUNT 75 | }; 76 | 77 | struct kcmenu; 78 | 79 | struct symbol { 80 | struct symbol *next; 81 | char *name; 82 | enum symbol_type type; 83 | struct symbol_value curr; 84 | struct symbol_value def[S_DEF_COUNT]; 85 | tristate visible; 86 | int flags; 87 | struct property *prop; 88 | struct expr_value dir_dep; 89 | struct expr_value rev_dep; 90 | struct expr_value implied; 91 | struct kcmenu *kcm; 92 | }; 93 | 94 | #define for_all_symbols(i, sym) \ 95 | for (i = 0; i < SYMBOL_HASHSIZE; i++) \ 96 | for (sym = kcm->symbol_hash[i]; sym; sym = sym->next) \ 97 | if (sym->type != S_OTHER) 98 | 99 | #define SYMBOL_CONST 0x0001 /* symbol is const */ 100 | #define SYMBOL_CHECK 0x0008 /* used during dependency checking */ 101 | #define SYMBOL_CHOICE 0x0010 /* start of a choice block (null name) */ 102 | #define SYMBOL_CHOICEVAL 0x0020 /* used as a value in a choice block */ 103 | #define SYMBOL_VALID 0x0080 /* set when symbol.curr is calculated */ 104 | #define SYMBOL_OPTIONAL 0x0100 /* choice is optional - values can be 'n' */ 105 | #define SYMBOL_WRITE 0x0200 /* write symbol to file (KCONFIG_CONFIG) */ 106 | #define SYMBOL_CHANGED 0x0400 /* ? */ 107 | #define SYMBOL_AUTO 0x1000 /* value from environment variable */ 108 | #define SYMBOL_CHECKED 0x2000 /* used during dependency checking */ 109 | #define SYMBOL_WARNED 0x8000 /* warning has been issued */ 110 | 111 | /* Set when symbol.def[] is used */ 112 | #define SYMBOL_DEF 0x10000 /* First bit of SYMBOL_DEF */ 113 | #define SYMBOL_DEF_USER 0x10000 /* symbol.def[S_DEF_USER] is valid */ 114 | #define SYMBOL_DEF_AUTO 0x20000 /* symbol.def[S_DEF_AUTO] is valid */ 115 | #define SYMBOL_DEF3 0x40000 /* symbol.def[S_DEF_3] is valid */ 116 | #define SYMBOL_DEF4 0x80000 /* symbol.def[S_DEF_4] is valid */ 117 | 118 | /* choice values need to be set before calculating this symbol value */ 119 | #define SYMBOL_NEED_SET_CHOICE_VALUES 0x100000 120 | 121 | /* Set symbol to y if allnoconfig; used for symbols that hide others */ 122 | #define SYMBOL_ALLNOCONFIG_Y 0x200000 123 | 124 | #define SYMBOL_MAXLENGTH 256 125 | #define SYMBOL_HASHSIZE 9973 126 | 127 | /* A property represent the config options that can be associated 128 | * with a config "symbol". 129 | * Sample: 130 | * config FOO 131 | * default y 132 | * prompt "foo prompt" 133 | * select BAR 134 | * config BAZ 135 | * int "BAZ Value" 136 | * range 1..255 137 | */ 138 | enum prop_type { 139 | P_UNKNOWN, 140 | P_PROMPT, /* prompt "foo prompt" or "BAZ Value" */ 141 | P_COMMENT, /* text associated with a comment */ 142 | P_MENU, /* prompt associated with a menuconfig option */ 143 | P_DEFAULT, /* default y */ 144 | P_CHOICE, /* choice value */ 145 | P_SELECT, /* select BAR */ 146 | P_IMPLY, /* imply BAR */ 147 | P_RANGE, /* range 7..100 (for a symbol) */ 148 | P_ENV, /* value from environment variable */ 149 | P_SYMBOL, /* where a symbol is defined */ 150 | }; 151 | 152 | struct property { 153 | struct property *next; /* next property - null if last */ 154 | struct symbol *sym; /* the symbol for which the property is associated */ 155 | enum prop_type type; /* type of property */ 156 | const char *text; /* the prompt value - P_PROMPT, P_MENU, P_COMMENT */ 157 | struct expr_value visible; 158 | struct expr *expr; /* the optional conditional part of the property */ 159 | struct menu *menu; /* the menu the property are associated with 160 | * valid for: P_SELECT, P_RANGE, P_CHOICE, 161 | * P_PROMPT, P_DEFAULT, P_MENU, P_COMMENT */ 162 | struct file *file; /* what file was this property defined */ 163 | int lineno; /* what lineno was this property defined */ 164 | }; 165 | 166 | #define for_all_properties(sym, st, tok) \ 167 | for (st = sym->prop; st; st = st->next) \ 168 | if (st->type == (tok)) 169 | #define for_all_defaults(sym, st) for_all_properties(sym, st, P_DEFAULT) 170 | #define for_all_choices(sym, st) for_all_properties(sym, st, P_CHOICE) 171 | #define for_all_prompts(sym, st) \ 172 | for (st = sym->prop; st; st = st->next) \ 173 | if (st->text) 174 | 175 | struct menu { 176 | struct menu *next; 177 | struct menu *parent; 178 | struct menu *list; 179 | struct symbol *sym; 180 | struct property *prompt; 181 | struct expr *visibility; 182 | struct expr *dep; 183 | unsigned int flags; 184 | char *help; 185 | struct file *file; 186 | int lineno; 187 | void *data; 188 | }; 189 | 190 | #define MENU_CHANGED 0x0001 191 | #define MENU_ROOT 0x0002 192 | 193 | struct jump_key { 194 | struct list_head entries; 195 | size_t offset; 196 | struct menu *target; 197 | int index; 198 | }; 199 | 200 | #define JUMP_NB 9 201 | 202 | struct msg_out; 203 | 204 | typedef void (*msgprint_t)(struct msg_out *mo, int type, const char *fmt, va_list ap); 205 | struct msg_out 206 | { 207 | msgprint_t print; 208 | void *obj; 209 | }; 210 | 211 | typedef struct kcmenu 212 | { 213 | struct menu root; 214 | 215 | struct menu **last_entry_ptr; 216 | struct file *file_list; 217 | struct menu *current_entry; 218 | struct menu *current_menu; 219 | void *yyscanner; 220 | struct expr *sym_env_list; 221 | struct symbol *sym_defconfig_list; 222 | tristate modules_val; 223 | struct symbol *modules_sym; 224 | struct symbol *symbol_hash[SYMBOL_HASHSIZE]; 225 | int sym_change_count; 226 | struct msg_out msgout; 227 | int zconfnerrs; 228 | }kcmenu_t; 229 | 230 | struct file *lookup_file(const char *name); 231 | 232 | extern struct symbol symbol_yes, symbol_no, symbol_mod; 233 | 234 | struct expr *expr_alloc_symbol(struct symbol *sym); 235 | struct expr *expr_alloc_one(enum expr_type type, struct expr *ce); 236 | struct expr *expr_alloc_two(enum expr_type type, struct expr *e1, struct expr *e2); 237 | struct expr *expr_alloc_comp(enum expr_type type, struct symbol *s1, struct symbol *s2); 238 | struct expr *expr_alloc_and(struct expr *e1, struct expr *e2); 239 | struct expr *expr_alloc_or(struct expr *e1, struct expr *e2); 240 | struct expr *expr_copy(const struct expr *org); 241 | void expr_free(struct expr *e); 242 | void expr_eliminate_eq(struct expr **ep1, struct expr **ep2); 243 | tristate expr_calc_value(struct expr *e); 244 | struct expr *expr_trans_bool(struct expr *e); 245 | struct expr *expr_eliminate_dups(struct expr *e); 246 | struct expr *expr_transform(struct expr *e); 247 | int expr_contains_symbol(struct expr *dep, struct symbol *sym); 248 | bool expr_depends_symbol(struct expr *dep, struct symbol *sym); 249 | struct expr *expr_trans_compare(struct expr *e, enum expr_type type, struct symbol *sym); 250 | struct expr *expr_simplify_unmet_dep(struct expr *e1, struct expr *e2); 251 | 252 | void expr_fprint(struct expr *e, FILE *out); 253 | struct gstr; /* forward */ 254 | void expr_gstr_print(struct expr *e, struct gstr *gs); 255 | 256 | static inline int expr_is_yes(struct expr *e) 257 | { 258 | return !e || (e->type == E_SYMBOL && e->left.sym == &symbol_yes); 259 | } 260 | 261 | static inline int expr_is_no(struct expr *e) 262 | { 263 | return e && (e->type == E_SYMBOL && e->left.sym == &symbol_no); 264 | } 265 | 266 | #ifdef __cplusplus 267 | } 268 | #endif 269 | 270 | #endif /* EXPR_H */ 271 | -------------------------------------------------------------------------------- /KConfig/images.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2002 Roman Zippel 3 | * Released under the terms of the GNU GPL v2.0. 4 | */ 5 | 6 | static const char *xpm_load[] = { 7 | "22 22 5 1", 8 | ". c None", 9 | "# c #000000", 10 | "c c #838100", 11 | "a c #ffff00", 12 | "b c #ffffff", 13 | "......................", 14 | "......................", 15 | "......................", 16 | "............####....#.", 17 | "...........#....##.##.", 18 | "..................###.", 19 | ".................####.", 20 | ".####...........#####.", 21 | "#abab##########.......", 22 | "#babababababab#.......", 23 | "#ababababababa#.......", 24 | "#babababababab#.......", 25 | "#ababab###############", 26 | "#babab##cccccccccccc##", 27 | "#abab##cccccccccccc##.", 28 | "#bab##cccccccccccc##..", 29 | "#ab##cccccccccccc##...", 30 | "#b##cccccccccccc##....", 31 | "###cccccccccccc##.....", 32 | "##cccccccccccc##......", 33 | "###############.......", 34 | "......................"}; 35 | 36 | static const char *xpm_save[] = { 37 | "22 22 5 1", 38 | ". c None", 39 | "# c #000000", 40 | "a c #838100", 41 | "b c #c5c2c5", 42 | "c c #cdb6d5", 43 | "......................", 44 | ".####################.", 45 | ".#aa#bbbbbbbbbbbb#bb#.", 46 | ".#aa#bbbbbbbbbbbb#bb#.", 47 | ".#aa#bbbbbbbbbcbb####.", 48 | ".#aa#bbbccbbbbbbb#aa#.", 49 | ".#aa#bbbccbbbbbbb#aa#.", 50 | ".#aa#bbbbbbbbbbbb#aa#.", 51 | ".#aa#bbbbbbbbbbbb#aa#.", 52 | ".#aa#bbbbbbbbbbbb#aa#.", 53 | ".#aa#bbbbbbbbbbbb#aa#.", 54 | ".#aaa############aaa#.", 55 | ".#aaaaaaaaaaaaaaaaaa#.", 56 | ".#aaaaaaaaaaaaaaaaaa#.", 57 | ".#aaa#############aa#.", 58 | ".#aaa#########bbb#aa#.", 59 | ".#aaa#########bbb#aa#.", 60 | ".#aaa#########bbb#aa#.", 61 | ".#aaa#########bbb#aa#.", 62 | ".#aaa#########bbb#aa#.", 63 | "..##################..", 64 | "......................"}; 65 | 66 | static const char *xpm_back[] = { 67 | "22 22 3 1", 68 | ". c None", 69 | "# c #000083", 70 | "a c #838183", 71 | "......................", 72 | "......................", 73 | "......................", 74 | "......................", 75 | "......................", 76 | "...........######a....", 77 | "..#......##########...", 78 | "..##...####......##a..", 79 | "..###.###.........##..", 80 | "..######..........##..", 81 | "..#####...........##..", 82 | "..######..........##..", 83 | "..#######.........##..", 84 | "..########.......##a..", 85 | "...............a###...", 86 | "...............###....", 87 | "......................", 88 | "......................", 89 | "......................", 90 | "......................", 91 | "......................", 92 | "......................"}; 93 | 94 | static const char *xpm_tree_view[] = { 95 | "22 22 2 1", 96 | ". c None", 97 | "# c #000000", 98 | "......................", 99 | "......................", 100 | "......#...............", 101 | "......#...............", 102 | "......#...............", 103 | "......#...............", 104 | "......#...............", 105 | "......########........", 106 | "......#...............", 107 | "......#...............", 108 | "......#...............", 109 | "......#...............", 110 | "......#...............", 111 | "......########........", 112 | "......#...............", 113 | "......#...............", 114 | "......#...............", 115 | "......#...............", 116 | "......#...............", 117 | "......########........", 118 | "......................", 119 | "......................"}; 120 | 121 | static const char *xpm_single_view[] = { 122 | "22 22 2 1", 123 | ". c None", 124 | "# c #000000", 125 | "......................", 126 | "......................", 127 | "..........#...........", 128 | "..........#...........", 129 | "..........#...........", 130 | "..........#...........", 131 | "..........#...........", 132 | "..........#...........", 133 | "..........#...........", 134 | "..........#...........", 135 | "..........#...........", 136 | "..........#...........", 137 | "..........#...........", 138 | "..........#...........", 139 | "..........#...........", 140 | "..........#...........", 141 | "..........#...........", 142 | "..........#...........", 143 | "..........#...........", 144 | "..........#...........", 145 | "......................", 146 | "......................"}; 147 | 148 | static const char *xpm_split_view[] = { 149 | "22 22 2 1", 150 | ". c None", 151 | "# c #000000", 152 | "......................", 153 | "......................", 154 | "......#......#........", 155 | "......#......#........", 156 | "......#......#........", 157 | "......#......#........", 158 | "......#......#........", 159 | "......#......#........", 160 | "......#......#........", 161 | "......#......#........", 162 | "......#......#........", 163 | "......#......#........", 164 | "......#......#........", 165 | "......#......#........", 166 | "......#......#........", 167 | "......#......#........", 168 | "......#......#........", 169 | "......#......#........", 170 | "......#......#........", 171 | "......#......#........", 172 | "......................", 173 | "......................"}; 174 | 175 | static const char *xpm_symbol_no[] = { 176 | "12 12 2 1", 177 | " c white", 178 | ". c black", 179 | " ", 180 | " .......... ", 181 | " . . ", 182 | " . . ", 183 | " . . ", 184 | " . . ", 185 | " . . ", 186 | " . . ", 187 | " . . ", 188 | " . . ", 189 | " .......... ", 190 | " "}; 191 | 192 | static const char *xpm_symbol_mod[] = { 193 | "12 12 2 1", 194 | " c white", 195 | ". c black", 196 | " ", 197 | " .......... ", 198 | " . . ", 199 | " . . ", 200 | " . .. . ", 201 | " . .... . ", 202 | " . .... . ", 203 | " . .. . ", 204 | " . . ", 205 | " . . ", 206 | " .......... ", 207 | " "}; 208 | 209 | static const char *xpm_symbol_yes[] = { 210 | "12 12 2 1", 211 | " c white", 212 | ". c black", 213 | " ", 214 | " .......... ", 215 | " . . ", 216 | " . . ", 217 | " . . . ", 218 | " . .. . ", 219 | " . . .. . ", 220 | " . .... . ", 221 | " . .. . ", 222 | " . . ", 223 | " .......... ", 224 | " "}; 225 | 226 | static const char *xpm_choice_no[] = { 227 | "12 12 2 1", 228 | " c white", 229 | ". c black", 230 | " ", 231 | " .... ", 232 | " .. .. ", 233 | " . . ", 234 | " . . ", 235 | " . . ", 236 | " . . ", 237 | " . . ", 238 | " . . ", 239 | " .. .. ", 240 | " .... ", 241 | " "}; 242 | 243 | static const char *xpm_choice_yes[] = { 244 | "12 12 2 1", 245 | " c white", 246 | ". c black", 247 | " ", 248 | " .... ", 249 | " .. .. ", 250 | " . . ", 251 | " . .. . ", 252 | " . .... . ", 253 | " . .... . ", 254 | " . .. . ", 255 | " . . ", 256 | " .. .. ", 257 | " .... ", 258 | " "}; 259 | 260 | static const char *xpm_menu[] = { 261 | "12 12 2 1", 262 | " c white", 263 | ". c black", 264 | " ", 265 | " .......... ", 266 | " . . ", 267 | " . .. . ", 268 | " . .... . ", 269 | " . ...... . ", 270 | " . ...... . ", 271 | " . .... . ", 272 | " . .. . ", 273 | " . . ", 274 | " .......... ", 275 | " "}; 276 | 277 | static const char *xpm_menu_inv[] = { 278 | "12 12 2 1", 279 | " c white", 280 | ". c black", 281 | " ", 282 | " .......... ", 283 | " .......... ", 284 | " .. ...... ", 285 | " .. .... ", 286 | " .. .. ", 287 | " .. .. ", 288 | " .. .... ", 289 | " .. ...... ", 290 | " .......... ", 291 | " .......... ", 292 | " "}; 293 | 294 | static const char *xpm_menuback[] = { 295 | "12 12 2 1", 296 | " c white", 297 | ". c black", 298 | " ", 299 | " .......... ", 300 | " . . ", 301 | " . .. . ", 302 | " . .... . ", 303 | " . ...... . ", 304 | " . ...... . ", 305 | " . .... . ", 306 | " . .. . ", 307 | " . . ", 308 | " .......... ", 309 | " "}; 310 | 311 | static const char *xpm_void[] = { 312 | "12 12 2 1", 313 | " c white", 314 | ". c black", 315 | " ", 316 | " ", 317 | " ", 318 | " ", 319 | " ", 320 | " ", 321 | " ", 322 | " ", 323 | " ", 324 | " ", 325 | " ", 326 | " "}; 327 | -------------------------------------------------------------------------------- /KConfig/list.h: -------------------------------------------------------------------------------- 1 | #ifndef LIST_H 2 | #define LIST_H 3 | 4 | /* 5 | * Copied from include/linux/... 6 | */ 7 | 8 | #undef offsetof 9 | #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) 10 | 11 | /** 12 | * container_of - cast a member of a structure out to the containing structure 13 | * @ptr: the pointer to the member. 14 | * @type: the type of the container struct this is embedded in. 15 | * @member: the name of the member within the struct. 16 | * 17 | */ 18 | #define container_of(ptr, type, member) ({ \ 19 | const typeof( ((type *)0)->member ) *__mptr = (ptr); \ 20 | (type *)( (char *)__mptr - offsetof(type,member) );}) 21 | 22 | 23 | struct list_head { 24 | struct list_head *next, *prev; 25 | }; 26 | 27 | 28 | #define LIST_HEAD_INIT(name) { &(name), &(name) } 29 | 30 | #define LIST_HEAD(name) \ 31 | struct list_head name = LIST_HEAD_INIT(name) 32 | 33 | /** 34 | * list_entry - get the struct for this entry 35 | * @ptr: the &struct list_head pointer. 36 | * @type: the type of the struct this is embedded in. 37 | * @member: the name of the list_head within the struct. 38 | */ 39 | #define list_entry(ptr, type, member) \ 40 | container_of(ptr, type, member) 41 | 42 | /** 43 | * list_for_each_entry - iterate over list of given type 44 | * @pos: the type * to use as a loop cursor. 45 | * @head: the head for your list. 46 | * @member: the name of the list_head within the struct. 47 | */ 48 | #define list_for_each_entry(pos, head, member) \ 49 | for (pos = list_entry((head)->next, typeof(*pos), member); \ 50 | &pos->member != (head); \ 51 | pos = list_entry(pos->member.next, typeof(*pos), member)) 52 | 53 | /** 54 | * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry 55 | * @pos: the type * to use as a loop cursor. 56 | * @n: another type * to use as temporary storage 57 | * @head: the head for your list. 58 | * @member: the name of the list_head within the struct. 59 | */ 60 | #define list_for_each_entry_safe(pos, n, head, member) \ 61 | for (pos = list_entry((head)->next, typeof(*pos), member), \ 62 | n = list_entry(pos->member.next, typeof(*pos), member); \ 63 | &pos->member != (head); \ 64 | pos = n, n = list_entry(n->member.next, typeof(*n), member)) 65 | 66 | /** 67 | * list_empty - tests whether a list is empty 68 | * @head: the list to test. 69 | */ 70 | static inline int list_empty(const struct list_head *head) 71 | { 72 | return head->next == head; 73 | } 74 | 75 | /* 76 | * Insert a new entry between two known consecutive entries. 77 | * 78 | * This is only for internal list manipulation where we know 79 | * the prev/next entries already! 80 | */ 81 | static inline void __list_add(struct list_head *_new, 82 | struct list_head *prev, 83 | struct list_head *next) 84 | { 85 | next->prev = _new; 86 | _new->next = next; 87 | _new->prev = prev; 88 | prev->next = _new; 89 | } 90 | 91 | /** 92 | * list_add_tail - add a new entry 93 | * @new: new entry to be added 94 | * @head: list head to add it before 95 | * 96 | * Insert a new entry before the specified head. 97 | * This is useful for implementing queues. 98 | */ 99 | static inline void list_add_tail(struct list_head *_new, struct list_head *head) 100 | { 101 | __list_add(_new, head->prev, head); 102 | } 103 | 104 | /* 105 | * Delete a list entry by making the prev/next entries 106 | * point to each other. 107 | * 108 | * This is only for internal list manipulation where we know 109 | * the prev/next entries already! 110 | */ 111 | static inline void __list_del(struct list_head *prev, struct list_head *next) 112 | { 113 | next->prev = prev; 114 | prev->next = next; 115 | } 116 | 117 | #define LIST_POISON1 ((void *) 0x00100100) 118 | #define LIST_POISON2 ((void *) 0x00200200) 119 | /** 120 | * list_del - deletes entry from list. 121 | * @entry: the element to delete from the list. 122 | * Note: list_empty() on entry does not return true after this, the entry is 123 | * in an undefined state. 124 | */ 125 | static inline void list_del(struct list_head *entry) 126 | { 127 | __list_del(entry->prev, entry->next); 128 | entry->next = (struct list_head*)LIST_POISON1; 129 | entry->prev = (struct list_head*)LIST_POISON2; 130 | } 131 | #endif 132 | -------------------------------------------------------------------------------- /KConfig/lkc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2002 Roman Zippel 3 | * Released under the terms of the GNU GPL v2.0. 4 | */ 5 | 6 | #ifndef LKC_H 7 | #define LKC_H 8 | 9 | #include "expr.h" 10 | 11 | static inline const char *gettext(const char *txt) { return txt; } 12 | static inline void textdomain(const char *domainname) {} 13 | static inline void bindtextdomain(const char *name, const char *dir) {} 14 | static inline char *bind_textdomain_codeset(const char *dn, char *c) { return c; } 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | #include "lkc_proto.h" 21 | 22 | #define SRCTREE "srctree" 23 | 24 | #ifndef PACKAGE 25 | #define PACKAGE "linux" 26 | #endif 27 | 28 | #define LOCALEDIR "/usr/share/locale" 29 | 30 | #define _(text) gettext(text) 31 | #define N_(text) (text) 32 | 33 | #ifndef CONFIG_ 34 | #define CONFIG_ "CONFIG_" 35 | #endif 36 | static inline const char *CONFIG_prefix(void) 37 | { 38 | return getenv( "CONFIG_" ) ?: CONFIG_; 39 | } 40 | #undef CONFIG_ 41 | #define CONFIG_ CONFIG_prefix() 42 | 43 | #define TF_COMMAND 0x0001 44 | #define TF_PARAM 0x0002 45 | #define TF_OPTION 0x0004 46 | 47 | enum conf_def_mode { 48 | def_default, 49 | def_yes, 50 | def_mod, 51 | def_no, 52 | def_random 53 | }; 54 | 55 | #define T_OPT_MODULES 1 56 | #define T_OPT_DEFCONFIG_LIST 2 57 | #define T_OPT_ENV 3 58 | #define T_OPT_ALLNOCONFIG_Y 4 59 | 60 | struct kconf_id { 61 | int name; 62 | int token; 63 | unsigned int flags; 64 | enum symbol_type stype; 65 | }; 66 | 67 | #define YY_TYPEDEF_YY_SCANNER_T 68 | 69 | typedef void* yyscan_t; 70 | 71 | struct file* zconf_current_file(yyscan_t yyscanner); 72 | void zconf_starthelp(yyscan_t yyscanner); 73 | FILE *zconf_fopen(const char *name); 74 | int zconf_initscan(const char *name, yyscan_t *yyscanner, struct msg_out *msgout); 75 | bool zconf_nextfile(const char *name, yyscan_t yyscanner); 76 | int zconf_lineno(yyscan_t yyscanner); 77 | const char *zconf_curname(yyscan_t yyscanner); 78 | void zconf_print_fileinfo(yyscan_t yyscanner, const char *fmt); 79 | 80 | /* confdata.c */ 81 | const char *conf_get_configname(void); 82 | const char *conf_get_autoconfig_name(void); 83 | char *conf_get_default_confname(void); 84 | void sym_add_change_count(kcmenu_t *kcm, int count); 85 | bool conf_set_all_new_symbols(enum conf_def_mode mode); 86 | void set_all_choice_values(struct symbol *csym); 87 | int conf_write(const char *name, kcmenu_t *kcm); 88 | 89 | /* confdata.c and expr.c */ 90 | static inline void xfwrite(const void *str, size_t len, size_t count, FILE *out) 91 | { 92 | assert(len != 0); 93 | 94 | if (fwrite(str, len, count, out) != count) 95 | fprintf(stderr, "Error in writing or end of file.\n"); 96 | } 97 | 98 | /* menu.c */ 99 | void _menu_init(kcmenu_t *kcm); 100 | void menu_warn(struct menu *menu, const char *fmt, ...); 101 | struct menu *menu_add_menu(kcmenu_t *kcm); 102 | void menu_end_menu(kcmenu_t *kcm); 103 | void menu_add_entry(struct symbol *sym, kcmenu_t *kcm); 104 | void menu_end_entry(void); 105 | void menu_add_dep(struct expr *dep, kcmenu_t *kcm); 106 | void menu_add_visibility(struct expr *dep, kcmenu_t *kcm); 107 | struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr *dep, kcmenu_t *kcm); 108 | void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep, kcmenu_t *kcm); 109 | void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep, kcmenu_t *kcm); 110 | void menu_add_option(int token, char *arg, kcmenu_t *kcm); 111 | void menu_finalize(struct menu *parent, kcmenu_t *kcm); 112 | void menu_set_type(int type, kcmenu_t *kcm); 113 | 114 | /* util.c */ 115 | struct file *file_lookup(const char *name, struct file **file_list); 116 | int file_write_dep(const char *name, kcmenu_t *kcm); 117 | void *xmalloc(size_t size); 118 | void *xcalloc(size_t nmemb, size_t size); 119 | 120 | struct gstr { 121 | size_t len; 122 | char *s; 123 | /* 124 | * when max_width is not zero long lines in string s (if any) get 125 | * wrapped not to exceed the max_width value 126 | */ 127 | int max_width; 128 | }; 129 | struct gstr str_new(void); 130 | void str_free(struct gstr *gs); 131 | void str_append(struct gstr *gs, const char *s); 132 | void str_printf(struct gstr *gs, const char *fmt, ...); 133 | const char *str_get(struct gstr *gs); 134 | 135 | /* symbol.c */ 136 | void sym_init(kcmenu_t *kcm); 137 | void sym_clear_all_valid(kcmenu_t *kcm); 138 | struct symbol *sym_choice_default(struct symbol *sym); 139 | const char *sym_get_string_default(struct symbol *sym); 140 | struct symbol *sym_check_deps(struct symbol *sym); 141 | struct property *prop_alloc(enum prop_type type, struct symbol *sym, kcmenu_t *kcm); 142 | struct symbol *prop_get_symbol(struct property *prop); 143 | struct property *sym_get_env_prop(struct symbol *sym); 144 | 145 | static inline tristate sym_get_tristate_value(struct symbol *sym) 146 | { 147 | return sym->curr.tri; 148 | } 149 | 150 | 151 | static inline struct symbol *sym_get_choice_value(struct symbol *sym) 152 | { 153 | return (struct symbol *)sym->curr.val; 154 | } 155 | 156 | static inline bool sym_set_choice_value(struct symbol *ch, struct symbol *chval) 157 | { 158 | return sym_set_tristate_value(chval, yes); 159 | } 160 | 161 | static inline bool sym_is_choice(struct symbol *sym) 162 | { 163 | return sym->flags & SYMBOL_CHOICE ? true : false; 164 | } 165 | 166 | static inline bool sym_is_choice_value(struct symbol *sym) 167 | { 168 | return sym->flags & SYMBOL_CHOICEVAL ? true : false; 169 | } 170 | 171 | static inline bool sym_is_optional(struct symbol *sym) 172 | { 173 | return sym->flags & SYMBOL_OPTIONAL ? true : false; 174 | } 175 | 176 | static inline bool sym_has_value(struct symbol *sym) 177 | { 178 | return sym->flags & SYMBOL_DEF_USER ? true : false; 179 | } 180 | 181 | #ifdef __cplusplus 182 | } 183 | #endif 184 | 185 | #endif /* LKC_H */ 186 | -------------------------------------------------------------------------------- /KConfig/lkc_proto.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* confdata.c */ 4 | int conf_parse(const char *name, kcmenu_t *kcm); 5 | int conf_read(const char *name, kcmenu_t *kcm); 6 | int conf_read_simple(const char *name, int, kcmenu_t *kcm); 7 | int conf_write_defconfig(const char *name); 8 | int conf_write(const char *name, kcmenu_t *kcm); 9 | int conf_write_autoconf(kcmenu_t *kcm); 10 | bool conf_get_changed(kcmenu_t *kcm); 11 | void conf_set_changed_callback(void (*fn)(void)); 12 | void conf_set_message_callback(void (*fn)(const char *fmt, va_list ap)); 13 | 14 | /* menu.c */ 15 | bool menu_is_empty(struct menu *menu); 16 | bool menu_is_visible(struct menu *menu); 17 | bool menu_has_prompt(struct menu *menu); 18 | const char * menu_get_prompt(struct menu *menu); 19 | struct menu * menu_get_root_menu(struct menu *menu); 20 | struct menu * menu_get_parent_menu(struct menu *menu, struct menu *rm); 21 | bool menu_has_help(struct menu *menu); 22 | const char * menu_get_help(struct menu *menu); 23 | struct gstr get_relations_str(struct symbol **sym_arr, struct list_head *head, kcmenu_t *kcm); 24 | void menu_get_ext_help(struct menu *menu, struct gstr *help, struct menu *root); 25 | 26 | /* symbol.c */ 27 | struct symbol * sym_lookup(const char *name, int flags, kcmenu_t *kcm); 28 | struct symbol * sym_find(const char *name); 29 | const char * sym_expand_string_value(const char *in); 30 | const char * sym_escape_string_value(const char *in); 31 | struct symbol ** sym_re_search(const char *pattern, kcmenu_t *kcm); 32 | const char * sym_type_name(enum symbol_type type); 33 | void sym_calc_value(struct symbol *sym); 34 | enum symbol_type sym_get_type(struct symbol *sym); 35 | bool sym_tristate_within_range(struct symbol *sym,tristate tri); 36 | bool sym_set_tristate_value(struct symbol *sym,tristate tri); 37 | tristate sym_toggle_tristate_value(struct symbol *sym); 38 | bool sym_string_valid(struct symbol *sym, const char *newval); 39 | bool sym_string_within_range(struct symbol *sym, const char *str); 40 | bool sym_set_string_value(struct symbol *sym, const char *newval); 41 | bool sym_is_changable(struct symbol *sym); 42 | struct property * sym_get_choice_prop(struct symbol *sym); 43 | const char * sym_get_string_value(struct symbol *sym); 44 | 45 | const char * prop_get_type_name(enum prop_type type); 46 | 47 | /* expr.c */ 48 | void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *), void *data, int prevtoken); 49 | -------------------------------------------------------------------------------- /KConfig/qconf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2002 Roman Zippel 3 | * Released under the terms of the GNU GPL v2.0. 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include "expr.h" 16 | 17 | class ConfigView; 18 | class ConfigList; 19 | class ConfigItem; 20 | class ConfigLineEdit; 21 | class ConfigMainWindow; 22 | 23 | enum colIdx 24 | { 25 | promptColIdx, nameColIdx, 26 | noColIdx, modColIdx, 27 | yesColIdx, dataColIdx, colNr 28 | }; 29 | 30 | enum listMode 31 | { 32 | singleMode, menuMode, symbolMode, 33 | fullMode, listMode 34 | }; 35 | 36 | enum optionMode 37 | { 38 | normalOpt = 0, allOpt, promptOpt 39 | }; 40 | 41 | class ConfigList : public QTreeWidget 42 | { 43 | Q_OBJECT 44 | 45 | typedef class QTreeWidget Parent; 46 | 47 | public: 48 | ConfigList(ConfigView* p, const char *name = 0); 49 | void reinit(void); 50 | ConfigView* parent(void) const 51 | { 52 | return (ConfigView*)Parent::parent(); 53 | } 54 | ConfigItem* findConfigItem(struct menu *); 55 | 56 | protected: 57 | void keyPressEvent(QKeyEvent *e); 58 | void mouseReleaseEvent(QMouseEvent *e); 59 | void mouseDoubleClickEvent(QMouseEvent *e); 60 | void focusInEvent(QFocusEvent *e); 61 | 62 | public slots: 63 | void setRootMenu(struct menu *menu); 64 | 65 | void updateList(ConfigItem *item); 66 | void setValue(ConfigItem* item, tristate val); 67 | void changeValue(ConfigItem* item); 68 | void updateSelection(void); 69 | 70 | signals: 71 | void menuChanged(struct menu *menu); 72 | void menuSelected(struct menu *menu); 73 | void parentSelected(void); 74 | void gotFocus(struct menu *); 75 | 76 | public: 77 | void updateListAll(void) 78 | { 79 | updateAll = true; 80 | updateList(NULL); 81 | updateAll = false; 82 | } 83 | ConfigList* listView() 84 | { 85 | return this; 86 | } 87 | ConfigItem* firstChild() const 88 | { 89 | return (ConfigItem *)children().first(); 90 | } 91 | void addColumn(colIdx idx) 92 | { 93 | showColumn(idx); 94 | } 95 | void removeColumn(colIdx idx) 96 | { 97 | hideColumn(idx); 98 | } 99 | void setAllOpen(bool open); 100 | void setParentMenu(menu *rm); 101 | 102 | bool menuSkip(struct menu *); 103 | 104 | void updateMenuList(ConfigItem *parent, struct menu*); 105 | void updateMenuList(ConfigList *parent, struct menu*); 106 | 107 | bool updateAll; 108 | 109 | QPixmap symbolYesPix, symbolModPix, symbolNoPix; 110 | QPixmap choiceYesPix, choiceNoPix; 111 | QPixmap menuPix, menuInvPix, menuBackPix, voidPix; 112 | 113 | enum listMode mode; 114 | enum optionMode optMode; 115 | struct menu *rootEntry, *rootMen; 116 | QPalette disabledColorGroup; 117 | QPalette inactivedColorGroup; 118 | QMenu* headerPopup; 119 | }; 120 | 121 | class ConfigItem : public QTreeWidgetItem 122 | { 123 | typedef class QTreeWidgetItem Parent; 124 | 125 | public: 126 | ConfigItem(ConfigList *parent, ConfigItem *after, struct menu *m, bool v) 127 | : Parent(parent, after), nextItem(0), menu(m), visible(v), goParent(false) 128 | { 129 | init(); 130 | } 131 | ConfigItem(ConfigItem *parent, ConfigItem *after, struct menu *m, bool v) 132 | : Parent(parent, after), nextItem(0), menu(m), visible(v), goParent(false) 133 | { 134 | init(); 135 | } 136 | ConfigItem(ConfigList *parent, ConfigItem *after, bool v) 137 | : Parent(parent, after), nextItem(0), menu(0), visible(v), goParent(true) 138 | { 139 | init(); 140 | } 141 | ~ConfigItem(void); 142 | void init(void); 143 | void okRename(int col); 144 | void updateMenu(void); 145 | void testUpdateMenu(bool v); 146 | ConfigList* listView() const 147 | { 148 | return (ConfigList*)Parent::treeWidget(); 149 | } 150 | ConfigItem* firstChild() const 151 | { 152 | return (ConfigItem *)Parent::child(0); 153 | } 154 | ConfigItem* nextSibling() 155 | { 156 | ConfigItem *ret = NULL; 157 | ConfigItem *_parent = (ConfigItem *)parent(); 158 | 159 | if(_parent) { 160 | ret = (ConfigItem *)_parent->child(_parent->indexOfChild(this)+1); 161 | } else { 162 | QTreeWidget *_treeWidget = treeWidget(); 163 | ret = (ConfigItem *)_treeWidget->topLevelItem(_treeWidget->indexOfTopLevelItem(this)+1); 164 | } 165 | 166 | return ret; 167 | } 168 | void setText(colIdx idx, const QString& text) 169 | { 170 | Parent::setText(idx, text); 171 | } 172 | QString text(colIdx idx) const 173 | { 174 | return Parent::text(idx); 175 | } 176 | void setPixmap(colIdx idx, const QIcon &icon) 177 | { 178 | Parent::setIcon(idx, icon); 179 | } 180 | const QIcon pixmap(colIdx idx) const 181 | { 182 | return icon(idx); 183 | } 184 | // TODO: Implement paintCell 185 | 186 | ConfigItem* nextItem; 187 | struct menu *menu; 188 | bool visible; 189 | bool goParent; 190 | }; 191 | 192 | class ConfigLineEdit : public QLineEdit { 193 | Q_OBJECT 194 | typedef class QLineEdit Parent; 195 | public: 196 | ConfigLineEdit(ConfigView* parent); 197 | ConfigView* parent(void) const 198 | { 199 | return (ConfigView*)Parent::parent(); 200 | } 201 | void show(ConfigItem *i); 202 | void keyPressEvent(QKeyEvent *e); 203 | 204 | public: 205 | ConfigItem *item; 206 | }; 207 | 208 | class ConfigView : public QWidget 209 | { 210 | Q_OBJECT 211 | typedef class QWidget Parent; 212 | public: 213 | ConfigView(QWidget* parent, const char *name = 0); 214 | ~ConfigView(void); 215 | void updateList(ConfigItem* item); 216 | void updateListAll(void); 217 | 218 | public: 219 | ConfigList* list; 220 | ConfigLineEdit* lineEdit; 221 | }; 222 | 223 | class ConfigInfoView : public QWidget 224 | { 225 | Q_OBJECT 226 | typedef class QWidget Parent; 227 | 228 | public: 229 | ConfigInfoView(QWidget* parent, const char *name = 0); 230 | bool showDebug(void) const { return _showDebug; } 231 | void addMsg(QString str, int type = 0); 232 | 233 | public slots: 234 | void setInfo(struct menu *menu); 235 | void setShowDebug(bool); 236 | 237 | signals: 238 | void showDebugChanged(bool); 239 | void menuSelected(struct menu *); 240 | 241 | protected: 242 | void symbolInfo(void); 243 | void menuInfo(void); 244 | QString debug_info(struct symbol *sym); 245 | static QString print_filter(const QString &str); 246 | static void expr_print_help(void *data, struct symbol *sym, const char *str); 247 | 248 | struct symbol *sym; 249 | struct menu *_menu; 250 | bool _showDebug; 251 | 252 | public: 253 | struct menu *rootMen; 254 | 255 | private: 256 | QTextBrowser *helpWin; 257 | QTextEdit *msgWin; 258 | }; 259 | 260 | class QKconfig; 261 | #include "NewSession/nstypes.h" 262 | 263 | class ConfigMainWindow : public QMainWindow 264 | { 265 | Q_OBJECT 266 | 267 | public: 268 | ConfigMainWindow(void); 269 | void parse(QString &name); 270 | void conf_changed(void); 271 | void setSettings(Session &ss); 272 | 273 | public slots: 274 | void changeMenu(struct menu *); 275 | void setMenuLink(struct menu *); 276 | void listFocusChanged(void); 277 | void goBack(void); 278 | void loadConfig(void); 279 | bool saveConfig(void); 280 | void saveConfigAs(void); 281 | 282 | void showSplitView(void); 283 | void parseDone(int err); 284 | void msgRecv(QString msg); 285 | 286 | private: 287 | void initToolBt(void); 288 | 289 | protected: 290 | void closeEvent(QCloseEvent *e); 291 | 292 | ConfigView *menuView; 293 | ConfigList *menuList; 294 | ConfigView *configView; 295 | ConfigList *configList; 296 | ConfigInfoView *helpText; 297 | 298 | QSplitter *split1; 299 | QSplitter *split2; 300 | menu *rootMen; 301 | QKconfig *worker; 302 | 303 | private: 304 | QPushButton *btLoad; 305 | QPushButton *btSave; 306 | }; 307 | -------------------------------------------------------------------------------- /KConfig/util.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2002-2005 Roman Zippel 3 | * Copyright (C) 2002-2005 Sam Ravnborg 4 | * 5 | * Released under the terms of the GNU GPL v2.0. 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include "lkc.h" 12 | 13 | /* file already present in list? If not add it */ 14 | struct file *file_lookup(const char *name, struct file **file_list) 15 | { 16 | struct file *file; 17 | const char *file_name = sym_expand_string_value(name); 18 | 19 | for (file = *file_list; file; file = file->next) { 20 | if (!strcmp(name, file->name)) { 21 | free((void *)file_name); 22 | return file; 23 | } 24 | } 25 | 26 | file = xmalloc(sizeof(*file)); 27 | memset(file, 0, sizeof(*file)); 28 | file->name = file_name; 29 | file->next = *file_list; 30 | *file_list = file; 31 | 32 | return file; 33 | } 34 | 35 | /* write a dependency file as used by kbuild to track dependencies */ 36 | int file_write_dep(const char *name, kcmenu_t *kcm) 37 | { 38 | struct symbol *sym, *env_sym; 39 | struct expr *e; 40 | struct file *file; 41 | FILE *out; 42 | 43 | if (!name) 44 | name = ".kconfig.d"; 45 | out = fopen("..config.tmp", "w"); 46 | if (!out) 47 | return 1; 48 | fprintf(out, "deps_config := \\\n"); 49 | for (file = kcm->file_list; file; file = file->next) { 50 | if (file->next) 51 | fprintf(out, "\t%s \\\n", file->name); 52 | else 53 | fprintf(out, "\t%s\n", file->name); 54 | } 55 | fprintf(out, "\n%s: \\\n" 56 | "\t$(deps_config)\n\n", conf_get_autoconfig_name()); 57 | 58 | expr_list_for_each_sym(kcm->sym_env_list, e, sym) { 59 | struct property *prop; 60 | const char *value; 61 | 62 | prop = sym_get_env_prop(sym); 63 | env_sym = prop_get_symbol(prop); 64 | if (!env_sym) 65 | continue; 66 | value = getenv(env_sym->name); 67 | if (!value) 68 | value = ""; 69 | fprintf(out, "ifneq \"$(%s)\" \"%s\"\n", env_sym->name, value); 70 | fprintf(out, "%s: FORCE\n", conf_get_autoconfig_name()); 71 | fprintf(out, "endif\n"); 72 | } 73 | 74 | fprintf(out, "\n$(deps_config): ;\n"); 75 | fclose(out); 76 | rename("..config.tmp", name); 77 | return 0; 78 | } 79 | 80 | 81 | /* Allocate initial growable string */ 82 | struct gstr str_new(void) 83 | { 84 | struct gstr gs; 85 | gs.s = xmalloc(sizeof(char) * 64); 86 | gs.len = 64; 87 | gs.max_width = 0; 88 | strcpy(gs.s, "\0"); 89 | return gs; 90 | } 91 | 92 | /* Free storage for growable string */ 93 | void str_free(struct gstr *gs) 94 | { 95 | if (gs->s) 96 | free(gs->s); 97 | gs->s = NULL; 98 | gs->len = 0; 99 | } 100 | 101 | /* Append to growable string */ 102 | void str_append(struct gstr *gs, const char *s) 103 | { 104 | size_t l; 105 | if (s) { 106 | l = strlen(gs->s) + strlen(s) + 1; 107 | if (l > gs->len) { 108 | gs->s = realloc(gs->s, l); 109 | gs->len = l; 110 | } 111 | strcat(gs->s, s); 112 | } 113 | } 114 | 115 | /* Append printf formatted string to growable string */ 116 | void str_printf(struct gstr *gs, const char *fmt, ...) 117 | { 118 | va_list ap; 119 | char s[10000]; /* big enough... */ 120 | va_start(ap, fmt); 121 | vsnprintf(s, sizeof(s), fmt, ap); 122 | str_append(gs, s); 123 | va_end(ap); 124 | } 125 | 126 | /* Retrieve value of growable string */ 127 | const char *str_get(struct gstr *gs) 128 | { 129 | return gs->s; 130 | } 131 | 132 | void *xmalloc(size_t size) 133 | { 134 | void *p = malloc(size); 135 | if (p) 136 | return p; 137 | fprintf(stderr, "Out of memory.\n"); 138 | exit(1); 139 | } 140 | 141 | void *xcalloc(size_t nmemb, size_t size) 142 | { 143 | void *p = calloc(nmemb, size); 144 | if (p) 145 | return p; 146 | fprintf(stderr, "Out of memory.\n"); 147 | exit(1); 148 | } 149 | -------------------------------------------------------------------------------- /Modem/Modem.cpp: -------------------------------------------------------------------------------- 1 | #include "Modem.h" 2 | #include "ui_modem.h" 3 | 4 | #include "Ymodem.h" 5 | 6 | #include 7 | 8 | Modem::Modem(QWidget *parent) : 9 | QDialog(parent), 10 | ui(new Ui::Modem) 11 | { 12 | ui->setupUi(this); 13 | 14 | ym = new Ymodem(this); 15 | connect(ym, SIGNAL(showTransfer(int, int, float)), this, SLOT(showTransfer(int, int, float))); 16 | connect(ym, SIGNAL(finished()), this, SLOT(closed())); 17 | } 18 | 19 | Modem::~Modem() 20 | { 21 | delete ui; 22 | } 23 | 24 | void Modem::getFile(QString &name) 25 | { 26 | name = filename; 27 | } 28 | 29 | void Modem::setFile(QString &name) 30 | { 31 | filename = name; 32 | } 33 | 34 | void Modem::showTransfer(int total, int remain, float speed) 35 | { 36 | float p; 37 | QString fmt; 38 | 39 | p = ((total - remain)/(float)total) * 100; 40 | fmt = fmt.fromLocal8Bit("%1%").arg(QString::number(p, 'f', 2)); 41 | ui->progress->setValue((int)p); 42 | ui->progress->setFormat(fmt); 43 | 44 | fmt = fmt.asprintf("速度:%.2fKB/S 剩余:%d/%dKB", 45 | speed/1024, remain/1024, total/1024); 46 | showStatus(fmt); 47 | } 48 | 49 | void Modem::startTransfer(char type) 50 | { 51 | showTransfer(1, 1, 0); 52 | show(); 53 | ym->setModemMode(type); 54 | ym->start(); 55 | } 56 | 57 | void Modem::putData(const QByteArray &data) 58 | { 59 | ym->put(data); 60 | } 61 | 62 | void Modem::showStatus(const char *s) 63 | { 64 | ui->lbmsg->setText(s); 65 | } 66 | 67 | void Modem::showStatus(QString &s) 68 | { 69 | ui->lbmsg->setText(s); 70 | } 71 | 72 | void Modem::closed() 73 | { 74 | emit exitTransfer(); 75 | } 76 | 77 | void Modem::closeEvent(QCloseEvent *event) 78 | { 79 | QMessageBox::StandardButton button; 80 | 81 | button = QMessageBox::question(this, tr("退出程序"), 82 | QString(tr("警告:任务正在运行中,是否结束操作退出?")), 83 | QMessageBox::Yes | QMessageBox::No); 84 | 85 | if (button == QMessageBox::No) 86 | { 87 | event->ignore(); //忽略退出信号,程序继续运行 88 | } 89 | else if (button == QMessageBox::Yes) 90 | { 91 | event->accept(); //接受退出信号,程序退出 92 | ym->close(); 93 | } 94 | } 95 | 96 | -------------------------------------------------------------------------------- /Modem/Modem.h: -------------------------------------------------------------------------------- 1 | #ifndef MODEM_H 2 | #define MODEM_H 3 | 4 | #include 5 | #include 6 | 7 | namespace Ui { 8 | class Modem; 9 | } 10 | 11 | class Ymodem; 12 | 13 | class Modem : public QDialog 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | explicit Modem(QWidget *parent = 0); 19 | ~Modem(); 20 | 21 | void setFile(QString &name); 22 | void getFile(QString &name); 23 | void startTransfer(char type = 'y'); 24 | void showStatus(const char *s); 25 | void showStatus(QString &s); 26 | 27 | public Q_SLOTS: 28 | void putData(const QByteArray &data); 29 | 30 | private Q_SLOTS: 31 | void showTransfer(int total, int remain, float speed); 32 | void closed(); 33 | 34 | Q_SIGNALS: 35 | void outData(const QByteArray &data); 36 | void exitTransfer(); 37 | 38 | private: 39 | void closeEvent(QCloseEvent *event); 40 | 41 | private: 42 | Ui::Modem *ui; 43 | Ymodem *ym; 44 | QString filename; 45 | }; 46 | 47 | #endif // MODEM_H 48 | -------------------------------------------------------------------------------- /Modem/Ymodem.cpp: -------------------------------------------------------------------------------- 1 | #include "Ymodem.h" 2 | #include "Modem.h" 3 | #include "crc.h" 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | Ymodem::Ymodem(Modem *parent) 10 | { 11 | isrun = false; 12 | ui = parent; 13 | mMode = 'y'; 14 | } 15 | 16 | void Ymodem::close() 17 | { 18 | isrun = false; 19 | if (!isFinished()) 20 | { 21 | wait(); 22 | } 23 | } 24 | 25 | void Ymodem::time_start() 26 | { 27 | stx_time = time(NULL); 28 | } 29 | 30 | float Ymodem::speed_clc(int total, int remain) 31 | { 32 | float s = 0; 33 | int t; 34 | 35 | t = (int)(time(NULL) - stx_time); 36 | s = (total - remain)/(float)t; 37 | 38 | return s; 39 | } 40 | 41 | void Ymodem::put(const QByteArray &data) 42 | { 43 | if (!isrun) 44 | return; 45 | 46 | for (int i = 0; i < data.size(); i ++) 47 | msgq_push(data.at(i)); 48 | } 49 | 50 | int Ymodem::makeFirstRsp(string &name, int size, QByteArray &byte) 51 | { 52 | int len = 133; 53 | ymhead_t *pkt; 54 | uint16_t *sum; 55 | 56 | byte.resize(len); 57 | sn = 0; 58 | pkt = (ymhead_t*)byte.data(); 59 | pkt->start = 0x01; 60 | pkt->sn = 0; 61 | pkt->nsn = 0xFF; 62 | memset(pkt->data, 0, sizeof(pkt->data)); 63 | strcpy(pkt->data, name.c_str()); 64 | sprintf(&pkt->data[name.size() + 1], "%d", size); 65 | 66 | sum = (uint16_t*)(((char*)pkt) + 131); 67 | *sum = crc16(pkt->data, 128); 68 | 69 | return len; 70 | } 71 | 72 | int Ymodem::makeNextRsp(char *data, int size, QByteArray &byte, int mode) 73 | { 74 | int len = 0; 75 | ymhead_t *pkt; 76 | uint16_t *sum; 77 | int fmsize; 78 | uint8_t start; 79 | 80 | if (mode == 'x') 81 | { 82 | fmsize = 128; 83 | start = 0x01; 84 | } 85 | else 86 | { 87 | fmsize = 1024; 88 | start = 0x02; 89 | } 90 | 91 | byte.resize(3 + fmsize + 2); 92 | pkt = (ymhead_t *)byte.data(); 93 | sn ++; 94 | pkt->start = start; 95 | pkt->sn = sn; 96 | pkt->nsn = 0xFF - sn; 97 | memcpy(pkt->data, data, size); 98 | if (size < fmsize) 99 | { 100 | memset(&pkt->data[size], 0, fmsize - size); 101 | } 102 | len = fmsize + 3; 103 | sum = (uint16_t*)(((char*)pkt) + len); 104 | *sum = crc16(pkt->data, fmsize); 105 | len += 2; 106 | 107 | return len; 108 | } 109 | 110 | uint16_t Ymodem::crc16(char *data, int size) 111 | { 112 | uint16_t sum; 113 | 114 | sum = crc16_ccitt(0, (uint8_t*)data, size); 115 | sum = ((sum >> 8) | (sum << 8)); 116 | 117 | return sum; 118 | } 119 | 120 | void Ymodem::msgq_push(int msg) 121 | { 122 | msgq.push(msg); 123 | } 124 | 125 | bool Ymodem::msgq_get(int &msg) 126 | { 127 | msg = 0; 128 | if (msgq.empty()) 129 | return false; 130 | 131 | msg = msgq.front(); 132 | msgq.pop(); 133 | 134 | return true; 135 | } 136 | 137 | int Ymodem::makeFinishRsp(QByteArray &byte) 138 | { 139 | int len = 133; 140 | ymhead_t *pkt; 141 | uint16_t *sum; 142 | 143 | byte.resize(len); 144 | 145 | pkt = (ymhead_t*)byte.data(); 146 | pkt->start = 0x01; 147 | pkt->sn = 0; 148 | pkt->nsn = 0xFF; 149 | memset(pkt->data, 0, sizeof(pkt->data)); 150 | 151 | sum = (uint16_t*)(byte.data() + 131); 152 | *sum = crc16(pkt->data, 128); 153 | 154 | return len; 155 | } 156 | 157 | int Ymodem::makeEotRsp(QByteArray &byte) 158 | { 159 | byte.resize(1); 160 | 161 | byte[0] = mcEOT; 162 | 163 | return 1; 164 | } 165 | 166 | void Ymodem::outData(const QByteArray &data) 167 | { 168 | emit ui->outData(data); 169 | } 170 | 171 | void Ymodem::showStatus(const char *s) 172 | { 173 | ui->showStatus(s); 174 | } 175 | 176 | void Ymodem::setModemMode(int m) 177 | { 178 | mMode = m; 179 | } 180 | 181 | void Ymodem::run() 182 | { 183 | QString filename; 184 | char fbuf[1024]; 185 | bool isread = false; 186 | QByteArray byte; 187 | int filesize = 0; 188 | QFile file; 189 | string stext; 190 | int remain = 0; 191 | int fmsize; 192 | int msg = 0; 193 | 194 | showStatus("已启动Ymodem"); 195 | ui->getFile(filename); 196 | if (filename.isEmpty()) 197 | { 198 | showStatus("错误:文件名为空"); 199 | goto err; 200 | } 201 | 202 | file.setFileName(filename); 203 | if (!file.open(QFile::ReadOnly)) 204 | { 205 | showStatus("错误:打开文件失败"); 206 | goto err; 207 | } 208 | 209 | Stage = msFirst; 210 | 211 | if (mMode == 'x') 212 | fmsize = 128; 213 | else 214 | fmsize = 1024; 215 | 216 | while (msgq_get(msg)); 217 | isrun = true; 218 | 219 | while (isrun) 220 | { 221 | msgq_get(msg); 222 | 223 | switch (Stage) 224 | { 225 | case msFirst: 226 | { 227 | switch (msg) 228 | { 229 | case mcREQ: 230 | { 231 | QFileInfo info(filename); 232 | 233 | showStatus("请求传输文件"); 234 | stext = info.fileName().toStdString(); 235 | remain = file.size(); 236 | filesize = remain; 237 | makeFirstRsp(stext, remain, byte); 238 | outData(byte); 239 | } 240 | break; 241 | case mcACK: 242 | { 243 | Stage = msReady; 244 | } 245 | break; 246 | } 247 | } 248 | break; 249 | case msReady: 250 | { 251 | switch (msg) 252 | { 253 | case mcREQ: 254 | { 255 | showStatus("请求传输数据"); 256 | Stage = msTrans; 257 | time_start(); 258 | } 259 | break; 260 | } 261 | } 262 | break; 263 | case msTrans: 264 | { 265 | if (!isread) 266 | { 267 | int size; 268 | 269 | size = file.read(fbuf, fmsize); 270 | remain -= size; 271 | makeNextRsp(fbuf, size, byte, mMode); 272 | 273 | isread = true; 274 | outData(byte); 275 | } 276 | 277 | switch (msg) 278 | { 279 | case mcACK: 280 | float speed; 281 | 282 | isread = false; 283 | speed = speed_clc(filesize, remain); 284 | emit showTransfer(filesize, remain, speed); 285 | if (remain == 0) 286 | { 287 | Stage = msEnding; 288 | msgq_push(mcACK); 289 | } 290 | break; 291 | case mcREQ: 292 | Stage = msFirst; 293 | break; 294 | } 295 | } 296 | break; 297 | case msRepeat: 298 | { 299 | outData(byte); 300 | } 301 | break; 302 | case msEnding: 303 | { 304 | switch (msg) 305 | { 306 | case mcACK: 307 | makeEotRsp(byte); 308 | outData(byte); 309 | Stage = msFinish; 310 | break; 311 | } 312 | } 313 | break; 314 | case msFinish: 315 | { 316 | switch (msg) 317 | { 318 | case mcACK: 319 | makeFinishRsp(byte); 320 | outData(byte); 321 | goto err; 322 | break; 323 | case mcNAK: 324 | makeEotRsp(byte); 325 | outData(byte); 326 | break; 327 | } 328 | } 329 | break; 330 | default: 331 | break; 332 | } 333 | 334 | msleep(10); 335 | } 336 | 337 | err: 338 | showStatus("退出Ymodem"); 339 | isrun = false; 340 | } 341 | -------------------------------------------------------------------------------- /Modem/Ymodem.h: -------------------------------------------------------------------------------- 1 | #ifndef YMODEM_H 2 | #define YMODEM_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | class Modem; 11 | 12 | class Ymodem : public QThread 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | Ymodem(Modem *parent); 18 | 19 | void close(); 20 | void put(const QByteArray &data); 21 | void setModemMode(int m); 22 | 23 | private: 24 | 25 | int makeFirstRsp(string &name, int size, QByteArray &byte); 26 | int makeNextRsp(char *data, int size, QByteArray &byte, int mode); 27 | int makeEotRsp(QByteArray &byte); 28 | int makeFinishRsp(QByteArray &byte); 29 | 30 | signals: 31 | void showTransfer(int total, int remain, float speed); 32 | 33 | private: 34 | enum modemWaitfor 35 | { 36 | mwNon = 0x00, 37 | mwReq = 0x43, 38 | mwAck = 0x06, 39 | }; 40 | 41 | enum modemStage 42 | { 43 | msFirst, 44 | msReady, 45 | msTrans, 46 | msRepeat, 47 | msEnding, 48 | msFinish, 49 | }; 50 | 51 | enum modemCode 52 | { 53 | mcSOH = 0x01, 54 | mcSTX = 0x02, 55 | mcEOT = 0x04, 56 | mcACK = 0x06, 57 | mcNAK = 0x15, 58 | mcCAN = 0x18, 59 | mcREQ = 0x43, 60 | }; 61 | 62 | typedef struct 63 | { 64 | uint8_t start; 65 | uint8_t sn; 66 | uint8_t nsn; 67 | char data[128]; 68 | //short crc; 69 | }ymhead_t; 70 | 71 | private: 72 | void run(); 73 | void msgq_push(int msg); 74 | bool msgq_get(int &msg); 75 | uint16_t crc16(char *data, int size); 76 | void time_start(); 77 | float speed_clc(int total, int remain); 78 | void outData(const QByteArray &data); 79 | void showStatus(const char *s); 80 | 81 | private: 82 | enum modemStage Stage; 83 | enum modemWaitfor Wait; 84 | bool isrun; 85 | Modem *ui; 86 | uint8_t sn; 87 | queue msgq; 88 | time_t stx_time; 89 | int mMode; 90 | }; 91 | 92 | #endif // YMODEM_H 93 | -------------------------------------------------------------------------------- /Modem/crc.h: -------------------------------------------------------------------------------- 1 | #ifndef CRC_H 2 | #define CRC_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | uint16_t crc16_ccitt(uint16_t crc_start, uint8_t *buf, int len); 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif // CRC_H 17 | -------------------------------------------------------------------------------- /Modem/crc16.c: -------------------------------------------------------------------------------- 1 | /* 2 | *========================================================================== 3 | * 4 | * crc16.c 5 | * 6 | * 16 bit CRC with polynomial x^16+x^12+x^5+1 7 | * 8 | *========================================================================== 9 | * SPDX-License-Identifier: eCos-2.0 10 | *========================================================================== 11 | *#####DESCRIPTIONBEGIN#### 12 | * 13 | * Author(s): gthomas 14 | * Contributors: gthomas,asl 15 | * Date: 2001-01-31 16 | * Purpose: 17 | * Description: 18 | * 19 | * This code is part of eCos (tm). 20 | * 21 | *####DESCRIPTIONEND#### 22 | * 23 | *========================================================================== 24 | */ 25 | 26 | #include "crc.h" 27 | 28 | /* Table of CRC constants - implements x^16+x^12+x^5+1 */ 29 | static const uint16_t crc16_tab[] = 30 | { 31 | 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 32 | 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, 33 | 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, 34 | 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, 35 | 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, 36 | 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, 37 | 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, 38 | 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, 39 | 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, 40 | 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, 41 | 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, 42 | 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, 43 | 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, 44 | 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, 45 | 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, 46 | 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, 47 | 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, 48 | 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, 49 | 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, 50 | 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, 51 | 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, 52 | 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, 53 | 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, 54 | 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, 55 | 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, 56 | 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, 57 | 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, 58 | 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, 59 | 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, 60 | 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, 61 | 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, 62 | 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0, 63 | }; 64 | 65 | uint16_t crc16_ccitt(uint16_t crc_start, uint8_t *buf, int len) 66 | { 67 | int i; 68 | uint16_t cksum; 69 | 70 | cksum = crc_start; 71 | for (i = 0; i < len; i++) 72 | cksum = crc16_tab[((cksum>>8) ^ *buf++) & 0xff] ^ (cksum << 8); 73 | 74 | return cksum; 75 | } 76 | -------------------------------------------------------------------------------- /Modem/modem.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Modem 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 300 11 | 12 | 13 | 14 | Ymodem 15 | 16 | 17 | 18 | 19 | 60 20 | 210 21 | 281 22 | 23 23 | 24 | 25 | 26 | 0 27 | 28 | 29 | %p% 30 | 31 | 32 | 33 | 34 | 35 | 10 36 | 274 37 | 351 38 | 21 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /NetAssist/NetAssist.cpp: -------------------------------------------------------------------------------- 1 | #include "NetAssist.h" 2 | #include "ui_NetAssist.h" 3 | 4 | #include "SendSave/SendSave.h" 5 | 6 | #include 7 | #include 8 | 9 | NetAssist::NetAssist(QWidget *parent) : 10 | QMainWindow(parent), 11 | ui(new Ui::NetAssist) 12 | { 13 | ui->setupUi(this); 14 | udpServer = NULL; 15 | initSendSave(); 16 | } 17 | 18 | NetAssist::~NetAssist() 19 | { 20 | delete ui; 21 | delete dlgSS; 22 | delete udpServer; 23 | } 24 | 25 | void NetAssist::setSettings(Session &ss) 26 | { 27 | QString id; 28 | 29 | netParam = ss; 30 | 31 | id = ss.id + ".dblite"; 32 | dlgSS->connectDb(id); 33 | 34 | initNet(ss); 35 | } 36 | 37 | void NetAssist::initSendSave() 38 | { 39 | dlgSS = new SendSave; 40 | 41 | statusBar()->addWidget(dlgSS->toolButton(0)); 42 | statusBar()->addWidget(dlgSS->toolButton(1)); 43 | statusBar()->addWidget(dlgSS->toolButton(2)); 44 | statusBar()->addWidget(dlgSS->toolButton(3)); 45 | 46 | connect(dlgSS, SIGNAL(outData(QByteArray)), this, SLOT(recordSend(QByteArray))); 47 | } 48 | 49 | void NetAssist::initNet(Session &ss) 50 | { 51 | QList ipAL = QNetworkInterface::allAddresses(); 52 | 53 | ui->lport->setValue(ss.param["lport"].toUShort()); 54 | ui->ptype->setText(ss.param["ptype"]); 55 | foreach (QHostAddress ip, ipAL) 56 | { 57 | bool ok; 58 | 59 | ip.toIPv4Address(&ok); 60 | if (ok) 61 | ui->lip->addItem(ip.toString()); 62 | } 63 | udpServer = new QUdpSocket(this); 64 | ui->cbrip->setCurrentText(ss.param["rhost"]); 65 | connect(udpServer, SIGNAL(readyRead()), this, SLOT(udpServerReadData())); 66 | } 67 | 68 | void NetAssist::udpServerReadData() 69 | { 70 | QHostAddress senderServerIP; 71 | quint16 senderServerPort; 72 | QByteArray data; 73 | QString buffer; 74 | 75 | do 76 | { 77 | data.resize(udpServer->pendingDatagramSize()); 78 | udpServer->readDatagram(data.data(), data.size(), &senderServerIP, &senderServerPort); 79 | 80 | buffer = data.toStdString().c_str(); 81 | ui->display->appendPlainText(buffer); 82 | } while (udpServer->hasPendingDatagrams()); 83 | } 84 | 85 | void NetAssist::recordSend(QByteArray buf) 86 | { 87 | QString str; 88 | 89 | str = buf; 90 | ui->pesend->clear(); 91 | ui->pesend->appendPlainText(str); 92 | 93 | udpSend(buf); 94 | } 95 | 96 | void NetAssist::on_open_clicked() 97 | { 98 | bool ok; 99 | uint16_t lport; 100 | 101 | if (ui->open->text() == "打开") 102 | { 103 | QHostAddress ha(ui->lip->currentText()); 104 | 105 | lport = ui->lport->text().toUShort(); 106 | udpServer->abort(); 107 | ok = udpServer->bind(ha, lport); 108 | if (ok) 109 | ui->open->setText("关闭"); 110 | } 111 | else 112 | { 113 | udpServer->abort(); 114 | ui->open->setText("打开"); 115 | } 116 | } 117 | 118 | void NetAssist::udpSend(QByteArray &buf) 119 | { 120 | QString ip, port; 121 | QStringList list; 122 | 123 | list = ui->cbrip->currentText().split(":"); 124 | ip = list.at(0); 125 | port = list.at(1); 126 | 127 | udpServer->writeDatagram(buf, QHostAddress(ip), port.toUShort()); 128 | } 129 | 130 | void NetAssist::on_rcvclear_clicked() 131 | { 132 | ui->display->clear(); 133 | } 134 | 135 | void NetAssist::on_btsend_clicked() 136 | { 137 | QByteArray buf; 138 | 139 | buf = ui->pesend->toPlainText().toStdString().c_str(); 140 | udpSend(buf); 141 | } 142 | -------------------------------------------------------------------------------- /NetAssist/NetAssist.h: -------------------------------------------------------------------------------- 1 | #ifndef NETASSIST_H 2 | #define NETASSIST_H 3 | 4 | #include 5 | #include "NewSession/nstypes.h" 6 | 7 | namespace Ui { 8 | class NetAssist; 9 | } 10 | 11 | class QUdpSocket; 12 | class SendSave; 13 | 14 | class NetAssist : public QMainWindow 15 | { 16 | Q_OBJECT 17 | 18 | public: 19 | explicit NetAssist(QWidget *parent = 0); 20 | ~NetAssist(); 21 | 22 | void setSettings(Session &ss); 23 | 24 | private slots: 25 | void on_open_clicked(); 26 | 27 | private slots: 28 | void recordSend(QByteArray buf); 29 | void udpServerReadData(); 30 | 31 | void on_rcvclear_clicked(); 32 | 33 | void on_btsend_clicked(); 34 | 35 | private: 36 | void initSendSave(); 37 | void initNet(Session &ss); 38 | void udpSend(QByteArray &buf); 39 | 40 | private: 41 | Ui::NetAssist *ui; 42 | SendSave *dlgSS; 43 | QUdpSocket *udpServer; 44 | Session netParam; 45 | int protoType; 46 | }; 47 | 48 | #endif // NETASSIST_H 49 | -------------------------------------------------------------------------------- /NetAssist/NetAssist.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | NetAssist 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 600 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 10 21 | 20 22 | 141 23 | 181 24 | 25 | 26 | 27 | 28 | 29 | 30 | 网络设置 31 | 32 | 33 | 34 | 35 | 10 36 | 50 37 | 54 38 | 12 39 | 40 | 41 | 42 | 本地地址 43 | 44 | 45 | 46 | 47 | 48 | 10 49 | 100 50 | 54 51 | 12 52 | 53 | 54 | 55 | 本地端口 56 | 57 | 58 | 59 | 60 | 61 | 30 62 | 150 63 | 75 64 | 23 65 | 66 | 67 | 68 | 打开 69 | 70 | 71 | 72 | 73 | 74 | 10 75 | 22 76 | 54 77 | 20 78 | 79 | 80 | 81 | QFrame::Box 82 | 83 | 84 | 85 | 86 | 87 | Qt::AlignCenter 88 | 89 | 90 | 91 | 92 | 93 | 10 94 | 70 95 | 111 96 | 22 97 | 98 | 99 | 100 | 101 | 102 | 103 | 10 104 | 120 105 | 111 106 | 22 107 | 108 | 109 | 110 | 65535 111 | 112 | 113 | 114 | 115 | 116 | 117 | 190 118 | 20 119 | 401 120 | 201 121 | 122 | 123 | 124 | 接收 125 | 126 | 127 | 128 | 129 | 20 130 | 20 131 | 371 132 | 371 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 10 141 | 220 142 | 131 143 | 131 144 | 145 | 146 | 147 | 接收设置 148 | 149 | 150 | 151 | 152 | 30 153 | 90 154 | 75 155 | 23 156 | 157 | 158 | 159 | 清空 160 | 161 | 162 | 163 | 164 | 165 | 166 | 210 167 | 260 168 | 371 169 | 51 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 10 179 | 10 180 | 48 181 | 12 182 | 183 | 184 | 185 | 远程主机 186 | 187 | 188 | 189 | 190 | 191 | 70 192 | 10 193 | 201 194 | 22 195 | 196 | 197 | 198 | true 199 | 200 | 201 | 202 | 203 | 204 | 280 205 | 10 206 | 75 207 | 23 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 220 219 | 330 220 | 301 221 | 71 222 | 223 | 224 | 225 | 226 | 227 | 228 | 530 229 | 350 230 | 61 231 | 23 232 | 233 | 234 | 235 | 发送 236 | 237 | 238 | 239 | 240 | 241 | 242 | 0 243 | 0 244 | 800 245 | 23 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | -------------------------------------------------------------------------------- /NewSession/KconfigSetting.cpp: -------------------------------------------------------------------------------- 1 | #include "KconfigSetting.h" 2 | #include "ui_KconfigSetting.h" 3 | 4 | #include 5 | 6 | KconfigSetting::KconfigSetting(QWidget *parent) : 7 | Setting(parent), 8 | ui(new Ui::KconfigSetting) 9 | { 10 | ui->setupUi(this); 11 | } 12 | 13 | KconfigSetting::~KconfigSetting() 14 | { 15 | delete ui; 16 | } 17 | 18 | void KconfigSetting::getSetting(SesParam &ns) 19 | { 20 | ns["file"] = ui->file->text(); 21 | ns["env"] = ui->env->text(); 22 | ns["cmd"] = ui->cmd->text(); 23 | } 24 | 25 | void KconfigSetting::on_find_clicked() 26 | { 27 | QString s = QFileDialog::getOpenFileName(this, QString("kconfig")); 28 | if (s.isEmpty()) 29 | return; 30 | 31 | ui->file->setText(s); 32 | } 33 | -------------------------------------------------------------------------------- /NewSession/KconfigSetting.h: -------------------------------------------------------------------------------- 1 | #ifndef KCONFIGSETTING_H 2 | #define KCONFIGSETTING_H 3 | 4 | #include "Setting.h" 5 | 6 | namespace Ui { 7 | class KconfigSetting; 8 | } 9 | 10 | class KconfigSetting : public Setting 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit KconfigSetting(QWidget *parent = 0); 16 | ~KconfigSetting(); 17 | 18 | void getSetting(SesParam &ns); 19 | 20 | private slots: 21 | void on_find_clicked(); 22 | 23 | private: 24 | Ui::KconfigSetting *ui; 25 | }; 26 | 27 | #endif // KCONFIGSETTING_H 28 | -------------------------------------------------------------------------------- /NewSession/KconfigSetting.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | KconfigSetting 4 | 5 | 6 | 7 | 0 8 | 0 9 | 254 10 | 197 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 20 20 | 30 21 | 54 22 | 12 23 | 24 | 25 | 26 | 文件名: 27 | 28 | 29 | 30 | 31 | 32 | 90 33 | 20 34 | 113 35 | 20 36 | 37 | 38 | 39 | 40 | 41 | 42 | 20 43 | 60 44 | 54 45 | 12 46 | 47 | 48 | 49 | 环境变量 50 | 51 | 52 | 53 | 54 | 55 | 90 56 | 50 57 | 113 58 | 20 59 | 60 | 61 | 62 | <html><head/><body><p>例:ENV1=set1,ENV2=set2</p></body></html> 63 | 64 | 65 | 66 | 67 | 68 | 20 69 | 100 70 | 54 71 | 12 72 | 73 | 74 | 75 | 用户命令 76 | 77 | 78 | 79 | 80 | 81 | 90 82 | 90 83 | 113 84 | 20 85 | 86 | 87 | 88 | 89 | 90 | 91 | 210 92 | 20 93 | 31 94 | 23 95 | 96 | 97 | 98 | .. 99 | 100 | 101 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /NewSession/NetAssistSetting.cpp: -------------------------------------------------------------------------------- 1 | #include "NetAssistSetting.h" 2 | #include "ui_NetAssistSetting.h" 3 | 4 | NetAssistSetting::NetAssistSetting(QWidget *parent) : 5 | Setting(parent), 6 | ui(new Ui::NetAssistSetting) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | NetAssistSetting::~NetAssistSetting() 12 | { 13 | delete ui; 14 | } 15 | 16 | void NetAssistSetting::getSetting(SesParam &ns) 17 | { 18 | ns["ptype"] = ui->ptype->currentText(); 19 | ns["lport"] = ui->lport->text(); 20 | ns["rhost"] = ui->rhost->text(); 21 | } 22 | -------------------------------------------------------------------------------- /NewSession/NetAssistSetting.h: -------------------------------------------------------------------------------- 1 | #ifndef NETASSISTSETTING_H 2 | #define NETASSISTSETTING_H 3 | 4 | #include "Setting.h" 5 | 6 | namespace Ui { 7 | class NetAssistSetting; 8 | } 9 | 10 | class NetAssistSetting : public Setting 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit NetAssistSetting(QWidget *parent = 0); 16 | ~NetAssistSetting(); 17 | 18 | void getSetting(SesParam &ns); 19 | 20 | private: 21 | Ui::NetAssistSetting *ui; 22 | }; 23 | 24 | #endif // NETASSISTSETTING_H 25 | -------------------------------------------------------------------------------- /NewSession/NetAssistSetting.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | NetAssistSetting 4 | 5 | 6 | 7 | 0 8 | 0 9 | 218 10 | 214 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 10 20 | 20 21 | 54 22 | 21 23 | 24 | 25 | 26 | 协议类型 27 | 28 | 29 | 30 | 31 | 32 | 70 33 | 20 34 | 71 35 | 22 36 | 37 | 38 | 39 | 40 | udp 41 | 42 | 43 | 44 | 45 | 46 | 47 | 10 48 | 52 49 | 54 50 | 20 51 | 52 | 53 | 54 | 本地端口 55 | 56 | 57 | 58 | 59 | 60 | 70 61 | 50 62 | 71 63 | 22 64 | 65 | 66 | 67 | 65535 68 | 69 | 70 | 5000 71 | 72 | 73 | 74 | 75 | 76 | 10 77 | 82 78 | 54 79 | 20 80 | 81 | 82 | 83 | 远程主机 84 | 85 | 86 | 87 | 88 | 89 | 70 90 | 80 91 | 131 92 | 20 93 | 94 | 95 | 96 | 192.168.1.199:5000 97 | 98 | 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /NewSession/NewSession.cpp: -------------------------------------------------------------------------------- 1 | #include "NewSession.h" 2 | #include "ui_NewSession.h" 3 | #include 4 | 5 | #include "SerialSetting.h" 6 | #include "TelnetSetting.h" 7 | #include "NetAssistSetting.h" 8 | 9 | NewSession::NewSession(QWidget *parent) : 10 | QDialog(parent), 11 | ui(new Ui::NewSession) 12 | { 13 | ui->setupUi(this); 14 | 15 | SerialSetting *sset = new SerialSetting; 16 | 17 | sset->setParent(ui->fmParam); 18 | ui->sesType->setCurrentRow(0); 19 | 20 | wSetting["串口终端"] = sset; 21 | wSetting["telnet"] = new TelnetSetting; 22 | wSetting["网络助手"] = new NetAssistSetting; 23 | } 24 | 25 | NewSession::~NewSession() 26 | { 27 | delete ui; 28 | wSetting.clear(); 29 | } 30 | 31 | void NewSession::getSetting(Session &s) 32 | { 33 | QString type; 34 | Setting *cur; 35 | 36 | type = ui->sesType->currentItem()->text(); 37 | cur = wSetting[type]; 38 | s.type = type; 39 | s.name = ui->sesName->text(); 40 | s.show = "1"; 41 | if (cur != NULL) 42 | { 43 | cur->getSetting(s.param); 44 | } 45 | makeID(s.id); 46 | } 47 | 48 | void NewSession::makeID(QString &id) 49 | { 50 | QDateTime dt; 51 | 52 | dt = dt.currentDateTime(); 53 | id = id.asprintf("%d", dt.toTime_t()); 54 | } 55 | 56 | void NewSession::on_sesType_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous) 57 | { 58 | Setting *cur, *pre = NULL; 59 | 60 | cur = wSetting[current->text()]; 61 | if (previous) 62 | { 63 | pre = wSetting[previous->text()]; 64 | } 65 | 66 | if (pre != NULL) 67 | { 68 | pre->hide(); 69 | } 70 | 71 | if (cur != NULL) 72 | { 73 | cur->setParent(ui->fmParam); 74 | cur->show(); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /NewSession/NewSession.h: -------------------------------------------------------------------------------- 1 | #ifndef NEWSESSION_H 2 | #define NEWSESSION_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "Setting.h" 9 | 10 | namespace Ui { 11 | class NewSession; 12 | } 13 | 14 | class NewSession : public QDialog 15 | { 16 | Q_OBJECT 17 | 18 | public: 19 | explicit NewSession(QWidget *parent = 0); 20 | ~NewSession(); 21 | 22 | void getSetting(Session &s); 23 | 24 | private: 25 | void makeID(QString &id); 26 | 27 | private slots: 28 | void on_sesType_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous); 29 | 30 | private: 31 | Ui::NewSession *ui; 32 | QMap wSetting; 33 | }; 34 | 35 | #endif // NEWSESSION_H 36 | -------------------------------------------------------------------------------- /NewSession/NewSession.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | NewSession 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 329 11 | 12 | 13 | 14 | 新建会话 15 | 16 | 17 | true 18 | 19 | 20 | 21 | 22 | 40 23 | 280 24 | 341 25 | 32 26 | 27 | 28 | 29 | Qt::Horizontal 30 | 31 | 32 | QDialogButtonBox::Cancel|QDialogButtonBox::Ok 33 | 34 | 35 | 36 | 37 | 38 | 10 39 | 50 40 | 101 41 | 141 42 | 43 | 44 | 45 | -1 46 | 47 | 48 | 49 | 串口终端 50 | 51 | 52 | 53 | 54 | telnet 55 | 56 | 57 | 58 | 59 | Console 60 | 61 | 62 | 63 | 64 | 网络助手 65 | 66 | 67 | 68 | 69 | 70 | 71 | 130 72 | 14 73 | 38 74 | 31 75 | 76 | 77 | 78 | 名称: 79 | 80 | 81 | 82 | 83 | 84 | 180 85 | 10 86 | 131 87 | 31 88 | 89 | 90 | 91 | 会话1 92 | 93 | 94 | 95 | 96 | 97 | 130 98 | 60 99 | 251 100 | 211 101 | 102 | 103 | 104 | 参数 105 | 106 | 107 | 108 | 109 | 110 | 111 | buttonBox 112 | accepted() 113 | NewSession 114 | accept() 115 | 116 | 117 | 248 118 | 254 119 | 120 | 121 | 157 122 | 274 123 | 124 | 125 | 126 | 127 | buttonBox 128 | rejected() 129 | NewSession 130 | reject() 131 | 132 | 133 | 316 134 | 260 135 | 136 | 137 | 286 138 | 274 139 | 140 | 141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /NewSession/SerialSetting.cpp: -------------------------------------------------------------------------------- 1 | #include "SerialSetting.h" 2 | #include "ui_SerialSetting.h" 3 | 4 | #include 5 | 6 | SerialSetting::SerialSetting(QWidget *parent) : 7 | Setting(parent), 8 | ui(new Ui::SerialSetting) 9 | { 10 | ui->setupUi(this); 11 | 12 | initParam(); 13 | updateDevice(); 14 | } 15 | 16 | SerialSetting::~SerialSetting() 17 | { 18 | delete ui; 19 | } 20 | 21 | void SerialSetting::initParam() 22 | { 23 | ui->speed->addItem(QStringLiteral("9600"), QSerialPort::Baud9600); 24 | ui->speed->addItem(QStringLiteral("19200"), QSerialPort::Baud19200); 25 | ui->speed->addItem(QStringLiteral("38400"), QSerialPort::Baud38400); 26 | ui->speed->addItem(QStringLiteral("115200"), QSerialPort::Baud115200); 27 | ui->speed->setCurrentIndex(3); 28 | 29 | ui->parity->addItem(QStringLiteral("None"), QSerialPort::NoParity); 30 | ui->parity->addItem(QStringLiteral("Even"), QSerialPort::EvenParity); 31 | ui->parity->addItem(QStringLiteral("Odd"), QSerialPort::OddParity); 32 | 33 | ui->stopbits->addItem(QStringLiteral("1"), QSerialPort::OneStop); 34 | ui->stopbits->addItem(QStringLiteral("2"), QSerialPort::TwoStop); 35 | } 36 | 37 | void SerialSetting::updateDevice() 38 | { 39 | QStringList list; 40 | 41 | ui->devname->clear(); 42 | 43 | list << QString(tr("刷新")); 44 | 45 | ui->devname->addItem(list.first(), list); 46 | 47 | foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) 48 | { 49 | QStringList list; 50 | 51 | list << info.portName(); 52 | 53 | ui->devname->addItem(list.first(), list); 54 | } 55 | 56 | if (ui->devname->count() != 1) 57 | { 58 | ui->devname->setCurrentIndex(1); 59 | } 60 | } 61 | 62 | void SerialSetting::getSetting(SesParam &ns) 63 | { 64 | ns["dev"] = ui->devname->currentText(); 65 | ns["speed"] = ui->speed->currentText(); 66 | } 67 | 68 | void SerialSetting::on_devname_activated(int index) 69 | { 70 | if (index == 0) 71 | { 72 | updateDevice(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /NewSession/SerialSetting.h: -------------------------------------------------------------------------------- 1 | #ifndef SERIALSETTING_H 2 | #define SERIALSETTING_H 3 | 4 | #include "Setting.h" 5 | 6 | namespace Ui { 7 | class SerialSetting; 8 | } 9 | 10 | class SerialSetting : public Setting 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit SerialSetting(QWidget *parent = 0); 16 | ~SerialSetting(); 17 | 18 | void updateDevice(); 19 | void getSetting(SesParam &ns); 20 | 21 | private slots: 22 | void on_devname_activated(int index); 23 | 24 | private: 25 | void initParam(); 26 | 27 | private: 28 | Ui::SerialSetting *ui; 29 | }; 30 | 31 | #endif // SERIALSETTING_H 32 | -------------------------------------------------------------------------------- /NewSession/SerialSetting.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | SerialSetting 4 | 5 | 6 | 7 | 0 8 | 0 9 | 239 10 | 198 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 130 20 | 20 21 | 87 22 | 22 23 | 24 | 25 | 26 | 27 | 28 | 29 | 130 30 | 60 31 | 87 32 | 22 33 | 34 | 35 | 36 | 37 | 38 | 39 | 130 40 | 100 41 | 87 42 | 22 43 | 44 | 45 | 46 | 47 | 48 | 49 | 130 50 | 140 51 | 87 52 | 22 53 | 54 | 55 | 56 | 57 | 58 | 59 | 40 60 | 30 61 | 54 62 | 12 63 | 64 | 65 | 66 | 端口 67 | 68 | 69 | 70 | 71 | 72 | 40 73 | 70 74 | 54 75 | 12 76 | 77 | 78 | 79 | 波特率 80 | 81 | 82 | 83 | 84 | 85 | 40 86 | 110 87 | 54 88 | 12 89 | 90 | 91 | 92 | 校验 93 | 94 | 95 | 96 | 97 | 98 | 40 99 | 150 100 | 54 101 | 12 102 | 103 | 104 | 105 | 停止位 106 | 107 | 108 | 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /NewSession/SessionWindow.cpp: -------------------------------------------------------------------------------- 1 | #include "SessionWindow.h" 2 | 3 | SessionWindow::SessionWindow() 4 | { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /NewSession/SessionWindow.h: -------------------------------------------------------------------------------- 1 | #ifndef SESSIONWINDOW_H 2 | #define SESSIONWINDOW_H 3 | 4 | #include 5 | 6 | #include "Setting.h" 7 | 8 | class SessionWindow : public QWidget 9 | { 10 | Q_OBJECT 11 | 12 | public: 13 | explicit SessionWindow(); 14 | 15 | virtual QWidget* getWindow() = 0; 16 | virtual void setSetting(const SesParam &ns) = 0; 17 | virtual void open() = 0; 18 | virtual void close() = 0; 19 | 20 | }; 21 | 22 | #endif // SESSIONWINDOW_H 23 | -------------------------------------------------------------------------------- /NewSession/Setting.cpp: -------------------------------------------------------------------------------- 1 | #include "Setting.h" 2 | 3 | Setting::Setting(QWidget *parent) : 4 | QWidget(parent) 5 | { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /NewSession/Setting.h: -------------------------------------------------------------------------------- 1 | #ifndef SETTING_H 2 | #define SETTING_H 3 | 4 | #include 5 | #include 6 | 7 | #include "nstypes.h" 8 | 9 | class Setting : public QWidget 10 | { 11 | Q_OBJECT 12 | public: 13 | explicit Setting(QWidget *parent = 0); 14 | 15 | virtual void getSetting(SesParam &ns) = 0; 16 | 17 | signals: 18 | 19 | public slots: 20 | }; 21 | 22 | #endif // SETTING_H 23 | -------------------------------------------------------------------------------- /NewSession/TelnetSetting.cpp: -------------------------------------------------------------------------------- 1 | #include "TelnetSetting.h" 2 | #include "ui_TelnetSetting.h" 3 | 4 | TelnetSetting::TelnetSetting(QWidget *parent) : 5 | Setting(parent), 6 | ui(new Ui::TelnetSetting) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | TelnetSetting::~TelnetSetting() 12 | { 13 | delete ui; 14 | } 15 | 16 | void TelnetSetting::getSetting(SesParam &ns) 17 | { 18 | ns["host"] = ui->host->text(); 19 | ns["port"] = ui->port->text(); 20 | } 21 | -------------------------------------------------------------------------------- /NewSession/TelnetSetting.h: -------------------------------------------------------------------------------- 1 | #ifndef TELNETSETTING_H 2 | #define TELNETSETTING_H 3 | 4 | #include "Setting.h" 5 | 6 | namespace Ui { 7 | class TelnetSetting; 8 | } 9 | 10 | class TelnetSetting : public Setting 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit TelnetSetting(QWidget *parent = 0); 16 | ~TelnetSetting(); 17 | 18 | void getSetting(SesParam &ns); 19 | 20 | private: 21 | Ui::TelnetSetting *ui; 22 | }; 23 | 24 | #endif // TELNETSETTING_H 25 | -------------------------------------------------------------------------------- /NewSession/TelnetSetting.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | TelnetSetting 4 | 5 | 6 | 7 | 0 8 | 0 9 | 229 10 | 185 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 30 20 | 30 21 | 72 22 | 15 23 | 24 | 25 | 26 | 地址: 27 | 28 | 29 | 30 | 31 | 32 | 30 33 | 110 34 | 72 35 | 15 36 | 37 | 38 | 39 | 端口: 40 | 41 | 42 | 43 | 44 | 45 | 50 46 | 60 47 | 131 48 | 21 49 | 50 | 51 | 52 | localhost 53 | 54 | 55 | 56 | 57 | 58 | 50 59 | 140 60 | 131 61 | 21 62 | 63 | 64 | 65 | 23 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /NewSession/nstypes.h: -------------------------------------------------------------------------------- 1 | #ifndef NSTYPES_H 2 | #define NSTYPES_H 3 | 4 | #include 5 | #include 6 | 7 | typedef QMap SesParam; 8 | 9 | typedef struct 10 | { 11 | QString type; 12 | QString name; 13 | QString id; 14 | QString show; 15 | 16 | SesParam param; 17 | }Session; 18 | 19 | typedef QList SesList; 20 | 21 | #endif // NSTYPES_H 22 | -------------------------------------------------------------------------------- /QSuperTerm.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2017-03-21T19:23:08 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui serialport sql network xml 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = QSuperTerm 12 | TEMPLATE = app 13 | DESTDIR = bin 14 | 15 | FORMS += \ 16 | SuperTerm/mainwindow.ui \ 17 | NewSession/NewSession.ui \ 18 | NewSession/SerialSetting.ui \ 19 | NewSession/TelnetSetting.ui \ 20 | Telnet/TelnetTerm.ui \ 21 | Serial/SerialTerm.ui \ 22 | SendSave/SendSave.ui \ 23 | Console/console.ui \ 24 | NetAssist/NetAssist.ui \ 25 | NewSession/NetAssistSetting.ui \ 26 | 27 | HEADERS += \ 28 | SuperTerm/mainwindow.h \ 29 | NewSession/NewSession.h \ 30 | NewSession/SerialSetting.h \ 31 | NewSession/Setting.h \ 32 | NewSession/TelnetSetting.h \ 33 | QTermWidget/QTermScreen.h \ 34 | QTermWidget/QTermWidget.h \ 35 | NewSession/SessionWindow.h \ 36 | Telnet/qttelnet.h \ 37 | Telnet/TelnetTerm.h \ 38 | Serial/SerialTerm.h \ 39 | SendSave/SendSave.h \ 40 | SendSave/SSWorker.h \ 41 | SuperTerm/projectfile.h \ 42 | NewSession/nstypes.h \ 43 | Console/Console.h \ 44 | Console/pty.h \ 45 | NetAssist/NetAssist.h \ 46 | NewSession/NetAssistSetting.h \ 47 | NewSession/KconfigSetting.h 48 | 49 | 50 | SOURCES += \ 51 | SuperTerm/main.cpp \ 52 | SuperTerm/mainwindow.cpp \ 53 | NewSession/NewSession.cpp \ 54 | NewSession/SerialSetting.cpp \ 55 | NewSession/Setting.cpp \ 56 | NewSession/TelnetSetting.cpp \ 57 | QTermWidget/QTermScreen.cpp \ 58 | QTermWidget/QTermWidget.cpp \ 59 | NewSession/SessionWindow.cpp \ 60 | Telnet/qttelnet.cpp \ 61 | Telnet/TelnetTerm.cpp \ 62 | Serial/SerialTerm.cpp \ 63 | SendSave/SendSave.cpp \ 64 | SendSave/SSWorker.cpp \ 65 | SuperTerm/projectfile.cpp \ 66 | Console/Console.cpp \ 67 | Console/pty.cpp \ 68 | NetAssist/NetAssist.cpp \ 69 | NewSession/NetAssistSetting.cpp \ 70 | NewSession/KconfigSetting.cpp 71 | 72 | win: 73 | { 74 | LIBS += -L$$PWD/./ -lwinpty 75 | } 76 | -------------------------------------------------------------------------------- /QTermWidget/QTermScreen.cpp: -------------------------------------------------------------------------------- 1 | #include "QTermScreen.h" 2 | 3 | #include 4 | #include 5 | 6 | QTermScreen::QTermScreen(QWidget *parent): 7 | QPlainTextEdit(parent) 8 | { 9 | QPalette p = palette(); 10 | p.setColor(QPalette::Base, Qt::black); 11 | p.setColor(QPalette::Text, Qt::white); 12 | setPalette(p); 13 | setLineWrapMode(NoWrap); 14 | 15 | bcolor = p.color(QPalette::Base); 16 | fcolor = p.color(QPalette::Text); 17 | } 18 | 19 | void QTermScreen::CursorStartOfLine() 20 | { 21 | QTextCursor tc = textCursor(); 22 | 23 | tc.movePosition(QTextCursor::StartOfBlock); 24 | setTextCursor(tc); 25 | } 26 | 27 | void QTermScreen::CursorNewLine(int n) 28 | { 29 | QTextCursor tc = textCursor(); 30 | 31 | do 32 | { 33 | tc.movePosition(QTextCursor::EndOfBlock); 34 | 35 | if (tc.atEnd()) 36 | { 37 | tc.insertBlock(); 38 | } 39 | else 40 | { 41 | tc.movePosition(QTextCursor::NextBlock); 42 | } 43 | 44 | n --; 45 | }while (n > 0); 46 | 47 | setTextCursor(tc); 48 | 49 | DisplayColor(bcolor, fcolor); 50 | } 51 | 52 | void QTermScreen::SelectRight(int n) 53 | { 54 | QTextCursor tc = textCursor(); 55 | int endpos, pos; 56 | QTextCursor tcend = textCursor(); 57 | 58 | tcend.movePosition(QTextCursor::EndOfBlock); 59 | endpos = tcend.position(); 60 | pos = tc.position(); 61 | if (pos + n > endpos) 62 | { 63 | n = endpos - pos; 64 | } 65 | if (n > 0) 66 | { 67 | tc.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, n); 68 | setTextCursor(tc); 69 | } 70 | } 71 | 72 | void QTermScreen::CursorUp(int n) 73 | { 74 | QTextCursor tc = textCursor(); 75 | 76 | tc.movePosition(QTextCursor::Up, QTextCursor::MoveAnchor, n); 77 | setTextCursor(tc); 78 | } 79 | 80 | void QTermScreen::CursorDown(int n) 81 | { 82 | QTextCursor tc = textCursor(); 83 | 84 | tc.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, n); 85 | setTextCursor(tc); 86 | } 87 | 88 | void QTermScreen::CursorLeft(int n) 89 | { 90 | QTextCursor tc = textCursor(); 91 | 92 | tc.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, n); 93 | setTextCursor(tc); 94 | } 95 | 96 | void QTermScreen::CursorRight(int n) 97 | { 98 | QTextCursor tc = textCursor(); 99 | 100 | tc.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, n); 101 | setTextCursor(tc); 102 | } 103 | 104 | void QTermScreen::CursorPosition(int row, int column) 105 | { 106 | QTextCursor tc; 107 | int lines; 108 | 109 | moveCursor(QTextCursor::End); 110 | tc = cursorForPosition(QPoint(0, 0)); 111 | lines = tc.document()->blockCount(); 112 | 113 | for (int i = 1; i < row; i ++) 114 | { 115 | if (lines == 0) 116 | { 117 | tc.movePosition(QTextCursor::EndOfBlock); 118 | tc.insertBlock(); 119 | } 120 | else 121 | { 122 | tc.movePosition(QTextCursor::NextBlock); 123 | lines --; 124 | } 125 | } 126 | 127 | for (int i = 1; i < column; i ++) 128 | { 129 | tc.movePosition(QTextCursor::Right); 130 | } 131 | 132 | setTextCursor(tc); 133 | } 134 | 135 | void QTermScreen::CursorHorizontal(int pos) 136 | { 137 | QTextCursor tc = textCursor(); 138 | int cp; 139 | 140 | tc.movePosition(QTextCursor::End); 141 | cp = tc.positionInBlock(); 142 | if (pos > cp) 143 | { 144 | QString space(pos - cp - 1, ' '); 145 | 146 | setTextCursor(tc); 147 | insertPlainText(space); 148 | } 149 | else 150 | { 151 | tc.movePosition(QTextCursor::Start); 152 | tc.setPosition(pos); 153 | setTextCursor(tc); 154 | } 155 | } 156 | 157 | void QTermScreen::DisplayForeground(QColor &color) 158 | { 159 | QTextCharFormat fmt; 160 | QTextCursor cursor = textCursor(); 161 | 162 | fmt = cursor.charFormat(); 163 | fmt.setForeground(color); 164 | 165 | cursor.setCharFormat(fmt); 166 | setTextCursor(cursor); 167 | 168 | fcolor = color; 169 | } 170 | 171 | void QTermScreen::DisplayBackground(QColor &color) 172 | { 173 | QTextCharFormat fmt; 174 | QTextCursor cursor = textCursor(); 175 | 176 | fmt = cursor.charFormat(); 177 | fmt.setBackground(color); 178 | 179 | cursor.setCharFormat(fmt); 180 | setTextCursor(cursor); 181 | 182 | bcolor = color; 183 | } 184 | 185 | void QTermScreen::DisplayColor(QColor &b, QColor &f) 186 | { 187 | QTextCharFormat fmt; 188 | 189 | fmt.setBackground(b); 190 | fmt.setForeground(f); 191 | QTextCursor cursor = textCursor(); 192 | cursor.mergeCharFormat(fmt); 193 | setTextCursor(cursor); 194 | } 195 | 196 | QColor QTermScreen::GetColor(int col) 197 | { 198 | QColor color[8] = 199 | { 200 | "black", "red", "green", "yellow", 201 | "deepskyblue", "magenta", "cyan", "white" 202 | }; 203 | 204 | if (col >= 0 && col <= 7) 205 | { 206 | return color[col]; 207 | } 208 | else 209 | { 210 | return color[0]; 211 | } 212 | } 213 | 214 | void QTermScreen::DisplayReset() 215 | { 216 | QColor color; 217 | 218 | color = GetColor(0); 219 | DisplayBackground(color); 220 | color = GetColor(7); 221 | DisplayForeground(color); 222 | } 223 | 224 | void QTermScreen::EraseEndOfLine() 225 | { 226 | QTextCursor tc = textCursor(); 227 | tc.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor); 228 | tc.removeSelectedText(); 229 | setTextCursor(tc); 230 | } 231 | 232 | void QTermScreen::EraseStartOfLine() 233 | { 234 | QTextCursor tc = textCursor(); 235 | tc.movePosition(QTextCursor::StartOfBlock, QTextCursor::KeepAnchor); 236 | tc.removeSelectedText(); 237 | setTextCursor(tc); 238 | } 239 | 240 | void QTermScreen::EraseEntireLine() 241 | { 242 | QTextCursor tc = textCursor(); 243 | tc.select(QTextCursor::LineUnderCursor); 244 | tc.removeSelectedText(); 245 | } 246 | 247 | void QTermScreen::EraseDown() 248 | { 249 | int bntop, bnbot; 250 | 251 | QTextCursor tctop = textCursor(); 252 | QTextCursor tcbot = cursorForPosition(QPoint(0, rect().bottom())); 253 | 254 | bntop = tctop.blockNumber(); 255 | bnbot = tcbot.blockNumber(); 256 | 257 | EraseEndOfLine(); 258 | CursorDown(bnbot - bntop); 259 | for (; bntop < bnbot; bntop ++) 260 | { 261 | EraseEndOfLine(); 262 | CursorUp(); 263 | } 264 | } 265 | 266 | void QTermScreen::EraseUp() 267 | { 268 | QTextCursor tc = textCursor(); 269 | QTextCursor tcup = cursorForPosition(QPoint(0, 0)); 270 | 271 | tc.setPosition(tcup.position(), QTextCursor::KeepAnchor); 272 | tc.removeSelectedText(); 273 | } 274 | 275 | void QTermScreen::EraseScreen() 276 | { 277 | EraseDown(); 278 | EraseUp(); 279 | } 280 | 281 | QByteArray QTermScreen::GetLine(int n) 282 | { 283 | QString str; 284 | QByteArray buf; 285 | int num; 286 | 287 | num = document()->lineCount(); 288 | if (n<0) 289 | n = textCursor().blockNumber(); 290 | 291 | if (n > num - 1) 292 | return buf; 293 | 294 | str = document()->findBlockByLineNumber(n).text(); 295 | buf = str.toStdString().c_str(); 296 | 297 | return buf; 298 | } 299 | 300 | -------------------------------------------------------------------------------- /QTermWidget/QTermScreen.h: -------------------------------------------------------------------------------- 1 | #ifndef QTERMSCREEN_H 2 | #define QTERMSCREEN_H 3 | 4 | #include 5 | 6 | class QTermScreen : public QPlainTextEdit 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | QTermScreen(QWidget *parent = Q_NULLPTR); 12 | 13 | public: 14 | void CursorStartOfLine(); 15 | void CursorNewLine(int n = 1); 16 | void CursorUp(int n = 1); 17 | void CursorDown(int n = 1); 18 | void CursorLeft(int n = 1); 19 | void CursorRight(int n = 1); 20 | void CursorPosition(int row = 1, int column = 1); 21 | void CursorHorizontal(int pos); 22 | 23 | public: 24 | QColor GetColor(int c); 25 | 26 | void DisplayReset(); 27 | void DisplayForeground(QColor &color); 28 | void DisplayBackground(QColor &color); 29 | void DisplayColor(QColor &b, QColor &f); 30 | 31 | public: 32 | void EraseEndOfLine(); 33 | void EraseStartOfLine(); 34 | void EraseEntireLine(); 35 | void EraseDown(); 36 | void EraseUp(); 37 | void EraseScreen(); 38 | 39 | public: 40 | void SelectRight(int n = 1); 41 | QByteArray GetLine(int n = -1); 42 | 43 | private: 44 | QColor bcolor; 45 | QColor fcolor; 46 | }; 47 | 48 | #endif // QTERMSCREEN_H 49 | -------------------------------------------------------------------------------- /QTermWidget/QTermWidget.h: -------------------------------------------------------------------------------- 1 | #ifndef QTERMWIDGET_H 2 | #define QTERMWIDGET_H 3 | 4 | #include "QTermScreen.h" 5 | 6 | class QTermWidget : public QTermScreen 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | explicit QTermWidget(QWidget *parent = Q_NULLPTR); 12 | 13 | void setEcho(bool en); 14 | void setSendLine(bool en); 15 | 16 | public slots: 17 | void putData(const QByteArray &data); 18 | void paste(); 19 | 20 | signals: 21 | void outData(const QByteArray &data); 22 | 23 | protected: 24 | virtual void mousePressEvent(QMouseEvent *e); 25 | virtual void keyPressEvent(QKeyEvent *e); 26 | virtual void wheelEvent(QWheelEvent *e); 27 | virtual void keyReleaseEvent(QKeyEvent *e); 28 | virtual void contextMenuEvent(QContextMenuEvent *e); 29 | 30 | private: 31 | void recvChar(char ch); 32 | void parseParam(QVector ¶m, int np = 1, int defval = 0); 33 | void flushText(); 34 | void debug(const QByteArray &data); 35 | void gbtou(const QByteArray &gb, QString &u); 36 | 37 | private: 38 | void eraseText(char cmd); 39 | void moveCursor(char cmd); 40 | void setDisplay(); 41 | void setTitle(); 42 | 43 | private: 44 | int m_Mode; 45 | QString m_Param; 46 | QByteArray m_Text; 47 | QByteArray m_Line; 48 | bool m_Echo; 49 | bool m_SLine; 50 | int m_Cnt; 51 | bool ctrl_press; 52 | }; 53 | 54 | #endif // QTERMWIDGET_H 55 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # QTerminal 2 | VT100/102 3 | -------------------------------------------------------------------------------- /SendSave/SSWorker.cpp: -------------------------------------------------------------------------------- 1 | #include "SSWorker.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include "SendSave.h" 7 | 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | SSWorker::SSWorker(SendSave *parent) 14 | { 15 | ui = parent; 16 | dbSS = NULL; 17 | query = NULL; 18 | } 19 | 20 | SSWorker::~SSWorker() 21 | { 22 | dbSS->close(); 23 | delete dbSS; 24 | delete query; 25 | } 26 | 27 | bool SSWorker::dbInit() 28 | { 29 | if (dbSS->open()) 30 | { 31 | query = new QSqlQuery(*dbSS); 32 | return true; 33 | } 34 | 35 | return false; 36 | } 37 | 38 | void SSWorker::connectDb(QString name) 39 | { 40 | if (dbSS == NULL) 41 | { 42 | dbSS = new QSqlDatabase; 43 | *dbSS = QSqlDatabase::addDatabase("QSQLITE", name); 44 | dbSS->setDatabaseName(name); 45 | 46 | start(); 47 | } 48 | } 49 | 50 | void SSWorker::dbNewTable() 51 | { 52 | QString str = "CREATE TABLE sendlist" 53 | "(" 54 | "sn VARCHAR," 55 | "name VARCHAR," 56 | "type VARCHAR," 57 | "value VARCHAR," 58 | "endline VARCHAR" 59 | ");"; 60 | 61 | query->exec(str); 62 | } 63 | 64 | void SSWorker::dbAddRow(QString &sn, QString &name, QString &type, QString &value, QString &endline) 65 | { 66 | QString str; 67 | ostringstream tmp; 68 | 69 | if (!query) 70 | return; 71 | 72 | tmp << "INSERT INTO sendlist VALUES(" 73 | << "'" << sn.toStdString() << "'," 74 | << "'" << name.toStdString() << "'," 75 | << "'" << type.toStdString() << "'," 76 | << "'" << value.toStdString() << "'," 77 | << "'" << endline.toStdString() << "'" 78 | << ");"; 79 | 80 | str = QString::fromStdString(tmp.str()); 81 | 82 | query->exec(str); 83 | } 84 | 85 | void SSWorker::dbUpdateRow(QString &sn, int col, QString &val) 86 | { 87 | string head = "UPDATE sendlist SET "; 88 | QString str; 89 | ostringstream temp; 90 | 91 | if (!query) 92 | return; 93 | 94 | temp << head; 95 | 96 | switch (col) 97 | { 98 | case 0: 99 | temp << "name = '" << val.toStdString() << "'"; 100 | break; 101 | case 1: 102 | temp << "value = '" << val.toStdString() << "'"; 103 | break; 104 | case 2: 105 | temp << "endline = '" << val.toStdString() << "'"; 106 | break; 107 | default: 108 | break; 109 | } 110 | 111 | temp << " WHERE sn = '" << sn.toStdString() << "'"; 112 | 113 | str = str.fromStdString(temp.str()); 114 | query->prepare(str); 115 | 116 | query->exec(); 117 | } 118 | 119 | void SSWorker::dbDelAll() 120 | { 121 | string head = "DELETE FROM sendlist;"; 122 | QString str; 123 | ostringstream temp; 124 | 125 | if (!query) 126 | return; 127 | 128 | temp << head; 129 | str = str.fromStdString(temp.str()); 130 | query->exec(str); 131 | } 132 | 133 | void SSWorker::dbQuery() 134 | { 135 | query->exec("SELECT * FROM sendlist;"); 136 | 137 | while(query->next()) 138 | { 139 | QString name; 140 | QString type; 141 | QString value; 142 | QString endline; 143 | 144 | name = query->value(1).toString(); 145 | type = query->value(2).toString(); 146 | value = query->value(3).toString(); 147 | endline = query->value(4).toString(); 148 | 149 | ui->tableAddRow(name, type, value, endline); 150 | } 151 | } 152 | 153 | void SSWorker::run() 154 | { 155 | if (dbInit()) 156 | { 157 | dbNewTable(); 158 | dbQuery(); 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /SendSave/SSWorker.h: -------------------------------------------------------------------------------- 1 | #ifndef SSWORKER_H 2 | #define SSWORKER_H 3 | 4 | #include 5 | 6 | class QSqlDatabase; 7 | class SendSave; 8 | class QSqlQuery; 9 | 10 | class SSWorker : public QThread 11 | { 12 | public: 13 | SSWorker(SendSave *parent); 14 | ~SSWorker(); 15 | 16 | void connectDb(QString name); 17 | 18 | private: 19 | void run(); 20 | 21 | bool dbInit(); 22 | void dbNewTable(); 23 | void dbQuery(); 24 | 25 | public: 26 | void dbAddRow(QString &sn, QString &name, QString &type, QString &value, QString &endline); 27 | void dbUpdateRow(QString &sn, int col, QString &val); 28 | void dbDelAll(); 29 | 30 | private: 31 | QSqlDatabase *dbSS; 32 | SendSave *ui; 33 | QSqlQuery *query; 34 | }; 35 | 36 | #endif // SSWORKER_H 37 | -------------------------------------------------------------------------------- /SendSave/SendSave.cpp: -------------------------------------------------------------------------------- 1 | #include "SendSave.h" 2 | #include "ui_SendSave.h" 3 | #include "SSWorker.h" 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | using namespace std; 10 | 11 | SendSave::SendSave(QWidget *parent) : 12 | QDialog(parent), 13 | ui(new Ui::SendSave) 14 | { 15 | ui->setupUi(this); 16 | 17 | tableInit(); 18 | 19 | worker = new SSWorker(this); 20 | } 21 | 22 | SendSave::~SendSave() 23 | { 24 | delete ui; 25 | delete worker; 26 | } 27 | 28 | void SendSave::connectDb(QString name) 29 | { 30 | worker->connectDb(name); 31 | } 32 | 33 | void SendSave::tableInit() 34 | { 35 | ui->tbSave->setColumnCount(3); 36 | 37 | QStringList header; 38 | 39 | header << "名称" << "内容" << "换行符"; 40 | ui->tbSave->setHorizontalHeaderLabels(header); 41 | 42 | ui->tbSave->setSelectionBehavior(QAbstractItemView::SelectRows); 43 | ui->tbSave->horizontalHeader()->resizeSection(0, 60); 44 | ui->tbSave->horizontalHeader()->resizeSection(1, 160); 45 | 46 | QHeaderView *vh; 47 | 48 | vh = ui->tbSave->verticalHeader(); 49 | connect(vh, SIGNAL(sectionClicked(int)), this, SLOT(VHeaderClicked(int))); 50 | } 51 | 52 | void SendSave::VHeaderClicked(int index) 53 | { 54 | QByteArray buf; 55 | QString name; 56 | QString value; 57 | QString endline; 58 | QTableWidgetItem *item; 59 | 60 | if (index >= ui->tbSave->rowCount() || index < 0) 61 | return; 62 | 63 | item = ui->tbSave->item(index, 0); 64 | name = item->text(); 65 | item = ui->tbSave->item(index, 1); 66 | value = item->text(); 67 | item = ui->tbSave->item(index, 2); 68 | endline = item->text(); 69 | 70 | dataMake(buf, value, endline, name.at(0) == '\\'); 71 | if (buf.size()) 72 | { 73 | emit outData(buf); 74 | } 75 | } 76 | 77 | void SendSave::tableAddRow(QString &name, QString &type, QString &value, QString &endline) 78 | { 79 | int row; 80 | 81 | row = ui->tbSave->rowCount(); 82 | ui->tbSave->insertRow(row); 83 | QTableWidgetItem *item = new QTableWidgetItem[3]; 84 | 85 | item->setText(name); 86 | ui->tbSave->setItem(row, 0, item); 87 | item ++; 88 | 89 | item->setText(value); 90 | ui->tbSave->setItem(row, 1, item); 91 | item ++; 92 | 93 | item->setText(endline); 94 | ui->tbSave->setItem(row, 2, item); 95 | 96 | item = new QTableWidgetItem("发送"); 97 | ui->tbSave->setVerticalHeaderItem(row, item); 98 | 99 | setBtName(row, name); 100 | } 101 | 102 | void SendSave::on_send1_clicked() 103 | { 104 | VHeaderClicked(0); 105 | hide(); 106 | } 107 | 108 | void SendSave::on_send2_clicked() 109 | { 110 | VHeaderClicked(1); 111 | hide(); 112 | } 113 | 114 | void SendSave::on_send3_clicked() 115 | { 116 | VHeaderClicked(2); 117 | hide(); 118 | } 119 | 120 | void SendSave::on_add_clicked() 121 | { 122 | QString sn; 123 | QString type = "ascii"; 124 | QString endline = "\\n"; 125 | QString value = "test"; 126 | 127 | sn = QString::asprintf("%d", ui->tbSave->rowCount() + 1); 128 | tableAddRow(sn, type, value, endline); 129 | worker->dbAddRow(sn, sn, type, value, endline); 130 | } 131 | 132 | void SendSave::on_tbSave_itemChanged(QTableWidgetItem *item) 133 | { 134 | QString sn; 135 | QString val; 136 | 137 | sn = QString::asprintf("%d", item->row() + 1); 138 | val = item->text(); 139 | worker->dbUpdateRow(sn, item->column(), val); 140 | 141 | if (item->column() == 0) 142 | { 143 | setBtName(item->row(), val); 144 | } 145 | } 146 | 147 | void SendSave::setBtName(int row, QString name) 148 | { 149 | if (row > 2) 150 | return; 151 | 152 | switch (row) 153 | { 154 | case 0: 155 | ui->send1->setText(name); 156 | break; 157 | case 1: 158 | ui->send2->setText(name); 159 | break; 160 | case 2: 161 | ui->send3->setText(name); 162 | break; 163 | } 164 | } 165 | 166 | void SendSave::on_clear_clicked() 167 | { 168 | int row = ui->tbSave->rowCount(); 169 | 170 | worker->dbDelAll(); 171 | 172 | for (int i = 0; i < row; i ++) 173 | { 174 | ui->tbSave->removeRow(0); 175 | } 176 | } 177 | 178 | void SendSave::dataMake(QByteArray &buf, QString &value, QString &endline, bool escape) 179 | { 180 | bool es = false; 181 | 182 | if (value.isEmpty()) 183 | return; 184 | 185 | if (escape) 186 | { 187 | int ch; 188 | QByteArray tmp = value.toStdString().c_str(); 189 | char *c = tmp.data(); 190 | QString str; 191 | 192 | for (int i = 0; i < tmp.length(); i ++) 193 | { 194 | ch = c[i]; 195 | if (ch == '\\') 196 | { 197 | es = true; 198 | continue; 199 | } 200 | 201 | if (es) 202 | { 203 | switch (ch) 204 | { 205 | case 'x': 206 | { 207 | bool ok; 208 | 209 | str = value.mid(i + 1, 2); 210 | 211 | ch = str.toInt(&ok, 16); 212 | if (!ok) 213 | { 214 | str = value.mid(i + 1, 1); 215 | ch = str.toInt(&ok, 16); 216 | } 217 | 218 | if (ok) 219 | { 220 | buf.append(ch); 221 | i += str.length(); 222 | } 223 | } 224 | break; 225 | } 226 | 227 | es = false; 228 | continue; 229 | } 230 | 231 | buf.append(ch); 232 | } 233 | } 234 | else 235 | { 236 | buf = value.toStdString().c_str(); 237 | } 238 | 239 | int r, n; 240 | r = endline.count("\\r"); 241 | n = endline.count("\\n"); 242 | 243 | for (int i = 0; i < r; i++) 244 | { 245 | buf.append('\r'); 246 | } 247 | 248 | for (int i = 0; i < n; i++) 249 | { 250 | buf.append('\n'); 251 | } 252 | } 253 | 254 | void SendSave::on_send_clicked() 255 | { 256 | int sel = ui->tbSave->currentRow(); 257 | 258 | VHeaderClicked(sel); 259 | } 260 | 261 | QWidget* SendSave::toolButton(int index) 262 | { 263 | QWidget* bt = NULL; 264 | 265 | switch (index) 266 | { 267 | case 0: 268 | bt = ui->send1; 269 | break; 270 | case 1: 271 | bt = ui->send2; 272 | break; 273 | case 2: 274 | bt = ui->send3; 275 | break; 276 | case 3: 277 | bt = ui->show; 278 | break; 279 | } 280 | 281 | return bt; 282 | } 283 | 284 | void SendSave::on_show_clicked() 285 | { 286 | show(); 287 | activateWindow(); 288 | } 289 | -------------------------------------------------------------------------------- /SendSave/SendSave.h: -------------------------------------------------------------------------------- 1 | #ifndef SENDSAVE_H 2 | #define SENDSAVE_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class SendSave; 8 | } 9 | 10 | class SSWorker; 11 | class QTableWidgetItem; 12 | class QToolButton; 13 | 14 | class SendSave : public QDialog 15 | { 16 | Q_OBJECT 17 | 18 | public: 19 | explicit SendSave(QWidget *parent = 0); 20 | ~SendSave(); 21 | 22 | void tableAddRow(QString &name, QString &type, QString &value, QString &endline); 23 | QWidget* toolButton(int index = 0); 24 | 25 | void connectDb(QString name); 26 | 27 | signals: 28 | void outData(const QByteArray &data); 29 | 30 | private: 31 | void tableInit(); 32 | void dataMake(QByteArray &buf, QString &value, QString &endline, bool escape); 33 | void setBtName(int row, QString name); 34 | 35 | private slots: 36 | void on_send1_clicked(); 37 | 38 | void on_send2_clicked(); 39 | 40 | void on_send3_clicked(); 41 | 42 | void on_add_clicked(); 43 | 44 | void on_tbSave_itemChanged(QTableWidgetItem *item); 45 | 46 | void on_clear_clicked(); 47 | 48 | void VHeaderClicked(int index); 49 | 50 | void on_send_clicked(); 51 | 52 | void on_show_clicked(); 53 | 54 | private: 55 | Ui::SendSave *ui; 56 | SSWorker *worker; 57 | }; 58 | 59 | #endif // SENDSAVE_H 60 | -------------------------------------------------------------------------------- /SendSave/SendSave.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | SendSave 4 | 5 | 6 | 7 | 0 8 | 0 9 | 356 10 | 244 11 | 12 | 13 | 14 | 发送列表 15 | 16 | 17 | 18 | 19 | 20 | 2 21 | 22 | 23 | 24 | 25 | 26 | 27 | 3 28 | 29 | 30 | 31 | 32 | 33 | 34 | 发送 35 | 36 | 37 | 38 | 39 | 40 | 41 | + 42 | 43 | 44 | 45 | 46 | 47 | 48 | 清空 49 | 50 | 51 | 52 | 53 | 54 | 55 | 1 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 记录 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /Serial/SerialTerm.cpp: -------------------------------------------------------------------------------- 1 | #include "SerialTerm.h" 2 | #include "ui_SerialTerm.h" 3 | 4 | #include "QTermWidget/QTermWidget.h" 5 | #include "SendSave/SendSave.h" 6 | 7 | SerialTerm::SerialTerm(QWidget *parent) : 8 | QMainWindow(parent), 9 | ui(new Ui::SerialTerm) 10 | { 11 | ui->setupUi(this); 12 | 13 | initTerm(); 14 | 15 | statusBar()->addWidget(ui->btConnect); 16 | 17 | initSendSave(); 18 | initSerial(); 19 | 20 | statusBar()->addWidget(ui->lbParam); 21 | } 22 | 23 | SerialTerm::~SerialTerm() 24 | { 25 | delete ui; 26 | delete serial; 27 | delete dlgSS; 28 | delete term; 29 | } 30 | 31 | void SerialTerm::initTerm() 32 | { 33 | term = new QTermWidget; 34 | 35 | connect(term, SIGNAL(outData(QByteArray)), this, SLOT(writeData(QByteArray))); 36 | setCentralWidget((QWidget*)term); 37 | } 38 | 39 | void SerialTerm::initSendSave() 40 | { 41 | dlgSS = new SendSave; 42 | 43 | statusBar()->addWidget(dlgSS->toolButton(0)); 44 | statusBar()->addWidget(dlgSS->toolButton(1)); 45 | statusBar()->addWidget(dlgSS->toolButton(2)); 46 | statusBar()->addWidget(dlgSS->toolButton(3)); 47 | 48 | connect(dlgSS, SIGNAL(outData(QByteArray)), this, SLOT(writeData(QByteArray))); 49 | } 50 | 51 | void SerialTerm::initSerial() 52 | { 53 | serial = new QSerialPort; 54 | 55 | connect(serial, SIGNAL(readyRead()), this, SLOT(readData())); 56 | connect(serial, SIGNAL(error(QSerialPort::SerialPortError)), 57 | this, SLOT(error(QSerialPort::SerialPortError))); 58 | } 59 | 60 | void SerialTerm::error(QSerialPort::SerialPortError e) 61 | { 62 | if (e == QSerialPort::PermissionError) 63 | { 64 | ui->btConnect->setText(QString("连接")); 65 | } 66 | } 67 | 68 | bool SerialTerm::openSerial() 69 | { 70 | bool ret; 71 | 72 | serial->setPortName(settings["dev"]); 73 | serial->setBaudRate(settings["speed"].toInt()); 74 | 75 | serial->setParity(QSerialPort::NoParity); 76 | serial->setStopBits(QSerialPort::OneStop); 77 | serial->setDataBits(QSerialPort::Data8); 78 | serial->setFlowControl(QSerialPort::NoFlowControl); 79 | 80 | ret = serial->open(QIODevice::ReadWrite); 81 | 82 | return ret; 83 | } 84 | 85 | void SerialTerm::setSettings(SesParam &ss, QString id) 86 | { 87 | settings = ss; 88 | QString p; 89 | 90 | p = ss["dev"] + "," + ss["speed"]; 91 | ui->lbParam->setText(p); 92 | id += ".dblite"; 93 | dlgSS->connectDb(id); 94 | } 95 | 96 | void SerialTerm::writeData(const QByteArray &data) 97 | { 98 | serial->write(data); 99 | } 100 | 101 | void SerialTerm::readData() 102 | { 103 | QByteArray data; 104 | 105 | data = serial->readAll(); 106 | 107 | term->putData(data); 108 | } 109 | 110 | void SerialTerm::on_btConnect_clicked() 111 | { 112 | if (serial->isOpen()) 113 | { 114 | serial->close(); 115 | ui->btConnect->setText(QString("连接")); 116 | } 117 | else if (openSerial()) 118 | { 119 | ui->btConnect->setText(QString("断开")); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /Serial/SerialTerm.h: -------------------------------------------------------------------------------- 1 | #ifndef SERIALTERM_H 2 | #define SERIALTERM_H 3 | 4 | #include 5 | #include 6 | 7 | namespace Ui { 8 | class SerialTerm; 9 | } 10 | 11 | class QTermWidget; 12 | class SendSave; 13 | 14 | #include "NewSession/Setting.h" 15 | 16 | class SerialTerm : public QMainWindow 17 | { 18 | Q_OBJECT 19 | 20 | public: 21 | explicit SerialTerm(QWidget *parent = 0); 22 | ~SerialTerm(); 23 | 24 | void setSettings(SesParam &ss, QString id); 25 | 26 | private slots: 27 | void writeData(const QByteArray &data); 28 | void readData(); 29 | void error(QSerialPort::SerialPortError e); 30 | 31 | private slots: 32 | void on_btConnect_clicked(); 33 | 34 | private: 35 | void initSendSave(); 36 | void initSerial(); 37 | void initTerm(); 38 | bool openSerial(); 39 | 40 | private: 41 | Ui::SerialTerm *ui; 42 | QTermWidget *term; 43 | SendSave *dlgSS; 44 | QSerialPort *serial; 45 | SesParam settings; 46 | }; 47 | 48 | #endif // SERIALTERM_H 49 | -------------------------------------------------------------------------------- /Serial/SerialTerm.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | SerialTerm 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 480 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 0 21 | 420 22 | 51 23 | 23 24 | 25 | 26 | 27 | 连接 28 | 29 | 30 | 31 | 32 | 33 | 160 34 | 430 35 | 341 36 | 16 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /SuperTerm/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /SuperTerm/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define VERSION "1.0.0" 9 | 10 | #include "NewSession/NewSession.h" 11 | 12 | MainWindow::MainWindow(QWidget *parent) : 13 | QMainWindow(parent), 14 | ui(new Ui::MainWindow) 15 | { 16 | ui->setupUi(this); 17 | 18 | ui->tabWidget->removeTab(0); 19 | ui->tabWidget->removeTab(0); 20 | ui->dockWidget->setWidget(ui->twProject); 21 | 22 | loadSession(); 23 | } 24 | 25 | MainWindow::~MainWindow() 26 | { 27 | delete ui; 28 | } 29 | 30 | void MainWindow::loadSession() 31 | { 32 | SesList sl; 33 | 34 | prjfile.Load("qstprj.xml"); 35 | prjfile.GetSessionList(sl); 36 | 37 | for (int i = 0; i < sl.count(); i ++) 38 | { 39 | Session s; 40 | 41 | s = sl.at(i); 42 | addSession(s, false); 43 | } 44 | } 45 | 46 | void MainWindow::about(void) 47 | { 48 | QMessageBox mbox; 49 | 50 | mbox.about(this, tr("关于"), tr("版本号: " VERSION)); 51 | } 52 | 53 | void MainWindow::on_new_s_triggered() 54 | { 55 | NewSession *ns = new NewSession; 56 | 57 | ns->show(); 58 | ns->exec(); 59 | 60 | if (ns->result() == 1) 61 | { 62 | Session set; 63 | 64 | ns->getSetting(set); 65 | 66 | addSession(set); 67 | } 68 | 69 | delete ns; 70 | } 71 | 72 | void MainWindow::addSession(Session &set, bool save) 73 | { 74 | QTreeWidgetItem *child; 75 | QWidget *w; 76 | 77 | child = addSessionProject(set); 78 | 79 | w = addSessionWindow(set, child); 80 | if (w != NULL) 81 | { 82 | QVariant var; 83 | 84 | var.setValue(w); 85 | child->setData(0, Qt::UserRole, var); 86 | 87 | var.setValue(set.id); 88 | child->setData(1, Qt::UserRole, var); 89 | w->setUserData(0, (QObjectUserData*)child); 90 | 91 | if (set.show == "1") 92 | ui->tabWidget->addTab(w, set.name); 93 | 94 | if (save) 95 | { 96 | prjfile.AddSession(set); 97 | prjfile.Save(); 98 | } 99 | } 100 | } 101 | 102 | QTreeWidgetItem* MainWindow::addSessionProject(Session &set) 103 | { 104 | QTreeWidgetItem *type = new QTreeWidgetItem; 105 | bool addtype = true; 106 | 107 | for (int i = 0; i < ui->twProject->topLevelItemCount(); i ++) 108 | { 109 | QTreeWidgetItem *tmptype = ui->twProject->topLevelItem(i); 110 | 111 | if (tmptype->text(0) == set.type) 112 | { 113 | delete type; 114 | type = tmptype; 115 | addtype = false; 116 | break; 117 | } 118 | } 119 | 120 | type->setText(0, set.type); 121 | if (addtype) 122 | { 123 | QVariant var(0); 124 | 125 | type->setData(0, Qt::UserRole, var); 126 | ui->twProject->addTopLevelItem(type); 127 | } 128 | 129 | QTreeWidgetItem *child = new QTreeWidgetItem; 130 | child->setText(0, set.name); 131 | type->addChild(child); 132 | 133 | return child; 134 | } 135 | 136 | #include "Serial/SerialTerm.h" 137 | #include "Telnet/TelnetTerm.h" 138 | #include "Console/Console.h" 139 | #include "NetAssist/NetAssist.h" 140 | 141 | QWidget* MainWindow::addSessionWindow(Session &set, QTreeWidgetItem *item) 142 | { 143 | QWidget *w = NULL; 144 | 145 | if (set.type == "串口终端") 146 | { 147 | SerialTerm *term = new SerialTerm; 148 | 149 | term->setSettings(set.param, set.id); 150 | w = term; 151 | } 152 | 153 | if (set.type == "telnet") 154 | { 155 | TelnetTerm *term = new TelnetTerm; 156 | 157 | term->setSettings(set.param); 158 | w = term; 159 | } 160 | 161 | if (set.type == "Console") 162 | { 163 | Console *con = new Console; 164 | 165 | con->setSettings(set.param, set.id); 166 | w = con; 167 | } 168 | 169 | if (set.type == "网络助手") 170 | { 171 | NetAssist *con = new NetAssist; 172 | 173 | con->setSettings(set); 174 | w = con; 175 | } 176 | 177 | return w; 178 | } 179 | 180 | void MainWindow::on_twProject_itemDoubleClicked(QTreeWidgetItem *item, int column) 181 | { 182 | QWidget *w; 183 | QVariant var; 184 | QString id; 185 | 186 | var = item->data(0, Qt::UserRole); 187 | if (var == 0) 188 | return; 189 | 190 | w = var.value(); 191 | if (ui->tabWidget->indexOf(w) >= 0) 192 | { 193 | ui->tabWidget->setCurrentWidget(w); 194 | } 195 | else 196 | { 197 | ui->tabWidget->addTab(w, item->text(0)); 198 | 199 | var = item->data(1, Qt::UserRole); 200 | id = var.value(); 201 | prjfile.SetSesShow(id, true); 202 | } 203 | } 204 | 205 | void MainWindow::on_twProject_customContextMenuRequested(const QPoint &pos) 206 | { 207 | QTreeWidgetItem* curItem; 208 | 209 | curItem = ui->twProject->itemAt(pos); 210 | if (curItem == NULL) 211 | return; 212 | 213 | QVariant var = curItem->data(0, Qt::UserRole); 214 | if (var == 0) 215 | return; 216 | 217 | QMenu *popMenu =new QMenu(this); 218 | 219 | popMenu->addAction(ui->del_s);//往菜单内添加QAction 该action在前面用设计器定义了 220 | popMenu->exec(QCursor::pos()); 221 | 222 | delete popMenu; 223 | } 224 | 225 | void MainWindow::on_del_s_triggered() 226 | { 227 | QTreeWidgetItem* curItem, *top; 228 | QVariant var; 229 | QString id; 230 | QWidget* w; 231 | 232 | curItem = ui->twProject->currentItem(); 233 | if (curItem == NULL) 234 | return; 235 | var = curItem->data(0, Qt::UserRole); 236 | if (var == 0) 237 | return; 238 | 239 | top = curItem->parent(); 240 | 241 | var = curItem->data(1, Qt::UserRole); 242 | id = var.value(); 243 | prjfile.DelSession(id); 244 | 245 | var = curItem->data(0, Qt::UserRole); 246 | w = var.value(); 247 | top->removeChild(curItem); 248 | 249 | ui->tabWidget->removeTab(ui->tabWidget->indexOf(w)); 250 | 251 | QFile dbf; 252 | 253 | id += ".dblite"; 254 | 255 | w->setUserData(0, NULL); 256 | delete w; 257 | delete curItem; 258 | dbf.remove(id); 259 | } 260 | 261 | void MainWindow::on_tabWidget_tabCloseRequested(int index) 262 | { 263 | QString id; 264 | QVariant var; 265 | QWidget *w; 266 | QTreeWidgetItem *item; 267 | 268 | w = ui->tabWidget->widget(index); 269 | 270 | item = (QTreeWidgetItem *)w->userData(0); 271 | var = item->data(1, Qt::UserRole); 272 | id = var.value(); 273 | 274 | ui->tabWidget->removeTab(index); 275 | prjfile.SetSesShow(id, false); 276 | } 277 | 278 | void MainWindow::closeEvent(QCloseEvent *e) 279 | { 280 | QTreeWidget *prj; 281 | 282 | prj = ui->twProject; 283 | for (int i = 0; i < prj->topLevelItemCount(); i ++) 284 | { 285 | QTreeWidgetItem *type; 286 | 287 | type = prj->topLevelItem(i); 288 | for (int c = 0; c < type->childCount(); c ++) 289 | { 290 | QWidget *term; 291 | 292 | term = getTerm(type->child(c)); 293 | if (!term->close()) 294 | { 295 | e->ignore(); 296 | return; 297 | } 298 | } 299 | } 300 | } 301 | 302 | QWidget* MainWindow::getTerm(QTreeWidgetItem *prjit) 303 | { 304 | QVariant var; 305 | 306 | var = prjit->data(0, Qt::UserRole); 307 | 308 | return var.value(); 309 | } 310 | -------------------------------------------------------------------------------- /SuperTerm/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace Ui { 10 | class MainWindow; 11 | } 12 | 13 | #include "NewSession/Setting.h" 14 | #include "projectfile.h" 15 | 16 | class MainWindow : public QMainWindow 17 | { 18 | Q_OBJECT 19 | 20 | public: 21 | explicit MainWindow(QWidget *parent = 0); 22 | ~MainWindow(); 23 | 24 | private: 25 | void addSession(Session &set, bool save = true); 26 | QTreeWidgetItem* addSessionProject(Session &set); 27 | QWidget* addSessionWindow(Session &set, QTreeWidgetItem *item); 28 | void loadSession(); 29 | QWidget* getTerm(QTreeWidgetItem *prjit); 30 | 31 | private: 32 | void closeEvent(QCloseEvent *e); 33 | 34 | private slots: 35 | void about(void); 36 | 37 | void on_new_s_triggered(); 38 | 39 | void on_twProject_itemDoubleClicked(QTreeWidgetItem *item, int column); 40 | 41 | void on_twProject_customContextMenuRequested(const QPoint &pos); 42 | 43 | void on_del_s_triggered(); 44 | 45 | void on_tabWidget_tabCloseRequested(int index); 46 | 47 | private: 48 | void menuInit(void); 49 | 50 | private: 51 | Ui::MainWindow *ui; 52 | ProjectFile prjfile; 53 | }; 54 | 55 | #endif // MAINWINDOW_H 56 | -------------------------------------------------------------------------------- /SuperTerm/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 915 10 | 496 11 | 12 | 13 | 14 | 奇梦.终端 15 | 16 | 17 | 18 | 19 | 20 | 0 21 | 0 22 | 691 23 | 481 24 | 25 | 26 | 27 | 0 28 | 29 | 30 | true 31 | 32 | 33 | false 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | Tab 2 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 0 51 | 0 52 | 915 53 | 23 54 | 55 | 56 | 57 | 58 | 文件 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 200 69 | 524287 70 | 71 | 72 | 73 | QDockWidget::NoDockWidgetFeatures 74 | 75 | 76 | Qt::LeftDockWidgetArea 77 | 78 | 79 | 1 80 | 81 | 82 | 83 | 84 | 0 85 | 0 86 | 87 | 88 | 89 | 90 | 200 91 | 16777215 92 | 93 | 94 | 95 | 96 | 97 | -10 98 | 30 99 | 200 100 | 331 101 | 102 | 103 | 104 | 105 | 0 106 | 0 107 | 108 | 109 | 110 | 111 | 200 112 | 16777215 113 | 114 | 115 | 116 | Qt::CustomContextMenu 117 | 118 | 119 | false 120 | 121 | 122 | 123 | 1 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 新建 132 | 133 | 134 | 135 | 136 | 删除会话 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /SuperTerm/projectfile.cpp: -------------------------------------------------------------------------------- 1 | #include "projectfile.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | ProjectFile::ProjectFile(QObject *parent) : QObject(parent) 9 | { 10 | init(); 11 | } 12 | 13 | bool ProjectFile::Load(QString filename) 14 | { 15 | bool ret = true; 16 | 17 | prjfile->setFileName(filename); 18 | 19 | if(!prjfile->open(QFile::ReadOnly | QFile::Text)) 20 | { 21 | return false; 22 | } 23 | 24 | QString errorStr; 25 | int errorLine; 26 | int errorColumn; 27 | 28 | if(!doc->setContent(prjfile, false, &errorStr, &errorLine, &errorColumn)) 29 | { 30 | return false; 31 | } 32 | 33 | prjfile->close(); 34 | 35 | return ret; 36 | } 37 | 38 | void ProjectFile::getSession(QDomElement &sesEle, Session &ses) 39 | { 40 | QDomNodeList list; 41 | 42 | ses.id = sesEle.attribute("ID"); 43 | 44 | list = sesEle.elementsByTagName("param"); 45 | for (int i = 0; i < list.size(); i ++) 46 | { 47 | QDomElement paramEle = list.item(i).toElement(); 48 | 49 | getParam(paramEle, ses); 50 | } 51 | } 52 | 53 | void ProjectFile::getParam(QDomElement &parEle, Session &ses) 54 | { 55 | QDomNamedNodeMap nmap; 56 | QString key, value; 57 | 58 | nmap = parEle.attributes(); 59 | 60 | for (int i = 0; i < nmap.size(); i ++) 61 | { 62 | key = nmap.item(i).nodeName(); 63 | value = nmap.item(i).nodeValue(); 64 | 65 | ses.param[key] = value; 66 | } 67 | } 68 | 69 | bool ProjectFile::GetSessionList(SesList &sl) 70 | { 71 | bool ret = false; 72 | QDomElement r; 73 | 74 | *root = doc->documentElement(); 75 | 76 | QDomNodeList list; 77 | 78 | list = doc->elementsByTagName("type"); 79 | for (int i = 0; i < list.size(); i ++) 80 | { 81 | QDomNode item = list.item(i); 82 | QDomElement type; 83 | Session ses; 84 | QDomNodeList seslist; 85 | 86 | type = item.toElement(); 87 | seslist = type.elementsByTagName("session"); 88 | 89 | ses.type = type.attribute("ID"); 90 | 91 | for (int n = 0; n < seslist.size(); n ++) 92 | { 93 | QDomElement sesEle = seslist.item(n).toElement(); 94 | 95 | ses.id = sesEle.attribute("ID"); 96 | ses.name = sesEle.attribute("name"); 97 | ses.show = sesEle.attribute("show"); 98 | 99 | getSession(sesEle, ses); 100 | 101 | sl.append(ses); 102 | ret = true; 103 | } 104 | } 105 | 106 | return ret; 107 | } 108 | 109 | void ProjectFile::addType(QString &name) 110 | { 111 | QDomElement type; 112 | 113 | type = doc->createElement("type"); 114 | type.setAttribute("ID", name); 115 | root->appendChild(type); 116 | } 117 | 118 | void ProjectFile::AddSession(Session &ses) 119 | { 120 | QDomNodeList list; 121 | int addtype = 0; 122 | 123 | _again: 124 | list = doc->elementsByTagName("type"); 125 | 126 | for (int i = 0; i < list.size(); i ++) 127 | { 128 | QDomNode item = list.item(i); 129 | QDomElement type; 130 | 131 | type = item.toElement(); 132 | if (type.attribute("ID") == ses.type) 133 | { 134 | QDomElement e; 135 | 136 | e = doc->createElement("session"); 137 | e.setAttribute("ID", ses.id); 138 | e.setAttribute("name", ses.name); 139 | e.setAttribute("show", ses.show); 140 | type.appendChild(e); 141 | 142 | addParam(e, ses); 143 | addtype = 1; 144 | break; 145 | } 146 | } 147 | 148 | if (addtype == 0) 149 | { 150 | addType(ses.type); 151 | goto _again; 152 | } 153 | } 154 | 155 | void ProjectFile::addParam(QDomElement &e, Session &ses) 156 | { 157 | QDomElement child; 158 | QList keys; 159 | int cnt; 160 | 161 | keys = ses.param.keys(); 162 | cnt = keys.size(); 163 | 164 | child = doc->createElement("param"); 165 | for (int i = 0; i < cnt; i ++) 166 | { 167 | QString key = keys[i]; 168 | 169 | child.setAttribute(key, ses.param[key]); 170 | } 171 | e.appendChild(child); 172 | } 173 | 174 | void ProjectFile::init() 175 | { 176 | QDomProcessingInstruction instruction; 177 | 178 | doc = new QDomDocument; 179 | root = new QDomElement; 180 | 181 | instruction = doc->createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""); 182 | *root = doc->createElement("Project"); 183 | 184 | doc->appendChild(instruction); 185 | doc->appendChild(*root); 186 | 187 | prjfile = new QFile; 188 | } 189 | 190 | void ProjectFile::SetSesShow(QString &id, bool s) 191 | { 192 | QString val; 193 | QDomNodeList list; 194 | 195 | val = s? "1":"0"; 196 | 197 | list = doc->elementsByTagName("type"); 198 | 199 | for (int i = 0; i < list.size(); i ++) 200 | { 201 | QDomNode item = list.item(i); 202 | QDomElement type, ele; 203 | 204 | type = item.toElement(); 205 | ele = type.firstChildElement(); 206 | 207 | while (!ele.isNull()) 208 | { 209 | if (ele.attribute("ID") == id) 210 | { 211 | ele.setAttribute(QString("show"), val); 212 | Save(); 213 | return; 214 | } 215 | 216 | ele = ele.nextSiblingElement(); 217 | } 218 | } 219 | } 220 | 221 | void ProjectFile::DelSession(QString &id) 222 | { 223 | QDomNodeList list; 224 | 225 | list = doc->elementsByTagName("type"); 226 | 227 | for (int i = 0; i < list.size(); i ++) 228 | { 229 | QDomNode item = list.item(i); 230 | QDomElement type, ele; 231 | 232 | type = item.toElement(); 233 | ele = type.firstChildElement(); 234 | 235 | while (!ele.isNull()) 236 | { 237 | if (ele.attribute("ID") == id) 238 | { 239 | type.removeChild(ele); 240 | Save(); 241 | return; 242 | } 243 | 244 | ele = ele.nextSiblingElement(); 245 | } 246 | } 247 | } 248 | 249 | void ProjectFile::Save() 250 | { 251 | if (!prjfile->open(QIODevice::WriteOnly | QIODevice::Truncate)) 252 | return; 253 | 254 | QTextStream out(prjfile); 255 | 256 | doc->save(out, 4); 257 | prjfile->close(); 258 | } 259 | -------------------------------------------------------------------------------- /SuperTerm/projectfile.h: -------------------------------------------------------------------------------- 1 | #ifndef PROJECTFILE_H 2 | #define PROJECTFILE_H 3 | 4 | #include 5 | #include "NewSession/nstypes.h" 6 | 7 | class QDomDocument; 8 | class QDomElement; 9 | class QFile; 10 | 11 | class ProjectFile : public QObject 12 | { 13 | Q_OBJECT 14 | public: 15 | explicit ProjectFile(QObject *parent = 0); 16 | 17 | bool Load(QString filename); 18 | bool GetSessionList(SesList &sl); 19 | 20 | void DelSession(QString &id); 21 | void AddSession(Session &ses); 22 | void Save(); 23 | void SetSesShow(QString &id, bool s); 24 | 25 | signals: 26 | 27 | public slots: 28 | 29 | private: 30 | void init(); 31 | void addParam(QDomElement &e, Session &ses); 32 | void getSession(QDomElement &sesEle, Session &ses); 33 | void getParam(QDomElement &parEle, Session &ses); 34 | void addType(QString &name); 35 | 36 | private: 37 | QDomDocument *doc; 38 | QDomElement *root; 39 | QFile *prjfile; 40 | }; 41 | 42 | #endif // PROJECTFILE_H 43 | -------------------------------------------------------------------------------- /Telnet/TelnetTerm.cpp: -------------------------------------------------------------------------------- 1 | #include "TelnetTerm.h" 2 | #include "ui_TelnetTerm.h" 3 | 4 | #include "qttelnet.h" 5 | 6 | TelnetTerm::TelnetTerm(QWidget *parent) : 7 | QMainWindow(parent), 8 | ui(new Ui::TelnetTerm) 9 | { 10 | ui->setupUi(this); 11 | 12 | initTelnet(); 13 | initTerm(); 14 | 15 | statusBar()->addWidget(ui->btConnect); 16 | } 17 | 18 | TelnetTerm::~TelnetTerm() 19 | { 20 | delete ui; 21 | } 22 | 23 | void TelnetTerm::setSettings(SesParam &ss) 24 | { 25 | settings = ss; 26 | } 27 | 28 | void TelnetTerm::initTerm() 29 | { 30 | term = new QTermWidget; 31 | 32 | connect(term, SIGNAL(outData(QByteArray)), this, SLOT(writeData(QByteArray))); 33 | 34 | setCentralWidget(term); 35 | } 36 | 37 | void TelnetTerm::initTelnet() 38 | { 39 | telnet = new QtTelnet; 40 | 41 | connect(telnet, SIGNAL(message(QString)), this, SLOT(readData(QString))); 42 | } 43 | 44 | void TelnetTerm::writeData(const QByteArray &data) 45 | { 46 | telnet->sendData(data); 47 | } 48 | 49 | void TelnetTerm::readData(const QString &data) 50 | { 51 | term->putData(data.toLocal8Bit()); 52 | } 53 | 54 | void TelnetTerm::on_btConnect_clicked() 55 | { 56 | QString host = settings["host"]; 57 | short port = settings["port"].toShort(); 58 | 59 | telnet->connectToHost(host, port); 60 | } 61 | -------------------------------------------------------------------------------- /Telnet/TelnetTerm.h: -------------------------------------------------------------------------------- 1 | #ifndef TELNETTERM_H 2 | #define TELNETTERM_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class TelnetTerm; 8 | } 9 | 10 | #include "NewSession/SessionWindow.h" 11 | #include "QTermWidget/QTermWidget.h" 12 | 13 | class QtTelnet; 14 | 15 | class TelnetTerm : public QMainWindow 16 | { 17 | Q_OBJECT 18 | 19 | public: 20 | explicit TelnetTerm(QWidget *parent = 0); 21 | ~TelnetTerm(); 22 | 23 | void setSettings(SesParam &ss); 24 | 25 | private slots: 26 | void readData(const QString &data); 27 | void writeData(const QByteArray &data); 28 | 29 | private slots: 30 | void on_btConnect_clicked(); 31 | 32 | private: 33 | void initTelnet(); 34 | void initTerm(); 35 | 36 | private: 37 | Ui::TelnetTerm *ui; 38 | QTermWidget *term; 39 | SesParam settings; 40 | QtTelnet *telnet; 41 | }; 42 | 43 | #endif // TELNETTERM_H 44 | -------------------------------------------------------------------------------- /Telnet/TelnetTerm.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | TelnetTerm 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 600 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 20 21 | 530 22 | 71 23 | 24 24 | 25 | 26 | 27 | 连接 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Telnet/qttelnet.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** This file is part of a Qt Solutions component. 4 | ** 5 | ** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: Qt Software Information (qt-info@nokia.com) 8 | ** 9 | ** Commercial Usage 10 | ** Licensees holding valid Qt Commercial licenses may use this file in 11 | ** accordance with the Qt Solutions Commercial License Agreement provided 12 | ** with the Software or, alternatively, in accordance with the terms 13 | ** contained in a written agreement between you and Nokia. 14 | ** 15 | ** GNU Lesser General Public License Usage 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser 17 | ** General Public License version 2.1 as published by the Free Software 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the 19 | ** packaging of this file. Please review the following information to 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 | ** 23 | ** In addition, as a special exception, Nokia gives you certain 24 | ** additional rights. These rights are described in the Nokia Qt LGPL 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 | ** package. 27 | ** 28 | ** GNU General Public License Usage 29 | ** Alternatively, this file may be used under the terms of the GNU 30 | ** General Public License version 3.0 as published by the Free Software 31 | ** Foundation and appearing in the file LICENSE.GPL included in the 32 | ** packaging of this file. Please review the following information to 33 | ** ensure the GNU General Public License version 3.0 requirements will be 34 | ** met: http://www.gnu.org/copyleft/gpl.html. 35 | ** 36 | ** Please note Third Party Software included with Qt Solutions may impose 37 | ** additional restrictions and it is the user's responsibility to ensure 38 | ** that they have met the licensing requirements of the GPL, LGPL, or Qt 39 | ** Solutions Commercial license and the relevant license of the Third 40 | ** Party Software they are using. 41 | ** 42 | ** If you are unsure which license is appropriate for your use, please 43 | ** contact the sales department at qt-sales@nokia.com. 44 | ** 45 | ****************************************************************************/ 46 | 47 | #ifndef QTTELNET_H 48 | #define QTTELNET_H 49 | 50 | #include 51 | #include 52 | #include 53 | #include 54 | 55 | class QtTelnetPrivate; 56 | 57 | #if defined(Q_WS_WIN) 58 | # if !defined(QT_QTTELNET_EXPORT) && !defined(QT_QTTELNET_IMPORT) 59 | # define QT_QTTELNET_EXPORT 60 | # elif defined(QT_QTTELNET_IMPORT) 61 | # if defined(QT_QTTELNET_EXPORT) 62 | # undef QT_QTTELNET_EXPORT 63 | # endif 64 | # define QT_QTTELNET_EXPORT __declspec(dllimport) 65 | # elif defined(QT_QTTELNET_EXPORT) 66 | # undef QT_QTTELNET_EXPORT 67 | # define QT_QTTELNET_EXPORT __declspec(dllexport) 68 | # endif 69 | #else 70 | # define QT_QTTELNET_EXPORT 71 | #endif 72 | 73 | class QT_QTTELNET_EXPORT QtTelnet : public QObject 74 | { 75 | Q_OBJECT 76 | 77 | friend class QtTelnetPrivate; 78 | 79 | public: 80 | QtTelnet(QObject *parent = 0); 81 | ~QtTelnet(); 82 | 83 | enum Control 84 | { 85 | GoAhead, InterruptProcess, 86 | AreYouThere, AbortOutput, 87 | EraseCharacter, EraseLine, 88 | Break, EndOfFile, 89 | Suspend, Abort 90 | }; 91 | 92 | void connectToHost(const QString &host, quint16 port = 23); 93 | 94 | void login(const QString &user, const QString &pass); 95 | 96 | void setWindowSize(const QSize &size); 97 | void setWindowSize(int width, int height); // In number of characters 98 | QSize windowSize() const; 99 | bool isValidWindowSize() const; 100 | 101 | void setSocket(QTcpSocket *socket); 102 | QTcpSocket *socket() const; 103 | 104 | void setPromptPattern(const QRegExp &pattern); 105 | void setPromptString(const QString &pattern) 106 | { 107 | setPromptPattern(QRegExp(QRegExp::escape(pattern))); 108 | } 109 | 110 | public Q_SLOTS: 111 | void close(); 112 | void logout(); 113 | void sendControl(Control ctrl); 114 | void sendData(const QString &data); 115 | void sendSync(); 116 | 117 | Q_SIGNALS: 118 | void loginRequired(); 119 | void loginFailed(); 120 | void loggedIn(); 121 | void loggedOut(); 122 | void connectionError(QAbstractSocket::SocketError error); 123 | void message(const QString &data); 124 | 125 | public: 126 | void setLoginPattern(const QRegExp &pattern); 127 | void setLoginString(const QString &pattern) 128 | { 129 | setLoginPattern(QRegExp(QRegExp::escape(pattern))); 130 | } 131 | void setPasswordPattern(const QRegExp &pattern); 132 | void setPasswordString(const QString &pattern) 133 | { 134 | setPasswordPattern(QRegExp(QRegExp::escape(pattern))); 135 | } 136 | 137 | private: 138 | QtTelnetPrivate *d; 139 | }; 140 | #endif 141 | -------------------------------------------------------------------------------- /images/application-exit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heyuanjie87/QTerminal/9635df9c2aabd3136847c7ad71bc029249bc433f/images/application-exit.png -------------------------------------------------------------------------------- /images/clear.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heyuanjie87/QTerminal/9635df9c2aabd3136847c7ad71bc029249bc433f/images/clear.png -------------------------------------------------------------------------------- /images/connect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heyuanjie87/QTerminal/9635df9c2aabd3136847c7ad71bc029249bc433f/images/connect.png -------------------------------------------------------------------------------- /images/disconnect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heyuanjie87/QTerminal/9635df9c2aabd3136847c7ad71bc029249bc433f/images/disconnect.png -------------------------------------------------------------------------------- /images/settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heyuanjie87/QTerminal/9635df9c2aabd3136847c7ad71bc029249bc433f/images/settings.png -------------------------------------------------------------------------------- /simple.pro: -------------------------------------------------------------------------------- 1 | QT += widgets serialport sql 2 | 3 | TARGET = QTerm 4 | TEMPLATE = app 5 | 6 | SOURCES += \ 7 | simple/main.cpp \ 8 | simple/mainwindow.cpp \ 9 | simple/settingsdialog.cpp \ 10 | SendSave/SendSave.cpp \ 11 | SendSave/SSWorker.cpp \ 12 | QTermWidget/QTermScreen.cpp \ 13 | QTermWidget/QTermWidget.cpp \ 14 | Modem/Modem.cpp \ 15 | Modem/Ymodem.cpp \ 16 | Modem/crc16.c 17 | 18 | HEADERS += \ 19 | simple/mainwindow.h \ 20 | simple/settingsdialog.h \ 21 | SendSave/SendSave.h \ 22 | SendSave/SSWorker.h \ 23 | QTermWidget/QTermScreen.h \ 24 | QTermWidget/QTermWidget.h \ 25 | Modem/Modem.h \ 26 | Modem/Ymodem.h \ 27 | Modem/crc.h 28 | 29 | FORMS += \ 30 | simple/mainwindow.ui \ 31 | simple/settingsdialog.ui \ 32 | SendSave/SendSave.ui \ 33 | Modem/modem.ui 34 | 35 | RESOURCES += \ 36 | simple/terminal.qrc 37 | -------------------------------------------------------------------------------- /simple/main.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2012 Denis Shienkov 4 | ** Copyright (C) 2012 Laszlo Papp 5 | ** Contact: https://www.qt.io/licensing/ 6 | ** 7 | ** This file is part of the QtSerialPort module of the Qt Toolkit. 8 | ** 9 | ** $QT_BEGIN_LICENSE:BSD$ 10 | ** Commercial License Usage 11 | ** Licensees holding valid commercial Qt licenses may use this file in 12 | ** accordance with the commercial license agreement provided with the 13 | ** Software or, alternatively, in accordance with the terms contained in 14 | ** a written agreement between you and The Qt Company. For licensing terms 15 | ** and conditions see https://www.qt.io/terms-conditions. For further 16 | ** information use the contact form at https://www.qt.io/contact-us. 17 | ** 18 | ** BSD License Usage 19 | ** Alternatively, you may use this file under the terms of the BSD license 20 | ** as follows: 21 | ** 22 | ** "Redistribution and use in source and binary forms, with or without 23 | ** modification, are permitted provided that the following conditions are 24 | ** met: 25 | ** * Redistributions of source code must retain the above copyright 26 | ** notice, this list of conditions and the following disclaimer. 27 | ** * Redistributions in binary form must reproduce the above copyright 28 | ** notice, this list of conditions and the following disclaimer in 29 | ** the documentation and/or other materials provided with the 30 | ** distribution. 31 | ** * Neither the name of The Qt Company Ltd nor the names of its 32 | ** contributors may be used to endorse or promote products derived 33 | ** from this software without specific prior written permission. 34 | ** 35 | ** 36 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 37 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 38 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 39 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 40 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 41 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 42 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 43 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 44 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 45 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 46 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 47 | ** 48 | ** $QT_END_LICENSE$ 49 | ** 50 | ****************************************************************************/ 51 | 52 | #include 53 | 54 | #include "mainwindow.h" 55 | 56 | int main(int argc, char *argv[]) 57 | { 58 | QApplication a(argc, argv); 59 | 60 | qRegisterMetaType("string"); 61 | 62 | MainWindow w; 63 | w.show(); 64 | return a.exec(); 65 | } 66 | -------------------------------------------------------------------------------- /simple/mainwindow.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2012 Denis Shienkov 4 | ** Copyright (C) 2012 Laszlo Papp 5 | ** Contact: https://www.qt.io/licensing/ 6 | ** 7 | ** This file is part of the QtSerialPort module of the Qt Toolkit. 8 | ** 9 | ** $QT_BEGIN_LICENSE:BSD$ 10 | ** Commercial License Usage 11 | ** Licensees holding valid commercial Qt licenses may use this file in 12 | ** accordance with the commercial license agreement provided with the 13 | ** Software or, alternatively, in accordance with the terms contained in 14 | ** a written agreement between you and The Qt Company. For licensing terms 15 | ** and conditions see https://www.qt.io/terms-conditions. For further 16 | ** information use the contact form at https://www.qt.io/contact-us. 17 | ** 18 | ** BSD License Usage 19 | ** Alternatively, you may use this file under the terms of the BSD license 20 | ** as follows: 21 | ** 22 | ** "Redistribution and use in source and binary forms, with or without 23 | ** modification, are permitted provided that the following conditions are 24 | ** met: 25 | ** * Redistributions of source code must retain the above copyright 26 | ** notice, this list of conditions and the following disclaimer. 27 | ** * Redistributions in binary form must reproduce the above copyright 28 | ** notice, this list of conditions and the following disclaimer in 29 | ** the documentation and/or other materials provided with the 30 | ** distribution. 31 | ** * Neither the name of The Qt Company Ltd nor the names of its 32 | ** contributors may be used to endorse or promote products derived 33 | ** from this software without specific prior written permission. 34 | ** 35 | ** 36 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 37 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 38 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 39 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 40 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 41 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 42 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 43 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 44 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 45 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 46 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 47 | ** 48 | ** $QT_END_LICENSE$ 49 | ** 50 | ****************************************************************************/ 51 | 52 | #ifndef MAINWINDOW_H 53 | #define MAINWINDOW_H 54 | 55 | #include 56 | 57 | #include 58 | #include 59 | #include 60 | #include 61 | 62 | using namespace std; 63 | 64 | #include "QTermWidget/QTermWidget.h" 65 | 66 | QT_BEGIN_NAMESPACE 67 | 68 | class QLabel; 69 | class SendSave; 70 | 71 | namespace Ui { 72 | class MainWindow; 73 | } 74 | 75 | QT_END_NAMESPACE 76 | 77 | class SettingsDialog; 78 | class Modem; 79 | class QTimer; 80 | 81 | class MainWindow : public QMainWindow 82 | { 83 | Q_OBJECT 84 | 85 | public: 86 | explicit MainWindow(QWidget *parent = 0); 87 | ~MainWindow(); 88 | 89 | private slots: 90 | void openSerialPort(); 91 | void closeSerialPort(); 92 | void about(); 93 | void writeData(const QByteArray &data); 94 | void readData(); 95 | void startModem(); 96 | void handleError(QSerialPort::SerialPortError error); 97 | void showStatus(string s); 98 | void exitTransfer(); 99 | 100 | void on_actionClear_triggered(); 101 | 102 | protected: 103 | virtual void dropEvent(QDropEvent *event); 104 | virtual void dragEnterEvent(QDragEnterEvent *event); 105 | 106 | private: 107 | void initActionsConnections(); 108 | 109 | private: 110 | void showStatusMessage(const QString &message); 111 | 112 | Ui::MainWindow *ui; 113 | QLabel *status; 114 | SettingsDialog *settings; 115 | QSerialPort *serial; 116 | SendSave *dlgSS; 117 | QTermWidget *term; 118 | Modem *modem; 119 | bool m_modemEn; 120 | QTimer *modemCheck; 121 | }; 122 | 123 | #endif // MAINWINDOW_H 124 | -------------------------------------------------------------------------------- /simple/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 861 10 | 693 11 | 12 | 13 | 14 | 15 | Consolas 16 | 12 17 | 18 | 19 | 20 | QyTerm 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 0 32 | 0 33 | 861 34 | 23 35 | 36 | 37 | 38 | 39 | Calls 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | Tools 49 | 50 | 51 | 52 | 53 | 54 | 55 | Help 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | TopToolBarArea 67 | 68 | 69 | false 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 14 80 | 81 | 82 | 83 | 84 | 85 | &About 86 | 87 | 88 | About program 89 | 90 | 91 | Alt+A 92 | 93 | 94 | 95 | 96 | About Qt 97 | 98 | 99 | 100 | 101 | 102 | :/images/connect.png:/images/connect.png 103 | 104 | 105 | C&onnect 106 | 107 | 108 | Connect to serial port 109 | 110 | 111 | Ctrl+O 112 | 113 | 114 | 115 | 116 | 117 | :/images/disconnect.png:/images/disconnect.png 118 | 119 | 120 | &Disconnect 121 | 122 | 123 | Disconnect from serial port 124 | 125 | 126 | Ctrl+D 127 | 128 | 129 | 130 | 131 | 132 | :/images/settings.png:/images/settings.png 133 | 134 | 135 | &Configure 136 | 137 | 138 | Configure serial port 139 | 140 | 141 | Alt+C 142 | 143 | 144 | 145 | 146 | 147 | :/images/clear.png:/images/clear.png 148 | 149 | 150 | C&lear 151 | 152 | 153 | Clear data 154 | 155 | 156 | Alt+L 157 | 158 | 159 | 160 | 161 | 162 | :/images/application-exit.png:/images/application-exit.png 163 | 164 | 165 | &Quit 166 | 167 | 168 | Ctrl+Q 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | -------------------------------------------------------------------------------- /simple/settingsdialog.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2012 Denis Shienkov 4 | ** Copyright (C) 2012 Laszlo Papp 5 | ** Contact: http://www.qt-project.org/legal 6 | ** 7 | ** This file is part of the QtSerialPort module of the Qt Toolkit. 8 | ** 9 | ** $QT_BEGIN_LICENSE:LGPL$ 10 | ** Commercial License Usage 11 | ** Licensees holding valid commercial Qt licenses may use this file in 12 | ** accordance with the commercial license agreement provided with the 13 | ** Software or, alternatively, in accordance with the terms contained in 14 | ** a written agreement between you and Digia. For licensing terms and 15 | ** conditions see http://qt.digia.com/licensing. For further information 16 | ** use the contact form at http://qt.digia.com/contact-us. 17 | ** 18 | ** GNU Lesser General Public License Usage 19 | ** Alternatively, this file may be used under the terms of the GNU Lesser 20 | ** General Public License version 2.1 as published by the Free Software 21 | ** Foundation and appearing in the file LICENSE.LGPL included in the 22 | ** packaging of this file. Please review the following information to 23 | ** ensure the GNU Lesser General Public License version 2.1 requirements 24 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 25 | ** 26 | ** In addition, as a special exception, Digia gives you certain additional 27 | ** rights. These rights are described in the Digia Qt LGPL Exception 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 29 | ** 30 | ** GNU General Public License Usage 31 | ** Alternatively, this file may be used under the terms of the GNU 32 | ** General Public License version 3.0 as published by the Free Software 33 | ** Foundation and appearing in the file LICENSE.GPL included in the 34 | ** packaging of this file. Please review the following information to 35 | ** ensure the GNU General Public License version 3.0 requirements will be 36 | ** met: http://www.gnu.org/copyleft/gpl.html. 37 | ** 38 | ** 39 | ** $QT_END_LICENSE$ 40 | ** 41 | ****************************************************************************/ 42 | 43 | #include "settingsdialog.h" 44 | #include "ui_settingsdialog.h" 45 | 46 | #include 47 | #include 48 | #include 49 | 50 | QT_USE_NAMESPACE 51 | 52 | SettingsDialog::SettingsDialog(QWidget *parent) : 53 | QDialog(parent), 54 | ui(new Ui::SettingsDialog) 55 | { 56 | ui->setupUi(this); 57 | 58 | intValidator = new QIntValidator(0, 4000000, this); 59 | 60 | ui->baudRateBox->setInsertPolicy(QComboBox::NoInsert); 61 | 62 | connect(ui->applyButton, SIGNAL(clicked()), 63 | this, SLOT(apply())); 64 | connect(ui->serialPortInfoListBox, SIGNAL(currentIndexChanged(int)), 65 | this, SLOT(showPortInfo(int))); 66 | connect(ui->baudRateBox, SIGNAL(currentIndexChanged(int)), 67 | this, SLOT(checkCustomBaudRatePolicy(int))); 68 | 69 | fillPortsParameters(); 70 | fillPortsInfo(); 71 | 72 | updateSettings(); 73 | } 74 | 75 | SettingsDialog::~SettingsDialog() 76 | { 77 | delete ui; 78 | } 79 | 80 | SettingsDialog::Settings SettingsDialog::settings() const 81 | { 82 | return currentSettings; 83 | } 84 | 85 | void SettingsDialog::showPortInfo(int idx) 86 | { 87 | if (idx != -1) 88 | { 89 | QStringList list = ui->serialPortInfoListBox->itemData(idx).toStringList(); 90 | ui->descriptionLabel->setText(tr("描述: %1").arg(list.at(1))); 91 | } 92 | } 93 | 94 | void SettingsDialog::apply() 95 | { 96 | updateSettings(); 97 | hide(); 98 | } 99 | 100 | void SettingsDialog::checkCustomBaudRatePolicy(int idx) 101 | { 102 | bool isCustomBaudRate = !ui->baudRateBox->itemData(idx).isValid(); 103 | ui->baudRateBox->setEditable(isCustomBaudRate); 104 | if (isCustomBaudRate) 105 | { 106 | ui->baudRateBox->clearEditText(); 107 | QLineEdit *edit = ui->baudRateBox->lineEdit(); 108 | edit->setValidator(intValidator); 109 | } 110 | } 111 | 112 | void SettingsDialog::fillPortsParameters() 113 | { 114 | ui->baudRateBox->addItem(QStringLiteral("9600"), QSerialPort::Baud9600); 115 | ui->baudRateBox->addItem(QStringLiteral("19200"), QSerialPort::Baud19200); 116 | ui->baudRateBox->addItem(QStringLiteral("38400"), QSerialPort::Baud38400); 117 | ui->baudRateBox->addItem(QStringLiteral("115200"), QSerialPort::Baud115200); 118 | ui->baudRateBox->addItem(QStringLiteral("961200"), 961200); 119 | ui->baudRateBox->addItem(QStringLiteral("自定义")); 120 | ui->baudRateBox->setCurrentIndex(3); 121 | 122 | ui->dataBitsBox->addItem(QStringLiteral("5"), QSerialPort::Data5); 123 | ui->dataBitsBox->addItem(QStringLiteral("6"), QSerialPort::Data6); 124 | ui->dataBitsBox->addItem(QStringLiteral("7"), QSerialPort::Data7); 125 | ui->dataBitsBox->addItem(QStringLiteral("8"), QSerialPort::Data8); 126 | ui->dataBitsBox->setCurrentIndex(3); 127 | 128 | ui->parityBox->addItem(QStringLiteral("None"), QSerialPort::NoParity); 129 | ui->parityBox->addItem(QStringLiteral("Even"), QSerialPort::EvenParity); 130 | ui->parityBox->addItem(QStringLiteral("Odd"), QSerialPort::OddParity); 131 | ui->parityBox->addItem(QStringLiteral("Mark"), QSerialPort::MarkParity); 132 | ui->parityBox->addItem(QStringLiteral("Space"), QSerialPort::SpaceParity); 133 | 134 | ui->stopBitsBox->addItem(QStringLiteral("1"), QSerialPort::OneStop); 135 | ui->stopBitsBox->addItem(QStringLiteral("2"), QSerialPort::TwoStop); 136 | 137 | ui->flowControlBox->addItem(QStringLiteral("None"), QSerialPort::NoFlowControl); 138 | ui->flowControlBox->addItem(QStringLiteral("RTS/CTS"), QSerialPort::HardwareControl); 139 | ui->flowControlBox->addItem(QStringLiteral("XON/XOFF"), QSerialPort::SoftwareControl); 140 | } 141 | 142 | void SettingsDialog::fillPortsInfo() 143 | { 144 | static const QString blankString = QObject::tr("N/A"); 145 | QString description; 146 | QStringList list; 147 | 148 | ui->serialPortInfoListBox->clear(); 149 | 150 | list << QString(tr("刷新")) 151 | << QString(tr("点击更新列表")); 152 | ui->serialPortInfoListBox->addItem(list.first(), list); 153 | 154 | foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) 155 | { 156 | QStringList list; 157 | description = info.description(); 158 | 159 | list << info.portName() 160 | << (!description.isEmpty() ? description : blankString); 161 | 162 | ui->serialPortInfoListBox->addItem(list.first(), list); 163 | } 164 | 165 | if (ui->serialPortInfoListBox->count() != 1) 166 | { 167 | ui->serialPortInfoListBox->setCurrentIndex(1); 168 | } 169 | } 170 | 171 | void SettingsDialog::updateSettings() 172 | { 173 | currentSettings.name = ui->serialPortInfoListBox->currentText(); 174 | 175 | if (ui->baudRateBox->currentIndex() == 4) 176 | { 177 | currentSettings.baudRate = ui->baudRateBox->currentText().toInt(); 178 | } 179 | else 180 | { 181 | currentSettings.baudRate = static_cast( 182 | ui->baudRateBox->itemData(ui->baudRateBox->currentIndex()).toInt()); 183 | } 184 | 185 | currentSettings.stringBaudRate = QString::number(currentSettings.baudRate); 186 | 187 | currentSettings.dataBits = static_cast( 188 | ui->dataBitsBox->itemData(ui->dataBitsBox->currentIndex()).toInt()); 189 | currentSettings.stringDataBits = ui->dataBitsBox->currentText(); 190 | 191 | currentSettings.parity = static_cast( 192 | ui->parityBox->itemData(ui->parityBox->currentIndex()).toInt()); 193 | currentSettings.stringParity = ui->parityBox->currentText(); 194 | 195 | currentSettings.stopBits = static_cast( 196 | ui->stopBitsBox->itemData(ui->stopBitsBox->currentIndex()).toInt()); 197 | currentSettings.stringStopBits = ui->stopBitsBox->currentText(); 198 | 199 | currentSettings.flowControl = static_cast( 200 | ui->flowControlBox->itemData(ui->flowControlBox->currentIndex()).toInt()); 201 | currentSettings.stringFlowControl = ui->flowControlBox->currentText(); 202 | } 203 | 204 | void SettingsDialog::on_serialPortInfoListBox_activated(int index) 205 | { 206 | if (index == 0) 207 | { 208 | fillPortsInfo(); 209 | } 210 | } 211 | -------------------------------------------------------------------------------- /simple/settingsdialog.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2012 Denis Shienkov 4 | ** Copyright (C) 2012 Laszlo Papp 5 | ** Contact: http://www.qt-project.org/legal 6 | ** 7 | ** This file is part of the QtSerialPort module of the Qt Toolkit. 8 | ** 9 | ** $QT_BEGIN_LICENSE:LGPL$ 10 | ** Commercial License Usage 11 | ** Licensees holding valid commercial Qt licenses may use this file in 12 | ** accordance with the commercial license agreement provided with the 13 | ** Software or, alternatively, in accordance with the terms contained in 14 | ** a written agreement between you and Digia. For licensing terms and 15 | ** conditions see http://qt.digia.com/licensing. For further information 16 | ** use the contact form at http://qt.digia.com/contact-us. 17 | ** 18 | ** GNU Lesser General Public License Usage 19 | ** Alternatively, this file may be used under the terms of the GNU Lesser 20 | ** General Public License version 2.1 as published by the Free Software 21 | ** Foundation and appearing in the file LICENSE.LGPL included in the 22 | ** packaging of this file. Please review the following information to 23 | ** ensure the GNU Lesser General Public License version 2.1 requirements 24 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 25 | ** 26 | ** In addition, as a special exception, Digia gives you certain additional 27 | ** rights. These rights are described in the Digia Qt LGPL Exception 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 29 | ** 30 | ** GNU General Public License Usage 31 | ** Alternatively, this file may be used under the terms of the GNU 32 | ** General Public License version 3.0 as published by the Free Software 33 | ** Foundation and appearing in the file LICENSE.GPL included in the 34 | ** packaging of this file. Please review the following information to 35 | ** ensure the GNU General Public License version 3.0 requirements will be 36 | ** met: http://www.gnu.org/copyleft/gpl.html. 37 | ** 38 | ** 39 | ** $QT_END_LICENSE$ 40 | ** 41 | ****************************************************************************/ 42 | 43 | #ifndef SETTINGSDIALOG_H 44 | #define SETTINGSDIALOG_H 45 | 46 | #include 47 | #include 48 | 49 | QT_USE_NAMESPACE 50 | 51 | QT_BEGIN_NAMESPACE 52 | 53 | namespace Ui { 54 | class SettingsDialog; 55 | } 56 | 57 | class QIntValidator; 58 | 59 | QT_END_NAMESPACE 60 | 61 | class SettingsDialog : public QDialog 62 | { 63 | Q_OBJECT 64 | 65 | public: 66 | struct Settings 67 | { 68 | QString name; 69 | qint32 baudRate; 70 | QString stringBaudRate; 71 | QSerialPort::DataBits dataBits; 72 | QString stringDataBits; 73 | QSerialPort::Parity parity; 74 | QString stringParity; 75 | QSerialPort::StopBits stopBits; 76 | QString stringStopBits; 77 | QSerialPort::FlowControl flowControl; 78 | QString stringFlowControl; 79 | bool localEchoEnabled; 80 | }; 81 | 82 | explicit SettingsDialog(QWidget *parent = 0); 83 | ~SettingsDialog(); 84 | 85 | Settings settings() const; 86 | 87 | private slots: 88 | void showPortInfo(int idx); 89 | void apply(); 90 | void checkCustomBaudRatePolicy(int idx); 91 | 92 | void on_serialPortInfoListBox_activated(int index); 93 | 94 | private: 95 | void fillPortsParameters(); 96 | void fillPortsInfo(); 97 | void updateSettings(); 98 | 99 | private: 100 | Ui::SettingsDialog *ui; 101 | Settings currentSettings; 102 | QIntValidator *intValidator; 103 | }; 104 | 105 | #endif // SETTINGSDIALOG_H 106 | -------------------------------------------------------------------------------- /simple/settingsdialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | SettingsDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 327 10 | 263 11 | 12 | 13 | 14 | 设置 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Qt::Horizontal 23 | 24 | 25 | 26 | 96 27 | 20 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 应用 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 端口选择 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 描述: 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 参数设置 64 | 65 | 66 | 67 | 68 | 69 | 波特率 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 数据位 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 校验 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 停止位 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 流控 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /simple/terminal.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ../images/application-exit.png 4 | ../images/clear.png 5 | ../images/connect.png 6 | ../images/disconnect.png 7 | ../images/settings.png 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/dialog.cpp: -------------------------------------------------------------------------------- 1 | #include "dialog.h" 2 | #include "ui_dialog.h" 3 | 4 | Dialog::Dialog(QWidget *parent) : 5 | QDialog(parent), 6 | ui(new Ui::Dialog) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | Dialog::~Dialog() 12 | { 13 | delete ui; 14 | } 15 | 16 | void Dialog::on_home_clicked() 17 | { 18 | QByteArray data; 19 | QString r,c,t; 20 | 21 | r = ui->row->text(); 22 | c = ui->column->text(); 23 | t = "\x1B[" + r + ";" + c + "H"; 24 | data = t.toLocal8Bit(); 25 | 26 | emit outData(data); 27 | } 28 | 29 | void Dialog::on_start_clicked() 30 | { 31 | QByteArray data = "\r行首"; 32 | 33 | emit outData(data); 34 | } 35 | 36 | void Dialog::on_up_clicked() 37 | { 38 | QByteArray data = "\x1B[A"; 39 | 40 | emit outData(data); 41 | } 42 | 43 | void Dialog::on_down_clicked() 44 | { 45 | QByteArray data = "\x1B[B"; 46 | 47 | emit outData(data); 48 | } 49 | 50 | void Dialog::on_left_clicked() 51 | { 52 | QByteArray data = "\x1B[C"; 53 | 54 | emit outData(data); 55 | } 56 | 57 | void Dialog::on_right_clicked() 58 | { 59 | QByteArray data = "\x1B[D"; 60 | 61 | emit outData(data); 62 | } 63 | 64 | void Dialog::on_reset_clicked() 65 | { 66 | QByteArray data = "\x1B[0myes"; 67 | 68 | emit outData(data); 69 | } 70 | 71 | void Dialog::on_color_clicked() 72 | { 73 | QByteArray data; 74 | QString b,f,t; 75 | 76 | b = ui->back->currentText(); 77 | f = ui->fore->currentText(); 78 | t = "\x1B[" + b + ";" + f + "mtest"; 79 | data = t.toLocal8Bit(); 80 | 81 | emit outData(data); 82 | } 83 | 84 | void Dialog::on_lend_clicked() 85 | { 86 | QByteArray data = "\x1B[K"; 87 | 88 | emit outData(data); 89 | } 90 | 91 | void Dialog::on_lstart_clicked() 92 | { 93 | QByteArray data = "\x1B[1K"; 94 | 95 | emit outData(data); 96 | } 97 | 98 | void Dialog::on_lentire_clicked() 99 | { 100 | QByteArray data = "\x1B[2K"; 101 | 102 | emit outData(data); 103 | } 104 | 105 | void Dialog::on_ldown_clicked() 106 | { 107 | QByteArray data = "\x1B[J"; 108 | 109 | emit outData(data); 110 | } 111 | 112 | void Dialog::on_lup_clicked() 113 | { 114 | QByteArray data = "\x1B[1J"; 115 | 116 | emit outData(data); 117 | } 118 | 119 | void Dialog::on_screen_clicked() 120 | { 121 | QByteArray data = "\x1B[2J"; 122 | 123 | emit outData(data); 124 | } 125 | 126 | void Dialog::on_crlf_clicked() 127 | { 128 | QByteArray data = "\x0D\x0Alala"; 129 | 130 | emit outData(data); 131 | } 132 | 133 | void Dialog::on_nl_clicked() 134 | { 135 | QByteArray data = "\r\n"; 136 | 137 | emit outData(data); 138 | } 139 | 140 | void Dialog::on_test1_clicked() 141 | { 142 | char ch[] ={0x0D, 0x0A, 143 | 0x1B, 0x5B, 0x31, 0x3B, 0x31, 0x48, 0x1B, 0x5B, 0x30, 0x4A, 144 | 0x0D, 0x70, 0x72, 0x6F, 0x63, 0x20, 0x20, 0x20, 0x20, 0x20, 145 | 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2F, 0x70, 0x72, 146 | 0x6F, 0x63, 0x20, 0x20, 0x20, 0x70, 0x72, 0x6F, 0x63, 0x20, 147 | 0x20, 0x20, 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6C, 0x74, 148 | 0x73, 0x20, 0x20, 0x20, 0x20, 0x30, 0x20, 0x20, 0x20, 0x30, 149 | 0x0A, 0x0D, 0x73, 0x79, 0x73, 0x66, 0x73, 0x20, 0x20, 0x20, 150 | 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2F, 0x73, 151 | 0x79, 0x73, 0x20, 0x20, 0x20, 0x20, 0x73, 0x79, 0x73, 0x66, 152 | 0x73, 0x20, 0x20, 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6C, 153 | 0x74, 0x73, 0x20, 0x20, 0x20, 0x20, 0x30, 0x20, 0x20, 0x20, 154 | 0x30, 0x0A, 0x0D, 0x7E, 0x0A, 0x0D, 0x7E, 0x0A, 0x0D, 0x7E, 155 | 0x0A, 0x0D, 0x7E, 0x0A, 0x0D, 0x7E, 0x0A, 0x0D, 0x7E, 0x0A, 0x0D, 156 | 0x7E, 0x0A, 0x0D, 0x7E, 0x0A, 0x0D, 0x7E, 0x0A, 0x0D, 0x7E, 157 | 0x0A, 0x0D, 0x7E, 0x0A, 0x0D, 0x7E, 0x0A, 0x0D, 0x7E, 0x0A, 0x0D, 158 | 0x7E, 0x0A, 0x0D, 0x7E, 0x0A, 0x0D, 0x7E, 0x0A, 0x0D, 0x7E, 0x0A, 0x0D, 159 | 0x7E, 0x0A, 0x0D, 0x7E, 0x0A, 0x0D, 0x7E, 0x0A, 0x0D, 0x7E, 160 | 0x1B, 0x5B, 0x31, 0x3B, 0x31, 0x48, 0x1B, 0x5B, 0x32, 0x34, 0x3B, 0x31, 0x48, 161 | 0x1B, 0x5B, 0x30, 0x4B, 162 | 0x2D, 0x20, 0x66, 0x73, 0x74, 0x61, 0x62, 0x20, 0x31, 0x2F, 0x32, 0x20, 163 | 0x35, 0x30, 0x25, 0x1B, 0x5B, 0x31, 0x3B, 0x31, 0x48, 164 | 0x00 165 | }; 166 | 167 | QByteArray data = ch; 168 | 169 | emit outData(data); 170 | } 171 | 172 | void Dialog::on_test2_clicked() 173 | { 174 | char ch[] = 175 | { 176 | 0x0D, 0x0A, 177 | #if 1 178 | 0x1B, 0x5B, 0x3F, 0x31, 0x30, 0x34, 0x39, 0x68, 179 | #endif 180 | 0x1B, 0x5B, 0x31, 0x3B, 0x31, 0x48, 181 | 0x1B, 0x5B, 0x4A, 182 | 0x1B, 0x5B, 0x32, 0x3B, 0x31, 0x48, 0x7E, 183 | #if 1 184 | 0x1B, 0x5B, 0x33, 0x3B, 0x31, 0x48, 0x7E, 185 | 0x1B, 0x5B, 0x34, 0x3B, 0x31, 0x48, 0x7E, 186 | 0x1B, 0x5B, 0x35, 0x3B, 0x31, 0x48, 0x7E, 187 | 188 | 0x1B, 0x5B, 0x36, 0x3B, 0x31, 0x48, 0x7E, 189 | 0x1B, 0x5B, 0x37, 0x3B, 0x31, 0x48, 0x7E, 190 | 0x1B, 0x5B, 0x38, 0x3B, 0x31, 0x48, 0x7E, 191 | 0x1B, 0x5B, 0x39, 0x3B, 0x31, 0x48, 0x7E, 192 | 0x1B, 0x5B, 0x31, 0x30, 0x3B, 0x31, 0x48, 0x7E, 193 | 0x1B, 0x5B, 0x31, 0x31, 0x3B, 0x31, 0x48, 0x7E, 194 | 0x1B, 0x5B, 0x31, 0x32, 0x3B, 0x31, 0x48, 0x7E, 195 | 0x1B, 0x5B, 0x31, 0x33, 0x3B, 0x31, 0x48, 0x7E, 196 | 0x1B, 0x5B, 0x31, 0x34, 0x3B, 0x31, 0x48, 0x7E, 197 | 0x1B, 0x5B, 0x31, 0x35, 0x3B, 0x31, 0x48, 0x7E, 198 | 0x1B, 0x5B, 0x31, 0x36, 0x3B, 0x31, 0x48, 0x7E, 199 | 0x1B, 0x5B, 0x31, 0x37, 0x3B, 0x31, 0x48, 0x7E, 200 | 0x1B, 0x5B, 0x31, 0x38, 0x3B, 0x31, 0x48, 0x7E, 201 | 0x1B, 0x5B, 0x31, 0x39, 0x3B, 0x31, 0x48, 0x7E, 202 | 0x1B, 0x5B, 0x32, 0x30, 0x3B, 0x31, 0x48, 0x7E, 203 | 0x1B, 0x5B, 0x32, 0x31, 0x3B, 0x31, 0x48, 0x7E, 204 | 0x1B, 0x5B, 0x32, 0x32, 0x3B, 0x31, 0x48, 0x7E, 205 | 0x1B, 0x5B, 0x32, 0x33, 0x3B, 0x31, 0x48, 0x7E, 206 | #endif 207 | 208 | #if 1 209 | 0x1B, 0x5B, 0x31, 0x3B, 0x31, 0x48, 210 | 0x1B, 0x5B, 0x32, 0x34, 0x3B, 0x31, 0x48, 211 | 0x1B, 0x5B, 0x4B, 0x2D, 0x20, 0x65, 0x65, 0x20, 0x5B, 0x4D, 0x6F, 0x64, 0x69, 0x66, 0x69, 0x65, 0x64, 0x5D, 0x20, 0x31, 0x2F, 0x31, 0x20, 0x31, 0x30, 0x30, 0x25, 212 | 0x1B, 0x5B, 0x31, 0x3B, 0x31, 0x48, 213 | #endif 214 | 0x00 215 | }; 216 | 217 | QByteArray data = ch; 218 | 219 | emit outData(data); 220 | } 221 | 222 | void Dialog::on_test3_clicked() 223 | { 224 | char ch[] = 225 | { 226 | 0x0D, 0x0A, 227 | 0x1B, 0x5B, 0x31, 0x3B, 0x31, 0x48, 228 | 0x1B, 0x5B, 0x30, 0x4A, 229 | 0x0D, 230 | 0x70, 0x72, 0x6F, 0x63, 0x20, 0x20, 0x20, 0x20, 0x20, 231 | 0x1B, 0x5B, 0x31, 0x3B, 0x31, 0x48, 232 | 0x00 233 | }; 234 | 235 | QByteArray data = ch; 236 | 237 | emit outData(data); 238 | } 239 | 240 | void Dialog::on_cn_clicked() 241 | { 242 | QByteArray data = "cn中文\n"; 243 | 244 | emit outData(data); 245 | } 246 | 247 | void Dialog::on_add_clicked() 248 | { 249 | QByteArray data = "\ncnaaddddddddd"; 250 | 251 | emit outData(data); 252 | } 253 | 254 | void Dialog::on_pushButton_clicked() 255 | { 256 | char ch[] = 257 | { 258 | 0x1B, 0x5B, 0x31, 0x3B, 0x33, 0x34, 0x6D, 0x73, 0x68, 0x61, 0x72, 0x65, 259 | 0x1B, 0x5B, 0x30, 0x6D, 0x0D, 0x0A, 260 | 0x1B, 0x5B, 0x31, 0x3B, 0x33, 0x34, 0x6D, 0x77, 0x77, 0x77, 261 | 0x1B, 0x5B, 0x30, 0x6D, 0x0D, 0x0A, 262 | 0x5B, 0x72, 0x6F, 0x6F, 0x74, 0x40, 0x51, 0x54, 0x3A, 0x2F, 0x75, 0x73, 0x72, 0x5D, 0x23, 0x20, 0x0D, 0x0A, 263 | 0x00 264 | }; 265 | 266 | QByteArray data = ch; 267 | 268 | emit outData(data); 269 | } 270 | -------------------------------------------------------------------------------- /test/dialog.h: -------------------------------------------------------------------------------- 1 | #ifndef DIALOG_H 2 | #define DIALOG_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class Dialog; 8 | } 9 | 10 | class Dialog : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit Dialog(QWidget *parent = 0); 16 | ~Dialog(); 17 | 18 | signals: 19 | void outData(const QByteArray &data); 20 | 21 | private slots: 22 | void on_home_clicked(); 23 | 24 | void on_start_clicked(); 25 | 26 | void on_up_clicked(); 27 | 28 | void on_down_clicked(); 29 | 30 | void on_left_clicked(); 31 | 32 | void on_right_clicked(); 33 | 34 | void on_reset_clicked(); 35 | 36 | void on_color_clicked(); 37 | 38 | void on_lend_clicked(); 39 | 40 | void on_lstart_clicked(); 41 | 42 | void on_lentire_clicked(); 43 | 44 | void on_ldown_clicked(); 45 | 46 | void on_lup_clicked(); 47 | 48 | void on_screen_clicked(); 49 | 50 | void on_crlf_clicked(); 51 | 52 | void on_nl_clicked(); 53 | 54 | void on_test1_clicked(); 55 | 56 | void on_test2_clicked(); 57 | 58 | void on_test3_clicked(); 59 | 60 | void on_cn_clicked(); 61 | 62 | void on_add_clicked(); 63 | 64 | void on_pushButton_clicked(); 65 | 66 | private: 67 | Ui::Dialog *ui; 68 | }; 69 | 70 | #endif // DIALOG_H 71 | -------------------------------------------------------------------------------- /test/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /test/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | 4 | #include "dialog.h" 5 | #include "QTermWidget.h" 6 | 7 | MainWindow::MainWindow(QWidget *parent) : 8 | QMainWindow(parent), 9 | ui(new Ui::MainWindow) 10 | { 11 | ui->setupUi(this); 12 | 13 | test = new Dialog; 14 | term = new QTermWidget; 15 | 16 | setCentralWidget(term); 17 | 18 | connect(test, &test->outData, term, &term->putData); 19 | 20 | statusBar()->addWidget(ui->bttest); 21 | test->show(); 22 | } 23 | 24 | MainWindow::~MainWindow() 25 | { 26 | delete ui; 27 | } 28 | 29 | void MainWindow::on_bttest_clicked() 30 | { 31 | test->show(); 32 | test->activateWindow(); 33 | } 34 | -------------------------------------------------------------------------------- /test/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class Dialog; 11 | class QTermWidget; 12 | 13 | class MainWindow : public QMainWindow 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | explicit MainWindow(QWidget *parent = 0); 19 | ~MainWindow(); 20 | 21 | private slots: 22 | 23 | void on_bttest_clicked(); 24 | 25 | private: 26 | Ui::MainWindow *ui; 27 | Dialog *test; 28 | QTermWidget *term; 29 | }; 30 | 31 | #endif // MAINWINDOW_H 32 | -------------------------------------------------------------------------------- /test/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 792 10 | 588 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 120 21 | 130 22 | 93 23 | 28 24 | 25 | 26 | 27 | 测试 28 | 29 | 30 | 31 | 32 | 33 | 34 | 0 35 | 0 36 | 792 37 | 26 38 | 39 | 40 | 41 | 42 | 43 | TopToolBarArea 44 | 45 | 46 | false 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /test/test.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2017-01-04T14:16:14 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = test 12 | TEMPLATE = app 13 | 14 | INCLUDEPATH += ../QTermWidget 15 | 16 | SOURCES += main.cpp\ 17 | mainwindow.cpp \ 18 | dialog.cpp \ 19 | ../QTermWidget/QTermScreen.cpp \ 20 | ../QTermWidget/QTermWidget.cpp 21 | 22 | HEADERS += mainwindow.h \ 23 | dialog.h \ 24 | ../QTermWidget/QTermScreen.h \ 25 | ../QTermWidget/QTermWidget.h 26 | 27 | FORMS += mainwindow.ui \ 28 | dialog.ui 29 | -------------------------------------------------------------------------------- /winpty-agent.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heyuanjie87/QTerminal/9635df9c2aabd3136847c7ad71bc029249bc433f/winpty-agent.exe -------------------------------------------------------------------------------- /winpty.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heyuanjie87/QTerminal/9635df9c2aabd3136847c7ad71bc029249bc433f/winpty.dll --------------------------------------------------------------------------------