[glom] Move all command-line handling into the remote Application.



commit 0a5f79d41880f76cdc17dfaae0885d6ad1978306
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Feb 10 11:55:37 2012 +0100

    Move all command-line handling into the remote Application.
    
    * glom/main.cc:
    * glom/application.cc:
    * glom/main_local_options.[h|cc]:
    * glom/main_remote_options.[h|cc]: Split the command-line options into
    two OptionGroups, in their own files, even putting local option handling in
    its separate file. This lets us handle them properly, despite the lack of
    GApplication support for separate local/remote GOption handling.
    ( See https://bugzilla.gnome.org/show_bug.cgi?id=634990#c6 )
    thanks to our use of G_APPLICATION_NON_UNIQUE.
    Having them separate should make it easier to really do it properly if
    GApplication ever allows it.

 ChangeLog                   |   16 +++++
 Makefile_glom.am            |    8 ++-
 glom/application.cc         |  117 ++++++++++++++++++++++++++++++--
 glom/application.h          |    5 +-
 glom/main.cc                |  158 +------------------------------------------
 glom/main_local_options.cc  |   91 +++++++++++++++++++++++++
 glom/main_local_options.h   |   54 +++++++++++++++
 glom/main_remote_options.cc |   58 ++++++++++++++++
 glom/main_remote_options.h  |   49 +++++++++++++
 po/POTFILES.in              |    3 +
 10 files changed, 394 insertions(+), 165 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 03beded..7824b5e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2012-02-10  Murray Cumming  <murrayc murrayc com>>
+
+	Move all command-line handling into the remote Application.
+
+	* glom/main.cc:
+	* glom/application.cc:
+	* glom/main_local_options.[h|cc]:
+	* glom/main_remote_options.[h|cc]: Split the command-line options into 
+	two OptionGroups, in their own files, even putting local option handling in
+	its separate file. This lets us handle them properly, despite the lack of 
+	GApplication support for separate local/remote GOption handling.
+	( See https://bugzilla.gnome.org/show_bug.cgi?id=634990#c6 )
+	thanks to our use of G_APPLICATION_NON_UNIQUE.
+	Having them separate should make it easier to really do it properly if
+	GApplication ever allows it.
+
 2012-02-10  Murray Cumming  <murrayc murrayc com>
 
 	Use G_APPLICATION_NON_UNIQUE.
diff --git a/Makefile_glom.am b/Makefile_glom.am
index ce41894..2f27e19 100644
--- a/Makefile_glom.am
+++ b/Makefile_glom.am
@@ -67,8 +67,6 @@ glom_canvas_files =  \
 	glom/utility_widgets/canvas/canvas_text_movable.h
 
 glom_source_files = \
-	glom/application.cc						\
-	glom/application.h						\
 	glom/appwindow.cc						\
 	glom/appwindow.h						\
 	glom/base_db.cc							\
@@ -396,7 +394,13 @@ glom_source_files +=							\
 	glom/navigation/box_tables.h
 
 glom_glom_SOURCES =							\
+	glom/application.cc						\
+	glom/application.h						\
 	glom/main.cc							\
+	glom/main_local_options.cc \
+	glom/main_local_options.h \
+	glom/main_remote_options.cc \
+	glom/main_remote_options.h \
 	$(glom_source_files)
 
 glom_all_libs = $(win_resfile) \
diff --git a/glom/application.cc b/glom/application.cc
index 9eb5108..d118b74 100644
--- a/glom/application.cc
+++ b/glom/application.cc
@@ -18,11 +18,15 @@
  * Boston, MA 02111-1307, USA.
  */
 
-#include "application.h"
-#include "appwindow.h"
+#include <glom/application.h>
+#include <glom/appwindow.h>
+#include <glom/main_local_options.h>
 #include <glom/glade_utils.h>
+#include <glibmm/optioncontext.h>
 #include <iostream>
 
+#include <glibmm/i18n.h>
+
 namespace Glom
 {
 
@@ -30,7 +34,7 @@ namespace Glom
 // to simplify our code.
 // We also want to prevent all instances from crashing when one instance crashes.
 Application::Application()
-: Gtk::Application("org.glom.application", Gio::APPLICATION_HANDLES_OPEN | Gio::APPLICATION_NON_UNIQUE)
+: Gtk::Application("org.glom.application", Gio::APPLICATION_HANDLES_OPEN | Gio::APPLICATION_HANDLES_COMMAND_LINE | Gio::APPLICATION_NON_UNIQUE)
 {
 }
 
@@ -41,10 +45,15 @@ Glib::RefPtr<Application> Application::create()
 
 void Application::create_window(const Glib::RefPtr<Gio::File>& file)
 {
+  //std::cout << G_STRFUNC << ": debug" << std::endl;
+
   AppWindow* window = 0;
   Glom::Utils::get_glade_widget_derived_with_warning(window);
   g_assert(window);
 
+  window->set_show_sql_debug(m_remote_option_group.m_arg_debug_sql);
+  window->set_stop_auto_server_shutdown(m_remote_option_group.m_arg_stop_auto_server_shutdown);
+
   //Make sure that the application runs for as long this window is still open:
   add_window(*window);
 
@@ -58,7 +67,7 @@ void Application::create_window(const Glib::RefPtr<Gio::File>& file)
     input_uri = file->get_uri();
   }
 
-  const bool test = window->init(input_uri, false /* TODO: group.m_arg_restore */); //Sets it up and shows it.
+  const bool test = window->init(input_uri, m_remote_option_group.m_arg_restore); //Sets it up and shows it.
   if(!test) //The user could cancel the offer of a new or existing database.
   {
     window->hide(); //This will cause it to be deleted by on_window_hide.
@@ -72,7 +81,8 @@ void Application::on_window_hide(Gtk::Window* window)
 
 void Application::on_activate()
 {
-  //std::cout << "debug1: " << G_STRFUNC << std::endl;
+  //std::cout << G_STRFUNC << ": debug" << std::endl;
+
   // The application has been started, so let's show a window:
   create_window();
 }
@@ -80,6 +90,8 @@ void Application::on_activate()
 void Application::on_open(const Gio::Application::type_vec_files& files,
   const Glib::ustring& hint)
 {
+  //std::cout << G_STRFUNC << ": debug" << std::endl;
+  
   // The application has been asked to open some files,
   // so let's open a new window for each one.
   //std::cout << "debug: files.size()=" << files.size() << std::endl;
@@ -97,4 +109,99 @@ void Application::on_open(const Gio::Application::type_vec_files& files,
   Application::on_open(files, hint);
 }
 
+
+int Application::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine>& command_line)
+{
+  //std::cout << G_STRFUNC << ": debug" << std::endl;
+  
+  //Parse command-line arguments that were passed either to the main (first) instance
+  //or to subsequent instances.
+  //Note that this parsing is happening in the main (not remote) instance.
+  int argc = 0;
+  char** argv =	command_line->get_arguments(argc);
+
+  Glib::OptionContext context;
+  context.set_main_group(m_remote_option_group);
+  
+  //Note that these options should really be parsed in main(),
+  //but we do it here because of glib bug: https://bugzilla.gnome.org/show_bug.cgi?id=634990#c6
+  //Handling the two groups together here is possible due to our use of Gio::APPLICATION_NON_UNIQUE .
+  LocalOptionGroup local_group;
+  context.add_group(local_group);
+
+  try
+  {
+    context.parse(argc, argv);
+  }
+  catch(const Glib::OptionError& ex)
+  {
+    std::cout << _("Error while parsing command-line options: ") << std::endl << ex.what() << std::endl;
+    std::cout << _("Use --help to see a list of available command-line options.") << std::endl;
+    return EXIT_FAILURE;
+  }
+  catch(const Glib::Error& ex)
+  {
+    std::cout << "Error: " << ex.what() << std::endl;
+    return EXIT_FAILURE;
+  }
+
+  //Get command-line parameters, if any:  
+  if(!main_handle_local_options(local_group))
+    return EXIT_FAILURE;
+
+  Glib::ustring input_uri = m_remote_option_group.m_arg_filename;
+
+  // The GOption documentation says that options without names will be returned to the application as "rest arguments".
+  // I guess this means they will be left in the argv. Murray.
+  if(input_uri.empty() && (argc > 1))
+  {
+     const char* pch = argv[1];
+     if(pch)
+       input_uri = pch;
+  }
+
+  Glib::RefPtr<Gio::File> file;
+  if(!input_uri.empty())
+  {
+    //Get a URI (file://something) from the filepath:
+    file = Gio::File::create_for_commandline_arg(input_uri);
+
+    if(!file->query_exists())
+    {
+      std::cerr << _("Glom: The file does not exist.") << std::endl;
+      std::cerr << "uri: " << input_uri << std::endl;
+
+      std::cerr << std::endl << context.get_help() << std::endl;
+      return EXIT_FAILURE;
+    }
+
+    const Gio::FileType file_type = file->query_file_type();
+    if(file_type == Gio::FILE_TYPE_DIRECTORY)
+    {
+      std::cerr << _("Glom: The file path is a directory instead of a file.") << std::endl;
+
+      std::cerr << std::endl << context.get_help() << std::endl;
+      return EXIT_FAILURE;
+    }
+
+    //std::cout << "URI = " << input_uri << std::endl;
+  }
+
+  //debugging:
+  //input_uri = "file:///home/murrayc/cvs/gnome212/glom/examples/example_smallbusiness.glom";
+
+  if(file)
+  {
+    open(file); //TODO: Find out why calling open() with a null File causes an infinite loop.
+  }
+  else
+  {
+    //Open a new "document" instead:
+    activate();
+  }
+
+  //The local instance will eventually exit with this status code:
+  return EXIT_SUCCESS;
+}
+
 } //namespace Glom
diff --git a/glom/application.h b/glom/application.h
index 3f4ed97..f312f61 100644
--- a/glom/application.h
+++ b/glom/application.h
@@ -21,7 +21,7 @@
 #ifndef GLOM_APPLICATION_H
 #define GLOM_APPLICATION_H
 
-
+#include <glom/main_remote_options.h>
 #include <gtkmm/application.h>
 
 namespace Glom
@@ -40,11 +40,14 @@ protected:
   virtual void on_activate();
   virtual void on_open(const Gio::Application::type_vec_files& files,
     const Glib::ustring& hint);
+  virtual int on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine>& command_line);
 
 private:
   void create_window(const Glib::RefPtr<Gio::File>& file = Glib::RefPtr<Gio::File>());
 
   void on_window_hide(Gtk::Window* window);
+  
+  RemoteOptionGroup m_remote_option_group;
 };
 
 } //namespace Glom
diff --git a/glom/main.cc b/glom/main.cc
index 9ce4a81..f121a0a 100644
--- a/glom/main.cc
+++ b/glom/main.cc
@@ -32,7 +32,6 @@
 #include <gtkmm/main.h>
 
 #include <giomm/file.h>
-#include <glibmm/optioncontext.h>
 #include <glibmm/convert.h>
 #include <glibmm/miscutils.h>
 
@@ -45,7 +44,6 @@
 #endif //GLOM_ENABLE_POSTGRESQL
 
 // For sanity checks:
-#include <libglom/data_structure/glomconversions.h>
 #include <glom/python_embed/glom_python.h>
 
 #ifndef GLOM_ENABLE_CLIENT_ONLY
@@ -178,61 +176,6 @@ pgwin32_is_admin(void)
 namespace Glom
 {
 
-class OptionGroup : public Glib::OptionGroup
-{
-public:
-  OptionGroup();
-
-  //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.
-  std::string m_arg_filename;
-  bool m_arg_version;
-  bool m_arg_restore;
-  bool m_arg_stop_auto_server_shutdown;
-  bool m_arg_debug_sql;
-  bool m_arg_debug_date_check;
-};
-
-OptionGroup::OptionGroup()
-: Glib::OptionGroup("Glom", _("Glom options"), _("Command-line options for glom")),
-  m_arg_version(false),
-  m_arg_restore(false),
-  m_arg_stop_auto_server_shutdown(false),
-  m_arg_debug_sql(false),
-  m_arg_debug_date_check(false)
-{
-  Glib::OptionEntry entry;
-  entry.set_long_name("file");
-  entry.set_short_name('f');
-  entry.set_description(_("The Filename"));
-  add_entry_filename(entry, m_arg_filename);
-
-  entry.set_long_name("version");
-  entry.set_short_name('V');
-  entry.set_description(_("The version of this application."));
-  add_entry(entry, m_arg_version);
-
-  entry.set_long_name("restore");
-  entry.set_short_name(0);
-  entry.set_description(_("Whether the filename is a .tar.gz backup to be restored."));
-  add_entry(entry, m_arg_restore);
-
-  entry.set_long_name("stop-auto-server-shutdown");
-  entry.set_short_name(0);
-  entry.set_description(_("Do not automatically stop the database server if Glom quits. This is helpful for debugging with gdb."));
-  add_entry(entry, m_arg_stop_auto_server_shutdown);
-
-  entry.set_long_name("debug_sql");
-  entry.set_short_name(0);
-  entry.set_description(_("Show the generated SQL queries on stdout, for debugging."));
-  add_entry(entry, m_arg_debug_sql);
-
-  entry.set_long_name("debug-date-check");
-  entry.set_short_name(0);
-  entry.set_description(_("Show how Glom outputs a date in this locale, then stop."));
-  add_entry(entry, m_arg_debug_date_check);
-}
-
 #ifdef GLOM_ENABLE_POSTGRESQL
 bool check_user_is_not_root_with_warning()
 {
@@ -458,18 +401,13 @@ main(int argc, char* argv[])
 
   Glom::libglom_init(); //Also initializes python.
 
-  Glib::OptionContext context;
-
-  Glom::OptionGroup group;
-  context.set_main_group(group);
-
   //We use python for calculated-fields:
   PySys_SetArgv(argc, argv);
 
   std::auto_ptr<Gtk::Main> mainInstance;
   try
   {
-    mainInstance = std::auto_ptr<Gtk::Main>( new Gtk::Main(argc, argv, context) );
+    mainInstance = std::auto_ptr<Gtk::Main>( new Gtk::Main(argc, argv) );
   }
   catch(const Glib::Error& ex)
   {
@@ -479,29 +417,6 @@ main(int argc, char* argv[])
 
   try
   {
-    context.parse(argc, argv);
-  }
-  catch(const Glib::OptionError& ex)
-  {
-      std::cout << _("Error while parsing command-line options: ") << std::endl << ex.what() << std::endl;
-      std::cout << _("Use --help to see a list of available command-line options.") << std::endl;
-      return EXIT_FAILURE;
-  }
-  catch(const Glib::Error& ex)
-  {
-    std::cout << "Error: " << ex.what() << std::endl;
-    return EXIT_FAILURE;
-  }
-
-
-  if(group.m_arg_version)
-  {
-    std::cout << PACKAGE_STRING << std::endl;
-    return EXIT_SUCCESS;
-  }
-
-  try
-  {
 #ifndef GLOM_ENABLE_CLIENT_ONLY
     Gsv::init();
     Goocanvas::init();
@@ -509,49 +424,6 @@ main(int argc, char* argv[])
 
     ev_init();
 
-    //Get command-line parameters, if any:
-    Glib::ustring input_uri = group.m_arg_filename;
-
-    // The GOption documentation says that options without names will be returned to the application as "rest arguments".
-    // I guess this means they will be left in the argv. Murray.
-    if(input_uri.empty() && (argc > 1))
-    {
-       const char* pch = argv[1];
-       if(pch)
-         input_uri = pch;
-    }
-
-    if(!input_uri.empty())
-    {
-      //Get a URI (file://something) from the filepath:
-      Glib::RefPtr<Gio::File> file = Gio::File::create_for_commandline_arg(input_uri);
-
-      if(!file->query_exists())
-      {
-        std::cerr << _("Glom: The file does not exist.") << std::endl;
-        std::cerr << "uri: " << input_uri << std::endl;
-
-        std::cerr << std::endl << context.get_help() << std::endl;
-        return EXIT_FAILURE;
-      }
-
-      const Gio::FileType file_type = file->query_file_type();
-      if(file_type == Gio::FILE_TYPE_DIRECTORY)
-      {
-        std::cerr << _("Glom: The file path is a directory instead of a file.") << std::endl;
-
-        std::cerr << std::endl << context.get_help() << std::endl;
-        return EXIT_FAILURE;
-      }
-
-      input_uri = file->get_uri();
-
-      //std::cout << "URI = " << input_uri << std::endl;
-    }
-
-    //debugging:
-    //input_uri = "file:///home/murrayc/cvs/gnome212/glom/examples/example_smallbusiness.glom";
-
 #ifdef GLOM_ENABLE_POSTGRESQL
 
     //Check that the libgda postgres provider is really available:
@@ -590,36 +462,8 @@ main(int argc, char* argv[])
       return EXIT_FAILURE;
 
 
-    // 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;
-    const bool test1 =
-      Glom::Conversions::sanity_check_date_text_representation_uses_4_digit_years(group.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;
-    }
-
-    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;
-    }
-
-    if(group.m_arg_debug_date_check)
-    {
-      return date_check_ok ? EXIT_SUCCESS : EXIT_FAILURE; //This command-line option is documented as stopping afterwards.
-    }
-
     Glib::RefPtr<Glom::Application> application = 
       Glom::Application::create();
-    //TODO: application->set_show_sql_debug(group.m_arg_debug_sql);
-    //TODO: application->set_stop_auto_server_shutdown(group.m_arg_stop_auto_server_shutdown);
-    Glom::ConnectionPool::get_instance()->set_show_debug_output(group.m_arg_debug_sql); //TODO: Put this in Application::set_show_sql_debug().
-
     const int status = application->run(argc, argv);
     if(status != EXIT_SUCCESS) //TODO: Is this right?
       return status;
diff --git a/glom/main_local_options.cc b/glom/main_local_options.cc
new file mode 100644
index 0000000..cd64bb5
--- /dev/null
+++ b/glom/main_local_options.cc
@@ -0,0 +1,91 @@
+/* Glom
+ *
+ * Copyright (C) 2012 Murray Cumming
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include <glom/main_local_options.h>
+
+// For sanity checks:
+#include <libglom/data_structure/glomconversions.h>
+#include <glom/python_embed/glom_python.h>
+
+#include <glibmm/optionentry.h>
+
+#include <glibmm/i18n.h>
+
+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)
+{
+  Glib::OptionEntry entry;
+  entry.set_long_name("version");
+  entry.set_short_name('V');
+  entry.set_description(_("The version of this application."));
+  add_entry(entry, m_arg_version);
+
+  entry.set_long_name("debug-date-check");
+  entry.set_short_name(0);
+  entry.set_description(_("Show how Glom outputs a date in this locale, then stop."));
+  add_entry(entry, m_arg_debug_date_check);
+}
+
+
+bool main_handle_local_options(const LocalOptionGroup& group)
+{
+  if(group.m_arg_version)
+  {
+    std::cout << PACKAGE_STRING << std::endl;
+    return EXIT_SUCCESS;
+  }
+  
+  // 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;
+  const bool test1 =
+    Glom::Conversions::sanity_check_date_text_representation_uses_4_digit_years(group.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;
+  }
+
+  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;
+  }
+
+  if(group.m_arg_debug_date_check)
+  {
+    return date_check_ok; //This command-line option is documented as stopping afterwards.
+  }
+  
+  return true;
+}
+
+
+} //namespace Glom
+
diff --git a/glom/main_local_options.h b/glom/main_local_options.h
new file mode 100644
index 0000000..43da6f0
--- /dev/null
+++ b/glom/main_local_options.h
@@ -0,0 +1,54 @@
+/* Glom
+ *
+ * Copyright (C) 2012 Murray Cumming
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef GLOM_MAIN_LOCAL_OPTIONS_H
+#define GLOM_MAIN_LOCAL_OPTIONS_H
+
+#include <glibmm/optiongroup.h>
+
+namespace Glom
+{
+
+
+//These options can be run by the local (short-lived) instance:
+//However, real separation (or even real remote handling) of OptionGroups is
+//not possible yet:
+//https://bugzilla.gnome.org/show_bug.cgi?id=634990#c6
+//This only works at all because we use Gio::APPLICATION_NON_UNIQUE .
+class LocalOptionGroup : public Glib::OptionGroup
+{
+public:
+  LocalOptionGroup();
+
+  //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;
+};
+
+
+/**
+ * @result If this is false then the GApplication, or main() should return EXIT_FAILURE.
+ */
+bool main_handle_local_options(const LocalOptionGroup& group);
+
+} //namespace Glom
+
+#endif //GLOM_MAIN_LOCAL_OPTIONS
diff --git a/glom/main_remote_options.cc b/glom/main_remote_options.cc
new file mode 100644
index 0000000..8f94a78
--- /dev/null
+++ b/glom/main_remote_options.cc
@@ -0,0 +1,58 @@
+/* Glom
+ *
+ * Copyright (C) 2012 Murray Cumming
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <glom/main_remote_options.h>
+
+#include <glibmm/optionentry.h>
+
+#include <glibmm/i18n.h>
+
+namespace Glom
+{
+
+RemoteOptionGroup::RemoteOptionGroup()
+: Glib::OptionGroup("glom", _("Main Glom options"), _("Main command-line options for glom")),
+  m_arg_restore(false),
+  m_arg_stop_auto_server_shutdown(false),
+  m_arg_debug_sql(false)
+{
+  Glib::OptionEntry entry;
+  entry.set_long_name("file");
+  entry.set_short_name('f');
+  entry.set_description(_("The Filename"));
+  add_entry_filename(entry, m_arg_filename);
+
+  entry.set_long_name("restore");
+  entry.set_short_name(0);
+  entry.set_description(_("Whether the filename is a .tar.gz backup to be restored."));
+  add_entry(entry, m_arg_restore);
+
+  entry.set_long_name("stop-auto-server-shutdown");
+  entry.set_short_name(0);
+  entry.set_description(_("Do not automatically stop the database server if Glom quits. This is helpful for debugging with gdb."));
+  add_entry(entry, m_arg_stop_auto_server_shutdown);
+
+  entry.set_long_name("debug_sql");
+  entry.set_short_name(0);
+  entry.set_description(_("Show the generated SQL queries on stdout, for debugging."));
+  add_entry(entry, m_arg_debug_sql);
+}
+
+} //namespace Glom
diff --git a/glom/main_remote_options.h b/glom/main_remote_options.h
new file mode 100644
index 0000000..a8c249c
--- /dev/null
+++ b/glom/main_remote_options.h
@@ -0,0 +1,49 @@
+/* Glom
+ *
+ * Copyright (C) 2012 Murray Cumming
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef GLOM_MAIN_REMOTE_OPTIONS_H
+#define GLOM_MAIN_REMOTE_OPTIONS_H
+
+#include <glibmm/optiongroup.h>
+
+namespace Glom
+{
+
+//These options can be run by the remote (main) instance:
+//However, real separation (or even real remote handling) of OptionGroups is
+//not possible yet:
+//https://bugzilla.gnome.org/show_bug.cgi?id=634990#c6
+//This only works at all because we use Gio::APPLICATION_NON_UNIQUE .
+class RemoteOptionGroup : public Glib::OptionGroup
+{
+public:
+  RemoteOptionGroup();
+
+  //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.
+  std::string m_arg_filename;
+  bool m_arg_restore;
+  bool m_arg_stop_auto_server_shutdown;
+  bool m_arg_debug_sql;
+};
+
+} //namespace Glom
+
+#endif //GLOM_MAIN_REMOTE_OPTIONS
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 4070be2..735e927 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,6 +1,7 @@
 [encoding: UTF-8]
 # List of source files containing translatable strings.
 # Please keep this file sorted alphabetically.
+glom/application.cc
 glom/appwindow.cc
 glom/base_db.cc
 glom/base_db_table_data.cc
@@ -64,6 +65,8 @@ glom/glom_export_po_all.cc
 glom/glom_import_po_all.cc
 glom/glom_test_connection.cc
 glom/main.cc
+glom/main_local_options.cc
+glom/main_remote_options.cc
 glom/mode_data/box_data_calendar_related.cc
 glom/mode_data/box_data.cc
 glom/mode_data/box_data_details.cc



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