mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2024-11-24 21:28:41 -05:00
Support for a startup configuration
The --config <configuration> (-c for short) command line option can be used to select an existing configuration at start up. If the configuration does not exist the last configuration used is selected. git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@7567 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
parent
75d371ebd9
commit
b4ea0194f1
@ -144,7 +144,7 @@ class MultiSettings::impl final
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit impl (MultiSettings const * parent);
|
||||
explicit impl (MultiSettings const * parent, QString const& config_name);
|
||||
bool reposition ();
|
||||
void create_menu_actions (QMainWindow * main_window, QMenu * menu);
|
||||
bool exit ();
|
||||
@ -201,8 +201,8 @@ private:
|
||||
#include "MultiSettings.moc"
|
||||
#include "moc_MultiSettings.cpp"
|
||||
|
||||
MultiSettings::MultiSettings ()
|
||||
: m_ {this}
|
||||
MultiSettings::MultiSettings (QString const& config_name)
|
||||
: m_ {this, config_name}
|
||||
{
|
||||
}
|
||||
|
||||
@ -263,7 +263,7 @@ bool MultiSettings::exit ()
|
||||
return m_->exit ();
|
||||
}
|
||||
|
||||
MultiSettings::impl::impl (MultiSettings const * parent)
|
||||
MultiSettings::impl::impl (MultiSettings const * parent, QString const& config_name)
|
||||
: settings_ {settings_path (), QSettings::IniFormat}
|
||||
, parent_ {parent}
|
||||
, name_change_emit_pending_ {true}
|
||||
@ -303,15 +303,33 @@ MultiSettings::impl::impl (MultiSettings const * parent)
|
||||
}
|
||||
|
||||
// bootstrap
|
||||
QStringList available_configurations;
|
||||
{
|
||||
SettingsGroup alternatives {&settings_, multi_settings_root_group};
|
||||
available_configurations = settings_.childGroups ();
|
||||
// use last selected configuration
|
||||
current_ = settings_.value (multi_settings_current_name_key).toString ();
|
||||
if (!current_.size ())
|
||||
{
|
||||
// no configurations so use default name
|
||||
current_ = tr (default_string);
|
||||
settings_.setValue (multi_settings_current_name_key, current_);
|
||||
}
|
||||
}
|
||||
|
||||
if (config_name.size () && available_configurations.contains (config_name) && config_name != current_)
|
||||
{
|
||||
// switch to specified configuration
|
||||
{
|
||||
SettingsGroup alternatives {&settings_, multi_settings_root_group};
|
||||
// save the target settings
|
||||
SettingsGroup target_group {&settings_, config_name};
|
||||
new_settings_ = get_settings ();
|
||||
}
|
||||
current_ = config_name;
|
||||
reposition_type_ = RepositionType::save_and_replace;
|
||||
reposition ();
|
||||
}
|
||||
settings_.sync ();
|
||||
}
|
||||
|
||||
@ -394,9 +412,8 @@ void MultiSettings::impl::create_menu_actions (QMainWindow * main_window, QMenu
|
||||
// and set as the current configuration
|
||||
default_menu->menuAction ()->setChecked (true);
|
||||
|
||||
QStringList available_configurations;
|
||||
// get the existing alternatives
|
||||
available_configurations = settings_.childGroups ();
|
||||
auto const& available_configurations {settings_.childGroups ()};
|
||||
|
||||
// add all the other configurations
|
||||
for (auto const& configuration_name: available_configurations)
|
||||
|
@ -3,13 +3,13 @@
|
||||
|
||||
#include <QObject>
|
||||
#include <QVariant>
|
||||
#include <QString>
|
||||
|
||||
#include "pimpl_h.hpp"
|
||||
|
||||
class QSettings;
|
||||
class QMainWindow;
|
||||
class QMenu;
|
||||
class QString;
|
||||
|
||||
//
|
||||
// MultiSettings - Manage multiple configuration names
|
||||
@ -65,7 +65,11 @@ class MultiSettings
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MultiSettings ();
|
||||
// config_name will be selected if it is an existing configuration
|
||||
// name otherwise the last used configuration will be selected or
|
||||
// the default configuration if none exist
|
||||
explicit MultiSettings (QString const& config_name = QString {});
|
||||
|
||||
MultiSettings (MultiSettings const&) = delete;
|
||||
MultiSettings& operator = (MultiSettings const&) = delete;
|
||||
~MultiSettings ();
|
||||
|
11
main.cpp
11
main.cpp
@ -110,7 +110,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
#if QT_VERSION >= 0x050200
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription ("\nJT65A & JT9 Weak Signal Communications Program.");
|
||||
parser.setApplicationDescription ("\nJT65, JT9, JT4, MSK144, QRA64, ISCAT & WSPR Weak Signal Communications Program.");
|
||||
auto help_option = parser.addHelpOption ();
|
||||
auto version_option = parser.addVersionOption ();
|
||||
|
||||
@ -120,6 +120,12 @@ int main(int argc, char *argv[])
|
||||
, a.translate ("main", "rig-name"));
|
||||
parser.addOption (rig_option);
|
||||
|
||||
// support for start up configuration
|
||||
QCommandLineOption cfg_option (QStringList {} << "c" << "config"
|
||||
, a.translate ("main", "Where <configuration> is an existing one.")
|
||||
, a.translate ("main", "configuration"));
|
||||
parser.addOption (cfg_option);
|
||||
|
||||
QCommandLineOption test_option (QStringList {} << "test-mode"
|
||||
, a.translate ("main", "Writable files in test location. Use with caution, for testing only."));
|
||||
parser.addOption (test_option);
|
||||
@ -168,8 +174,9 @@ int main(int argc, char *argv[])
|
||||
|
||||
multiple = true;
|
||||
}
|
||||
|
||||
// now we have the application name we can open the settings
|
||||
MultiSettings multi_settings;
|
||||
MultiSettings multi_settings {parser.value (cfg_option)};
|
||||
|
||||
// find the temporary files path
|
||||
QDir temp_dir {QStandardPaths::writableLocation (QStandardPaths::TempLocation)};
|
||||
|
Loading…
Reference in New Issue
Block a user