summaryrefslogtreecommitdiffstats
path: root/panels/sharing/cc-sharing-switch.c
blob: 4c752148be72f8a20aaeb5932dd2e4f562695025 (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
/*
 * Copyright (C) 2014 Bastien Nocera <hadess@hadess.net>
 *
 * 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 <gtk/gtk.h>
#include <gio/gio.h>
#include "cc-sharing-switch.h"

struct _CcSharingSwitch {
  GtkSwitch  parent_instance;

  GtkWidget *widget;
};

G_DEFINE_TYPE (CcSharingSwitch, cc_sharing_switch, GTK_TYPE_SWITCH)

enum {
  PROP_0,
  PROP_WIDGET
};

static void     cc_sharing_switch_class_init     (CcSharingSwitchClass *klass);
static void     cc_sharing_switch_init           (CcSharingSwitch      *self);
static void     cc_sharing_switch_finalize       (GObject                *object);

static void
cc_sharing_switch_constructed (GObject *object)
{
  CcSharingSwitch *self;
  GtkWidget *other_sw;

  G_OBJECT_CLASS (cc_sharing_switch_parent_class)->constructed (object);

  self = CC_SHARING_SWITCH (object);

  other_sw = g_object_get_data (G_OBJECT (self->widget), "switch");

  g_object_bind_property (other_sw, "visible", self, "visible", G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
  g_object_bind_property (other_sw, "state", self, "state", G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
  g_object_bind_property (other_sw, "active", self, "active", G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
  g_object_bind_property (other_sw, "sensitive", self, "sensitive", G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);

  gtk_widget_set_valign (GTK_WIDGET (self), GTK_ALIGN_CENTER);
}

static void
cc_sharing_switch_init (CcSharingSwitch *self)
{
}

GtkWidget *
cc_sharing_switch_new (GtkWidget *widget)
{
  g_return_val_if_fail (widget != NULL, NULL);

  return GTK_WIDGET (g_object_new (CC_TYPE_SHARING_SWITCH,
				   "widget", widget,
				   NULL));
}

static void
cc_sharing_switch_set_property (GObject      *object,
				  guint         prop_id,
				  const GValue *value,
				  GParamSpec   *pspec)
{
  CcSharingSwitch *self;

  self = CC_SHARING_SWITCH (object);

  switch (prop_id) {
  case PROP_WIDGET:
    self->widget = g_value_dup_object (value);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    break;
  }
}

static void
cc_sharing_switch_finalize (GObject *object)
{
  CcSharingSwitch *self;

  g_return_if_fail (object != NULL);
  g_return_if_fail (CC_IS_SHARING_SWITCH (object));

  self = CC_SHARING_SWITCH (object);

  g_return_if_fail (self != NULL);

  g_clear_object (&self->widget);

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

static void
cc_sharing_switch_class_init (CcSharingSwitchClass *klass)
{
  GObjectClass  *object_class = G_OBJECT_CLASS (klass);

  object_class->set_property = cc_sharing_switch_set_property;
  object_class->finalize = cc_sharing_switch_finalize;
  object_class->constructed = cc_sharing_switch_constructed;

  g_object_class_install_property (object_class,
                                   PROP_WIDGET,
                                   g_param_spec_object ("widget",
                                                        "widget",
                                                        "widget",
                                                        GTK_TYPE_WIDGET,
                                                        G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
}

/*
 * vim: sw=2 ts=8 cindent noai bs=2
 */