~ubuntu-branches/ubuntu/precise/nvidia-settings/precise-proposed

« back to all changes in this revision

Viewing changes to src/gtk+-2.x/ctkdevice.c

  • Committer: Bazaar Package Importer
  • Author(s): Randall Donald
  • Date: 2004-07-03 19:09:17 UTC
  • Revision ID: james.westby@ubuntu.com-20040703190917-rqkze2s58ux5pamy
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * nvidia-settings: A tool for configuring the NVIDIA X driver on Unix
 
3
 * and Linux systems.
 
4
 *
 
5
 * Copyright (C) 2004 NVIDIA Corporation.
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or
 
8
 * modify it under the terms of Version 2 of the GNU General Public
 
9
 * License as published by the Free Software Foundation.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful, but
 
12
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See Version 2
 
14
 * of the GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the:
 
18
 *
 
19
 *           Free Software Foundation, Inc.
 
20
 *           59 Temple Place - Suite 330
 
21
 *           Boston, MA 02111-1307, USA
 
22
 *
 
23
 */
 
24
 
 
25
#include <gtk/gtk.h>
 
26
#include "NvCtrlAttributes.h"
 
27
 
 
28
#include <stdio.h>
 
29
 
 
30
#include "big_banner_penguin.h"
 
31
#include "big_banner_bsd.h"
 
32
 
 
33
#include "image.h"
 
34
 
 
35
#include "ctkdevice.h"
 
36
#include "ctkhelp.h"
 
37
 
 
38
static void add_table_row(GtkWidget *table,
 
39
                          const gint row,
 
40
                          const gint value_alignment,
 
41
                          const gchar *name,
 
42
                          const gchar *value);
 
43
 
 
44
#define N_GDK_PIXBUFS 45
 
45
 
 
46
 
 
47
GType ctk_device_get_type(
 
48
    void
 
49
)
 
50
{
 
51
    static GType ctk_device_type = 0;
 
52
 
 
53
    if (!ctk_device_type) {
 
54
        static const GTypeInfo info_ctk_device = {
 
55
            sizeof (CtkDeviceClass),
 
56
            NULL, /* base_init */
 
57
            NULL, /* base_finalize */
 
58
            NULL, /* class_init */
 
59
            NULL, /* class_finalize */
 
60
            NULL, /* class_data */
 
61
            sizeof (CtkDevice),
 
62
            0, /* n_preallocs */
 
63
            NULL, /* instance_init */
 
64
        };
 
65
 
 
66
        ctk_device_type =
 
67
            g_type_register_static(GTK_TYPE_VBOX,
 
68
                                   "CtkDevice", &info_ctk_device, 0);
 
69
    }
 
70
    
 
71
    return ctk_device_type;
 
72
}
 
73
 
 
74
 
 
75
 
 
76
GtkWidget* ctk_device_new(
 
77
    NvCtrlAttributeHandle *handle
 
78
)
 
79
{
 
80
    GObject *object;
 
81
    CtkDevice *ctk_device;
 
82
    GtkWidget *label;
 
83
    GtkWidget *vbox;
 
84
    GtkWidget *hbox;
 
85
    GtkWidget *frame;
 
86
    GtkWidget *image;
 
87
    GtkWidget *hseparator;
 
88
    GtkWidget *table;
 
89
    GtkWidget *alignment;
 
90
 
 
91
    guint8 *image_buffer = NULL;
 
92
    const nv_image_t *img;
 
93
 
 
94
    char *product_name, *bus_type, *vbios_version, *video_ram, *irq;
 
95
    char *os, *arch, *version;
 
96
    char scratch[64];
 
97
    ReturnStatus ret;
 
98
    gint tmp, os_val;
 
99
 
 
100
    gchar *__unknown = "Unknown";
 
101
 
 
102
    /*
 
103
     * get the data that we will display below
 
104
     * 
 
105
     * XXX should be able to update any of this if an attribute
 
106
     * changes.
 
107
     */
 
108
 
 
109
    /* NV_CTRL_STRING_PRODUCT_NAME */
 
110
 
 
111
    ret = NvCtrlGetStringAttribute(handle, NV_CTRL_STRING_PRODUCT_NAME,
 
112
                                   &product_name);
 
113
    if (ret != NvCtrlSuccess) product_name = "Unknown GPU";
 
114
    
 
115
    /* NV_CTRL_BUS_TYPE */
 
116
 
 
117
    ret = NvCtrlGetAttribute(handle, NV_CTRL_BUS_TYPE, &tmp);
 
118
    bus_type = NULL;
 
119
    if (ret == NvCtrlSuccess) {
 
120
        if (tmp == NV_CTRL_BUS_TYPE_AGP) bus_type = "AGP";
 
121
        if (tmp == NV_CTRL_BUS_TYPE_PCI) bus_type = "PCI";
 
122
        if (tmp == NV_CTRL_BUS_TYPE_PCI_EXPRESS) bus_type = "PCI Express";
 
123
    }
 
124
    if (!bus_type) bus_type = __unknown;
 
125
    
 
126
    /* NV_CTRL_STRING_VBIOS_VERSION */
 
127
 
 
128
    ret = NvCtrlGetStringAttribute(handle, NV_CTRL_STRING_VBIOS_VERSION,
 
129
                                   &vbios_version);
 
130
    if (ret != NvCtrlSuccess) vbios_version = __unknown;
 
131
    
 
132
    /* NV_CTRL_VIDEO_RAM */
 
133
 
 
134
    ret = NvCtrlGetAttribute(handle, NV_CTRL_VIDEO_RAM, &tmp);
 
135
    if (ret != NvCtrlSuccess) tmp = 0;
 
136
    video_ram = g_strdup_printf("%d MB", tmp >> 10);
 
137
        
 
138
    /* NV_CTRL_IRQ */
 
139
    
 
140
    ret = NvCtrlGetAttribute(handle, NV_CTRL_IRQ, &tmp);
 
141
    if (ret != NvCtrlSuccess) tmp = 0;
 
142
    irq = g_strdup_printf("%d", tmp);
 
143
    
 
144
    /* NV_CTRL_OPERATING_SYSTEM */
 
145
 
 
146
    os_val = NV_CTRL_OPERATING_SYSTEM_LINUX;
 
147
    ret = NvCtrlGetAttribute(handle, NV_CTRL_OPERATING_SYSTEM, &os_val);
 
148
    os = NULL;
 
149
    if (ret == NvCtrlSuccess) {
 
150
        if (os_val == NV_CTRL_OPERATING_SYSTEM_LINUX) os = "Linux";
 
151
        if (os_val == NV_CTRL_OPERATING_SYSTEM_FREEBSD) os = "FreeBSD";
 
152
    }
 
153
    if (!os) os = __unknown;
 
154
 
 
155
    /* NV_CTRL_ARCHITECTURE */
 
156
    
 
157
    ret = NvCtrlGetAttribute(handle, NV_CTRL_ARCHITECTURE, &tmp);
 
158
    arch = NULL;
 
159
    if (ret == NvCtrlSuccess) {
 
160
        if (tmp == NV_CTRL_ARCHITECTURE_X86) arch = "x86";
 
161
        if (tmp == NV_CTRL_ARCHITECTURE_X86_64) arch = "amd64";
 
162
        if (tmp == NV_CTRL_ARCHITECTURE_IA64) arch = "ia64";
 
163
    }
 
164
    if (!arch) arch = __unknown;
 
165
 
 
166
    snprintf(scratch, 64, "%s-%s", os, arch);
 
167
 
 
168
    /* NV_CTRL_STRING_NVIDIA_DRIVER_VERSION */
 
169
 
 
170
    ret = NvCtrlGetStringAttribute(handle,
 
171
                                   NV_CTRL_STRING_NVIDIA_DRIVER_VERSION,
 
172
                                   &version);
 
173
    if (ret != NvCtrlSuccess) version = __unknown;
 
174
    
 
175
    
 
176
    
 
177
    /* now, create the object */
 
178
    
 
179
    object = g_object_new(CTK_TYPE_DEVICE, NULL);
 
180
    ctk_device = CTK_DEVICE(object);
 
181
 
 
182
    /* cache the attribute handle */
 
183
 
 
184
    ctk_device->handle = handle;
 
185
 
 
186
    /* set container properties of the object */
 
187
 
 
188
    gtk_box_set_spacing(GTK_BOX(ctk_device), 10);
 
189
 
 
190
    /* banner */
 
191
 
 
192
    alignment = gtk_alignment_new(0, 0, 0, 0);
 
193
    gtk_box_pack_start(GTK_BOX(ctk_device), alignment, FALSE, FALSE, 0);
 
194
 
 
195
    frame = gtk_frame_new(NULL);
 
196
    gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
 
197
    gtk_container_add(GTK_CONTAINER(alignment), frame);
 
198
 
 
199
    if (os_val == NV_CTRL_OPERATING_SYSTEM_LINUX) {
 
200
        img = &big_banner_penguin_image;
 
201
    } else {
 
202
        img = &big_banner_bsd_image;
 
203
    }
 
204
 
 
205
    image_buffer = decompress_image_data(img);
 
206
 
 
207
    image = gtk_image_new_from_pixbuf
 
208
        (gdk_pixbuf_new_from_data(image_buffer, GDK_COLORSPACE_RGB,
 
209
                                  FALSE, 8, img->width, img->height,
 
210
                                  img->width * img->bytes_per_pixel,
 
211
                                  free_decompressed_image, NULL));
 
212
    
 
213
    gtk_container_add(GTK_CONTAINER(frame), image);
 
214
        
 
215
    /*
 
216
     * Device information: TOP->MIDDLE - LEFT->RIGHT
 
217
     *
 
218
     * This displays basic display adatper information, including
 
219
     * product name, bios version, bus type, video ram and interrupt
 
220
     * line.
 
221
     */
 
222
 
 
223
    vbox = gtk_vbox_new(FALSE, 5);
 
224
    gtk_box_pack_start(GTK_BOX(ctk_device), vbox, TRUE, TRUE, 0);
 
225
 
 
226
    hbox = gtk_hbox_new(FALSE, 0);
 
227
    gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
 
228
 
 
229
    label = gtk_label_new("Graphics Card Information");
 
230
    gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
 
231
 
 
232
    hseparator = gtk_hseparator_new();
 
233
    gtk_box_pack_start(GTK_BOX(hbox), hseparator, TRUE, TRUE, 5);
 
234
 
 
235
    table = gtk_table_new(7, 2, FALSE);
 
236
    gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
 
237
 
 
238
    gtk_table_set_row_spacings(GTK_TABLE(table), 3);
 
239
    gtk_table_set_col_spacings(GTK_TABLE(table), 15);
 
240
 
 
241
    gtk_container_set_border_width(GTK_CONTAINER(table), 5);
 
242
 
 
243
    
 
244
    add_table_row(table, 0, 0, "Graphics Processor:", product_name);
 
245
    add_table_row(table, 1, 0, "Bus Type:", bus_type);
 
246
    add_table_row(table, 2, 0, "VBIOS Version:", vbios_version);
 
247
    add_table_row(table, 3, 0, "Video Memory:", video_ram);
 
248
    add_table_row(table, 4, 0, "IRQ:", irq);
 
249
    add_table_row(table, 5, 0, "Operating System:", scratch);
 
250
    add_table_row(table, 6, 0, "NVIDIA Driver Version:", version);
 
251
 
 
252
  
 
253
   
 
254
    gtk_widget_show_all(GTK_WIDGET(object));
 
255
    
 
256
    return GTK_WIDGET(object);
 
257
}
 
258
 
 
259
 
 
260
static void add_table_row(GtkWidget *table,
 
261
                          const gint row,
 
262
                          const gint value_alignment,
 
263
                          const gchar *name,
 
264
                          const gchar *value)
 
265
{
 
266
    GtkWidget *label;
 
267
 
 
268
    label = gtk_label_new(name);
 
269
    gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
270
    gtk_table_attach(GTK_TABLE(table), label, 0, 1, row, row + 1,
 
271
                     GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
272
 
 
273
    label = gtk_label_new(value);
 
274
    gtk_misc_set_alignment(GTK_MISC(label), value_alignment, 0.5);
 
275
    gtk_table_attach(GTK_TABLE(table), label, 1, 2, row, row + 1,
 
276
                     GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
277
}
 
278
    
 
279
    
 
280
GtkTextBuffer *ctk_device_create_help(GtkTextTagTable *table,
 
281
                                      const gchar *screen_name)
 
282
{
 
283
    GtkTextIter i;
 
284
    GtkTextBuffer *b;
 
285
 
 
286
    b = gtk_text_buffer_new(table);
 
287
    
 
288
    gtk_text_buffer_get_iter_at_offset(b, &i, 0);
 
289
 
 
290
    ctk_help_title(b, &i, "Graphics Card Information Help");
 
291
 
 
292
    ctk_help_para(b, &i, "This page in the NVIDIA "
 
293
                  "X Server Control Panel describes basic "
 
294
                  "information about the Graphics Processing Unit "
 
295
                  "(GPU) on which the X screen '%s' is running.",
 
296
                  screen_name);
 
297
    
 
298
    ctk_help_heading(b, &i, "Graphics Processor");
 
299
    ctk_help_para(b, &i, "This is the product name of the GPU.");
 
300
    
 
301
    ctk_help_heading(b, &i, "Bus Type");
 
302
    ctk_help_para(b, &i, "This is the bus type which is "
 
303
                  "used to connect the NVIDIA GPU to the rest of "
 
304
                  "your computer; possible values are AGP, PCI, or "
 
305
                  "PCI Express.");
 
306
    
 
307
    ctk_help_heading(b, &i, "VBIOS Version");
 
308
    ctk_help_para(b, &i, "This is the Video BIOS version.");
 
309
    
 
310
    
 
311
    ctk_help_heading(b, &i, "Video Memory"); 
 
312
    ctk_help_para(b, &i, "This is the amount of video memory on your "
 
313
                  "graphics card.");
 
314
 
 
315
    ctk_help_heading(b, &i, "IRQ");
 
316
    ctk_help_para(b, &i, "This is the interrupt request line assigned to "
 
317
                  "this GPU.");
 
318
    
 
319
    ctk_help_heading(b, &i, "Operating System");
 
320
    ctk_help_para(b, &i, "This is the operating system on which the NVIDIA "
 
321
                  "X driver is running; possible values are "
 
322
                  "'Linux' and 'FreeBSD'.  This also specifies the platform "
 
323
                  "on which the operating system is running, such as x86, "
 
324
                  "amd64, or ia64");
 
325
    
 
326
    ctk_help_heading(b, &i, "NVIDIA Driver Version");
 
327
    ctk_help_para(b, &i, "This is the version of the NVIDIA Accelerated "
 
328
                  "Graphics Driver currently in use.");
 
329
    
 
330
    ctk_help_finish(b);
 
331
 
 
332
    return b;
 
333
}