aboutsummaryrefslogtreecommitdiffstats
path: root/src/app_info.c
blob: f1146cd5cd850dd7fbc8505306aaeada19c1faa3 (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
// SPDX-License-Identifier: Apache-2.0
/*
 * Copyright (C) 2021 Collabora Ltd
 */

#include <gio/gio.h>

#include "app_info.h"

struct _AppInfo {
    GObject parent_instance;

    gchar *app_id;
    gchar *name;
    gchar *icon_path;
    gchar *service;

    AppStatus status;

    /*
     * `runtime_data` is an opaque pointer depending on the app startup method.
     * It is set in by ProcessManager or SystemdManager.
     */
    gpointer runtime_data;
};

G_DEFINE_TYPE(AppInfo, app_info, G_TYPE_OBJECT);

/*
 * Initialization & cleanup functions
 */

static void app_info_dispose(GObject *object)
{
    AppInfo *self = APPLAUNCHD_APP_INFO(object);

    g_clear_pointer(&self->app_id, g_free);
    g_clear_pointer(&self->name, g_free);
    g_clear_pointer(&self->icon_path, g_free);
    g_clear_pointer(&self->service, g_free);
    g_clear_pointer(&self->runtime_data, g_free);

    G_OBJECT_CLASS(app_info_parent_class)->dispose(object);
}

static void app_info_finalize(GObject *object)
{
    G_OBJECT_CLASS(app_info_parent_class)->finalize(object);
}

static void app_info_class_init(AppInfoClass *klass)
{
    GObjectClass *object_class = (GObjectClass *)klass;

    object_class->dispose = app_info_dispose;
    object_class->finalize = app_info_finalize;
}

static void app_info_init(AppInfo *self)
{
}

/*
 * Public functions
 */

AppInfo *app_info_new(const gchar *app_id, const gchar *name,
                      const gchar *icon_path, const gchar *service)
{
    AppInfo *self = g_object_new(APPLAUNCHD_TYPE_APP_INFO, NULL);

    self->app_id = g_strdup(app_id);
    self->name = g_strdup(name);
    self->icon_path = g_strdup(icon_path);
    self->service = g_strdup(service);

    return self;
}

const gchar *app_info_get_app_id(AppInfo *self)
{
    g_return_val_if_fail(APPLAUNCHD_IS_APP_INFO(self), NULL);

    return self->app_id;
}

const gchar *app_info_get_name(AppInfo *self)
{
    g_return_val_if_fail(APPLAUNCHD_IS_APP_INFO(self), NULL);

    return self->name;
}

const gchar *app_info_get_icon_path(AppInfo *self)
{
    g_return_val_if_fail(APPLAUNCHD_IS_APP_INFO(self), NULL);

    return self->icon_path;
}

const gchar *app_info_get_service(AppInfo *self)
{
    g_return_val_if_fail(APPLAUNCHD_IS_APP_INFO(self), NULL);

    return self->service;
}

AppStatus app_info_get_status(AppInfo *self)
{
    g_return_val_if_fail(APPLAUNCHD_IS_APP_INFO(self), APP_STATUS_INACTIVE);

    return self->status;
}

gpointer app_info_get_runtime_data(AppInfo *self)
{
    g_return_val_if_fail(APPLAUNCHD_IS_APP_INFO(self), NULL);

    return self->runtime_data;
}

void app_info_set_runtime_data(AppInfo *self, gpointer runtime_data)
{
    g_return_if_fail(APPLAUNCHD_IS_APP_INFO(self));

    self->runtime_data = runtime_data;
}

void app_info_set_status(AppInfo *self, AppStatus status)
{
    g_return_if_fail(APPLAUNCHD_IS_APP_INFO(self));

    self->status = status;
}