-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeedback.cpp
More file actions
1437 lines (1268 loc) · 49.5 KB
/
feedback.cpp
File metadata and controls
1437 lines (1268 loc) · 49.5 KB
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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
*
* 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 version 3, 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; if not, see <http://www.gnu.org/licenses/>.
*
*/
#include "feedback.h"
#include "submit_fail.h"
#include "submit_success.h"
#include <QFileDialog>
#include <QApplication>
#include <QDebug>
#include <QFileInfo>
#include <QFile>
#include <QModelIndex>
#include <QLabel>
#include <QLocale>
#include <QPushButton>
#include <QMessageBox>
#include <QStandardItemModel>
#include <QEventLoop>
#include <QTextCodec>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QNetworkRequest>
#include <QHttpPart>
#include <QGraphicsDropShadowEffect>
#include <QTranslator>
#include <QLocale>
#include <QStandardPaths>
#include "fileitem_init.h"
#include <QTimer>
#include "customstyle.h"
#include <QStyleFactory>
#include <QElapsedTimer>
extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed);
feedback::feedback(QWidget *parent)
: QMainWindow(parent)
{
UI_init();
feedback_init();
setAttribute(Qt::WA_TranslucentBackground);
}
feedback::~feedback()
{
// qDebug()<<"this is ~feedback";
// //程序结束时删除所有数据------
// if(submitting_timer != nullptr)
// delete submitting_timer;
// if(accessManager_file != nullptr)
// delete accessManager_file;
// if(multiPart != nullptr)
// delete multiPart;
// if(accessManager != nullptr)
// delete accessManager;
// if(success_dialog != nullptr)
// delete success_dialog;
// if(fail_dialog != nullptr)
// delete fail_dialog;
//************************** UI
delete file_listwidget;
delete pushButton_mix;
delete pushButton_close;
delete label_13;
delete checkBox_3;
delete checkBox_2;
delete checkBox;
delete horizontalLayout;
delete layoutWidget;
delete label_9;
delete label_8;
delete label_10;
delete label_11;
delete effect;
delete frame_2;
delete verticalWidget;
delete pushButton_3;
delete pushButton_2;
delete checkBox_4;
delete pushButton;
delete lineEdit;
delete lineEdit_2;
delete textEdit;
delete label_7;
delete label_6;
delete label_5;
delete email_err_msg_label;
delete label_4;
delete frame;
delete label_3;
delete label_2;
delete comboBox;
delete label;
delete centralwidget;
//---------------------------
}
void feedback::UI_init()
{
if (this->objectName().isEmpty())
this->setObjectName(QString::fromUtf8("feedback"));
this->resize(600, 917);
QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(this->sizePolicy().hasHeightForWidth());
this->setSizePolicy(sizePolicy);
this->setSizeIncrement(QSize(0, 0));
this->setWindowTitle(tr("用户反馈"));
this->setFixedSize(600,550);
this->setWindowIcon(QIcon(":/image/kylin-feedback.png"));
this->setWindowFlags(Qt::FramelessWindowHint);//设置窗口无边框
//--------设置圆角
QBitmap bmp(this->size());
bmp.fill();
QPainter p(&bmp);
p.setPen(Qt::NoPen);
p.setBrush(Qt::black);
p.setRenderHint(QPainter::Antialiasing);
p.drawRoundedRect(bmp.rect(),6,6);
setMask(bmp);
//----- ------------------------
centralwidget = new QWidget(this);
centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
centralwidget->setAttribute(Qt::WA_TranslucentBackground);
label = new QLabel(centralwidget);
label->setText(tr("问题反馈"));
label->setObjectName(QString::fromUtf8("label"));
label->setGeometry(QRect(35, 40, 160, 41));
label->setStyleSheet(QString::fromUtf8("font: 24px \"Sans Serif\";\n"
"color: rgb(68, 68, 68);"));
label_2 = new QLabel(centralwidget);
label_2->setText(tr("问题类型"));
label_2->setObjectName(QString::fromUtf8("label_2"));
label_2->setGeometry(QRect(35, 105, 61, 20));
label_2->setStyleSheet(QString::fromUtf8("font: 14px;\n"
"color: rgb(68, 68, 68);\n"
""));
comboBox = new QComboBox(centralwidget);
comboBox->addItem(QString(tr("系统问题")));
comboBox->addItem(QString(tr("意见建议")));
comboBox->addItem(QString(tr("商务合作")));
comboBox->addItem(QString(tr("其他")));
comboBox->setObjectName(QString::fromUtf8("comboBox"));
comboBox->setGeometry(QRect(140, 105, 320, 30));
comboBox->setStyle(new CustomStyle());
//设置combobox中item的高度和宽度
comboBox->setStyleSheet("QComboBox { min-height: 30px; }"
"QComboBox QAbstractItemView::item{ min-height: 30px; }");
comboBox->setView(new QListView());
// comboBox->setStyleSheet(QString::fromUtf8("min-height: 30px;background-color: rgb(255, 255, 255);"
// "color: rgb(68, 68, 68);font: 14px ;"));
label_3 = new QLabel(centralwidget);
label_3->setText(tr("问题描述"));
label_3->setObjectName(QString::fromUtf8("label_3"));
label_3->setGeometry(QRect(35, 145, 75, 20));
label_3->setStyleSheet(QString::fromUtf8("font: 14px ;\n"
"color: rgb(68, 68, 68);\n"
""));
frame = new QFrame(centralwidget);
frame->setObjectName(QString::fromUtf8("frame"));
frame->setGeometry(QRect(140, 145, 320, 120));
frame->setFrameShape(QFrame::StyledPanel);
frame->setFrameShadow(QFrame::Raised);
textEdit = new QTextEdit(frame);
textEdit->setObjectName(QString::fromUtf8("textEdit"));
textEdit->setGeometry(QRect(10, 10, 300, 100));
textEdit->setFrameShape(QFrame::NoFrame);
QPalette palette_textedit = textEdit->palette();
palette_textedit.setBrush(QPalette::Base,Qt::white);
palette_textedit.setBrush(QPalette::Text,Qt::black);
// palette_textedit.setBrush(QPalette::PlaceholderText,QColor("#CCCCCC"));
textEdit->setPalette(palette_textedit);
#if QT_VERSION >= 0x050c00
textEdit->setPlaceholderText(tr("请输入内容"));//设置详细输入框的提示信息
#endif
textEdit->setStyle(new CustomStyle("ukui-light"));
textEdit->setAcceptRichText(false); //不接受富文本
label_4 = new QLabel(centralwidget);
label_4->setText(tr("邮箱"));
label_4->setObjectName(QString::fromUtf8("label_4"));
label_4->setGeometry(QRect(35, 275, 32, 23));
label_4->setStyleSheet(QString::fromUtf8("font: 14px;\n"
"color: rgb(68, 68, 68);\n"
""));
email_err_msg_label = new QLabel(centralwidget);
email_err_msg_label->setText(tr("邮箱格式输入不正确"));
email_err_msg_label->setGeometry(QRect(140,305,240,15));
email_err_msg_label->setStyleSheet(QString::fromUtf8("color: rgb(255, 0, 0);"));
email_err_msg_label->hide();
label_5 = new QLabel(centralwidget);
label_5->setText(tr("*"));
label_5->setObjectName(QString::fromUtf8("label_5"));
label_5->setGeometry(QRect(110, 143, 16, 16));
label_5->setStyleSheet(QString::fromUtf8("font: 11pt \"Sans Serif\";\n"
"color: rgb(255, 0, 0);"));
label_6 = new QLabel(centralwidget);
label_6->setText(tr("*"));
label_6->setObjectName(QString::fromUtf8("label_6"));
label_6->setGeometry(QRect(68, 277, 16, 16));
label_6->setStyleSheet(QString::fromUtf8("font: 11pt \"Sans Serif\";\n"
"color: rgb(255, 0, 0);"));
lineEdit_2 = new QLineEdit(centralwidget);
lineEdit_2->setObjectName(QString::fromUtf8("lineEdit_2"));
lineEdit_2->setGeometry(QRect(140, 275, 320, 30));
lineEdit_2->setStyle(new CustomStyle("ukui"));
QPalette palette_lineedit_2 = lineEdit_2->palette();
palette_lineedit_2.setBrush(QPalette::Text,Qt::black);
// palette_lineedit_2.setBrush(QPalette::PlaceholderText,QColor("#CCCCCC"));
lineEdit_2->setPalette(palette_lineedit_2);
label_7 = new QLabel(centralwidget);
label_7->setText(tr("上传附件"));
label_7->setObjectName(QString::fromUtf8("label_7"));
label_7->setGeometry(QRect(35,365, 61, 30));
label_7->setStyleSheet(QString::fromUtf8("font: 14px ;\n"
"color: rgb(68, 68, 68);\n"
""));
lineEdit = new QLineEdit(centralwidget);
lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
lineEdit->setGeometry(QRect(140, 367, 320, 30));
lineEdit->setReadOnly(true);
lineEdit->setFrame(true);
#if QT_VERSION >= 0x050c00
lineEdit->setPlaceholderText(tr("文件大小不能超过10MB"));
#endif
lineEdit->setStyle(new CustomStyle("ukui"));
QPalette palette_lineedit = lineEdit->palette();
palette_lineedit.setBrush(QPalette::Text,Qt::black);
// palette_lineedit.setBrush(QPalette::PlaceholderText,QColor("#CCCCCC"));
lineEdit->setPalette(palette_lineedit);
pushButton = new browse_button(centralwidget);
pushButton->setText(tr("浏览..."));
pushButton->setObjectName(QString::fromUtf8("pushButton"));
pushButton->setGeometry(QRect(470, 367, 80, 30));
pushButton->setStyleSheet(QString::fromUtf8("font: 14px;\n"
"background-color: rgb(233, 233, 233);\n"
"color: rgb(68, 68, 68);\n"
"border:4px ;"));
checkBox_4 = new QCheckBox(centralwidget);
checkBox_4->setText(tr("同意获取我的"));
checkBox_4->setObjectName(QString::fromUtf8("checkBox_4"));
checkBox_4->setGeometry(QRect(35, 490, 121, 24));
checkBox_4->setStyleSheet(" spacing: 6px;");
checkBox_4->setStyleSheet(QString::fromUtf8("font: 14px;color:rgb(0,0,0)"));
QPalette palette_checkbox = checkBox_4->palette();
palette_checkbox.setBrush(QPalette::Base,QColor("#CFCFCF"));
checkBox_4->setPalette(palette_checkbox);
pushButton_2 = new QPushButton(centralwidget);
pushButton_2->setText(tr("提交"));
pushButton_2->setObjectName(QString::fromUtf8("pushButton_2"));
pushButton_2->setGeometry(QRect(440, 475, 120, 45));
pushButton_2->setEnabled(false);
pushButton_2->setStyleSheet(QString::fromUtf8("font: 18px;\n"
"color: rgb(255, 255, 255);\n"
"background-color: rgb(233, 233, 233);\n"
"border:4px ;"));
pushButton_3 = new systeminfo_button(centralwidget);
pushButton_3->setText(tr("系统信息"));
pushButton_3->setObjectName(QString::fromUtf8("pushButton_3"));
pushButton_3->setGeometry(QRect(140, 490, 68, 24));
pushButton_3->setFeedBack(this);
pushButton_3->setFlat(true);
pushButton_3->setEnabled(false);
pushButton_3->setStyleSheet(QString::fromUtf8("font: 14px;\n"
"color: rgb(85, 85, 255);"
"background-color:rgb(255,255,255)"));
verticalWidget = new QWidget();
verticalWidget->setObjectName(QString::fromUtf8("verticalWidget"));
verticalWidget->setWindowFlags(Qt::FramelessWindowHint| Qt::WindowStaysOnTopHint);
verticalWidget->setProperty("blurRegion", QRegion(QRect(1, 1, 1, 1)));
verticalWidget->hide();
verticalWidget->setAttribute(Qt::WA_TranslucentBackground);//设置窗口透明
verticalWidget->setStyleSheet(QString::fromUtf8("background-color: rgba(255, 255, 255);\n"
"border-top-left-radius:4px;\n"
"\n"
"border-top-right-radius:4px;\n"
"\n"
"border-bottom-left-radius:4px;\n"
"\n"
"border-bottom-right-radius:4px;\n"
"border:0.5px solid black;\n"
""));
frame_2 = new QFrame(verticalWidget);
frame_2->setObjectName(QString::fromUtf8("frame_2"));
frame_2->setGeometry(QRect(0, 0, 217,77));
frame_2->setFrameShape(QFrame::StyledPanel);
frame_2->setFrameShadow(QFrame::Raised);
effect = new QGraphicsDropShadowEffect;
effect->setOffset(1,1);
effect->setColor(QColor(80,80,80));
effect->setBlurRadius(10);
frame_2->setGraphicsEffect(effect);
frame_2->setStyleSheet("border-color: rgba(255, 255, 255,0.1);");
label_10 = new QLabel(frame_2);
label_10->setObjectName(QString::fromUtf8("label_10"));
label_10->setGeometry(QRect(15, 10, 200, 20));
label_10->setStyleSheet(QString::fromUtf8("border-color: rgb(255, 255, 255);color:rgb(0,0,0);font:12px;"));
label_12 = new QLabel(frame_2);
label_12->setObjectName(QString::fromUtf8("label_12"));
label_12->setGeometry(QRect(15, 30, 200, 20));
label_12->setStyleSheet(QString::fromUtf8("border-color: rgb(255, 255, 255);color:rgb(0,0,0);font:12px;"));
label_11 = new QLabel(frame_2);
label_11->setObjectName(QString::fromUtf8("label_11"));
label_11->setGeometry(QRect(15, 50, 200, 20));
label_11->setStyleSheet(QString::fromUtf8("border-color: rgb(255, 255, 255);color:rgb(0,0,0);font:12px;"));
label_8 = new QLabel(centralwidget);
label_8->setText(tr("日志文件"));
label_8->setObjectName(QString::fromUtf8("label_8"));
label_8->setGeometry(QRect(35, 325, 71, 23));
label_8->setStyleSheet(QString::fromUtf8("font: 14px;\n"
"color: rgb(68, 68, 68);\n"
""));
label_9 = new QLabel(centralwidget);
label_9->setText(tr("限200字"));
label_9->setObjectName(QString::fromUtf8("label_9"));
label_9->setGeometry(QRect(470, 145, 50, 18));
label_9->setStyleSheet(QString::fromUtf8("color: rgb(136, 136, 136);\n"
"font: 12px;"));
layoutWidget = new QWidget(centralwidget);
layoutWidget->setObjectName(QString::fromUtf8("layoutWidget"));
layoutWidget->setGeometry(QRect(140, 327, 320, 23));
horizontalLayout = new QHBoxLayout(layoutWidget);
horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
horizontalLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
horizontalLayout->setContentsMargins(0, 0, 0, 0);
horizontalLayout->setGeometry(QRect(140,325, 320, 23));
checkBox = new QCheckBox(layoutWidget);
checkBox->setText(tr("syslog"));
checkBox->setObjectName(QString::fromUtf8("checkBox"));
checkBox->setStyleSheet(QString::fromUtf8("font: 14px;\n"
"color:rgb(0,0,0);\n"
""));
checkBox->setPalette(palette_checkbox);
horizontalLayout->addWidget(checkBox);
checkBox_2 = new QCheckBox(layoutWidget);
checkBox_2->setText(tr("apport.log"));
checkBox_2->setObjectName(QString::fromUtf8("checkBox_2"));
checkBox_2->setStyleSheet(QString::fromUtf8("font: 14px ;\n"
"spacing: 5px;"
"color:rgb(0,0,0);\n"
""));
checkBox_2->setPalette(palette_checkbox);
horizontalLayout->addWidget(checkBox_2);
checkBox_3 = new QCheckBox(layoutWidget);
checkBox_3->setText(tr("dpkg.log"));
checkBox_3->setObjectName(QString::fromUtf8("checkBox_3"));
checkBox_3->setStyleSheet(QString::fromUtf8("font: 14px;\n"
"spacing: 5px;\n"
"color:rgb(0,0,0);\n"
""));
checkBox_3->setPalette(palette_checkbox);
horizontalLayout->addWidget(checkBox_3);
label_13 = new QLabel(centralwidget);
label_13->setText(tr("文件大小超过了10MB或文件格式不支持"));
label_13->setObjectName(QString::fromUtf8("label_13"));
label_13->setGeometry(QRect(140, 407, 300, 16));
label_13->hide();
label_13->setStyleSheet(QString::fromUtf8("color: rgb(255, 0, 0);font:12px"));
this->setCentralWidget(centralwidget);
//最小化和关闭按钮
pushButton_mix = new hideBtn_hover(centralwidget);
pushButton_mix->setGeometry(QRect(520, 14, 30, 30));
pushButton_mix->setStyleSheet("background-color: rgb(255,255,255);border-image:url(:/image/mix_default.png);border-radius:4px;");
connect(pushButton_mix,SIGNAL(clicked()),this,SLOT(on_pushButton_mix_clicked()));
pushButton_close = new closeBtn_hover(centralwidget);
pushButton_close->setGeometry(QRect(554, 14, 30, 30));
pushButton_close->setStyleSheet("background-color: rgb(255,255,255);border-image:url(:/image/close_default.png);border-radius:4px;");
//添加附件列表
file_listwidget = new QListWidget(this);
file_listwidget->setGeometry(QRect(140,407,320,40));
file_listwidget->setStyleSheet("selection-background-color: rgb(255,255,255);");
file_listwidget->setStyle(new CustomStyle("ukui-light"));
file_listwidget->setAttribute(Qt::WA_TranslucentBackground);
file_listwidget->setFrameShape(QListWidget::NoFrame);
//设置横向纵向无下拉条
// file_listwidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
file_listwidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
//添加提交图片
submitting_pixmap[0] =QPixmap(":/image/conning-a/1.png");
submitting_pixmap[1] =QPixmap(":/image/conning-a/2.png");
submitting_pixmap[2] =QPixmap(":/image/conning-a/3.png");
submitting_pixmap[3] =QPixmap(":/image/conning-a/4.png");
submitting_pixmap[4] =QPixmap(":/image/conning-a/5.png");
submitting_pixmap[5] =QPixmap(":/image/conning-a/6.png");
submitting_pixmap[6] =QPixmap(":/image/conning-a/7.png");
submitting_pixmap[7] =QPixmap(":/image/conning-a/8.png");
connect(pushButton_close,SIGNAL(clicked()),this,SLOT(on_pushButton_close_clicked()));
connect(pushButton,SIGNAL(clicked()),this,SLOT(on_pushButton_clicked()));
connect(pushButton_2,SIGNAL(clicked()),this,SLOT(on_pushButton_2_clicked()));
connect(checkBox,SIGNAL(stateChanged(int)),this,SLOT(on_checkBox_stateChanged(int)));
connect(checkBox_2,SIGNAL(stateChanged(int)),this,SLOT(on_checkBox_2_stateChanged(int)));
connect(checkBox_3,SIGNAL(stateChanged(int)),this,SLOT(on_checkBox_3_stateChanged(int)));
connect(checkBox_4,SIGNAL(stateChanged(int)),this,SLOT(on_checkBox_4_stateChanged(int)));
connect(comboBox,SIGNAL(currentIndexChanged(QString)),this,SLOT(on_comboBox_currentIndexChanged(QString)));
connect(textEdit,SIGNAL(textChanged()),this,SLOT(on_textEdit_textChanged()));
connect(lineEdit_2,SIGNAL(textChanged(QString)),this,SLOT(on_lineEdit_2_textChanged()));
add_systeminfo();//将系统信息添加到信息框
}
void feedback::feedback_init()
{
//http客户端初始化
httpclient_init();
submitting_timer = new QTimer();
submitting_timer->setInterval(100);
connect(submitting_timer,SIGNAL(timeout()),this,SLOT(submit_change_load_image()));
}
//点击提交之后按钮更换加载图片
void feedback::submit_change_load_image()
{
pushButton_2->setText("");
pushButton_2->setIcon(submitting_pixmap[pixmap_i]);
pixmap_i++;
if(pixmap_i == 8 ){
pixmap_i = 0;
}
}
//最小化窗口
void feedback::on_pushButton_mix_clicked()
{
pushButton_mix->setStyleSheet("background-color:rgb(50,87,202);border-image:url(:/image/mix_hover.png);border-radius:4px;");
this->showNormal();
this->showMinimized();
}
//关闭窗口
void feedback::on_pushButton_close_clicked()
{
pushButton_close->setStyleSheet("background-color:rgb(215,52,53);border-image:url(:/image/close_hover.png);border-radius:4px;");
if(file_send_failed_flag)
{
this->close();
}
else{
this->hide();
accessManager->disconnect();
submitting_timer->stop();
feedback_info_init();
window_is_close_flag = true;
}
}
void feedback::window_close()
{
if(file_send_failed_flag)
{
this->close();
}
this->hide();
feedback_info_init();
window_is_close_flag = true;
}
//发送失败后 重新发送
void feedback::resend_info_when_sendfail()
{
this->on_pushButton_2_clicked();
}
//获取图片
void feedback::on_pushButton_clicked()
{
pushButton->setStyleSheet("font: 14px;border-radius:4px;background-color:rgb(65,95,196);color: rgb(68, 68, 68)");
filename=QFileDialog::getOpenFileName(this,tr("选择附件"),"/","(*.gif *.jpg *.png *.pptx *.wps *.xlsx *.pdf *.txt *.docx)",0);
if (filename.isEmpty())
return;
//判断文件个数
if (file_name_list.size() ==0)
{
//添加附件框改变
lineEdit->setText(filename);
add_fileinfo_model();
}
//最多传五个附件
else if(file_name_list.size() >= 5)
{
return ;
}
else{
int file_diff_flags = 0;
for(int fileNum=0; fileNum<file_path_list.size(); fileNum++)
{
if(filename.compare(file_path_list.at(fileNum)) == 0)
{
//添加的文件已经添加过
file_diff_flags++;
}
}
if(file_diff_flags == 0)
{
//添加附件框改变
lineEdit->setText(filename);
add_fileinfo_model();
}
}
}
//设置详细描述框最大字符数
void feedback::on_textEdit_textChanged()
{
textContent = textEdit->toPlainText();
if (textContent.isEmpty()){
describeflag = 0;
}
else
describeflag = 1;//详细描述是否填写
if (emailflag == 1 && describeflag == 1){//邮箱和详细描述都已经填写
pushButton_2->setEnabled(true);//设置提交按钮属性
pushButton_2->setStyleSheet("font: 18px ;border-radius:4px;background-color:rgb(61,107,229);color: rgb(255, 255, 255)");
}
else
{
pushButton_2->setEnabled(false);//设置提交按钮属性
pushButton_2->setStyleSheet("font: 18px ;border-radius:4px;background-color:rgb(233, 233, 233);color: rgb(255, 255, 255)");
}
int length = textContent.count();
int maxLength = 200; // 最大字符数
if(length > maxLength) {
QTextCursor cursor = textEdit->textCursor();
cursor.movePosition(QTextCursor::End);
if(cursor.hasSelection()) {
cursor.clearSelection();
}
cursor.deletePreviousChar();
//设置当前的光标为更改后的光标ing>
textEdit->setTextCursor(cursor);
}
length = textEdit->toPlainText().count();
}
//系统信息显示
void feedback::systeminfo_show(QPointF pt)
{
verticalWidget->setGeometry(pt.x()+5,pt.y()+15,220,80);
verticalWidget->show();
}
//系统信息隐藏
void feedback::systeminfo_hide()
{
verticalWidget->hide();
}
//添加系统信息
void feedback::add_systeminfo()
{
string encoding_info = "系统语言: ";
string desktop_info = "桌面环境: ";
string os_info = "操作系统: ";
if((QLocale::system().name()) == "en_US"){
encoding_info = "Lang: ";
desktop_info = "Deskenv: ";
os_info= "Osrelease: ";
}
//获取系统信息
//1.获取系统版本
string system_info;
string system_name;
string system_version_id;
string s;
ifstream fp("/etc/os-release");
if(!fp){
system_info = "None";
}
else{
while (getline(fp,s)){
string::size_type idx;
idx = s.find("=");//字符串中查找字符串
if (idx == string::npos){//不存在
}
else{
string str2 = s.substr(0,idx);//截取字符串中=前面的内容
if(str2 == "NAME"){
system_name = s.substr(5);//截取"NAME="后面的内容
}
else if(str2 =="VERSION_ID"){
system_version_id = s.substr(11);//截取"VERSION_ID="后面的内容
}
}
}
system_info = os_info +system_name +" " + system_version_id;
}
send_os_info = QString::fromStdString(system_name +" " + system_version_id);
system_info_str = QString::fromStdString(system_info);//string 转QString
system_info_str.remove(QChar('"'), Qt::CaseInsensitive); //将字符串中"字符删除
label_10->setText(system_info_str);
//2.获取桌面环境信息
char * desktop = getenv("DESKTOP_SESSION");
desktop_info.append(desktop);
send_dekstop_info.append(desktop);
desktop_info_str = QString::fromStdString(desktop_info);
label_12->setText(desktop_info_str);
//3.获取编码格式
char *encoding = getenv("GDM_LANG");
char *emcoding_2;
emcoding_2 = (char *)malloc(8);
if (encoding == NULL) {
QString locale = QLocale::system().name();
if (locale == "en_US") {
strcpy(emcoding_2, "en_US");
} else {
strcpy(emcoding_2, "zh_CN");
}
encoding = emcoding_2;
}
qDebug() << "encoding" << encoding;
encoding_info.append(encoding);
send_encoding_info.append(encoding);
encoding_info_str = QString::fromStdString(encoding_info);
label_11->setText(encoding_info_str);
}
//syslog点选
void feedback::on_checkBox_stateChanged(int state)
{
if (state == Qt::Checked) // "选中"
{
emit syslog();
syslogflag = 1;
}
else // 未选中 - Qt::Unchecked
{
syslogflag = 0;
}
//再次判断大小是否超过10M,如果不超过并且详细描述和邮箱都填写 激活提交
if((all_file_size_than_10M() == false) && describeflag == 1 && emailflag == 1 )
{
label_13->hide();
file_listwidget->move(140,407);
pushButton_2->setEnabled(true);
pushButton_2->setStyleSheet("font: 18px;border-radius:4px;background-color:rgb(65,95,196);color: rgb(255, 255, 255)");
}
}
//apport.log点选
void feedback::on_checkBox_2_stateChanged(int state)
{
if (state == Qt::Checked) // "选中"
{
emit syslog();
apportlogflag = 1;
}
else // 未选中 - Qt::Unchecked
{
apportlogflag = 0;
}
//再次判断大小是否超过10M,如果不超过并且详细描述和邮箱都填写 激活提交
if((all_file_size_than_10M() == false) && describeflag == 1 && emailflag == 1 )
{
label_13->hide();
file_listwidget->move(140,407);
pushButton_2->setEnabled(true);
pushButton_2->setStyleSheet("font: 18px;border-radius:4px;background-color:rgb(65,95,196);color: rgb(255, 255, 255)");
}
}
//dpkglog点选
void feedback::on_checkBox_3_stateChanged(int state)
{
if (state == Qt::Checked) // "选中"
{
emit syslog();
dpkglogflag = 1;
}
else // 未选中 - Qt::Unchecked
{
dpkglogflag = 0;
}
//再次判断大小是否超过10M,如果不超过并且详细描述和邮箱都填写 激活提交
if((all_file_size_than_10M() == false) && describeflag == 1 && emailflag == 1 )
{
label_13->hide();
file_listwidget->move(140,407);
pushButton_2->setEnabled(true);
pushButton_2->setStyleSheet("font: 18px;border-radius:4px;background-color:rgb(65,95,196);color: rgb(255, 255, 255)");
}
}
//是否获取系统信息
void feedback::on_checkBox_4_stateChanged(int state)
{
if (state == Qt::Checked) // "选中"
{
get_systeminfoflag = 1;
}
else // 未选中 - Qt::Unchecked
{
get_systeminfoflag = 0;
}
}
//获取反馈类型
void feedback::on_comboBox_currentIndexChanged(const QString &arg1)
{
Q_UNUSED(arg1);
feedback_type = comboBox->currentText();
}
//提交过程中所有控件不可以操作
void feedback::set_all_disable_in_submit()
{
// comboBox->setEnabled(false);
textEdit->setEnabled(false);
lineEdit_2->setEnabled(false);
checkBox->setEnabled(false);
checkBox_2->setEnabled(false);
checkBox_3->setEnabled(false);
checkBox_4->setEnabled(false);
pushButton->setEnabled(false);
pushButton_2->setEnabled(false);
for (int filenum = 0; filenum< file_name_list.size();filenum++)
{
file_widget[filenum]->deletebtn0->setEnabled(false);
}
}
//提交完成后所有控件还原
void feedback::set_all_enable_after_submit()
{
// comboBox->setEnabled(true);
textEdit->setEnabled(true);
lineEdit_2->setEnabled(true);
checkBox->setEnabled(true);
checkBox_2->setEnabled(true);
checkBox_3->setEnabled(true);
checkBox_4->setEnabled(true);
pushButton->setEnabled(true);
// pushButton_2->setEnabled(true);
for (int filenum = 0; filenum< file_name_list.size();filenum++)
{
file_widget[filenum]->deletebtn0->setEnabled(true);
}
}
//提交按钮
void feedback::on_pushButton_2_clicked()
{
//判断邮箱格式
QRegExp rx("^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+");
int pos=0;
QRegExpValidator v(rx, 0);
if(2==v.validate(email_str,pos)){
email_err_msg_label->hide();
}
else{
email_err_msg_label->show();
pushButton_2->setEnabled(false);//设置提交按钮属性
pushButton_2->setStyleSheet("font: 18px;border-radius:4px;background-color:rgb(233, 233, 233);color: rgb(255, 255, 255)");
return ;
}
//判断文件总大小是否超过10M,如果超过,提示
if(all_file_size_than_10M() == true)
{
label_13->show();
file_listwidget->move(140,430);
qDebug()<<"文件大小超过10M";
pushButton_2->setEnabled(false);//设置提交按钮属性
pushButton_2->setStyleSheet("font: 18px;border-radius:4px;background-color:rgb(233, 233, 233);color: rgb(255, 255, 255)");
return;
}
label_13->hide();
file_listwidget->move(140,407);
pushButton_2->setEnabled(false);
pushButton_2->setStyleSheet("font: 18px;border-radius:4px;background-color:rgb(65,95,196);color: rgb(255, 255, 255)");
qDebug()<<"submitting_timer->start();";
submitting_timer->start();
set_all_disable_in_submit();
//超时
QTimer timer_http;
timer_http.setInterval(30000); // 设置超时时间 30 秒
timer_http.setSingleShot(true); // 单次触发
QJsonObject feedback_info_json;
//反馈信息类型
feedback_info_json.insert("subject",feedback_type);
//详细描述
feedback_info_json.insert("description",textContent);
//邮箱
feedback_info_json.insert("email",email_str);
//系统信息发送
if(get_systeminfoflag == 1){
feedback_info_json.insert("version",send_os_info);
feedback_info_json.insert("desktop",send_dekstop_info);
feedback_info_json.insert("language",send_encoding_info);
}
else{
feedback_info_json.insert("version","");
feedback_info_json.insert("desktop","");
feedback_info_json.insert("language","");
}
QString url_filepath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) +"/.config/ukui/url.conf";
qDebug () << "url_filepath-->" << url_filepath;
//从配置文件中读服务器地址
QFile file_url(url_filepath);
QFileInfo url_fileinfo(url_filepath);
if(!url_fileinfo.isFile())
{
file_url.open(QIODevice::ReadWrite | QIODevice::Text);
file_url.write("http://feedback.ubuntukylin.com/v1/issue/");
urlstring.append("http://feedback.ubuntukylin.com/v1/issue/");
}
else{
file_url.open(QIODevice::ReadWrite | QIODevice::Text);
urlstring = file_url.readLine();
}
file_url.close();
//去掉从配置文件中读出的换行符(删除最后一个字符)
//urlstring.remove(urlstring.length()-1,1);
//设置request属性
set_request_header();
request.setUrl(QUrl(urlstring));
qDebug()<<"url:"<<urlstring;
//发送JSON表单
QJsonDocument json_doc;
json_doc.setObject(feedback_info_json);
QByteArray post_feedback_info_array = json_doc.toJson(QJsonDocument::Compact);
qDebug()<<post_feedback_info_array;
QNetworkReply *pReply = accessManager->post(request,post_feedback_info_array);
QEventLoop loop;
connect(&timer_http, &QTimer::timeout, &loop, &QEventLoop::quit);
connect(pReply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
timer_http.start();
loop.exec(); // 启动事件循环
if (timer_http.isActive()) { // 处理响应
if(window_is_close_flag == false){
timer_http.stop();
finishedSlot(pReply);
}
} else { // 处理超时
if (window_is_close_flag ==false){
timeout_http_flag=true;
finishedSlot(pReply);
timer_http.stop();
disconnect(pReply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
pReply->abort();
pReply->deleteLater();
qDebug() << "Timeout";
}
}
}
//截取今天的syslog
QByteArray feedback::get_today_syslog()
{
QDate date(QDate::currentDate());
QList<QString> month_str = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
QProcess process;
QString shell ;
shell.append("cat /var/log/syslog | grep ");
shell.append("'");
shell.append(month_str.at(date.month()-1));
shell.append(" ");
shell.append(QString::number(date.day()));
shell.append("'");
qDebug()<<"shell=========" <<shell;
process.start(shell);
process.waitForFinished();
QByteArray output = process.readAllStandardOutput();
return output;
}
void feedback::add_file_to_Part(QString filepath,QString file_type,QString file_name)
{
qDebug()<<"this is add_file_to_Part";
QHttpPart upload_part;
upload_part.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant(QString("form-data; name=\"%1\";filename=\"%2\"").arg(file_type).arg(file_name)));
QFile *upload_file = new QFile(filepath);
if(!(upload_file->open(QIODevice::ReadOnly))){
qDebug()<<"file open fail";
}
if(file_name.compare("syslog") == 0){
upload_part.setBody(get_today_syslog());
}
else{
upload_part.setBody(upload_file->readAll());
}
multiPart->append(upload_part);
delete upload_file;
return ;
}
void feedback::send_file_httpserver(QString uid)
{
file_send_failed_flag = false;
qDebug()<<"this is send file httpserver";
qDebug()<<"uid:"<<uid;
//初始化http发送文件请求
accessManager_file = new QNetworkAccessManager(this);
connect(accessManager_file, SIGNAL(finished(QNetworkReply*)), this, SLOT(sendfile_finished(QNetworkReply* )));
//设置请求头
request_file.setHeader(QNetworkRequest::ContentTypeHeader,"multipart/form-data");
//设置url
QString urlstring_file = urlstring + "annex/";
request_file.setUrl(QUrl(urlstring_file));
qDebug()<<urlstring_file<<"---";
//构建发送信息
multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
//**************自我添加部分****************************
QString bd = "X-INSOMNIA-BOUNDARY";
multiPart->setBoundary(bd.toLatin1());
request_file.setHeader(QNetworkRequest::ContentTypeHeader,"multipart/form-data;boundary="+bd);
//把发送反馈信息服务器返回的uid 加入此次发送中
QHttpPart uid_part;
uid_part.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"issue_uid\""));