mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2025-07-12 14:45:18 -04:00
Do not try to open a missing Hamlib settings file
git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@6349 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
parent
da7fbe947b
commit
6595c329a8
@ -240,45 +240,49 @@ HamlibTransceiver::HamlibTransceiver (int model_number, TransceiverFactory::Para
|
|||||||
//
|
//
|
||||||
// user defined Hamlib settings
|
// user defined Hamlib settings
|
||||||
//
|
//
|
||||||
QFile settings_file {QStandardPaths::locate (
|
auto settings_file_name = QStandardPaths::locate (
|
||||||
#if QT_VERSION >= 0x050500
|
#if QT_VERSION >= 0x050500
|
||||||
QStandardPaths::AppConfigLocation
|
QStandardPaths::AppConfigLocation
|
||||||
#else
|
#else
|
||||||
QStandardPaths::ConfigLocation
|
QStandardPaths::ConfigLocation
|
||||||
#endif
|
#endif
|
||||||
, "hamlib_settings.json")};
|
, "hamlib_settings.json");
|
||||||
if (settings_file.open (QFile::ReadOnly))
|
if (!settings_file_name.isEmpty ())
|
||||||
{
|
{
|
||||||
QJsonParseError status;
|
QFile settings_file {settings_file_name};
|
||||||
auto settings_doc = QJsonDocument::fromJson (settings_file.readAll (), &status);
|
if (settings_file.open (QFile::ReadOnly))
|
||||||
if (status.error)
|
{
|
||||||
{
|
QJsonParseError status;
|
||||||
throw error {tr ("Hamlib settings file error: %1 at character offset %2")
|
auto settings_doc = QJsonDocument::fromJson (settings_file.readAll (), &status);
|
||||||
.arg (status.errorString ()).arg (status.offset)};
|
if (status.error)
|
||||||
}
|
{
|
||||||
if (!settings_doc.isObject ())
|
throw error {tr ("Hamlib settings file error: %1 at character offset %2")
|
||||||
{
|
.arg (status.errorString ()).arg (status.offset)};
|
||||||
throw error {tr ("Hamlib settings file error: top level must be a JSON object")};
|
}
|
||||||
}
|
if (!settings_doc.isObject ())
|
||||||
auto const& settings = settings_doc.object ();
|
{
|
||||||
|
throw error {tr ("Hamlib settings file error: top level must be a JSON object")};
|
||||||
|
}
|
||||||
|
auto const& settings = settings_doc.object ();
|
||||||
|
|
||||||
//
|
//
|
||||||
// configuration settings
|
// configuration settings
|
||||||
//
|
//
|
||||||
auto const& config = settings["config"];
|
auto const& config = settings["config"];
|
||||||
if (!config.isUndefined ())
|
if (!config.isUndefined ())
|
||||||
{
|
{
|
||||||
if (!config.isObject ())
|
if (!config.isObject ())
|
||||||
{
|
{
|
||||||
throw error {tr ("Hamlib settings file error: config must be a JSON object")};
|
throw error {tr ("Hamlib settings file error: config must be a JSON object")};
|
||||||
}
|
}
|
||||||
auto const& config_list = config.toObject ();
|
auto const& config_list = config.toObject ();
|
||||||
for (auto item = config_list.constBegin (); item != config_list.constEnd (); ++item)
|
for (auto item = config_list.constBegin (); item != config_list.constEnd (); ++item)
|
||||||
{
|
{
|
||||||
set_conf (item.key ().toLocal8Bit ().constData ()
|
set_conf (item.key ().toLocal8Bit ().constData ()
|
||||||
, (*item).toVariant ().toString ().toLocal8Bit ().constData ());
|
, (*item).toVariant ().toString ().toLocal8Bit ().constData ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user