| 1 |
/* |
| 2 |
* second-time.c |
| 3 |
* This file is part of libpeas |
| 4 |
* |
| 5 |
* Copyright (C) 2009-2010 Steve Frécinaux |
| 6 |
* |
| 7 |
* libpeas is free software; you can redistribute it and/or |
| 8 |
* modify it under the terms of the GNU Lesser General Public |
| 9 |
* License as published by the Free Software Foundation; either |
| 10 |
* version 2.1 of the License, or (at your option) any later version. |
| 11 |
* |
| 12 |
* libpeas is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
* Lesser General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU Lesser General Public |
| 18 |
* License along with this library; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 |
*/ |
| 21 |
|
| 22 |
#ifdef HAVE_CONFIG_H |
| 23 |
#include <config.h> |
| 24 |
#endif |
| 25 |
|
| 26 |
#include <glib.h> |
| 27 |
#include <glib-object.h> |
| 28 |
#include <gmodule.h> |
| 29 |
#include <gtk/gtk.h> |
| 30 |
|
| 31 |
#include <libpeas/peas.h> |
| 32 |
|
| 33 |
#include "second-time.h" |
| 34 |
|
| 35 |
static void peas_activatable_iface_init (PeasActivatableInterface *iface); |
| 36 |
|
| 37 |
G_DEFINE_DYNAMIC_TYPE_EXTENDED (PeasDemoSecondTime, |
| 38 |
peasdemo_second_time, |
| 39 |
PEAS_TYPE_EXTENSION_BASE, |
| 40 |
0, |
| 41 |
G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE, |
| 42 |
peas_activatable_iface_init)) |
| 43 |
|
| 44 |
enum { |
| 45 |
PROP_0, |
| 46 |
PROP_OBJECT |
| 47 |
}; |
| 48 |
|
| 49 |
static void |
| 50 |
peasdemo_second_time_set_property (GObject *object, |
| 51 |
guint prop_id, |
| 52 |
const GValue *value, |
| 53 |
GParamSpec *pspec) |
| 54 |
{ |
| 55 |
PeasDemoSecondTime *plugin = PEASDEMO_SECOND_TIME (object); |
| 56 |
|
| 57 |
switch (prop_id) |
| 58 |
{ |
| 59 |
case PROP_OBJECT: |
| 60 |
plugin->window = GTK_WIDGET (g_value_dup_object (value)); |
| 61 |
break; |
| 62 |
|
| 63 |
default: |
| 64 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 65 |
break; |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
static void |
| 70 |
peasdemo_second_time_get_property (GObject *object, |
| 71 |
guint prop_id, |
| 72 |
GValue *value, |
| 73 |
GParamSpec *pspec) |
| 74 |
{ |
| 75 |
PeasDemoSecondTime *plugin = PEASDEMO_SECOND_TIME (object); |
| 76 |
|
| 77 |
switch (prop_id) |
| 78 |
{ |
| 79 |
case PROP_OBJECT: |
| 80 |
g_value_set_object (value, plugin->window); |
| 81 |
break; |
| 82 |
|
| 83 |
default: |
| 84 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 85 |
break; |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
static void |
| 91 |
peasdemo_second_time_init (PeasDemoSecondTime *plugin) |
| 92 |
{ |
| 93 |
g_debug ("%s", G_STRFUNC); |
| 94 |
} |
| 95 |
|
| 96 |
static void |
| 97 |
peasdemo_second_time_finalize (GObject *object) |
| 98 |
{ |
| 99 |
PeasDemoSecondTime *plugin = PEASDEMO_SECOND_TIME (object); |
| 100 |
|
| 101 |
g_debug ("%s", G_STRFUNC); |
| 102 |
|
| 103 |
g_object_unref (plugin->label); |
| 104 |
g_object_unref (plugin->window); |
| 105 |
|
| 106 |
G_OBJECT_CLASS (peasdemo_second_time_parent_class)->finalize (object); |
| 107 |
} |
| 108 |
|
| 109 |
static GtkBox * |
| 110 |
get_box (GtkWidget *window) |
| 111 |
{ |
| 112 |
return GTK_BOX (gtk_bin_get_child (GTK_BIN (window))); |
| 113 |
} |
| 114 |
|
| 115 |
static void |
| 116 |
peasdemo_second_time_activate (PeasActivatable *activatable) |
| 117 |
{ |
| 118 |
PeasDemoSecondTime *plugin = PEASDEMO_SECOND_TIME (activatable); |
| 119 |
|
| 120 |
g_debug ("%s", G_STRFUNC); |
| 121 |
|
| 122 |
plugin->label = gtk_label_new ("A second time!"); |
| 123 |
gtk_box_pack_start (get_box (plugin->window), plugin->label, 1, 1, 0); |
| 124 |
gtk_widget_show (plugin->label); |
| 125 |
g_object_ref (plugin->label); |
| 126 |
} |
| 127 |
|
| 128 |
static void |
| 129 |
peasdemo_second_time_deactivate (PeasActivatable *activatable) |
| 130 |
{ |
| 131 |
PeasDemoSecondTime *plugin = PEASDEMO_SECOND_TIME (activatable); |
| 132 |
|
| 133 |
g_debug ("%s", G_STRFUNC); |
| 134 |
|
| 135 |
gtk_container_remove (GTK_CONTAINER (get_box (plugin->window)), plugin->label); |
| 136 |
} |
| 137 |
|
| 138 |
static void |
| 139 |
peasdemo_second_time_class_init (PeasDemoSecondTimeClass *klass) |
| 140 |
{ |
| 141 |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
| 142 |
|
| 143 |
object_class->set_property = peasdemo_second_time_set_property; |
| 144 |
object_class->get_property = peasdemo_second_time_get_property; |
| 145 |
object_class->finalize = peasdemo_second_time_finalize; |
| 146 |
|
| 147 |
g_object_class_override_property (object_class, PROP_OBJECT, "object"); |
| 148 |
} |
| 149 |
|
| 150 |
static void |
| 151 |
peas_activatable_iface_init (PeasActivatableInterface *iface) |
| 152 |
{ |
| 153 |
iface->activate = peasdemo_second_time_activate; |
| 154 |
iface->deactivate = peasdemo_second_time_deactivate; |
| 155 |
} |
| 156 |
|
| 157 |
static void |
| 158 |
peasdemo_second_time_class_finalize (PeasDemoSecondTimeClass *klass) |
| 159 |
{ |
| 160 |
} |
| 161 |
|
| 162 |
G_MODULE_EXPORT void |
| 163 |
peas_register_types (PeasObjectModule *module) |
| 164 |
{ |
| 165 |
peasdemo_second_time_register_type (G_TYPE_MODULE (module)); |
| 166 |
|
| 167 |
peas_object_module_register_extension_type (module, |
| 168 |
PEAS_TYPE_ACTIVATABLE, |
| 169 |
PEASDEMO_TYPE_SECOND_TIME); |
| 170 |
} |