summaryrefslogtreecommitdiff
path: root/lib/wireplumber/src/profile.c
blob: 291dc7f0e2c07d90e911bea2f37978f0048f15ec (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
#include "profile.h"

#include <wp/wp.h>

struct _AstalWpProfile {
    GObject parent_instance;

    gint index;
    gchar *description;
};

G_DEFINE_FINAL_TYPE(AstalWpProfile, astal_wp_profile, G_TYPE_OBJECT);

typedef enum {
    ASTAL_WP_PROFILE_PROP_INDEX = 1,
    ASTAL_WP_PROFILE_PROP_DESCRIPTION,
    ASTAL_WP_PROFILE_N_PROPERTIES,
} AstalWpProfileProperties;

static GParamSpec *astal_wp_profile_properties[ASTAL_WP_PROFILE_N_PROPERTIES] = {
    NULL,
};

gint astal_wp_profile_get_index(AstalWpProfile *self) { return self->index; }

const gchar *astal_wp_profile_get_description(AstalWpProfile *self) { return self->description; }

static void astal_wp_profile_get_property(GObject *object, guint property_id, GValue *value,
                                          GParamSpec *pspec) {
    AstalWpProfile *self = ASTAL_WP_PROFILE(object);

    switch (property_id) {
        case ASTAL_WP_PROFILE_PROP_INDEX:
            g_value_set_int(value, self->index);
            break;
        case ASTAL_WP_PROFILE_PROP_DESCRIPTION:
            g_value_set_string(value, self->description);
            break;
        default:
            G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
            break;
    }
}

static void astal_wp_profile_set_property(GObject *object, guint property_id, const GValue *value,
                                          GParamSpec *pspec) {
    AstalWpProfile *self = ASTAL_WP_PROFILE(object);

    switch (property_id) {
        case ASTAL_WP_PROFILE_PROP_INDEX:
            self->index = g_value_get_int(value);
            break;
        case ASTAL_WP_PROFILE_PROP_DESCRIPTION:
            g_free(self->description);
            self->description = g_strdup(g_value_get_string(value));
            break;
        default:
            G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
            break;
    }
}

static void astal_wp_profile_init(AstalWpProfile *self) { self->description = NULL; }

static void astal_wp_profile_finalize(GObject *object) {
    AstalWpProfile *self = ASTAL_WP_PROFILE(object);
    g_free(self->description);
}

static void astal_wp_profile_class_init(AstalWpProfileClass *class) {
    GObjectClass *object_class = G_OBJECT_CLASS(class);
    object_class->finalize = astal_wp_profile_finalize;
    object_class->get_property = astal_wp_profile_get_property;
    object_class->set_property = astal_wp_profile_set_property;

    astal_wp_profile_properties[ASTAL_WP_PROFILE_PROP_DESCRIPTION] =
        g_param_spec_string("description", "description", "description", NULL,
                            G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
    astal_wp_profile_properties[ASTAL_WP_PROFILE_PROP_INDEX] =
        g_param_spec_int("index", "index", "index", G_MININT, G_MAXINT, 0,
                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
    g_object_class_install_properties(object_class, ASTAL_WP_PROFILE_N_PROPERTIES,
                                      astal_wp_profile_properties);
}