aboutsummaryrefslogtreecommitdiff
path: root/libindicate/indicator.c
blob: 8121cebcca5b193e0eec0a511096fad042d5a948 (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

#include "glib.h"
#include "glib/gmessages.h"
#include "indicator.h"

/* Signals */
enum {
	HIDE,
	SHOW,
	USER_DISPLAY,
	LAST_SIGNAL
};

static guint signals[LAST_SIGNAL] = { 0 };

G_DEFINE_TYPE (IndicateIndicator, indicate_indicator, G_TYPE_OBJECT);

static void indicate_indicator_finalize (GObject * object);


/* Functions */
static void
indicate_indicator_class_init (IndicateIndicatorClass * class)
{
	g_debug("Indicator Class Initialized.");

	GObjectClass * gobj;
	gobj = G_OBJECT_CLASS(class);

	gobj->finalize = indicate_indicator_finalize;

	signals[USER_DISPLAY] = g_signal_new(INDICATE_INDICATOR_SIGNAL_DISPLAY,
	                                     G_TYPE_FROM_CLASS(class),
	                                     G_SIGNAL_RUN_LAST,
	                                     G_STRUCT_OFFSET(IndicateIndicatorClass, user_display),
	                                     NULL, NULL,
	                                     g_cclosure_marshal_VOID__VOID,
	                                     G_TYPE_NONE, 0);
	signals[HIDE] = g_signal_new(INDICATE_INDICATOR_SIGNAL_HIDE,
	                                     G_TYPE_FROM_CLASS(class),
	                                     G_SIGNAL_RUN_LAST,
	                                     G_STRUCT_OFFSET(IndicateIndicatorClass, hide),
	                                     NULL, NULL,
	                                     g_cclosure_marshal_VOID__VOID,
	                                     G_TYPE_NONE, 0);
	signals[SHOW] = g_signal_new(INDICATE_INDICATOR_SIGNAL_SHOW,
	                                     G_TYPE_FROM_CLASS(class),
	                                     G_SIGNAL_RUN_LAST,
	                                     G_STRUCT_OFFSET(IndicateIndicatorClass, show),
	                                     NULL, NULL,
	                                     g_cclosure_marshal_VOID__VOID,
	                                     G_TYPE_NONE, 0);

	return;
}

static void
indicate_indicator_init (IndicateIndicator * indicator)
{
	g_debug("Indicator Object Initialized.");

	indicator->is_visible = FALSE;
	indicator->server = indicate_server_ref_default();
	indicator->id = indicate_server_get_next_id(indicator->server);
	indicate_server_add_indicator(indicator->server, indicator);

	return;
}

static void
indicate_indicator_finalize (GObject * obj)
{
	IndicateIndicator * indicator = INDICATE_INDICATOR(obj);

	indicate_server_remove_indicator(indicator->server, indicator);
	g_object_unref(indicator->server);
	indicator->server = NULL;

	return;
}

IndicateIndicator *
indicate_indicator_new (void)
{
	IndicateIndicator * indicator = g_object_new(INDICATE_TYPE_INDICATOR, NULL);
	return indicator;
}

void
indicate_indicator_show (IndicateIndicator * indicator)
{
	if (indicator->is_visible) {
		return;
	}

	if (indicator->server) {
		indicate_server_show(indicator->server);
	}

	indicator->is_visible = TRUE;
	g_signal_emit(indicator, signals[SHOW], 0, TRUE);
}

void
indicate_indicator_hide (IndicateIndicator * indicator)
{
	if (!indicator->is_visible) {
		return;
	}

	indicator->is_visible = FALSE;
	g_signal_emit(indicator, signals[HIDE], 0, TRUE);
}

gboolean
indicate_indicator_is_visible (IndicateIndicator * indicator)
{
	return indicator->is_visible;
}

guint
indicate_indicator_get_id (IndicateIndicator * indicator)
{
	g_return_val_if_fail(INDICATE_IS_INDICATOR(indicator), 0);
	return indicator->id;
}

const gchar *
indicate_indicator_get_indicator_type (IndicateIndicator * indicator)
{
	g_return_val_if_fail(INDICATE_IS_INDICATOR(indicator), NULL);
	IndicateIndicatorClass * class = INDICATE_INDICATOR_GET_CLASS(indicator);

	if (class->get_type != NULL) {
		return INDICATE_INDICATOR_GET_CLASS(indicator)->get_type(indicator);
	}

	return NULL;
}