mirror of
				https://github.com/saitohirga/WSJT-X.git
				synced 2025-10-30 20:40:28 -04: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 |   Q_OBJECT | ||||||
| 
 | 
 | ||||||
| public: | public: | ||||||
|   explicit impl (MultiSettings const * parent); |   explicit impl (MultiSettings const * parent, QString const& config_name); | ||||||
|   bool reposition (); |   bool reposition (); | ||||||
|   void create_menu_actions (QMainWindow * main_window, QMenu * menu); |   void create_menu_actions (QMainWindow * main_window, QMenu * menu); | ||||||
|   bool exit (); |   bool exit (); | ||||||
| @ -201,8 +201,8 @@ private: | |||||||
| #include "MultiSettings.moc" | #include "MultiSettings.moc" | ||||||
| #include "moc_MultiSettings.cpp" | #include "moc_MultiSettings.cpp" | ||||||
| 
 | 
 | ||||||
| MultiSettings::MultiSettings () | MultiSettings::MultiSettings (QString const& config_name) | ||||||
|   : m_ {this} |   : m_ {this, config_name} | ||||||
| { | { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -263,7 +263,7 @@ bool MultiSettings::exit () | |||||||
|   return m_->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} |   : settings_ {settings_path (), QSettings::IniFormat} | ||||||
|   , parent_ {parent} |   , parent_ {parent} | ||||||
|   , name_change_emit_pending_ {true} |   , name_change_emit_pending_ {true} | ||||||
| @ -303,15 +303,33 @@ MultiSettings::impl::impl (MultiSettings const * parent) | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|   // bootstrap
 |   // bootstrap
 | ||||||
|  |   QStringList available_configurations; | ||||||
|   { |   { | ||||||
|     SettingsGroup alternatives {&settings_, multi_settings_root_group}; |     SettingsGroup alternatives {&settings_, multi_settings_root_group}; | ||||||
|  |     available_configurations = settings_.childGroups (); | ||||||
|  |     // use last selected configuration
 | ||||||
|     current_ = settings_.value (multi_settings_current_name_key).toString (); |     current_ = settings_.value (multi_settings_current_name_key).toString (); | ||||||
|     if (!current_.size ()) |     if (!current_.size ()) | ||||||
|       { |       { | ||||||
|  |         // no configurations so use default name
 | ||||||
|         current_ = tr (default_string); |         current_ = tr (default_string); | ||||||
|         settings_.setValue (multi_settings_current_name_key, current_); |         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 (); |   settings_.sync (); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -394,9 +412,8 @@ void MultiSettings::impl::create_menu_actions (QMainWindow * main_window, QMenu | |||||||
|   // and set as the current configuration
 |   // and set as the current configuration
 | ||||||
|   default_menu->menuAction ()->setChecked (true); |   default_menu->menuAction ()->setChecked (true); | ||||||
| 
 | 
 | ||||||
|   QStringList available_configurations; |  | ||||||
|   // get the existing alternatives
 |   // get the existing alternatives
 | ||||||
|   available_configurations = settings_.childGroups (); |   auto const& available_configurations {settings_.childGroups ()}; | ||||||
| 
 | 
 | ||||||
|   // add all the other configurations
 |   // add all the other configurations
 | ||||||
|   for (auto const& configuration_name: available_configurations) |   for (auto const& configuration_name: available_configurations) | ||||||
|  | |||||||
| @ -3,13 +3,13 @@ | |||||||
| 
 | 
 | ||||||
| #include <QObject> | #include <QObject> | ||||||
| #include <QVariant> | #include <QVariant> | ||||||
|  | #include <QString> | ||||||
| 
 | 
 | ||||||
| #include "pimpl_h.hpp" | #include "pimpl_h.hpp" | ||||||
| 
 | 
 | ||||||
| class QSettings; | class QSettings; | ||||||
| class QMainWindow; | class QMainWindow; | ||||||
| class QMenu; | class QMenu; | ||||||
| class QString; |  | ||||||
| 
 | 
 | ||||||
| //
 | //
 | ||||||
| // MultiSettings - Manage multiple configuration names
 | // MultiSettings - Manage multiple configuration names
 | ||||||
| @ -65,7 +65,11 @@ class MultiSettings | |||||||
|   Q_OBJECT |   Q_OBJECT | ||||||
| 
 | 
 | ||||||
| public: | 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 (MultiSettings const&) = delete; | ||||||
|   MultiSettings& operator = (MultiSettings const&) = delete; |   MultiSettings& operator = (MultiSettings const&) = delete; | ||||||
|   ~MultiSettings (); |   ~MultiSettings (); | ||||||
|  | |||||||
							
								
								
									
										11
									
								
								main.cpp
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								main.cpp
									
									
									
									
									
								
							| @ -110,7 +110,7 @@ int main(int argc, char *argv[]) | |||||||
| 
 | 
 | ||||||
| #if QT_VERSION >= 0x050200 | #if QT_VERSION >= 0x050200 | ||||||
|       QCommandLineParser parser; |       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 help_option = parser.addHelpOption (); | ||||||
|       auto version_option = parser.addVersionOption (); |       auto version_option = parser.addVersionOption (); | ||||||
| 
 | 
 | ||||||
| @ -120,6 +120,12 @@ int main(int argc, char *argv[]) | |||||||
|                                      , a.translate ("main", "rig-name")); |                                      , a.translate ("main", "rig-name")); | ||||||
|       parser.addOption (rig_option); |       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" |       QCommandLineOption test_option (QStringList {} << "test-mode" | ||||||
|                                       , a.translate ("main", "Writable files in test location.  Use with caution, for testing only.")); |                                       , a.translate ("main", "Writable files in test location.  Use with caution, for testing only.")); | ||||||
|       parser.addOption (test_option); |       parser.addOption (test_option); | ||||||
| @ -168,8 +174,9 @@ int main(int argc, char *argv[]) | |||||||
| 
 | 
 | ||||||
|           multiple = true; |           multiple = true; | ||||||
|         } |         } | ||||||
|  | 
 | ||||||
|       // now we have the application name we can open the settings
 |       // 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
 |       // find the temporary files path
 | ||||||
|       QDir temp_dir {QStandardPaths::writableLocation (QStandardPaths::TempLocation)}; |       QDir temp_dir {QStandardPaths::writableLocation (QStandardPaths::TempLocation)}; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user