From 2bd4245d85c70ce9a8d30116a5edca4a56a2554f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20A=2E=20L=C3=B3pez=20L=C3=B3pez?= Date: Sat, 8 Jun 2024 23:25:14 -0400 Subject: [PATCH 1/5] Add .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6ead3ca --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +mystiq.pro.user From 943e013db9a13d3f3cdd1fc84d5805979a9af09f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20A=2E=20L=C3=B3pez=20L=C3=B3pez?= Date: Sun, 9 Jun 2024 10:54:37 -0400 Subject: [PATCH 2/5] WIP: Migration to Qt6 All references to `QRegExp` changed to `QRegularExpression` and `QRegularExpressionMath` Changes related to `QMediaPlayer` API Other minor changes to remove warnings related to the usage of `char*` directly where `QString::fromLatin1` is reccommended. --- .gitignore | 1 + converter/audiofilter.cpp | 18 +- converter/conversionparameters.cpp | 19 +- converter/exepath.cpp | 11 +- converter/ffmpeginterface.cpp | 272 ++++---- converter/mediaconverter.cpp | 8 +- converter/mediaprobe.cpp | 113 ++-- converter/presets.cpp | 44 +- main.cpp | 45 +- mystiq.pro | 1 + services/constants.cpp | 49 +- services/filepathoperations.cpp | 12 +- services/versioncompare.cpp | 9 +- ui/mainwindow.cpp | 10 +- ui/mainwindow.cpp.autosave | 971 ----------------------------- ui/mediaplayerwidget.cpp | 39 +- ui/mediaplayerwidget.h | 2 + ui/optionsdialog.cpp | 2 +- ui/poweroffdialog.cpp | 4 +- ui/progressbar.cpp | 5 +- ui/timerangeedit.cpp | 4 +- ui/updatedialog.cpp | 14 +- 22 files changed, 373 insertions(+), 1280 deletions(-) delete mode 100644 ui/mainwindow.cpp.autosave diff --git a/.gitignore b/.gitignore index 6ead3ca..63e4f11 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ mystiq.pro.user +build/ diff --git a/converter/audiofilter.cpp b/converter/audiofilter.cpp index 7df21b0..0997088 100644 --- a/converter/audiofilter.cpp +++ b/converter/audiofilter.cpp @@ -61,7 +61,8 @@ AudioFilter::AudioFilter(QObject *parent) : QSet muxing, demuxing; FFmpegInterface::getSupportedMuxingFormats(muxing); FFmpegInterface::getSupportedDemuxingFormats(demuxing); - m_useSoxFormat = muxing.contains("sox") && demuxing.contains("sox"); + m_useSoxFormat = muxing.contains(QString::fromLatin1("sox")) + && demuxing.contains(QString::fromLatin1("sox")); } bool AudioFilter::start(ConversionParameters& params, QProcess *dest) @@ -81,21 +82,24 @@ bool AudioFilter::start(ConversionParameters& params, QProcess *dest) } // ffmpeg process settings - ffmpeg_param << "-i" << params.source << "-vn" << "-f" << fmt << "-"; + ffmpeg_param << QString::fromLatin1("-i") << params.source << QString::fromLatin1("-vn") + << QString::fromLatin1("-f") << QString::fromLatin1(fmt) + << QString::fromLatin1("-"); m_extractAudioProc->setStandardOutputProcess(m_soxProc); // sox process settings - sox_param << "-t" << fmt << "-" << "-t" << fmt << "-"; + sox_param << QString::fromLatin1("-t") << QString::fromLatin1(fmt) << QString::fromLatin1("-") + << QString::fromLatin1("-t") << QString::fromLatin1(fmt) << QString::fromLatin1("-"); if (params.speed_scaling) { - sox_param << "tempo" << QString::number(params.speed_scaling_factor); + sox_param << QString::fromLatin1("tempo") << QString::number(params.speed_scaling_factor); } m_soxProc->setStandardOutputProcess(dest); qDebug() << "ffmpeg" << ffmpeg_param; qDebug() << "sox" << sox_param; // start the two processes - m_extractAudioProc->start(ExePath::getPath("ffmpeg"), ffmpeg_param); - m_soxProc->start(ExePath::getPath("sox"), sox_param); + m_extractAudioProc->start(ExePath::getPath(QString::fromLatin1("ffmpeg")), ffmpeg_param); + m_soxProc->start(ExePath::getPath(QString::fromLatin1("sox")), sox_param); return m_extractAudioProc->waitForStarted(TIMEOUT) && m_soxProc->waitForStarted(TIMEOUT); @@ -104,6 +108,6 @@ bool AudioFilter::start(ConversionParameters& params, QProcess *dest) bool AudioFilter::available() { QProcess sox_process; - sox_process.start(ExePath::getPath("sox"), QStringList()); + sox_process.start(ExePath::getPath(QString::fromLatin1("sox")), QStringList()); return sox_process.waitForStarted(TIMEOUT); } diff --git a/converter/conversionparameters.cpp b/converter/conversionparameters.cpp index 574124a..91bf2c4 100644 --- a/converter/conversionparameters.cpp +++ b/converter/conversionparameters.cpp @@ -54,7 +54,7 @@ int parseFFmpegArguments(QStringList& args, int index, ConversionParameters& res #define CHECK_OPTION_2_METHOD(argument, property, convertmethod) \ else if (arg == argument) do { \ QString nextarg = args[index+1]; \ - nextarg.replace(QRegExp("[a-z]"), ""); /* remove units */ \ + nextarg.replace(QRegularExpression("[a-z]"), ""); /* remove units */ \ result.property = nextarg.convertmethod(); \ used_arg_count = 2; } while (0) @@ -112,17 +112,18 @@ int parseFFmpegArguments(QStringList& args, int index, ConversionParameters& res // width and height are in the same parameter (for example: "-s 800x600") CHECK_OPTION("-s") { - QRegExp pattern("([0-9]+)x([0-9]+)"); - if (pattern.indexIn(args[index+1]) != -1) { - result.video_width = pattern.cap(1).toInt(); - result.video_height = pattern.cap(2).toInt(); + QRegularExpression pattern(QString::fromLatin1("([0-9]+)x([0-9]+)")); + QRegularExpressionMatch match = pattern.match(args[index+1]); + if (match.hasMatch()) { + result.video_width = match.captured(1).toInt(); + result.video_height = match.captured(2).toInt(); used_arg_count = 2; } } CHECK_OPTION("-filter:v") { - QRegularExpression pattern("crop=(\\d+):(\\d+):(\\d+):(\\d+)"); + QRegularExpression pattern(QString::fromLatin1("crop=(\\d+):(\\d+):(\\d+):(\\d+)")); QRegularExpressionMatch match = pattern.match(args[index + 1]); if (match.hasMatch()) @@ -172,7 +173,7 @@ ConversionParameters ConversionParameters::fromFFmpegParameters(const QString ¶ms_str) { ConversionParameters result; - QStringList args = params_str.split(" ", QString::SkipEmptyParts); + QStringList args = params_str.split(QString::fromLatin1(" "), Qt::SkipEmptyParts); for (int i=0; i -#include +#include #include #include #include @@ -77,11 +77,11 @@ namespace inner { int find_encoders_in_desc(QStringList& target, const QString& s) { const char *keyword_begin = "(encoders:"; const char *keyword_end = ")"; - int begin = s.indexOf(keyword_begin); + int begin = s.indexOf(QString::fromLatin1(keyword_begin)); if (begin < 0) return 0; // encoder name not found in description begin += strlen(keyword_begin); - int end = s.indexOf(keyword_end, begin); + int end = s.indexOf(QString::fromLatin1(keyword_end), begin); if (end < 0) return 0; // error, mission ')' int length = end - begin; @@ -91,7 +91,7 @@ namespace inner { QString encoders_str = s.mid(begin, length); // split encoder_str into encoder names and skip whitespaces - QStringList encoders = encoders_str.split(' ', QString::SkipEmptyParts); + QStringList encoders = encoders_str.split(' ', Qt::SkipEmptyParts); foreach (QString s, encoders) { target.push_back(s); // fill codec names into the list } @@ -103,12 +103,12 @@ namespace inner { { QProcess ffmpeg_process; QStringList parameters; - parameters.push_back(QString(flag)); + parameters.push_back(QString::fromLatin1(flag)); ffmpeg_process.setReadChannel(QProcess::StandardOutput); //qDebug() << ExePath::getPath("ffmpeg") << parameters.join(" "); - ffmpeg_process.start(ExePath::getPath("ffmpeg"), parameters); + ffmpeg_process.start(ExePath::getPath(QString::fromLatin1("ffmpeg")), parameters); // Wait until ffmpeg has started. if (!ffmpeg_process.waitForStarted(TIMEOUT)) { @@ -125,7 +125,7 @@ namespace inner { } // Find all available encoders - QRegExp pattern("[ D]E([ VAS])...\\s+([^ ]+)\\s*(.*)$"); + QRegularExpression pattern(QString::fromLatin1("[ D]E([ VAS])...\\s+([^ ]+)\\s*(.*)$")); QStringList encoder_list; // temporary storage of encoder names const int AV_INDEX = 1; const int CODEC_NAME_INDEX = 2; @@ -133,27 +133,29 @@ namespace inner { ffmpeg_codec_info.clear(); while (ffmpeg_process.canReadLine()) { - QString line(ffmpeg_process.readLine()); + QString line(QString::fromLatin1(ffmpeg_process.readLine())); ffmpeg_codec_info.append(line); - if (pattern.indexIn(line) != -1) { - QString av = pattern.cap(AV_INDEX); - QString codec = pattern.cap(CODEC_NAME_INDEX); - QString desc = pattern.cap(CODEC_DESC); + QRegularExpressionMatch match = pattern.match(line); + if (match.hasMatch()) { + QString av = match.captured(AV_INDEX); + QString codec = match.captured(CODEC_NAME_INDEX); + QString desc = match.captured(CODEC_DESC); // extract codec names encoder_list.clear(); - if (!find_encoders_in_desc(encoder_list, desc)) + if (!find_encoders_in_desc(encoder_list, desc)) { encoder_list.push_back(codec); + } foreach (QString codec_name, encoder_list) { - if (av == "A") { // audio encoder + if (av == QString::fromLatin1("A")) { // audio encoder //qDebug() << "Audio Codec: " + codec_name; audio_encoders.push_back(codec_name); - } else if (av == "V") { // video encoder + } else if (av == QString::fromLatin1("V")) { // video encoder //qDebug() << "Video Codec: " + codec_name; video_encoders.push_back(codec_name); - } else if (av == "S") { // subtitle encoder + } else if (av == QString::fromLatin1("S")) { // subtitle encoder //qDebug() << "Subtitle Codec: " + codec_name; subtitle_encoders.push_back(codec_name); } @@ -168,14 +170,14 @@ namespace inner { { QProcess ffmpeg_process; QStringList parameters; - parameters.push_back(QString("-version")); + parameters.push_back(QString::fromLatin1("-version")); //qDebug() << ExePath::getPath("ffmpeg") << parameters.join(" "); - ffmpeg_process.start(ExePath::getPath("ffmpeg"), parameters); + ffmpeg_process.start(ExePath::getPath(QString::fromLatin1("ffmpeg")), parameters); ffmpeg_process.waitForStarted(TIMEOUT); ffmpeg_process.waitForFinished(TIMEOUT); - ffmpeg_version = QString(ffmpeg_process.readAll()); + ffmpeg_version = QString::fromLatin1(ffmpeg_process.readAll()); return true; } @@ -184,9 +186,9 @@ namespace inner { { QProcess ffmpeg_process; QStringList parameters; - parameters << "-formats"; + parameters << QString::fromLatin1("-formats"); - ffmpeg_process.start(ExePath::getPath("ffmpeg"), parameters); + ffmpeg_process.start(ExePath::getPath(QString::fromLatin1("ffmpeg")), parameters); ffmpeg_process.waitForStarted(TIMEOUT); ffmpeg_process.waitForFinished(TIMEOUT); @@ -197,20 +199,21 @@ namespace inner { demuxing_formats.clear(); ffmpeg_format_info.clear(); - QRegExp pattern("^ ([ D])([ E]) ([^ ]+)\\s+(.*)$"); + QRegularExpression pattern(QString::fromLatin1("^ ([ D])([ E]) ([^ ]+)\\s+(.*)$")); const int INDEX_DEMUX = 1; const int INDEX_MUX = 2; const int INDEX_NAME = 3; //const int INDEX_DETAIL = 4; while (ffmpeg_process.canReadLine()) { - QString line(ffmpeg_process.readLine()); + QString line(QString::fromLatin1(ffmpeg_process.readLine())); ffmpeg_format_info.append(line); - if (pattern.indexIn(line) != -1) { - QString name = pattern.cap(INDEX_NAME); - if (pattern.cap(INDEX_DEMUX) == "D") + QRegularExpressionMatch match = pattern.match(line); + if (match.hasMatch()) { + QString name = match.captured(INDEX_NAME); + if (match.captured(INDEX_DEMUX) == QString::fromLatin1("D")) demuxing_formats.append(name); - if (pattern.cap(INDEX_MUX) == "E") + if (match.captured(INDEX_MUX) == QString::fromLatin1("E")) muxing_formats.append(name); } } @@ -257,12 +260,10 @@ namespace inner { // extract error message from the line QString extract_errmsg(const QString& line) { - QRegExp pattern("^[^:]*:(.*)$"); + QRegularExpression pattern(QString::fromLatin1("^[^:]*:(.*)$")); const int INDEX_MESSAGE = 1; - if (pattern.indexIn(line) != -1) - return pattern.cap(INDEX_MESSAGE).trimmed(); - else - return ""; + QRegularExpressionMatch match = pattern.match(line); + return match.hasMatch() ? match.captured(INDEX_MESSAGE).trimmed() : QString::fromLatin1(""); } // scale sec with speed_factor if scale == true @@ -283,9 +284,9 @@ struct FFmpegInterface::Private double duration; double progress; QString stringBuffer; - QRegExp progress_pattern; - QRegExp progress_pattern_2; - QRegExp duration_pattern; + QRegularExpression progress_pattern; + QRegularExpression progress_pattern_2; + QRegularExpression duration_pattern; bool encoders_read; bool __dummy_padding[7]; // Avoid internally padding of struct on RAM @@ -295,11 +296,14 @@ struct FFmpegInterface::Private QString errmsg; - Private() : duration(0), progress(0) - , progress_pattern(patterns::progress) - , progress_pattern_2(patterns::progress2) - , duration_pattern(patterns::duration) - , encoders_read(false) { } + Private() + : duration(0) + , progress(0) + , progress_pattern(QString::fromLatin1(patterns::progress)) + , progress_pattern_2(QString::fromLatin1(patterns::progress2)) + , duration_pattern(QString::fromLatin1(patterns::duration)) + , encoders_read(false) + {} bool check_progress(const QString&); QStringList getOptionList(const ConversionParameters&, bool*, bool*); @@ -311,21 +315,22 @@ struct FFmpegInterface::Private */ bool FFmpegInterface::Private::check_progress(const QString& line) { - QRegExp& pattern = progress_pattern; - int index = pattern.indexIn(line); - if (index != -1) { - const double t = pattern.cap(patterns::PROG_1_TIME).toDouble(); + QRegularExpression &pattern = progress_pattern; + QRegularExpressionMatch match = pattern.match(line); + if (match.hasMatch()) { + const double t = match.captured(patterns::PROG_1_TIME).toDouble(); // calculate progress progress = (t / duration) * 100; return true; } else { // try another pattern - QRegExp& alternate_pattern = progress_pattern_2; - if (alternate_pattern.indexIn(line) != -1) { - const int hour = alternate_pattern.cap(patterns::PROG_2_HR).toInt(); - const int min = alternate_pattern.cap(patterns::PROG_2_MIN).toInt(); - const double sec = alternate_pattern.cap(patterns::PROG_2_SEC).toDouble(); + QRegularExpression &alternate_pattern = progress_pattern_2; + QRegularExpressionMatch match_alternate = alternate_pattern.match(line); + if (match_alternate.hasMatch()) { + const int hour = match_alternate.captured(patterns::PROG_2_HR).toInt(); + const int min = match_alternate.captured(patterns::PROG_2_MIN).toInt(); + const double sec = match_alternate.captured(patterns::PROG_2_SEC).toDouble(); const double t = hour*3600 + min*60 + sec; progress = (t / duration) * 100; @@ -361,21 +366,21 @@ QStringList FFmpegInterface::Private::getOptionList(const ConversionParameters & QStringList list; QString source = o.source; - int last_point_source = source.lastIndexOf("."); + int last_point_source = source.lastIndexOf(QString::fromLatin1(".")); -//Begins Subtitle files declaration - QString subtitlesrt, subtitlessa, subtitlesub, subtitleass; - if (last_point_source==-1){ - subtitlesrt = source+".srt"; - subtitlessa = source+".ssa"; - subtitlesub = source+".sub"; - subtitleass = source+".ass"; + //Begins Subtitle files declaration + QString subtitlesrt, subtitlessa, subtitlesub, subtitleass; + if (last_point_source == -1) { + subtitlesrt = source + ".srt"; + subtitlessa = source + ".ssa"; + subtitlesub = source + ".sub"; + subtitleass = source + ".ass"; } else{ - subtitlesrt = source.replace(last_point_source, 5, ".srt"); - subtitlessa = source.replace(last_point_source, 5, ".ssa"); - subtitlesub = source.replace(last_point_source, 5, ".sub"); - subtitleass = source.replace(last_point_source, 5, ".ass"); + subtitlesrt = source.replace(last_point_source, 5, QString::fromLatin1(".srt")); + subtitlessa = source.replace(last_point_source, 5, QString::fromLatin1(".ssa")); + subtitlesub = source.replace(last_point_source, 5, QString::fromLatin1(".sub")); + subtitleass = source.replace(last_point_source, 5, QString::fromLatin1(".ass")); } QFile subtitle_srt, subtitle_ssa, subtitle_sub, subtitle_ass; subtitle_srt.setFileName(subtitlesrt); @@ -400,30 +405,42 @@ QStringList FFmpegInterface::Private::getOptionList(const ConversionParameters & #endif if (subtitle_srt.exists()) { - command = QString("subtitles='%1':force_style='FontName=Sans Serif,OutlineColour=&H00000000,WrapStyle=2,Borderstyle=1,Outline=1,Shadow=1,Fontsize=28':charenc=ISO-8859-1").arg(subtitlesrt); + command = QString::fromLatin1("subtitles='%1':force_style='FontName=Sans " + "Serif,OutlineColour=&H00000000,WrapStyle=2,Borderstyle=" + "1,Outline=1,Shadow=1,Fontsize=28':charenc=ISO-8859-1") + .arg(subtitlesrt); } else if (subtitle_ssa.exists()) { - command = QString("subtitles='%1':force_style='FontName=Sans Serif,OutlineColour=&H00000000,WrapStyle=2,Borderstyle=1,Outline=1,Shadow=1,Fontsize=28':charenc=ISO-8859-1").arg(subtitlessa); + command = QString::fromLatin1("subtitles='%1':force_style='FontName=Sans " + "Serif,OutlineColour=&H00000000,WrapStyle=2,Borderstyle=" + "1,Outline=1,Shadow=1,Fontsize=28':charenc=ISO-8859-1") + .arg(subtitlessa); } else if (subtitle_sub.exists()) { - command = QString("subtitles='%1':force_style='FontName=Sans Serif,OutlineColour=&H00000000,WrapStyle=2,Borderstyle=1,Outline=1,Shadow=1,Fontsize=28':charenc=ISO-8859-1").arg(subtitlesub); + command = QString::fromLatin1("subtitles='%1':force_style='FontName=Sans " + "Serif,OutlineColour=&H00000000,WrapStyle=2,Borderstyle=" + "1,Outline=1,Shadow=1,Fontsize=28':charenc=ISO-8859-1") + .arg(subtitlesub); } else if (subtitle_ass.exists()) { - command = QString("subtitles='%1':force_style='FontName=Sans Serif,OutlineColour=&H00000000,WrapStyle=2,Borderstyle=1,Outline=1,Shadow=1,Fontsize=28':charenc=ISO-8859-1").arg(subtitleass); + command = QString::fromLatin1("subtitles='%1':force_style='FontName=Sans " + "Serif,OutlineColour=&H00000000,WrapStyle=2,Borderstyle=" + "1,Outline=1,Shadow=1,Fontsize=28':charenc=ISO-8859-1") + .arg(subtitleass); } //Finishing Subtitle files declaration // overwrite if file exists - list.append("-y"); + list.append(QString::fromLatin1("-y")); if (!bNeedsAudioFilter) { /* in this configuration, input is read from file arguments: -i */ - list << "-i" << o.source; + list << QString::fromLatin1("-i") << o.source; } else { /* In this configuration, video (if any) is read from file and audio is read from stdin @@ -433,11 +450,12 @@ QStringList FFmpegInterface::Private::getOptionList(const ConversionParameters & arguments: -i - */ if (probe.hasVideo() && !o.disable_video) - list << "-i" << o.source << "-i" << "-" - << "-map" << QString("0:%1").arg(probe.videoStreamIndex()) - << "-map" << "1"; + list << QString::fromLatin1("-i") << o.source << QString::fromLatin1("-i") + << QString::fromLatin1("-") << QString::fromLatin1("-map") + << QString::fromLatin1("0:%1").arg(probe.videoStreamIndex()) + << QString::fromLatin1("-map") << QString::fromLatin1("1"); else{ - list << "-i" << "-"; + list << QString::fromLatin1("-i") << QString::fromLatin1("-"); } } @@ -446,14 +464,14 @@ QStringList FFmpegInterface::Private::getOptionList(const ConversionParameters & /* ==== Additional Options ==== */ if (!o.ffmpeg_options.isEmpty()) { - QList additional_options = - o.ffmpeg_options.split(" ", QString::SkipEmptyParts); + QList additional_options = o.ffmpeg_options.split(QString::fromLatin1(" "), + Qt::SkipEmptyParts); foreach (QString opt, additional_options) list.append(opt); } if (o.threads >= 2) { - list.append("-threads"); + list.append(QString::fromLatin1("-threads")); list.append(QString::number(o.threads)); } @@ -461,21 +479,21 @@ QStringList FFmpegInterface::Private::getOptionList(const ConversionParameters & // Audio Options if (o.disable_audio) { - list.append("-an"); // no audio + list.append(QString::fromLatin1("-an")); // no audio } else if (o.copy_audio) { // copy audio data (no re-encode) - list.append("-acodec"); - list.append("copy"); + list.append(QString::fromLatin1("-acodec")); + list.append(QString::fromLatin1("copy")); } else { // audio enabled // audio bitrate in kb/s if (o.audio_bitrate > 0) { - list.append("-ab"); - list.append(QString("%1k").arg(o.audio_bitrate)); + list.append(QString::fromLatin1("-ab")); + list.append(QString::fromLatin1("%1k").arg(o.audio_bitrate)); } // audio sample rate in hz if (o.audio_sample_rate > 0) { - list.append("-ar"); + list.append(QString::fromLatin1("-ar")); int sample_rate = o.audio_sample_rate; if (o.audio_keep_sample_rate @@ -485,46 +503,46 @@ QStringList FFmpegInterface::Private::getOptionList(const ConversionParameters & qDebug() << "Apply probed sample rate: " + QString::number(sample_rate); } - list.append(QString("%1").arg(sample_rate)); + list.append(QString::fromLatin1("%1").arg(sample_rate)); } // audio channels if (o.audio_channels > 0) { - list.append("-ac"); - list.append(QString("%1").arg(o.audio_channels)); + list.append(QString::fromLatin1("-ac")); + list.append(QString::fromLatin1("%1").arg(o.audio_channels)); } // volume // 256 is normal volume if (o.audio_volume > 0 && o.audio_volume != 256) { - list.append("-vol"); - list.append(QString("%1").arg(o.audio_volume)); + list.append(QString::fromLatin1("-vol")); + list.append(QString::fromLatin1("%1").arg(o.audio_volume)); } } // Video Options if (o.disable_video || !probe.hasVideo()) { - list.append("-vn"); // no video + list.append(QString::fromLatin1("-vn")); // no video } else if (o.copy_video) { // copy video data (no re-encode) - list.append("-vcodec"); - list.append("copy"); + list.append(QString::fromLatin1("-vcodec")); + list.append(QString::fromLatin1("copy")); } else { // video enabled // same video quality as source if (o.video_same_quality) { - list.append("-sameq"); + list.append(QString::fromLatin1("-sameq")); } // deinterlace if (o.video_deinterlace) { - list.append("-deinterlace"); + list.append(QString::fromLatin1("-deinterlace")); } // begining insert subtitle or disable color or flip or rotate or stereoscopic if (o.insert_subtitle || o.disable_color || o.vertical_flip || o.horizontal_flip || o.rotate_90more || o.rotate_90less || o.rotate_180 || o.rggm || o.rbgm || o.rcc || o.rchc || o.rcd || o.gmgm || o.gmc || o.ybc) { - list.append("-vf"); + list.append(QString::fromLatin1("-vf")); } if (o.insert_subtitle && !o.disable_color) { @@ -535,7 +553,7 @@ QStringList FFmpegInterface::Private::getOptionList(const ConversionParameters & } if (!o.insert_subtitle && o.disable_color) { - list.append("hue=s=0"); + list.append(QString::fromLatin1("hue=s=0")); } if (o.insert_subtitle && o.disable_color) { @@ -545,85 +563,85 @@ QStringList FFmpegInterface::Private::getOptionList(const ConversionParameters & } else { - list.append("hue=s=0"); + list.append(QString::fromLatin1("hue=s=0")); } } if (o.vertical_flip && !o.horizontal_flip && !o.rotate_90more && !o.rotate_90less) { - list.append("vflip"); + list.append(QString::fromLatin1("vflip")); } if (!o.vertical_flip && o.horizontal_flip) { - list.append("hflip"); + list.append(QString::fromLatin1("hflip")); } if (o.vertical_flip && o.horizontal_flip && !o.rotate_90more && o.rotate_90less) { - list.append("vflip,hflip"); + list.append(QString::fromLatin1("vflip,hflip")); } if (o.rotate_90more && !o.vertical_flip) { - list.append("transpose=1"); + list.append(QString::fromLatin1("transpose=1")); } if (o.rotate_90more && o.vertical_flip) { - list.append("transpose=3"); + list.append(QString::fromLatin1("transpose=3")); } if (o.rotate_90less && !o.vertical_flip ) { - list.append("transpose=2"); + list.append(QString::fromLatin1("transpose=2")); } if (o.rotate_90less && o.vertical_flip ) { - list.append("transpose=0"); + list.append(QString::fromLatin1("transpose=0")); } if (o.rotate_180) { - list.append("transpose=2,transpose=2"); + list.append(QString::fromLatin1("transpose=2,transpose=2")); } if (o.rggm) { - list.append("stereo3d=sbs2l:argg"); + list.append(QString::fromLatin1("stereo3d=sbs2l:argg")); } if (o.rbgm) { - list.append("stereod3d=sbs2l:arbg"); + list.append(QString::fromLatin1("stereod3d=sbs2l:arbg")); } if (o.rcc) { - list.append("stereo3d=sbs2l:arcc"); + list.append(QString::fromLatin1("stereo3d=sbs2l:arcc")); } if (o.rchc) { - list.append("stereo3d=sbs2l:arch"); + list.append(QString::fromLatin1("stereo3d=sbs2l:arch")); } if (o.rcd) { - list.append("stereo3d=sbs2l:arcd"); + list.append(QString::fromLatin1("stereo3d=sbs2l:arcd")); } if (o.gmgm) { - list.append("stereo3d=sbs2l:agmg"); + list.append(QString::fromLatin1("stereo3d=sbs2l:agmg")); } if (o.gmc) { - list.append("stereo3d=sbs2l:agmc"); + list.append(QString::fromLatin1("stereo3d=sbs2l:agmc")); } if (o.ybc) { - list.append("stereo3d=sbs2l:aybc"); + list.append(QString::fromLatin1("stereo3d=sbs2l:aybc")); } // finishing insert subtitle or disable color or flip or rotate or stereoscopic // video bitrate if (o.video_bitrate > 0) { - list.append("-b"); - list.append(QString("%1k").arg(o.video_bitrate)); + list.append(QString::fromLatin1("-b")); + list.append(QString::fromLatin1("%1k").arg(o.video_bitrate)); } // video dimensions if (o.video_width > 0 && o.video_height > 0) { - list.append("-s"); - list.append(QString("%1x%2").arg(o.video_width).arg(o.video_height)); + list.append(QString::fromLatin1("-s")); + list.append(QString::fromLatin1("%1x%2").arg(o.video_width).arg(o.video_height)); } qDebug() << "CHECKING IF CROP IS ACTIVATED" << o.toCrop << o.video_crop_top; @@ -631,20 +649,21 @@ QStringList FFmpegInterface::Private::getOptionList(const ConversionParameters & // crop video if (o.toCrop) { - list.append("-filter:v"); + list.append(QString::fromLatin1("-filter:v")); - QString crop = QString("crop=%1:%2:%3:%4") - .arg(o.video_crop_right - o.video_crop_left) - .arg(o.video_crop_bottom - o.video_crop_top) - .arg(o.video_crop_left) - .arg(o.video_crop_top); + QString crop = QString::fromLatin1("crop=%1:%2:%3:%4") + .arg(o.video_crop_right - o.video_crop_left) + .arg(o.video_crop_bottom - o.video_crop_top) + .arg(o.video_crop_left) + .arg(o.video_crop_top); list.append(crop); } /* -vf "setpts=<1/rate>*PTS": video filter to change video speed <1/rate> is the reciprocal of the scaling factor (1.0 is original speed) */ if (o.speed_scaling) - list << "-vf" << QString("setpts=%1*PTS").arg(1/o.speed_scaling_factor); + list << QString::fromLatin1("-vf") + << QString::fromLatin1("setpts=%1*PTS").arg(1 / o.speed_scaling_factor); } // Time Options @@ -660,16 +679,16 @@ QStringList FFmpegInterface::Private::getOptionList(const ConversionParameters & When used as an output option, ffmpeg decodes but discards input until timestamp reaches time_begin */ if (o.time_begin > 0) { - list.append("-ss"); - list.append(QString("%1").arg(scaled_time_begin)); + list.append(QString::fromLatin1("-ss")); + list.append(QString::fromLatin1("%1").arg(scaled_time_begin)); } /* -t time_duration Stop writing the output after its duration reaches time_duration */ if (o.time_end > 0) { Q_ASSERT(o.time_end >= o.time_begin); double scaled_duration = scaled_time_end - scaled_time_begin; - list.append("-t"); - list.append(QString("%1").arg(scaled_duration)); + list.append(QString::fromLatin1("-t")); + list.append(QString::fromLatin1("%1").arg(scaled_duration)); } // destination file @@ -700,7 +719,7 @@ FFmpegInterface::~FFmpegInterface() // virtual functions QString FFmpegInterface::executableName() const { - return ExePath::getPath("ffmpeg"); + return ExePath::getPath(QString::fromLatin1("ffmpeg")); } void FFmpegInterface::reset() @@ -734,7 +753,8 @@ void FFmpegInterface::parseProcessOutput(const QString &data) //qDebug() << data; // split incoming data by [end of line] or [carriage return] - QStringList lines(data.split(QRegExp("[\r\n]"), QString::KeepEmptyParts)); + QStringList lines( + data.split(QRegularExpression(QString::fromLatin1("[\r\n]")), Qt::KeepEmptyParts)); if (!p->stringBuffer.isEmpty()) { // prepend buffered data lines.front().prepend(p->stringBuffer); diff --git a/converter/mediaconverter.cpp b/converter/mediaconverter.cpp index 252da42..b7776e0 100644 --- a/converter/mediaconverter.cpp +++ b/converter/mediaconverter.cpp @@ -79,7 +79,7 @@ bool MediaConverter::start(ConversionParameters param) qDebug() << "Audio filter is turned on."; m_pAudioFilter->start(param, &m_proc); } - qDebug() << m_pConv->executableName() << list.join(" "); + qDebug() << m_pConv->executableName() << list.join(QString::fromLatin1(" ")); m_proc.start(m_pConv->executableName(), list); return m_proc.waitForStarted(TIMEOUT); @@ -111,13 +111,13 @@ bool MediaConverter::checkExternalPrograms(QString &msg) QString errmsg = tr(" FFmpeg or FFprobe %1 have not been found in the system. Please consider installing them before running MystiQ"); // check ffmpeg if (!FFmpegInterface::hasFFmpeg()) { - msg = errmsg.arg(ExePath::getPath("ffmpeg")); + msg = errmsg.arg(ExePath::getPath(QString::fromLatin1("ffmpeg"))); return false; } // check ffprobe if (!MediaProbe::available()) { // The probe failed to start. - msg = errmsg.arg(ExePath::getPath("ffprobe")); + msg = errmsg.arg(ExePath::getPath(QString::fromLatin1("ffprobe"))); return false; } @@ -135,7 +135,7 @@ QString MediaConverter::errorMessage() const void MediaConverter::readProcessOutput() { - m_pConv->parseProcessOutput(QString(m_proc.readAll())); + m_pConv->parseProcessOutput(QString::fromLatin1(m_proc.readAll())); } void MediaConverter::convertProgressFinished(int exitcode, QProcess::ExitStatus) diff --git a/converter/mediaprobe.cpp b/converter/mediaprobe.cpp index 0285e1a..0d6f4b9 100644 --- a/converter/mediaprobe.cpp +++ b/converter/mediaprobe.cpp @@ -86,22 +86,26 @@ struct MetaInformation double start; ///< start time in seconds int bitrate; ///< bitrate in kb/s bool __dummy_padding[4]; - QRegExp pattern; + QRegularExpression pattern; - MetaInformation() : pattern(patterns::meta) { clear(); } + MetaInformation() + : pattern(QString::fromLatin1(patterns::meta)) + { + clear(); + } void clear() { duration = 0; start = 0; bitrate = 0; } bool parse(const QString& line) { - int index = pattern.indexIn(line); - if (index != -1) { - int hour = pattern.cap(patterns::META_HOUR_INDEX).toInt(); - int minute = pattern.cap(patterns::META_MINUTE_INDEX).toInt(); - double second = pattern.cap(patterns::META_SECOND_INDEX).toDouble(); + QRegularExpressionMatch match = this->pattern.match(line); + if (match.hasMatch()) { + int hour = match.captured(patterns::META_HOUR_INDEX).toInt(); + int minute = match.captured(patterns::META_MINUTE_INDEX).toInt(); + double second = match.captured(patterns::META_SECOND_INDEX).toDouble(); duration = hour * SECONDS_PER_HOUR + minute * SECONDS_PER_MINUTE + second; - start = pattern.cap(patterns::META_START_INDEX).toDouble(); - bitrate = pattern.cap(patterns::META_BITRATE_INDEX).toInt(); + start = match.captured(patterns::META_START_INDEX).toDouble(); + bitrate = match.captured(patterns::META_BITRATE_INDEX).toInt(); return true; } return false; @@ -117,11 +121,15 @@ struct AudioInformation int bitrate; ///< bitrate in kb/s int channels; ///< number of channels QString codec; - QRegExp pattern; - QRegExp pattern_check; + QRegularExpression pattern; + QRegularExpression pattern_check; - AudioInformation() : pattern(patterns::audio) - , pattern_check(patterns::audio_check) { clear(); } + AudioInformation() + : pattern(QString::fromLatin1(patterns::audio)) + , pattern_check(QString::fromLatin1(patterns::audio_check)) + { + clear(); + } void clear() { @@ -134,30 +142,32 @@ struct AudioInformation bool parse(const QString& line) { - int index = pattern.indexIn(line); - if (index != -1) { + QRegularExpressionMatch match = this->pattern.match(line); + if (match.hasMatch()) { has_audio = true; - codec = pattern.cap(patterns::AUDIO_CODEC_INDEX); - sample_rate = pattern.cap(patterns::AUDIO_SAMPLERATE_INDEX).toInt(); - bitrate = pattern.cap(patterns::AUDIO_BITRATE_INDEX).toInt(); + codec = match.captured(patterns::AUDIO_CODEC_INDEX); + sample_rate = match.captured(patterns::AUDIO_SAMPLERATE_INDEX).toInt(); + bitrate = match.captured(patterns::AUDIO_BITRATE_INDEX).toInt(); // extract number of channels - QString channels_field = pattern.cap(patterns::AUDIO_CHANNELS_INDEX); - QRegExp channels_pattern("([0-9]+)\\s+channel"); - if (channels_pattern.indexIn(channels_field) != -1) { - channels = channels_pattern.cap(1).toInt(); - } else if (channels_field.indexOf("stereo") != -1) { + QString channels_field = match.captured(patterns::AUDIO_CHANNELS_INDEX); + QRegularExpression channels_pattern(QString::fromLatin1("([0-9]+)\\s+channel")); + QRegularExpressionMatch match_channel = channels_pattern.match(channels_field); + if (match_channel.hasMatch()) { + channels = match_channel.captured(1).toInt(); + } else if (channels_field.indexOf(QString::fromLatin1("stereo")) != -1) { channels = 2; - } else if (channels_field.indexOf("mono") != -1) { + } else if (channels_field.indexOf(QString::fromLatin1("mono")) != -1) { channels = 1; } return true; } // audio existence must be correct - if (pattern_check.indexIn(line) != -1) { + QRegularExpressionMatch match_pattern_check = this->pattern_check.match(line); + if (match_pattern_check.hasMatch()) { has_audio = true; - codec = "unknown"; + codec = QString::fromLatin1("unknown"); } return false; } @@ -176,11 +186,15 @@ struct VideoInformation double frame_rate; ///< frame rate in fps QString codec; QString format; - QRegExp pattern; - QRegExp pattern_check; + QRegularExpression pattern; + QRegularExpression pattern_check; - VideoInformation() : pattern(patterns::video) - , pattern_check(patterns::video_check) { clear(); } + VideoInformation() + : pattern(QString::fromLatin1(patterns::video)) + , pattern_check(QString::fromLatin1(patterns::video_check)) + { + clear(); + } void clear() { @@ -195,21 +209,22 @@ struct VideoInformation bool parse(const QString& line) { - int index = pattern.indexIn(line); - if (index != -1) { + QRegularExpressionMatch match = this->pattern.match(line); + if (match.hasMatch()) { has_video = true; - stream_index = pattern.cap(patterns::VIDEO_STREAM_INDEX).toInt(); - width = pattern.cap(patterns::VIDEO_WIDTH_INDEX).toInt(); - height = pattern.cap(patterns::VIDEO_HEIGHT_INDEX).toInt(); - bitrate = pattern.cap(patterns::VIDEO_BITRATE_INDEX).toInt(); - frame_rate = pattern.cap(patterns::VIDEO_FRAMERATE_INDEX).toDouble(); - codec = pattern.cap(patterns::VIDEO_CODEC_INDEX); + stream_index = match.captured(patterns::VIDEO_STREAM_INDEX).toInt(); + width = match.captured(patterns::VIDEO_WIDTH_INDEX).toInt(); + height = match.captured(patterns::VIDEO_HEIGHT_INDEX).toInt(); + bitrate = match.captured(patterns::VIDEO_BITRATE_INDEX).toInt(); + frame_rate = match.captured(patterns::VIDEO_FRAMERATE_INDEX).toDouble(); + codec = match.captured(patterns::VIDEO_CODEC_INDEX); return true; } // video existence must be correct - if (pattern_check.indexIn(line) != -1) { + match = this->pattern_check.match(line); + if (match.hasMatch()) { has_video = true; - codec = "unknown"; + codec = QString::fromLatin1("unknown"); } return false; } @@ -220,16 +235,18 @@ struct SubtitleInformation { bool has_subtitle; bool __dummy_padding[7]; - QRegExp pattern; + QRegularExpression pattern; - SubtitleInformation() : pattern(patterns::subtitle) { } + SubtitleInformation() + : pattern(QString::fromLatin1(patterns::subtitle)) + {} void clear() { has_subtitle = false; } bool parse(const QString& line) { - int index = pattern.indexIn(line); - if (index != -1) { - has_subtitle = true; + QRegularExpressionMatch match = this->pattern.match(line); + if (match.hasMatch()) { + this->has_subtitle = true; } return false; // reject all inputs } @@ -313,7 +330,7 @@ bool MediaProbe::start(const QString& filename) list.push_back(filename); p->ffprobe_proc.setReadChannel(QProcess::StandardError); - p->ffprobe_proc.start(ExePath::getPath("ffprobe"), list); + p->ffprobe_proc.start(ExePath::getPath(QString::fromLatin1("ffprobe")), list); return p->ffprobe_proc.waitForStarted(TIMEOUT); } return false; @@ -321,7 +338,7 @@ bool MediaProbe::start(const QString& filename) bool MediaProbe::start(const char *filename) { - return start(QString(filename)); + return start(QString::fromLatin1(filename)); } bool MediaProbe::run(const QString &filename, int timeout) @@ -459,7 +476,7 @@ void MediaProbe::m_proc_finished(int exitcode) if (exitcode == 0) { // If the process finished normally, parse its output. p->clear(); while (p->ffprobe_proc.canReadLine()) { - QString line = QString(p->ffprobe_proc.readLine()).trimmed(); + QString line = QString::fromLatin1(p->ffprobe_proc.readLine()).trimmed(); p->parse_line(line); } } diff --git a/converter/presets.cpp b/converter/presets.cpp index 920426c..a02709e 100644 --- a/converter/presets.cpp +++ b/converter/presets.cpp @@ -22,6 +22,7 @@ #include #include #include +#include struct Presets::Private { @@ -65,7 +66,7 @@ bool Presets::Private::parseXmlFile(QFile &file, bool removeUnavailableCodecs) if (level == 0) { top_level_tag = xml.name().toString(); ++level; - } else if (level == 1 && top_level_tag == "presets") { + } else if (level == 1 && top_level_tag == QString::fromLatin1("presets")) { if (!parsePreset(xml)) return false; } @@ -118,7 +119,7 @@ bool Presets::Private::readElementData(QXmlStreamReader &xml, Preset& target) return false; QString property_name = xml.name().toString(); QString versionrange_str; - if (property_name == "params") + if (property_name == QString::fromLatin1("params")) versionrange_str = getVersionAttribute(xml.attributes()); xml.readNext(); @@ -128,17 +129,17 @@ bool Presets::Private::readElementData(QXmlStreamReader &xml, Preset& target) QString property_value = xml.text().toString().trimmed(); - if (property_name == "label") { + if (property_name == QString::fromLatin1("label")) { target.label = property_value; - } else if (property_name == "params") { + } else if (property_name == QString::fromLatin1("params")) { Version ffmpegVersion(FFmpegInterface::getFFmpegVersionInfo()); if (versionrange_str.isEmpty() || VersionRange(versionrange_str).containsVersion(ffmpegVersion)) { target.parameters = property_value; } - } else if (property_name == "extension") { + } else if (property_name == QString::fromLatin1("extension")) { target.extension = property_value; - } else if (property_name == "category") { + } else if (property_name == QString::fromLatin1("category")) { target.category = property_value; } @@ -156,9 +157,9 @@ void Presets::Private::removeUnavailablePresets() if (!FFmpegInterface::getSubtitleEncoders(subtitle_encoders)) Q_ASSERT(subtitle_encoders.isEmpty()); - QRegExp audio_codec_pattern("-acodec\\s+([^ ]+)"); - QRegExp video_codec_pattern("-vcodec\\s+([^ ]+)"); - QRegExp subtitle_codec_pattern("-scodec\\s+([^ ]+)"); + QRegularExpression audio_codec_pattern(QString::fromLatin1("-acodec\\s+([^ ]+)")); + QRegularExpression video_codec_pattern(QString::fromLatin1("-vcodec\\s+([^ ]+)")); + QRegularExpression subtitle_codec_pattern(QString::fromLatin1("-scodec\\s+([^ ]+)")); QMultiMap::iterator it = presets.begin(); while (it!=presets.end()) { @@ -166,22 +167,25 @@ void Presets::Private::removeUnavailablePresets() QString& params = it.value().parameters; // Check unavailable audio presets - if (audio_codec_pattern.indexIn(params) != -1) { - if (!audio_encoders.contains(audio_codec_pattern.cap(1))) { + QRegularExpressionMatch match_audio_codec = audio_codec_pattern.match(params); + if (match_audio_codec.hasMatch()) { + if (!audio_encoders.contains(match_audio_codec.captured(1))) { remove = true; } } // Check unavailable video presets - if (!remove && video_codec_pattern.indexIn(params) != -1) { - if (!video_encoders.contains(video_codec_pattern.cap(1))) { + QRegularExpressionMatch match_video_codec = video_codec_pattern.match(params); + if (!remove && match_video_codec.hasMatch()) { + if (!video_encoders.contains(match_video_codec.captured(1))) { remove = true; } } // Check unavailable subtitle presets - if (!remove && subtitle_codec_pattern.indexIn(params) != -1) { - if (!subtitle_encoders.contains(subtitle_codec_pattern.cap(1))) { + QRegularExpressionMatch match_subtitle_codec = subtitle_codec_pattern.match(params); + if (!remove && match_subtitle_codec.hasMatch()) { + if (!subtitle_encoders.contains(match_subtitle_codec.captured(1))) { remove = true; } } @@ -196,8 +200,8 @@ void Presets::Private::removeUnavailablePresets() QString Presets::Private::getVersionAttribute(const QXmlStreamAttributes &attrs) { QString version; - foreach (QXmlStreamAttribute attr, attrs) { - if (attr.name() == "version") { + for(const QXmlStreamAttribute &attr : qAsConst(attrs)){ + if (attr.name().toString() == QString::fromLatin1("version")) { version = attr.value().toString(); break; } @@ -234,7 +238,7 @@ bool Presets::readFromFile(const QString &filename, bool removeUnavailableCodecs bool Presets::readFromFile(const char *filename, bool removeUnavailableCodecs) { - return readFromFile(QString(filename), removeUnavailableCodecs); + return readFromFile(QString::fromLatin1(filename), removeUnavailableCodecs); } bool Presets::getExtensions(QList &target) const @@ -243,7 +247,7 @@ bool Presets::getExtensions(QList &target) const std::sort(presetList.begin(), presetList.end()); // sort presets by id target.clear(); - QString extension(""); + QString extension(QString::fromLatin1("")); foreach (Preset preset, presetList) { if (extension != preset.extension) { // new extension appears extension = preset.extension; @@ -290,5 +294,5 @@ bool Presets::getPresets(const QString &extension, QList &target) bool Presets::getPresets(const char *extension, QList &target) { - return getPresets(QString(extension), target); + return getPresets(QString::fromLatin1(extension), target); } diff --git a/main.cpp b/main.cpp index a140db0..6300947 100644 --- a/main.cpp +++ b/main.cpp @@ -41,8 +41,8 @@ static QString find_translation_file() QString locale = QLocale::system().name(); // language code + country code (xx_XX) QString language = locale.mid(0, 2); // language code (first two chars of locale) QString translation_file_basename = - //QDir(Paths::translationPath()).absoluteFilePath("mystiq_"); - QDir(":/translations/").absoluteFilePath("mystiq_"); + //QDir(Paths::translationPath()).absoluteFilePath("mystiq_"); + QDir(QString::fromLatin1(":/translations/")).absoluteFilePath(QString::fromLatin1("mystiq_")); // look for mystiq_xx_XX.qm in the translation directory QString translation_language_country = translation_file_basename + locale + ".qm"; @@ -55,7 +55,7 @@ static QString find_translation_file() return translation_language; // translation for current locale not found, return empty string - return ""; + return QString::fromLatin1(""); } /** @@ -70,26 +70,29 @@ static bool load_constants(QApplication& app) #else QString app_path = app.applicationDirPath(); #endif - QString constant_xml_filename = ":/other/constants.xml"; + QString constant_xml_filename = QString::fromLatin1(":/other/constants.xml"); // open constant xml file QFile constant_xml(constant_xml_filename); constant_xml.open(QIODevice::ReadOnly); if (!constant_xml.isOpen()) { qCritical() << "Failed to read file: " << constant_xml_filename; - QMessageBox::critical(nullptr, "MystiQ", - QString("Cannot load %1. The program will exit now.") - .arg(constant_xml_filename)); + QMessageBox::critical(nullptr, + QString::fromLatin1("MystiQ"), + QString::fromLatin1("Cannot load %1. The program will exit now.") + .arg(constant_xml_filename)); return false; } qDebug() << "Reading file: " << constant_xml_filename; // parse the xml file if (!Constants::readFile(constant_xml)) { - QMessageBox::critical(nullptr, "MystiQ", - QString("%1 contains error(s). " - "Reinstall the application may solve the problem.") - .arg(constant_xml_filename)); + QMessageBox::critical(nullptr, + QString::fromLatin1("MystiQ"), + QString::fromLatin1( + "%1 contains error(s). " + "Reinstall the application may solve the problem.") + .arg(constant_xml_filename)); return false; } @@ -100,7 +103,7 @@ static bool load_constants(QApplication& app) // returns whether the tool can be successfully invoked static bool register_tool(const char *id, const char *name) { - QString exefile = name; // default: use the program in PATH + QString exefile = QString::fromLatin1(name); // default: use the program in PATH #ifdef TOOLS_IN_DATA_PATH // Search external tools in /tools #ifdef Q_OS_WIN32 // executable files must end with .exe on MS Windows exefile = Paths::dataFileName("tools/%1.exe").arg(name); @@ -111,11 +114,11 @@ static bool register_tool(const char *id, const char *name) exefile = Paths::dataFileName("tools/%1").arg(name); #endif // Q_OS_MACOS #endif // TOOLS_IN_DATA_PATH - ExePath::setPath(id, exefile); - if (ExePath::checkProgramAvailability(id)) + ExePath::setPath(QString::fromLatin1(id), exefile); + if (ExePath::checkProgramAvailability(QString::fromLatin1(id))) return true; // failed to invoke the program - ExePath::setPath(id, ""); // unset the tool + ExePath::setPath(QString::fromLatin1(id), QString::fromLatin1("")); // unset the tool return false; } @@ -130,13 +133,11 @@ static void register_external_tools() ExePath::loadSettings(); // If the setting of ffmpeg is not available, register it again. // If "ffmpeg" doesn't exist on the system, try "avconv" instead. - ExePath::checkProgramAvailability("ffmpeg") - || register_tool("ffmpeg") - || register_tool("ffmpeg", "avconv"); + ExePath::checkProgramAvailability(QString::fromLatin1("ffmpeg")) || register_tool("ffmpeg") + || register_tool("ffmpeg", "avconv"); // same as "ffmpeg" (try "avprobe" if "ffprobe" not available) - ExePath::checkProgramAvailability("ffprobe") - || register_tool("ffprobe") - || register_tool("ffprobe", "avprobe"); + ExePath::checkProgramAvailability(QString::fromLatin1("ffprobe")) || register_tool("ffprobe") + || register_tool("ffprobe", "avprobe"); // same as above // these tools have no alternative names register_tool("sox"); @@ -153,7 +154,7 @@ int main(int argc, char *argv[]) } // Register QSettings information. - app.setOrganizationName("mystiq"); + app.setOrganizationName(QString::fromLatin1("mystiq")); QSettings::setDefaultFormat(QSettings::IniFormat); if (Constants::getBool("Portable")) { // Portable App: Save settings in /mystiq.ini. diff --git a/mystiq.pro b/mystiq.pro index 5b0f76e..0e4439d 100644 --- a/mystiq.pro +++ b/mystiq.pro @@ -5,6 +5,7 @@ #------------------------------------------------- QT += core gui network opengl multimedia qml widgets quick quickwidgets multimediawidgets +DEFINES += QT_DISABLE_DEPRECATED_UP_TO=0x050F00 #DEFINES += QT_DEPRECATED_WARNINGS QMAKE_CFLAGS_RELEASE += -flto diff --git a/services/constants.cpp b/services/constants.cpp index 9bd7320..906019c 100644 --- a/services/constants.cpp +++ b/services/constants.cpp @@ -20,13 +20,13 @@ #include "constants.h" #include "xmllookuptable.h" -#define REGEXP_HEXDIGIT "[0-9a-fA-F]" +#define REGEXP_HEXDIGIT QString::fromLatin1("[0-9a-fA-F]" namespace { bool constants_initialized = false; XmlLookupTable constants; - QString color_pattern(QString("#(%1%1)(%1%1)(%1%1)(%1%1)?").arg(REGEXP_HEXDIGIT)); + QString color_pattern(QString::fromLatin1("#(%1%1)(%1%1)(%1%1)(%1%1)?").arg(REGEXP_HEXDIGIT))); QString lookup_constant(const QString& key) { @@ -39,7 +39,7 @@ namespace int hex2int(const QString& hex_str) { - QString qualified_str = QString("0x%1").arg(hex_str); + QString qualified_str = QString::fromLatin1("0x%1").arg(hex_str); bool ok; int value = qualified_str.toInt(&ok, 16); if (ok) @@ -50,18 +50,18 @@ namespace QColor str2color(const QString& color_str) { - QRegExp color(color_pattern); - if (color.indexIn(color_str) >= 0) { - int r_value = hex2int(color.cap(1)); - int g_value = hex2int(color.cap(2)); - int b_value = hex2int(color.cap(3)); - int a_value = 0xff; - if (!color.cap(4).isEmpty()) // with alpha value - a_value = hex2int(color.cap(4)); - return QColor(r_value, g_value, b_value, a_value); - } else { - return QColor(0, 0, 0); // default black + QColor c = QColor(0, 0, 0); // default black + QRegularExpression color(color_pattern); + QRegularExpressionMatch match = color.match(color_str); + if (match.hasMatch()) { + c.setRed(hex2int(match.captured(1))); + c.setGreen(hex2int(match.captured(2))); + c.setBlue(hex2int(match.captured(3))); + if(match.hasCaptured(4)) { // has alpha value + c.setAlpha(hex2int(match.captured(4))); + } } + return c; } } @@ -71,7 +71,7 @@ bool Constants::readFile(QFile &file) constants_initialized = false; if (constants.readFile(file)) { constants_initialized = true; - constants.setPrefix("MystiQConstants"); + constants.setPrefix(QString::fromLatin1("MystiQConstants")); } return constants_initialized; } @@ -79,8 +79,9 @@ bool Constants::readFile(QFile &file) bool Constants::getBool(const char *key) { Q_ASSERT(constants_initialized); - QString value = lookup_constant(key).trimmed().toLower(); - if (value.isEmpty() || value == "0" || value == "false") + QString value = lookup_constant(QString::fromLatin1(key)).trimmed().toLower(); + if (value.isEmpty() || value == QString::fromLatin1("0") + || value == QString::fromLatin1("false")) return false; else return true; @@ -89,30 +90,32 @@ bool Constants::getBool(const char *key) int Constants::getInteger(const char *key) { Q_ASSERT(constants_initialized); - return lookup_constant(key).toInt(); + return lookup_constant(QString::fromLatin1(key)).toInt(); } float Constants::getFloat(const char *key) { Q_ASSERT(constants_initialized); - return lookup_constant(key).toFloat(); + return lookup_constant(QString::fromLatin1(key)).toFloat(); } QString Constants::getString(const char *key) { Q_ASSERT(constants_initialized); - return lookup_constant(key).trimmed(); + return lookup_constant(QString::fromLatin1(key)).trimmed(); } QStringList Constants::getSpaceSeparatedList(const char *key) { Q_ASSERT(constants_initialized); - QString collapsed_string = lookup_constant(key).replace(QRegExp("[\n\t ]"), " "); - return collapsed_string.split(" ", QString::SkipEmptyParts); + QString collapsed_string = lookup_constant(QString::fromLatin1(key)) + .replace(QRegularExpression(QString::fromLatin1("[\n\t ]")), + QString::fromLatin1(" ")); + return collapsed_string.split(QString::fromLatin1(" "), Qt::SkipEmptyParts); } QColor Constants::getColor(const char *key) { Q_ASSERT(constants_initialized); - return str2color(lookup_constant(key)); + return str2color(lookup_constant(QString::fromLatin1(key))); } diff --git a/services/filepathoperations.cpp b/services/filepathoperations.cpp index 7c511c9..a64d9d1 100644 --- a/services/filepathoperations.cpp +++ b/services/filepathoperations.cpp @@ -30,10 +30,10 @@ QString FilePathOperations::GenerateUniqueFileName(const QDir& output_dir, const QString result; do { // The index part of the file - QString str_index(""); + QString str_index(QString::fromLatin1("")); if (filename_index > 1) { // If the index is larger than 1, append -index to the filename. - str_index = QString("-%1").arg(filename_index); + str_index = QString::fromLatin1("-%1").arg(filename_index); } // Fill in output filename. @@ -62,9 +62,11 @@ QString FilePathOperations::GenerateTempFileName(const QString& filename) QString result; do { // Generate temporary file name. - result = QString("%1-%2-temp-%3.%4").arg(filename) - .arg(QRandomGenerator::global()->generate()).arg(QCoreApplication::applicationPid()) - .arg(QFileInfo(filename).suffix()); + result = QString::fromLatin1("%1-%2-temp-%3.%4") + .arg(filename) + .arg(QRandomGenerator::global()->generate()) + .arg(QCoreApplication::applicationPid()) + .arg(QFileInfo(filename).suffix()); } while (QFileInfo(result).exists()); // Regenerate if exists. return result; diff --git a/services/versioncompare.cpp b/services/versioncompare.cpp index f6cef63..47e6b7e 100644 --- a/services/versioncompare.cpp +++ b/services/versioncompare.cpp @@ -39,9 +39,10 @@ Version::Version(const QString &s) { m_major = m_minor = m_patch = -1; // invalid value for (int i=0; version_patterns[i]; i++) { // try each pattern - QRegExp pattern(version_patterns[i]); - if (pattern.indexIn(s) != -1) { - const QStringList cap = pattern.capturedTexts(); + QRegularExpression pattern(version_patterns[i]); + QRegularExpressionMatch match = pattern.match(s); + if (match.hasMatch()) { + const QStringList cap = match.capturedTexts(); const int capture_count = cap.size() - 1; m_major = m_minor = m_patch = 0; if (capture_count >= 1) @@ -108,7 +109,7 @@ bool Version::operator >=(const Version& other) const VersionRange::VersionRange(const QString &s) { if (!s.isEmpty()) { - QStringList lst = s.split(",", QString::SkipEmptyParts); + QStringList lst = s.split(",", Qt::SkipEmptyParts); foreach (QString range, lst) { m_range.push_back(range.trimmed()); } diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index 29cc4db..92a1e18 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -26,7 +26,6 @@ #include "aboutdialog.h" #include "poweroffdialog.h" #include "updatedialog.h" -#include "services/paths.h" #include "services/notification.h" #include "services/powermanagement.h" #include "converter/mediaconverter.h" @@ -48,6 +47,9 @@ #include #include #include +#include +#include +#include MainWindow::MainWindow(QWidget *parent, const QStringList& fileList) : QMainWindow(parent), @@ -289,7 +291,7 @@ void MainWindow::slotReport() stringList << "info@mystiqapp.com"; stringList << "?"; stringList << "subject="; - stringList << QString( tr("Reporting bugs from MystiQ ")+ tr("%1").arg(VERSION_STRING) ); + stringList << tr("Reporting bugs from MystiQ ")+ tr("%1").arg(VERSION_STRING); stringList << "&"; stringList << "body="; stringList << tr("Your comment:"); @@ -765,9 +767,9 @@ void MainWindow::setup_appicon() QIcon icon; QDir iconDir = QDir(":/app/icons/"); QStringList fileList = iconDir.entryList(); - QRegExp pattern("^mystiq_[0-9]+x[0-9]+\\.png$"); + QRegularExpression pattern("^mystiq_[0-9]+x[0-9]+\\.png$"); foreach (QString file, fileList) { - if (pattern.indexIn(file) >= 0) { + if (file.indexOf(pattern) >= 0) { icon.addPixmap(QPixmap(iconDir.absoluteFilePath(file))); } } diff --git a/ui/mainwindow.cpp.autosave b/ui/mainwindow.cpp.autosave deleted file mode 100644 index bde1e62..0000000 --- a/ui/mainwindow.cpp.autosave +++ /dev/null @@ -1,971 +0,0 @@ -/* MystiQ - a C++/Qt5 gui frontend for ffmpeg - * Copyright (C) 2011-2019 Maikel Llamaret Heredia - * - * 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 of the License, 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 . - */ - -#include "mainwindow.h" -#include "version.h" -#include "ui_mainwindow.h" -#include "convertlist.h" -#include "addtaskwizard.h" -#include "aboutffmpegdialog.h" -#include "helpmystiqdialog.h" -#include "optionsdialog.h" -#include "aboutdialog.h" -#include "poweroffdialog.h" -#include "updatedialog.h" -#include "services/paths.h" -#include "services/notification.h" -#include "services/powermanagement.h" -#include "converter/mediaconverter.h" -#include "converter/presets.h" -#include "services/updatechecker.h" -#include "services/constants.h" -#include "services/settingtimer.h" -#include "interactivecuttingdialog.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -MainWindow::MainWindow(QWidget *parent, const QStringList& fileList) : - QMainWindow(parent), - ui(new Ui::MainWindow), - m_presets(new Presets(this)), - m_list(new ConvertList(m_presets, this)), - m_argv_input_files(fileList), - m_elapsedTimeLabel(new QLabel(this)), - m_timer(new QTimer(this)), - m_poweroff_button(nullptr), - m_poweroff_actiongroup(nullptr), - m_update_checker(new UpdateChecker(this)) -{ - ui->setupUi(this); - - connect(m_list, SIGNAL(task_finished(int)), - this, SLOT(task_finished(int))); - connect(m_list, SIGNAL(all_tasks_finished()), - this, SLOT(all_tasks_finished())); - connect(m_list, SIGNAL(customContextMenuRequested(QPoint)), - this, SLOT(slotListContextMenu(QPoint))); - connect(m_list, SIGNAL(itemSelectionChanged()), - this, SLOT(refresh_action_states())); - connect(m_timer, SIGNAL(timeout()), - this, SLOT(timerEvent())); - connect(m_list, SIGNAL(started()), - this, SLOT(conversion_started())); - connect(m_list, SIGNAL(stopped()), - this, SLOT(conversion_stopped())); - connect(m_update_checker, SIGNAL(receivedResult(int)), - this, SLOT(received_update_result(int))); - - setup_widgets(); - setup_menus(); - setup_poweroff_button(); - setup_toolbar(Constants::getSpaceSeparatedList("ToolbarEntries")); - setup_statusbar(); - setup_appicon(); - - load_settings(); - - refresh_action_states(); - - if (!check_execute_conditions()) { - // Close the window immediately after it has started. - QTimer::singleShot(0, this, SLOT(close())); - } else { - QTimer::singleShot(0, this, SLOT(window_ready())); - } - -} - -MainWindow::~MainWindow() -{ - delete ui; -} - -void MainWindow::window_ready() -{ - if (!m_argv_input_files.isEmpty()) { - add_files(m_argv_input_files); - } - QSettings settings; - if (settings.value("options/check_update_on_startup", - Constants::getBool("CheckUpdateOnStartup")).toBool()) { - if (ask_for_update_permission()) - m_update_checker->checkUpdate(); - } - refresh_status(); -} - -void MainWindow::task_finished(int exitcode) -{ - if (exitcode == 0) { // succeed - #if defined(Q_OS_LINUX) || defined(Q_OS_MACOS) - Notification::send(this, "MystiQ" - , tr("Conversion finished successfully.") - , NotifyLevel::INFO); - #endif - } else { // failed - QMessageBox::critical(this, this->windowTitle() - , tr("Conversion failed.") - , QMessageBox::Ok); - } -} - -void MainWindow::all_tasks_finished() -{ - Notification::send(this, "MystiQ", - tr("All tasks have finished."), NotifyLevel::INFO); - activateWindow(); // notify the user (make taskbar entry blink) - refresh_action_states(); - - if (PowerManagement::implemented() && m_poweroff_button->isChecked()) { - // show poweroff dialog - if (PoweroffDialog(this).exec(get_poweroff_behavior()) == QDialog::Accepted) { - save_settings(); // save settings in case of power failure - } - } -} - -// Menu Events - -void MainWindow::slotAddFiles() -{ - add_files(); -} - -void MainWindow::slotOptions() -{ - OptionsDialog dialog(this); - dialog.exec(); -} - -void MainWindow::slotSetTools() -{ - OptionsDialog dialog(this); - dialog.exec_tools(); -} - -void MainWindow::slotExit() -{ - this->close(); -} - -void MainWindow::slotStartConversion() -{ - if (m_list->isEmpty()) { - QMessageBox::information(this, this->windowTitle(), - tr("Nothing to convert."), QMessageBox::Ok); - } else { - m_list->start(); - } -} - -void MainWindow::slotStopConversion() -{ - m_list->stop(); -} - -void MainWindow::slotSetConversionParameters() -{ - if (m_list->selectedCount() > 0) { - m_list->editSelectedParameters(); - } -} - -// Open the output folder of the file. -void MainWindow::slotOpenOutputFolder() -{ - const ConversionParameters *param = m_list->getCurrentIndexParameter(); - if (param) { - QString folder_path = QFileInfo(param->destination).path(); - if (QFileInfo(folder_path).exists()) { - QDesktopServices::openUrl(QUrl::fromLocalFile(folder_path)); - } - } -} - -void MainWindow::slotAboutQt() -{ - QMessageBox::aboutQt(this); -} - -void MainWindow::slotAboutFFmpeg() -{ - AboutFFmpegDialog(this).exec(); -} - -void MainWindow::slotAbout() -{ - AboutDialog(this).exec(); -} - -void MainWindow::slotHelpMystiQDialog() -{ - HelpMystiQDialog(this).exec(); -} - -void MainWindow::slotDonate() -{ - QMessageBox d(this); - d.setWindowTitle(tr("Support MystiQ")); - QPushButton * liberapay_button = d.addButton("Liberapay", QMessageBox::YesRole); - QPushButton * opencollective_button = d.addButton("Open Collective", QMessageBox::YesRole); - QPushButton * patreon_button = d.addButton("Patreon", QMessageBox::YesRole); - d.addButton(tr("Close"), QMessageBox::NoRole); - d.setDefaultButton(liberapay_button); - d.setText("

" + tr("MystiQ needs you") + "

" + - tr("MystiQ is free software. However the development requires a lot of time and a lot of work. In order to keep developing MystiQ with new features we need your help. Please consider to support the MystiQ project by sending a donation. Even the smallest amount will help a lot.") - ); - d.exec(); - if (d.clickedButton() == liberapay_button) { - QDesktopServices::openUrl(QUrl("https://liberapay.com/MystiQ/donate")); - } - if (d.clickedButton() == opencollective_button) { - QDesktopServices::openUrl(QUrl("https://opencollective.com/mystiq/donate")); - } - if (d.clickedButton() == patreon_button) { - QDesktopServices::openUrl(QUrl("https://patreon.com/mystiq")); - } -} - -void MainWindow::slotTranslate() -{ - QString translateWeb="https://www.transifex.com/swl-x-project/mystiq-video-converter/"; - bool b = QDesktopServices::openUrl( QUrl( translateWeb, QUrl::TolerantMode ) ); - Q_UNUSED(b) -} - -void MainWindow::slotOpenSettingFolder() -{ - QDesktopServices::openUrl(QUrl(Paths::appPath())); -} - -void MainWindow::slotReport() -{ - QMessageBox d(this); - d.setWindowTitle(tr("Report Bugs")); - QPushButton * email_button = d.addButton(tr("Email"), QMessageBox::YesRole); - QPushButton * github_button = d.addButton(tr("Github"), QMessageBox::YesRole); - QPushButton * gitter_button = d.addButton(tr("Gitter"), QMessageBox::YesRole); - d.addButton(tr("Close"), QMessageBox::NoRole); - d.setDefaultButton(email_button); - d.setText("

" + tr("We need your feedback") + "

" + - tr("MystiQ Video Converter development team needs users who use the application to help detect errors. If you find an error and report it to our team, it will help speed up the correction process. Therefore, you can be part of our development team even if you are not a developer. To report an error, you can send us an email with the detailed description of it or you can enter Github and describe the issue (in this case you must have a GitHub Account).") - ); - d.exec(); - if (d.clickedButton() == email_button) { - #ifdef Q_OS_WIN - QString eol = "\r\n"; - #endif - #if defined(Q_OS_LINUX) || defined(Q_OS_MACOS) - QString eol = "\n"; - #endif - QStringList stringList; - stringList << "mailto:"; - stringList << "info@mystiqapp.com"; - stringList << "?"; - stringList << "subject="; - stringList << QString( tr("Reporting bugs from MystiQ ")+ tr("%1").arg(VERSION_STRING) ); - stringList << "&"; - stringList << "body="; - stringList << tr("Your comment:"); - stringList << eol; - stringList << eol; - stringList << eol; - stringList << eol; - stringList << "--------------------------------"; - stringList << eol; - stringList << tr("Report:"); - stringList << eol; - stringList << eol; - stringList << eol; - stringList << eol; - stringList << "--------------------------------"; - - QString string = stringList.join( "" ); - bool b = QDesktopServices::openUrl( QUrl( string, QUrl::TolerantMode ) ); - Q_UNUSED(b) - } - if (d.clickedButton() == github_button) { - QString github_issue="https://github.com/swl-x/MystiQ/issues/new/choose"; - bool b = QDesktopServices::openUrl( QUrl( github_issue, QUrl::TolerantMode ) ); - Q_UNUSED(b) - } - if (d.clickedButton() == gitter_button) { - QString gitter_room="https://gitter.im/swl-x-MystiQ/community"; - bool b = QDesktopServices::openUrl( QUrl( gitter_room, QUrl::TolerantMode ) ); - Q_UNUSED(b) - } -} - -void MainWindow::slotShowUpdateDialog() -{ - if (ask_for_update_permission()) { - UpdateChecker update_checker; - UpdateDialog(this).exec(update_checker); - } -} - -void MainWindow::slotCut() -{ - m_list->cutSelectedTask(); -} - -void MainWindow::slotListContextMenu(QPoint /*pos*/) -{ - refresh_action_states(); - - QMenu menu; - menu.addAction(ui->actionOpenOutputFolder); - menu.addSeparator(); - menu.addAction(ui->actionRemoveSelectedItems); - menu.addSeparator(); - menu.addAction(ui->actionRetry); - menu.addAction(ui->actionRetryAll); - menu.addSeparator(); - menu.addAction(ui->actionShowErrorMessage); - menu.addAction(ui->actionChangeOutputFilename); - menu.addAction(ui->actionChangeOutputDirectory); - menu.addAction(ui->actionSetParameters); - menu.addAction(ui->actionCut); - - menu.exec(QCursor::pos()); -} - -// Events - -void MainWindow::closeEvent(QCloseEvent *event) -{ - if (m_list->isBusy()) { - int reply = QMessageBox::warning(this, this->windowTitle(), - tr("Conversion is still in progress. Abort?"), - QMessageBox::Yes | QMessageBox::No, QMessageBox::No); - if (reply == QMessageBox::No) { - event->ignore(); - return; - } - } - - m_list->stop(); - - save_settings(); -} - -void MainWindow::timerEvent() -{ - refresh_status(); -} - -void MainWindow::conversion_started() -{ - m_elapsedTimeLabel->clear(); - m_timer->start(1000); - refresh_status(); - refresh_action_states(); -} - -void MainWindow::conversion_stopped() -{ - m_timer->stop(); - refresh_status(); - refresh_action_states(); -} - -void MainWindow::update_poweroff_button(int id) -{ - const char *icon_id = ""; - QString title = "Shutdown Options"; - QString status_tip = "Shutdown Options"; - switch (id) { - case PowerManagement::SHUTDOWN: - icon_id = ":/actions/icons/system_shutdown.svg"; - title = tr("Shutdown"); - status_tip = tr("Shutdown when all tasks are done."); - break; - case PowerManagement::SUSPEND: - icon_id = ":/actions/icons/system_suspend.svg"; - title = tr("Suspend"); - status_tip = tr("Suspend when all tasks are done."); - break; - case PowerManagement::HIBERNATE: - icon_id = ":/actions/icons/system_hibernate.svg"; - title = tr("Hibernate"); - status_tip = tr("Hibernate when all tasks are done."); - break; - default: - Q_ASSERT_X(false, __FUNCTION__, "Incorrect id! Be sure to handle every power action in switch()."); - } - m_poweroff_button->setIcon(QIcon(icon_id)); - m_poweroff_button->setToolTip(status_tip); - m_poweroff_button->setStatusTip(status_tip); - ui->actionPoweroff->setIcon(QIcon(icon_id)); - ui->actionPoweroff->setText(title); - ui->actionPoweroff->setStatusTip(status_tip); - m_poweroff_button->setIcon(QIcon(icon_id)); - ui->actionPoweroff->setIcon(QIcon(icon_id)); - - -} - -void MainWindow::received_update_result(int status) -{ - if (status == UpdateChecker::UpdateFound) { - QSettings settings; - SettingTimer timer("mainwindow/last_remind_update_time"); - const int seconds_per_day = 86400; - const unsigned int prev_update_version = - settings.value("mainwindow/last_remind_update_version").toUInt(); - const unsigned int new_update_version = m_update_checker->versionId(); - const bool timeout = !timer.isValid() - || timer.elapsedSeconds() > seconds_per_day; - const bool is_different_version = - new_update_version != prev_update_version; - - // Show update dialog only if the update dialog has not been shown - // for a certain period or the version is different. - if (timeout || is_different_version) { - UpdateDialog(this).exec(*m_update_checker); - timer.restart(); - settings.setValue("mainwindow/last_remind_update_version", - new_update_version); - } - } -} - -// Private Methods - -/* Check if all execute conditions are met. - This function should return true if all the conditions are met - and return false if any of the conditions fails. -*/ -bool MainWindow::check_execute_conditions() -{ - QString errmsg; - - // check external programs - if (!MediaConverter::checkExternalPrograms(errmsg)) { - QMessageBox::critical(this, this->windowTitle(), errmsg); -#ifdef TOOLS_IN_DATA_PATH - return false; // fatal: ffmpeg should be in the data path but doesn't exist -#else - QTimer::singleShot(0, this, SLOT(slotSetTools())); -#endif - } - // load presets - if (!load_presets()) - return false; - - return true; -} - -// We should respect the user and ask before connecting to the Internet to -// check for updates. -// If the user says yes, remember the decision and don't ask next time. -// If the user says no, disable checking for updates on startup. -bool MainWindow::ask_for_update_permission() -{ - const char *setting_key = "update_permission"; - QSettings settings; - bool permitted = settings.value(setting_key, false).toBool(); - if (permitted) return true; - - QString msg = tr("This program is going to check for updates online. " - "Do you allow this program to use the Internet " - "to check for updates?"); - - int reply = QMessageBox::information(this, - windowTitle(), - msg, - QMessageBox::Yes, - QMessageBox::No); - - if (reply == QMessageBox::Yes) { // permitted - settings.setValue(setting_key, true); // don't ask next time - return true; - } else { // rejected - // disable auto update because the user probably doesn't like it - settings.setValue("options/check_update_on_startup", false); - return false; - } -} - -// Popup wizard to add tasks. -void MainWindow::add_files() -{ - AddTaskWizard wizard(m_presets, this); - - if (wizard.exec_openfile() == QDialog::Accepted) { - // Add all input files to the list. - const QList ¶mList = wizard.getConversionParameters(); - m_list->addTasks(paramList); - } -} - -void MainWindow::add_files(const QStringList &fileList) -{ - AddTaskWizard wizard(m_presets, this); - - if (wizard.exec(fileList) == QDialog::Accepted) { - // Add all input files to the list. - const QList ¶mList = wizard.getConversionParameters(); - m_list->addTasks(paramList); - } -} - -void MainWindow::setup_widgets() -{ - // list - ui->layoutListPlaceholder->addWidget(m_list); - m_list->adjustSize(); - m_list->setContextMenuPolicy(Qt::CustomContextMenu); - - this->m_elapsedTimeLabel->clear(); -} - -void MainWindow::setup_menus() -{ - /* === Menu Events === */ - - // File - connect(ui->actionAddFiles, SIGNAL(triggered()), - this, SLOT(slotAddFiles())); - connect(ui->actionOptions, SIGNAL(triggered()), - this, SLOT(slotOptions())); - connect(ui->actionExit, SIGNAL(triggered()), - this, SLOT(slotExit())); - - // Edit - connect(ui->menuEdit, SIGNAL(aboutToShow()), - this, SLOT(refresh_action_states())); - connect(ui->actionRemoveSelectedItems, SIGNAL(triggered()), - m_list, SLOT(removeSelectedItems())); - connect(ui->actionRemoveCompletedItems, SIGNAL(triggered()), - m_list, SLOT(removeCompletedItems())); - connect(ui->actionClearList, SIGNAL(triggered()), - m_list, SLOT(clear())); - connect(ui->actionSetParameters, SIGNAL(triggered()), - this, SLOT(slotSetConversionParameters())); - connect(ui->actionOpenOutputFolder, SIGNAL(triggered()), - this, SLOT(slotOpenOutputFolder())); - connect(ui->actionOpenSettingFolder, SIGNAL(triggered()), - this, SLOT(slotOpenSettingFolder())); - connect(ui->actionChangeOutputFilename, SIGNAL(triggered()), - m_list, SLOT(changeSelectedOutputFile())); - connect(ui->actionChangeOutputDirectory, SIGNAL(triggered()), - m_list, SLOT(changeSelectedOutputDirectory())); - connect(ui->actionShowErrorMessage, SIGNAL(triggered()), - m_list, SLOT(showErrorMessage())); - connect(ui->actionCut, SIGNAL(triggered()), SLOT(slotCut())); - ui->actionCut->setVisible(InteractiveCuttingDialog::available()); - - // Convert - connect(ui->menuConvert, SIGNAL(aboutToShow()), - this, SLOT(refresh_action_states())); - connect(ui->actionStartConversion, SIGNAL(triggered()), - this, SLOT(slotStartConversion())); - connect(ui->actionStopConversion, SIGNAL(triggered()), - this, SLOT(slotStopConversion())); - connect(ui->actionRetry, SIGNAL(triggered()), - m_list, SLOT(retrySelectedItems())); - connect(ui->actionRetry, SIGNAL(triggered()), - this, SLOT(refresh_action_states())); - connect(ui->actionRetryAll, SIGNAL(triggered()), - m_list, SLOT(retryAll())); - connect(ui->actionRetryAll, SIGNAL(triggered()), - this, SLOT(refresh_action_states())); - - // About - connect(ui->actionHelpMystiQDialog, SIGNAL(triggered()), - this, SLOT(slotHelpMystiQDialog())); - connect(ui->actionAboutQt, SIGNAL(triggered()), - this, SLOT(slotAboutQt())); - connect(ui->actionAboutFFmpeg, SIGNAL(triggered()), - this, SLOT(slotAboutFFmpeg())); - connect(ui->actionAbout, SIGNAL(triggered()), - this, SLOT(slotAbout())); - connect(ui->actionReport, SIGNAL(triggered()), - this, SLOT(slotReport())); - connect(ui->actionDonate, SIGNAL(triggered()), - this, SLOT(slotDonate())); - connect(ui->actionTranslate, SIGNAL(triggered()), - this, SLOT(slotTranslate())); - connect(ui->actionCheckUpdate, SIGNAL(triggered()), - this, SLOT(slotShowUpdateDialog())); -} - -void MainWindow::setup_toolbar(const QStringList &entries) -{ - Q_ASSERT(m_poweroff_button && "setup_poweroff_button() must be called first"); - - // construct a table of available actions - // map action name to action pointer - QMap toolbar_table; -#define ADD_ACTION(name) toolbar_table[QString(#name).toUpper()] = ui->action ## name - ADD_ACTION(AddFiles); - ADD_ACTION(Options); - ADD_ACTION(Exit); - ADD_ACTION(RemoveSelectedItems); - ADD_ACTION(RemoveCompletedItems); - ADD_ACTION(ClearList); - ADD_ACTION(OpenOutputFolder); - ADD_ACTION(OpenSettingFolder); - ADD_ACTION(SetParameters); - ADD_ACTION(ChangeOutputFilename); - ADD_ACTION(ChangeOutputDirectory); // TODO: rename to "folder" - ADD_ACTION(ShowErrorMessage); - ADD_ACTION(StartConversion); - ADD_ACTION(StopConversion); - ADD_ACTION(Retry); - ADD_ACTION(RetryAll); - // "Shutdown" button is special, so we don't add it here -#define POWEROFF_BUTTON_NAME "POWEROFF" - ADD_ACTION(AboutQt); - ADD_ACTION(AboutFFmpeg); - ADD_ACTION(About); - ADD_ACTION(CheckUpdate); - ADD_ACTION(Report); - ADD_ACTION(Donate); - ADD_ACTION(Translate); - ADD_ACTION(HelpMystiQDialog); - - for (int i=0; itoolBar->addWidget(m_poweroff_button); - else if (entry == "|") // separator - ui->toolBar->addSeparator(); - else if (toolbar_table.contains(entry)) - ui->toolBar->addAction(toolbar_table[entry]); - } -} - -void MainWindow::setup_statusbar() -{ - ui->statusBar->addPermanentWidget(m_elapsedTimeLabel); -} - -/* - * Setup the poweroff button and menu. - * The poweroff button is handled differently from other menu and buttons. - * Its icon and title changes as the action changes. - * When this function finishes, m_poweroff_button will point to the constructed - * button widget. - */ -void MainWindow::setup_poweroff_button() -{ - QToolButton *button = new QToolButton(this); - QMenu *menu = new QMenu(this); - QList actionList; - QActionGroup *checkGroup = new QActionGroup(this); - - m_poweroff_button = button; - m_poweroff_actiongroup = checkGroup; - - // Insert all actions into the list. - for (int i=0; iaddAction(action); - action->setCheckable(true); - action->setActionGroup(checkGroup); - } - - button->setMenu(menu); - button->setPopupMode(QToolButton::MenuButtonPopup); - - // ensure that the toolbutton and actionPoweroff are both checkable - ui->actionPoweroff->setCheckable(true); - button->setCheckable(true); - button->setChecked(false); - - /* Synchronize the checked state of the toolbutton and actionPoweroff. - This cyclic connection doesn't cause an infinite loop because - toggled(bool) is only triggered when the checked() state changes. - */ - connect(button, SIGNAL(toggled(bool)) - , ui->actionPoweroff, SLOT(setChecked(bool))); - connect(ui->actionPoweroff, SIGNAL(toggled(bool)) - , button, SLOT(setChecked(bool))); - - // update the poweroff button when the action changes - for (int i=0; itrigger(); - - /* Check if the power management functions are available. - If not, hide poweroff button and menus. - */ - if (!PowerManagement::implemented()) { - m_poweroff_button->setVisible(false); - ui->actionPoweroff->setVisible(false); - } -} - -// Fill window icon with multiple sizes of images. -void MainWindow::setup_appicon() -{ - QIcon icon; - QDir iconDir = QDir(":/app/icons/"); - QStringList fileList = iconDir.entryList(); - QRegExp pattern("^mystiq_[0-9]+x[0-9]+\\.png$"); - foreach (QString file, fileList) { - if (pattern.indexIn(file) >= 0) { - icon.addPixmap(QPixmap(iconDir.absoluteFilePath(file))); - } - } - setWindowIcon(icon); - // Using logo app as About icon - //ui->actionAbout->setIcon(icon); -} - -void MainWindow::set_poweroff_behavior(int action) -{ - if (action >= PowerManagement::ACTION_COUNT) - action = PowerManagement::SHUTDOWN; - m_poweroff_actiongroup->actions().at(action)->trigger(); -} - -int MainWindow::get_poweroff_behavior() -{ - for (int i=0; iactions().size(); i++) { - if (m_poweroff_actiongroup->actions().at(i)->isChecked()) - return i; - } - return PowerManagement::SHUTDOWN; -} - -bool MainWindow::load_presets() -{ - // The default preset file is located in /presets.xml - QString default_preset_file = ":/other/presets.xml"; - - QString local_preset_file; - if (!Constants::getBool("Portable")) { // non-portable app - // rename local preset file created by older versions of mystiq - // operation: mv ~/.mystiq/presets.xml ~/.mystiq/presets.xml.old - QString local_preset_file_old = QDir(QDir::homePath()).absoluteFilePath(".mystiq/presets.xml"); - if (QFile(local_preset_file_old).exists()) { - QFile::remove(local_preset_file_old + ".old"); - if (QFile::rename(local_preset_file_old, local_preset_file_old + ".old")) { - qDebug() << local_preset_file_old + " is no longer used, " - "rename to " + local_preset_file_old + ".old"; - } - } - - // use global preset temporarily - local_preset_file = default_preset_file; - } else { - // portable app - local_preset_file = default_preset_file; - } - - QSettings settings; - bool removeUnavailableCodecs = settings.value("options/hideformats", true).toBool(); - // Load the preset file from the user's home directory - // The presets are loaded once and shared between objects - // that need the information. - if (!m_presets->readFromFile(local_preset_file, removeUnavailableCodecs)) { - QMessageBox::critical(this, this->windowTitle(), - tr("Failed to load preset file. " - "The application will quit now.")); - return false; - } - return true; -} - -// Hide unused actions -void MainWindow::refresh_action_states() -{ - int selected_file_count = m_list->selectedCount(); - - // Hide actionSetParameters if no item in m_list is selected. - bool hide_SetParameters = (selected_file_count == 0); - - // Hide actionStartConversion if the conversion is in progress. - bool hide_StartConversion = m_list->isBusy(); - - // Hide actionStopConversion if nothing is being converted. - bool hide_StopConversion = !m_list->isBusy(); - - // Show actionOpenOutputFolder only if 1 file is selected. - bool hide_OpenFolder = (selected_file_count <= 0); - - // Hide actionRemoveSelectedItems if no file is selected. - bool hide_RemoveSelectedItems = (selected_file_count == 0); - - bool hide_Retry = (selected_file_count == 0); - bool hide_RetryAll = (m_list->isEmpty()); - - bool hide_ClearList = (m_list->isEmpty()); - - bool hide_ChangeOutputFilename = m_list->selectedCount() != 1; - bool hide_ChangeOutputDirectory = m_list->selectedCount() <= 0; - - - /* Show actionShowErrorMessage if and only if one task is selected - and the state of the selected task is FAILED - */ - bool hide_ShowErrorMessage = (selected_file_count != 1 - || !m_list->selectedTaskFailed()); - - ui->actionSetParameters->setDisabled(hide_SetParameters); - ui->actionStartConversion->setDisabled(hide_StartConversion); - ui->actionStopConversion->setDisabled(hide_StopConversion); - ui->actionOpenOutputFolder->setDisabled(hide_OpenFolder); - ui->actionRemoveSelectedItems->setDisabled(hide_RemoveSelectedItems); - ui->actionRetry->setDisabled(hide_Retry); - ui->actionRetryAll->setDisabled(hide_RetryAll); - ui->actionClearList->setDisabled(hide_ClearList); - ui->actionChangeOutputFilename->setDisabled(hide_ChangeOutputFilename); - ui->actionChangeOutputDirectory->setDisabled(hide_ChangeOutputDirectory); - ui->actionShowErrorMessage->setDisabled(hide_ShowErrorMessage); - ui->actionCut->setEnabled(selected_file_count == 1); // cut only 1 file at a time -} - -void MainWindow::load_settings() -{ - QSettings settings; - restoreGeometry(settings.value("mainwindow/geometry").toByteArray()); - restoreState(settings.value("mainwindow/state").toByteArray()); - int poweroff_behavior = settings.value("options/poweroff_behavior" - , PowerManagement::SHUTDOWN).toInt(); - set_poweroff_behavior(poweroff_behavior); - -} - -void MainWindow::save_settings() -{ - QSettings settings; - settings.setValue("mainwindow/geometry", saveGeometry()); - settings.setValue("mainwindow/state", saveState()); - settings.setValue("options/poweroff_behavior", get_poweroff_behavior()); -} - -void MainWindow::refresh_status() -{ - refresh_statusbar(); - refresh_titlebar(); -} - -void MainWindow::refresh_statusbar() -{ - if (m_list->isBusy()) { - int total_seconds = m_list->elapsedTime() / 1000; - int hours = total_seconds / 3600; - int minutes = (total_seconds / 60) % 60; - int seconds = total_seconds % 60; - - QString timeinfo = tr("Elapsed Time: %1 h %2 m %3 s") - .arg(hours).arg(minutes).arg(seconds); - //m_elapsedTimeLabel->setText(timeinfo); - this->m_elapsedTimeLabel->setText(timeinfo); - } else { - //m_elapsedTimeLabel->clear(); - //ui->lblTime->clear(); - } -} - -void MainWindow::refresh_titlebar() -{ - const int task_count = m_list->count(); - const int finished_task_count = m_list->finishedCount(); - if (finished_task_count < task_count && m_list->isBusy()) { - //: Converting the %1-th file in %2 files. %2 is the number of files. - setWindowTitle(tr("MystiQ is Converting %1/%2") - .arg(finished_task_count+1).arg(task_count)); - } else { - setWindowTitle(tr("MystiQ Video Converter")); - } -} - -//void MainWindow::on_pushButton_clicked() -//{ -// this->close(); -//} - -void MainWindow::on_actionHelpMystiQDialog_triggered() -{ - -} - -void MainWindow::on_actionAbout_triggered() -{ - -} - -void MainWindow::on_actionReport_triggered() -{ - -} - -void MainWindow::on_actionDonate_triggered() -{ - -} - -void MainWindow::on_actionTranslate_triggered() -{ - -} - -void MainWindow::on_actionOpenSettingFolder_triggered() -{ - -} diff --git a/ui/mediaplayerwidget.cpp b/ui/mediaplayerwidget.cpp index 3e453c8..67374d2 100755 --- a/ui/mediaplayerwidget.cpp +++ b/ui/mediaplayerwidget.cpp @@ -56,6 +56,9 @@ MediaPlayerWidget::MediaPlayerWidget(QWidget *parent) : ui->slideVolume->setRange(0, MAX_VOLUME); m_mediaPlayer = new QMediaPlayer(this); + m_audioOutput = new QAudioOutput(); + m_mediaPlayer->setAudioOutput(m_audioOutput); + m_videoView = new QVideoWidget(this); ui->layoutPlayer->addWidget(m_videoView); @@ -64,7 +67,7 @@ MediaPlayerWidget::MediaPlayerWidget(QWidget *parent) : ui->slideSeek->setStyleSheet(SLIDER_STYLESHEET); - connect(m_mediaPlayer, &QMediaPlayer::stateChanged, [this] { + connect(m_mediaPlayer, &QMediaPlayer::playbackStateChanged, [this] { refreshTimeDisplay(); refreshButtonState(); emit stateChanged(); @@ -73,7 +76,7 @@ MediaPlayerWidget::MediaPlayerWidget(QWidget *parent) : connect(m_mediaPlayer, &QMediaPlayer::positionChanged, [this] { if (m_playUntil > 0 && m_mediaPlayer->position() >= m_playUntil * 1000 - && m_mediaPlayer->state() != QMediaPlayer::PausedState) + && m_mediaPlayer->playbackState() != QMediaPlayer::PausedState) { pause(); @@ -105,7 +108,7 @@ MediaPlayerWidget::MediaPlayerWidget(QWidget *parent) : }); connect(m_mediaPlayer, &QMediaPlayer::mediaStatusChanged, [this] (QMediaPlayer::MediaStatus status) { - if (status != QMediaPlayer::InvalidMedia && status != QMediaPlayer::LoadingMedia && status != QMediaPlayer::UnknownMediaStatus ) + if (status != QMediaPlayer::InvalidMedia && status != QMediaPlayer::LoadingMedia && status != QMediaPlayer::StalledMedia) { m_mediaPlayer->setPosition(m_beginSec * 1000); @@ -157,10 +160,10 @@ void MediaPlayerWidget::load(const QString &url, qint64 begin, qint64 end) update_limits(); - m_mediaPlayer->setMedia(QUrl::fromLocalFile(url)); + m_mediaPlayer->setSource(QUrl::fromLocalFile(url)); ui->slideVolume->setValue(m_volume); - m_mediaPlayer->setVolume(m_volume); + m_audioOutput->setVolume(m_volume); } void MediaPlayerWidget::reload() @@ -177,7 +180,7 @@ void MediaPlayerWidget::play() void MediaPlayerWidget::playRange(int begin_sec, int end_sec) { - if (m_mediaPlayer->state() != QMediaPlayer::PlayingState) + if (m_mediaPlayer->playbackState() != QMediaPlayer::PlayingState) { reload(); } @@ -221,7 +224,7 @@ void MediaPlayerWidget::seek_and_pause(qint64 sec) void MediaPlayerWidget::togglePlayPause() { - switch (m_mediaPlayer->state()) { + switch (m_mediaPlayer->playbackState()) { case QMediaPlayer::StoppedState: reload(); @@ -246,9 +249,8 @@ void MediaPlayerWidget::togglePlayPause() void MediaPlayerWidget::wheelEvent(QWheelEvent *event) { - int numDegrees = event->delta() / 8; // delta is in eighths of a degree - if (event->orientation() == Qt::Vertical) { - if (numDegrees >= 0) { + if (event->angleDelta().y() != 0) { // is vertical + if (event->angleDelta().y() / 8 >= 0) { seekForward(); } else { seekBackward(); @@ -279,19 +281,18 @@ void MediaPlayerWidget::refreshTimeDisplay() remaining = duration - position; - ui->lblPosition->setText(QString("%1 / %2") - .arg(sec2hms(position)) - .arg(sec2hms(duration))); + ui->lblPosition->setText( + QString::fromLatin1("%1 / %2").arg(sec2hms(position)).arg(sec2hms(duration))); - ui->lblRemaining->setText(QString("-%1").arg(sec2hms(remaining))); + ui->lblRemaining->setText(QString::fromLatin1("-%1").arg(sec2hms(remaining))); } void MediaPlayerWidget::refreshButtonState() { - QString button_icon = - m_mediaPlayer->state() == QMediaPlayer::PlayingState ? - ":/actions/icons/pause.svg" : - ":/actions/icons/play.svg"; + QString button_icon = QString::fromLatin1(m_mediaPlayer->playbackState() == QMediaPlayer::PlayingState + ? ":/actions/icons/pause.svg" + : ":/actions/icons/play.svg" + ); ui->btnPlayPause->setIcon(QIcon(button_icon)); } @@ -384,5 +385,5 @@ void MediaPlayerWidget::on_slideVolume_valueChanged(int value) QAudio::LogarithmicVolumeScale, QAudio::LinearVolumeScale); - m_mediaPlayer->setVolume(qRound(linearVolume * 100)); + m_audioOutput->setVolume(qRound(linearVolume * 100)); } diff --git a/ui/mediaplayerwidget.h b/ui/mediaplayerwidget.h index dd4cb2e..7c422d5 100644 --- a/ui/mediaplayerwidget.h +++ b/ui/mediaplayerwidget.h @@ -18,6 +18,7 @@ #ifndef MEDIAPLAYERWIDGET_H #define MEDIAPLAYERWIDGET_H +#include #include class QVideoWidget; @@ -114,6 +115,7 @@ private slots: Ui::MediaPlayerWidget *ui; QMediaPlayer *m_mediaPlayer; + QAudioOutput *m_audioOutput; QVideoWidget *m_videoView; QString m_file; diff --git a/ui/optionsdialog.cpp b/ui/optionsdialog.cpp index e5de9c6..ca16e93 100644 --- a/ui/optionsdialog.cpp +++ b/ui/optionsdialog.cpp @@ -39,7 +39,7 @@ OptionsDialog::OptionsDialog(QWidget *parent) : for (int i=0; itoolTable->insertRow(i); ui->toolTable->setItem(i, 0, new QTableWidgetItem(program_list[i])); - ui->toolTable->setItem(i, 1, new QTableWidgetItem("")); + ui->toolTable->setItem(i, 1, new QTableWidgetItem(QString::fromLatin1(""))); // make tool name not editable QTableWidgetItem *item = ui->toolTable->item(i, 0); item->setFlags(item->flags() ^ Qt::ItemIsEditable); diff --git a/ui/poweroffdialog.cpp b/ui/poweroffdialog.cpp index 0394df1..2064cd2 100644 --- a/ui/poweroffdialog.cpp +++ b/ui/poweroffdialog.cpp @@ -61,7 +61,7 @@ PoweroffDialog::~PoweroffDialog() int PoweroffDialog::exec(int action) { const char *icon_id = ""; - QString button_text = ""; + QString button_text = QString::fromLatin1(""); switch (action) { case PowerManagement::SHUTDOWN: @@ -83,7 +83,7 @@ int PoweroffDialog::exec(int action) Q_ASSERT_X(false, __FUNCTION__, "Incorrect id! Be sure to handle every power action in switch()."); } - ui->btnExecute->setIcon(QIcon(icon_id)); + ui->btnExecute->setIcon(QIcon(QString::fromLatin1(icon_id))); ui->btnExecute->setText(button_text); m_action = action; diff --git a/ui/progressbar.cpp b/ui/progressbar.cpp index 010ec74..437b1d1 100644 --- a/ui/progressbar.cpp +++ b/ui/progressbar.cpp @@ -98,8 +98,9 @@ void ProgressBar::paintEvent(QPaintEvent*) painter.setPen(pen); if (!m_show_text) { // show percentage - painter.drawText(rect_region, QString("%1%").arg(m_percentage) - , QTextOption(Qt::AlignCenter)); + painter.drawText(rect_region, + QString::fromLatin1("%1%").arg(m_percentage), + QTextOption(Qt::AlignCenter)); } else { // show custom text painter.drawText(rect_region, m_text, QTextOption(Qt::AlignCenter)); } diff --git a/ui/timerangeedit.cpp b/ui/timerangeedit.cpp index bf7ed96..98445cf 100644 --- a/ui/timerangeedit.cpp +++ b/ui/timerangeedit.cpp @@ -35,9 +35,9 @@ TimeRangeEdit::TimeRangeEdit(QWidget *parent) : { m_chkFromBegin->setText(tr("From Begin")); m_chkToEnd->setText(tr("To End")); - m_timeBegin->setDisplayFormat("hh:mm:ss"); + m_timeBegin->setDisplayFormat(QString::fromLatin1("hh:mm:ss")); m_timeBegin->setSelectedSection(QTimeEdit::SecondSection); - m_timeEnd->setDisplayFormat("hh:mm:ss"); + m_timeEnd->setDisplayFormat(QString::fromLatin1("hh:mm:ss")); m_timeEnd->setSelectedSection(QTimeEdit::SecondSection); QHBoxLayout *main_layout = new QHBoxLayout(this); diff --git a/ui/updatedialog.cpp b/ui/updatedialog.cpp index 0199fde..cb4b2e9 100644 --- a/ui/updatedialog.cpp +++ b/ui/updatedialog.cpp @@ -103,7 +103,7 @@ void UpdateDialog::slotReceivedUpdateResult(int result) message = tr("Failed to parse the received data."); break; case UpdateChecker::UpdateNotFound: - message = tr("You are already using the latest version of MystiQ.")+QString("
MystiQ Video Converter %1").arg(VERSION_STRING); + message = tr("You are already using the latest version of MystiQ.")+QString::fromLatin1("
MystiQ Video Converter %1").arg(VERSION_STRING); break; case UpdateChecker::UpdateDevChanel: message = tr("The current version you are using is newer than the release channel version.
Therefore, you are using the development channel."); @@ -111,7 +111,7 @@ void UpdateDialog::slotReceivedUpdateResult(int result) default: message = tr("An unknown error has occurred."); } - ui->lblStatus->setText(QString("%1").arg(message)); + ui->lblStatus->setText(QString::fromLatin1("%1").arg(message)); resizeToFit(); } @@ -138,22 +138,22 @@ QString UpdateDialog::get_status() { QStringList result; result << tr("A new version of MystiQ has been released!"); - result << "
"; + result << QString::fromLatin1("
"); //: %1 is version number, %2 is the project homepage result << tr("Version %1 is available at %2.") .arg(m_updateChecker->versionName(), link(m_updateChecker->downloadPage())); QString url = m_updateChecker->downloadUrl(); if (!url.isEmpty()) { - result << "
"; + result << QString::fromLatin1("
"); result << tr("You can download this version using the link:"); - result << "
"; + result << QString::fromLatin1("
"); result << link(m_updateChecker->downloadUrl()); } - return result.join(""); + return result.join(QString::fromLatin1("")); } QString UpdateDialog::link(const QString &s) { - return QString("%1").arg(s); + return QString::fromLatin1("%1").arg(s); } From a9cf6c0849896f4c58109ae06492a3e48191221a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20A=2E=20L=C3=B3pez=20L=C3=B3pez?= Date: Sun, 9 Jun 2024 15:35:13 -0400 Subject: [PATCH 3/5] WIP: Migration to Qt6 Fix to correct the detection of media duration --- converter/ffmpeginterface.cpp | 21 +++++++-------------- converter/mediaprobe.cpp | 8 +++----- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/converter/ffmpeginterface.cpp b/converter/ffmpeginterface.cpp index 1f63b32..afb6170 100644 --- a/converter/ffmpeginterface.cpp +++ b/converter/ffmpeginterface.cpp @@ -317,29 +317,28 @@ bool FFmpegInterface::Private::check_progress(const QString& line) { QRegularExpression &pattern = progress_pattern; QRegularExpressionMatch match = pattern.match(line); + bool matchFound = false; if (match.hasMatch()) { + matchFound = true; const double t = match.captured(patterns::PROG_1_TIME).toDouble(); // calculate progress progress = (t / duration) * 100; - - return true; } else { // try another pattern QRegularExpression &alternate_pattern = progress_pattern_2; QRegularExpressionMatch match_alternate = alternate_pattern.match(line); if (match_alternate.hasMatch()) { + matchFound = true; const int hour = match_alternate.captured(patterns::PROG_2_HR).toInt(); const int min = match_alternate.captured(patterns::PROG_2_MIN).toInt(); const double sec = match_alternate.captured(patterns::PROG_2_SEC).toDouble(); const double t = hour*3600 + min*60 + sec; - progress = (t / duration) * 100; - - return true; } } - errmsg = line; // save the last output line - return false; + if(!matchFound) errmsg = line; // save the last output line + + return matchFound; } /** @@ -749,9 +748,6 @@ void FFmpegInterface::fillParameterList(const ConversionParameters ¶m, QStri void FFmpegInterface::parseProcessOutput(const QString &data) { - //Show qDebug Message - //qDebug() << data; - // split incoming data by [end of line] or [carriage return] QStringList lines( data.split(QRegularExpression(QString::fromLatin1("[\r\n]")), Qt::KeepEmptyParts)); @@ -766,10 +762,7 @@ void FFmpegInterface::parseProcessOutput(const QString &data) lines.back().clear(); } - QStringList::iterator it = lines.begin(); - - for (; it!=lines.end(); ++it) { // parse lines - QString& line = *it; + for (const QString &line : lines) { if (line.isEmpty()) continue; if (p->check_progress(line)) { emit progressRefreshed(p->progress); diff --git a/converter/mediaprobe.cpp b/converter/mediaprobe.cpp index 0d6f4b9..091a98f 100644 --- a/converter/mediaprobe.cpp +++ b/converter/mediaprobe.cpp @@ -35,7 +35,7 @@ namespace patterns { // META const char meta[] - = "Duration: ([0-9]+):([0-9]+):([0-9]+\\.[0-9]*)(, start: ([0-9]+\\.[0-9]*))?, bitrate: ([0-9]+) kb/s"; + = "Duration: ([0-9]+):([0-9]+):([0-9]+\\.[0-9]*)(, start: (-[0-9]+\\.[0-9]*))?, bitrate: ([0-9]+) kb/s"; const char META_HOUR_INDEX = 1; // matched type: integer const char META_MINUTE_INDEX = 2; // matched type: integer const char META_SECOND_INDEX = 3; // matched type: double @@ -106,9 +106,8 @@ struct MetaInformation duration = hour * SECONDS_PER_HOUR + minute * SECONDS_PER_MINUTE + second; start = match.captured(patterns::META_START_INDEX).toDouble(); bitrate = match.captured(patterns::META_BITRATE_INDEX).toInt(); - return true; } - return false; + return match.hasMatch(); } }; @@ -331,6 +330,7 @@ bool MediaProbe::start(const QString& filename) p->ffprobe_proc.setReadChannel(QProcess::StandardError); p->ffprobe_proc.start(ExePath::getPath(QString::fromLatin1("ffprobe")), list); + return p->ffprobe_proc.waitForStarted(TIMEOUT); } return false; @@ -472,7 +472,6 @@ bool MediaProbe::hasSubtitle() const void MediaProbe::m_proc_finished(int exitcode) { p->exitcode = exitcode; - if (exitcode == 0) { // If the process finished normally, parse its output. p->clear(); while (p->ffprobe_proc.canReadLine()) { @@ -480,6 +479,5 @@ void MediaProbe::m_proc_finished(int exitcode) p->parse_line(line); } } - emit process_finished(); } From 2f9a1525ce9a2a5c2e44107417bfc611517c9a94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20A=2E=20L=C3=B3pez=20L=C3=B3pez?= Date: Sun, 9 Jun 2024 15:36:31 -0400 Subject: [PATCH 4/5] WIP: Migration to Qt6 Restore default options on QMainWindow --- ui/convertlist.cpp | 5 +--- ui/mainwindow.cpp | 4 +--- ui/mainwindow.ui | 57 ++++++++-------------------------------------- 3 files changed, 12 insertions(+), 54 deletions(-) diff --git a/ui/convertlist.cpp b/ui/convertlist.cpp index 62578f6..e303bc6 100644 --- a/ui/convertlist.cpp +++ b/ui/convertlist.cpp @@ -588,10 +588,7 @@ void ConvertList::task_finished_slot(int exitcode) ? Task::FINISHED : Task::FAILED; - if (exitcode != 0) - m_current_task->errmsg = m_converter->errorMessage(); - else - m_current_task->errmsg = ""; + m_current_task->errmsg = exitcode != 0 ? m_converter->errorMessage() : QString::fromLatin1(""); refresh_progressbar(m_current_task); diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index 92a1e18..66f285e 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -540,9 +540,7 @@ void MainWindow::add_files(const QStringList &fileList) void MainWindow::setup_widgets() { - // list - ui->layoutListPlaceholder->addWidget(m_list); - m_list->adjustSize(); + ui->centralWidget->layout()->addWidget(m_list); m_list->setContextMenuPolicy(Qt::CustomContextMenu); this->m_elapsedTimeLabel->clear(); diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index 6a2d1aa..2ce42f5 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -9,8 +9,8 @@ 0 0 - 990 - 450 + 450 + 250 @@ -26,12 +26,6 @@ :/app/icons/mystiq.svg:/app/icons/mystiq.svg - - true - - - - 22 @@ -53,13 +47,13 @@ - 1 + 0 - 1 + 0 - 1 + 0 0 @@ -67,28 +61,6 @@ 0 - - - - 0 - - - QLayout::SetMaximumSize - - - 0 - - - 0 - - - 0 - - - 0 - - - @@ -96,8 +68,8 @@ 0 0 - 990 - 29 + 450 + 23 @@ -179,22 +151,13 @@ false - Qt::LeftToolBarArea - - - - 25 - 25 - - - - Qt::ToolButtonIconOnly + Qt::TopToolBarArea - true + false - LeftToolBarArea + TopToolBarArea false From cb126832866c722f448639a237cda6bba796cc2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20A=2E=20L=C3=B3pez=20L=C3=B3pez?= Date: Mon, 10 Jun 2024 01:41:41 -0400 Subject: [PATCH 5/5] WIP: Migration to Qt6 Fix the QML Video Cropper --- qml/main.qml | 168 +++++++++++++++++++++++++++------------------------ 1 file changed, 88 insertions(+), 80 deletions(-) diff --git a/qml/main.qml b/qml/main.qml index 1a35dd2..aea340e 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -1,5 +1,6 @@ -import QtQuick 2.4 -import QtMultimedia 5.10 +import QtQuick +import QtQml +import QtMultimedia Rectangle { id: root @@ -15,11 +16,13 @@ Rectangle { property color cut_cortain_color: "black" property real cut_cortain_opacity: .9 - signal cut_up_changed(real value); - signal cut_bottom_changed(real value); - signal cut_left_changed(real value); - signal cut_right_changed(real value); - signal video_loaded(int w, int h); + signal cut_up_changed(real value) + signal cut_bottom_changed(real value) + signal cut_left_changed(real value) + signal cut_right_changed(real value) + signal video_loaded(int w, int h) + + property size resolution: undefined property bool __from_external: false property real __free_space_w: 0.0 @@ -29,48 +32,51 @@ Rectangle { property real oldH: 0.0 function top_cut_change(value) { - __from_external = true; + __from_external = true - var H = video.metaData.resolution.height; + var H = root.resolution.height - up_cut.y = value * (video.height - (__free_space_h * 2)) / H + __free_space_h; + up_cut.y = value * (output.height - (__free_space_h * 2)) / H + __free_space_h } function left_cut_change(value) { - __from_external = true; + __from_external = true - var w = video.metaData.resolution.width; + var w = root.resolution.width - left_cut.x = value * (video.width - (__free_space_w * 2)) / w + __free_space_w; + left_cut.x = value * (output.width - (__free_space_w * 2)) / w + __free_space_w } function bottom_cut_change(value) { - __from_external = true; + __from_external = true - var H = video.metaData.resolution.height; + var H = root.resolution.height - //down_cut.y = (value * (video.height - (__free_space_h * 2)) / H + __free_space_h) - cut_line_width; - down_cut.y = ((value * (video.height - (__free_space_h * 2)))/H) - (cut_line_width) - __free_space_h; + //down_cut.y = (value * (output.height - (__free_space_h * 2)) / H + __free_space_h) - cut_line_width; + down_cut.y = ((value * (output.height - (__free_space_h * 2))) / H) + - (cut_line_width) - __free_space_h } function right_cut_change(value) { - __from_external = true; + __from_external = true - var w = video.metaData.resolution.width; + var w = root.resolution.width - //right_cut.x = value * (video.width - (__free_space_w * 2)) / w + __free_space_w - right_cut.width; - right_cut.x = ((value * (video.width - (__free_space_w * 2))) / w) - cut_line_width + __free_space_w; + right_cut.x = ((value * (output.width - (__free_space_w * 2))) / w) + - cut_line_width + __free_space_w } function calculateRatios() { - if (video.metaData.resolution === undefined) return; - let ratio = video.metaData.resolution.width / video.metaData.resolution.height + if (root.resolution === undefined) + return + + let ratio = root.resolution.width / root.resolution.height - let direction = (root.height * ratio <= root.width); //TRUE -> Width : FALSE -> Height + let direction = (root.height * ratio <= root.width) - if (direction) - { + //TRUE -> Width : FALSE -> Height + if (direction) { __free_space_w = (root.width - (root.height * ratio)) / 2.0 __free_space_h = 0.0 @@ -79,9 +85,7 @@ Rectangle { down_cut.y = root.height - down_cut.height up_cut.y = 0.0 - } - else - { + } else { __free_space_h = (root.height - (root.width / ratio)) / 2.0 __free_space_w = 0.0 @@ -93,39 +97,47 @@ Rectangle { } } - Video { - id: video - anchors.fill: parent + MediaPlayer { + id: player + audioOutput: AudioOutput {} + videoOutput: output - focus: true source: root.file_source loops: MediaPlayer.Infinite - MouseArea { - anchors.fill: parent - onClicked: { - if (video.playbackState == MediaPlayer.PlayingState) { - video.pause() - } else { - video.play() - } - } - } - onErrorStringChanged: { - console.log("ERROR ON VIDEO RENDER:", errorString); + console.log("ERROR ON VIDEO RENDER:", errorString) } - onStatusChanged: { - if (status == MediaPlayer.Loaded && seekable == true) - { - seek(20 * duration / 100); - play(); - pause(); + onMediaStatusChanged: { + + console.log("player.onMediaStatusChanged", mediaStatus) + + if (mediaStatus == MediaPlayer.LoadedMedia) { + setPosition(20 * duration / 100) + play() + pause() - calculateRatios(); + calculateRatios() - root.video_loaded(metaData.resolution.width, metaData.resolution.height) + root.resolution = metaData.value(MediaMetaData.Resolution) + root.video_loaded(root.resolution.width, root.resolution.height) + } + } + } + + VideoOutput { + id: output + anchors.fill: parent + + MouseArea { + anchors.fill: parent + onClicked: { + if (player.playbackState == MediaPlayer.PlayingState) { + player.pause() + } else { + player.play() + } } } } @@ -211,10 +223,10 @@ Rectangle { onYChanged: { up.height = y - if (!__from_external && video.metaData.resolution !== undefined) - { - var H = video.metaData.resolution.height; - root.cut_up_changed((H * (y - __free_space_h)) / (video.height - __free_space_h * 2)); + if (!__from_external && root.resolution !== undefined) { + var H = root.resolution.height + root.cut_up_changed( + (H * (y - __free_space_h)) / (output.height - __free_space_h * 2)) } __from_external = false @@ -246,10 +258,10 @@ Rectangle { onYChanged: { down.height = root.height - y - if (!__from_external && video.metaData.resolution !== undefined) - { - var H = video.metaData.resolution.height; - root.cut_bottom_changed((H * (y + height + __free_space_h)) / (video.height - __free_space_h * 2)); + if (!__from_external && root.resolution !== undefined) { + var H = root.resolution.height + root.cut_bottom_changed((H * (y + height + __free_space_h)) + / (output.height - __free_space_h * 2)) } __from_external = false @@ -281,15 +293,13 @@ Rectangle { onXChanged: { left.width = x - if (!__from_external && video.metaData.resolution !== undefined) - { - var W = video.metaData.resolution.width - root.cut_left_changed((W * (x - __free_space_w)) / (video.width - __free_space_w * 2)); + if (!__from_external && root.resolution !== undefined) { + var W = root.resolution.width + root.cut_left_changed( + (W * (x - __free_space_w)) / (output.width - __free_space_w * 2)) } __from_external = false - - } } @@ -318,10 +328,10 @@ Rectangle { onXChanged: { right.width = root.width - x - if (!__from_external && video.metaData.resolution !== undefined) - { - var W = video.metaData.resolution.width; - root.cut_right_changed((W * (x + width - __free_space_w)) / (video.width - __free_space_w * 2)); + if (!__from_external && root.resolution !== undefined) { + var W = root.resolution.width + root.cut_right_changed((W * (x + width - __free_space_w)) + / (output.width - __free_space_w * 2)) } __from_external = false @@ -329,24 +339,22 @@ Rectangle { } onFile_sourceChanged: { - console.log("New video file", file_source); + console.log("New video file", file_source) } onWidthChanged: { - calculateRatios(); + calculateRatios() - if (video.metaData.resolution !== undefined) - { - root.video_loaded(video.metaData.resolution.width, video.metaData.resolution.height) + if (root.resolution !== undefined) { + root.video_loaded(root.resolution.width, root.resolution.height) } } onHeightChanged: { - calculateRatios(); + calculateRatios() - if (video.metaData.resolution !== undefined) - { - root.video_loaded(video.metaData.resolution.width, video.metaData.resolution.height) + if (root.resolution !== undefined) { + root.video_loaded(root.resolution.width, root.resolution.height) } } }