-
Notifications
You must be signed in to change notification settings - Fork 0
/
qt.cpp
306 lines (203 loc) · 5.14 KB
/
qt.cpp
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
#include <QtGui>
#include <QMainWindow>
#include <QWidget>
#include <QApplication>
#include <QAbstractItemView>
#include <QVBoxLayout>
#include <QThread>
#include <QLabel>
#include <QAction>
//#include <qtconcurrentrun.h>
//#include <unistd.h>
#include "qt_interface.h"
#include "qt_menu.h"
#include "common.h"
#include "sniffer.h"
#include "qt_dialog.h"
#include "qt_table.h"
#include "qt_th_iface.h"
#include "qt.h"
/*xBug
1. if interface is changed we must verify new channels
2. i don't know if when table is cleared items are realy distroyed
3. never free cr=new struct th_crack; in MyCrack::start
*/
//global variable
MyTable *tableq=NULL;
MyThreadInterface *threadq = NULL;
//int percent;
/*
void xlog_err(int debug_level, QWidget * parent,char *title,char *fmt, ...)
{
debug_level=debug_level;
char buf[LOGBUFFER_SIZE] = {'\0'};
va_list msg;
va_start(msg,fmt);
vsnprintf(buf, sizeof(buf), fmt, msg);
va_end(msg);
buf[sizeof(buf) - 1] = '\0';
QMessageBox::StandardButton reply;
reply = QMessageBox::information(parent, title, buf);
}
*/
void xlog_err(int debug_level, QWidget * parent,QString title,QString fmt, ...)
{
debug_level=debug_level;
char buf[LOGBUFFER_SIZE] = {'\0'};
va_list msg;
va_start(msg,fmt);
vsnprintf(buf, sizeof(buf), fmt.toLatin1().data(), msg);
va_end(msg);
buf[sizeof(buf) - 1] = '\0';
QMessageBox::StandardButton reply;
reply = QMessageBox::information(parent, title, buf);
}
void qt_update_fields(struct access_point *ap)
{
if (tableq==NULL){
qWarning("You are using qt_update_fields without initialising table!!!!");
return ;
}
if (ap==NULL){
qWarning("Display NULL AP!");
return ;
}
if (tableq->maxRow()<=ap->id){
tableq->addRow(ap);
}else{
tableq->updateRow(ap);
}
}
//use it in offline mode
void qt_insert_all(struct access_point *fap)
{
struct access_point *tmp_ap;
if (tableq==NULL){
qWarning("You are using qt_update_fields without initialising table!!!!");
return ;
}
if (fap==NULL){
qWarning("Display NULL AP!");
return ;
}
tmp_ap=fap;
while (tmp_ap!=NULL){
if (tableq->maxRow()<=tmp_ap->id){
tableq->addRow(tmp_ap);
}else{
//should never be here
tableq->updateRow(tmp_ap);
}
tmp_ap=tmp_ap->next;
}
// BUG !!! NU VA PUTEA NICIODATA AFISA MESAJELE DE EROARE DE AICI
//sniffq->stop();
//!!!! TO MODIFY!!!!!!!!!!!!!!!!!!!!
/////////!!!!!!!!!!!!!!!!!!!!!!!!!!!
// sniffq->progress_finish();
}
void qt_exit_unexpected(char* err,struct access_point *fap)
{
//if (err == NULL)
//xlog_err(LEVEL1,windowq,"Alert!","Loop died unexpected!");
//else
//xlog_err(LEVEL1,windowq,"Alert!","Loop died unexpected :%s",err);
if (is_offline() == 1){
if (fap!=NULL){
qt_insert_all(fap);
}
}
}
void qt_update_progress_bar(off_t value)
{
// value=value;
// if (sniffq == NULL){
// log_err(LEVEL1,(char *)"Sniffer is not initialised");
// return ;
// }
//sniffq->update_progress_bar_percent(value);
}
void x_message(char *msg)
{
threadq->emit_message(msg);
}
void crack_finish(int x)
{
}
int qt_main(int argc, char *argv[])
{
//int argc=0;
//char argv[1][1];
//argv[0][0]='\0';
//if ()
//fork();
QApplication app(argc,argv);
QWidget window;
MySniff *sniff;
QWidget *menuq;
QLabel *infoLabel;
window.resize(MAIN_WINDOW_X,MAIN_WINDOW_Y);
threadq = new MyThreadInterface(&window);
//create table with access points
tableq= new MyTable(&window);
sniff=new MySniff(&window);
//create menus
menuq= new MyMenu(sniff,tableq);
menuq->setMaximumHeight(20);
//create a label with informations
infoLabel = new QLabel("<i></i>");
infoLabel->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
infoLabel->setAlignment(Qt::AlignCenter);
app.connect(&app,SIGNAL(aboutToQuit()),menuq,SLOT(at_exit()));
//set layout
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(menuq);
layout->addWidget(tableq);
layout->addWidget(infoLabel);
window.setLayout(layout);
window.show();
//table.addrow();
//run(test1,&app);
//test1(&app);
//QFuture<int> f1 = run(test1,&app);
//QFuture<void> f2 = run(test2,&window,&table);
//while(1){};
//window.show();
return app.exec();
}
void *qt_interface(void *x)
{
x=x;
qt_main(NULL,NULL);
return NULL;
}
/*
int main(int argc, char *argv[]){
return qt_main(argc,argv);
}*/
/*int main(int argc, char *argv[]){
qt_main(argc,argv);
}
*/
/*
QFuture<void> f1 = run(hello, 1);
QFuture<void> f2 = run(hello, 2);
f1.waitForFinished();
f2.waitForFinished();
QTableWidget* mw=new QTableWidget(0);
QStringList labels;
labels << "Greeting" << "Planet";
mw->setColumnCount(2);
mw->setEditTriggers(QAbstractItemView::AllEditTriggers);
mw->setHorizontalHeaderLabels(labels);
mw->horizontalHeader()->setStretchLastSection(true);
mw->insertRow(0);
QTableWidgetItem* item=new QTableWidgetItem("Hello");
item->setFlags(Qt::ItemIsEnabled);
item->setWhatsThis("You can change this task's comment, start time and end time.");
mw->setItem(0,0,item);
QTableWidgetItem* item2=new QTableWidgetItem("World");
mw->setItem(0,1,item2);
mw->show();
khello.exec();
*/