File: e2cmdw.h

package info (click to toggle)
ponyprog 3.1.4%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,904 kB
  • sloc: cpp: 35,932; python: 981; sh: 565; xml: 67; makefile: 45; ansic: 38
file content (439 lines) | stat: -rw-r--r-- 10,678 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
//=========================================================================//
//                                                                         //
//  PonyProg - Serial Device Programmer                                    //
//                                                                         //
//  Copyright (C) 1997-2025   Claudio Lanconelli                           //
//                                                                         //
//  https://github.com/lancos/ponyprog                                        //
//                                                                         //
//-------------------------------------------------------------------------//
//                                                                         //
// This program is free software; you can redistribute it and/or           //
// modify it under the terms of the GNU  General Public License            //
// as published by the Free Software Foundation; either version2 of        //
// the License, or (at your option) any later version.                     //
//                                                                         //
// This program is distributed in the hope that it will be useful,         //
// but WITHOUT ANY WARRANTY; without even the implied warranty of          //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       //
// General Public License for more details.                                //
//                                                                         //
// You should have received a copy of the GNU  General Public License      //
// along with this program (see LICENSE);     if not, write to the         //
// Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. //
//                                                                         //
//=========================================================================//

#ifndef e2CMDW_H
#define e2CMDW_H


#include <QMainWindow>
#include <QTimer>
#include <QTextDocument>
#include <QLabel>
#include <QLineEdit>

#include <QProgressBar>

#include <QCloseEvent>
#include <QComboBox>
#include <QKeyEvent>
#include <QScrollArea>
#include <QImage>

#include <QProgressDialog>

#include <QActionGroup>
#include <QMenu>
#include <QVector>
#include <QFont>
#include <QSplitter>

#include "device.h"
#include "Translator.h"
#include "e2app.h"
#include "e2awinfo.h"


#include "ui_mainwindow.h"
#include "qhexedit.h"



struct menuToGroup
{
	QMenu *mnu;
	QString title;
	QString filter;
	QActionGroup *grp;
	// vector of main type
	QVector <int> pre_type;
	// copy of chipInfo
	QVector<chipInfo> info;
};


typedef enum
{
	verboseNo,
	verboseErr,
	verboseAll
} VerboseType;


class e2App;

class e2AppWinInfo;


class e2CmdWindow : public QMainWindow, public e2App, public Ui::MainWindow
{
	Q_OBJECT

  public:
	e2CmdWindow(QWidget *parent = 0);
	virtual ~e2CmdWindow();
	//      virtual int CloseAppWin();

	//      virtual void WindowCommand(ItemVal id, ItemVal val, CmdType cType);
	//      virtual void KeyIn(vKey keysym, unsigned int shift);

	void About();
	void Print();
	//      int NextLine();
	//      int PrevLine();
	//      void ScrollV(int top);

	void PostInit();
	//      void CharEdit(int row = -1, int col = -1);

	int IsBufChanged() const;

	void SetTitle();

	QString GetFileName();

	QProgressDialog *GetProgressDlg()
	{
		return e2Prg;
	}

	bool GetIgnoreFlag();
	void SetIgnoreFlag();

	void ClearIgnoreFlag();

	bool GetAbortFlag();
	void SetAbortFlag(bool a = true)
	{
		abortFlag = a;
	}

	void SetProgress(int progress = 0);

	bool IsAppBusy()
	{
		return (app_status == AppBusy);
	}
	bool IsAppReady()
	{
		return (app_status == AppReady);
	}

	void SetAppBusy();
	void SetAppReady();

	long GetCurrentChipType()
	{
		if (awip)
		{
			return awip->GetEEPId();
		}
		else
		{
			return EID_INVALID;
		}
	}

	//      virtual void DropFile(const char *fn);          //TODO use QDrag for drag&drop file into the buffer
	virtual void Exit();

	QString getStyleSheet()
	{
		return programStyleSheet;
	}


  private slots:
// 	void onNew();
	void onOpen(); //
	void onSave(); //
	void onSaveAs(); //
	void onReload(); //
	void onPrint(); //
	void onAboutQt();

	void onWrite(); //
	void onRead(); //
	void onErase(); //
	void onVerify(); //
	//void onRunScript();
	void onLoadScript(); //
	//void onDebugger();
	void onReset(); //
	void onInterfSetup();  //
	void onGetInfo(); //
	void onHelp(); //
	void onAbout(); //
	void onEditBufToggle(); //
	void onCalibration(); //
	void onProgram(); //
	void onByteSwap();
// 	void onLastFile1();
// 	void onLastFile2();
	void onDoubleSize();
	//     void onOverwriteMode(bool b);
	void onWriteHEndurance();
	void onAskToSave();
	//void onProgress(int val);
	//void onCloseAllDialog();

	void onSelectEEPType(int val);
	void onEEPSubType(int val);
	void onSetSerialNumber();
	void onClearBuf();
	void onEditNote();
	void onReadCalibration();
	void onReadSecurity(bool display_dialog);
	//void onWriteSecurity();
	void onFillBuf();
	void onSpecialBits();
	void onProgramOptions(); //
	void onSerialNumberOptions();
	void onOscCalibOption();
// 	void onClose(); //
	void onExit(); //
	void onDevType(int i);
	void onDevSubType(int i);

	// EK 2017: slot for signals from group actions
	void onSelectChip(QAction *a);

	//void onEndProgress();

	void selectFontSize(QAction *mnu);

	void setLang(QAction *mnu);
	//void setOverwriteMode(bool);
	//void dataChanged();

	void onSelectScript(QAction *a);
	void onSelectFile(QAction *a);
	void onDtaChanged();

	void on_actionPreferences_triggered();

  public:
	int CmdHelp();

  protected:
	//void CmdRemoteMode();
	void closeEvent(QCloseEvent *event) override;

  private:
	//All commands
	int CmdOpen(int type = ALL_TYPE, const QString &file = 0, long relocation = 0, int clear_buffer = -1);
	int CmdSave(int type = ALL_TYPE, const QString &file = 0, long relocation = 0);
	int CmdSaveAs(int type = ALL_TYPE, long relocation = 0);
	int CmdLastFile(int index = 0);
	int CmdReload();
	int CmdPrint();
	int CmdRead(int type = ALL_TYPE);
	int CmdWrite(int type = ALL_TYPE, bool verify = true);
	int CmdVerify(int type = ALL_TYPE);
	int CmdErase(int type = ALL_TYPE);
	int CmdGetInfo();
	int CmdReset();
	int CmdReadLock();
// 	int CmdWrite(int type);
	//      int CmdRunScript();
	int CmdLoadScript();
	int CmdWriteLock();
	int CmdReadSpecial();
	int CmdWriteSpecial();
	int CmdReadSecurity(bool display_dialog);
	int CmdWriteSecurity();
	int CmdDoubleSize();
	int CmdClearBuf(int type = ALL_TYPE);
	int CmdFillBuf();
	int CmdByteSwap();
	int CmdCalibration();

	int CmdEditNote();
	int CmdSelectDevice(long new_type, bool init = false);
	int CmdSetDeviceType(int val); // or const QString* ?
	int CmdSetDeviceSubType(int val);
	int CmdProgram();
	int CmdSetSerialNumber();
	int CmdReadCalibration(int idx);
	int CmdRunScript(bool test_mode = false);
	int SpecialBits(bool readonly = false);
	int ProgramOptions();
	int SerialNumberOptions();
	int OscCalibOption();

	void createToolBarNotice();
	void createToolBarCbx();
	void reateToolBarNotice();
	void createStatusWidgets();

	//int findItemInMenuVector(const QString &n);

	void addMenuVector(menuToGroup *vecMnu, const QString &filter = "");

	bool readLangDir();
	bool getLangTable();
	void setLangGUI();
	void translateGUI();

	void createScriptList();
	void createFileList();

  private:
	void createSignalSlotConnections();
	QString convertFilterListToString(const QStringList &lst);
	int filterNameToIndex(const QString &s, const QStringList &lst);

	void doProgress(const QString &text);

	void Draw(/*int rows = 0, int cols = 0*/);
	void UpdateBuffer();

// 	menuToGroup *searchMenuInDeviceVector(int new_type);

	void createDeviceMenues();
	void addI2C8Struct();
	void addI2C16Struct();
	void addI2CAT17Struct();
	void addMW16Struct();
	void addMW8Struct();
	void addSPIStruct();
	void addAT90Struct();
	void addAT89Struct();
	void addPIC16Struct();
	void addPIC12Struct();
	void addIMBUSStruct();
	void addSDEStruct();
	void addX24CStruct();


	int SaveFile(int force_select = 0);
	int OpenFile(const QString &file = 0);
	void UpdateStrFromBuf();
	void UpdateStrFromStr(const QString &s1, const QString &s2);
	void UpdateStrFromStr(const QString &s1);
	void UpdateStatusBar();

	//      void UpdateChipType(int pritype = -1, int subtype = -1);
	//      void SetChipSubType(int pritype, int subtype = 0);
	void UpdateMenues(menuToGroup &grp, QAction &act);
	void UpdateMenuType(long new_type = 0/*, long old_type = 0*/);
	void UpdateFileMenu();
	void UpdateScriptMenu();

	//      int TypeToMenuId(long type);
	//      long MenuIdToType(QAction * id);
	//      void MenuIdToCbxId(int id, int &idx1, int &idx2);
	//      void TypeToCbxId(long type, int &idx1, int &idx2);
	void CbxMenuInit();
	long CbxIdToType(int idx1, int idx2);
	int OpenScript(const QString &file);

	int OnError(int err_no, const QString &msgerr = 0);
	int PlaySoundMsg(bool val);

	long GetDevSize() const;

	void setFontForWidgets(void);
	void createFontSizeMenu();

	//      int CoordToIndex(int row, int col);
	//      void IndexToCoord(int index, int &row, int &col);
// 	void setMenuIndexes();
	long selectTypeSubtype(const QString &t, const QString &st);
	int ScriptError(int line_number, int arg_index, const QString &s, const QString msg = "");


  private:
	QString selectedLang;

	QFont sysFont;
	short fontSize;

	QLabel *txtComment;
	QLabel *txtID;

	QStringList arguments;
	QString programStyleSheet;

	QComboBox *cbxEEPType;
	QComboBox *cbxEEPSubType;
	QLabel *lblEEPInfo;
	QLabel *lblStringID;

	menuToGroup *currentMenu;
	QAction *currentAct;

	QLineEdit *txtEEPInfo;
	QLineEdit *txtStringID;
	//      QProgressBar *statusProgress;
	QMenu *scrptsMenu;
	QMenu *filesMenu;

	QActionGroup *fileListgrp;
	QActionGroup *scrListgrp;

	QAction *actionScriptList;
	QAction *actionFileList;

	QVector<QAction *> actLangSelect;
	QVector<QAction *> actFSizeSelect;

	QActionGroup *fsizeGroup;
	QActionGroup *langGroup;

	QStringList langFiles;

	// Standard elements
	QHexEdit *e2HexEdit;             // For the canvas
	QHexEdit *e2HexEditSplit;
	QBuffer *qbuf;
	QBuffer *qbufSplit;
	QSplitter *splitter;

	QProgressDialog *e2Prg;

	// Info for the TextCanvas
	int first_line;

	// Index for checking type menu
	//      int type_index;
	//      int curIndex;

	//      int exit_ok;

	bool ignoreFlag;
	bool abortFlag;          //True if we have to abort current op

	AppStatus app_status;           //tell if the App is busy (reading, writing, ...) or can react to user events

	//Verbose mode
	VerboseType verbose;
};

extern e2CmdWindow *cmdWin;

#endif