"Fossies" - the Fresh Open Source Software Archive

Member "glibmm-2.76.0/gio/src/appinfo.hg" (12 Mar 2023, 13810 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. See also the latest Fossies "Diffs" side-by-side code changes report for "appinfo.hg": 2.74.1_vs_2.76.0.

    1 /* Copyright (C) 2007 The gtkmm Development Team
    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 _CONFIGINCLUDE(giommconfig.h)
   18 
   19 #include <giomm/applaunchcontext.h>
   20 #include <giomm/asyncresult.h>
   21 #include <giomm/cancellable.h>
   22 
   23 #include <exception>
   24 
   25 #include <string>
   26 
   27 #include <glibmm/interface.h>
   28 #include <glibmm/object.h>
   29 #include <giomm/icon.h>
   30 
   31 _DEFS(giomm,gio)
   32 _PINCLUDE(glibmm/private/interface_p.h)
   33 _PINCLUDE(glibmm/private/object_p.h)
   34 
   35 #ifndef DOXYGEN_SHOULD_SKIP_THIS
   36 typedef struct _GAppInfoIface GAppInfoIface;
   37 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
   38 
   39 namespace Gio
   40 {
   41 
   42 
   43 class GIOMM_API File;
   44 
   45 /** Application information, to describe applications installed on the system,
   46  * and launch them.
   47  * See also AppLaunchContext.
   48  *
   49  * @newin{2,16}
   50  */
   51 class GIOMM_API AppInfo : public Glib::Interface
   52 {
   53   _CLASS_INTERFACE(AppInfo, GAppInfo, G_APP_INFO, GAppInfoIface, , , GIOMM_API)
   54 
   55 public:
   56   _WRAP_ENUM(CreateFlags, GAppInfoCreateFlags, NO_GTYPE, decl_prefix GIOMM_API)
   57 
   58   static Glib::RefPtr<AppInfo> create_from_commandline(const std::string& commandline,
   59                                                        const std::string& application_name,
   60                                                        CreateFlags flags);
   61 
   62   /**  Creates a duplicate of this AppInfo.
   63    * @return A duplicate of this AppInfo.
   64    * @newin{2,36}
   65    */
   66   Glib::RefPtr<AppInfo> create_duplicate() const;
   67   _IGNORE(g_app_info_dup)
   68 
   69   // Note that the implementation of equal() is virtual via equal_vfunc().
   70   /** Checks if two AppInfo<!-- -->s are equal.
   71    * @param other The other AppInfo.
   72    * @return <tt>true</tt> if @a *this is equal to @a other, <tt>false</tt> otherwise.
   73    */
   74   _WRAP_METHOD(bool equal(const Glib::RefPtr<AppInfo>& other) const, g_app_info_equal)
   75 
   76   _WRAP_METHOD(std::string get_id() const, g_app_info_get_id)
   77   _WRAP_METHOD(std::string get_name() const, g_app_info_get_name)
   78   _WRAP_METHOD(std::string get_display_name() const, g_app_info_get_display_name)
   79   _WRAP_METHOD(std::string get_description() const, g_app_info_get_description)
   80   _WRAP_METHOD(std::string get_executable() const, g_app_info_get_executable)
   81   _WRAP_METHOD(std::string get_commandline() const, g_app_info_get_commandline)
   82 
   83   _WRAP_METHOD(Glib::RefPtr<Icon> get_icon(), g_app_info_get_icon, refreturn)
   84   _WRAP_METHOD(const Glib::RefPtr<const Icon> get_icon() const,
   85                g_app_info_get_icon,
   86                refreturn, constversion)
   87 
   88 #m4 _CONVERSION(`const std::vector< Glib::RefPtr<Gio::File> >&',`GList*',`Glib::ListHandler<Glib::RefPtr<Gio::File> >::vector_to_list($3).data ()')
   89 
   90   /** Launches the application. This passes the @a file to the launched application
   91    * as an argument, using the optional @a context to get information
   92    * about the details of the launcher (like what screen it is on).
   93    * On error, an exception will be thrown accordingly.
   94    *
   95    * Note that even if the launch is successful the application launched
   96    * can fail to start if it runs into problems during startup. There is
   97    * no way to detect this.
   98    *
   99    * Some URIs can be changed when passed through a GFile (for instance
  100    * unsupported uris with strange formats like mailto:), so if you have
  101    * a textual uri you want to pass in as argument, consider using
  102    * launch_uris() instead.
  103    *
  104    * On UNIX, this function sets the @c GIO_LAUNCHED_DESKTOP_FILE
  105    * environment variable with the path of the launched desktop file and
  106    * @c GIO_LAUNCHED_DESKTOP_FILE_PID to the process
  107    * id of the launched process. This can be used to ignore
  108    * @c GIO_LAUNCHED_DESKTOP_FILE, should it be inherited
  109    * by further processes. The @c DISPLAY and
  110    * @c DESKTOP_STARTUP_ID environment variables are also
  111    * set, based on information provided in @a context.
  112    * @param file A File object.
  113    * @param context An AppLaunchContext.
  114    * @return <tt>true</tt> on successful launch, <tt>false</tt> otherwise.
  115    *
  116    * @newin{2,30}
  117    */
  118   bool launch(const Glib::RefPtr<Gio::File>& file, const Glib::RefPtr<AppLaunchContext>& context);
  119 
  120   /** Launches the application. This passes the @a file to the launched application
  121    * as an argument.
  122    * On error, an exception will be thrown accordingly.
  123    *
  124    * Note that even if the launch is successful the application launched
  125    * can fail to start if it runs into problems during startup. There is
  126    * no way to detect this.
  127    *
  128    * Some URIs can be changed when passed through a GFile (for instance
  129    * unsupported uris with strange formats like mailto:), so if you have
  130    * a textual uri you want to pass in as argument, consider using
  131    * launch_uris() instead.
  132    *
  133    * On UNIX, this function sets the @c GIO_LAUNCHED_DESKTOP_FILE
  134    * environment variable with the path of the launched desktop file and
  135    * @c GIO_LAUNCHED_DESKTOP_FILE_PID to the process
  136    * id of the launched process. This can be used to ignore
  137    * @c GIO_LAUNCHED_DESKTOP_FILE, should it be inherited
  138    * by further processes. The @c DISPLAY and
  139    * @c DESKTOP_STARTUP_ID environment variables are also
  140    * set, based on information provided in @a context.
  141    * @param file A File object.
  142    * @return <tt>true</tt> on successful launch, <tt>false</tt> otherwise.
  143    *
  144    * @newin{2,30}
  145    */
  146   bool launch(const Glib::RefPtr<Gio::File>& file);
  147 
  148   _WRAP_METHOD(bool launch(const std::vector< Glib::RefPtr<Gio::File> >& files,
  149                            const Glib::RefPtr<AppLaunchContext>& context{?}),
  150                g_app_info_launch,
  151                errthrow)
  152 
  153   _WRAP_METHOD(bool supports_uris() const, g_app_info_supports_uris)
  154   _WRAP_METHOD(bool supports_files() const, g_app_info_supports_files)
  155 
  156    #m4 _CONVERSION(`const std::vector<std::string>&',`GList*',`Glib::ListHandler<std::string>::vector_to_list($3).data()')
  157 
  158   //TODO: I think we use Glib::ustring elsewhere for URIs:
  159   // 2019-03-14 kjellahl: Glibmm is inconsistent; Glib::ustring in convert.hg,
  160   // std::string in uriutils.hg.
  161   // The reporter of libxml++ bug https://bugzilla.gnome.org/show_bug.cgi?id=790034
  162   // proposes std::string.
  163   _WRAP_METHOD(bool launch_uris(const std::vector<std::string>& uris,
  164                                 const Glib::RefPtr<AppLaunchContext>& context{?}),
  165                g_app_info_launch_uris,
  166                errthrow)
  167 
  168   /** Launches the application. This passes the @a uri to the launched application
  169    * as an arguments, using the optional @a context to get information
  170    * about the details of the launcher (like what screen it is on).
  171    * On error, an exception will be thrown accordingly.
  172    *
  173    * Note that even if the launch is successful the application launched
  174    * can fail to start if it runs into problems during startup. There is
  175    * no way to detect this.
  176    * @param uri A URI to launch.
  177    * @param context An AppLaunchContext.
  178    * @return <tt>true</tt> on successful launch, <tt>false</tt> otherwise.
  179    *
  180    * @newin{2,30}
  181    */
  182   bool launch_uri(const std::string& uri, const Glib::RefPtr<AppLaunchContext>& context);
  183 
  184   /** A launch_uri() convenience overload.
  185    *
  186    * @newin{2,30}
  187    */
  188   bool launch_uri(const std::string& uris);
  189 
  190   _WRAP_METHOD(void launch_uris_async(const std::vector<std::string>& uris,
  191     const Glib::RefPtr<AppLaunchContext>& context{.},
  192     const SlotAsyncReady& slot{callback?},
  193     const Glib::RefPtr<Cancellable>& cancellable{.} = {}),
  194     g_app_info_launch_uris_async, slot_name slot, slot_callback SignalProxy_async_callback, newin "2,60")
  195   _WRAP_METHOD(bool launch_uris_finish(const Glib::RefPtr<AsyncResult>& result),
  196     g_app_info_launch_uris_finish, errthrow, newin "2,60")
  197 
  198   _WRAP_METHOD(bool should_show() const, g_app_info_should_show)
  199   // FIXME: use better terminology than delete/do_delete
  200   _WRAP_METHOD(bool can_delete() const, g_app_info_can_delete)
  201   _WRAP_METHOD(bool do_delete(), g_app_info_delete)
  202 
  203   _WRAP_METHOD(bool set_as_default_for_type(const std::string& content_type),
  204                g_app_info_set_as_default_for_type,
  205                errthrow)
  206   _WRAP_METHOD(bool set_as_default_for_extension(const std::string& extension),
  207                g_app_info_set_as_default_for_extension,
  208                errthrow)
  209   _WRAP_METHOD(bool add_supports_type(const std::string& content_type),
  210                g_app_info_add_supports_type,
  211                errthrow)
  212   _WRAP_METHOD(bool can_remove_supports_type() const, g_app_info_can_remove_supports_type)
  213   _WRAP_METHOD(bool remove_supports_type(const std::string& content_type),
  214                g_app_info_remove_supports_type,
  215                errthrow)
  216 
  217 #m4 _CONVERSION(`const char**', `std::vector<Glib::ustring>', `Glib::ArrayHandler<Glib::ustring>::array_to_vector($3, Glib::OWNERSHIP_NONE)')
  218   _WRAP_METHOD(std::vector<Glib::ustring> get_supported_types() const, g_app_info_get_supported_types)
  219 
  220   _WRAP_METHOD(bool set_as_last_used_for_type(const std::string& content_type), g_app_info_set_as_last_used_for_type, errthrow)
  221 
  222 #m4 _CONVERSION(`GList*',`std::vector<Glib::RefPtr<AppInfo>>',`Glib::ListHandler<Glib::RefPtr<AppInfo>, TypeTraits_AppInfo>::list_to_vector($3, Glib::OWNERSHIP_DEEP)')
  223   _WRAP_METHOD(static std::vector<Glib::RefPtr<AppInfo>> get_all(), g_app_info_get_all)
  224 
  225   _WRAP_METHOD(static std::vector<Glib::RefPtr<AppInfo>> get_all_for_type(const std::string& content_type), g_app_info_get_all_for_type)
  226   _WRAP_METHOD(static std::vector<Glib::RefPtr<AppInfo>> get_recommended_for_type(const std::string& content_type),
  227     g_app_info_get_recommended_for_type, newin "2,76")
  228   _WRAP_METHOD(static std::vector<Glib::RefPtr<AppInfo>> get_fallback_for_type(const std::string& content_type),
  229     g_app_info_get_fallback_for_type, newin "2,76")
  230 
  231   _WRAP_METHOD(static Glib::RefPtr<AppInfo> get_default_for_type(const std::string& content_type,
  232     bool must_support_uris = true), g_app_info_get_default_for_type)
  233   _WRAP_METHOD(static void get_default_for_type_async(const std::string& content_type, bool must_support_uris,
  234     const SlotAsyncReady& slot{callback?}, const Glib::RefPtr<Cancellable>& cancellable{.} = {}),
  235     g_app_info_get_default_for_type_async, slot_name slot, slot_callback SignalProxy_async_callback)
  236   _WRAP_METHOD(static Glib::RefPtr<AppInfo> get_default_for_type_finish(const Glib::RefPtr<AsyncResult>& result),
  237     g_app_info_get_default_for_type_finish, errthrow)
  238 
  239   _WRAP_METHOD(static Glib::RefPtr<AppInfo> get_default_for_uri_scheme(const std::string& uri_scheme),
  240     g_app_info_get_default_for_uri_scheme)
  241   _WRAP_METHOD(static void get_default_for_uri_scheme_async(const std::string& content_type,
  242     const SlotAsyncReady& slot{callback?}, const Glib::RefPtr<Cancellable>& cancellable{.} = {}),
  243     g_app_info_get_default_for_uri_scheme_async, slot_name slot, slot_callback SignalProxy_async_callback)
  244   _WRAP_METHOD(static Glib::RefPtr<AppInfo> get_default_for_uri_scheme_finish(const Glib::RefPtr<AsyncResult>& result),
  245     g_app_info_get_default_for_uri_scheme_finish, errthrow)
  246 
  247   _WRAP_METHOD(static void reset_type_associations(const std::string& content_type), g_app_info_reset_type_associations)
  248   _WRAP_METHOD(static bool launch_default_for_uri(const std::string& uri, const Glib::RefPtr<AppLaunchContext>& context{?}), g_app_info_launch_default_for_uri, errthrow)
  249 
  250   _WRAP_METHOD(static void launch_default_for_uri_async(const std::string& uri, const Glib::RefPtr<AppLaunchContext>& context{.?},
  251     const SlotAsyncReady& slot{callback?}, const Glib::RefPtr<Cancellable>& cancellable{.?}),
  252     g_app_info_launch_default_for_uri_async, slot_name slot, slot_callback SignalProxy_async_callback)
  253   _WRAP_METHOD(static bool launch_default_for_uri_finish(const Glib::RefPtr<AsyncResult>& result), g_app_info_launch_default_for_uri_finish, errthrow)
  254 
  255 protected:
  256   //_WRAP_VFUNC(Glib::RefPtr<AppInfo> dup(), "dup")
  257   //_WRAP_VFUNC(bool equal(const Glib::RefPtr<AppInfo>& appinfo2), "equal")
  258   //_WRAP_VFUNC(std::string get_id() const, "get_id")
  259   //_WRAP_VFUNC(std::string get_name() const, "get_name")
  260   //_WRAP_VFUNC(std::string get_description() const, "get_description")
  261   //_WRAP_VFUNC(std::string get_executable() const, "get_executable")
  262   //_WRAP_VFUNC(Glib::RefPtr<Icon> get_icon() const, "get_icon")
  263   //_WRAP_VFUNC(bool launch(const std::vector<Gio::File>& filenames, const Glib::RefPtr<AppLaunchContext>& context, GError** error), "launch")
  264   //_WRAP_VFUNC(bool supports_uris() const, "supports_uris")
  265   //_WRAP_VFUNC(bool supports_files() const, "supports_files")
  266   //_WRAP_VFUNC(bool launch_uris(const std::vector<std::string>& uris, const Glib::RefPtr<AppLaunchContext>& context, GError** error), "launch_uris")
  267   //_WRAP_VFUNC(bool should_show() const, "should_show")
  268   //_WRAP_VFUNC(bool set_as_default_for_type(const std::string& content_type, GError** error), "set_as_default_for_type")
  269   //_WRAP_VFUNC(bool set_as_default_for_extension(const std::string& extension, GError** error), "set_as_default_for_extension")
  270   //_WRAP_VFUNC(bool add_supports_type(const std::string& content_type, GError** error), "add_supports_type")
  271   //_WRAP_VFUNC(bool can_remove_supports_type() const, "can_remove_supports_type")
  272   //_WRAP_VFUNC(bool remove_supports_type(const std::string& content_type, GError** error), "remove_supports_type")
  273 };
  274 
  275 } // namespace Gio