1 /*
2  * Virt Viewer: A virtual machine console viewer
3  *
4  * Copyright (C) 2007-2012 Red Hat, Inc.
5  * Copyright (C) 2009-2012 Daniel P. Berrange
6  * Copyright (C) 2010 Marc-André Lureau
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  *
22  * Author: Daniel P. Berrange <berrange@redhat.com>
23  */
24 
25 #include <config.h>
26 
27 #include "virt-viewer-notebook.h"
28 #include "virt-viewer-util.h"
29 
30 struct _VirtViewerNotebook {
31     GtkNotebook parent;
32     GtkWidget *status;
33 };
34 
G_DEFINE_TYPE(VirtViewerNotebook,virt_viewer_notebook,GTK_TYPE_NOTEBOOK)35 G_DEFINE_TYPE(VirtViewerNotebook, virt_viewer_notebook, GTK_TYPE_NOTEBOOK)
36 
37 static void
38 virt_viewer_notebook_get_property (GObject *object, guint property_id,
39                                    GValue *value G_GNUC_UNUSED, GParamSpec *pspec)
40 {
41     switch (property_id) {
42     default:
43         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
44     }
45 }
46 
47 static void
virt_viewer_notebook_set_property(GObject * object,guint property_id,const GValue * value G_GNUC_UNUSED,GParamSpec * pspec)48 virt_viewer_notebook_set_property (GObject *object, guint property_id,
49                                    const GValue *value G_GNUC_UNUSED, GParamSpec *pspec)
50 {
51     switch (property_id) {
52     default:
53         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
54     }
55 }
56 
57 static void
virt_viewer_notebook_class_init(VirtViewerNotebookClass * klass)58 virt_viewer_notebook_class_init (VirtViewerNotebookClass *klass)
59 {
60     GObjectClass *object_class = G_OBJECT_CLASS (klass);
61 
62     object_class->get_property = virt_viewer_notebook_get_property;
63     object_class->set_property = virt_viewer_notebook_set_property;
64 }
65 
66 static void
virt_viewer_notebook_init(VirtViewerNotebook * self)67 virt_viewer_notebook_init (VirtViewerNotebook *self)
68 {
69     self->status = gtk_label_new("");
70     gtk_notebook_set_show_tabs(GTK_NOTEBOOK(self), FALSE);
71     gtk_notebook_set_show_border(GTK_NOTEBOOK(self), FALSE);
72     gtk_widget_show_all(self->status);
73     gtk_notebook_append_page(GTK_NOTEBOOK(self), self->status, NULL);
74 }
75 
76 void
virt_viewer_notebook_show_status_va(VirtViewerNotebook * self,const gchar * fmt,va_list args)77 virt_viewer_notebook_show_status_va(VirtViewerNotebook *self, const gchar *fmt, va_list args)
78 {
79     gchar *text;
80 
81     g_debug("notebook show status %p", self);
82     g_return_if_fail(VIRT_VIEWER_IS_NOTEBOOK(self));
83 
84     text = g_strdup_vprintf(fmt, args);
85     gtk_label_set_text(GTK_LABEL(self->status), text);
86     gtk_notebook_set_current_page(GTK_NOTEBOOK(self), 0);
87     gtk_widget_show_all(GTK_WIDGET(self));
88     g_free(text);
89 }
90 
91 void
virt_viewer_notebook_show_status(VirtViewerNotebook * self,const gchar * fmt,...)92 virt_viewer_notebook_show_status(VirtViewerNotebook *self, const gchar *fmt, ...)
93 {
94     va_list args;
95 
96     g_return_if_fail(VIRT_VIEWER_IS_NOTEBOOK(self));
97 
98     va_start(args, fmt);
99     virt_viewer_notebook_show_status_va(self, fmt, args);
100     va_end(args);
101 }
102 
103 void
virt_viewer_notebook_show_display(VirtViewerNotebook * self)104 virt_viewer_notebook_show_display(VirtViewerNotebook *self)
105 {
106     GtkWidget *display;
107 
108     g_debug("notebook show display %p", self);
109     g_return_if_fail(VIRT_VIEWER_IS_NOTEBOOK(self));
110 
111     display = gtk_notebook_get_nth_page(GTK_NOTEBOOK(self), 1);
112     if (display == NULL)
113         g_debug("FIXME: showing display although it's not ready yet");
114     else
115         gtk_widget_grab_focus(display);
116 
117     gtk_notebook_set_current_page(GTK_NOTEBOOK(self), 1);
118     gtk_widget_show_all(GTK_WIDGET(self));
119 }
120 
121 VirtViewerNotebook*
virt_viewer_notebook_new(void)122 virt_viewer_notebook_new (void)
123 {
124     return g_object_new (VIRT_VIEWER_TYPE_NOTEBOOK, NULL);
125 }
126