File: testplugin.c

package info (click to toggle)
xfce4-panel 4.3.99.2-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 6,000 kB
  • ctags: 2,052
  • sloc: ansic: 17,370; sh: 8,587; xml: 2,908; makefile: 804
file content (146 lines) | stat: -rw-r--r-- 3,609 bytes parent folder | download
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
/* test plugin */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdlib.h>
#include <gtk/gtk.h>
#include <libxfcegui4/libxfcegui4.h>

#include <libxfce4panel/xfce-panel-plugin.h>

#define PLUGIN_NAME "testplugin"


/* Panel Plugin Interface */

static void test_construct (XfcePanelPlugin *plugin);

XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL(test_construct);


/* internal functions */

static void
test_orientation_changed (XfcePanelPlugin *plugin, GtkOrientation orientation, 
                     GtkWidget *label)
{
    gtk_label_set_angle (GTK_LABEL (label), 
            (orientation == GTK_ORIENTATION_HORIZONTAL) ? 0 : 90);
}

static void 
test_free_data (XfcePanelPlugin *plugin)
{
    DBG ("Free data: %s", PLUGIN_NAME);
    gtk_main_quit ();
}

static void 
test_save (XfcePanelPlugin *plugin)
{
    char *file;
    XfceRc *rc;
    
    DBG ("Save: %s", PLUGIN_NAME);

    if (!(file = xfce_panel_plugin_save_location (plugin, TRUE)))
        return;

    rc = xfce_rc_simple_open (file, FALSE);
    g_free (file);

    if (rc)
    {
        xfce_rc_write_entry (rc, "string", "stringvalue");
        xfce_rc_write_bool_entry (rc, "bool", TRUE);
        xfce_rc_write_int_entry (rc, "int", 12);

        xfce_rc_close (rc);
    }
}

static void
test_configure (XfcePanelPlugin *plugin)
{
    DBG ("Configure: %s", PLUGIN_NAME);
}

static gboolean 
test_set_size (XfcePanelPlugin *plugin, int size)
{
    DBG ("Set size to %d: %s", size, PLUGIN_NAME);

    if (xfce_panel_plugin_get_orientation (plugin) == 
        GTK_ORIENTATION_HORIZONTAL)
    {
        gtk_widget_set_size_request (GTK_WIDGET (plugin), -1, size);
    }
    else
    {
        gtk_widget_set_size_request (GTK_WIDGET (plugin), size, -1);
    }

    return TRUE;
}

/* create widgets and connect to signals */ 

static void 
test_construct (XfcePanelPlugin *plugin)
{
    GtkWidget *button;
    char *file;
    XfceRc *rc;
    GtkOrientation orientation = xfce_panel_plugin_get_orientation (plugin);
    
    xfce_textdomain (GETTEXT_PACKAGE, LOCALEDIR, "UTF-8"); 

    DBG ("Construct: %s", PLUGIN_NAME);
    
    DBG ("Properties: size = %d, panel_position = %d", 
         xfce_panel_plugin_get_size (plugin),
         xfce_panel_plugin_get_screen_position (plugin));

    if ((file = xfce_panel_plugin_lookup_rc_file (plugin)) != NULL)
    {
        rc = xfce_rc_simple_open (file, TRUE);
        g_free (file);

        if (rc)
            xfce_rc_close (rc);
    }
    
    button = 
        gtk_button_new_with_label (xfce_panel_plugin_get_display_name (plugin));
    gtk_widget_show (button);
    gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);

    gtk_label_set_angle (GTK_LABEL (GTK_BIN (button)->child), 
            (orientation == GTK_ORIENTATION_HORIZONTAL) ? 0 : 90);
    
    gtk_container_add (GTK_CONTAINER (plugin), button);

    xfce_panel_plugin_add_action_widget (plugin, button);

    g_signal_connect (plugin, "orientation-changed", 
                      G_CALLBACK (test_orientation_changed), 
                      GTK_BIN (button)->child);

    g_signal_connect (plugin, "free-data", 
                      G_CALLBACK (test_free_data), NULL);

    g_signal_connect (plugin, "save", 
                      G_CALLBACK (test_save), NULL);

    g_signal_connect (plugin, "size-changed", 
                      G_CALLBACK (test_set_size), GTK_BIN (button)->child);

    xfce_panel_plugin_menu_show_configure (plugin);
    g_signal_connect (plugin, "configure-plugin", 
                      G_CALLBACK (test_configure), NULL);
    
    xfce_panel_plugin_set_expand (plugin, TRUE);
}