File: wrapper-module.c

package info (click to toggle)
xfce4-panel 4.20.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,056 kB
  • sloc: ansic: 61,551; sh: 5,515; makefile: 1,330; python: 128; xml: 101; sed: 16
file content (170 lines) | stat: -rw-r--r-- 4,204 bytes parent folder | download | duplicates (2)
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
 * Copyright (C) 2009 Nick Schermer <nick@xfce.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 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.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "wrapper-module.h"

#include "common/panel-private.h"



static void
wrapper_module_dispose (GObject *object);
static gboolean
wrapper_module_load (GTypeModule *type_module);
static void
wrapper_module_unload (GTypeModule *type_module);



struct _WrapperModule
{
  GTypeModule __parent__;

  GModule *library;
  GType plugin_type;
};



G_DEFINE_FINAL_TYPE (WrapperModule, wrapper_module, G_TYPE_TYPE_MODULE)



static void
wrapper_module_class_init (WrapperModuleClass *klass)
{
  GObjectClass *gobject_class;
  GTypeModuleClass *gtype_module_class;

  gobject_class = G_OBJECT_CLASS (klass);
  gobject_class->dispose = wrapper_module_dispose;

  gtype_module_class = G_TYPE_MODULE_CLASS (klass);
  gtype_module_class->load = wrapper_module_load;
  gtype_module_class->unload = wrapper_module_unload;
}



static void
wrapper_module_init (WrapperModule *module)
{
  module->plugin_type = G_TYPE_NONE;
}



static void
wrapper_module_dispose (GObject *object)
{
  WrapperModule *module = WRAPPER_MODULE (object);

  if (module->plugin_type != G_TYPE_NONE)
    {
      /* a module containing type implementations must exist forever */
      g_object_ref (module);
      return;
    }

  G_OBJECT_CLASS (wrapper_module_parent_class)->dispose (object);
}



static gboolean
wrapper_module_load (GTypeModule *type_module)
{
  return TRUE;
}



static void
wrapper_module_unload (GTypeModule *type_module)
{
  /* foo */
}



WrapperModule *
wrapper_module_new (GModule *library)
{
  WrapperModule *module;

  module = g_object_new (WRAPPER_TYPE_MODULE, NULL);
  module->library = library;

  return module;
}



GtkWidget *
wrapper_module_new_provider (WrapperModule *module,
                             GdkScreen *screen,
                             const gchar *name,
                             gint unique_id,
                             const gchar *display_name,
                             const gchar *comment,
                             gchar **arguments)
{
  GtkWidget *plugin = NULL;
  PluginConstructFunc construct_func;
  PluginInitFunc init_func;

  panel_return_val_if_fail (WRAPPER_IS_MODULE (module), NULL);
  panel_return_val_if_fail (module->library != NULL, NULL);

  g_type_module_use (G_TYPE_MODULE (module));

  /* try to link the contruct or init function */
  if (g_module_symbol (module->library, "xfce_panel_module_init", (gpointer) &init_func)
      && init_func != NULL)
    {
      /* initialize the plugin */
      module->plugin_type = (init_func) (G_TYPE_MODULE (module), NULL);

      /* create the object */
      plugin = g_object_new (module->plugin_type,
                             "name", name,
                             "unique-id", unique_id,
                             "display-name", display_name,
                             "comment", comment,
                             "arguments", arguments, NULL);
    }
  else if (g_module_symbol (module->library, "xfce_panel_module_construct", (gpointer) &construct_func)
           && construct_func != NULL)
    {
      /* create a new panel plugin */
      plugin = (*construct_func) (name, unique_id,
                                  display_name, comment,
                                  arguments, screen);
    }
  else
    {
      /* print critical warning */
      g_critical ("Plugin \"%s\" lacks a plugin register function.", name);
    }

  return plugin;
}