/* Copyright (C) 2010 Jonathon Jongsma <jonathon@quotidian.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <glibmm/object.h>
#include <glibmm/variant.h>

_DEFS(giomm,gio)
_PINCLUDE(glibmm/private/object_p.h)

namespace Gio
{

/** ApplicationCommandLine - A command-line invocation of an application.
 * ApplicationCommandLine represents a command-line invocation of an
 * application. It is created by Application and emitted in the "command-line"
 * signal and virtual function.
 *
 * The class contains the list of arguments that the program was invoked with.
 * It is also possible to query if the commandline invocation was local (ie:
 * the current process is running in direct response to the invocation) or
 * remote (ie: some other process forwarded the commandline to this process).
 *
 * The ApplicationCommandLine object can provide the argc and argv parameters
 * for use with the Glib::OptionContext command-line parsing API, with the
 * get_arguments() method.
 *
 * The exit status of the originally-invoked process may be set and messages
 * can be printed to stdout or stderr of that process. The lifecycle of the
 * originally-invoked process is tied to the lifecycle of this object (ie: the
 * process exits when the last reference is dropped).
 *
 * The main use for ApplicationCommandline (and the "command-line" signal) is
 * 'Emacs server' like use cases: You can set the EDITOR environment variable
 * to have e.g. git use your favourite editor to edit commit messages, and if
 * you already have an instance of the editor running, the editing will happen
 * in the running instance, instead of opening a new one. An important aspect
 * of this use case is that the process that gets started by git does not
 * return until the editing is done.
 * @newin{2,32}
 */
class ApplicationCommandLine : public Glib::Object
{
  _CLASS_GOBJECT(ApplicationCommandLine, GApplicationCommandLine, G_APPLICATION_COMMAND_LINE, Glib::Object, GObject)

protected:
  _CTOR_DEFAULT

public:

  _WRAP_METHOD(char** get_arguments(int& argc) const, g_application_command_line_get_arguments)
  
  //We use std::string instead of ustring because the C documentation says that it may be non-UTF-8 data:
  _WRAP_METHOD(std::string get_cwd() const, g_application_command_line_get_cwd)

  //We use std::string instead of ustring because the C documentation says that it may be non-UTF-8 data:
#m4 _CONVERSION(`const gchar*const*',`std::vector<std::string>',`Glib::ArrayHandler<std::string>::array_to_vector($3, Glib::OWNERSHIP_NONE)')
  _WRAP_METHOD(std::vector<std::string> get_environ() const, g_application_command_line_get_environ)
  
  //We use std::string instead of ustring because the C documentation says that it may be non-UTF-8 data:
  _WRAP_METHOD(std::string getenv(const Glib::ustring& name) const, g_application_command_line_getenv)
  
  _WRAP_METHOD(bool is_remote() const, g_application_command_line_get_is_remote)

#m4 _CONVERSION(`GVariant*',`Glib::Variant< std::map<Glib::ustring, Glib::VariantBase> >',`$2($3)')
  _WRAP_METHOD(Glib::Variant< std::map<Glib::ustring, Glib::VariantBase> > get_platform_data() const, g_application_command_line_get_platform_data)
 
  _WRAP_METHOD(void set_exit_status(int exit_status), g_application_command_line_set_exit_status)
  _WRAP_METHOD(int get_exit_status() const, g_application_command_line_get_exit_status)
  
  /** Formats a message and prints it using the stdout print handler in the invoking process.
   * If this is a local invocation then this is exactly equivalent to g_print().
   *  If this is remote then this is equivalent to calling g_print() in the invoking process.
   *
   * @param message The text to print.
   */
  void print(const Glib::ustring& message);
  _IGNORE(g_application_command_line_print)
  
  /** Formats a message and prints it using the stderr print handler in the invoking process.
   * If this is a local invocation then this is exactly equivalent to g_printerr().
   *  If this is remote then this is equivalent to calling g_printerr() in the invoking process.
   *
   * @param message The text to print.
   */
  void printerr(const Glib::ustring& message);
  _IGNORE(g_application_command_line_printerr)
};


} // namespace Gio
