summaryrefslogtreecommitdiff
path: root/panels/network/panel-cell-renderer-security.c
blob: a964bcfde4107dd8af48e122d918f1b5729ede18 (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
/* -*- Security: C; tab-width: 8; indent-tabs-security: nil; c-basic-offset: 8 -*-
 *
 * Copyright (C) 2011 Red Hat, Inc
 *
 * Licensed under the GNU General Public License Version 2
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * 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 General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "config.h"

#include <glib.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>

#include "panel-cell-renderer-security.h"

enum {
        PROP_0,
        PROP_SECURITY,
        PROP_LAST
};

G_DEFINE_TYPE (PanelCellRendererSecurity, panel_cell_renderer_security, GTK_TYPE_CELL_RENDERER_PIXBUF)

static gpointer parent_class = NULL;

/**
 * panel_cell_renderer_security_get_property:
 **/
static void
panel_cell_renderer_security_get_property (GObject *object, guint param_id,
                                       GValue *value, GParamSpec *pspec)
{
        PanelCellRendererSecurity *renderer = PANEL_CELL_RENDERER_SECURITY (object);

        switch (param_id) {
        case PROP_SECURITY:
                g_value_set_uint (value, renderer->security);
                break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
                break;
        }
}

/**
 * panel_cell_renderer_set_name:
 **/
static void
panel_cell_renderer_set_name (PanelCellRendererSecurity *renderer)
{
        const gchar *icon_name = NULL;

        if (renderer->security != NM_AP_SEC_UNKNOWN &&
            renderer->security != NM_AP_SEC_NONE)
                icon_name = "network-wireless-encrypted-symbolic";

        if (icon_name != NULL) {
                g_object_set (renderer,
                              "icon-name", icon_name,
                              NULL);
        } else {
                g_object_set (renderer,
                              "icon-name", "",
                              NULL);
        }
}

/**
 * panel_cell_renderer_security_set_property:
 **/
static void
panel_cell_renderer_security_set_property (GObject *object, guint param_id,
                                       const GValue *value, GParamSpec *pspec)
{
        PanelCellRendererSecurity *renderer = PANEL_CELL_RENDERER_SECURITY (object);

        switch (param_id) {
        case PROP_SECURITY:
                renderer->security = g_value_get_uint (value);
                panel_cell_renderer_set_name (renderer);
                break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
                break;
        }
}

/**
 * panel_cell_renderer_finalize:
 **/
static void
panel_cell_renderer_finalize (GObject *object)
{
        PanelCellRendererSecurity *renderer;
        renderer = PANEL_CELL_RENDERER_SECURITY (object);
        g_free (renderer->icon_name);
        G_OBJECT_CLASS (parent_class)->finalize (object);
}

/**
 * panel_cell_renderer_security_class_init:
 **/
static void
panel_cell_renderer_security_class_init (PanelCellRendererSecurityClass *class)
{
        GObjectClass *object_class = G_OBJECT_CLASS (class);
        object_class->finalize = panel_cell_renderer_finalize;

        parent_class = g_type_class_peek_parent (class);

        object_class->get_property = panel_cell_renderer_security_get_property;
        object_class->set_property = panel_cell_renderer_security_set_property;

        g_object_class_install_property (object_class, PROP_SECURITY,
                                         g_param_spec_uint ("security", NULL,
                                                            NULL,
                                                            0, G_MAXUINT, 0,
                                                            G_PARAM_READWRITE));
}

/**
 * panel_cell_renderer_security_init:
 **/
static void
panel_cell_renderer_security_init (PanelCellRendererSecurity *renderer)
{
        renderer->security = 0;
        renderer->icon_name = NULL;
}

/**
 * panel_cell_renderer_security_new:
 **/
GtkCellRenderer *
panel_cell_renderer_security_new (void)
{
        return g_object_new (PANEL_TYPE_CELL_RENDERER_SECURITY, NULL);
}