summaryrefslogtreecommitdiff
path: root/gio/src/appinfo.hg
blob: 8d383ab158ca7d28aa66082b03f1b1565c27aa00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-

/* Copyright (C) 2007 The gtkmm Development Team
 *
 * 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 <exception>

#include <string>

#include <glibmm/interface.h>
#include <glibmm/object.h>
//#include <giomm/file.h>
#include <giomm/icon.h>

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

#ifndef DOXYGEN_SHOULD_SKIP_THIS
typedef struct _GAppInfoIface GAppInfoIface;
#endif /* DOXYGEN_SHOULD_SKIP_THIS */

namespace Gio
{

_WRAP_ENUM(AppInfoCreateFlags, GAppInfoCreateFlags, NO_GTYPE)

class AppInfo;
class File;

/** This is used to handle, for instance, startup notification and launching of the new application on the same screen as the launching window.
 * See also AppInfo.
 *
 * @newin{2,16}
 */
class AppLaunchContext : public Glib::Object
{
  _CLASS_GOBJECT(AppLaunchContext, GAppLaunchContext, G_APP_LAUNCH_CONTEXT, Glib::Object, GObject)

protected:
  _CTOR_DEFAULT()

public:
  _WRAP_CREATE()

#m4 _CONVERSION(`const Glib::ListHandle<std::string>&',`GList*',`$3.data()')
  _WRAP_METHOD(std::string get_display(const Glib::RefPtr<AppInfo>& info, const Glib::ListHandle< Glib::RefPtr<Gio::File> >& files),
               g_app_launch_context_get_display)

  _WRAP_METHOD(std::string get_startup_notify_id(const Glib::RefPtr<AppInfo>& info, const Glib::ListHandle< Glib::RefPtr<Gio::File> >& files),
               g_app_launch_context_get_startup_notify_id)
  _WRAP_METHOD(void launch_failed(const std::string& startup_notify_id),
               g_app_launch_context_launch_failed)
};

/** Application information, to describe applications installed on the system, 
 * and launch them.
 * See also AppLaunchContext.
 *
 * @newin{2,16}
 */
class AppInfo : public Glib::Interface
{
  _CLASS_INTERFACE(AppInfo, GAppInfo, G_APP_INFO, GAppInfoIface)

public:
  static Glib::RefPtr<AppInfo> create_from_commandline(const std::string& commandline,
                                                       const std::string& application_name,
                                                       AppInfoCreateFlags flags);

  //_IGNORE(g_app_info_dup)
  _IGNORE(g_app_info_equal)

  // Note that the implementation of equal() is virtual via equal_vfunc().
  _WRAP_METHOD(bool equal(const Glib::RefPtr<AppInfo>& other) const, g_app_info_equal)

  _WRAP_METHOD(std::string get_id() const, g_app_info_get_id)
  _WRAP_METHOD(std::string get_name() const, g_app_info_get_name)
  _WRAP_METHOD(std::string get_description() const, g_app_info_get_description)
  _WRAP_METHOD(std::string get_executable() const, g_app_info_get_executable)
  _WRAP_METHOD(std::string get_commandline() const, g_app_info_get_commandline)

  _WRAP_METHOD(Glib::RefPtr<Icon> get_icon(), g_app_info_get_icon, refreturn)
  _WRAP_METHOD(const Glib::RefPtr<const Icon> get_icon() const,
               g_app_info_get_icon,
               refreturn, constversion)

  _WRAP_METHOD(bool launch(const Glib::ListHandle<std::string>& files,
                           const Glib::RefPtr<AppLaunchContext>& launch_context),
               g_app_info_launch,
               errthrow)

  _WRAP_METHOD(bool supports_uris() const, g_app_info_supports_uris)
  _WRAP_METHOD(bool supports_files() const, g_app_info_supports_files)

  _WRAP_METHOD(bool launch_uris(const Glib::ListHandle<std::string>& uris,
                                GAppLaunchContext* launch_context),
               g_app_info_launch_uris,
               errthrow, deprecated "Use the method that takes an AppLaunchContext")

  //TODO: I think we use Glib::ustring elsewhere for URIs:
  _WRAP_METHOD(bool launch_uris(const Glib::ListHandle<std::string>& uris,
                                const Glib::RefPtr<AppLaunchContext>& launch_context{?}),
               g_app_info_launch_uris,
               errthrow)
                 
  _WRAP_METHOD(bool should_show() const, g_app_info_should_show)
  // FIXME: use better terminology than delete/do_delete
  _WRAP_METHOD(bool can_delete() const, g_app_info_can_delete)
  _WRAP_METHOD(bool do_delete(), g_app_info_delete)

  _WRAP_METHOD(bool set_as_default_for_type(const std::string& content_type),
               g_app_info_set_as_default_for_type,
               errthrow)
  _WRAP_METHOD(bool set_as_default_for_extension(const std::string& extension),
               g_app_info_set_as_default_for_extension,
               errthrow)
  _WRAP_METHOD(bool add_supports_type(const std::string& content_type),
               g_app_info_add_supports_type,
               errthrow)
  _WRAP_METHOD(bool can_remove_supports_type() const, g_app_info_can_remove_supports_type)
  _WRAP_METHOD(bool remove_supports_type(const std::string& content_type),
               g_app_info_remove_supports_type,
               errthrow)
#m4 _CONVERSION(`GList*',`Glib::ListHandle<Glib::RefPtr<AppInfo> >',`Glib::ListHandle<Glib::RefPtr<AppInfo> >($3, Glib::OWNERSHIP_SHALLOW)')
  _WRAP_METHOD(static Glib::ListHandle<Glib::RefPtr<AppInfo> > get_all(), g_app_info_get_all)
  _WRAP_METHOD(static Glib::ListHandle<Glib::RefPtr<AppInfo> > get_all_for_type(const std::string& content_type), g_app_info_get_all_for_type)
  _WRAP_METHOD(static Glib::RefPtr<AppInfo> get_default_for_type(const std::string& content_type, bool must_support_uris = true), g_app_info_get_default_for_type)
  _WRAP_METHOD(static Glib::RefPtr<AppInfo> get_default_for_uri_scheme(const std::string& uri_scheme), g_app_info_get_default_for_uri_scheme)
  _WRAP_METHOD(static void reset_type_associations(const std::string& content_type), g_app_info_reset_type_associations)
  _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)
  // same as above but without optional AppLaunchContext
  static bool launch_default_for_uri(const std::string& uri);

protected:
  //_WRAP_VFUNC(Glib::RefPtr<AppInfo> dup(), "dup")
  //_WRAP_VFUNC(bool equal(const Glib::RefPtr<AppInfo>& appinfo2), "equal")
  //_WRAP_VFUNC(std::string get_id() const, "get_id")
  //_WRAP_VFUNC(std::string get_name() const, "get_name")
  //_WRAP_VFUNC(std::string get_description() const, "get_description")
  //_WRAP_VFUNC(std::string get_executable() const, "get_executable")
  //_WRAP_VFUNC(Glib::RefPtr<Icon> get_icon() const, "get_icon")
#m4 _CONVERSION(`const Glib::ListHandle<std::string>&',`GList*',`$3.data()')
#m4 _CONVERSION(`GList*',`const Glib::ListHandle<std::string>&',`Glib::ListHandle<std::string>($3, Glib::OWNERSHIP_NONE)')
  //_WRAP_VFUNC(bool launch(const Glib::ListHandle<std::string>& filenames, const Glib::RefPtr<AppLaunchContext>& launch_context, GError** error), "launch")
  //_WRAP_VFUNC(bool supports_uris() const, "supports_uris")
  //_WRAP_VFUNC(bool supports_files() const, "supports_files")
  //_WRAP_VFUNC(bool launch_uris(const Glib::ListHandle<std::string>& uris, const Glib::RefPtr<AppLaunchContext>& launch_context, GError** error), "launch_uris")
  //_WRAP_VFUNC(bool should_show() const, "should_show")
  //_WRAP_VFUNC(bool set_as_default_for_type(const std::string& content_type, GError** error), "set_as_default_for_type")
  //_WRAP_VFUNC(bool set_as_default_for_extension(const std::string& extension, GError** error), "set_as_default_for_extension")
  //_WRAP_VFUNC(bool add_supports_type(const std::string& content_type, GError** error), "add_supports_type")
  //_WRAP_VFUNC(bool can_remove_supports_type() const, "can_remove_supports_type")
  //_WRAP_VFUNC(bool remove_supports_type(const std::string& content_type, GError** error), "remove_supports_type")
};

} // namespace Gio