gbp-flatpak-configuration.c 10.8 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* gbp-flatpak-configuration.c
 *
 * Copyright (C) 2016 Matthew Leeds <mleeds@redhat.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#define G_LOG_DOMAIN "gbp-flatpak-configuration"

#include "gbp-flatpak-configuration.h"
Christian Hergert's avatar
Christian Hergert committed
22
#include "gbp-flatpak-runtime.h"
23
24
25
26
27

struct _GbpFlatpakConfiguration
{
  IdeConfiguration parent_instance;

28
29
30
31
32
33
34
  gchar  *branch;
  gchar  *command;
  gchar **finish_args;
  GFile  *manifest;
  gchar  *platform;
  gchar  *primary_module;
  gchar  *sdk;
35
36
37
38
39
40
};

G_DEFINE_TYPE (GbpFlatpakConfiguration, gbp_flatpak_configuration, IDE_TYPE_CONFIGURATION)

enum {
  PROP_0,
41
42
43
  PROP_BRANCH,
  PROP_COMMAND,
  PROP_FINISH_ARGS,
44
  PROP_MANIFEST,
45
  PROP_PLATFORM,
46
  PROP_PRIMARY_MODULE,
47
  PROP_SDK,
48
49
50
51
52
  N_PROPS
};

static GParamSpec *properties [N_PROPS];

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
const gchar *
gbp_flatpak_configuration_get_branch (GbpFlatpakConfiguration *self)
{
  g_return_val_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self), NULL);

  return self->branch;
}

void
gbp_flatpak_configuration_set_branch (GbpFlatpakConfiguration *self,
                                      const gchar             *branch)
{
  g_return_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self));

  g_free (self->branch);
  self->branch = g_strdup (branch);
  g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_BRANCH]);
}

const gchar *
gbp_flatpak_configuration_get_command (GbpFlatpakConfiguration *self)
{
  g_return_val_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self), NULL);

  return self->command;
}

void
gbp_flatpak_configuration_set_command (GbpFlatpakConfiguration *self,
                                       const gchar             *command)
{
  g_return_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self));

  g_free (self->command);
  self->command = g_strdup (command);
  g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_COMMAND]);
}

const gchar * const *
gbp_flatpak_configuration_get_finish_args (GbpFlatpakConfiguration *self)
{
  g_return_val_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self), NULL);

  return (const gchar * const *)self->finish_args;
}

void
gbp_flatpak_configuration_set_finish_args (GbpFlatpakConfiguration *self,
                                           const gchar * const     *finish_args)
{
  g_return_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self));

  if (self->finish_args != (gchar **)finish_args)
    {
      g_strfreev (self->finish_args);
      self->finish_args = g_strdupv ((gchar **)finish_args);
      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_FINISH_ARGS]);
    }
}

gchar *
gbp_flatpak_configuration_get_manifest_path (GbpFlatpakConfiguration *self)
{
  g_return_val_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self), NULL);

  if (self->manifest != NULL)
    return g_file_get_path (self->manifest);

  return NULL;
}

Matthew Leeds's avatar
Matthew Leeds committed
124
125
GFile *
gbp_flatpak_configuration_get_manifest (GbpFlatpakConfiguration *self)
126
127
128
129
130
131
{
  g_return_val_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self), NULL);

  return self->manifest;
}

132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
const gchar *
gbp_flatpak_configuration_get_platform (GbpFlatpakConfiguration *self)
{
  g_return_val_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self), NULL);

  return self->platform;
}

void
gbp_flatpak_configuration_set_platform (GbpFlatpakConfiguration *self,
                                        const gchar             *platform)
{
  g_return_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self));

  g_free (self->platform);
  self->platform = g_strdup (platform);
  g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_PLATFORM]);
}

151
152
153
154
155
156
157
158
159
160
const gchar *
gbp_flatpak_configuration_get_primary_module (GbpFlatpakConfiguration *self)
{
  g_return_val_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self), NULL);

  return self->primary_module;
}

void
gbp_flatpak_configuration_set_primary_module (GbpFlatpakConfiguration *self,
161
                                              const gchar             *primary_module)
162
163
164
165
166
{
  g_return_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self));

  g_free (self->primary_module);
  self->primary_module = g_strdup (primary_module);
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
  g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_PRIMARY_MODULE]);
}

const gchar *
gbp_flatpak_configuration_get_sdk (GbpFlatpakConfiguration *self)
{
  g_return_val_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self), NULL);

  return self->sdk;
}

void
gbp_flatpak_configuration_set_sdk (GbpFlatpakConfiguration *self,
                                   const gchar             *sdk)
{
  g_return_if_fail (GBP_IS_FLATPAK_CONFIGURATION (self));

184
185
186
187
188
189
  if (g_strcmp0 (self->sdk, sdk) != 0)
    {
      g_free (self->sdk);
      self->sdk = g_strdup (sdk);
      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_SDK]);
    }
190
191
192
193
194
195
196
197
198
199
200
201
}

static void
gbp_flatpak_configuration_get_property (GObject    *object,
                                        guint       prop_id,
                                        GValue     *value,
                                        GParamSpec *pspec)
{
  GbpFlatpakConfiguration *self = GBP_FLATPAK_CONFIGURATION (object);

  switch (prop_id)
    {
202
203
204
205
206
207
208
209
210
211
212
213
    case PROP_BRANCH:
      g_value_set_string (value, gbp_flatpak_configuration_get_branch (self));
      break;

    case PROP_COMMAND:
      g_value_set_string (value, gbp_flatpak_configuration_get_command (self));
      break;

    case PROP_FINISH_ARGS:
      g_value_set_boxed (value, gbp_flatpak_configuration_get_finish_args (self));
      break;

214
215
216
217
    case PROP_MANIFEST:
      g_value_set_object (value, gbp_flatpak_configuration_get_manifest (self));
      break;

218
219
220
221
    case PROP_PLATFORM:
      g_value_set_string (value, gbp_flatpak_configuration_get_platform (self));
      break;

222
223
224
225
    case PROP_PRIMARY_MODULE:
      g_value_set_string (value, gbp_flatpak_configuration_get_primary_module (self));
      break;

226
227
228
229
    case PROP_SDK:
      g_value_set_string (value, gbp_flatpak_configuration_get_sdk (self));
      break;

230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
    }
}

static void
gbp_flatpak_configuration_set_property (GObject      *object,
                                        guint         prop_id,
                                        const GValue *value,
                                        GParamSpec   *pspec)
{
  GbpFlatpakConfiguration *self = GBP_FLATPAK_CONFIGURATION (object);

  switch (prop_id)
    {
245
246
247
248
249
250
251
252
253
254
255
256
    case PROP_BRANCH:
      gbp_flatpak_configuration_set_branch (self, g_value_get_string (value));
      break;

    case PROP_COMMAND:
      gbp_flatpak_configuration_set_command (self, g_value_get_string (value));
      break;

    case PROP_FINISH_ARGS:
      gbp_flatpak_configuration_set_finish_args (self, g_value_get_boxed (value));
      break;

257
258
259
260
    case PROP_MANIFEST:
      self->manifest = g_value_dup_object (value);
      break;

261
262
263
264
    case PROP_PLATFORM:
      gbp_flatpak_configuration_set_platform (self, g_value_get_string (value));
      break;

265
266
267
268
    case PROP_PRIMARY_MODULE:
      gbp_flatpak_configuration_set_primary_module (self, g_value_get_string (value));
      break;

269
270
271
272
    case PROP_SDK:
      gbp_flatpak_configuration_set_sdk (self, g_value_get_string (value));
      break;

273
274
275
276
277
278
279
280
281
282
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
    }
}

static void
gbp_flatpak_configuration_finalize (GObject *object)
{
  GbpFlatpakConfiguration *self = (GbpFlatpakConfiguration *)object;

283
284
285
  g_clear_pointer (&self->branch, g_free);
  g_clear_pointer (&self->command, g_free);
  g_clear_pointer (&self->finish_args, g_strfreev);
286
  g_clear_object (&self->manifest);
287
  g_clear_pointer (&self->platform, g_free);
288
  g_clear_pointer (&self->primary_module, g_free);
289
  g_clear_pointer (&self->sdk, g_free);
290
291
292
293
294
295
296
297
298
299
300
301
302

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

static void
gbp_flatpak_configuration_class_init (GbpFlatpakConfigurationClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->finalize = gbp_flatpak_configuration_finalize;
  object_class->get_property = gbp_flatpak_configuration_get_property;
  object_class->set_property = gbp_flatpak_configuration_set_property;

303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
  properties [PROP_BRANCH] =
    g_param_spec_string ("branch",
                         "Branch",
                         "Branch",
                         NULL,
                         (G_PARAM_READWRITE |
                          G_PARAM_CONSTRUCT |
                          G_PARAM_STATIC_STRINGS));

  properties [PROP_COMMAND] =
    g_param_spec_string ("command",
                         "Command",
                         "Command",
                         NULL,
                         (G_PARAM_READWRITE |
                          G_PARAM_CONSTRUCT |
                          G_PARAM_STATIC_STRINGS));

  properties [PROP_FINISH_ARGS] =
    g_param_spec_boxed ("finish-args",
                        "Finish args",
                        "Finish args",
                        G_TYPE_STRV,
                        (G_PARAM_READWRITE |
                         G_PARAM_CONSTRUCT |
                         G_PARAM_STATIC_STRINGS));

330
331
332
333
334
335
336
337
338
  properties [PROP_MANIFEST] =
    g_param_spec_object ("manifest",
                         "Manifest",
                         "Manifest file",
                         G_TYPE_FILE,
                         (G_PARAM_READWRITE |
                          G_PARAM_CONSTRUCT |
                          G_PARAM_STATIC_STRINGS));

339
340
341
342
343
344
345
346
347
  properties [PROP_PLATFORM] =
    g_param_spec_string ("platform",
                         "Platform",
                         "Platform",
                         NULL,
                         (G_PARAM_READWRITE |
                          G_PARAM_CONSTRUCT |
                          G_PARAM_STATIC_STRINGS));

348
349
350
351
352
353
354
355
356
  properties [PROP_PRIMARY_MODULE] =
    g_param_spec_string ("primary-module",
                         "Primary module",
                         "Primary module",
                         NULL,
                         (G_PARAM_READWRITE |
                          G_PARAM_CONSTRUCT |
                          G_PARAM_STATIC_STRINGS));

357
358
359
360
361
362
363
364
365
  properties [PROP_SDK] =
    g_param_spec_string ("sdk",
                         "Sdk",
                         "Sdk",
                         NULL,
                         (G_PARAM_READWRITE |
                          G_PARAM_CONSTRUCT |
                          G_PARAM_STATIC_STRINGS));

366
367
368
369
370
371
  g_object_class_install_properties (object_class, N_PROPS, properties);
}

static void
gbp_flatpak_configuration_init (GbpFlatpakConfiguration *self)
{
372
  ide_configuration_set_prefix (IDE_CONFIGURATION (self), "/app");
373
}