ka-plugin-dummy.c 3.06 KB
Newer Older
Guido Günther's avatar
Guido Günther committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * Copyright (C) 2010 Guido Guenther <agx@sigxcpu.org>
 *
 * 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, 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
15
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
Guido Günther's avatar
Guido Günther committed
16 17 18 19 20 21 22 23 24 25 26 27
 */

#include "ka-plugin-dummy.h"
#include <gmodule.h>

G_DEFINE_TYPE (KaPluginDummy, ka_plugin_dummy, KA_TYPE_PLUGIN)
#define GET_PRIVATE(o) \
  (G_TYPE_INSTANCE_GET_PRIVATE ((o), KA_TYPE_PLUGIN_DUMMY, KaPluginDummyPrivate))

int ka_plugin_major_version = KA_PLUGIN_MAJOR_VERSION;
int ka_plugin_minor_version = KA_PLUGIN_MINOR_VERSION;

Guido Günther's avatar
Guido Günther committed
28
G_MODULE_EXPORT KaPlugin *
Guido Günther's avatar
Guido Günther committed
29 30
ka_plugin_create (void)
{
Guido Günther's avatar
Guido Günther committed
31
    return KA_PLUGIN (ka_plugin_dummy_new ());
Guido Günther's avatar
Guido Günther committed
32 33 34 35 36 37 38 39
}

typedef struct _KaPluginDummyPrivate KaPluginDummyPrivate;

struct _KaPluginDummyPrivate {
    gulong handlers[3];
};

Guido Günther's avatar
Guido Günther committed
40 41
static void
event_cb (gpointer *applet, gchar *princ, guint when, gpointer user_data)
Guido Günther's avatar
Guido Günther committed
42
{
Guido Günther's avatar
Guido Günther committed
43
    g_message ("%s %s @%d", user_data, princ, when);
Guido Günther's avatar
Guido Günther committed
44 45 46 47 48
}

static void
ka_plugin_dummy_finalize (GObject *object)
{
Guido Günther's avatar
Guido Günther committed
49
    G_OBJECT_CLASS (ka_plugin_dummy_parent_class)->finalize (object);
Guido Günther's avatar
Guido Günther committed
50 51 52
}

static void
Guido Günther's avatar
Guido Günther committed
53
ka_plugin_dummy_activate (KaPlugin *self, KaApplet *applet)
Guido Günther's avatar
Guido Günther committed
54
{
Guido Günther's avatar
Guido Günther committed
55 56 57 58 59 60 61 62 63 64 65
    KaPluginDummyPrivate *priv = GET_PRIVATE (self);

    priv->handlers[0] = g_signal_connect (applet,
                                          "krb-tgt-expired",
                                          G_CALLBACK (event_cb), "Expired");
    priv->handlers[1] = g_signal_connect (applet,
                                          "krb-tgt-acquired",
                                          G_CALLBACK (event_cb), "Acquired");
    priv->handlers[2] = g_signal_connect (applet,
                                          "krb-tgt-renewed",
                                          G_CALLBACK (event_cb), "Renewed");
Guido Günther's avatar
Guido Günther committed
66 67 68
}

static void
Guido Günther's avatar
Guido Günther committed
69
ka_plugin_dummy_deactivate (KaPlugin *self, KaApplet *applet)
Guido Günther's avatar
Guido Günther committed
70
{
Guido Günther's avatar
Guido Günther committed
71 72
    int i;
    KaPluginDummyPrivate *priv = GET_PRIVATE (self);
Guido Günther's avatar
Guido Günther committed
73

Guido Günther's avatar
Guido Günther committed
74 75
    for (i = 0; i < G_N_ELEMENTS (priv->handlers); i++)
        g_signal_handler_disconnect (applet, priv->handlers[i]);
Guido Günther's avatar
Guido Günther committed
76 77 78 79 80
}

static void
ka_plugin_dummy_class_init (KaPluginDummyClass *klass)
{
Guido Günther's avatar
Guido Günther committed
81 82
    GObjectClass *object_class = G_OBJECT_CLASS (klass);
    KaPluginClass *plugin_class = KA_PLUGIN_CLASS (klass);
Guido Günther's avatar
Guido Günther committed
83

Guido Günther's avatar
Guido Günther committed
84
    g_type_class_add_private (klass, sizeof (KaPluginDummyPrivate));
Guido Günther's avatar
Guido Günther committed
85

Guido Günther's avatar
Guido Günther committed
86 87 88
    plugin_class->activate = ka_plugin_dummy_activate;
    plugin_class->deactivate = ka_plugin_dummy_deactivate;
    object_class->finalize = ka_plugin_dummy_finalize;
Guido Günther's avatar
Guido Günther committed
89 90 91 92 93 94 95
}

static void
ka_plugin_dummy_init (KaPluginDummy *self)
{
}

Guido Günther's avatar
Guido Günther committed
96
KaPluginDummy *
Guido Günther's avatar
Guido Günther committed
97 98
ka_plugin_dummy_new (void)
{
Guido Günther's avatar
Guido Günther committed
99 100
    return g_object_new (KA_TYPE_PLUGIN_DUMMY, KA_PLUGIN_PROP_NAME,
                         "dummy", NULL);
Guido Günther's avatar
Guido Günther committed
101
}