Skip to content

Commit 7171281

Browse files
Merge pull request #774 from g-maxime/qt6
Add Qt6 compatibility
2 parents ba29768 + d38c4bb commit 7171281

14 files changed

+172
-229
lines changed

Source/GUI/Qt/WebCommonPage.cpp

+7-16
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <QFileDialog>
1515
#include <QTextStream>
1616
#include <QDesktopServices>
17+
#include <QRegularExpression>
1718

1819
namespace MediaConch
1920
{
@@ -82,7 +83,6 @@ namespace MediaConch
8283
return;
8384

8485
QTextStream out(&file);
85-
out.setCodec("UTF-8");
8686
out << report;
8787
}
8888

@@ -795,34 +795,25 @@ namespace MediaConch
795795
//---------------------------------------------------------------------------
796796
bool WebCommonPage::report_is_html(const QString& report)
797797
{
798-
QRegExp reg("^(<\\!DOCTYPE.*html|<html>.*</html>$)", Qt::CaseInsensitive);
798+
QRegularExpression reg("^(<\\!DOCTYPE.*html|<html>.*</html>$)", QRegularExpression::CaseInsensitiveOption);
799799

800-
if (reg.indexIn(report.trimmed(), 0) != -1)
801-
return true;
802-
803-
return false;
800+
return reg.match(report.trimmed()).hasMatch();
804801
}
805802

806803
//---------------------------------------------------------------------------
807804
bool WebCommonPage::report_is_xml(const QString& report)
808805
{
809-
QRegExp reg("<\\?xml ", Qt::CaseInsensitive);
810-
811-
if (reg.indexIn(report, 0) != -1)
812-
return true;
806+
QRegularExpression reg("<\\?xml ", QRegularExpression::CaseInsensitiveOption);
813807

814-
return false;
808+
return reg.match(report).hasMatch();
815809
}
816810

817811
//---------------------------------------------------------------------------
818812
bool WebCommonPage::report_is_json(const QString& report)
819813
{
820-
QRegExp reg("^\\{.*\\}$", Qt::CaseInsensitive);
821-
822-
if (reg.indexIn(report.trimmed(), 0) != -1)
823-
return true;
814+
QRegularExpression reg("^\\{.*\\}$", QRegularExpression::CaseInsensitiveOption);
824815

825-
return false;
816+
return reg.match(report.trimmed()).hasMatch();
826817
}
827818

828819
QString WebCommonPage::get_file_tool(const QString& file)

Source/GUI/Qt/WebEnginePage.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ namespace MediaConch
7676
{
7777
QString value_input;
7878
if (select_file_name == "checkerRepository_directory")
79-
value_input = QFileDialog::getExistingDirectory(view(), NULL, suggested);
79+
value_input = QFileDialog::getExistingDirectory(NULL, NULL, suggested);
8080
else
81-
value_input = QFileDialog::getOpenFileName(view(), NULL, suggested);
81+
value_input = QFileDialog::getOpenFileName(NULL, NULL, suggested);
8282

8383
QMap<QString, QStringList>::iterator it = file_selector.find(select_file_name);
8484
if (!value_input.length())
@@ -103,7 +103,7 @@ namespace MediaConch
103103
}
104104
else
105105
{
106-
QStringList names = QFileDialog::getOpenFileNames(view(), QString::null, suggested);
106+
QStringList names = QFileDialog::getOpenFileNames(NULL, QString(), suggested);
107107

108108
if (names.size())
109109
{

Source/GUI/Qt/checkerwindow.cpp

+65-75
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
#include <QTextEdit>
1919
#include <QProgressBar>
20-
#include <QDesktopWidget>
2120
#include <QFileDialog>
2221
#include <QUrl>
22+
#include <QRegularExpression>
2323
#if QT_VERSION >= 0x050000
2424
#include <QStandardPaths>
2525
#else
@@ -213,139 +213,136 @@ void CheckerWindow::create_parsespeed_options(QString& parsespeed)
213213
//---------------------------------------------------------------------------
214214
void CheckerWindow::add_policy_to_html_selection(QString& policies, QString& html, const QString& selector)
215215
{
216-
QRegExp reg("class=\"policyList form-control\">");
216+
QRegularExpression reg("class=\"policyList form-control\">", QRegularExpression::InvertedGreedinessOption);
217217
int pos = html.indexOf(selector);
218218

219-
reg.setMinimal(true);
220-
221219
if (pos == -1)
222220
return;
223221

224-
if ((pos = reg.indexIn(html, pos)) != -1)
222+
QRegularExpressionMatch match = reg.match(html, pos);
223+
if ((pos = match.capturedStart()) != -1)
225224
{
226-
pos += reg.matchedLength();
225+
pos += match.capturedLength();
227226
html.insert(pos, policies);
228227
}
229228
}
230229

231230
//---------------------------------------------------------------------------
232231
void CheckerWindow::add_display_to_html_selection(QString& displays, QString& html, const QString& selector)
233232
{
234-
QRegExp reg("class=\"displayList form-control\">");
235-
reg.setMinimal(true);
233+
QRegularExpression reg("class=\"displayList form-control\">", QRegularExpression::InvertedGreedinessOption);
236234

237235
int pos = html.indexOf(selector);
238236
if (pos == -1)
239237
return;
240238

241-
if ((pos = reg.indexIn(html, pos)) != -1)
239+
QRegularExpressionMatch match = reg.match(html, pos);
240+
if ((pos = match.capturedStart()) != -1)
242241
{
243-
pos += reg.matchedLength();
242+
pos += match.capturedLength();
244243
html.insert(pos, displays);
245244
}
246245
}
247246

248247
//---------------------------------------------------------------------------
249248
void CheckerWindow::add_verbosity_to_html_selection(QString& verbosity, QString& html, const QString& selector)
250249
{
251-
QRegExp reg("class=\"verbosityList form-control\">");
252-
reg.setMinimal(true);
250+
QRegularExpression reg("class=\"verbosityList form-control\">", QRegularExpression::InvertedGreedinessOption);
253251

254252
int pos = html.indexOf(selector);
255253
if (pos == -1)
256254
return;
257255

258-
if ((pos = reg.indexIn(html, pos)) != -1)
256+
QRegularExpressionMatch match = reg.match(html, pos);
257+
if ((pos = match.capturedStart()) != -1)
259258
{
260-
pos += reg.matchedLength();
259+
pos += match.capturedLength();
261260
html.insert(pos, verbosity);
262261
}
263262
}
264263

265264
//---------------------------------------------------------------------------
266265
void CheckerWindow::add_parsespeed_to_html_selection(QString& parsespeed, QString& html, const QString& selector)
267266
{
268-
QRegExp reg("class=\"parsespeedList form-control\">");
269-
reg.setMinimal(true);
267+
QRegularExpression reg("class=\"parsespeedList form-control\">", QRegularExpression::InvertedGreedinessOption);
270268

271269
int pos = html.indexOf(selector);
272270
if (pos == -1)
273271
return;
274272

275-
if ((pos = reg.indexIn(html, pos)) != -1)
273+
QRegularExpressionMatch match = reg.match(html, pos);
274+
if ((pos = match.capturedStart()) != -1)
276275
{
277-
pos += reg.matchedLength();
276+
pos += match.capturedLength();
278277
html.insert(pos, parsespeed);
279278
}
280279
}
281280

282281
//---------------------------------------------------------------------------
283282
void CheckerWindow::load_include_in_template(QString& html)
284283
{
285-
QRegExp reg("\\{\\{[\\s]+include\\('AppBundle:(\\w+):(\\w+).html.twig'(,[\\s]*\\{ '\\w+':[\\s]*\\w+[\\s]*\\})?\\)[\\s]\\}\\}");
284+
QRegularExpression reg("\\{\\{[\\s]+include\\('AppBundle:(\\w+):(\\w+).html.twig'(,[\\s]*\\{ '\\w+':[\\s]*\\w+[\\s]*\\})?\\)[\\s]\\}\\}");
285+
QRegularExpressionMatch match;
286286
int pos = 0;
287287

288-
while ((pos = reg.indexIn(html, pos)) != -1)
288+
while ((pos = (match = reg.match(html, pos)).capturedStart()) != -1)
289289
{
290-
QString app = reg.cap(1);
291-
QString module = reg.cap(2);
290+
QString app = match.captured(1);
291+
QString module = match.captured(2);
292292
if (app == "Default" && module == "quotaExceeded")
293293
{
294-
html.replace(pos, reg.matchedLength(), "");
294+
html.replace(match.capturedStart(), match.capturedLength(), "");
295295
continue;
296296
}
297-
html.replace(pos, reg.matchedLength(), "");
297+
html.replace(match.capturedStart(), match.capturedLength(), "");
298298
pos = 0;
299299
}
300300
}
301301

302302
//---------------------------------------------------------------------------
303303
void CheckerWindow::remove_element_in_template(QString& html)
304304
{
305-
QRegExp reg("\\{% (.*) %\\}");
306-
int pos = 0;
307-
308-
reg.setMinimal(true);
309-
while ((pos = reg.indexIn(html, pos)) != -1)
310-
html.replace(pos, reg.matchedLength(), "");
305+
QRegularExpression reg("\\{% (.*) %\\}", QRegularExpression::InvertedGreedinessOption);
306+
html.replace(reg, "");
311307
}
312308

313309
//---------------------------------------------------------------------------
314310
void CheckerWindow::change_collapse_form(QString& html)
315311
{
316-
QRegExp reg("class=\"panel-collapse collapse in\"");
317-
int pos = 0;
318-
319-
while ((pos = reg.indexIn(html, pos)) != -1)
320-
html.replace(pos, reg.matchedLength(), "class=\"panel-collapse collapse\"");
312+
QRegularExpression reg("class=\"panel-collapse collapse in\"");
313+
html.replace(reg, "class=\"panel-collapse collapse\"");
321314
}
322315

323316
//---------------------------------------------------------------------------
324317
void CheckerWindow::load_form_in_template(QString& html)
325318
{
326-
QRegExp reg("\\{\\{[\\s]+form\\((\\w+)\\)[\\s]\\}\\}");
327-
int pos = 0;
319+
QRegularExpression reg("\\{\\{[\\s]+form\\((\\w+)\\)[\\s]\\}\\}");
320+
QRegularExpressionMatch match;
328321

329322
bool has_libcurl = main_window->mil_has_curl_enabled();
330-
while ((pos = reg.indexIn(html, pos)) != -1)
323+
324+
int pos = 0;
325+
while ((pos = (match = reg.match(html)).capturedStart()) != -1)
331326
{
332-
QString value = reg.cap(1);
327+
QString value = match.captured(1);
333328
if (value == "formUpload")
334-
html.replace(pos, reg.matchedLength(), create_form_upload());
329+
{
330+
html.replace(match.capturedStart(), match.capturedLength(), create_form_upload());
331+
}
335332
else if (value == "formOnline")
336333
{
337334
if (has_libcurl)
338-
html.replace(pos, reg.matchedLength(), create_form_online());
335+
html.replace(match.capturedStart(), match.capturedLength(), create_form_online());
339336
else
340337
{
341338
remove_form_online(pos, html);
342-
remove_li_online(pos, html);
339+
remove_li_online(html);
343340
}
344341
}
345342
else if (value == "formRepository")
346-
html.replace(pos, reg.matchedLength(), create_form_repository());
343+
html.replace(match.capturedStart(), match.capturedLength(), create_form_repository());
347344
else
348-
html.replace(pos, reg.matchedLength(), "");
345+
html.replace(match.capturedStart(), match.capturedLength(), "");
349346
}
350347

351348
change_collapse_form(html);
@@ -413,40 +410,31 @@ QString CheckerWindow::create_form_online()
413410
void CheckerWindow::remove_form_online(int pos, QString& html)
414411
{
415412
int start_div_pos = pos;
416-
QRegExp reg("<div role=\"tabpanel\" class=\"tab-pane panel col-md-12\" id=\"url\">");
417-
reg.setMinimal(true);
418-
start_div_pos = reg.lastIndexIn(html, start_div_pos);
413+
start_div_pos = html.lastIndexOf("<div role=\"tabpanel\" class=\"tab-pane panel col-md-12\" id=\"url\">", start_div_pos);
419414

420-
reg = QRegExp("</div>");
421-
reg.setMinimal(true);
422-
int end_div_pos = pos;
423-
if ((end_div_pos = reg.indexIn(html, end_div_pos)) != -1)
424-
end_div_pos += reg.matchedLength();
415+
int end_div_pos = html.indexOf("</div>", start_div_pos);
416+
if (end_div_pos != -1)
417+
end_div_pos += 6;
425418

426419
if (end_div_pos != -1 && start_div_pos != -1)
427420
html.remove(start_div_pos, end_div_pos - start_div_pos);
428421
}
429422

430423
//---------------------------------------------------------------------------
431-
void CheckerWindow::remove_li_online(int& pos, QString& html)
424+
void CheckerWindow::remove_li_online(QString& html)
432425
{
433-
QRegExp reg("<li role=\"presentation\" class=\"\"><a href=\"#url\"");
434-
reg.setMinimal(true);
435-
int start = reg.lastIndexIn(html);
426+
int start = html.lastIndexOf("<li role=\"presentation\" class=\"\"><a href=\"#url\"");
436427
if (start == -1)
437428
return;
438429

439-
reg = QRegExp("</li>");
440-
reg.setMinimal(true);
441-
int end_pos = -1;
442-
if ((end_pos = reg.indexIn(html, start)) != -1)
443-
end_pos += reg.matchedLength();
430+
int end_pos = html.indexOf("</li>", start);
431+
if (end_pos != -1)
432+
end_pos += 5;
444433

445434
if (end_pos != -1 && start != -1)
446435
{
447436
int len = end_pos - start;
448437
html.remove(start, len);
449-
pos -= len;
450438
}
451439
}
452440

@@ -503,23 +491,24 @@ void CheckerWindow::create_html_checker(QString& checker)
503491
//---------------------------------------------------------------------------
504492
void CheckerWindow::change_checker_in_template(const QString& checker, QString& html)
505493
{
506-
QRegExp reg("\\{% block checker %\\}\\{% endblock %\\}");
494+
QRegularExpression reg("\\{% block checker %\\}\\{% endblock %\\}", QRegularExpression::InvertedGreedinessOption);
507495
int pos = 0;
508496

509-
reg.setMinimal(true);
510-
while ((pos = reg.indexIn(html, pos)) != -1)
511-
html.replace(pos, reg.matchedLength(), checker);
497+
QRegularExpressionMatch match;
498+
while ((match = reg.match(html, pos)).hasMatch())
499+
{
500+
pos = match.capturedStart();
501+
html.replace(pos, match.capturedLength(), checker);
502+
}
512503
}
513504

514505
//---------------------------------------------------------------------------
515506
void CheckerWindow::change_body_script_in_template(QString& html)
516507
{
517-
QRegExp reg("\\{\\{ QT_SCRIPTS \\}\\}");
508+
QRegularExpression reg("\\{\\{ QT_SCRIPTS \\}\\}", QRegularExpression::InvertedGreedinessOption);
518509
QString script;
519510
int pos = 0;
520511

521-
reg.setMinimal(true);
522-
523512
#if defined(WEB_MACHINE_KIT)
524513
script += " <script type=\"text/javascript\" src=\"qrc:/checker/webkit.js\"></script>\n";
525514
#elif defined(WEB_MACHINE_ENGINE)
@@ -539,25 +528,26 @@ void CheckerWindow::change_body_script_in_template(QString& html)
539528
" <script type=\"text/javascript\" src=\"qrc:/utils/text.js\"></script>\n"
540529
" <script type=\"text/javascript\" src=\"qrc:/menu.js\"></script>\n";
541530

542-
if ((pos = reg.indexIn(html, pos)) != -1)
543-
html.replace(pos, reg.matchedLength(), script);
531+
QRegularExpressionMatch match = reg.match(html, pos);
532+
if ((pos = match.capturedStart()) != -1)
533+
html.replace(pos, match.capturedLength(), script);
544534
}
545535

546536
//---------------------------------------------------------------------------
547537
void CheckerWindow::set_webmachine_script_in_template(QString& html)
548538
{
549-
QRegExp reg("\\{\\{[\\s]+webmachine[\\s]\\}\\}");
539+
QRegularExpression reg("\\{\\{[\\s]+webmachine[\\s]\\}\\}", QRegularExpression::InvertedGreedinessOption);
550540
QString machine;
551541
int pos = 0;
552542

553-
reg.setMinimal(true);
554543
#if defined(WEB_MACHINE_KIT)
555544
machine = "WEB_MACHINE_KIT";
556545
#elif defined(WEB_MACHINE_ENGINE)
557546
machine = "WEB_MACHINE_ENGINE";
558547
#endif
559-
if ((pos = reg.indexIn(html, pos)) != -1)
560-
html.replace(pos, reg.matchedLength(), machine);
548+
QRegularExpressionMatch match = reg.match(html, pos);
549+
if ((pos = match.capturedStart()) != -1)
550+
html.replace(pos, match.capturedLength(), machine);
561551
}
562552

563553
//---------------------------------------------------------------------------

Source/GUI/Qt/checkerwindow.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class CheckerWindow : public CommonWebWindow
6565
QString create_form_online();
6666
QString create_form_repository();
6767
void remove_form_online(int pos, QString& html);
68-
void remove_li_online(int& pos, QString& html);
68+
void remove_li_online(QString& html);
6969
void change_collapse_form(QString& html);
7070
void change_checker_in_template(const QString& checker, QString& html);
7171
void change_body_script_in_template(QString& html);

0 commit comments

Comments
 (0)