aboutsummaryrefslogtreecommitdiffstats
path: root/e-util/e-emoticon.c
blob: c543e5241746df88f7a74bfaee8733143c10b676 (plain) (blame)
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
/*
 * e-emoticon.c
 *
 * Copyright (C) 2008 Novell, Inc.
 * Copyright (C) 2012 Dan Vrátil <dvratil@redhat.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 *
 * This program 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
 * General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include "e-emoticon.h"

#include <gtk/gtk.h>

static EEmoticon *
emoticon_copy (EEmoticon *emoticon)
{
    EEmoticon *copy;

    copy = g_slice_new (EEmoticon);
    copy->label = g_strdup (emoticon->label);
    copy->icon_name = g_strdup (emoticon->icon_name);
    copy->text_face = g_strdup (emoticon->text_face);

    return copy;
}

static void
emoticon_free (EEmoticon *emoticon)
{
    g_free (emoticon->label);
    g_free (emoticon->icon_name);
    g_free (emoticon->text_face);
    g_slice_free (EEmoticon, emoticon);
}

GType
e_emoticon_get_type (void)
{
    static GType type = 0;

    if (G_UNLIKELY (type == 0))
        type = g_boxed_type_register_static (
            "EEmoticon",
            (GBoxedCopyFunc) emoticon_copy,
            (GBoxedFreeFunc) emoticon_free);

    return type;
}

gboolean
e_emoticon_equal (EEmoticon *emoticon_a,
                  EEmoticon *emoticon_b)
{
    if (((emoticon_a == NULL) && (emoticon_b != NULL)) ||
        ((emoticon_a != NULL) && (emoticon_b == NULL)))
        return FALSE;

    if (emoticon_a == emoticon_b)
        return TRUE;

    if (g_strcmp0 (emoticon_a->label, emoticon_b->label) != 0)
        return FALSE;

    if (g_strcmp0 (emoticon_a->icon_name, emoticon_b->icon_name) != 0)
        return FALSE;

    if (g_strcmp0 (emoticon_a->text_face, emoticon_b->text_face) != 0)
        return FALSE;

    return TRUE;
}

EEmoticon *
e_emoticon_copy (EEmoticon *emoticon)
{
    return g_boxed_copy (E_TYPE_EMOTICON, emoticon);
}

void
e_emoticon_free (EEmoticon *emoticon)
{
    g_boxed_free (E_TYPE_EMOTICON, emoticon);
}

gchar *
e_emoticon_get_uri (EEmoticon *emoticon)
{
    GtkIconInfo *icon_info;
    GtkIconTheme *icon_theme;
    const gchar *filename;
    gchar *uri = NULL;

    icon_theme = gtk_icon_theme_get_default ();
    icon_info = gtk_icon_theme_lookup_icon (
        icon_theme, emoticon->icon_name, 16, 0);
    g_return_val_if_fail (icon_info != NULL, NULL);

    filename = gtk_icon_info_get_filename (icon_info);
    if (filename != NULL) {
        uri = g_filename_to_uri (filename, NULL, NULL);
    }
    gtk_icon_info_free (icon_info);
    g_return_val_if_fail (uri != NULL, NULL);

    return uri;
}