~ubuntu-branches/ubuntu/utopic/almanah/utopic

« back to all changes in this revision

Viewing changes to src/widgets/hyperlink-tag.c

  • Committer: Package Import Robot
  • Author(s): Angel Abad
  • Date: 2012-10-29 10:14:18 UTC
  • mfrom: (1.4.1) (10.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20121029101418-k2c27xb0aku22zeg
Tags: 0.10.0-1~exp1
* Imported Upstream version 0.10.0
* debian/control:
  - Bump evolution Build-Depends ( >=3.6.0)
  - debian/control: Depends on evolution-common (>= 3.6.0)
* Bump Standards-Version to 3.9.4 (no changes)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
 
2
/*
 
3
 * Almanah
 
4
 * Copyright (C) Philip Withnall 2011 <philip@tecnocode.co.uk>
 
5
 *
 
6
 * Almanah is free software: you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation, either version 3 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * Almanah is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with Almanah.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
#include <glib.h>
 
21
#include <gtk/gtk.h>
 
22
 
 
23
#include "hyperlink-tag.h"
 
24
 
 
25
static void constructed (GObject *object);
 
26
static void get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
 
27
static void set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
 
28
static void finalize (GObject *object);
 
29
 
 
30
struct _AlmanahHyperlinkTagPrivate {
 
31
        gchar *uri;
 
32
};
 
33
 
 
34
enum {
 
35
        PROP_URI = 1
 
36
};
 
37
 
 
38
G_DEFINE_TYPE (AlmanahHyperlinkTag, almanah_hyperlink_tag, GTK_TYPE_TEXT_TAG)
 
39
 
 
40
static void
 
41
almanah_hyperlink_tag_class_init (AlmanahHyperlinkTagClass *klass)
 
42
{
 
43
        GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 
44
 
 
45
        g_type_class_add_private (klass, sizeof (AlmanahHyperlinkTagPrivate));
 
46
 
 
47
        gobject_class->constructed = constructed;
 
48
        gobject_class->get_property = get_property;
 
49
        gobject_class->set_property = set_property;
 
50
        gobject_class->finalize = finalize;
 
51
 
 
52
        g_object_class_install_property (gobject_class, PROP_URI,
 
53
                                         g_param_spec_string ("uri",
 
54
                                                              "URI", "The URI which this hyperlink points to.",
 
55
                                                              NULL,
 
56
                                                              G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
57
}
 
58
 
 
59
static void
 
60
almanah_hyperlink_tag_init (AlmanahHyperlinkTag *self)
 
61
{
 
62
        self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, ALMANAH_TYPE_HYPERLINK_TAG, AlmanahHyperlinkTagPrivate);
 
63
        self->priv->uri = NULL;
 
64
}
 
65
 
 
66
static void
 
67
constructed (GObject *object)
 
68
{
 
69
        /* Chain up to the parent class */
 
70
        G_OBJECT_CLASS (almanah_hyperlink_tag_parent_class)->constructed (object);
 
71
 
 
72
        /* Set our default appearance */
 
73
        g_object_set (object,
 
74
                      "foreground", "blue",
 
75
                      "underline", PANGO_UNDERLINE_SINGLE,
 
76
                      NULL);
 
77
}
 
78
 
 
79
static void
 
80
get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
 
81
{
 
82
        AlmanahHyperlinkTagPrivate *priv = ALMANAH_HYPERLINK_TAG (object)->priv;
 
83
 
 
84
        switch (property_id) {
 
85
                case PROP_URI:
 
86
                        g_value_set_string (value, priv->uri);
 
87
                        break;
 
88
                default:
 
89
                        /* We don't have any other property... */
 
90
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
91
                        break;
 
92
        }
 
93
}
 
94
 
 
95
static void
 
96
set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
 
97
{
 
98
        switch (property_id) {
 
99
                case PROP_URI:
 
100
                        almanah_hyperlink_tag_set_uri (ALMANAH_HYPERLINK_TAG (object), g_value_get_string (value));
 
101
                        break;
 
102
                default:
 
103
                        /* We don't have any other property... */
 
104
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
105
                        break;
 
106
        }
 
107
}
 
108
 
 
109
static void
 
110
finalize (GObject *object)
 
111
{
 
112
        AlmanahHyperlinkTagPrivate *priv = ALMANAH_HYPERLINK_TAG (object)->priv;
 
113
 
 
114
        g_free (priv->uri);
 
115
 
 
116
        /* Chain up to the parent class */
 
117
        G_OBJECT_CLASS (almanah_hyperlink_tag_parent_class)->finalize (object);
 
118
}
 
119
 
 
120
AlmanahHyperlinkTag *
 
121
almanah_hyperlink_tag_new (const gchar *uri)
 
122
{
 
123
        return g_object_new (ALMANAH_TYPE_HYPERLINK_TAG,
 
124
                             "uri", uri,
 
125
                             NULL);
 
126
}
 
127
 
 
128
const gchar *
 
129
almanah_hyperlink_tag_get_uri (AlmanahHyperlinkTag *self)
 
130
{
 
131
        g_return_val_if_fail (ALMANAH_IS_HYPERLINK_TAG (self), NULL);
 
132
 
 
133
        return self->priv->uri;
 
134
}
 
135
 
 
136
void
 
137
almanah_hyperlink_tag_set_uri (AlmanahHyperlinkTag *self, const gchar *uri)
 
138
{
 
139
        g_return_if_fail (ALMANAH_IS_HYPERLINK_TAG (self));
 
140
        g_return_if_fail (uri != NULL && *uri != '\0');
 
141
 
 
142
        g_free (self->priv->uri);
 
143
        self->priv->uri = g_strdup (uri);;
 
144
        g_object_notify (G_OBJECT (self), "uri");
 
145
}