"Fossies" - the Fresh Open Source Software Archive

Member "glibmm-2.76.0/gio/src/applicationcommandline.hg" (12 Mar 2023, 6325 Bytes) of package /linux/misc/glibmm-2.76.0.tar.xz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 /* Copyright (C) 2010 Jonathon Jongsma <jonathon@quotidian.org>
    2  *
    3  * This library is free software; you can redistribute it and/or
    4  * modify it under the terms of the GNU Lesser General Public
    5  * License as published by the Free Software Foundation; either
    6  * version 2.1 of the License, or (at your option) any later version.
    7  *
    8  * This library is distributed in the hope that it will be useful,
    9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   11  * Lesser General Public License for more details.
   12  *
   13  * You should have received a copy of the GNU Lesser General Public
   14  * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
   15  */
   16 
   17 #include <giomm/file.h>
   18 #include <giomm/inputstream.h>
   19 #include <glibmm/object.h>
   20 #include <glibmm/variant.h>
   21 #include <glibmm/variantdict.h>
   22 
   23 _DEFS(giomm,gio)
   24 _PINCLUDE(glibmm/private/object_p.h)
   25 
   26 namespace Gio
   27 {
   28 
   29 /** ApplicationCommandLine - A command-line invocation of an application.
   30  * ApplicationCommandLine represents a command-line invocation of an
   31  * application. It is created by Application and emitted in the "command-line"
   32  * signal and virtual function.
   33  *
   34  * The class contains the list of arguments that the program was invoked with.
   35  * It is also possible to query if the commandline invocation was local (ie:
   36  * the current process is running in direct response to the invocation) or
   37  * remote (ie: some other process forwarded the commandline to this process).
   38  *
   39  * The ApplicationCommandLine object can provide the argc and argv parameters
   40  * for use with the Glib::OptionContext command-line parsing API, with the
   41  * get_arguments() method.
   42  *
   43  * The exit status of the originally-invoked process may be set and messages
   44  * can be printed to stdout or stderr of that process. The lifecycle of the
   45  * originally-invoked process is tied to the lifecycle of this object (ie: the
   46  * process exits when the last reference is dropped).
   47  *
   48  * The main use for ApplicationCommandline (and the "command-line" signal) is
   49  * 'Emacs server' like use cases: You can set the EDITOR environment variable
   50  * to have e.g. git use your favourite editor to edit commit messages, and if
   51  * you already have an instance of the editor running, the editing will happen
   52  * in the running instance, instead of opening a new one. An important aspect
   53  * of this use case is that the process that gets started by git does not
   54  * return until the editing is done.
   55  * @newin{2,32}
   56  */
   57 class GIOMM_API ApplicationCommandLine : public Glib::Object
   58 {
   59   _CLASS_GOBJECT(ApplicationCommandLine, GApplicationCommandLine, G_APPLICATION_COMMAND_LINE, Glib::Object, GObject, , , GIOMM_API)
   60 
   61 protected:
   62   _CTOR_DEFAULT
   63 
   64 public:
   65 
   66   /** Gets the list of arguments that was passed on the command line.
   67    *
   68    * The strings in the array may contain non-UTF-8 data on UNIX (such as
   69    * filenames or arguments given in the system locale) but are always in
   70    * UTF-8 on Windows.
   71    *
   72    * If you wish to use the return value with Glib::OptionContext, you must
   73    * use Glib::OptionContext::parse(char**& argv).
   74    *
   75    * The return value is nullptr-terminated and should be freed using
   76    * g_strfreev().
   77    *
   78    * @newin{2,28}
   79    *
   80    * @param[out] argc The length of the arguments array.
   81    * @return The string array containing the arguments (the argv).
   82    */
   83   _WRAP_METHOD(char** get_arguments(int& argc) const, g_application_command_line_get_arguments)
   84 
   85   //TODO: Wrap the GVariantDict*. See also Application's handle-local-options signal.
   86   _WRAP_METHOD(Glib::RefPtr<Glib::VariantDict> get_options_dict(), g_application_command_line_get_options_dict, refreturn)
   87   _WRAP_METHOD(Glib::RefPtr<const Glib::VariantDict> get_options_dict() const, g_application_command_line_get_options_dict, refreturn, constversion)
   88 
   89   _WRAP_METHOD(Glib::RefPtr<InputStream> get_stdin(), g_application_command_line_get_stdin, refreturn)
   90   _WRAP_METHOD(Glib::RefPtr<const InputStream> get_stdin() const, g_application_command_line_get_stdin, refreturn, constversion)
   91 
   92 
   93   //We use std::string instead of ustring because the C documentation says that it may be non-UTF-8 data:
   94   _WRAP_METHOD(std::string get_cwd() const, g_application_command_line_get_cwd)
   95 
   96   //We use std::string instead of ustring because the C documentation says that it may be non-UTF-8 data:
   97 #m4 _CONVERSION(`const gchar* const*',`std::vector<std::string>',`Glib::ArrayHandler<std::string>::array_to_vector($3, Glib::OWNERSHIP_NONE)')
   98   _WRAP_METHOD(std::vector<std::string> get_environ() const, g_application_command_line_get_environ)
   99 
  100   //We use std::string instead of ustring because the C documentation says that it may be non-UTF-8 data:
  101   _WRAP_METHOD(std::string getenv(const Glib::ustring& name) const, g_application_command_line_getenv)
  102 
  103   _WRAP_METHOD(bool is_remote() const, g_application_command_line_get_is_remote)
  104 
  105 #m4 _CONVERSION(`GVariant*',`Glib::Variant< std::map<Glib::ustring, Glib::VariantBase> >',`$2($3)')
  106   _WRAP_METHOD(Glib::Variant< std::map<Glib::ustring, Glib::VariantBase> > get_platform_data() const, g_application_command_line_get_platform_data)
  107 
  108   _WRAP_METHOD(void set_exit_status(int exit_status), g_application_command_line_set_exit_status)
  109   _WRAP_METHOD(int get_exit_status() const, g_application_command_line_get_exit_status)
  110 
  111   /** Formats a message and prints it using the stdout print handler in the invoking process.
  112    * If this is a local invocation then this is exactly equivalent to g_print().
  113    *  If this is remote then this is equivalent to calling g_print() in the invoking process.
  114    *
  115    * @param message The text to print.
  116    */
  117   void print(const Glib::ustring& message);
  118   _IGNORE(g_application_command_line_print)
  119 
  120   /** Formats a message and prints it using the stderr print handler in the invoking process.
  121    * If this is a local invocation then this is exactly equivalent to g_printerr().
  122    *  If this is remote then this is equivalent to calling g_printerr() in the invoking process.
  123    *
  124    * @param message The text to print.
  125    */
  126   void printerr(const Glib::ustring& message);
  127   _IGNORE(g_application_command_line_printerr)
  128 
  129   _WRAP_METHOD(Glib::RefPtr<File> create_file_for_arg(const Glib::ustring& arg) const, g_application_command_line_create_file_for_arg)
  130 };
  131 
  132 
  133 } // namespace Gio