~ubuntu-branches/ubuntu/dapper/hardinfo/dapper

« back to all changes in this revision

Viewing changes to hardinfo.c

  • Committer: Bazaar Package Importer
  • Author(s): Agney Lopes Roth Ferraz
  • Date: 2005-09-09 18:30:09 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050909183009-rtjed3czcwrw77z9
Tags: 0.3.7pre-2
Fixed FTBFS (file intl.c updated). Thanks to  Andreas Jochens. (Closes: #326033) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
#include "pixmaps/hdd.xpm"
18
18
#include "pixmaps/gen_connector.xpm"
19
19
#include "pixmaps/scsi.xpm"
 
20
#include "pixmaps/processor.xpm"
20
21
 
21
22
#include "computer.h"
22
23
#include "status.h"
 
24
#include "stock.h"
23
25
 
24
26
GenericDevice *generic_devices = NULL;
25
27
 
26
 
void hi_show_device_info(GtkCTree * tree, GList * node,
 
28
void hi_enable_details_button(GtkCTree * tree, GList * node,
27
29
                         gint column, gpointer user_data);
28
 
void hi_hide_device_info(GtkCTree * tree, GList * node,
 
30
void hi_enable_details_button_real(MainWindow *mainwindow, GenericDevice *dev);
 
31
void hi_disable_details_button(GtkCTree * tree, GList * node,
29
32
                         gint column, gpointer user_data);
30
33
void hi_scan_all(MainWindow * mainwindow);
31
34
 
37
40
        if (!mainwindow)
38
41
                return;
39
42
 
40
 
        hi_hide_device_info(NULL, NULL, 0, mainwindow);
 
43
        hi_disable_details_button(NULL, NULL, 0, mainwindow);
41
44
 
42
45
        memory_update(mainwindow);
43
46
        uptime_update(mainwindow);
50
53
about_window_create(void)
51
54
{
52
55
        GtkAbout *about;
 
56
        const gchar *sysinfo = HOSTNAME " (" PLATFORM KERNEL ")";
53
57
        const gchar *authors[] = {
54
58
                ">Written by:",
55
 
                        "Leandro Pereira (leandro@linuxmag.com.br)",
 
59
                "Leandro A. F. Pereira (leandro@linuxmag.com.br)",
56
60
                ">Disclaimer:",
57
 
                        "This is free software; you can modify and/or distribute it",
58
 
                        "under the terms of GNU GPL version 2. See http://www.fsf.org/",
59
 
                        "for more information.",
 
61
                "This is free software; you can modify and/or distribute it",
 
62
                "under the terms of GNU GPL version 2. See http://www.fsf.org/",
 
63
                "for more information.",
 
64
                ">Compiled on:",
 
65
                sysinfo,
60
66
                NULL
61
67
        };
62
68
 
63
69
        about = gtk_about_new("HardInfo", VERSION,
64
 
                              _("System information tool for Linux.\n"),
 
70
                              _("System information tool for GNU/Linux.\n"),
65
71
                              authors, IMG_PREFIX "logo.png");
66
72
 
67
73
}
69
75
MainWindow *
70
76
main_window_create(void)
71
77
{
72
 
        GtkWidget *window, *mbox, *vbox, *frame, *ctree, *scroll;
 
78
        GtkWidget *window, *mbox, *vbox, *ctree, *scroll;
73
79
        GtkWidget *notebook, *label, *hbox, *btn, *hbbox;
74
80
        MainWindow *mainwindow;
75
81
 
76
82
        mainwindow = g_new0(MainWindow, 1);
77
83
 
 
84
        mainwindow->det_window = detail_window_new();
 
85
 
78
86
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
79
87
        gtk_container_set_border_width(GTK_CONTAINER(window), 4);
80
88
        gtk_window_set_title(GTK_WINDOW(window), _("System Information"));
81
89
 
82
 
#ifdef GTK2
83
90
        g_signal_connect(G_OBJECT(window), "delete-event", gtk_main_quit, NULL);
84
 
#else
85
 
        gtk_signal_connect(GTK_OBJECT(window), "delete-event",
86
 
                           (GtkSignalFunc) gtk_main_quit, NULL);
87
 
#endif
 
91
        gtk_window_set_icon_from_file(GTK_WINDOW(window), IMG_PREFIX "logo.png", NULL);
88
92
 
89
93
        mbox = gtk_vbox_new(FALSE, 5);
90
94
        gtk_widget_show(mbox);
102
106
        gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox,
103
107
                                 gtk_label_new(_("Computer")));
104
108
 
105
 
#ifdef GTK2
106
109
        label = gtk_label_new(_("<b><big>Operating System</big></b>"));
107
110
        gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
108
 
#else
109
 
        label = gtk_label_new(_("Operating System"));
110
 
#endif
111
111
        gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
112
112
        gtk_widget_show(label);
113
113
        gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
114
114
        gtk_box_pack_start(GTK_BOX(vbox), os_get_widget(mainwindow),
115
115
                           FALSE, FALSE, 0);
116
116
 
117
 
#ifdef GTK2
118
117
        label = gtk_label_new(_("<b><big>Processor</big></b>"));
119
118
        gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
120
 
#else
121
 
        label = gtk_label_new(_("Processor"));
122
 
#endif
123
119
        gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
124
120
        gtk_widget_show(label);
125
121
        gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
126
122
        gtk_box_pack_start(GTK_BOX(vbox), processor_get_widget(), FALSE,
127
123
                           FALSE, 0);
128
124
 
129
 
#ifdef GTK2
130
125
        label = gtk_label_new(_("<b><big>Memory Usage</big></b>"));
131
126
        gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
132
 
#else
133
 
        label = gtk_label_new(_("Memory Usage"));
134
 
#endif
135
127
        gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
136
128
        gtk_widget_show(label);
137
129
        gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
145
137
        gtk_container_set_border_width(GTK_CONTAINER(vbox), 4);
146
138
        gtk_widget_show(vbox);
147
139
        gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox,
148
 
                                 gtk_label_new(_("Devices")));
 
140
                                 gtk_label_new(_("Details")));
 
141
 
 
142
        hbbox = gtk_hbutton_box_new();
 
143
        gtk_container_set_border_width(GTK_CONTAINER(hbbox), 4);
 
144
        gtk_widget_show(hbbox);
 
145
        gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
 
146
        gtk_button_box_set_spacing(GTK_BUTTON_BOX(hbbox), 6);
 
147
        gtk_button_box_set_layout(GTK_BUTTON_BOX(hbbox), GTK_BUTTONBOX_END);
 
148
 
 
149
        btn = gtk_button_new_from_stock(HI_DETAILS);
 
150
        g_signal_connect(G_OBJECT(btn), "clicked",
 
151
                         (GCallback) detail_window_show, mainwindow);
 
152
        gtk_widget_show(btn);
 
153
        gtk_box_pack_end(GTK_BOX(hbbox), btn, FALSE, FALSE, 0);
 
154
        mainwindow->details_button = btn;
149
155
 
150
156
        scroll = gtk_scrolled_window_new(NULL, NULL);
151
157
        gtk_box_pack_start(GTK_BOX(vbox), scroll, TRUE, TRUE, 0);
162
168
        gtk_clist_set_column_width(GTK_CLIST(ctree), 0, 32);
163
169
        gtk_clist_set_column_width(GTK_CLIST(ctree), 1, 32);
164
170
        gtk_clist_set_row_height(GTK_CLIST(ctree), 18);
165
 
#ifdef GTK2
166
171
        g_signal_connect(G_OBJECT(ctree), "tree-select-row",
167
 
                         (GCallback) hi_show_device_info, mainwindow);
 
172
                         (GCallback) hi_enable_details_button, mainwindow);
168
173
        g_signal_connect(G_OBJECT(ctree), "tree-unselect-row",
169
 
                         (GCallback) hi_hide_device_info, mainwindow);
170
 
#else
171
 
        gtk_signal_connect(GTK_OBJECT(ctree), "tree-select-row",
172
 
                           (GtkCTreeFunc) hi_show_device_info, mainwindow);
173
 
        gtk_signal_connect(GTK_OBJECT(ctree), "tree-unselect-row",
174
 
                           (GtkCTreeFunc) hi_hide_device_info, mainwindow);
175
 
#endif
176
 
 
177
 
        frame = gtk_frame_new(_("Device information"));
178
 
        gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0);
179
 
 
 
174
                         (GCallback) hi_disable_details_button, mainwindow);
 
175
                         
180
176
        /*
181
177
         * Environment tab
182
178
         */
186
182
        gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox,
187
183
                                 gtk_label_new(_("Environment")));
188
184
 
189
 
#ifdef GTK2
190
185
        label = gtk_label_new(_("<b><big>X-Window System</big></b>"));
191
186
        gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
192
 
#else
193
 
        label = gtk_label_new(_("X-Window System"));
194
 
#endif
195
187
        gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
196
188
        gtk_widget_show(label);
197
189
        gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
198
 
        gtk_box_pack_start(GTK_BOX(vbox), x11_get_widget(mainwindow),
199
 
                           FALSE, FALSE, 0);
 
190
//      gtk_box_pack_start(GTK_BOX(vbox), x11_get_widget(mainwindow),
 
191
//                         FALSE, FALSE, 0);
200
192
 
201
 
#if 0
202
193
        /*
203
194
         * Network tab
204
195
         */
208
199
        gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox,
209
200
                                 gtk_label_new(_("Network")));
210
201
 
211
 
#ifdef GTK2
212
202
        label = gtk_label_new(_("<b><big>Interfaces</big></b>"));
213
203
        gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
214
 
#else
215
 
        label = gtk_label_new(_("Interfaces"));
216
 
#endif
217
204
        gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
218
205
        gtk_widget_show(label);
219
206
        gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
220
207
        gtk_box_pack_start(GTK_BOX(vbox), net_get_widget(mainwindow),
221
208
                           TRUE, TRUE, 0);
222
209
 
223
 
#endif
224
210
        /*
225
211
         * Buttons
226
212
         */
227
 
 
228
213
        hbox = gtk_hbox_new(FALSE, 5);
229
214
        gtk_widget_show(hbox);
230
215
        gtk_box_pack_start(GTK_BOX(mbox), hbox, FALSE, FALSE, 0);
236
221
        gtk_button_box_set_spacing(GTK_BUTTON_BOX(hbbox), 6);
237
222
        gtk_button_box_set_layout(GTK_BUTTON_BOX(hbbox), GTK_BUTTONBOX_START);
238
223
 
239
 
        btn = gtk_button_new_with_mnemonic(_("Abo_ut..."));
240
 
#ifdef GTK2
 
224
        btn = gtk_button_new_from_stock(HI_ABOUT);
241
225
        g_signal_connect(G_OBJECT(btn), "clicked",
242
226
                         (GCallback) about_window_create, NULL);
243
 
#else
244
 
        gtk_signal_connect(GTK_OBJECT(btn), "clicked",
245
 
                           (GtkSignalFunc) about_window_create, NULL);
246
 
#endif
247
227
        gtk_widget_show(btn);
248
228
        gtk_box_pack_start(GTK_BOX(hbbox), btn, FALSE, FALSE, 0);
249
229
 
254
234
        gtk_button_box_set_spacing(GTK_BUTTON_BOX(hbbox), 6);
255
235
        gtk_button_box_set_layout(GTK_BUTTON_BOX(hbbox), GTK_BUTTONBOX_END);
256
236
 
257
 
#if 0
258
 
        btn = gtk_button_new_with_label(_("About"));
259
 
#ifdef GTK2
260
 
        g_signal_connect(G_OBJECT(btn), "clicked",
261
 
                         (GCallback) about_window_create, NULL);
262
 
#else
263
 
        gtk_signal_connect(GTK_OBJECT(btn), "clicked",
264
 
                           (GtkSignalFunc) about_window_create, NULL);
265
 
#endif
266
 
        gtk_widget_show(btn);
267
 
        gtk_box_pack_start(GTK_BOX(hbbox), btn, FALSE, FALSE, 0);
268
 
#endif
269
 
 
270
 
#ifdef GTK2
271
237
        btn = gtk_button_new_from_stock(GTK_STOCK_REFRESH);
272
238
        g_signal_connect(G_OBJECT(btn), "clicked",
273
239
                         (GCallback) main_window_refresh, mainwindow);
274
 
#else
275
 
        btn = gtk_button_new_with_label(_("Refresh"));
276
 
        gtk_signal_connect(GTK_OBJECT(btn), "clicked",
277
 
                           (GtkSignalFunc) main_window_refresh, mainwindow);
278
 
#endif
279
240
        gtk_widget_show(btn);
280
241
        gtk_box_pack_start(GTK_BOX(hbbox), btn, FALSE, FALSE, 0);
281
242
 
282
 
#ifdef GTK2
283
243
        btn = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
284
244
        g_signal_connect(G_OBJECT(btn), "clicked", gtk_main_quit, NULL);
285
 
#else
286
 
        btn = gtk_button_new_with_label(_("Close"));
287
 
        gtk_signal_connect(GTK_OBJECT(btn), "clicked",
288
 
                           (GtkSignalFunc) gtk_main_quit, NULL);
289
 
#endif
290
245
        gtk_widget_show(btn);
291
246
        gtk_box_pack_start(GTK_BOX(hbbox), btn, FALSE, FALSE, 0);
292
247
 
293
 
 
294
 
 
295
248
        gtk_widget_show_all(window);
296
 
        gtk_widget_hide(frame);
297
249
 
298
250
        mainwindow->window = window;
299
251
        mainwindow->ctree = ctree;
300
 
        mainwindow->frame = frame;
301
252
 
302
253
        return mainwindow;
303
254
}
347
298
        case SERIAL:
348
299
                pixmap = gdk_pixmap_colormap_create_from_xpm_d
349
300
                    (NULL, colormap, &mask, NULL, gen_connector_xpm);
350
 
 
351
301
                break;
352
302
        case V4L:
353
303
        case PCI:
367
317
                pixmap = gdk_pixmap_colormap_create_from_xpm_d
368
318
                    (NULL, colormap, &mask, NULL, usb_xpm);
369
319
                break;
 
320
        case MODULE:
 
321
        case PROCESSOR:
 
322
                pixmap = gdk_pixmap_colormap_create_from_xpm_d
 
323
                    (NULL, colormap, &mask, NULL, processor_xpm);
 
324
                break;
370
325
        default:
371
326
                mask = pixmap = NULL;
372
327
                break;
422
377
}
423
378
 
424
379
void
425
 
hi_hide_device_info(GtkCTree * tree, GList * node,
426
 
                    gint column, gpointer user_data)
427
 
{
428
 
        MainWindow *mainwindow = (MainWindow *) user_data;
429
 
 
430
 
        gtk_widget_hide(mainwindow->frame);
431
 
}
432
 
 
433
 
void
434
 
hi_show_device_info(GtkCTree * tree, GList * node,
435
 
                    gint column, gpointer user_data)
436
 
{
437
 
        GenericDevice *dev;
438
 
        MainWindow *mainwindow = (MainWindow *) user_data;
439
 
 
440
 
        dev = (GenericDevice *) gtk_ctree_node_get_row_data
441
 
            (GTK_CTREE(tree), GTK_CLIST(tree)->selection->data);
442
 
 
 
380
hi_disable_details_button(GtkCTree * tree, GList * node,
 
381
                    gint column, gpointer user_data)
 
382
{
 
383
        MainWindow *mainwindow = (MainWindow *) user_data;
 
384
 
 
385
        gtk_widget_set_sensitive(GTK_WIDGET(mainwindow->details_button), FALSE);
 
386
}
 
387
 
 
388
void hi_enable_details_button(GtkCTree * tree, GList * node,
 
389
                    gint column, gpointer user_data)
 
390
{
 
391
        MainWindow *mainwindow = (MainWindow *) user_data;
 
392
 
 
393
        gtk_widget_set_sensitive(GTK_WIDGET(mainwindow->details_button), TRUE);
 
394
}
 
395
 
 
396
void hi_show_device_info_real(MainWindow *mainwindow, GenericDevice *dev)
 
397
{
443
398
        if (!dev)
444
399
                return;
445
400
 
452
407
        break;
453
408
 
454
409
        switch (dev->type) {
 
410
        case MODULE:
 
411
                dev_info(ModInfo,   mod, hi_show_module_info);
 
412
        case PROCESSOR:
 
413
                dev_info(CPUDevice, cpu, hi_show_cpu_info);
455
414
        case PCI:
456
415
                dev_info(PCIDevice, pci, hi_show_pci_info);
457
416
        case ISAPnP:
474
433
                return;
475
434
                break;
476
435
        }
477
 
 
478
 
        gtk_widget_show(mainwindow->frame);
479
 
 
480
436
}
481
437
 
482
438
void
483
439
hi_scan_all(MainWindow * mainwindow)
484
440
{
485
 
        myStatus *status;
486
 
        PCIDevice *pci; 
487
 
        ISADevice *isa; 
488
 
        IDEDevice *ide;
489
 
        SCSIDevice *scsi;
490
 
        V4LDevice *v4l;
491
 
        ParportDevice *pp;
492
 
        SerialDevice *sd;
493
 
        GtkCTreeNode *node;
494
 
        GenericDevice *gd = generic_devices;
495
 
        gchar *buf;
 
441
        myStatus        *status;
 
442
        PCIDevice       *pci; 
 
443
        ISADevice       *isa; 
 
444
        IDEDevice       *ide;
 
445
        CPUDevice       *cpu;
 
446
        SCSIDevice      *scsi;
 
447
        V4LDevice       *v4l;
 
448
        ParportDevice   *pp;
 
449
        SerialDevice    *sd;
 
450
        GtkCTreeNode    *node;
 
451
        ModInfo         *mod;
 
452
        GenericDevice   *gd = generic_devices;
 
453
        gchar           *buf;
496
454
 
497
455
        status = my_status_new(_("Scanning Devices"), _("Scanning devices..."));
498
456
 
503
461
                g_free(buf); \
504
462
                my_status_pulse(status)
505
463
        
 
464
        DEVICE_SCAN("CPU",      cpu,    computer_get_info);
506
465
        DEVICE_SCAN("PCI",      pci,    hi_scan_pci);
507
466
        DEVICE_SCAN("ISA PnP",  isa,    hi_scan_isapnp);
508
467
        DEVICE_SCAN("IDE",      ide,    hi_scan_ide);
510
469
        DEVICE_SCAN("V4L",      v4l,    hi_scan_v4l);
511
470
        DEVICE_SCAN("Parallel", pp,     hi_scan_parport);
512
471
        DEVICE_SCAN("Serial",   sd,     hi_scan_serial);
 
472
        DEVICE_SCAN("modules",  mod,    hi_scan_modules);
513
473
 
514
474
        gtk_clist_freeze(GTK_CLIST(mainwindow->ctree));
515
475
 
539
499
                } \
540
500
        }
541
501
 
 
502
 
 
503
        /*
 
504
         * Processor info
 
505
         */
 
506
        node = tree_group_new(mainwindow, _("Processor"), PROCESSOR);
 
507
        hi_insert_generic(cpu, PROCESSOR);
 
508
        tree_insert_item(mainwindow, node, cpu->processor, generic_devices);
 
509
 
542
510
        CHECK_INSERT(pci, _("PCI Devices"), PCI, name);
543
511
        CHECK_INSERT(isa, _("ISA PnP Devices"), ISAPnP, card);
544
512
 
553
521
        CHECK_INSERT(v4l, _("Video for Linux"), V4L, name);
554
522
        CHECK_INSERT(sd, _("Communication Ports"), SERIAL, name);
555
523
        CHECK_INSERT(pp, _("Parallel Ports"), PARPORT, name);
556
 
 
 
524
 
 
525
        CHECK_INSERT(mod, _("Kernel Modules"), MODULE, description);
 
526
        
557
527
        gtk_clist_thaw(GTK_CLIST(mainwindow->ctree));
558
528
 
559
529
        my_status_destroy(status);
560
530
}
561
531
 
562
 
#if 0
563
532
static void
564
533
usage(char *argv0)
565
534
{
566
 
        g_print("%s [--prefix <prefix>]\n", argv0);
 
535
        g_print("%s [--help] [--prefix <prefix>]\n", argv0);
567
536
        exit(1);
568
537
}
569
 
#endif
570
538
 
571
539
int
572
540
main(int argc, char **argv)
573
541
{
574
542
        MainWindow *mainwindow;
575
 
#if 0
576
543
        gint i;
577
 
#endif
578
544
 
579
545
#ifdef ENABLE_NLS
580
546
        intl_init();
581
547
#endif
582
548
 
583
 
        g_print("HardInfo " VERSION "\n");
 
549
        g_print("HardInfo " VERSION);
 
550
        if (strstr(VERSION, "pre")) {
 
551
                g_print(" *** PRE-RELEASE ***");
 
552
        }
584
553
        g_print
585
 
            ("Copyright (c) 2003 Leandro Pereira <leandro@linuxmag.com.br>\n\n");
 
554
            ("\nCopyright (c) 2003 Leandro Pereira <leandro@linuxmag.com.br>\n\n");
586
555
        g_print(_
587
556
                ("This is free software; you can modify and/or distribute it\n"));
588
557
        g_print(_
591
560
 
592
561
        gtk_init(&argc, &argv);
593
562
 
594
 
#ifndef GTK2
595
 
        gdk_rgb_init();
596
 
        gtk_widget_set_default_colormap(gdk_rgb_get_cmap());
597
 
        gtk_widget_set_default_visual(gdk_rgb_get_visual());
598
 
#endif
 
563
        hi_stock_init();
599
564
 
600
 
#if 0
601
565
        for (i = 1; i < argc; i++) {
602
566
                if (!strncmp(argv[i], "--help", 6) ||
603
567
                    !strncmp(argv[i], "-h", 2)) {
612
576
                        g_print("prefix = %s\n", argv[i]);
613
577
                }
614
578
        }
615
 
#endif
616
579
 
617
580
        mainwindow = main_window_create();
618
581
        main_window_refresh(NULL, mainwindow);