aboutsummaryrefslogtreecommitdiff
path: root/libplanfahr/lpf-trip.c
blob: 3f63e353dcf2bc92f7e590aa77a249010b0f6aac (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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*
 * lpf-loc.c: a trip via public transport
 *
 * Copyright (C) 2014 Guido Günther
 *
 * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 *
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#include <glob.h>
#include <string.h>
#include <math.h>

#include <glib.h>
#include <glib/gprintf.h>
#include <gmodule.h>

#include "lpf-enumtypes.h"
#include "lpf-trip.h"
#include "lpf-loc.h"
#include "lpf-priv.h"

enum {
    LPF_TRIP_PROP_0 = 0,
    LPF_TRIP_PROP_PARTS,
    LPF_TRIP_PROP_STATUS,
};

/**
 * SECTION:lpf-trip
 * @short_description: A trip via public transport
 *
 * A #LpfTrip represents a trip. It consists of several #LpfTripParts each with a start
 * and end location.
 */

G_DEFINE_TYPE (LpfTrip, lpf_trip, G_TYPE_OBJECT)
#define GET_PRIVATE(o) \
    (G_TYPE_INSTANCE_GET_PRIVATE ((o), LPF_TYPE_TRIP, LpfTripPrivate))

typedef struct _LpfTripPrivate LpfTripPrivate;
struct _LpfTripPrivate {
    GSList *parts;
    LpfTripStatusFlags status;
};

/**
 * lpf_trip_get_parts:
 * @self: A #LpfTrip
 *
 * Returns the individual parts of the trip.
 *
 * Returns: (transfer none) (element-type LpfTripPart): The parts of the trip.
 **/
GSList*
lpf_trip_get_parts(LpfTrip *self)
{
    GSList *parts;

    g_object_get(self, "parts", &parts, NULL);
    return parts;
}


static void
lpf_trip_set_property (GObject *object,
                      guint property_id,
                      const GValue *value,
                      GParamSpec *pspec)
{
    LpfTrip *self = LPF_TRIP (object);
    LpfTripPrivate *priv = GET_PRIVATE(self);

    switch (property_id) {
    case LPF_TRIP_PROP_PARTS:
        priv->parts = g_value_get_pointer(value);
        break;
    case LPF_TRIP_PROP_STATUS:
        priv->status = g_value_get_flags (value);
        break;
    default:
        /* We don't have any other property... */
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
        break;
    }
}

static void
lpf_trip_get_property (GObject *object,
                      guint property_id,
                      GValue *value,
                      GParamSpec *pspec)
{
    LpfTrip *self = LPF_TRIP (object);
    LpfTripPrivate *priv = GET_PRIVATE(self);

    switch (property_id) {
    case LPF_TRIP_PROP_PARTS:
        g_value_set_pointer (value, priv->parts);
        break;
    case LPF_TRIP_PROP_STATUS:
        g_value_set_flags (value, priv->status);
        break;
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
        break;
    }
}


static void
lpf_trip_dispose(GObject *object)
{
    GObjectClass *parent_class = G_OBJECT_CLASS (lpf_trip_parent_class);

    if (parent_class->dispose != NULL)
        parent_class->dispose (object);
}


static void
lpf_trip_finalize (GObject *object)
{
    LpfTrip *self = LPF_TRIP (object);
    LpfTripPrivate *priv = GET_PRIVATE (self);
    GObjectClass *parent_class = G_OBJECT_CLASS (lpf_trip_parent_class);

    g_slist_free_full (priv->parts, g_object_unref);

    parent_class->finalize (object);
}


static void
lpf_trip_class_init (LpfTripClass *klass)
{
    GObjectClass *object_class = G_OBJECT_CLASS (klass);

    object_class->dispose = lpf_trip_dispose;
    object_class->finalize = lpf_trip_finalize;
    g_type_class_add_private (klass, sizeof (LpfTripPrivate));

    object_class->set_property = lpf_trip_set_property;
    object_class->get_property = lpf_trip_get_property;


/**
 * LpfTrip:parts: (type GSList(LpfTripPart))
 *
 * The parts of a trip as #LpfTripPart.
 */
    g_object_class_install_property (object_class,
                                     LPF_TRIP_PROP_PARTS,
                                     g_param_spec_pointer ("parts",
                                                           "trip parts",
                                                           "The parts of the trip",
                                                           G_PARAM_CONSTRUCT | G_PARAM_READWRITE));

/**
 * LpfTrip:status: (type LpfTripStatusFlags)
 *
 * The status of this trip
 */
    g_object_class_install_property (object_class,
                                     LPF_TRIP_PROP_STATUS,
                                     g_param_spec_flags ("status",
                                                         "trip status",
                                                         "The statusof the trip",
                                                         LPF_TYPE_TRIP_STATUS_FLAGS,
                                                         LPF_TRIP_STATUS_FLAGS_NONE,
                                                         G_PARAM_CONSTRUCT |
                                                         G_PARAM_READWRITE |
                                                         G_PARAM_STATIC_STRINGS));
}

static void
lpf_trip_init (LpfTrip *self)
{
}