~midori/midori/trunk

« back to all changes in this revision

Viewing changes to midori/midori-extension.c

  • Committer: Christian Dywan
  • Date: 2008-11-18 01:07:53 UTC
  • Revision ID: git-v1:3cd50f419b55c8ac81d557ddf5764f78bffd75ff
Introduce a C extension interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 Copyright (C) 2008 Christian Dywan <christian@twotoasts.de>
 
3
 
 
4
 This library is free software; you can redistribute it and/or
 
5
 modify it under the terms of the GNU Lesser General Public
 
6
 License as published by the Free Software Foundation; either
 
7
 version 2.1 of the License, or (at your option) any later version.
 
8
 
 
9
 See the file COPYING for the full license text.
 
10
*/
 
11
 
 
12
#include "midori-extension.h"
 
13
 
 
14
#include <katze/katze.h>
 
15
 
 
16
G_DEFINE_TYPE (MidoriExtension, midori_extension, G_TYPE_OBJECT);
 
17
 
 
18
struct _MidoriExtensionPrivate
 
19
{
 
20
    gchar* name;
 
21
    gchar* description;
 
22
    gchar* version;
 
23
    gchar* authors;
 
24
};
 
25
 
 
26
enum
 
27
{
 
28
    PROP_0,
 
29
 
 
30
    PROP_NAME,
 
31
    PROP_DESCRIPTION,
 
32
    PROP_VERSION,
 
33
    PROP_AUTHORS
 
34
};
 
35
 
 
36
static void
 
37
midori_extension_finalize (GObject* object);
 
38
 
 
39
static void
 
40
midori_extension_set_property (GObject*      object,
 
41
                               guint         prop_id,
 
42
                               const GValue* value,
 
43
                               GParamSpec*   pspec);
 
44
 
 
45
static void
 
46
midori_extension_get_property (GObject*    object,
 
47
                               guint       prop_id,
 
48
                               GValue*     value,
 
49
                               GParamSpec* pspec);
 
50
 
 
51
static void
 
52
midori_extension_class_init (MidoriExtensionClass* class)
 
53
{
 
54
    GObjectClass* gobject_class;
 
55
    GParamFlags flags;
 
56
 
 
57
    gobject_class = G_OBJECT_CLASS (class);
 
58
    gobject_class->finalize = midori_extension_finalize;
 
59
    gobject_class->set_property = midori_extension_set_property;
 
60
    gobject_class->get_property = midori_extension_get_property;
 
61
 
 
62
    flags = G_PARAM_READWRITE | G_PARAM_CONSTRUCT;
 
63
 
 
64
    g_object_class_install_property (gobject_class,
 
65
                                     PROP_NAME,
 
66
                                     g_param_spec_string (
 
67
                                     "name",
 
68
                                     "Name",
 
69
                                     "The name of the extension",
 
70
                                     NULL,
 
71
                                     flags));
 
72
 
 
73
    g_object_class_install_property (gobject_class,
 
74
                                     PROP_DESCRIPTION,
 
75
                                     g_param_spec_string (
 
76
                                     "description",
 
77
                                     "Description",
 
78
                                     "The description of the extension",
 
79
                                     NULL,
 
80
                                     flags));
 
81
 
 
82
    g_object_class_install_property (gobject_class,
 
83
                                     PROP_VERSION,
 
84
                                     g_param_spec_string (
 
85
                                     "version",
 
86
                                     "Version",
 
87
                                     "The version of the extension",
 
88
                                     NULL,
 
89
                                     flags));
 
90
 
 
91
    g_object_class_install_property (gobject_class,
 
92
                                     PROP_AUTHORS,
 
93
                                     g_param_spec_string (
 
94
                                     "authors",
 
95
                                     "Authors",
 
96
                                     "The authors of the extension",
 
97
                                     NULL,
 
98
                                     flags));
 
99
 
 
100
    g_type_class_add_private (class, sizeof (MidoriExtensionPrivate));
 
101
}
 
102
 
 
103
static void
 
104
midori_extension_init (MidoriExtension* extension)
 
105
{
 
106
    extension->priv = G_TYPE_INSTANCE_GET_PRIVATE (extension,
 
107
        MIDORI_TYPE_EXTENSION, MidoriExtensionPrivate);
 
108
}
 
109
 
 
110
static void
 
111
midori_extension_finalize (GObject* object)
 
112
{
 
113
    MidoriExtension* extension = MIDORI_EXTENSION (object);
 
114
 
 
115
    katze_assign (extension->priv->name, NULL);
 
116
    katze_assign (extension->priv->description, NULL);
 
117
    katze_assign (extension->priv->version, NULL);
 
118
    katze_assign (extension->priv->authors, NULL);
 
119
}
 
120
 
 
121
static void
 
122
midori_extension_set_property (GObject*      object,
 
123
                               guint         prop_id,
 
124
                               const GValue* value,
 
125
                               GParamSpec*   pspec)
 
126
{
 
127
    MidoriExtension* extension = MIDORI_EXTENSION (object);
 
128
 
 
129
    switch (prop_id)
 
130
    {
 
131
    case PROP_NAME:
 
132
        katze_assign (extension->priv->name, g_value_dup_string (value));
 
133
        break;
 
134
    case PROP_DESCRIPTION:
 
135
        katze_assign (extension->priv->description, g_value_dup_string (value));
 
136
        break;
 
137
    case PROP_VERSION:
 
138
        katze_assign (extension->priv->version, g_value_dup_string (value));
 
139
        break;
 
140
    case PROP_AUTHORS:
 
141
        katze_assign (extension->priv->authors, g_value_dup_string (value));
 
142
        break;
 
143
    default:
 
144
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
145
        break;
 
146
    }
 
147
}
 
148
 
 
149
static void
 
150
midori_extension_get_property (GObject*    object,
 
151
                               guint       prop_id,
 
152
                               GValue*     value,
 
153
                               GParamSpec* pspec)
 
154
{
 
155
    MidoriExtension* extension = MIDORI_EXTENSION (object);
 
156
 
 
157
    switch (prop_id)
 
158
    {
 
159
    case PROP_NAME:
 
160
        g_value_set_string (value, extension->priv->name);
 
161
        break;
 
162
    case PROP_DESCRIPTION:
 
163
        g_value_set_string (value, extension->priv->description);
 
164
        break;
 
165
    case PROP_VERSION:
 
166
        g_value_set_string (value, extension->priv->version);
 
167
        break;
 
168
    case PROP_AUTHORS:
 
169
        g_value_set_string (value, extension->priv->authors);
 
170
        break;
 
171
    default:
 
172
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
173
        break;
 
174
    }
 
175
}