From 69cd8d3a75e85b4652bf6c33d92c12ca939ebbf2 Mon Sep 17 00:00:00 2001 From: Mike Solar Date: Mon, 20 Jul 2026 01:01:18 +0800 Subject: [PATCH] refactor: move msg_box out of engine qtutils into the dialog layer The engine-side QtUtils no longer references QMessageBox; the two dialog call sites use the identical olive::msg_box() inline helper. --- app/common/qtutils.cpp | 22 ------------ app/common/qtutils.h | 5 --- app/dialog/export/export.cpp | 15 ++++---- app/dialog/msgbox.h | 60 ++++++++++++++++++++++++++++++++ app/dialog/sequence/sequence.cpp | 5 +-- 5 files changed, 71 insertions(+), 36 deletions(-) create mode 100644 app/dialog/msgbox.h diff --git a/app/common/qtutils.cpp b/app/common/qtutils.cpp index 7c6f852e6..4b469926a 100644 --- a/app/common/qtutils.cpp +++ b/app/common/qtutils.cpp @@ -50,28 +50,6 @@ QFrame *QtUtils::create_vertical_line() return l; } -int QtUtils::msg_box(QWidget *parent, QMessageBox::Icon icon, - const QString &title, const QString &message, - QMessageBox::StandardButtons buttons) -{ - QMessageBox b(parent); - b.setIcon(icon); - b.setWindowModality(Qt::WindowModal); - b.setWindowTitle(title); - b.setText(message); - - uint mask = QMessageBox::FirstButton; - while (mask <= QMessageBox::LastButton) { - uint sb = buttons & mask; - if (sb) { - b.addButton(static_cast(sb)); - } - mask <<= 1; - } - - return b.exec(); -} - QDateTime QtUtils::get_creation_date(const QFileInfo &info) { #if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) diff --git a/app/common/qtutils.h b/app/common/qtutils.h index 74a97e564..f99d57cb9 100644 --- a/app/common/qtutils.h +++ b/app/common/qtutils.h @@ -28,7 +28,6 @@ #include #include #include -#include namespace olive { @@ -48,10 +47,6 @@ public: static QFrame *create_vertical_line(); - static int msg_box(QWidget *parent, QMessageBox::Icon icon, - const QString &title, const QString &message, - QMessageBox::StandardButtons buttons = QMessageBox::Ok); - static QDateTime get_creation_date(const QFileInfo &info); static QString get_formatted_date_time(const QDateTime &dt); diff --git a/app/dialog/export/export.cpp b/app/dialog/export/export.cpp index ad6bd6037..323577392 100644 --- a/app/dialog/export/export.cpp +++ b/app/dialog/export/export.cpp @@ -33,6 +33,7 @@ #include "common/digit.h" #include "common/qtutils.h" +#include "dialog/msgbox.h" #include "dialog/task/task.h" #include "exportsavepresetdialog.h" #include "node/project.h" @@ -308,7 +309,7 @@ void ExportDialog::start_export() { if (!video_enabled_->isChecked() && !audio_enabled_->isChecked() && !subtitles_enabled_->isChecked()) { - QtUtils::msg_box( + msg_box( this, QMessageBox::Critical, tr("Invalid parameters"), tr("Video, audio, and subtitles are disabled. There's nothing to export.")); return; @@ -322,7 +323,7 @@ void ExportDialog::start_export() // If it doesn't, see if the user wants to append it automatically. If not, we don't abort the export. if (!proposed_filename.endsWith(necessary_ext, Qt::CaseInsensitive)) { - if (QtUtils::msg_box( + if (msg_box( this, QMessageBox::Warning, tr("Invalid filename"), tr("The filename must contain the extension \"%1\". Would you like to append it " "automatically?") @@ -341,7 +342,7 @@ void ExportDialog::start_export() // If the directory does not exist, try to create it QDir dest_dir(file_info.path()); if (!FileFunctions::directory_is_valid(dest_dir)) { - QtUtils::msg_box( + msg_box( this, QMessageBox::Critical, tr("Failed to create output directory"), tr("The intended output directory doesn't exist and Oak Video Editor couldn't create it. " @@ -353,7 +354,7 @@ void ExportDialog::start_export() if (video_tab_->is_image_sequence_set()) { // Ensure filename contains digits if (!Encoder::filename_contains_digit_placeholder(proposed_filename)) { - QtUtils::msg_box( + msg_box( this, QMessageBox::Critical, tr("Invalid filename"), tr("Export is set to an image sequence, but the filename does not have a section for digits " "(formatted as [#####] where the amount of # is the amount of digits).")); @@ -365,7 +366,7 @@ void ExportDialog::start_export() int current_digit_count = Encoder::get_image_sequence_placeholder_digit_count(proposed_filename); if (current_digit_count < needed_digit_count) { - QtUtils::msg_box( + msg_box( this, QMessageBox::Critical, tr("Invalid filename"), tr("Filename doesn't contain enough digits for the amount of frames " "this export will need (need %1 for %n frame(s)).", @@ -377,7 +378,7 @@ void ExportDialog::start_export() // Validate if the file exists and whether the user wishes to overwrite it if (file_info.exists()) { - if (QtUtils::msg_box( + if (msg_box( this, QMessageBox::Warning, tr("Confirm Overwrite"), tr("The file \"%1\" already exists. Do you want to overwrite it?") .arg(proposed_filename), @@ -392,7 +393,7 @@ void ExportDialog::start_export() video_tab_->get_selected_codec() == ExportCodec::k_codec_h265) && (video_tab_->width_slider()->get_value() % 2 != 0 || video_tab_->height_slider()->get_value() % 2 != 0)) { - QtUtils::msg_box(this, QMessageBox::Critical, tr("Invalid Parameters"), + msg_box(this, QMessageBox::Critical, tr("Invalid Parameters"), tr("Width and height must be multiples of 2.")); return; } diff --git a/app/dialog/msgbox.h b/app/dialog/msgbox.h new file mode 100644 index 000000000..300fce9ef --- /dev/null +++ b/app/dialog/msgbox.h @@ -0,0 +1,60 @@ +/*** + + Oak - Non-Linear Video Editor + Copyright (C) 2026 Oak Team + + 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 . + +***/ + +#ifndef OAK_MSGBOX_H +#define OAK_MSGBOX_H + +#include +#include + +namespace olive +{ + +/** + * @brief Shows a simple window-modal message box + * + * Lives in the UI layer: the engine (common/qtutils) must not reference + * QMessageBox. Previously QtUtils::msg_box. + */ +inline int msg_box(QWidget *parent, QMessageBox::Icon icon, + const QString &title, const QString &message, + QMessageBox::StandardButtons buttons = QMessageBox::Ok) +{ + QMessageBox b(parent); + b.setIcon(icon); + b.setWindowModality(Qt::WindowModal); + b.setWindowTitle(title); + b.setText(message); + + uint mask = QMessageBox::FirstButton; + while (mask <= QMessageBox::LastButton) { + uint sb = buttons & mask; + if (sb) { + b.addButton(static_cast(sb)); + } + mask <<= 1; + } + + return b.exec(); +} + +} + +#endif // OAK_MSGBOX_H diff --git a/app/dialog/sequence/sequence.cpp b/app/dialog/sequence/sequence.cpp index 9cd1c9441..454331cad 100644 --- a/app/dialog/sequence/sequence.cpp +++ b/app/dialog/sequence/sequence.cpp @@ -33,6 +33,7 @@ #include "config/config.h" #include "core.h" #include "common/qtutils.h" +#include "dialog/msgbox.h" #include "undo/undostack.h" namespace olive @@ -107,7 +108,7 @@ void SequenceDialog::set_name_is_editable(bool e) void SequenceDialog::accept() { if (name_field_->isEnabled() && name_field_->text().isEmpty()) { - QtUtils::msg_box(this, QMessageBox::Critical, + msg_box(this, QMessageBox::Critical, tr("Error editing Sequence"), tr("Please enter a name for this Sequence.")); return; @@ -178,7 +179,7 @@ void SequenceDialog::accept() void SequenceDialog::set_as_default_clicked() { - if (QtUtils::msg_box( + if (msg_box( this, QMessageBox::Question, tr("Confirm Set As Default"), tr("Are you sure you want to set the current parameters as defaults?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {