[glom/gtkapplication] --debug-date-check: Do not show the window.



commit 4e58bbadbf4fe2a556bb866b8ec6a2eea432224d
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Feb 10 12:26:45 2012 +0100

    --debug-date-check: Do not show the window.
    
    * glom/main_local_options.[h|cc]: Make the handler function a class method,
    and make the variables private. Add a get_debug_date_check_result() method.
    * glom/application.cc: Stop the application, before showing the window,
    if the --debug-date-check option was given, as before we used GApplication.

 ChangeLog                  |    9 +++++++++
 glom/application.cc        |   13 +++++++++++--
 glom/main_local_options.cc |   31 ++++++++++++++++++-------------
 glom/main_local_options.h  |   16 ++++++++++++----
 4 files changed, 50 insertions(+), 19 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 54fcada..8997f8c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2012-02-10  Murray Cumming  <murrayc murrayc com>
+
+	--debug-date-check: Do not show the window.
+
+	* glom/main_local_options.[h|cc]: Make the handler function a class method,
+	and make the variables private. Add a get_debug_date_check_result() method.
+	* glom/application.cc: Stop the application, before showing the window, 
+	if the --debug-date-check option was given, as before we used GApplication.
+	
 2012-02-10  Murray Cumming  <murrayc murrayc com>>
 
 	Move all command-line handling into the remote Application.
diff --git a/glom/application.cc b/glom/application.cc
index d118b74..4faa91b 100644
--- a/glom/application.cc
+++ b/glom/application.cc
@@ -145,9 +145,18 @@ int Application::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine>
     return EXIT_FAILURE;
   }
 
-  //Get command-line parameters, if any:  
-  if(!main_handle_local_options(local_group))
+  //Get command-line parameters, if any:
+  if(!local_group.handle_options())
     return EXIT_FAILURE;
+    
+  bool stop = false;
+  const bool date_check_ok = local_group.get_debug_date_check_result(stop);
+  if(stop)
+  {
+    //This command-line option is documented as stopping afterwards.
+    return date_check_ok ? EXIT_SUCCESS : EXIT_FAILURE;
+  }
+
 
   Glib::ustring input_uri = m_remote_option_group.m_arg_filename;
 
diff --git a/glom/main_local_options.cc b/glom/main_local_options.cc
index cd64bb5..2e123d3 100644
--- a/glom/main_local_options.cc
+++ b/glom/main_local_options.cc
@@ -36,7 +36,8 @@ namespace Glom
 LocalOptionGroup::LocalOptionGroup()
 : Glib::OptionGroup("glom-extra", _("Extra Glom options"), _("Extra command-line options for glom")),
   m_arg_version(false),
-  m_arg_debug_date_check(false)
+  m_arg_debug_date_check(false),
+  m_debug_date_check_result(false)
 {
   Glib::OptionEntry entry;
   entry.set_long_name("version");
@@ -51,41 +52,45 @@ LocalOptionGroup::LocalOptionGroup()
 }
 
 
-bool main_handle_local_options(const LocalOptionGroup& group)
+bool LocalOptionGroup::handle_options()
 {
-  if(group.m_arg_version)
+  if(m_arg_version)
   {
     std::cout << PACKAGE_STRING << std::endl;
-    return EXIT_SUCCESS;
+    return false; //Then stop.
   }
   
   // Some more sanity checking:
   // These print errors to the stdout if they fail.
   // In future we might refuse to start if they fail.
-  bool date_check_ok = true;
+  m_debug_date_check_result = true;
   const bool test1 =
-    Glom::Conversions::sanity_check_date_text_representation_uses_4_digit_years(group.m_arg_debug_date_check /* show debug output */);
+    Glom::Conversions::sanity_check_date_text_representation_uses_4_digit_years(m_arg_debug_date_check /* show debug output */);
   if(!test1)
   {
     std::cerr << "Glom: ERROR: Date presentation sanity checks failed. Glom will not display dates correctly. This needs attention from a translator. Please file a bug. See http://www.glom.org."; << std::endl;
-    date_check_ok = false;
+    m_debug_date_check_result = false;
   }
 
   const bool test2 = Glom::Conversions::sanity_check_date_parsing();
   if(!test2)
   {
     std::cerr << "Glom: ERROR: Date parsing sanity checks failed. Glom will not interpret dates correctly. This needs attention from a translator. Please file a bug. See http://www.glom.org."; << std::endl;
-    date_check_ok = false;
+    m_debug_date_check_result = false;
   }
 
-  if(group.m_arg_debug_date_check)
-  {
-    return date_check_ok; //This command-line option is documented as stopping afterwards.
-  }
-  
   return true;
 }
 
+bool LocalOptionGroup::get_debug_date_check_result(bool& stop) const
+{
+  //This command-line option is documented as stopping executing after checking,
+  //so that the execution result can be checked: 
+  stop = m_arg_debug_date_check;
+  
+  return m_debug_date_check_result;
+}
+
 
 } //namespace Glom
 
diff --git a/glom/main_local_options.h b/glom/main_local_options.h
index 43da6f0..809239a 100644
--- a/glom/main_local_options.h
+++ b/glom/main_local_options.h
@@ -36,18 +36,26 @@ class LocalOptionGroup : public Glib::OptionGroup
 {
 public:
   LocalOptionGroup();
+  
+  /**
+   * @result If this is false then the GApplication, or main() should return EXIT_FAILURE.
+   */
+  bool handle_options();
+  
+  bool get_debug_date_check_result(bool& stop) const;
+
+private:
 
   //These int instances should live as long as the OptionGroup to which they are added,
   //and as long as the OptionContext to which those OptionGroups are added.
   bool m_arg_version;
   bool m_arg_debug_date_check;
+
+  bool m_debug_date_check_result;
 };
 
 
-/**
- * @result If this is false then the GApplication, or main() should return EXIT_FAILURE.
- */
-bool main_handle_local_options(const LocalOptionGroup& group);
+
 
 } //namespace Glom
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]