1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
/*
* Hardware Information, version 0.3
* Copyright (C) 2003 Leandro Pereira <leandro@linuxmag.com.br>
*
* May be modified and/or distributed under the terms of GNU GPL version 2.
*
*/
#include "hardinfo.h"
#include "v4l.h"
#include <stdlib.h>
#include <dirent.h>
#define get_str_val(var) { \
walk_until_inclusive(':'); buf++; \
var = g_strdup(buf); \
continue; \
}
V4LDevice *hi_scan_v4l(void)
{
FILE *proc_video;
DIR *proc_dir;
struct dirent *sd;
V4LDevice *v4l_dev, *v4l;
struct stat st;
v4l = NULL;
if (stat("/proc/video/dev", &st))
return NULL;
proc_dir = opendir("/proc/video/dev");
if(!proc_dir)
return NULL;
while (sd = readdir(proc_dir)) {
gchar *dev, buffer[128];
dev = g_strdup_printf("/proc/video/dev/%s", sd->d_name);
proc_video = fopen(dev, "r");
g_free(dev);
if(!proc_video)
continue;
v4l_dev = g_new0(V4LDevice, 1);
v4l_dev->next = v4l;
v4l = v4l_dev;
while (fgets(buffer, 128, proc_video)) {
char *buf = g_strstrip(buffer);
if(!strncmp(buf, "name", 4))
get_str_val(v4l_dev->name)
else if(!strncmp(buf, "type", 4))
get_str_val(v4l_dev->type)
}
fclose(proc_video);
}
return v4l;
}
void hi_show_v4l_info(MainWindow *mainwindow, V4LDevice *device)
{
GtkWidget *hbox, *vbox, *label;
gchar *buf;
#ifdef GTK2
GtkWidget *pixmap;
#endif
if(!device) return;
hbox = gtk_hbox_new(FALSE, 2);
gtk_container_set_border_width(GTK_CONTAINER(hbox), 4);
gtk_widget_show(hbox);
#ifdef GTK2
buf = g_strdup_printf("%sv4l.png", IMG_PREFIX);
pixmap = gtk_image_new_from_file(buf);
gtk_widget_show(pixmap);
gtk_box_pack_start(GTK_BOX(hbox), pixmap, FALSE, FALSE, 0);
g_free(buf);
#endif
if(mainwindow->framec)
gtk_widget_destroy(mainwindow->framec);
gtk_container_add(GTK_CONTAINER(mainwindow->frame), hbox);
mainwindow->framec = hbox;
gtk_frame_set_label(GTK_FRAME(mainwindow->frame), _("Device Information"));
vbox = gtk_vbox_new(FALSE, 5);
gtk_widget_show(vbox);
gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 0);
#ifdef GTK2
buf = g_strdup_printf("<b>%s</b>", device->name);
label = gtk_label_new(buf);
gtk_widget_show(label);
gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
g_free(buf);
#else
label = gtk_label_new(device->name);
gtk_widget_show(label);
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
#endif
if (device->type) {
gchar *b = g_strdup(device->type);
gpointer b_start = b;
do {
if (*b == '|') *b = '\n';
b++;
} while(*b);
b = b_start;
buf = g_strdup_printf("Type:\n%s", b);
label = gtk_label_new(buf);
gtk_widget_show(label);
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
g_free(buf);
g_free(b);
}
}
|