~ubuntu-branches/ubuntu/lucid/gnome-commander/lucid

« back to all changes in this revision

Viewing changes to plugins/test/test-plugin.c

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2010-02-17 19:55:31 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20100217195531-wnv3t4hjpv5vys39
Tags: 1.2.8.5-0ubuntu1
* New upstream release.
* Bump Standards-Version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    GNOME Commander - A GNOME based file manager
3
 
    Copyright (C) 2001-2006 Marcus Bjurman
4
 
    Copyright (C) 2007-2009 Piotr Eljasiak
5
 
 
6
 
    This program is free software; you can redistribute it and/or modify
7
 
    it under the terms of the GNU General Public License as published by
8
 
    the Free Software Foundation; either version 2 of the License, or
9
 
    (at your option) any later version.
10
 
 
11
 
    This program is distributed in the hope that it will be useful,
12
 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
    GNU General Public License for more details.
15
 
 
16
 
    You should have received a copy of the GNU General Public License
17
 
    along with this program; if not, write to the Free Software
18
 
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19
 
*/
20
 
 
21
 
#include <config.h>
22
 
#include <gnome.h>
23
 
#include <libgcmd/libgcmd.h>
24
 
#include "test-plugin.h"
25
 
#include "test-plugin.xpm"
26
 
 
27
 
#define NAME "Example"
28
 
#define COPYRIGHT "Copyright \xc2\xa9 2003-2006 Marcus Bjurman"
29
 
#define AUTHOR "Marcus Bjurman <marbj499@student.liu.se>"
30
 
#define WEBPAGE "http://www.nongnu.org/gcmd"
31
 
 
32
 
 
33
 
static PluginInfo plugin_nfo = {
34
 
    GNOME_CMD_PLUGIN_SYSTEM_CURRENT_VERSION,
35
 
    NAME,
36
 
    VERSION,
37
 
    COPYRIGHT,
38
 
    NULL,
39
 
    NULL,
40
 
    NULL,
41
 
    NULL,
42
 
    WEBPAGE
43
 
};
44
 
 
45
 
struct _TestPluginPrivate
46
 
{
47
 
#ifdef __sun
48
 
    gchar dummy;  // Sun's forte compiler does not like empty structs
49
 
#endif
50
 
};
51
 
 
52
 
static GnomeCmdPluginClass *parent_class = NULL;
53
 
 
54
 
 
55
 
static void on_dummy (GtkMenuItem *item, gpointer data)
56
 
{
57
 
    gnome_ok_dialog ("Test plugin dummy operation");
58
 
}
59
 
 
60
 
 
61
 
static GtkWidget *create_menu_item (const gchar *name, gboolean show_pixmap, GtkSignalFunc callback, gpointer data)
62
 
{
63
 
    GtkWidget *item, *label;
64
 
 
65
 
    if (show_pixmap)
66
 
    {
67
 
        GdkPixbuf *pixbuf = gdk_pixbuf_new_from_xpm_data ((const char **) test_plugin_xpm);
68
 
        GtkWidget *pixmap = gtk_image_new_from_pixbuf (pixbuf);
69
 
        g_object_unref (G_OBJECT (pixbuf));
70
 
        item = gtk_image_menu_item_new ();
71
 
        if (pixmap)
72
 
        {
73
 
            gtk_widget_show (pixmap);
74
 
            gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), pixmap);
75
 
        }
76
 
    }
77
 
    else
78
 
        item = gtk_menu_item_new ();
79
 
 
80
 
    gtk_widget_show (item);
81
 
 
82
 
    // Create the contents of the menu item
83
 
    label = gtk_label_new (name);
84
 
    gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
85
 
    gtk_widget_show (label);
86
 
    gtk_container_add (GTK_CONTAINER (item), label);
87
 
 
88
 
    // Connect to the signal and set user data
89
 
    gtk_object_set_data (GTK_OBJECT (item), GNOMEUIINFO_KEY_UIDATA, data);
90
 
 
91
 
    if (callback)
92
 
        gtk_signal_connect (GTK_OBJECT (item), "activate", callback, data);
93
 
 
94
 
    return item;
95
 
}
96
 
 
97
 
 
98
 
static GtkWidget *create_main_menu (GnomeCmdPlugin *plugin, GnomeCmdState *state)
99
 
{
100
 
    GtkWidget *item, *child;
101
 
    GtkMenu *submenu;
102
 
 
103
 
    submenu = GTK_MENU (gtk_menu_new ());
104
 
    item = create_menu_item ("Test", FALSE, NULL, NULL);
105
 
    gtk_menu_item_set_submenu (GTK_MENU_ITEM (item),
106
 
                               GTK_WIDGET (submenu));
107
 
 
108
 
    child = create_menu_item ("Test plugin dummy operation", FALSE, GTK_SIGNAL_FUNC (on_dummy), state);
109
 
    gtk_menu_append (submenu, child);
110
 
 
111
 
    return item;
112
 
}
113
 
 
114
 
 
115
 
static GList *create_popup_menu_items (GnomeCmdPlugin *plugin, GnomeCmdState *state)
116
 
{
117
 
    GtkWidget *item = create_menu_item ("Test plugin dummy operation", TRUE, GTK_SIGNAL_FUNC (on_dummy), state);
118
 
 
119
 
    return g_list_append (NULL, item);
120
 
}
121
 
 
122
 
 
123
 
static void update_main_menu_state (GnomeCmdPlugin *plugin, GnomeCmdState *state)
124
 
{
125
 
}
126
 
 
127
 
 
128
 
static void configure (GnomeCmdPlugin *plugin)
129
 
{
130
 
    gnome_ok_dialog ("Test plugin configuration dialog");
131
 
}
132
 
 
133
 
 
134
 
 
135
 
 
136
 
/*******************************
137
 
 * Gtk class implementation
138
 
 *******************************/
139
 
 
140
 
static void destroy (GtkObject *object)
141
 
{
142
 
    //TestPlugin *plugin = TEST_PLUGIN (object);
143
 
 
144
 
    if (GTK_OBJECT_CLASS (parent_class)->destroy)
145
 
        (*GTK_OBJECT_CLASS (parent_class)->destroy) (object);
146
 
}
147
 
 
148
 
 
149
 
static void class_init (TestPluginClass *klass)
150
 
{
151
 
    GtkObjectClass *object_class;
152
 
    GnomeCmdPluginClass *plugin_class;
153
 
 
154
 
    object_class = GTK_OBJECT_CLASS (klass);
155
 
    plugin_class = GNOME_CMD_PLUGIN_CLASS (klass);
156
 
    parent_class = gtk_type_class (gnome_cmd_plugin_get_type ());
157
 
 
158
 
    object_class->destroy = destroy;
159
 
 
160
 
    plugin_class->create_main_menu = create_main_menu;
161
 
    plugin_class->create_popup_menu_items = create_popup_menu_items;
162
 
    plugin_class->update_main_menu_state = update_main_menu_state;
163
 
    plugin_class->configure = configure;
164
 
}
165
 
 
166
 
 
167
 
static void init (TestPlugin *plugin)
168
 
{
169
 
    plugin->priv = g_new (TestPluginPrivate, 1);
170
 
}
171
 
 
172
 
 
173
 
 
174
 
/***********************************
175
 
 * Public functions
176
 
 ***********************************/
177
 
 
178
 
GtkType test_plugin_get_type ()
179
 
{
180
 
    static GtkType type = 0;
181
 
 
182
 
    if (type == 0)
183
 
    {
184
 
        GtkTypeInfo info =
185
 
        {
186
 
            "TestPlugin",
187
 
            sizeof (TestPlugin),
188
 
            sizeof (TestPluginClass),
189
 
            (GtkClassInitFunc) class_init,
190
 
            (GtkObjectInitFunc) init,
191
 
            /* reserved_1 */ NULL,
192
 
            /* reserved_2 */ NULL,
193
 
            (GtkClassInitFunc) NULL
194
 
        };
195
 
 
196
 
        type = gtk_type_unique (gnome_cmd_plugin_get_type (), &info);
197
 
    }
198
 
    return type;
199
 
}
200
 
 
201
 
 
202
 
GnomeCmdPlugin *test_plugin_new ()
203
 
{
204
 
    TestPlugin *plugin = gtk_type_new (test_plugin_get_type ());
205
 
 
206
 
    return GNOME_CMD_PLUGIN (plugin);
207
 
}
208
 
 
209
 
 
210
 
GnomeCmdPlugin *create_plugin ()
211
 
{
212
 
    return test_plugin_new ();
213
 
}
214
 
 
215
 
 
216
 
PluginInfo *get_plugin_info ()
217
 
{
218
 
    if (!plugin_nfo.authors)
219
 
    {
220
 
        plugin_nfo.authors = g_new0 (gchar *, 2);
221
 
        plugin_nfo.authors[0] = AUTHOR;
222
 
        plugin_nfo.authors[1] = NULL;
223
 
        plugin_nfo.comments = g_strdup (_("This is an example plugin that is mostly useful as a "
224
 
                                          "simple example for aspiring plugin hackers"));
225
 
    }
226
 
 
227
 
    return &plugin_nfo;
228
 
}