[go: up one dir, main page]

File: snapd-app.c

package info (click to toggle)
snapd-glib 1.70-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,452 kB
  • sloc: ansic: 30,379; cpp: 15,591; makefile: 62; sh: 31
file content (322 lines) | stat: -rw-r--r-- 8,919 bytes parent folder | download | duplicates (2)
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/*
 * Copyright (C) 2016 Canonical Ltd.
 *
 * 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 or version 3 of the License.
 * See http://www.gnu.org/copyleft/lgpl.html the full text of the license.
 */

#include <string.h>

#include "snapd-app.h"
#include "snapd-enum-types.h"

/**
 * SECTION:snapd-app
 * @short_description: Application metadata
 * @include: snapd-glib/snapd-glib.h
 *
 * A #SnapdApp contains information about an application that snapd provides.
 * Apps are retrieved using snapd_snap_get_apps().
 */

/**
 * SnapdApp:
 *
 * #SnapdApp contains information about an app in a Snap.
 *
 * Snaps can contain apps which is a single binary executable.
 *
 * Since: 1.0
 */
struct _SnapdApp {
  GObject parent_instance;

  SnapdDaemonType daemon_type;
  gchar *name;
  gchar *snap;
  gchar *common_id;
  gchar *desktop_file;
  gboolean enabled;
  gboolean active;
};

enum {
  PROP_NAME = 1,
  PROP_ALIASES,
  PROP_DAEMON_TYPE,
  PROP_DESKTOP_FILE,
  PROP_SNAP,
  PROP_ACTIVE,
  PROP_ENABLED,
  PROP_COMMON_ID,
  PROP_LAST
};

G_DEFINE_TYPE(SnapdApp, snapd_app, G_TYPE_OBJECT)

/**
 * snapd_app_get_name:
 * @app: a #SnapdApp.
 *
 * Get the name of this app.
 *
 * Returns: a name.
 *
 * Since: 1.0
 */
const gchar *snapd_app_get_name(SnapdApp *self) {
  g_return_val_if_fail(SNAPD_IS_APP(self), NULL);
  return self->name;
}

/**
 * snapd_app_get_active:
 * @app: a #SnapdApp.
 *
 * Get if this service is active.
 *
 * Returns: %TRUE if active.
 *
 * Since: 1.25
 */
gboolean snapd_app_get_active(SnapdApp *self) {
  g_return_val_if_fail(SNAPD_IS_APP(self), FALSE);
  return self->active;
}

/**
 * snapd_app_get_aliases:
 * @app: a #SnapdApp.
 *
 * Get the aliases for this app.
 *
 * Returns: (transfer none) (array zero-terminated=1): the alias names.
 *
 * Since: 1.7
 * Deprecated: 1.25
 */
GStrv snapd_app_get_aliases(SnapdApp *self) {
  g_return_val_if_fail(SNAPD_IS_APP(self), NULL);
  return NULL;
}

/**
 * snapd_app_get_common_id:
 * @app: a #SnapdApp.
 *
 * Get the common ID associated with this app.
 *
 * Returns: (allow-none): an ID or %NULL.
 *
 * Since: 1.41
 */
const gchar *snapd_app_get_common_id(SnapdApp *self) {
  g_return_val_if_fail(SNAPD_IS_APP(self), NULL);
  return self->common_id;
}

/**
 * snapd_app_get_daemon_type:
 * @app: a #SnapdApp.
 *
 * Get the daemon type for this app.
 *
 * Returns: (allow-none): the daemon type or %NULL.
 *
 * Since: 1.9
 */
SnapdDaemonType snapd_app_get_daemon_type(SnapdApp *self) {
  g_return_val_if_fail(SNAPD_IS_APP(self), SNAPD_DAEMON_TYPE_NONE);
  return self->daemon_type;
}

/**
 * snapd_app_get_desktop_file:
 * @app: a #SnapdApp.
 *
 * Get the path to the desktop file for this app.
 *
 * Returns: (allow-none): a path or %NULL.
 *
 * Since: 1.14
 */
const gchar *snapd_app_get_desktop_file(SnapdApp *self) {
  g_return_val_if_fail(SNAPD_IS_APP(self), NULL);
  return self->desktop_file;
}

/**
 * snapd_app_get_enabled:
 * @app: a #SnapdApp.
 *
 * Get if this service is enabled.
 *
 * Returns: %TRUE if enabled.
 *
 * Since: 1.25
 */
gboolean snapd_app_get_enabled(SnapdApp *self) {
  g_return_val_if_fail(SNAPD_IS_APP(self), FALSE);
  return self->enabled;
}

/**
 * snapd_app_get_snap:
 * @app: a #SnapdApp.
 *
 * Get the snap this app is associated with.
 *
 * Returns: a snap name.
 *
 * Since: 1.25
 */
const gchar *snapd_app_get_snap(SnapdApp *self) {
  g_return_val_if_fail(SNAPD_IS_APP(self), NULL);
  return self->snap;
}

static void snapd_app_set_property(GObject *object, guint prop_id,
                                   const GValue *value, GParamSpec *pspec) {
  SnapdApp *self = SNAPD_APP(object);

  switch (prop_id) {
  case PROP_NAME:
    g_free(self->name);
    self->name = g_strdup(g_value_get_string(value));
    break;
  case PROP_ALIASES:
    break;
  case PROP_COMMON_ID:
    g_free(self->common_id);
    self->common_id = g_strdup(g_value_get_string(value));
    break;
  case PROP_DAEMON_TYPE:
    self->daemon_type = g_value_get_enum(value);
    break;
  case PROP_DESKTOP_FILE:
    g_free(self->desktop_file);
    self->desktop_file = g_strdup(g_value_get_string(value));
    break;
  case PROP_SNAP:
    g_free(self->snap);
    self->snap = g_strdup(g_value_get_string(value));
    break;
  case PROP_ACTIVE:
    self->active = g_value_get_boolean(value);
    break;
  case PROP_ENABLED:
    self->enabled = g_value_get_boolean(value);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
    break;
  }
}

static void snapd_app_get_property(GObject *object, guint prop_id,
                                   GValue *value, GParamSpec *pspec) {
  SnapdApp *self = SNAPD_APP(object);

  switch (prop_id) {
  case PROP_NAME:
    g_value_set_string(value, self->name);
    break;
  case PROP_ALIASES:
    g_value_set_boxed(value, NULL);
    break;
  case PROP_COMMON_ID:
    g_value_set_string(value, self->common_id);
    break;
  case PROP_DAEMON_TYPE:
    g_value_set_enum(value, self->daemon_type);
    break;
  case PROP_DESKTOP_FILE:
    g_value_set_string(value, self->desktop_file);
    break;
  case PROP_SNAP:
    g_value_set_string(value, self->snap);
    break;
  case PROP_ACTIVE:
    g_value_set_boolean(value, self->active);
    break;
  case PROP_ENABLED:
    g_value_set_boolean(value, self->enabled);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
    break;
  }
}

static void snapd_app_finalize(GObject *object) {
  SnapdApp *self = SNAPD_APP(object);

  g_clear_pointer(&self->name, g_free);
  g_clear_pointer(&self->common_id, g_free);
  g_clear_pointer(&self->desktop_file, g_free);
  g_clear_pointer(&self->snap, g_free);

  G_OBJECT_CLASS(snapd_app_parent_class)->finalize(object);
}

static void snapd_app_class_init(SnapdAppClass *klass) {
  GObjectClass *gobject_class = G_OBJECT_CLASS(klass);

  gobject_class->set_property = snapd_app_set_property;
  gobject_class->get_property = snapd_app_get_property;
  gobject_class->finalize = snapd_app_finalize;

  g_object_class_install_property(
      gobject_class, PROP_NAME,
      g_param_spec_string("name", "name", "App name", NULL,
                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
                              G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK |
                              G_PARAM_STATIC_BLURB));
  g_object_class_install_property(
      gobject_class, PROP_ALIASES,
      g_param_spec_boxed("aliases", "aliases", "App aliases", G_TYPE_STRV,
                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
                             G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK |
                             G_PARAM_STATIC_BLURB));
  g_object_class_install_property(
      gobject_class, PROP_COMMON_ID,
      g_param_spec_string("common-id", "common-id", "Common ID", NULL,
                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
                              G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK |
                              G_PARAM_STATIC_BLURB));
  g_object_class_install_property(
      gobject_class, PROP_DAEMON_TYPE,
      g_param_spec_enum("daemon-type", "daemon-type", "Daemon type",
                        SNAPD_TYPE_DAEMON_TYPE, SNAPD_DAEMON_TYPE_UNKNOWN,
                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
                            G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK |
                            G_PARAM_STATIC_BLURB));
  g_object_class_install_property(
      gobject_class, PROP_DESKTOP_FILE,
      g_param_spec_string(
          "desktop-file", "desktop-file", "App desktop file path", NULL,
          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_NAME |
              G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
  g_object_class_install_property(
      gobject_class, PROP_SNAP,
      g_param_spec_string("snap", "snap", "Snap name", NULL,
                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
                              G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK |
                              G_PARAM_STATIC_BLURB));
  g_object_class_install_property(
      gobject_class, PROP_ACTIVE,
      g_param_spec_boolean("active", "active", "TRUE if active", FALSE,
                           G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
                               G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK |
                               G_PARAM_STATIC_BLURB));
  g_object_class_install_property(
      gobject_class, PROP_ENABLED,
      g_param_spec_boolean("enabled", "enabled", "TRUE if enabled", FALSE,
                           G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
                               G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK |
                               G_PARAM_STATIC_BLURB));
}

static void snapd_app_init(SnapdApp *self) {}