summaryrefslogtreecommitdiffstats
path: root/src/virt-viewer-notebook.c
blob: 420c914e23da60d640d46f396976d85b62a1932d (plain)
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
/*
 * Virt Viewer: A virtual machine console viewer
 *
 * Copyright (C) 2007-2012 Red Hat, Inc.
 * Copyright (C) 2009-2012 Daniel P. Berrange
 * Copyright (C) 2010 Marc-André Lureau
 *
 * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Author: Daniel P. Berrange <berrange@redhat.com>
 */

#include <config.h>

#include "virt-viewer-notebook.h"
#include "virt-viewer-util.h"

G_DEFINE_TYPE (VirtViewerNotebook, virt_viewer_notebook, GTK_TYPE_NOTEBOOK)

#define GET_PRIVATE(o)                                                        \
    (G_TYPE_INSTANCE_GET_PRIVATE ((o), VIRT_VIEWER_TYPE_NOTEBOOK, VirtViewerNotebookPrivate))

struct _VirtViewerNotebookPrivate {
    GtkWidget *status;
};

static void
virt_viewer_notebook_get_property (GObject *object, guint property_id,
                                   GValue *value G_GNUC_UNUSED, GParamSpec *pspec)
{
    switch (property_id) {
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    }
}

static void
virt_viewer_notebook_set_property (GObject *object, guint property_id,
                                   const GValue *value G_GNUC_UNUSED, GParamSpec *pspec)
{
    switch (property_id) {
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    }
}

static void
virt_viewer_notebook_class_init (VirtViewerNotebookClass *klass)
{
    GObjectClass *object_class = G_OBJECT_CLASS (klass);

    g_type_class_add_private (klass, sizeof (VirtViewerNotebookPrivate));

    object_class->get_property = virt_viewer_notebook_get_property;
    object_class->set_property = virt_viewer_notebook_set_property;
}

static void
virt_viewer_notebook_init (VirtViewerNotebook *self)
{
    VirtViewerNotebookPrivate *priv;
    GdkRGBA color;

    self->priv = GET_PRIVATE(self);
    priv = self->priv;

    priv->status = gtk_label_new("");
    gtk_notebook_set_show_tabs(GTK_NOTEBOOK(self), FALSE);
    gtk_notebook_set_show_border(GTK_NOTEBOOK(self), FALSE);
    gtk_widget_show_all(priv->status);
    gtk_notebook_append_page(GTK_NOTEBOOK(self), priv->status, NULL);
    gdk_rgba_parse(&color, "white");
    /* FIXME:
     * This method has been deprecated in 3.16.
     * For more details on how to deal with this in the future, please, see:
     * https://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-override-color
     * For the bug report about this deprecated function, please, see:
     * https://bugs.freedesktop.org/show_bug.cgi?id=94276
     */
    gtk_widget_override_color(priv->status, GTK_STATE_FLAG_NORMAL, &color);
}

void
virt_viewer_notebook_show_status_va(VirtViewerNotebook *self, const gchar *fmt, va_list args)
{
    VirtViewerNotebookPrivate *priv;
    gchar *text;

    g_debug("notebook show status %p", self);
    g_return_if_fail(VIRT_VIEWER_IS_NOTEBOOK(self));

    text = g_strdup_vprintf(fmt, args);
    priv = self->priv;
    gtk_label_set_text(GTK_LABEL(priv->status), text);
    gtk_notebook_set_current_page(GTK_NOTEBOOK(self), 0);
    gtk_widget_show_all(GTK_WIDGET(self));
    g_free(text);
}

void
virt_viewer_notebook_show_status(VirtViewerNotebook *self, const gchar *fmt, ...)
{
    va_list args;

    g_return_if_fail(VIRT_VIEWER_IS_NOTEBOOK(self));

    va_start(args, fmt);
    virt_viewer_notebook_show_status_va(self, fmt, args);
    va_end(args);
}

void
virt_viewer_notebook_show_display(VirtViewerNotebook *self)
{
    GtkWidget *display;

    g_debug("notebook show display %p", self);
    g_return_if_fail(VIRT_VIEWER_IS_NOTEBOOK(self));

    display = gtk_notebook_get_nth_page(GTK_NOTEBOOK(self), 1);
    if (display == NULL)
        g_debug("FIXME: showing display although it's not ready yet");
    else
        gtk_widget_grab_focus(display);

    gtk_notebook_set_current_page(GTK_NOTEBOOK(self), 1);
    gtk_widget_show_all(GTK_WIDGET(self));
}

VirtViewerNotebook*
virt_viewer_notebook_new (void)
{
    return g_object_new (VIRT_VIEWER_TYPE_NOTEBOOK, NULL);
}

/*
 * Local variables:
 *  c-indent-level: 4
 *  c-basic-offset: 4
 *  indent-tabs-mode: nil
 * End:
 */