Make message boxes more platform independent with a wrapper

Instead  of  using the  Qt  QMessageBox  class  directly a  new  class
MessageBox  (MessageBox.hpp)  has been  added  to  deal with  platform
independence issues like the title not being shown on Mac OS X.

git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@6861 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
Bill Somerville 2016-07-03 20:31:19 +00:00
parent d375f0c874
commit 3f1ea9d10c
17 changed files with 393 additions and 218 deletions

View File

@ -197,6 +197,7 @@ set (WSJT_QT_CONF_DESTINATION ${QT_CONF_DESTINATION} CACHE PATH "Path for the qt
# #
set (wsjt_qt_CXXSRCS set (wsjt_qt_CXXSRCS
qt_helpers.cpp qt_helpers.cpp
MessageBox.cpp
MetaDataRegistry.cpp MetaDataRegistry.cpp
NetworkServerLookup.cpp NetworkServerLookup.cpp
revision_utils.cpp revision_utils.cpp

View File

@ -141,7 +141,6 @@
#include <QAudioDeviceInfo> #include <QAudioDeviceInfo>
#include <QAudioInput> #include <QAudioInput>
#include <QDialog> #include <QDialog>
#include <QMessageBox>
#include <QAction> #include <QAction>
#include <QFileDialog> #include <QFileDialog>
#include <QDir> #include <QDir>
@ -163,6 +162,7 @@
#include <QScopedPointer> #include <QScopedPointer>
#include <QDebug> #include <QDebug>
#include "pimpl_impl.hpp"
#include "qt_helpers.hpp" #include "qt_helpers.hpp"
#include "MetaDataRegistry.hpp" #include "MetaDataRegistry.hpp"
#include "SettingsGroup.hpp" #include "SettingsGroup.hpp"
@ -176,8 +176,7 @@
#include "FrequencyList.hpp" #include "FrequencyList.hpp"
#include "StationList.hpp" #include "StationList.hpp"
#include "NetworkServerLookup.hpp" #include "NetworkServerLookup.hpp"
#include "MessageBox.hpp"
#include "pimpl_impl.hpp"
#include "ui_Configuration.h" #include "ui_Configuration.h"
#include "moc_Configuration.cpp" #include "moc_Configuration.cpp"
@ -386,7 +385,6 @@ private:
void enumerate_rigs (); void enumerate_rigs ();
void set_rig_invariants (); void set_rig_invariants ();
bool validate (); bool validate ();
void message_box (QString const& reason, QString const& detail = QString ());
void fill_port_combo_box (QComboBox *); void fill_port_combo_box (QComboBox *);
Frequency apply_calibration (Frequency) const; Frequency apply_calibration (Frequency) const;
Frequency remove_calibration (Frequency) const; Frequency remove_calibration (Frequency) const;
@ -819,7 +817,8 @@ Configuration::impl::impl (Configuration * self, QDir const& temp_directory,
QDir data_dir {QStandardPaths::writableLocation (QStandardPaths::DataLocation)}; QDir data_dir {QStandardPaths::writableLocation (QStandardPaths::DataLocation)};
if (!data_dir.mkpath (".")) if (!data_dir.mkpath ("."))
{ {
QMessageBox::critical (this, "WSJT-X", tr ("Create data directory error: ") + data_dir.absolutePath ()); MessageBox::critical_message (this, tr ("Failed to create data directory"),
tr ("path: \"%1\"").arg (data_dir.absolutePath ()));
throw std::runtime_error {"Failed to create data directory"}; throw std::runtime_error {"Failed to create data directory"};
} }
@ -829,8 +828,9 @@ Configuration::impl::impl (Configuration * self, QDir const& temp_directory,
default_azel_directory_ = data_dir; default_azel_directory_ = data_dir;
if (!default_save_directory_.mkpath (save_dir) || !default_save_directory_.cd (save_dir)) if (!default_save_directory_.mkpath (save_dir) || !default_save_directory_.cd (save_dir))
{ {
QMessageBox::critical (this, "WSJT-X", tr ("Create Directory", "Cannot create directory \"") + MessageBox::critical_message (this, tr ("Failed to create save directory"),
default_save_directory_.absoluteFilePath (save_dir) + "\"."); tr ("path: \"%1\%")
.arg (default_save_directory_.absoluteFilePath (save_dir)));
throw std::runtime_error {"Failed to create save directory"}; throw std::runtime_error {"Failed to create save directory"};
} }
@ -840,9 +840,10 @@ Configuration::impl::impl (Configuration * self, QDir const& temp_directory,
QString samples_dir {"samples"}; QString samples_dir {"samples"};
if (!default_save_directory_.mkpath (samples_dir)) if (!default_save_directory_.mkpath (samples_dir))
{ {
QMessageBox::critical (this, "WSJT-X", tr ("Create Directory", "Cannot create directory \"") + MessageBox::critical_message (this, tr ("Failed to create samples directory"),
default_save_directory_.absoluteFilePath (samples_dir) + "\"."); tr ("path: \"%1\"")
throw std::runtime_error {"Failed to create save directory"}; .arg (default_save_directory_.absoluteFilePath (samples_dir)));
throw std::runtime_error {"Failed to create samples directory"};
} }
// copy in any new sample files to the sample directory // copy in any new sample files to the sample directory
@ -1537,20 +1538,20 @@ bool Configuration::impl::validate ()
if (ui_->sound_input_combo_box->currentIndex () < 0 if (ui_->sound_input_combo_box->currentIndex () < 0
&& !QAudioDeviceInfo::availableDevices (QAudio::AudioInput).empty ()) && !QAudioDeviceInfo::availableDevices (QAudio::AudioInput).empty ())
{ {
message_box (tr ("Invalid audio input device")); MessageBox::critical_message (this, tr ("Invalid audio input device"));
return false; return false;
} }
if (ui_->sound_output_combo_box->currentIndex () < 0 if (ui_->sound_output_combo_box->currentIndex () < 0
&& !QAudioDeviceInfo::availableDevices (QAudio::AudioOutput).empty ()) && !QAudioDeviceInfo::availableDevices (QAudio::AudioOutput).empty ())
{ {
message_box (tr ("Invalid audio output device")); MessageBox::critical_message (this, tr ("Invalid audio out device"));
return false; return false;
} }
if (!ui_->PTT_method_button_group->checkedButton ()->isEnabled ()) if (!ui_->PTT_method_button_group->checkedButton ()->isEnabled ())
{ {
message_box (tr ("Invalid PTT method")); MessageBox::critical_message (this, tr ("Invalid PTT method"));
return false; return false;
} }
@ -1560,7 +1561,7 @@ bool Configuration::impl::validate ()
&& (ptt_port.isEmpty () && (ptt_port.isEmpty ()
|| combo_box_item_disabled == ui_->PTT_port_combo_box->itemData (ui_->PTT_port_combo_box->findText (ptt_port), Qt::UserRole - 1))) || combo_box_item_disabled == ui_->PTT_port_combo_box->itemData (ui_->PTT_port_combo_box->findText (ptt_port), Qt::UserRole - 1)))
{ {
message_box (tr ("Invalid PTT port")); MessageBox::critical_message (this, tr ("Invalid PTT port"));
return false; return false;
} }
@ -1858,20 +1859,6 @@ void Configuration::impl::reject ()
QDialog::reject (); QDialog::reject ();
} }
void Configuration::impl::message_box (QString const& reason, QString const& detail)
{
QMessageBox mb;
mb.setText (reason);
if (!detail.isEmpty ())
{
mb.setDetailedText (detail);
}
mb.setStandardButtons (QMessageBox::Ok);
mb.setDefaultButton (QMessageBox::Ok);
mb.setIcon (QMessageBox::Critical);
mb.exec ();
}
void Configuration::impl::on_font_push_button_clicked () void Configuration::impl::on_font_push_button_clicked ()
{ {
next_font_ = QFontDialog::getFont (0, next_font_, this); next_font_ = QFontDialog::getFont (0, next_font_, this);
@ -2120,10 +2107,10 @@ void Configuration::impl::delete_frequencies ()
void Configuration::impl::on_reset_frequencies_push_button_clicked (bool /* checked */) void Configuration::impl::on_reset_frequencies_push_button_clicked (bool /* checked */)
{ {
if (QMessageBox::Yes == QMessageBox::question (this, tr ("Reset Working Frequencies") if (MessageBox::Yes == MessageBox::query_message (this, tr ("Reset Working Frequencies")
, tr ("Are you sure you want to discard your current " , tr ("Are you sure you want to discard your current "
"working frequencies and replace them with default " "working frequencies and replace them with default "
"ones?"))) "ones?")))
{ {
next_frequencies_.reset_to_defaults (); next_frequencies_.reset_to_defaults ();
} }
@ -2197,7 +2184,8 @@ bool Configuration::impl::have_rig ()
{ {
if (!open_rig ()) if (!open_rig ())
{ {
QMessageBox::critical (this, "WSJT-X", tr ("Failed to open connection to rig")); MessageBox::critical_message (this, tr ("Rig control error")
, tr ("Failed to open connection to rig"));
} }
return rig_active_; return rig_active_;
} }
@ -2401,7 +2389,7 @@ void Configuration::impl::handle_transceiver_failure (QString const& reason)
if (isVisible ()) if (isVisible ())
{ {
message_box (tr ("Rig failure"), reason); MessageBox::critical_message (this, tr ("Rig failure"), reason);
} }
else else
{ {

View File

@ -3,11 +3,11 @@
#include <QApplication> #include <QApplication>
#include <QString> #include <QString>
#include <QPalette> #include <QPalette>
#include <QMessageBox>
#include <QFile> #include <QFile>
#include <QTextStream> #include <QTextStream>
#include "qt_helpers.hpp" #include "qt_helpers.hpp"
#include <MessageBox.hpp>
HelpTextWindow::HelpTextWindow (QString const& title, QString const& file_name, QFont const& font, QWidget * parent) HelpTextWindow::HelpTextWindow (QString const& title, QString const& file_name, QFont const& font, QWidget * parent)
: QLabel {parent, Qt::WindowCloseButtonHint | Qt::WindowMinimizeButtonHint} : QLabel {parent, Qt::WindowCloseButtonHint | Qt::WindowMinimizeButtonHint}
@ -15,9 +15,9 @@ HelpTextWindow::HelpTextWindow (QString const& title, QString const& file_name,
QFile source {file_name}; QFile source {file_name};
if (!source.open (QIODevice::ReadOnly | QIODevice::Text)) if (!source.open (QIODevice::ReadOnly | QIODevice::Text))
{ {
QMessageBox::warning (this, QApplication::applicationName () MessageBox::warning_message (this, tr ("Help file error")
, "Cannot open \"" + source.fileName () , tr ("Cannot open \"%1\" for reading").arg (source.fileName ())
+ "\" for reading:" + source.errorString ()); , tr ("Error: %1").arg (source.errorString ()));
return; return;
} }
setText (QTextStream {&source}.readAll ()); setText (QTextStream {&source}.readAll ());

101
MessageBox.cpp Normal file
View File

@ -0,0 +1,101 @@
#include "MessageBox.hpp"
#include <QDialogButtonBox>
#include <QPushButton>
#include "revision_utils.hpp"
MessageBox::MessageBox (QWidget * parent)
: QMessageBox {parent}
{
setWindowTitle (program_title ());
}
MessageBox::MessageBox (Icon icon, QString const& text, StandardButtons buttons
, QWidget * parent, Qt::WindowFlags flags)
: QMessageBox {icon, program_title (), text, buttons, parent, flags}
{
}
void MessageBox::about_message (QWidget * parent, QString const& text)
{
QMessageBox::about (parent, program_title (), text);
}
void MessageBox::about_Qt_message (QWidget * parent)
{
QMessageBox::aboutQt (parent, program_title ());
}
namespace
{
QMessageBox::StandardButton show_it (QWidget *parent, MessageBox::Icon icon
, QString const& text
, QString const& informative
, QString const& detail
, MessageBox::StandardButtons buttons
, MessageBox::StandardButton default_button)
{
MessageBox mb {icon, text, MessageBox::NoButton, parent};
QDialogButtonBox * button_box = mb.findChild<QDialogButtonBox *> ();
Q_ASSERT (button_box);
uint mask = MessageBox::FirstButton;
while (mask <= MessageBox::LastButton) {
uint sb = buttons & mask;
mask <<= 1;
if (!sb)
continue;
QPushButton * button = mb.addButton (static_cast<MessageBox::StandardButton> (sb));
// Choose the first accept role as the default
if (mb.defaultButton ())
continue;
if ((default_button == MessageBox::NoButton
&& button_box->buttonRole (button) == QDialogButtonBox::AcceptRole)
|| (default_button != MessageBox::NoButton
&& sb == static_cast<uint> (default_button)))
mb.setDefaultButton (button);
}
mb.setInformativeText (informative);
mb.setDetailedText (detail);
if (mb.exec() == -1)
return MessageBox::Cancel;
return mb.standardButton (mb.clickedButton ());
}
}
auto MessageBox::information_message (QWidget * parent, QString const& text
, QString const& informative
, QString const& detail
, StandardButtons buttons
, StandardButton default_button) -> StandardButton
{
return show_it (parent, Information, text, informative, detail, buttons, default_button);
}
auto MessageBox::query_message (QWidget * parent, QString const& text
, QString const& informative
, QString const& detail
, StandardButtons buttons
, StandardButton default_button) -> StandardButton
{
return show_it (parent, Question, text, informative, detail, buttons, default_button);
}
auto MessageBox::warning_message (QWidget * parent, QString const& text
, QString const& informative
, QString const& detail
, StandardButtons buttons
, StandardButton default_button) -> StandardButton
{
return show_it (parent, Warning, text, informative, detail, buttons, default_button);
}
auto MessageBox::critical_message (QWidget * parent, QString const& text
, QString const& informative
, QString const& detail
, StandardButtons buttons
, StandardButton default_button) -> StandardButton
{
return show_it (parent, Critical, text, informative, detail, buttons, default_button);
}

58
MessageBox.hpp Normal file
View File

@ -0,0 +1,58 @@
#ifndef MESSAGE_BOX_HPP__
#define MESSAGE_BOX_HPP__
#include <QMessageBox>
// get rid of the nasty MS define
#ifdef MessageBox
#undef MessageBox
#endif
//
// MessageBox - wrap the Qt QMessageBox class to give a more platform
// neutral and functional interface
//
class MessageBox
: public QMessageBox
{
public:
explicit MessageBox (QWidget * parent = nullptr);
explicit MessageBox (Icon, QString const& text, StandardButtons = NoButton
, QWidget * parent = nullptr
, Qt::WindowFlags = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
static void about_message (QWidget * parent, QString const& text);
static void about_Qt_message (QWidget * parent);
static StandardButton information_message (QWidget * parent, QString const& text
, QString const& informative = QString {}
, QString const& detail = QString {}
, StandardButtons buttons = Ok
, StandardButton default_button = NoButton);
static StandardButton query_message (QWidget * parent, QString const& text
, QString const& informative = QString {}
, QString const& detail = QString {}
, StandardButtons buttons = Yes | No
, StandardButton default_button = NoButton);
static StandardButton warning_message (QWidget * parent, QString const& text
, QString const& informative = QString {}
, QString const& detail = QString {}
, StandardButtons buttons = Ok
, StandardButton default_button = NoButton);
static StandardButton critical_message (QWidget * parent, QString const& text
, QString const& informative = QString {}
, QString const& detail = QString {}
, StandardButtons buttons = Ok
, StandardButton default_button = NoButton);
private:
// hide the parent static functions so that users use our versions
// above that are correctly branded and have better platform
// independence
using QMessageBox::about;
using QMessageBox::aboutQt;
using QMessageBox::information;
using QMessageBox::question;
using QMessageBox::warning;
using QMessageBox::critical;
};
#endif

View File

@ -14,7 +14,6 @@
#include <QMenu> #include <QMenu>
#include <QAction> #include <QAction>
#include <QActionGroup> #include <QActionGroup>
#include <QMessageBox>
#include <QDialog> #include <QDialog>
#include <QLineEdit> #include <QLineEdit>
#include <QRegularExpression> #include <QRegularExpression>
@ -30,6 +29,8 @@
#include "SettingsGroup.hpp" #include "SettingsGroup.hpp"
#include "qt_helpers.hpp" #include "qt_helpers.hpp"
#include "SettingsGroup.hpp"
#include "MessageBox.hpp"
#include "pimpl_impl.hpp" #include "pimpl_impl.hpp"
@ -551,11 +552,11 @@ void MultiSettings::impl::clone_into_configuration (QMainWindow * main_window)
if (sources.size () && (1 == sources.size () || QDialog::Accepted == dialog.exec ())) if (sources.size () && (1 == sources.size () || QDialog::Accepted == dialog.exec ()))
{ {
QString source_name {1 == sources.size () ? sources.at (0) : dialog.name ()}; QString source_name {1 == sources.size () ? sources.at (0) : dialog.name ()};
if (QMessageBox::Yes == QMessageBox::question (main_window, if (MessageBox::Yes == MessageBox::query_message (main_window,
tr ("Clone Into Configuration"), tr ("Clone Into Configuration"),
tr ("Confirm overwrite of all values for configuration \"%1\" with values from \"%2\"?") tr ("Confirm overwrite of all values for configuration \"%1\" with values from \"%2\"?")
.arg (target_name) .arg (target_name)
.arg (source_name))) .arg (source_name)))
{ {
// grab the data to clone from // grab the data to clone from
if (source_name == current_group_name) if (source_name == current_group_name)
@ -597,10 +598,10 @@ void MultiSettings::impl::reset_configuration (QMainWindow * main_window)
{ {
auto const& target_name = active_sub_menu_->title (); auto const& target_name = active_sub_menu_->title ();
if (QMessageBox::Yes != QMessageBox::question (main_window, if (MessageBox::Yes != MessageBox::query_message (main_window,
tr ("Reset Configuration"), tr ("Reset Configuration"),
tr ("Confirm reset to default values for configuration \"%1\"?") tr ("Confirm reset to default values for configuration \"%1\"?")
.arg (target_name))) .arg (target_name)))
{ {
return; return;
} }
@ -680,10 +681,10 @@ void MultiSettings::impl::delete_configuration (QMainWindow * main_window)
} }
else else
{ {
if (QMessageBox::Yes != QMessageBox::question (main_window, if (MessageBox::Yes != MessageBox::query_message (main_window,
tr ("Delete Configuration"), tr ("Delete Configuration"),
tr ("Confirm deletion of configuration \"%1\"?") tr ("Confirm deletion of configuration \"%1\"?")
.arg (target_name))) .arg (target_name)))
{ {
return; return;
} }

View File

@ -4,10 +4,10 @@
#include <QSettings> #include <QSettings>
#include <QtWidgets> #include <QtWidgets>
#include "pimpl_impl.hpp"
#include "SettingsGroup.hpp" #include "SettingsGroup.hpp"
#include "SampleDownloader/Directory.hpp" #include "SampleDownloader/Directory.hpp"
#include "MessageBox.hpp"
#include "pimpl_impl.hpp"
#include "moc_SampleDownloader.cpp" #include "moc_SampleDownloader.cpp"
@ -124,7 +124,7 @@ SampleDownloader::impl::impl (QSettings * settings
} }
else else
{ {
QMessageBox::warning (this, "Input Error", "Invalid URL format"); MessageBox::warning_message (this, tr ("Input Error"), tr ("Invalid URL format"));
} }
}); });
} }

View File

@ -11,7 +11,6 @@
#include <QNetworkReply> #include <QNetworkReply>
#include <QTreeWidgetItem> #include <QTreeWidgetItem>
#include <QTreeWidgetItemIterator> #include <QTreeWidgetItemIterator>
#include <QMessageBox>
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonParseError> #include <QJsonParseError>
#include <QJsonArray> #include <QJsonArray>
@ -22,6 +21,7 @@
#include "DirectoryNode.hpp" #include "DirectoryNode.hpp"
#include "FileNode.hpp" #include "FileNode.hpp"
#include "revision_utils.hpp" #include "revision_utils.hpp"
#include "MessageBox.hpp"
#include "moc_Directory.cpp" #include "moc_Directory.cpp"
@ -89,7 +89,7 @@ bool Directory::url_root (QUrl root)
void Directory::error (QString const& title, QString const& message) void Directory::error (QString const& title, QString const& message)
{ {
QMessageBox::warning (this, title, message); MessageBox::warning_message (this, title, message);
} }
bool Directory::refresh () bool Directory::refresh ()
@ -107,10 +107,10 @@ bool Directory::refresh ()
} }
else else
{ {
QMessageBox::warning (this MessageBox::warning_message (this
, tr ("URL Error") , tr ("URL Error")
, tr ("Invalid URL:\n\"%1\"") , tr ("Invalid URL:\n\"%1\"")
.arg (url.toDisplayString ())); .arg (url.toDisplayString ()));
} }
return false; return false;
} }
@ -126,16 +126,16 @@ void Directory::download_finished (bool success)
auto content = QJsonDocument::fromJson (contents.readAll (), &json_status); auto content = QJsonDocument::fromJson (contents.readAll (), &json_status);
if (json_status.error) if (json_status.error)
{ {
QMessageBox::warning (this MessageBox::warning_message (this
, tr ("JSON Error") , tr ("JSON Error")
, tr ("Contents file syntax error %1 at character offset %2") , tr ("Contents file syntax error %1 at character offset %2")
.arg (json_status.errorString ()).arg (json_status.offset)); .arg (json_status.errorString ()).arg (json_status.offset));
return; return;
} }
if (!content.isArray ()) if (!content.isArray ())
{ {
QMessageBox::warning (this, tr ("JSON Error") MessageBox::warning_message (this, tr ("JSON Error")
, tr ("Contents file top level must be a JSON array")); , tr ("Contents file top level must be a JSON array"));
return; return;
} }
QTreeWidgetItem * parent {invisibleRootItem ()}; QTreeWidgetItem * parent {invisibleRootItem ()};
@ -146,11 +146,11 @@ void Directory::download_finished (bool success)
} }
else else
{ {
QMessageBox::warning (this, tr ("File System Error") MessageBox::warning_message (this, tr ("File System Error")
, tr ("Failed to open \"%1\"\nError: %2 - %3") , tr ("Failed to open \"%1\"\nError: %2 - %3")
.arg (contents.fileName ()) .arg (contents.fileName ())
.arg (contents.error ()) .arg (contents.error ())
.arg (contents.errorString ())); .arg (contents.errorString ()));
} }
} }
} }
@ -183,10 +183,10 @@ void Directory::parse_entries (QJsonArray const& entries, QDir const& dir, QTree
} }
else else
{ {
QMessageBox::warning (this MessageBox::warning_message (this
, tr ("URL Error") , tr ("URL Error")
, tr ("Invalid URL:\n\"%1\"") , tr ("Invalid URL:\n\"%1\"")
.arg (url.toDisplayString ())); .arg (url.toDisplayString ()));
} }
} }
else if ("directory" == type) else if ("directory" == type)
@ -202,34 +202,34 @@ void Directory::parse_entries (QJsonArray const& entries, QDir const& dir, QTree
} }
else else
{ {
QMessageBox::warning (this, tr ("JSON Error") MessageBox::warning_message (this, tr ("JSON Error")
, tr ("Contents entries must be a JSON array")); , tr ("Contents entries must be a JSON array"));
} }
} }
else else
{ {
QMessageBox::warning (this, tr ("JSON Error") MessageBox::warning_message (this, tr ("JSON Error")
, tr ("Contents entries must have a valid type")); , tr ("Contents entries must have a valid type"));
} }
} }
else else
{ {
QMessageBox::warning (this, tr ("JSON Error") MessageBox::warning_message (this, tr ("JSON Error")
, tr ("Contents entries must have a valid name")); , tr ("Contents entries must have a valid name"));
} }
} }
else else
{ {
QMessageBox::warning (this, tr ("JSON Error") MessageBox::warning_message (this, tr ("JSON Error")
, tr ("Contents entries must be JSON objects")); , tr ("Contents entries must be JSON objects"));
} }
} }
} }
else else
{ {
QMessageBox::warning (this, tr ("JSON Error") MessageBox::warning_message (this, tr ("JSON Error")
, tr ("Contents directories must be relative and within \"%1\"") , tr ("Contents directories must be relative and within \"%1\"")
.arg (samples_dir_name)); .arg (samples_dir_name));
} }
} }
@ -295,5 +295,5 @@ void Directory::update (QTreeWidgetItem * item)
void Directory::authentication (QNetworkReply * /* reply */ void Directory::authentication (QNetworkReply * /* reply */
, QAuthenticator * /* authenticator */) , QAuthenticator * /* authenticator */)
{ {
QMessageBox::warning (this, "Network Error", "Authentication required"); MessageBox::warning_message (this, tr ("Network Error"), tr ("Authentication required"));
} }

View File

@ -4,9 +4,9 @@
#include <QUrl> #include <QUrl>
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>
#include <QMessageBox>
#include "Directory.hpp" #include "Directory.hpp"
#include "MessageBox.hpp"
FileNode::FileNode (QTreeWidgetItem * parent FileNode::FileNode (QTreeWidgetItem * parent
, QNetworkAccessManager * network_manager , QNetworkAccessManager * network_manager
@ -26,7 +26,7 @@ FileNode::FileNode (QTreeWidgetItem * parent
void FileNode::error (QString const& title, QString const& message) void FileNode::error (QString const& title, QString const& message)
{ {
QMessageBox::warning (treeWidget (), title, message); MessageBox::warning_message (treeWidget (), title, message);
} }
bool FileNode::sync (bool local) bool FileNode::sync (bool local)

View File

@ -81,7 +81,7 @@ MessageAggregatorMainWindow::MessageAggregatorMainWindow ()
// connect up server // connect up server
connect (server_, &MessageServer::error, [this] (QString const& message) { connect (server_, &MessageServer::error, [this] (QString const& message) {
QMessageBox::warning (this, tr ("Network Error"), message); QMessageBox::warning (this, QApplication::applicationName (), tr ("Network Error"), message);
}); });
connect (server_, &MessageServer::client_opened, this, &MessageAggregatorMainWindow::add_client); connect (server_, &MessageServer::client_opened, this, &MessageAggregatorMainWindow::add_client);
connect (server_, &MessageServer::client_closed, this, &MessageAggregatorMainWindow::remove_client); connect (server_, &MessageServer::client_closed, this, &MessageAggregatorMainWindow::remove_client);

View File

@ -5,7 +5,6 @@
#include <QApplication> #include <QApplication>
#include <QFile> #include <QFile>
#include <QTextStream> #include <QTextStream>
#include <QMessageBox>
#include <QSettings> #include <QSettings>
#include <QDateTime> #include <QDateTime>
#include <QStandardPaths> #include <QStandardPaths>
@ -13,6 +12,7 @@
#include <QDebug> #include <QDebug>
#include "commons.h" #include "commons.h"
#include "MessageBox.hpp"
#include "Configuration.hpp" #include "Configuration.hpp"
#include "SettingsGroup.hpp" #include "SettingsGroup.hpp"
#include "qt_helpers.hpp" #include "qt_helpers.hpp"
@ -214,8 +214,9 @@ void Astro::check_split ()
{ {
if (doppler_tracking () && !configuration_->split_mode ()) if (doppler_tracking () && !configuration_->split_mode ())
{ {
QMessageBox::warning (this, "Doppler Tracking", MessageBox::warning_message (this, tr ("Doppler Tracking Error"),
"Split operating is required for Doppler tracking"); tr ("Split operating is required for Doppler tracking"),
tr ("Go to \"Menu->File->Settings->Radio\" to enable split operation"));
ui_->rbNoDoppler->click (); ui_->rbNoDoppler->click ();
} }
} }

View File

@ -7,9 +7,9 @@
#include <QDebug> #include <QDebug>
#include "logbook/adif.h" #include "logbook/adif.h"
#include "MessageBox.hpp"
#include "ui_logqso.h" #include "ui_logqso.h"
#include "moc_logqso.cpp" #include "moc_logqso.cpp"
LogQSO::LogQSO(QString const& programTitle, QSettings * settings, QWidget *parent) LogQSO::LogQSO(QString const& programTitle, QSettings * settings, QWidget *parent)
@ -112,17 +112,16 @@ void LogQSO::accept()
adifile.init(adifilePath); adifile.init(adifilePath);
if (!adifile.addQSOToFile(hisCall,hisGrid,mode,rptSent,rptRcvd,date,time,band,comments,name,strDialFreq,m_myCall,m_myGrid,m_txPower)) if (!adifile.addQSOToFile(hisCall,hisGrid,mode,rptSent,rptRcvd,date,time,band,comments,name,strDialFreq,m_myCall,m_myGrid,m_txPower))
{ {
QMessageBox m; MessageBox::warning_message (this, tr ("Log file error"),
m.setText("Cannot open file \"" + adifilePath + "\"."); tr ("Cannot open \"%1\"").arg (adifilePath));
m.exec();
} }
//Log this QSO to file "wsjtx.log" //Log this QSO to file "wsjtx.log"
static QFile f {QDir {QStandardPaths::writableLocation (QStandardPaths::DataLocation)}.absoluteFilePath ("wsjtx.log")}; static QFile f {QDir {QStandardPaths::writableLocation (QStandardPaths::DataLocation)}.absoluteFilePath ("wsjtx.log")};
if(!f.open(QIODevice::Text | QIODevice::Append)) { if(!f.open(QIODevice::Text | QIODevice::Append)) {
QMessageBox m; MessageBox::warning_message (this, tr ("Log file error"),
m.setText("Cannot open file \"" + f.fileName () + "\" for append:" + f.errorString ()); tr ("Cannot open \"%1\" for append").arg (f.fileName ()),
m.exec(); tr ("Error: %1").arg (f.errorString ()));
} else { } else {
QString logEntry=m_dateTime.date().toString("yyyy-MMM-dd,") + QString logEntry=m_dateTime.date().toString("yyyy-MMM-dd,") +
m_dateTime.time().toString("hh:mm,") + hisCall + "," + m_dateTime.time().toString("hh:mm,") + hisCall + "," +

View File

@ -17,7 +17,6 @@
#include <QDir> #include <QDir>
#include <QStandardPaths> #include <QStandardPaths>
#include <QStringList> #include <QStringList>
#include <QMessageBox>
#include <QLockFile> #include <QLockFile>
#include <QStack> #include <QStack>
@ -36,6 +35,7 @@
#include "lib/init_random_seed.h" #include "lib/init_random_seed.h"
#include "Radio.hpp" #include "Radio.hpp"
#include "FrequencyList.hpp" #include "FrequencyList.hpp"
#include "MessageBox.hpp" // last to avoid nasty MS macro definitions
extern "C" { extern "C" {
// Fortran procedures we need // Fortran procedures we need
@ -127,19 +127,19 @@ int main(int argc, char *argv[])
if (!parser.parse (a.arguments ())) if (!parser.parse (a.arguments ()))
{ {
QMessageBox::critical (nullptr, a.applicationName (), parser.errorText ()); MessageBox::critical_message (nullptr, a.translate ("main", "Command line error"), parser.errorText ());
return -1; return -1;
} }
else else
{ {
if (parser.isSet (help_option)) if (parser.isSet (help_option))
{ {
QMessageBox::information (nullptr, a.applicationName (), parser.helpText ()); MessageBox::information_message (nullptr, a.translate ("main", "Command line help"), parser.helpText ());
return 0; return 0;
} }
else if (parser.isSet (version_option)) else if (parser.isSet (version_option))
{ {
QMessageBox::information (nullptr, a.applicationName (), a.applicationVersion ()); MessageBox::information_message (nullptr, a.translate ("main", "Application version"), a.applicationVersion ());
return 0; return 0;
} }
} }
@ -181,18 +181,19 @@ int main(int argc, char *argv[])
{ {
if (QLockFile::LockFailedError == instance_lock.error ()) if (QLockFile::LockFailedError == instance_lock.error ())
{ {
auto button = QMessageBox::question (nullptr auto button = MessageBox::query_message (nullptr
, QApplication::applicationName () , a.translate ("main", "Another instance may be running")
, QObject::tr ("Another instance may be running, try to remove stale lock file?") , a.translate ("main", "try to remove stale lock file?")
, QMessageBox::Yes | QMessageBox::Retry | QMessageBox::No , QString {}
, QMessageBox::Yes); , MessageBox::Yes | MessageBox::Retry | MessageBox::No
, MessageBox::Yes);
switch (button) switch (button)
{ {
case QMessageBox::Yes: case MessageBox::Yes:
instance_lock.removeStaleLockFile (); instance_lock.removeStaleLockFile ();
break; break;
case QMessageBox::Retry: case MessageBox::Retry:
break; break;
default: default:
@ -216,18 +217,19 @@ int main(int argc, char *argv[])
if (!temp_dir.mkpath (unique_directory) if (!temp_dir.mkpath (unique_directory)
|| !temp_dir.cd (unique_directory)) || !temp_dir.cd (unique_directory))
{ {
QMessageBox::critical (nullptr, MessageBox::critical_message (nullptr,
"WSJT-X", a.translate ("main", "Failed to create a temporary directory"),
QObject::tr ("Create temporary directory error: ") + temp_dir.absolutePath ()); a.translate ("main", "Path: \"%1\"").arg (temp_dir.absolutePath ()));
throw std::runtime_error {"Failed to create a temporary directory"}; throw std::runtime_error {"Failed to create a temporary directory"};
} }
if (!temp_dir.isReadable () || !(temp_ok = QTemporaryFile {temp_dir.absoluteFilePath ("test")}.open ())) if (!temp_dir.isReadable () || !(temp_ok = QTemporaryFile {temp_dir.absoluteFilePath ("test")}.open ()))
{ {
if (QMessageBox::Cancel == QMessageBox::critical (nullptr, auto button = MessageBox::critical_message (nullptr,
"WSJT-X", a.translate ("main", "Failed to create a usable temporary directory"),
QObject::tr ("Create temporary directory error:\n%1\n" a.translate ("main", "Another application may be locking the directory"),
"Another application may be locking the directory").arg (temp_dir.absolutePath ()), a.translate ("main", "Path: \"%1\"").arg (temp_dir.absolutePath ()),
QMessageBox::Retry | QMessageBox::Cancel)) MessageBox::Retry | MessageBox::Cancel);
if (MessageBox::Cancel == button)
{ {
throw std::runtime_error {"Failed to create a usable temporary directory"}; throw std::runtime_error {"Failed to create a usable temporary directory"};
} }
@ -270,8 +272,9 @@ int main(int argc, char *argv[])
if(!mem_jt9.attach()) { if(!mem_jt9.attach()) {
if (!mem_jt9.create(sizeof(struct dec_data))) { if (!mem_jt9.create(sizeof(struct dec_data))) {
QMessageBox::critical (nullptr, "Error", "Unable to create shared memory segment."); MessageBox::critical_message (nullptr, a.translate ("main", "Shared memory error"),
exit(1); a.translate ("main", "Unable to create shared memory segment"));
throw std::runtime_error {"Shared memory error"};
} }
} }
memset(mem_jt9.data(),0,sizeof(struct dec_data)); //Zero all decoding params in shared memory memset(mem_jt9.data(),0,sizeof(struct dec_data)); //Zero all decoding params in shared memory
@ -319,13 +322,13 @@ int main(int argc, char *argv[])
} }
catch (std::exception const& e) catch (std::exception const& e)
{ {
QMessageBox::critical (nullptr, a.applicationName (), e.what ()); MessageBox::critical_message (nullptr, a.translate ("main", "Fatal error"), e.what ());
std::cerr << "Error: " << e.what () << '\n'; std::cerr << "Error: " << e.what () << '\n';
} }
catch (...) catch (...)
{ {
QMessageBox::critical (nullptr, a.applicationName (), QObject::tr ("Unexpected error")); MessageBox::critical_message (nullptr, a.translate ("main", "Unexpected fatal error"));
std::cerr << "Unexpected error\n"; std::cerr << "Unexpected fatal error\n";
throw; // hoping the runtime might tell us more about the exception throw; // hoping the runtime might tell us more about the exception
} }
return -1; return -1;

View File

@ -168,6 +168,8 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple,
m_config {temp_directory, m_settings, this}, m_config {temp_directory, m_settings, this},
m_WSPR_band_hopping {m_settings, &m_config, this}, m_WSPR_band_hopping {m_settings, &m_config, this},
m_WSPR_tx_next {false}, m_WSPR_tx_next {false},
m_rigErrorMessageBox {MessageBox::Critical, tr ("Rig Control Error")
, MessageBox::Cancel | MessageBox::Ok | MessageBox::Retry},
m_wideGraph (new WideGraph(m_settings)), m_wideGraph (new WideGraph(m_settings)),
m_echoGraph (new EchoGraph(m_settings)), m_echoGraph (new EchoGraph(m_settings)),
m_fastGraph (new FastGraph(m_settings)), m_fastGraph (new FastGraph(m_settings)),
@ -346,9 +348,7 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple,
// parts of the rig error message box that are fixed // parts of the rig error message box that are fixed
m_rigErrorMessageBox.setInformativeText (tr ("Do you want to reconfigure the radio interface?")); m_rigErrorMessageBox.setInformativeText (tr ("Do you want to reconfigure the radio interface?"));
m_rigErrorMessageBox.setStandardButtons (QMessageBox::Cancel | QMessageBox::Ok | QMessageBox::Retry); m_rigErrorMessageBox.setDefaultButton (MessageBox::Ok);
m_rigErrorMessageBox.setDefaultButton (QMessageBox::Ok);
m_rigErrorMessageBox.setIcon (QMessageBox::Critical);
// start audio thread and hook up slots & signals for shutdown management // start audio thread and hook up slots & signals for shutdown management
// these objects need to be in the audio thread so that invoking // these objects need to be in the audio thread so that invoking
@ -544,7 +544,7 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple,
auto const& result = m_saveWAVWatcher.future ().result (); auto const& result = m_saveWAVWatcher.future ().result ();
if (!result.isEmpty ()) // error if (!result.isEmpty ()) // error
{ {
QMessageBox::critical (this, tr("Error writing WAV file"), result); MessageBox::critical_message (this, tr("Error Writing WAV File"), result);
} }
}); });
@ -665,8 +665,10 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple,
{ {
int iret=killbyname("jt9.exe"); int iret=killbyname("jt9.exe");
if(iret == 603) break; if(iret == 603) break;
if(iret != 0) msgBox("KillByName return code: " + if(iret != 0)
QString::number(iret)); MessageBox::warning_message (this, tr ("Error Killing jt9.exe Process")
, tr ("KillByName return code: %1")
.arg (iret));
} }
} }
#endif #endif
@ -682,8 +684,8 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple,
{ {
if (!quitFile.remove ()) if (!quitFile.remove ())
{ {
msgBox ("Error removing \"" + quitFile.fileName () + MessageBox::query_message (this, tr ("Error removing \"%1\"").arg (quitFile.fileName ())
"\" - OK to retry."); , tr ("Click OK to retry"));
} }
} }
} }
@ -1288,10 +1290,10 @@ void MainWindow::fastSink(qint64 frames)
} }
void MainWindow::showSoundInError(const QString& errorMsg) void MainWindow::showSoundInError(const QString& errorMsg)
{QMessageBox::critical(this, tr("Error in SoundInput"), errorMsg);} {MessageBox::critical_message (this, tr ("Error in Sound Input"), errorMsg);}
void MainWindow::showSoundOutError(const QString& errorMsg) void MainWindow::showSoundOutError(const QString& errorMsg)
{QMessageBox::critical(this, tr("Error in SoundOutput"), errorMsg);} {MessageBox::critical_message (this, tr ("Error in Sound Output"), errorMsg);}
void MainWindow::showStatusMessage(const QString& statusMsg) void MainWindow::showStatusMessage(const QString& statusMsg)
{statusBar()->showMessage(statusMsg);} {statusBar()->showMessage(statusMsg);}
@ -1589,7 +1591,9 @@ void MainWindow::statusChanged()
<< ui->rptSpinBox->value() << ";" << m_modeTx << endl; << ui->rptSpinBox->value() << ";" << m_modeTx << endl;
f.close(); f.close();
} else { } else {
msgBox (tr ("Cannot open \"%1\" for writing: %2").arg (f.fileName ()).arg (f.errorString ())); MessageBox::warning_message (this, tr ("Status File Error")
, tr ("Cannot open \"%1\" for writing: %2")
.arg (f.fileName ()).arg (f.errorString ()));
} }
} }
@ -1729,10 +1733,12 @@ void MainWindow::subProcessFailed (QProcess * process, int exit_code, QProcess::
if (argument.contains (' ')) argument = '"' + argument + '"'; if (argument.contains (' ')) argument = '"' + argument + '"';
arguments << argument; arguments << argument;
} }
msgBox (tr ("Subprocess failed with exit code %1\nRunning:%2\n%3") MessageBox::critical_message (this, tr ("Subprocess Error")
.arg (exit_code) , tr ("Subprocess failed with exit code %1")
.arg (process->program () + ' ' + arguments.join (' ')) .arg (exit_code)
.arg (QString {process->readAllStandardError()})); , tr ("Running: %1\n%2")
.arg (process->program () + ' ' + arguments.join (' '))
.arg (QString {process->readAllStandardError()}));
QTimer::singleShot (0, this, SLOT (close ())); QTimer::singleShot (0, this, SLOT (close ()));
m_valid = false; // ensures exit if still constructing m_valid = false; // ensures exit if still constructing
} }
@ -1748,9 +1754,10 @@ void MainWindow::subProcessError (QProcess * process, QProcess::ProcessError)
if (argument.contains (' ')) argument = '"' + argument + '"'; if (argument.contains (' ')) argument = '"' + argument + '"';
arguments << argument; arguments << argument;
} }
msgBox (tr ("Subprocess error\nRunning: %1\n%2") MessageBox::critical_message (this, tr ("Subprocess error")
.arg (process->program () + ' ' + arguments.join (' ')) , tr ("Running: %1\n%2")
.arg (process->errorString ())); .arg (process->program () + ' ' + arguments.join (' '))
.arg (process->errorString ()));
QTimer::singleShot (0, this, SLOT (close ())); QTimer::singleShot (0, this, SLOT (close ()));
m_valid = false; // ensures exit if still constructing m_valid = false; // ensures exit if still constructing
} }
@ -1785,18 +1792,11 @@ void MainWindow::on_stopButton_clicked() //stopButton
monitor (false); monitor (false);
m_loopall=false; m_loopall=false;
if(m_bRefSpec) { if(m_bRefSpec) {
// msgBox("Reference spectrum saved."); // MessageBox::information_message (this, tr ("Reference spectrum saved"));
m_bRefSpec=false; m_bRefSpec=false;
} }
} }
void MainWindow::msgBox (QString const& text)
{
msgBox0.setText (text);
QApplication::alert (this);
msgBox0.exec ();
}
void MainWindow::on_actionOnline_User_Guide_triggered() //Display manual void MainWindow::on_actionOnline_User_Guide_triggered() //Display manual
{ {
#if defined (CMAKE_BUILD) #if defined (CMAKE_BUILD)
@ -1979,10 +1979,10 @@ void MainWindow::diskDat() //diskDat()
//Delete ../save/*.wav //Delete ../save/*.wav
void MainWindow::on_actionDelete_all_wav_files_in_SaveDir_triggered() void MainWindow::on_actionDelete_all_wav_files_in_SaveDir_triggered()
{ {
if (QMessageBox::Yes == QMessageBox::warning(this, "Confirm Delete", auto button = MessageBox::query_message (this, tr ("Confirm Delete"),
"Are you sure you want to delete all *.wav and *.c2 files in\n" + tr ("Are you sure you want to delete all *.wav and *.c2 files in \"%1\"?")
QDir::toNativeSeparators(m_config.save_directory ().absolutePath ()) + " ?", .arg (QDir::toNativeSeparators (m_config.save_directory ().absolutePath ())));
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes)) { if (MessageBox::Yes == button) {
Q_FOREACH (auto const& file Q_FOREACH (auto const& file
, m_config.save_directory ().entryList ({"*.wav", "*.c2"}, QDir::Files | QDir::Writable)) { , m_config.save_directory ().entryList ({"*.wav", "*.c2"}, QDir::Files | QDir::Writable)) {
m_config.save_directory ().remove (file); m_config.save_directory ().remove (file);
@ -2255,7 +2255,9 @@ void::MainWindow::fast_decode_done()
out << message.mid(0,n-2) << endl; out << message.mid(0,n-2) << endl;
f.close(); f.close();
} else { } else {
msgBox (tr ("Cannot open \"%1\" for append: %2").arg (f.fileName ()).arg (f.errorString ())); MessageBox::warning_message (this, tr ("File Open Error")
, tr ("Cannot open \"%1\" for append: %2")
.arg (f.fileName ()).arg (f.errorString ()));
} }
if(m_mode=="JT9" or m_mode=="JTMSK" or m_mode=="MSK144") { if(m_mode=="JT9" or m_mode=="JTMSK" or m_mode=="MSK144") {
@ -2342,7 +2344,9 @@ void MainWindow::readFromStdout() //readFromStdout
out << t.mid(0,n-2) << endl; out << t.mid(0,n-2) << endl;
f.close(); f.close();
} else { } else {
msgBox (tr ("Cannot open \"%1\" for append: %2").arg (f.fileName ()).arg (f.errorString ())); MessageBox::warning_message (this, tr ("File Open Error")
, tr ("Cannot open \"%1\" for append: %2")
.arg (f.fileName ()).arg (f.errorString ()));
} }
if (m_config.insert_blank () && m_blankLine) if (m_config.insert_blank () && m_blankLine)
@ -2591,13 +2595,15 @@ void MainWindow::guiUpdate()
if (m_auto) auto_tx_mode (false); if (m_auto) auto_tx_mode (false);
if(onAirFreq!=m_onAirFreq0) { if(onAirFreq!=m_onAirFreq0) {
m_onAirFreq0=onAirFreq; m_onAirFreq0=onAirFreq;
auto const& message = tr ("Please choose another Tx frequency.\n" auto const& message = tr ("Please choose another Tx frequency."
"WSJT-X will not knowingly transmit another\n" " WSJT-X will not knowingly transmit another"
"mode in the WSPR sub-band on 30 m."); " mode in the WSPR sub-band on 30m.");
#if QT_VERSION >= 0x050400 #if QT_VERSION >= 0x050400
QTimer::singleShot (0, [=] {msgBox (message);}); // don't block guiUpdate QTimer::singleShot (0, [=] { // don't block guiUpdate
MessageBox::warning_message (this, tr ("WSPR Guard Band"), message);
});
#else #else
msgBox (message); MessageBox::warning_message (this, tr ("WSPR Guard Band"), message);
#endif #endif
} }
} }
@ -2745,9 +2751,11 @@ void MainWindow::guiUpdate()
auto const& message = tr ("Cannot open \"%1\" for append: %2") auto const& message = tr ("Cannot open \"%1\" for append: %2")
.arg (f.fileName ()).arg (f.errorString ()); .arg (f.fileName ()).arg (f.errorString ());
#if QT_VERSION >= 0x050400 #if QT_VERSION >= 0x050400
QTimer::singleShot (0, [=] {msgBox (message);}); // don't block guiUpdate QTimer::singleShot (0, [=] { // don't block guiUpdate
MessageBox::warning_message (this, tr ("Log File Error"), message);
});
#else #else
msgBox (message); MessageBox::warning_message (this, tr ("Log File Error"), message);
#endif #endif
} }
if (m_config.TX_messages ()) if (m_config.TX_messages ())
@ -2849,9 +2857,11 @@ void MainWindow::guiUpdate()
auto const& message = tr ("Cannot open \"%1\" for append: %2") auto const& message = tr ("Cannot open \"%1\" for append: %2")
.arg (f.fileName ()).arg(f.errorString ()); .arg (f.fileName ()).arg(f.errorString ());
#if QT_VERSION >= 0x050400 #if QT_VERSION >= 0x050400
QTimer::singleShot (0, [=] {msgBox (message);}); // don't block guiUpdate QTimer::singleShot (0, [=] { // don't block guiUpdate
MessageBox::warning_message (this, tr ("Log File Error"), message);
});
#else #else
msgBox (message); MessageBox::warning_message (this, tr ("Log File Error"), message);
#endif #endif
} }
} }
@ -2971,8 +2981,9 @@ void MainWindow::startTx2()
<< m_currentMessage << " " + m_mode << endl; << m_currentMessage << " " + m_mode << endl;
f.close(); f.close();
} else { } else {
msgBox (tr ("Cannot open \"%1\" for append: %2") MessageBox::warning_message (this, tr ("Log File Error"),
.arg (f.fileName ()).arg (f.errorString ())); tr ("Cannot open \"%1\" for append: %2")
.arg (f.fileName ()).arg (f.errorString ()));
} }
} }
} }
@ -3095,7 +3106,10 @@ void MainWindow::doubleClickOnCall(bool shift, bool ctrl)
{ {
QTextCursor cursor; QTextCursor cursor;
QString t; //Full contents QString t; //Full contents
if(m_mode=="ISCAT") msgBox("Double-click not presently implemented for ISCAT mode"); if(m_mode=="ISCAT") {
MessageBox::information_message (this,
"Double-click not presently implemented for ISCAT mode");
}
if(shift) t=""; //Silence compiler warning if(shift) t=""; //Silence compiler warning
if(m_decodedText2) { if(m_decodedText2) {
cursor=ui->decodedTextBrowser->textCursor(); cursor=ui->decodedTextBrowser->textCursor();
@ -3574,7 +3588,8 @@ void MainWindow::on_lookupButton_clicked() //Lookup button
void MainWindow::on_addButton_clicked() //Add button void MainWindow::on_addButton_clicked() //Add button
{ {
if(ui->dxGridEntry->text()=="") { if(ui->dxGridEntry->text()=="") {
msgBox("Please enter a valid grid locator."); MessageBox::warning_message (this, tr ("Add to CALL3.TXT")
, tr ("Please enter a valid grid locator"));
return; return;
} }
m_call3Modified=false; m_call3Modified=false;
@ -3582,10 +3597,9 @@ void MainWindow::on_addButton_clicked() //Add button
QString hisgrid=ui->dxGridEntry->text().trimmed(); QString hisgrid=ui->dxGridEntry->text().trimmed();
QString newEntry=hisCall + "," + hisgrid; QString newEntry=hisCall + "," + hisgrid;
// int ret = QMessageBox::warning(this, "Add", // int ret = MessageBox::query_message(this, tr ("Add to CALL3.TXT"),
// newEntry + "\n" + "Is this station known to be active on EME?", // tr ("Is %1 known to be active on EME?").arg (newEntry));
// QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); // if(ret==MessageBox::Yes) {
// if(ret==QMessageBox::Yes) {
// newEntry += ",EME,,"; // newEntry += ",EME,,";
// } else { // } else {
newEntry += ",,,"; newEntry += ",,,";
@ -3593,7 +3607,9 @@ void MainWindow::on_addButton_clicked() //Add button
QFile f1 {m_dataDir.absoluteFilePath ("CALL3.TXT")}; QFile f1 {m_dataDir.absoluteFilePath ("CALL3.TXT")};
if(!f1.open(QIODevice::ReadWrite | QIODevice::Text)) { if(!f1.open(QIODevice::ReadWrite | QIODevice::Text)) {
msgBox("Cannot open \"" + f1.fileName () + "\" for read/write:" + f1.errorString ()); MessageBox::warning_message (this, tr ("Add to CALL3.TXT")
, tr ("Cannot open \"%1\" for read/write: %2")
.arg (f1.fileName ()).arg (f1.errorString ()));
return; return;
} }
if(f1.size()==0) { if(f1.size()==0) {
@ -3604,7 +3620,9 @@ void MainWindow::on_addButton_clicked() //Add button
} }
QFile f2 {m_dataDir.absoluteFilePath ("CALL3.TMP")}; QFile f2 {m_dataDir.absoluteFilePath ("CALL3.TMP")};
if(!f2.open(QIODevice::WriteOnly | QIODevice::Text)) { if(!f2.open(QIODevice::WriteOnly | QIODevice::Text)) {
msgBox("Cannot open \"" + f2.fileName () + "\" for writing:" + f2.errorString ()); MessageBox::warning_message (this, tr ("Add to CALL3.TXT")
, tr ("Cannot open \"%1\" for writing: %2")
.arg (f2.fileName ()).arg (f2.errorString ()));
return; return;
} }
QTextStream in(&f1); //Read from CALL3.TXT QTextStream in(&f1); //Read from CALL3.TXT
@ -3626,11 +3644,10 @@ void MainWindow::on_addButton_clicked() //Add button
out << s + "\n"; out << s + "\n";
m_call3Modified=true; m_call3Modified=true;
} else if(hc==hc2) { } else if(hc==hc2) {
QString t=s + "\n\n is already in CALL3.TXT\n" + QString t {tr ("%1\nis already in CALL3.TXT"
"Do you wish to replace it?"; ", do you wish to replace it?").arg (s)};
int ret = QMessageBox::warning(this, "Add",t, int ret = MessageBox::query_message (this, tr ("Add to CALL3.TXT"), t);
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); if(ret==MessageBox::Yes) {
if(ret==QMessageBox::Yes) {
out << newEntry + "\n"; out << newEntry + "\n";
m_call3Modified=true; m_call3Modified=true;
} }
@ -4112,7 +4129,7 @@ void MainWindow::on_actionWSPR_2_triggered()
void MainWindow::on_actionWSPR_15_triggered() void MainWindow::on_actionWSPR_15_triggered()
{ {
msgBox("WSPR-15 is not yet available"); MessageBox::information_message (this, tr ("WSPR-15 is not yet available"));
switch_mode (Modes::WSPR); switch_mode (Modes::WSPR);
} }
@ -4315,10 +4332,9 @@ void MainWindow::on_inGain_valueChanged(int n)
void MainWindow::on_actionErase_ALL_TXT_triggered() //Erase ALL.TXT void MainWindow::on_actionErase_ALL_TXT_triggered() //Erase ALL.TXT
{ {
int ret = QMessageBox::warning(this, "Confirm Erase", int ret = MessageBox::query_message (this, tr ("Confirm Erase"),
"Are you sure you want to erase file ALL.TXT ?", tr ("Are you sure you want to erase file ALL.TXT?"));
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); if(ret==MessageBox::Yes) {
if(ret==QMessageBox::Yes) {
QFile f {m_dataDir.absoluteFilePath ("ALL.TXT")}; QFile f {m_dataDir.absoluteFilePath ("ALL.TXT")};
f.remove(); f.remove();
m_RxLog=1; m_RxLog=1;
@ -4327,10 +4343,9 @@ void MainWindow::on_actionErase_ALL_TXT_triggered() //Erase ALL.TXT
void MainWindow::on_actionErase_wsjtx_log_adi_triggered() void MainWindow::on_actionErase_wsjtx_log_adi_triggered()
{ {
int ret = QMessageBox::warning(this, "Confirm Erase", int ret = MessageBox::query_message (this, tr ("Confirm Erase"),
"Are you sure you want to erase file wsjtx_log.adi ?", tr ("Are you sure you want to erase file wsjtx_log.adi?"));
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); if(ret==MessageBox::Yes) {
if(ret==QMessageBox::Yes) {
QFile f {m_dataDir.absoluteFilePath ("wsjtx_log.adi")}; QFile f {m_dataDir.absoluteFilePath ("wsjtx_log.adi")};
f.remove(); f.remove();
} }
@ -4742,7 +4757,9 @@ void MainWindow::handle_transceiver_update (Transceiver::TransceiverState const&
<< m_mode << endl; << m_mode << endl;
f2.close(); f2.close();
} else { } else {
msgBox("Cannot open \"" + f2.fileName () + "\" for append:" + f2.errorString ()); MessageBox::warning_message (this, tr ("File Error")
,tr ("Cannot open \"%1\" for append: %2")
.arg (f2.fileName ()).arg (f2.errorString ()));
} }
} }
@ -4771,10 +4788,10 @@ void MainWindow::handle_transceiver_failure (QString const& reason)
update_dynamic_property (ui->readFreq, "state", "error"); update_dynamic_property (ui->readFreq, "state", "error");
ui->readFreq->setEnabled (true); ui->readFreq->setEnabled (true);
on_stopTxButton_clicked (); on_stopTxButton_clicked ();
rigFailure ("Rig Control Error", reason); rigFailure (reason);
} }
void MainWindow::rigFailure (QString const& reason, QString const& detail) void MainWindow::rigFailure (QString const& reason)
{ {
if (m_first_error) if (m_first_error)
{ {
@ -4784,21 +4801,20 @@ void MainWindow::rigFailure (QString const& reason, QString const& detail)
} }
else else
{ {
m_rigErrorMessageBox.setText (reason); m_rigErrorMessageBox.setDetailedText (reason);
m_rigErrorMessageBox.setDetailedText (detail);
// don't call slot functions directly to avoid recursion // don't call slot functions directly to avoid recursion
switch (m_rigErrorMessageBox.exec ()) switch (m_rigErrorMessageBox.exec ())
{ {
case QMessageBox::Ok: case MessageBox::Ok:
QTimer::singleShot (0, this, SLOT (on_actionSettings_triggered ())); QTimer::singleShot (0, this, SLOT (on_actionSettings_triggered ()));
break; break;
case QMessageBox::Retry: case MessageBox::Retry:
QTimer::singleShot (0, this, SLOT (rigOpen ())); QTimer::singleShot (0, this, SLOT (rigOpen ()));
break; break;
case QMessageBox::Cancel: case MessageBox::Cancel:
QTimer::singleShot (0, this, SLOT (close ())); QTimer::singleShot (0, this, SLOT (close ()));
break; break;
} }
@ -5287,12 +5303,14 @@ void MainWindow::postWSPRDecode (bool is_new, QStringList parts)
void MainWindow::networkError (QString const& e) void MainWindow::networkError (QString const& e)
{ {
if (QMessageBox::Retry == QMessageBox::warning (this, tr ("Network Error") if (MessageBox::Retry == MessageBox::warning_message (this, tr ("Network Error")
, tr ("Error: %1\nUDP server %2:%3") , tr ("Error: %1\nUDP server %2:%3")
.arg (e) .arg (e)
.arg (m_config.udp_server_name ()) .arg (m_config.udp_server_name ())
.arg (m_config.udp_server_port ()) .arg (m_config.udp_server_port ())
, QMessageBox::Cancel | QMessageBox::Retry, QMessageBox::Cancel)) , QString {}
, MessageBox::Cancel | MessageBox::Retry
, MessageBox::Cancel))
{ {
// retry server lookup // retry server lookup
m_messageClient->set_server (m_config.udp_server_name ()); m_messageClient->set_server (m_config.udp_server_name ());
@ -5428,7 +5446,9 @@ void MainWindow::WSPR_history(Frequency dialFreq, int ndecodes)
out << t1 << endl; out << t1 << endl;
f.close(); f.close();
} else { } else {
msgBox("Cannot open \"" + f.fileName () + "\" for append:" + f.errorString ()); MessageBox::warning_message (this, tr ("File Error")
, tr ("Cannot open \"%1\" for append: %2")
.arg (f.fileName ()).arg (f.errorString ()));
} }
} }

View File

@ -34,6 +34,7 @@
#include "decodedtext.h" #include "decodedtext.h"
#include "commons.h" #include "commons.h"
#include "astro.h" #include "astro.h"
#include "MessageBox.hpp"
#define NUM_JT4_SYMBOLS 206 //(72+31)*2, embedded sync #define NUM_JT4_SYMBOLS 206 //(72+31)*2, embedded sync
#define NUM_JT65_SYMBOLS 126 //63 data + 63 sync #define NUM_JT65_SYMBOLS 126 //63 data + 63 sync
@ -290,7 +291,7 @@ private:
Configuration m_config; Configuration m_config;
WSPRBandHopping m_WSPR_band_hopping; WSPRBandHopping m_WSPR_band_hopping;
bool m_WSPR_tx_next; bool m_WSPR_tx_next;
QMessageBox m_rigErrorMessageBox; MessageBox m_rigErrorMessageBox;
QScopedPointer<SampleDownloader> m_sampleDownloader; QScopedPointer<SampleDownloader> m_sampleDownloader;
QScopedPointer<WideGraph> m_wideGraph; QScopedPointer<WideGraph> m_wideGraph;
@ -434,8 +435,6 @@ private:
QLabel band_hopping_label; QLabel band_hopping_label;
QProgressBar progressBar; QProgressBar progressBar;
QMessageBox msgBox0;
QFuture<void> m_wav_future; QFuture<void> m_wav_future;
QFutureWatcher<void> m_wav_future_watcher; QFutureWatcher<void> m_wav_future_watcher;
QFutureWatcher<void> watcher3; QFutureWatcher<void> watcher3;
@ -514,7 +513,6 @@ private:
void writeSettings(); void writeSettings();
void createStatusBar(); void createStatusBar();
void updateStatusBar(); void updateStatusBar();
void msgBox(QString const&);
void genStdMsgs(QString rpt); void genStdMsgs(QString rpt);
void clearDX (); void clearDX ();
void lookup(); void lookup();
@ -525,7 +523,7 @@ private:
bool gridOK(QString g); bool gridOK(QString g);
bool shortList(QString callsign); bool shortList(QString callsign);
void transmit (double snr = 99.); void transmit (double snr = 99.);
void rigFailure (QString const& reason, QString const& detail); void rigFailure (QString const& reason);
void pskSetLocal (); void pskSetLocal ();
void displayDialFrequency (); void displayDialFrequency ();
void transmitDisplay (bool); void transmitDisplay (bool);

View File

@ -4,13 +4,13 @@
#include "ui_widegraph.h" #include "ui_widegraph.h"
#include "commons.h" #include "commons.h"
#include "Configuration.hpp" #include "Configuration.hpp"
#include "MessageBox.hpp"
#include "moc_widegraph.cpp" #include "moc_widegraph.cpp"
static float swide[MAX_SCREENSIZE];
namespace namespace
{ {
auto user_defined = QObject::tr ("User Defined"); auto user_defined = QObject::tr ("User Defined");
float swide[MAX_SCREENSIZE];
} }
WideGraph::WideGraph(QSettings * settings, QWidget *parent) : WideGraph::WideGraph(QSettings * settings, QWidget *parent) :
@ -367,9 +367,7 @@ void WideGraph::readPalette () //readPalette
} }
catch (std::exception const& e) catch (std::exception const& e)
{ {
QMessageBox msgBox0; MessageBox::warning_message (this, tr ("Read Palette"), e.what ());
msgBox0.setText(e.what());
msgBox0.exec();
} }
} }
@ -412,9 +410,7 @@ void WideGraph::on_adjust_palette_push_button_clicked (bool) //Adjust Palette
} }
catch (std::exception const& e) catch (std::exception const& e)
{ {
QMessageBox msgBox0; MessageBox::warning_message (this, tr ("Read Palette"), e.what ());
msgBox0.setText(e.what());
msgBox0.exec();
} }
} }

View File

@ -33,4 +33,13 @@
#define WSJTX_STRINGIZE1(x) #x #define WSJTX_STRINGIZE1(x) #x
#define WSJTX_STRINGIZE(x) WSJTX_STRINGIZE1(x) #define WSJTX_STRINGIZE(x) WSJTX_STRINGIZE1(x)
/* consistent UNICODE behaviour */
#ifndef UNICODE
# undef _UNICODE
#else
# ifndef _UNICODE
# define _UNICODE
# endif
#endif
#endif #endif