~indicator-applet-developers/indicator-session/trunk.0.1

« back to all changes in this revision

Viewing changes to src/status-provider.c

  • Committer: Ted Gould
  • Date: 2009-07-27 04:47:27 UTC
  • mfrom: (9.1.94 fusa.libindicator)
  • Revision ID: ted@canonical.com-20090727044727-m04ul5d8sxqt2pd4
Merging in the branch to port everything to libindicator and fleshing thigns out.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifdef HAVE_CONFIG_H
 
2
#include "config.h"
 
3
#endif
 
4
 
 
5
#include "status-provider.h"
 
6
 
 
7
/* Signals */
 
8
enum {
 
9
        STATUS_CHANGED,
 
10
        LAST_SIGNAL
 
11
};
 
12
 
 
13
static guint signals[LAST_SIGNAL] = { 0 };
 
14
 
 
15
/* GObject Boilerplate */
 
16
static void status_provider_class_init (StatusProviderClass *klass);
 
17
static void status_provider_init       (StatusProvider *self);
 
18
 
 
19
G_DEFINE_TYPE (StatusProvider, status_provider, G_TYPE_OBJECT);
 
20
 
 
21
static void
 
22
status_provider_class_init (StatusProviderClass *klass)
 
23
{
 
24
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
25
 
 
26
        klass->status_changed = NULL;
 
27
 
 
28
        klass->set_status = NULL;
 
29
        klass->get_status = NULL;
 
30
 
 
31
        /**
 
32
                StatusProvider::status-changed:
 
33
                @arg0: The #StatusProvider object.
 
34
                @arg1: The new status #StatusProviderStatus
 
35
 
 
36
                Should be emitted by subclasses everytime that the status
 
37
                changes externally to us.
 
38
        */
 
39
        signals[STATUS_CHANGED]    = g_signal_new(STATUS_PROVIDER_SIGNAL_STATUS_CHANGED,
 
40
                                                  G_TYPE_FROM_CLASS(klass),
 
41
                                                  G_SIGNAL_RUN_LAST,
 
42
                                                  G_STRUCT_OFFSET(StatusProviderClass, status_changed),
 
43
                                                  NULL, NULL,
 
44
                                                  g_cclosure_marshal_VOID__UINT,
 
45
                                                  G_TYPE_NONE, 1, G_TYPE_UINT);
 
46
 
 
47
        return;
 
48
}
 
49
 
 
50
static void
 
51
status_provider_init (StatusProvider *self)
 
52
{
 
53
 
 
54
        return;
 
55
}
 
56
 
 
57
void
 
58
status_provider_set_status (StatusProvider * sp, StatusProviderStatus status)
 
59
{
 
60
        g_return_if_fail(IS_STATUS_PROVIDER(sp));
 
61
 
 
62
        StatusProviderClass * class = STATUS_PROVIDER_GET_CLASS(sp);
 
63
        g_return_if_fail(class != NULL);
 
64
        g_return_if_fail(class->set_status != NULL);
 
65
 
 
66
        return class->set_status(sp, status);
 
67
}
 
68
 
 
69
StatusProviderStatus
 
70
status_provider_get_status (StatusProvider * sp)
 
71
{
 
72
        g_return_val_if_fail(IS_STATUS_PROVIDER(sp), STATUS_PROVIDER_STATUS_OFFLINE);
 
73
 
 
74
        StatusProviderClass * class = STATUS_PROVIDER_GET_CLASS(sp);
 
75
        g_return_val_if_fail(class->get_status != NULL, STATUS_PROVIDER_STATUS_OFFLINE);
 
76
 
 
77
        return class->get_status(sp);
 
78
}
 
79
 
 
80
void
 
81
status_provider_emit_status_changed (StatusProvider * sp, StatusProviderStatus newstatus)
 
82
{
 
83
        g_return_if_fail(IS_STATUS_PROVIDER(sp));
 
84
        g_signal_emit(sp, signals[STATUS_CHANGED], 0, newstatus, TRUE);
 
85
        return;
 
86
}