コード例 #1
0
ファイル: dclock.c プロジェクト: geekless/waterline
/* Plugin constructor. */
static int dclock_constructor(Plugin * p)
{
    /* Allocate and initialize plugin context and set into Plugin private data pointer. */
    DClockPlugin * dc = g_new0(DClockPlugin, 1);
    plugin_set_priv(p, dc);
    dc->plugin = p;

    /* Initialize the clock display. */
    dc->clock_format = g_strdup(_(DEFAULT_CLOCK_FORMAT));
    dc->tooltip_format = g_strdup(_(DEFAULT_TIP_FORMAT));

    su_json_read_options(plugin_inner_json(p), option_definitions, dc);

    /* Allocate top level widget and set into Plugin widget pointer. */
    GtkWidget * pwid = gtk_event_box_new();
    plugin_set_widget(p, pwid);
    gtk_widget_set_has_window(pwid, FALSE);

    GtkWidget * hbox = gtk_hbox_new(FALSE, 0);
    gtk_container_add(GTK_CONTAINER(pwid), hbox);
    gtk_widget_show(hbox);

    dc->label_box = gtk_hbox_new(FALSE, 0);
    gtk_container_add(GTK_CONTAINER(hbox), dc->label_box);

    /* Connect signals. */
    g_signal_connect(G_OBJECT (pwid), "button_press_event", G_CALLBACK(dclock_button_press_event), (gpointer) p);

    dclock_apply_configuration(p);

    /* Show the widget and return. */
    gtk_widget_show(pwid);
    return 1;
}
コード例 #2
0
ファイル: dclock.c プロジェクト: psachin/lxpanel
/* Callback when panel configuration changes. */
static void dclock_panel_configuration_changed(Plugin * p)
{
    dclock_apply_configuration(p);
}
コード例 #3
0
ファイル: dclock.c プロジェクト: psachin/lxpanel
/* Plugin constructor. */
static int dclock_constructor(Plugin * p, char ** fp)
{
    /* Allocate and initialize plugin context and set into Plugin private data pointer. */
    DClockPlugin * dc = g_new0(DClockPlugin, 1);
    p->priv = dc;
    dc->plugin = p;

    /* Load parameters from the configuration file. */
    line s;
    s.len = 256;
    if (fp != NULL)
    {
        while (lxpanel_get_line(fp, &s) != LINE_BLOCK_END)
        {
            if (s.type == LINE_NONE)
            {
                ERR( "dclock: illegal token %s\n", s.str);
                return 0;
            }
            if (s.type == LINE_VAR)
            {
                if (g_ascii_strcasecmp(s.t[0], "ClockFmt") == 0)
                    dc->clock_format = g_strdup(s.t[1]);
                else if (g_ascii_strcasecmp(s.t[0], "TooltipFmt") == 0)
                    dc->tooltip_format = g_strdup(s.t[1]);
                else if (g_ascii_strcasecmp(s.t[0], "Action") == 0)
                    dc->action = g_strdup(s.t[1]);
                else if (g_ascii_strcasecmp(s.t[0], "BoldFont") == 0)
                    dc->bold = str2num(bool_pair, s.t[1], 0);
                else if (g_ascii_strcasecmp(s.t[0], "IconOnly") == 0)
                    dc->icon_only = str2num(bool_pair, s.t[1], 0);
                else if (g_ascii_strcasecmp(s.t[0], "CenterText") == 0)
                    dc->center_text = str2num(bool_pair, s.t[1], 0);
                else
                    ERR( "dclock: unknown var %s\n", s.t[0]);
            }
            else
            {
                ERR( "dclock: illegal in this context %s\n", s.str);
                return 0;
            }
        }
    }

    /* Allocate top level widget and set into Plugin widget pointer. */
    p->pwid = gtk_event_box_new();

    /* Allocate a horizontal box as the child of the top level. */
    GtkWidget * hbox = gtk_hbox_new(TRUE, 0);
    gtk_container_add(GTK_CONTAINER(p->pwid), hbox);
    gtk_widget_show(hbox);

    /* Create a label and an image as children of the horizontal box.
     * Only one of these is visible at a time, controlled by user preference. */
    dc->clock_label = gtk_label_new(NULL);
    gtk_misc_set_alignment(GTK_MISC(dc->clock_label), 0.5, 0.5);
    gtk_misc_set_padding(GTK_MISC(dc->clock_label), 4, 0);
    gtk_container_add(GTK_CONTAINER(hbox), dc->clock_label);
    dc->clock_icon = gtk_image_new();
    gtk_container_add(GTK_CONTAINER(hbox), dc->clock_icon);

    /* Connect signals. */
    g_signal_connect(G_OBJECT (p->pwid), "button_press_event", G_CALLBACK(dclock_button_press_event), (gpointer) p);

    /* Initialize the clock display. */
    if (dc->clock_format == NULL)
        dc->clock_format = g_strdup(DEFAULT_CLOCK_FORMAT);
    if (dc->tooltip_format == NULL)
        dc->tooltip_format = g_strdup(DEFAULT_TIP_FORMAT);
    dclock_apply_configuration(p);

    /* Show the widget and return. */
    gtk_widget_show(p->pwid);
    return 1;
}