Skip to content

Commit

Permalink
Add Qt6 compatibility
Browse files Browse the repository at this point in the history
Signed-off-by: Maxime Gervais <[email protected]>
  • Loading branch information
g-maxime committed Jan 10, 2024
1 parent d3393c3 commit d38c4bb
Show file tree
Hide file tree
Showing 14 changed files with 172 additions and 229 deletions.
23 changes: 7 additions & 16 deletions Source/GUI/Qt/WebCommonPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <QFileDialog>
#include <QTextStream>
#include <QDesktopServices>
#include <QRegularExpression>

namespace MediaConch
{
Expand Down Expand Up @@ -82,7 +83,6 @@ namespace MediaConch
return;

QTextStream out(&file);
out.setCodec("UTF-8");
out << report;
}

Expand Down Expand Up @@ -785,34 +785,25 @@ namespace MediaConch
//---------------------------------------------------------------------------
bool WebCommonPage::report_is_html(const QString& report)
{
QRegExp reg("^(<\\!DOCTYPE.*html|<html>.*</html>$)", Qt::CaseInsensitive);
QRegularExpression reg("^(<\\!DOCTYPE.*html|<html>.*</html>$)", QRegularExpression::CaseInsensitiveOption);

if (reg.indexIn(report.trimmed(), 0) != -1)
return true;

return false;
return reg.match(report.trimmed()).hasMatch();
}

//---------------------------------------------------------------------------
bool WebCommonPage::report_is_xml(const QString& report)
{
QRegExp reg("<\\?xml ", Qt::CaseInsensitive);

if (reg.indexIn(report, 0) != -1)
return true;
QRegularExpression reg("<\\?xml ", QRegularExpression::CaseInsensitiveOption);

return false;
return reg.match(report).hasMatch();
}

//---------------------------------------------------------------------------
bool WebCommonPage::report_is_json(const QString& report)
{
QRegExp reg("^\\{.*\\}$", Qt::CaseInsensitive);

if (reg.indexIn(report.trimmed(), 0) != -1)
return true;
QRegularExpression reg("^\\{.*\\}$", QRegularExpression::CaseInsensitiveOption);

return false;
return reg.match(report.trimmed()).hasMatch();
}

QString WebCommonPage::get_file_tool(const QString& file)
Expand Down
6 changes: 3 additions & 3 deletions Source/GUI/Qt/WebEnginePage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ namespace MediaConch
{
QString value_input;
if (select_file_name == "checkerRepository_directory")
value_input = QFileDialog::getExistingDirectory(view(), NULL, suggested);
value_input = QFileDialog::getExistingDirectory(NULL, NULL, suggested);
else
value_input = QFileDialog::getOpenFileName(view(), NULL, suggested);
value_input = QFileDialog::getOpenFileName(NULL, NULL, suggested);

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

if (names.size())
{
Expand Down
140 changes: 65 additions & 75 deletions Source/GUI/Qt/checkerwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

#include <QTextEdit>
#include <QProgressBar>
#include <QDesktopWidget>
#include <QFileDialog>
#include <QUrl>
#include <QRegularExpression>
#if QT_VERSION >= 0x050000
#include <QStandardPaths>
#else
Expand Down Expand Up @@ -213,139 +213,136 @@ void CheckerWindow::create_parsespeed_options(QString& parsespeed)
//---------------------------------------------------------------------------
void CheckerWindow::add_policy_to_html_selection(QString& policies, QString& html, const QString& selector)
{
QRegExp reg("class=\"policyList form-control\">");
QRegularExpression reg("class=\"policyList form-control\">", QRegularExpression::InvertedGreedinessOption);
int pos = html.indexOf(selector);

reg.setMinimal(true);

if (pos == -1)
return;

if ((pos = reg.indexIn(html, pos)) != -1)
QRegularExpressionMatch match = reg.match(html, pos);
if ((pos = match.capturedStart()) != -1)
{
pos += reg.matchedLength();
pos += match.capturedLength();
html.insert(pos, policies);
}
}

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

int pos = html.indexOf(selector);
if (pos == -1)
return;

if ((pos = reg.indexIn(html, pos)) != -1)
QRegularExpressionMatch match = reg.match(html, pos);
if ((pos = match.capturedStart()) != -1)
{
pos += reg.matchedLength();
pos += match.capturedLength();
html.insert(pos, displays);
}
}

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

int pos = html.indexOf(selector);
if (pos == -1)
return;

if ((pos = reg.indexIn(html, pos)) != -1)
QRegularExpressionMatch match = reg.match(html, pos);
if ((pos = match.capturedStart()) != -1)
{
pos += reg.matchedLength();
pos += match.capturedLength();
html.insert(pos, verbosity);
}
}

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

int pos = html.indexOf(selector);
if (pos == -1)
return;

if ((pos = reg.indexIn(html, pos)) != -1)
QRegularExpressionMatch match = reg.match(html, pos);
if ((pos = match.capturedStart()) != -1)
{
pos += reg.matchedLength();
pos += match.capturedLength();
html.insert(pos, parsespeed);
}
}

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

while ((pos = reg.indexIn(html, pos)) != -1)
while ((pos = (match = reg.match(html, pos)).capturedStart()) != -1)
{
QString app = reg.cap(1);
QString module = reg.cap(2);
QString app = match.captured(1);
QString module = match.captured(2);
if (app == "Default" && module == "quotaExceeded")
{
html.replace(pos, reg.matchedLength(), "");
html.replace(match.capturedStart(), match.capturedLength(), "");
continue;
}
html.replace(pos, reg.matchedLength(), "");
html.replace(match.capturedStart(), match.capturedLength(), "");
pos = 0;
}
}

//---------------------------------------------------------------------------
void CheckerWindow::remove_element_in_template(QString& html)
{
QRegExp reg("\\{% (.*) %\\}");
int pos = 0;

reg.setMinimal(true);
while ((pos = reg.indexIn(html, pos)) != -1)
html.replace(pos, reg.matchedLength(), "");
QRegularExpression reg("\\{% (.*) %\\}", QRegularExpression::InvertedGreedinessOption);
html.replace(reg, "");
}

//---------------------------------------------------------------------------
void CheckerWindow::change_collapse_form(QString& html)
{
QRegExp reg("class=\"panel-collapse collapse in\"");
int pos = 0;

while ((pos = reg.indexIn(html, pos)) != -1)
html.replace(pos, reg.matchedLength(), "class=\"panel-collapse collapse\"");
QRegularExpression reg("class=\"panel-collapse collapse in\"");
html.replace(reg, "class=\"panel-collapse collapse\"");
}

//---------------------------------------------------------------------------
void CheckerWindow::load_form_in_template(QString& html)
{
QRegExp reg("\\{\\{[\\s]+form\\((\\w+)\\)[\\s]\\}\\}");
int pos = 0;
QRegularExpression reg("\\{\\{[\\s]+form\\((\\w+)\\)[\\s]\\}\\}");
QRegularExpressionMatch match;

bool has_libcurl = main_window->mil_has_curl_enabled();
while ((pos = reg.indexIn(html, pos)) != -1)

int pos = 0;
while ((pos = (match = reg.match(html)).capturedStart()) != -1)
{
QString value = reg.cap(1);
QString value = match.captured(1);
if (value == "formUpload")
html.replace(pos, reg.matchedLength(), create_form_upload());
{
html.replace(match.capturedStart(), match.capturedLength(), create_form_upload());
}
else if (value == "formOnline")
{
if (has_libcurl)
html.replace(pos, reg.matchedLength(), create_form_online());
html.replace(match.capturedStart(), match.capturedLength(), create_form_online());
else
{
remove_form_online(pos, html);
remove_li_online(pos, html);
remove_li_online(html);
}
}
else if (value == "formRepository")
html.replace(pos, reg.matchedLength(), create_form_repository());
html.replace(match.capturedStart(), match.capturedLength(), create_form_repository());
else
html.replace(pos, reg.matchedLength(), "");
html.replace(match.capturedStart(), match.capturedLength(), "");
}

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

reg = QRegExp("</div>");
reg.setMinimal(true);
int end_div_pos = pos;
if ((end_div_pos = reg.indexIn(html, end_div_pos)) != -1)
end_div_pos += reg.matchedLength();
int end_div_pos = html.indexOf("</div>", start_div_pos);
if (end_div_pos != -1)
end_div_pos += 6;

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

//---------------------------------------------------------------------------
void CheckerWindow::remove_li_online(int& pos, QString& html)
void CheckerWindow::remove_li_online(QString& html)
{
QRegExp reg("<li role=\"presentation\" class=\"\"><a href=\"#url\"");
reg.setMinimal(true);
int start = reg.lastIndexIn(html);
int start = html.lastIndexOf("<li role=\"presentation\" class=\"\"><a href=\"#url\"");
if (start == -1)
return;

reg = QRegExp("</li>");
reg.setMinimal(true);
int end_pos = -1;
if ((end_pos = reg.indexIn(html, start)) != -1)
end_pos += reg.matchedLength();
int end_pos = html.indexOf("</li>", start);
if (end_pos != -1)
end_pos += 5;

if (end_pos != -1 && start != -1)
{
int len = end_pos - start;
html.remove(start, len);
pos -= len;
}
}

Expand Down Expand Up @@ -503,23 +491,24 @@ void CheckerWindow::create_html_checker(QString& checker)
//---------------------------------------------------------------------------
void CheckerWindow::change_checker_in_template(const QString& checker, QString& html)
{
QRegExp reg("\\{% block checker %\\}\\{% endblock %\\}");
QRegularExpression reg("\\{% block checker %\\}\\{% endblock %\\}", QRegularExpression::InvertedGreedinessOption);
int pos = 0;

reg.setMinimal(true);
while ((pos = reg.indexIn(html, pos)) != -1)
html.replace(pos, reg.matchedLength(), checker);
QRegularExpressionMatch match;
while ((match = reg.match(html, pos)).hasMatch())
{
pos = match.capturedStart();
html.replace(pos, match.capturedLength(), checker);
}
}

//---------------------------------------------------------------------------
void CheckerWindow::change_body_script_in_template(QString& html)
{
QRegExp reg("\\{\\{ QT_SCRIPTS \\}\\}");
QRegularExpression reg("\\{\\{ QT_SCRIPTS \\}\\}", QRegularExpression::InvertedGreedinessOption);
QString script;
int pos = 0;

reg.setMinimal(true);

#if defined(WEB_MACHINE_KIT)
script += " <script type=\"text/javascript\" src=\"qrc:/checker/webkit.js\"></script>\n";
#elif defined(WEB_MACHINE_ENGINE)
Expand All @@ -539,25 +528,26 @@ void CheckerWindow::change_body_script_in_template(QString& html)
" <script type=\"text/javascript\" src=\"qrc:/utils/text.js\"></script>\n"
" <script type=\"text/javascript\" src=\"qrc:/menu.js\"></script>\n";

if ((pos = reg.indexIn(html, pos)) != -1)
html.replace(pos, reg.matchedLength(), script);
QRegularExpressionMatch match = reg.match(html, pos);
if ((pos = match.capturedStart()) != -1)
html.replace(pos, match.capturedLength(), script);
}

//---------------------------------------------------------------------------
void CheckerWindow::set_webmachine_script_in_template(QString& html)
{
QRegExp reg("\\{\\{[\\s]+webmachine[\\s]\\}\\}");
QRegularExpression reg("\\{\\{[\\s]+webmachine[\\s]\\}\\}", QRegularExpression::InvertedGreedinessOption);
QString machine;
int pos = 0;

reg.setMinimal(true);
#if defined(WEB_MACHINE_KIT)
machine = "WEB_MACHINE_KIT";
#elif defined(WEB_MACHINE_ENGINE)
machine = "WEB_MACHINE_ENGINE";
#endif
if ((pos = reg.indexIn(html, pos)) != -1)
html.replace(pos, reg.matchedLength(), machine);
QRegularExpressionMatch match = reg.match(html, pos);
if ((pos = match.capturedStart()) != -1)
html.replace(pos, match.capturedLength(), machine);
}

//---------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion Source/GUI/Qt/checkerwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class CheckerWindow : public CommonWebWindow
QString create_form_online();
QString create_form_repository();
void remove_form_online(int pos, QString& html);
void remove_li_online(int& pos, QString& html);
void remove_li_online(QString& html);
void change_collapse_form(QString& html);
void change_checker_in_template(const QString& checker, QString& html);
void change_body_script_in_template(QString& html);
Expand Down
Loading

0 comments on commit d38c4bb

Please sign in to comment.