"Fossies" - the Fresh Open Source Software Archive

Member "glibmm-2.74.0/gio/src/appinfo.ccg" (19 Sep 2022, 4092 Bytes) of package /linux/misc/glibmm-2.74.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) 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 #include <giomm/file.h>
   18 #include <glibmm/vectorutils.h>
   19 #include <giomm/slot_async.h>
   20 #include <gio/gio.h>
   21 
   22 namespace
   23 {
   24 /* Special type traits for pointers to the GAppInfo interface.
   25  * The partial specialization in glibmm/glib/glibmm/containerhandle_shared.h
   26  * is not well suited for interfaces which do not already have a wrapper.
   27  * Its to_cpp_type() calls Glib::wrap_auto() instead id Glib::wrap_auto_interface().
   28  * These type traits are used by Glib::ListHandler<>::list_to_vector() in
   29  * Gio::AppInfo::get_all() and Gio::AppInfo::get_all_for_type().
   30  * https://gitlab.gnome.org/GNOME/glibmm/-/issues/94
   31  */
   32 struct TypeTraits_AppInfo
   33 {
   34   using T = Gio::AppInfo;
   35   using CppType = Glib::RefPtr<T>;
   36   using CType = typename T::BaseObjectType*;
   37   using CTypeNonConst = typename T::BaseObjectType*;
   38 
   39   static CType to_c_type(const CppType& ptr) { return Glib::unwrap(ptr); }
   40   static CType to_c_type(CType ptr) { return ptr; }
   41   static CppType to_cpp_type(CType ptr) { return Glib::wrap(ptr, true); }
   42 
   43   static void release_c_type(CType ptr)
   44   {
   45     GLIBMM_DEBUG_UNREFERENCE(nullptr, ptr);
   46     g_object_unref(ptr);
   47   }
   48 };
   49 } // anonymous namespace
   50 
   51 namespace Gio
   52 {
   53 
   54 Glib::RefPtr<AppInfo>
   55 AppInfo::create_from_commandline(
   56   const std::string& commandline, const std::string& application_name, CreateFlags flags)
   57 {
   58   GAppInfo* capp_info = nullptr;
   59   GError* gerror = nullptr;
   60 
   61   capp_info = g_app_info_create_from_commandline(commandline.c_str(), application_name.c_str(),
   62     static_cast<GAppInfoCreateFlags>(flags), &gerror);
   63 
   64   if (gerror)
   65     ::Glib::Error::throw_exception(gerror);
   66 
   67   return Glib::wrap(capp_info);
   68 }
   69 
   70 Glib::RefPtr<AppInfo>
   71 AppInfo::create_duplicate() const
   72 {
   73   return Glib::wrap(g_app_info_dup(const_cast<GAppInfo*>(gobj())));
   74 }
   75 
   76 bool
   77 AppInfo::launch(
   78   const Glib::RefPtr<Gio::File>& file, const Glib::RefPtr<AppLaunchContext>& launch_context)
   79 {
   80   std::vector<Glib::RefPtr<Gio::File>> vec = { file };
   81 
   82   GError* gerror = nullptr;
   83   const bool retvalue = g_app_info_launch(gobj(),
   84     Glib::ListHandler<Glib::RefPtr<Gio::File>>::vector_to_list(vec).data(),
   85     Glib::unwrap(launch_context), &(gerror));
   86   if (gerror)
   87     ::Glib::Error::throw_exception(gerror);
   88 
   89   return retvalue;
   90 }
   91 
   92 bool
   93 AppInfo::launch(const Glib::RefPtr<Gio::File>& file)
   94 {
   95   std::vector<Glib::RefPtr<Gio::File>> vec = { file };
   96 
   97   GError* gerror = nullptr;
   98   const bool retvalue = g_app_info_launch(gobj(),
   99     Glib::ListHandler<Glib::RefPtr<Gio::File>>::vector_to_list(vec).data(), nullptr, &(gerror));
  100   if (gerror)
  101     ::Glib::Error::throw_exception(gerror);
  102 
  103   return retvalue;
  104 }
  105 
  106 bool
  107 AppInfo::launch_uri(const std::string& uri, const Glib::RefPtr<AppLaunchContext>& launch_context)
  108 {
  109   std::vector<std::string> vec = { uri };
  110 
  111   GError* gerror = nullptr;
  112   const bool retvalue =
  113     g_app_info_launch_uris(gobj(), Glib::ListHandler<std::string>::vector_to_list(vec).data(),
  114       Glib::unwrap(launch_context), &(gerror));
  115   if (gerror)
  116     ::Glib::Error::throw_exception(gerror);
  117 
  118   return retvalue;
  119 }
  120 
  121 bool
  122 AppInfo::launch_uri(const std::string& uri)
  123 {
  124   std::vector<std::string> vec = { uri };
  125 
  126   GError* gerror = nullptr;
  127   const bool retvalue = g_app_info_launch_uris(
  128     gobj(), Glib::ListHandler<std::string>::vector_to_list(vec).data(), nullptr, &(gerror));
  129   if (gerror)
  130     ::Glib::Error::throw_exception(gerror);
  131 
  132   return retvalue;
  133 }
  134 
  135 } // namespace Gio