* Similar to `QMessageBox::critical` but with the following changes: * 1. The title is prefixed with the plugin name * 2. MacOS: Shows text in the title bar * 3. MacOS: The message is not bold by default * 4. A common footer is appended to the message * 5. The message box is shown after a delay (default 2000ms) * 6. Shows the dialog as WindowStaysOnTopHint and NonModal * 7. Deletes t
| 136 | * @param milliseconds The delay in milliseconds before the message box is shown |
| 137 | */ |
| 138 | void showCriticalMessageBoxDelayed(const QString &title, const QString &message, int milliseconds = 2000) |
| 139 | { |
| 140 | auto newTitle = QString("%1 : %2").arg(PLUGIN_DISPLAY_NAME, title); |
| 141 | |
| 142 | auto newMessage = message; |
| 143 | newMessage.remove(QRegularExpression("(\r?\n?<br>\r?\n?)+$")); |
| 144 | auto newMessageFormat = QRegularExpression("(</ol>|</ul>)$").match(newMessage).hasMatch() ? "%1%2" |
| 145 | : "%1<br><br>%2"; |
| 146 | newMessage = QString(newMessageFormat) |
| 147 | .arg(newMessage, |
| 148 | QTStr("NDIPlugin.PluginLimitedFeatures") |
| 149 | .arg(PLUGIN_DISPLAY_NAME, rehostUrl(PLUGIN_REDIRECT_TROUBLESHOOTING_URL), |
| 150 | rehostUrl(PLUGIN_REDIRECT_REPORT_BUG_URL))); |
| 151 | QTimer::singleShot(milliseconds, [newTitle, newMessage] { |
| 152 | auto dlg = new QMessageBox(QMessageBox::Critical, newTitle, newMessage, QMessageBox::Ok); |
| 153 | #if defined(Q_OS_MACOS) |
| 154 | // Make title bar show text: https://stackoverflow.com/a/22187538/25683720 |
| 155 | dlg->QDialog::setWindowTitle(newTitle); |
| 156 | #endif |
| 157 | QObject::connect(dlg, &QMessageBox::finished, [](int result) { |
| 158 | if (result != QMessageBox::Ok) { |
| 159 | return; |
| 160 | } |
| 161 | |
| 162 | if (output_settings) { |
| 163 | output_settings->show(); |
| 164 | output_settings->raise(); |
| 165 | output_settings->activateWindow(); |
| 166 | obs_log(LOG_DEBUG, |
| 167 | "showCriticalMessageBoxDelayed: opened DistroAV settings after OK click"); |
| 168 | } else { |
| 169 | obs_log(LOG_DEBUG, |
| 170 | "showCriticalMessageBoxDelayed: DistroAV settings are unavailable at OK click"); |
| 171 | } |
| 172 | }); |
| 173 | dlg->setAttribute(Qt::WA_DeleteOnClose, true); |
| 174 | dlg->setWindowFlags(dlg->windowFlags() | Qt::WindowStaysOnTopHint); |
| 175 | dlg->setWindowModality(Qt::NonModal); |
| 176 | dlg->show(); |
| 177 | }); |
| 178 | } |
| 179 | |
| 180 | // |
| 181 | // |
no test coverage detected