[gnome-control-center] info: add graphics info
- From: William Jon McCann <mccann src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] info: add graphics info
- Date: Fri, 4 Feb 2011 19:28:34 +0000 (UTC)
commit d734bbc7348021ae90d50ea7d1aef0f726c45d3b
Author: William Jon McCann <jmccann redhat com>
Date: Fri Feb 4 14:27:25 2011 -0500
info: add graphics info
Try to get the graphics info first from glxinfo and then
from lspci. Then prettify the results a bit.
panels/info/cc-info-panel.c | 181 ++++++++++++++++++++++++++++++++++++++++++-
panels/info/info.ui | 122 ++++++++++++++++++++++-------
2 files changed, 273 insertions(+), 30 deletions(-)
---
diff --git a/panels/info/cc-info-panel.c b/panels/info/cc-info-panel.c
index da1a8aa..c9b3c47 100644
--- a/panels/info/cc-info-panel.c
+++ b/panels/info/cc-info-panel.c
@@ -162,6 +162,175 @@ load_gnome_version (char **version,
return ret;
};
+static char *
+get_graphics_info_lspci (void)
+{
+ GError *error;
+ GRegex *re;
+ GMatchInfo *match_info;
+ char *output;
+ GString *info;
+
+ info = g_string_new (NULL);
+
+ error = NULL;
+ g_spawn_command_line_sync ("lspci -nn", &output, NULL, NULL, &error);
+ if (error != NULL)
+ {
+ g_warning ("Unable to get graphics info: %s", error->message);
+ g_error_free (error);
+ return NULL;
+ }
+
+ re = g_regex_new ("^[^ ]+ VGA compatible controller [^:]*: ([^([]+).*$", G_REGEX_MULTILINE, 0, &error);
+ if (re == NULL)
+ {
+ g_warning ("Error building regex: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ g_regex_match (re, output, 0, &match_info);
+ while (g_match_info_matches (match_info))
+ {
+ char *device;
+
+ device = g_match_info_fetch (match_info, 1);
+ g_string_append_printf (info, "%s ", device);
+ g_free (device);
+
+ g_match_info_next (match_info, NULL);
+ }
+
+ g_match_info_free (match_info);
+ g_regex_unref (re);
+
+ out:
+ g_free (output);
+
+ return g_string_free (info, FALSE);
+}
+
+static char *
+get_graphics_info_glxinfo (void)
+{
+ GError *error;
+ GRegex *re;
+ GMatchInfo *match_info;
+ char *output;
+ GString *info;
+
+ info = g_string_new (NULL);
+
+ error = NULL;
+ g_spawn_command_line_sync ("glxinfo -l", &output, NULL, NULL, &error);
+ if (error != NULL)
+ {
+ g_warning ("Unable to get graphics info: %s", error->message);
+ g_error_free (error);
+ return NULL;
+ }
+
+ re = g_regex_new ("^OpenGL renderer string: (.+)$", G_REGEX_MULTILINE, 0, &error);
+ if (re == NULL)
+ {
+ g_warning ("Error building regex: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ g_regex_match (re, output, 0, &match_info);
+ while (g_match_info_matches (match_info))
+ {
+ char *device;
+
+ device = g_match_info_fetch (match_info, 1);
+ g_string_append_printf (info, "%s ", device);
+ g_free (device);
+
+ g_match_info_next (match_info, NULL);
+ }
+ g_match_info_free (match_info);
+ g_regex_unref (re);
+
+ out:
+ g_free (output);
+
+ return g_string_free (info, FALSE);
+}
+
+typedef struct
+{
+ char *regex;
+ char *replacement;
+} ReplaceStrings;
+
+static char *
+prettify_info (const char *info)
+{
+ char *pretty;
+ int i;
+ static const ReplaceStrings rs[] = {
+ { "Mesa DRI ", ""},
+ { "Intel[(]R[)]", "Intel<sup>\302\256</sup>"},
+ { "Core[(]TM[)]", "Core<sup>\342\204\242</sup>"},
+ { "Graphics Controller", "Graphics"},
+ };
+
+ pretty = g_markup_escape_text (info, -1);
+
+ for (i = 0; i < G_N_ELEMENTS (rs); i++)
+ {
+ GError *error;
+ GRegex *re;
+ char *new;
+
+ error = NULL;
+
+ re = g_regex_new (rs[i].regex, 0, 0, &error);
+ if (re == NULL)
+ {
+ g_warning ("Error building regex: %s", error->message);
+ g_error_free (error);
+ continue;
+ }
+
+ new = g_regex_replace_literal (re,
+ pretty,
+ -1,
+ 0,
+ rs[i].replacement,
+ 0,
+ &error);
+
+ g_regex_unref (re);
+
+ if (error != NULL)
+ {
+ g_warning ("Error replacing %s: %s", rs[i].regex, error->message);
+ g_error_free (error);
+ continue;
+ }
+
+ g_free (pretty);
+ pretty = new;
+ }
+
+ return pretty;
+}
+
+static char *
+get_graphics_info (void)
+{
+ char *info;
+
+ info = get_graphics_info_glxinfo ();
+ if (info == NULL)
+ info = get_graphics_info_lspci ();
+
+ return info;
+}
+
static void
cc_info_panel_get_property (GObject *object,
guint property_id,
@@ -440,6 +609,7 @@ cc_info_panel_init (CcInfoPanel *self)
glibtop_mem mem;
const glibtop_sysinfo *info;
char *text;
+ char *pretty;
self->priv = INFO_PANEL_PRIVATE (self);
@@ -478,7 +648,9 @@ cc_info_panel_init (CcInfoPanel *self)
widget = WID (self->priv->builder, "processor_label");
text = get_cpu_info (info);
- gtk_label_set_text (GTK_LABEL (widget), text ? text : "");
+ pretty = prettify_info (text);
+ gtk_label_set_markup (GTK_LABEL (widget), pretty ? pretty : "");
+ g_free (pretty);
g_free (text);
widget = WID (self->priv->builder, "os_type_label");
@@ -491,6 +663,13 @@ cc_info_panel_init (CcInfoPanel *self)
gtk_label_set_text (GTK_LABEL (widget), text ? text : "");
g_free (text);
+ text = get_graphics_info ();
+ pretty = prettify_info (text);
+ widget = WID (self->priv->builder, "graphics_label");
+ gtk_label_set_markup (GTK_LABEL (widget), pretty ? pretty : "");
+ g_free (text);
+ g_free (pretty);
+
widget = WID (self->priv->builder, "info_vbox");
gtk_widget_reparent (widget, (GtkWidget *) self);
}
diff --git a/panels/info/info.ui b/panels/info/info.ui
index d197a1d..66db5ee 100644
--- a/panels/info/info.ui
+++ b/panels/info/info.ui
@@ -1,26 +1,28 @@
-<?xml version="1.0"?>
+<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="2.16"/>
- <!-- interface-naming-policy project-wide -->
<object class="GtkWindow" id="window1">
+ <property name="can_focus">False</property>
<child>
<object class="GtkVBox" id="info_vbox">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="border_width">10</property>
- <property name="orientation">vertical</property>
<property name="spacing">12</property>
<child>
<object class="GtkAlignment" id="alignment1">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="top_padding">20</property>
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
- <property name="orientation">vertical</property>
+ <property name="can_focus">False</property>
<property name="spacing">18</property>
<child>
<object class="GtkImage" id="system_image">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="pixbuf">GnomeLogoVerticalMedium.svg</property>
</object>
<packing>
@@ -32,10 +34,11 @@
<child>
<object class="GtkLabel" id="version_label">
<property name="visible">True</property>
- <property name="label" translatable="no">Version 3.0</property>
+ <property name="can_focus">False</property>
+ <property name="label">Version 3.0</property>
<property name="selectable">True</property>
<attributes>
- <attribute name="scale" value="1.250000"/>
+ <attribute name="scale" value="1.25"/>
</attributes>
</object>
<packing>
@@ -47,12 +50,14 @@
<child>
<object class="GtkTable" id="table1">
<property name="visible">True</property>
- <property name="n_rows">5</property>
+ <property name="can_focus">False</property>
+ <property name="n_rows">6</property>
<property name="n_columns">3</property>
<property name="column_spacing">12</property>
<property name="row_spacing">5</property>
<child>
<object class="GtkLabel" id="label1">
+ <property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="xalign">1</property>
<property name="label" translatable="yes">Device name:</property>
@@ -61,6 +66,7 @@
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">1</property>
<property name="label" translatable="yes">Memory:</property>
</object>
@@ -72,6 +78,7 @@
<child>
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">1</property>
<property name="label" translatable="yes">Processor:</property>
</object>
@@ -83,30 +90,32 @@
<child>
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">1</property>
<property name="label" translatable="yes">OS type:</property>
</object>
<packing>
- <property name="top_attach">3</property>
- <property name="bottom_attach">4</property>
+ <property name="top_attach">4</property>
+ <property name="bottom_attach">5</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label5">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">1</property>
<property name="label" translatable="yes">Disk:</property>
</object>
<packing>
- <property name="top_attach">4</property>
- <property name="bottom_attach">5</property>
+ <property name="top_attach">5</property>
+ <property name="bottom_attach">6</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="entry1">
<property name="can_focus">True</property>
<property name="no_show_all">True</property>
- <property name="invisible_char">●</property>
+ <property name="invisible_char">â??</property>
<property name="width_chars">12</property>
<property name="caps_lock_warning">False</property>
</object>
@@ -118,8 +127,9 @@
<child>
<object class="GtkLabel" id="memory_label">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
- <property name="label" translatable="no">2 GB</property>
+ <property name="label">Unknown</property>
<property name="selectable">True</property>
</object>
<packing>
@@ -132,8 +142,9 @@
<child>
<object class="GtkLabel" id="processor_label">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
- <property name="label" translatable="no">AmTel Duo Core 2.2 GHz</property>
+ <property name="label">Unknown</property>
<property name="selectable">True</property>
</object>
<packing>
@@ -146,35 +157,38 @@
<child>
<object class="GtkLabel" id="os_type_label">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
- <property name="label" translatable="no">32-bit</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">3</property>
- <property name="bottom_attach">4</property>
+ <property name="top_attach">4</property>
+ <property name="bottom_attach">5</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="disk_label">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="xalign">0</property>
- <property name="label" translatable="no">80 GB (4 GB free)</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">4</property>
- <property name="bottom_attach">5</property>
+ <property name="top_attach">5</property>
+ <property name="bottom_attach">6</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label6">
<property name="visible">True</property>
- <property name="label" translatable="no"> </property>
+ <property name="can_focus">False</property>
+ <property name="label"> </property>
</object>
<packing>
<property name="left_attach">2</property>
@@ -185,7 +199,8 @@
<child>
<object class="GtkLabel" id="label7">
<property name="visible">True</property>
- <property name="label" translatable="no"> </property>
+ <property name="can_focus">False</property>
+ <property name="label"> </property>
</object>
<packing>
<property name="left_attach">2</property>
@@ -198,7 +213,8 @@
<child>
<object class="GtkLabel" id="label8">
<property name="visible">True</property>
- <property name="label" translatable="no"> </property>
+ <property name="can_focus">False</property>
+ <property name="label"> </property>
</object>
<packing>
<property name="left_attach">2</property>
@@ -211,29 +227,72 @@
<child>
<object class="GtkLabel" id="label9">
<property name="visible">True</property>
- <property name="label" translatable="no"> </property>
+ <property name="can_focus">False</property>
+ <property name="label"> </property>
</object>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
- <property name="top_attach">3</property>
- <property name="bottom_attach">4</property>
+ <property name="top_attach">4</property>
+ <property name="bottom_attach">5</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label10">
<property name="visible">True</property>
- <property name="label" translatable="no"> </property>
+ <property name="can_focus">False</property>
+ <property name="label"> </property>
</object>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
- <property name="top_attach">4</property>
- <property name="bottom_attach">5</property>
+ <property name="top_attach">5</property>
+ <property name="bottom_attach">6</property>
+ <property name="x_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label11">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">1</property>
+ <property name="label" translatable="yes">Graphics:</property>
+ </object>
+ <packing>
+ <property name="top_attach">3</property>
+ <property name="bottom_attach">4</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label12">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label"> </property>
+ </object>
+ <packing>
+ <property name="left_attach">2</property>
+ <property name="right_attach">3</property>
+ <property name="top_attach">3</property>
+ <property name="bottom_attach">4</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
+ <child>
+ <object class="GtkLabel" id="graphics_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">3</property>
+ <property name="bottom_attach">4</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">False</property>
@@ -245,12 +304,15 @@
</child>
</object>
<packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkHButtonBox" id="hbuttonbox1">
<property name="visible">True</property>
+ <property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="button1">
@@ -258,6 +320,7 @@
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="no_show_all">True</property>
+ <property name="use_action_appearance">False</property>
</object>
<packing>
<property name="expand">False</property>
@@ -272,6 +335,7 @@
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="no_show_all">True</property>
+ <property name="use_action_appearance">False</property>
</object>
<packing>
<property name="expand">False</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]