summaryrefslogtreecommitdiff
path: root/demos/icon-browser/iconbrowsercontext.c
blob: edee71eff53b1a94276e0ade4bda3c0770d22959 (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
#include "iconbrowsercontext.h"

struct _IbContext
{
  GObject parent_instance;

  char *id;
  char *name;
  char *description;
};

struct _IbContextClass
{
  GObjectClass parent_class;
};

enum {
  PROP_ID = 1,
  PROP_NAME,
  PROP_DESCRIPTION,
  PROP_NUM_PROPERTIES
};

G_DEFINE_TYPE (IbContext, ib_context, G_TYPE_OBJECT)

static void
ib_context_init (IbContext *context)
{
}

static void
ib_context_finalize (GObject *object)
{
  IbContext *context = IB_CONTEXT (object);

  g_free (context->id);
  g_free (context->name);
  g_free (context->description);

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

static void
ib_context_set_property (GObject      *object,
                         guint         property_id,
                         const GValue *value,
                         GParamSpec   *pspec)
{
  IbContext *context = IB_CONTEXT (object);

  switch (property_id)
    {
    case PROP_ID:
      g_free (context->id);
      context->id = g_value_dup_string (value);
      break;

    case PROP_NAME:
      g_free (context->name);
      context->name = g_value_dup_string (value);
      break;

    case PROP_DESCRIPTION:
      g_free (context->description);
      context->description = g_value_dup_string (value);
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
    }
}

static void
ib_context_get_property (GObject    *object,
                      guint       property_id,
                      GValue     *value,
                      GParamSpec *pspec)
{
  IbContext *context = IB_CONTEXT (object);

  switch (property_id)
    {
    case PROP_ID:
      g_value_set_string (value, context->id);
      break;

    case PROP_NAME:
      g_value_set_string (value, context->name);
      break;

    case PROP_DESCRIPTION:
      g_value_set_string (value, context->description);
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
    }
}

static void
ib_context_class_init (IbContextClass *class)
{
  GObjectClass *object_class = G_OBJECT_CLASS (class);
  GParamSpec *pspec;

  object_class->finalize = ib_context_finalize;
  object_class->set_property = ib_context_set_property;
  object_class->get_property = ib_context_get_property;

  pspec = g_param_spec_string ("id", "Id", "Id",
                               NULL,
                               G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
  g_object_class_install_property (object_class, PROP_ID, pspec);

  pspec = g_param_spec_string ("name", "Name", "Name",
                               NULL,
                               G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
  g_object_class_install_property (object_class, PROP_NAME, pspec);

  pspec = g_param_spec_string ("description", "Description", "Description",
                               NULL,
                               G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
  g_object_class_install_property (object_class, PROP_DESCRIPTION, pspec);
}

IbContext *
ib_context_new (const char *id,
                const char *name,
                const char *description)
{
  return g_object_new (IB_TYPE_CONTEXT,
                       "id", id,
                       "name", name,
                       "description", description,
                       NULL);
}

const char *
ib_context_get_id (IbContext *context)
{
  return context->id;
}

const char *
ib_context_get_name (IbContext *context)
{
  return context->name;
}

const char *
ib_context_get_description (IbContext *context)
{
  return context->description;
}