[gnome-control-center] info: Detect and display Virtualisation method used
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] info: Detect and display Virtualisation method used
- Date: Wed, 17 Oct 2012 07:40:48 +0000 (UTC)
commit aecd7c860ded37e14ec27e7dda3122cb6782df00
Author: Bastien Nocera <hadess hadess net>
Date: Mon Oct 15 19:36:50 2012 +0200
info: Detect and display Virtualisation method used
Using systemd's "Virtualization" property on the systemd manager
object. We translate the raw names (as detected by systemd-detect-virt)
into (barely) human readable strings.
https://bugzilla.gnome.org/show_bug.cgi?id=685531
panels/info/cc-info-panel.c | 121 +++++++++++++++++++++++++++++++++++++++++++
panels/info/info.ui | 44 ++++++++++++++--
2 files changed, 160 insertions(+), 5 deletions(-)
---
diff --git a/panels/info/cc-info-panel.c b/panels/info/cc-info-panel.c
index dacd918..8049d0f 100644
--- a/panels/info/cc-info-panel.c
+++ b/panels/info/cc-info-panel.c
@@ -883,6 +883,126 @@ info_panel_setup_graphics (CcInfoPanel *self)
}
static void
+move_one_up (GtkWidget *table,
+ GtkWidget *child)
+{
+ int top_attach, bottom_attach;
+
+ gtk_container_child_get (GTK_CONTAINER (table),
+ child,
+ "top-attach", &top_attach,
+ "bottom-attach", &bottom_attach,
+ NULL);
+ gtk_container_child_set (GTK_CONTAINER (table),
+ child,
+ "top-attach", top_attach - 1,
+ "bottom-attach", bottom_attach - 1,
+ NULL);
+}
+
+static struct {
+ const char *id;
+ const char *display;
+} const virt_tech[] = {
+ { "kvm", "KVM" },
+ { "qemu", "QEmu" },
+ { "vmware", "VMWare" },
+ { "microsoft", "Microsoft" },
+ { "oracle", "Oracle" },
+ { "xen", "Xen" },
+ { "bochs", "Bochs" },
+ { "chroot", "chroot" },
+ { "openvz", "OpenVZ" },
+ { "lxc", "LXC" },
+ { "lxc-libvirt", "LXC (libvirt)" },
+ { "systemd-nspawn", "systemd (nspawn)" }
+};
+
+static void
+set_virtualization_label (CcInfoPanel *self,
+ const char *virt)
+{
+ const char *display_name;
+ GtkWidget *widget;
+ guint i;
+
+ if (virt == NULL || *virt == '\0')
+ {
+ gtk_widget_hide (WID ("virt_type_label"));
+ gtk_widget_hide (WID ("label18"));
+ move_one_up (WID("table1"), WID("label8"));
+ move_one_up (WID("table1"), WID("disk_label"));
+ return;
+ }
+
+ display_name = NULL;
+ for (i = 0; i < G_N_ELEMENTS (virt_tech); i++)
+ {
+ if (g_str_equal (virt_tech[i].id, virt) == 0)
+ {
+ display_name = _(virt_tech[i].display);
+ break;
+ }
+ }
+
+ widget = WID ("virt_type_label");
+ gtk_label_set_text (GTK_LABEL (widget), display_name ? display_name : virt);
+}
+
+static void
+info_panel_setup_virt (CcInfoPanel *self)
+{
+ GError *error = NULL;
+ GDBusProxy *systemd_proxy;
+ GVariant *variant;
+ GVariant *inner;
+ char *str;
+
+ str = NULL;
+
+ systemd_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.freedesktop.systemd1",
+ "/org/freedesktop/systemd1",
+ "org.freedesktop.systemd1",
+ NULL,
+ &error);
+
+ if (systemd_proxy == NULL)
+ {
+ g_debug ("systemd not available, bailing: %s", error->message);
+ g_error_free (error);
+ goto bail;
+ }
+
+ variant = g_dbus_proxy_call_sync (systemd_proxy,
+ "org.freedesktop.DBus.Properties.Get",
+ g_variant_new ("(ss)", "org.freedesktop.systemd1.Manager", "Virtualization"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+ if (variant == NULL)
+ {
+ g_debug ("Failed to get property '%s': %s", "Virtualization", error->message);
+ g_error_free (error);
+ g_object_unref (systemd_proxy);
+ goto bail;
+ }
+
+ g_variant_get (variant, "(v)", &inner);
+ str = g_variant_dup_string (inner, NULL);
+ g_variant_unref (variant);
+
+ g_object_unref (systemd_proxy);
+
+bail:
+ set_virtualization_label (self, str);
+ g_free (str);
+}
+
+static void
default_app_changed (GtkAppChooserButton *button,
CcInfoPanel *self)
{
@@ -2022,6 +2142,7 @@ cc_info_panel_init (CcInfoPanel *self)
info_panel_setup_default_apps (self);
info_panel_setup_media (self);
info_panel_setup_graphics (self);
+ info_panel_setup_virt (self);
}
void
diff --git a/panels/info/info.ui b/panels/info/info.ui
index 74d17cf..63fd1e8 100644
--- a/panels/info/info.ui
+++ b/panels/info/info.ui
@@ -267,7 +267,7 @@
<object class="GtkTable" id="table1">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="n_rows">6</property>
+ <property name="n_rows">7</property>
<property name="n_columns">3</property>
<property name="column_spacing">12</property>
<property name="row_spacing">5</property>
@@ -343,8 +343,8 @@
</style>
</object>
<packing>
- <property name="top_attach">5</property>
- <property name="bottom_attach">6</property>
+ <property name="top_attach">6</property>
+ <property name="bottom_attach">7</property>
</packing>
</child>
<child>
@@ -415,8 +415,8 @@
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
- <property name="top_attach">5</property>
- <property name="bottom_attach">6</property>
+ <property name="top_attach">6</property>
+ <property name="bottom_attach">7</property>
</packing>
</child>
<child>
@@ -531,6 +531,40 @@
<property name="bottom_attach">4</property>
</packing>
</child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label18">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes">Virtualization</property>
+ <property name="mnemonic_widget">virt_type_label</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ <packing>
+ <property name="top_attach">5</property>
+ <property name="bottom_attach">6</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="virt_type_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="label">Unknown</property>
+ <property name="selectable">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">5</property>
+ <property name="bottom_attach">6</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">False</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]