]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - LinuxGUI/Ventoy2Disk/QT/ventoy2diskwindow.cpp
fixed russian translation (#2190)
[Ventoy.git] / LinuxGUI / Ventoy2Disk / QT / ventoy2diskwindow.cpp
1 #include "ventoy2diskwindow.h"
2 #include "ui_ventoy2diskwindow.h"
3 #include "partcfgdialog.h"
4
5 #include <QMessageBox>
6
7 extern "C" {
8 #include "ventoy_define.h"
9 #include "ventoy_util.h"
10 #include "ventoy_disk.h"
11 #include "ventoy_json.h"
12 #include "ventoy_http.h"
13 #include "ventoy_qt.h"
14 }
15
16 MyQThread::MyQThread(QObject *parent) : QThread(parent)
17 {
18 m_index = -1;
19 m_type = 0;
20 m_running = false;
21 }
22
23 void MyQThread::install_run()
24 {
25 int ret = 0;
26 int pos = 0;
27 int buflen = 0;
28 int percent = 0;
29 char buf[1024];
30 char dec[64];
31 char out[256];
32 char disk_name[32];
33 ventoy_disk *cur;
34
35 vlog("install run %d ...\n", m_index);
36
37 cur = g_disk_list + m_index;
38 snprintf(disk_name, sizeof(disk_name), "%s", cur->disk_name);
39 snprintf(dec, sizeof(dec), "%llu", (unsigned long long)m_reserve_space);
40
41 buflen = sizeof(buf);
42 VTOY_JSON_FMT_BEGIN(pos, buf, buflen);
43 VTOY_JSON_FMT_OBJ_BEGIN();
44 VTOY_JSON_FMT_STRN("method", "install");
45 VTOY_JSON_FMT_STRN("disk", disk_name);
46 VTOY_JSON_FMT_STRN("reserve_space", dec);
47 VTOY_JSON_FMT_UINT("partstyle", ventoy_code_get_cur_part_style());
48 VTOY_JSON_FMT_UINT("secure_boot", m_secureboot);
49 VTOY_JSON_FMT_UINT("align_4kb", m_align4K);
50 VTOY_JSON_FMT_OBJ_END();
51 VTOY_JSON_FMT_END(pos);
52
53 out[0] = 0;
54 ventoy_func_handler(buf, out, sizeof(out));
55 vlog("func handler install <%s>\n", out);
56
57 if (strstr(out, "success"))
58 {
59 while (percent != 100)
60 {
61 percent = ventoy_code_get_percent();
62 emit thread_event(THREAD_MSG_PROGRESS_BAR, percent);
63 msleep(50);
64 }
65
66 ret = ventoy_code_get_result();
67 ventoy_code_refresh_device();
68 cur = NULL;
69 }
70 else
71 {
72 ret = 1;
73 }
74
75 emit thread_event(THREAD_MSG_INSTALL_FINISH, ret);
76 m_running = false;
77 }
78
79 void MyQThread::update_run()
80 {
81 int ret = 0;
82 int percent = 0;
83 char buf[1024];
84 char out[256];
85 char disk_name[32];
86 ventoy_disk *cur;
87
88 vlog("install run %d ...\n", m_index);
89
90 cur = g_disk_list + m_index;
91 snprintf(disk_name, sizeof(disk_name), "%s", cur->disk_name);
92 snprintf(buf, sizeof(buf), "{\"method\":\"update\",\"disk\":\"%s\",\"secure_boot\":%d}", disk_name, m_secureboot);
93
94 out[0] = 0;
95 ventoy_func_handler(buf, out, sizeof(out));
96 vlog("func handler update <%s>\n", out);
97
98 if (strstr(out, "success"))
99 {
100 while (percent != 100)
101 {
102 percent = ventoy_code_get_percent();
103 emit thread_event(THREAD_MSG_PROGRESS_BAR, percent);
104 msleep(50);
105 }
106
107 ret = ventoy_code_get_result();
108 ventoy_code_refresh_device();
109 cur = NULL;
110 }
111 else
112 {
113 ret = 1;
114 }
115
116 emit thread_event(THREAD_MSG_UPDATE_FINISH, ret);
117 m_running = false;
118 }
119
120 void MyQThread::run()
121 {
122 if (THREAD_TYPE_INSTALL == m_type)
123 {
124 install_run();
125 }
126 else if (THREAD_TYPE_UPDATE == m_type)
127 {
128 update_run();
129 }
130 else
131 {
132
133 }
134 }
135
136
137 Ventoy2DiskWindow::Ventoy2DiskWindow(QWidget *parent)
138 : QMainWindow(parent)
139 , ui(new Ui::Ventoy2DiskWindow)
140 {
141 m_partcfg = new PartCfgDialog();
142 m_part_group = new QActionGroup(this);
143 m_lang_group = new QActionGroup(this);
144 m_thread = new MyQThread(this);
145
146 ui->setupUi(this);
147 }
148
149 Ventoy2DiskWindow::~Ventoy2DiskWindow()
150 {
151 delete m_partcfg;
152 delete m_part_group;
153 delete m_lang_group;
154 delete m_thread;
155 delete ui;
156 }
157
158 bool LangCompare(const QString &s1, const QString &s2)
159 {
160 if (true == s1.startsWith("Chinese Simplified") && false == s2.startsWith("Chinese Simplified"))
161 {
162 return true;
163 }
164 else if (false == s1.startsWith("Chinese Simplified") && true == s2.startsWith("Chinese Simplified"))
165 {
166 return false;
167 }
168 else
169 {
170 return s1 < s2;
171 }
172 }
173
174 int Ventoy2DiskWindow::lang_string(const QString &id, QString &str)
175 {
176 QString cur = ventoy_code_get_cur_language();
177
178 for (QJsonArray::iterator p = m_lang_array.begin(); p != m_lang_array.end(); p++)
179 {
180 if (p->toObject().value("name") == cur)
181 {
182 str = p->toObject().value(id).toString();
183 str = str.replace("#@", "\r\n");
184 return 0;
185 }
186 }
187
188 return 1;
189 }
190
191 void Ventoy2DiskWindow::update_ui_language()
192 {
193 QString dev;
194 QJsonObject obj;
195 QString cur = ventoy_code_get_cur_language();
196
197 for (QJsonArray::iterator p = m_lang_array.begin(); p != m_lang_array.end(); p++)
198 {
199 if (p->toObject().value("name") == cur)
200 {
201 obj = p->toObject();
202 break;
203 }
204 }
205
206 ui->menuOption->setTitle(_LANG_STR("STR_MENU_OPTION"));
207 ui->actionSecure_Boot_Support->setText(_LANG_STR("STR_MENU_SECURE_BOOT"));
208 ui->menuPartition_Style->setTitle(_LANG_STR("STR_MENU_PART_STYLE"));
209 ui->actionPartition_Configuration->setText(_LANG_STR("STR_MENU_PART_CFG"));
210 ui->actionClear_Ventoy->setText(_LANG_STR("STR_MENU_CLEAR"));
211 ui->actionShow_All_Devices->setText(_LANG_STR("STR_SHOW_ALL_DEV"));
212
213 dev = _LANG_STR("STR_DEVICE");
214 if (m_partcfg->reserve)
215 {
216 QString str;
217 str.sprintf(" [ -%lld%s ]", (long long)m_partcfg->resvalue, m_partcfg->unit ? "GB" : "MB");
218 ui->groupBoxDevice->setTitle(dev + str);
219 }
220 else
221 {
222 ui->groupBoxDevice->setTitle(dev);
223 }
224
225 ui->groupBoxVentoyLocal->setTitle(_LANG_STR("STR_LOCAL_VER"));
226 ui->groupBoxVentoyDevice->setTitle(_LANG_STR("STR_DISK_VER"));
227 ui->groupBoxStatus->setTitle(_LANG_STR("STR_STATUS"));
228 ui->ButtonInstall->setText(_LANG_STR("STR_INSTALL"));
229 ui->ButtonUpdate->setText(_LANG_STR("STR_UPDATE"));
230 m_partcfg->update_language_ui(obj);
231 m_partcfg->setWindowTitle(_LANG_STR("STR_MENU_PART_CFG"));
232 }
233
234 void Ventoy2DiskWindow::lang_check_action(QAction *act)
235 {
236 ventoy_code_set_cur_language(act->text().toStdString().c_str());
237 update_ui_language();
238 }
239
240 void Ventoy2DiskWindow::LoadLanguages()
241 {
242 QString curlang = ventoy_code_get_cur_language();
243 if (curlang.isEmpty())
244 {
245 QString LANG = qgetenv("LANG");
246 if (LANG.startsWith("zh_CN"))
247 {
248 ventoy_code_set_cur_language("Chinese Simplified (简体中文)");
249 }
250 else
251 {
252 ventoy_code_set_cur_language("English (English)");
253 }
254 curlang = ventoy_code_get_cur_language();
255 }
256
257
258 QFile inFile("./tool/languages.json");
259 inFile.open(QIODevice::ReadOnly|QIODevice::Text);
260 QByteArray data = inFile.readAll();
261 inFile.close();
262
263 QJsonParseError errorPtr;
264 QJsonDocument doc = QJsonDocument::fromJson(data, &errorPtr);
265
266 m_lang_array = doc.array();
267 QVector<QString> List;
268 for (QJsonArray::iterator p = m_lang_array.begin(); p != m_lang_array.end(); p++)
269 {
270 List.push_back(p->toObject().value("name").toString());
271 }
272
273 connect(m_lang_group, SIGNAL(triggered(QAction *)), this, SLOT(lang_check_action(QAction *)));
274
275 std::sort(List.begin(), List.end(), LangCompare);
276
277 for (QVector<QString>::iterator p = List.begin(); p != List.end(); p++)
278 {
279 QAction *action = new QAction(*p, m_lang_group);
280 action->setCheckable(true);
281
282 if (p->compare(curlang) == 0)
283 {
284 action->setChecked(true);
285 m_lang_group->triggered(action);
286 }
287
288 ui->menuLanguage->addAction(action);
289 }
290
291
292 }
293
294 void Ventoy2DiskWindow::part_style_check_action(QAction *action)
295 {
296 int style = 0;
297
298 if (action->text() == "MBR")
299 {
300 style = 0;
301 ui->labelVentoyLocalPartStyle->setText("MBR");
302 }
303 else
304 {
305 style = 1;
306 ui->labelVentoyLocalPartStyle->setText("GPT");
307 }
308
309 if (style != ventoy_code_get_cur_part_style())
310 {
311 ventoy_code_set_cur_part_style(style);
312 }
313 }
314
315 static ventoy_disk *select_active_dev(const QString &select, int *activeid)
316 {
317 int i;
318 int alldev = ventoy_code_get_cur_show_all();
319 ventoy_disk *cur = NULL;
320
321 /* find the match one */
322 if (!select.isEmpty())
323 {
324 for (i = 0; i < g_disk_num; i++)
325 {
326 cur = g_disk_list + i;
327 if (alldev == 0 && cur->type != VTOY_DEVICE_USB)
328 {
329 continue;
330 }
331
332 if (select.compare(cur->disk_name) == 0)
333 {
334 *activeid = i;
335 return cur;
336 }
337 }
338 }
339
340 /* find the first one that installed with Ventoy */
341 for (i = 0; i < g_disk_num; i++)
342 {
343 cur = g_disk_list + i;
344 if (alldev == 0 && cur->type != VTOY_DEVICE_USB)
345 {
346 continue;
347 }
348
349 if (cur->vtoydata.ventoy_valid)
350 {
351 *activeid = i;
352 return cur;
353 }
354 }
355
356 /* find the first USB interface device */
357 for (i = 0; i < g_disk_num; i++)
358 {
359 cur = g_disk_list + i;
360 if (alldev == 0 && cur->type != VTOY_DEVICE_USB)
361 {
362 continue;
363 }
364
365 if (cur->type == VTOY_DEVICE_USB)
366 {
367 *activeid = i;
368 return cur;
369 }
370 }
371
372 /* use the first one */
373 for (i = 0; i < g_disk_num; i++)
374 {
375 cur = g_disk_list + i;
376 if (alldev == 0 && cur->type != VTOY_DEVICE_USB)
377 {
378 continue;
379 }
380
381 *activeid = i;
382 return cur;
383 }
384
385 return NULL;
386 }
387
388
389 void Ventoy2DiskWindow::FillDeviceList(const QString &select)
390 {
391 int active;
392 int count = 0;
393 int alldev = ventoy_code_get_cur_show_all();
394 ventoy_disk *cur;
395
396 ui->comboBoxDevice->clear();
397
398 for (int i = 0; i < g_disk_num; i++)
399 {
400 cur = g_disk_list + i;
401
402 if (alldev == 0 && cur->type != VTOY_DEVICE_USB)
403 {
404 continue;
405 }
406
407 QString item;
408 item.sprintf("%s [%s] %s", cur->disk_name, cur->human_readable_size, cur->disk_model);
409 ui->comboBoxDevice->addItem(item);
410 count++;
411 }
412
413 cur = select_active_dev(select, &active);
414 if (cur)
415 {
416 vlog("combox count:%d, active:%s id:%d\n", count, cur->disk_name, active);
417 ui->ButtonInstall->setEnabled(true);
418 ui->ButtonUpdate->setEnabled(cur->vtoydata.ventoy_valid);
419 ui->comboBoxDevice->setCurrentIndex(active);
420 }
421 else
422 {
423 vlog("combox count:%d, no active id\n", count);
424 ui->ButtonInstall->setEnabled(false);
425 ui->ButtonUpdate->setEnabled(false);
426 }
427 }
428
429
430 void Ventoy2DiskWindow::OnInitWindow(void)
431 {
432 int len;
433 const uchar *data;
434 QIcon icon;
435 QPixmap pix1;
436 QPixmap pix2;
437 char ver[512];
438
439 ui->labelVentoyLocalSecure->hide();
440
441 m_part_group->addAction(ui->actionMBR);
442 m_part_group->addAction(ui->actionGPT);
443 connect(m_part_group, SIGNAL(triggered(QAction *)), this, SLOT(part_style_check_action(QAction *)));
444
445 if (ventoy_code_get_cur_part_style())
446 {
447 ui->actionGPT->setChecked(true);
448 m_part_group->triggered(ui->actionGPT);
449 }
450 else
451 {
452 ui->actionMBR->setChecked(true);
453 m_part_group->triggered(ui->actionMBR);
454 }
455
456 snprintf(ver, sizeof(ver), VERSION_FMT, ventoy_get_local_version());
457 ui->labelVentoyLocalVer->setText(QApplication::translate("Ventoy2DiskWindow", ver, nullptr));
458
459 LoadLanguages();
460
461 data = (const uchar *)get_refresh_icon_raw_data(&len);
462 pix1.loadFromData(data, len);
463 icon.addPixmap(pix1);
464 ui->ButtonRefresh->setIcon(icon);
465
466 data = (const uchar *)get_secure_icon_raw_data(&len);
467 pix2.loadFromData(data, len);
468 ui->labelVentoyLocalSecure->setPixmap(pix2);
469 ui->labelVentoyDeviceSecure->setPixmap(pix2);
470
471 ui->labelVentoyDeviceSecure->setHidden(true);
472 ui->labelVentoyDeviceVer->setText("");
473 ui->labelVentoyDevicePartStyle->setText("");
474
475 ui->actionSecure_Boot_Support->trigger();
476
477 ui->actionShow_All_Devices->setChecked(ventoy_code_get_cur_show_all());
478
479 connect(m_thread, &MyQThread::thread_event, this, &Ventoy2DiskWindow::thread_event);
480
481 FillDeviceList("");
482 }
483
484 void Ventoy2DiskWindow::showEvent(QShowEvent *ev)
485 {
486 QMainWindow::showEvent(ev);
487 OnInitWindow();
488 }
489
490 void Ventoy2DiskWindow::on_ButtonInstall_clicked()
491 {
492 int index;
493 quint64 size = 0, space = 0;
494 ventoy_disk *cur;
495 QString title_warn, title_err, msg;
496
497 lang_string("STR_ERROR", title_err);
498 lang_string("STR_WARNING", title_warn);
499
500 if (m_thread->m_running || ventoy_code_is_busy())
501 {
502 lang_string("STR_WAIT_PROCESS", msg);
503 QMessageBox::warning(NULL, title_warn, msg);
504 return;
505 }
506
507 index = ui->comboBoxDevice->currentIndex();
508 if (index < 0 || index > g_disk_num)
509 {
510 vlog("Invalid combobox current index %d\n", index);
511 return;
512 }
513
514 cur = g_disk_list + index;
515
516 if (cur->is4kn)
517 {
518 lang_string("STR_4KN_UNSUPPORTED", msg);
519 QMessageBox::critical(NULL, title_err, msg);
520 return;
521 }
522
523 if (ventoy_code_get_cur_part_style() == 0 && cur->size_in_byte > 2199023255552ULL)
524 {
525 lang_string("STR_DISK_2TB_MBR_ERROR", msg);
526 QMessageBox::critical(NULL, title_err, msg);
527 return;
528 }
529
530 if (m_partcfg->reserve)
531 {
532 size = cur->size_in_byte / SIZE_1MB;
533 space = m_partcfg->resvalue;
534 if (m_partcfg->unit == 1)
535 {
536 space = m_partcfg->resvalue * 1024;
537 }
538
539 if (size <= space || (size - space) <= VTOYEFI_PART_BYTES / SIZE_1MB)
540 {
541 lang_string("STR_SPACE_VAL_INVALID", msg);
542 QMessageBox::critical(NULL, title_err, msg);
543 vlog("reserved space too big.\n");
544 return;
545 }
546 }
547
548 lang_string("STR_INSTALL_TIP", msg);
549 if (QMessageBox::Yes != QMessageBox::warning(NULL, title_warn, msg, QMessageBox::Yes | QMessageBox::No, QMessageBox::No))
550 {
551 return;
552 }
553
554 lang_string("STR_INSTALL_TIP2", msg);
555 if (QMessageBox::Yes != QMessageBox::warning(NULL, title_warn, msg, QMessageBox::Yes | QMessageBox::No, QMessageBox::No))
556 {
557 return;
558 }
559
560 ui->ButtonRefresh->setEnabled(false);
561 ui->ButtonInstall->setEnabled(false);
562 ui->ButtonRefresh->setEnabled(false);
563
564 m_thread->m_type = THREAD_TYPE_INSTALL;
565 m_thread->m_index = index;
566 m_thread->m_reserve_space = space * SIZE_1MB;
567 m_thread->m_secureboot = ui->actionSecure_Boot_Support->isChecked();
568 m_thread->m_align4K = m_partcfg->align;
569 m_thread->m_running = true;
570
571 m_thread->start();
572 }
573
574 void Ventoy2DiskWindow::on_ButtonUpdate_clicked()
575 {
576 int index;
577 ventoy_disk *cur;
578 QString title_info, title_warn, title_err, msg;
579
580 lang_string("STR_ERROR", title_err);
581 lang_string("STR_WARNING", title_warn);
582 lang_string("STR_INFO", title_info);
583
584 if (m_thread->m_running || ventoy_code_is_busy())
585 {
586 lang_string("STR_WAIT_PROCESS", msg);
587 QMessageBox::warning(NULL, title_warn, msg);
588 return;
589 }
590
591 index = ui->comboBoxDevice->currentIndex();
592 if (index < 0 || index > g_disk_num)
593 {
594 vlog("Invalid combobox current index %d\n", index);
595 return;
596 }
597
598 cur = g_disk_list + index;
599 if (cur->vtoydata.ventoy_valid == 0)
600 {
601 vlog("invalid ventoy version");
602 return;
603 }
604
605 lang_string("STR_UPDATE_TIP", msg);
606 if (QMessageBox::Yes != QMessageBox::information(NULL, title_info, msg, QMessageBox::Yes | QMessageBox::No, QMessageBox::No))
607 {
608 return;
609 }
610
611 ui->ButtonRefresh->setEnabled(false);
612 ui->ButtonInstall->setEnabled(false);
613 ui->ButtonRefresh->setEnabled(false);
614
615 m_thread->m_type = THREAD_TYPE_UPDATE;
616 m_thread->m_index = index;
617 m_thread->m_secureboot = ui->actionSecure_Boot_Support->isChecked();
618
619 m_thread->m_running = true;
620 m_thread->start();
621 }
622
623 void Ventoy2DiskWindow::on_ButtonRefresh_clicked()
624 {
625 QString title_warn, msg;
626
627 if (m_thread->m_running || ventoy_code_is_busy())
628 {
629 lang_string("STR_WARNING", title_warn);
630 lang_string("STR_WAIT_PROCESS", msg);
631 QMessageBox::warning(NULL, title_warn, msg);
632 return;
633 }
634
635 ventoy_code_refresh_device();
636 FillDeviceList("");
637 }
638
639 void Ventoy2DiskWindow::on_comboBoxDevice_currentIndexChanged(int index)
640 {
641 char ver[512];
642 ventoy_disk *cur;
643
644 ui->labelVentoyDeviceSecure->setHidden(true);
645 ui->labelVentoyDeviceVer->setText("");
646 ui->labelVentoyDevicePartStyle->setText("");
647
648 if (index < 0 || index > g_disk_num)
649 {
650 vlog("invalid combobox index %d\n", index);
651 return;
652 }
653
654 cur = g_disk_list + index;
655 if (cur->vtoydata.ventoy_valid)
656 {
657 if (cur->vtoydata.secure_boot_flag)
658 {
659 ui->labelVentoyDeviceSecure->setHidden(false);
660 }
661 else
662 {
663 ui->labelVentoyDeviceSecure->setHidden(true);
664 }
665
666 if ((int)(ui->actionSecure_Boot_Support->isChecked()) != cur->vtoydata.secure_boot_flag)
667 {
668 ui->actionSecure_Boot_Support->trigger();
669 }
670
671 snprintf(ver, sizeof(ver), VERSION_FMT, cur->vtoydata.ventoy_ver);
672 ui->labelVentoyDeviceVer->setText(QApplication::translate("Ventoy2DiskWindow", ver, nullptr));
673 ui->labelVentoyDevicePartStyle->setText(cur->vtoydata.partition_style ? "GPT" : "MBR");
674 }
675 else
676 {
677 if (!(ui->actionSecure_Boot_Support->isChecked()))
678 {
679 ui->actionSecure_Boot_Support->trigger();
680 }
681 }
682 }
683
684 void Ventoy2DiskWindow::on_actionPartition_Configuration_triggered()
685 {
686 m_partcfg->update_ui_status();
687 if (QDialog::Accepted == m_partcfg->exec())
688 {
689 QString str;
690 QString dev;
691 lang_string("STR_DEVICE", dev);
692
693 if (m_partcfg->reserve)
694 {
695 str.sprintf(" [ -%lld%s ]", (long long)m_partcfg->resvalue, m_partcfg->unit ? "GB" : "MB");
696 ui->groupBoxDevice->setTitle(dev + str);
697 }
698 else
699 {
700 ui->groupBoxDevice->setTitle(dev);
701 }
702 }
703 }
704
705 void Ventoy2DiskWindow::on_actionClear_Ventoy_triggered()
706 {
707 int ret;
708 int index;
709 ventoy_disk *cur;
710 QString title_err, title_warn, title_info, msg;
711 char disk_name[64];
712 char buf[256];
713 char out[256];
714
715 lang_string("STR_ERROR", title_err);
716 lang_string("STR_WARNING", title_warn);
717 lang_string("STR_INFO", title_info);
718
719 if (m_thread->m_running || ventoy_code_is_busy())
720 {
721 lang_string("STR_WAIT_PROCESS", msg);
722 QMessageBox::warning(NULL, title_warn, msg);
723 return;
724 }
725
726 index = ui->comboBoxDevice->currentIndex();
727 if (index < 0 || index > g_disk_num)
728 {
729 vlog("Invalid combobox current index %d\n", index);
730 return;
731 }
732
733 cur = g_disk_list + index;
734
735 lang_string("STR_INSTALL_TIP", msg);
736 if (QMessageBox::Yes != QMessageBox::warning(NULL, title_warn, msg, QMessageBox::Yes | QMessageBox::No, QMessageBox::No))
737 {
738 return;
739 }
740
741 lang_string("STR_INSTALL_TIP2", msg);
742 if (QMessageBox::Yes != QMessageBox::warning(NULL, title_warn, msg, QMessageBox::Yes | QMessageBox::No, QMessageBox::No))
743 {
744 return;
745 }
746
747 snprintf(disk_name, sizeof(disk_name), "%s", cur->disk_name);
748 snprintf(buf, sizeof(buf), "{\"method\":\"clean\",\"disk\":\"%s\"}", disk_name);
749
750 out[0] = 0;
751 ventoy_func_handler(buf, out, sizeof(out));
752 vlog("func handler clean <%s>\n", out);
753
754 if (strstr(out, "success"))
755 {
756 ret = ventoy_code_get_result();
757 ventoy_code_refresh_device();
758 cur = NULL;
759 }
760 else
761 {
762 ret = 1;
763 }
764
765 if (ret == 0)
766 {
767 lang_string("STR_CLEAR_SUCCESS", msg);
768 QMessageBox::information(NULL, title_info, msg);
769 }
770 else
771 {
772 lang_string("STR_CLEAR_FAILED", msg);
773 QMessageBox::critical(NULL, title_err, msg);
774 }
775
776 FillDeviceList(disk_name);
777 }
778
779 void Ventoy2DiskWindow::on_actionShow_All_Devices_toggled(bool arg1)
780 {
781 ventoy_code_set_cur_show_all(arg1);
782 FillDeviceList("");
783 }
784
785
786 void Ventoy2DiskWindow::closeEvent(QCloseEvent *event)
787 {
788 vlog("On closeEvent ...\n");
789
790 if (m_thread->m_running)
791 {
792 QString title;
793 QString msg;
794
795 lang_string("STR_WARNING", title);
796 lang_string("STR_WAIT_PROCESS", msg);
797 QMessageBox::warning(NULL, title, msg);
798
799 event->ignore();
800 return;
801 }
802
803 ventoy_code_save_cfg();
804
805 event->accept();
806 }
807
808 void Ventoy2DiskWindow::on_actionSecure_Boot_Support_triggered()
809 {
810 ui->labelVentoyLocalSecure->setHidden(!(ui->actionSecure_Boot_Support->isChecked()));
811 }
812
813 void Ventoy2DiskWindow::set_percent(int percent)
814 {
815 int index;
816 QString status, radio;
817
818 ui->progressBar->setValue(percent);
819
820 lang_string("STR_STATUS", status);
821
822 if (percent == 0)
823 {
824 ui->groupBoxStatus->setTitle(status);
825 }
826 else
827 {
828 index = status.indexOf("-");
829 radio.sprintf("%d%%", percent);
830 ui->groupBoxStatus->setTitle(status.left(index + 2) + radio);
831 }
832 }
833
834 void Ventoy2DiskWindow::thread_event(int msg, int data)
835 {
836 char disk_name[32];
837 QString title_err, title_info, tipmsg;
838
839 if (msg == THREAD_MSG_PROGRESS_BAR)
840 {
841 set_percent(data);
842 }
843 else if (msg == THREAD_MSG_INSTALL_FINISH)
844 {
845 lang_string("STR_ERROR", title_err);
846 lang_string("STR_INFO", title_info);
847
848 if (data == 0)
849 {
850 lang_string("STR_INSTALL_SUCCESS", tipmsg);
851 QMessageBox::information(NULL, title_info, tipmsg);
852 }
853 else
854 {
855 lang_string("STR_INSTALL_FAILED", tipmsg);
856 QMessageBox::critical(NULL, title_err, tipmsg);
857 }
858
859 set_percent(0);
860 ui->ButtonRefresh->setEnabled(true);
861 ui->ButtonInstall->setEnabled(true);
862 ui->ButtonRefresh->setEnabled(true);
863
864 snprintf(disk_name, sizeof(disk_name), "%s", g_disk_list[m_thread->m_index].disk_name);
865 FillDeviceList(disk_name);
866 }
867 else if (msg == THREAD_MSG_UPDATE_FINISH)
868 {
869 lang_string("STR_ERROR", title_err);
870 lang_string("STR_INFO", title_info);
871
872 if (data == 0)
873 {
874 lang_string("STR_UPDATE_SUCCESS", tipmsg);
875 QMessageBox::information(NULL, title_info, tipmsg);
876 }
877 else
878 {
879 lang_string("STR_UPDATE_FAILED", tipmsg);
880 QMessageBox::critical(NULL, title_err, tipmsg);
881 }
882
883 set_percent(0);
884 ui->ButtonRefresh->setEnabled(true);
885 ui->ButtonInstall->setEnabled(true);
886 ui->ButtonRefresh->setEnabled(true);
887
888 snprintf(disk_name, sizeof(disk_name), "%s", g_disk_list[m_thread->m_index].disk_name);
889 FillDeviceList(disk_name);
890 }
891 }