summaryrefslogtreecommitdiff
path: root/v4l.c
blob: 118d9fde105082a04d703fa6c0c31a6f7357708d (plain)
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
/*
 * 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)
{
	gchar *buf;

	if(!device) return;

	buf = g_strdup_printf("%sv4l.png", IMG_PREFIX);
	detail_window_set_icon(mainwindow->det_window, buf);	
	g_free(buf);

	gtk_window_set_title(GTK_WINDOW(mainwindow->det_window->window), _("Device Information"));
	

	detail_window_set_dev_name(mainwindow->det_window, device->name);

	if (device->type) {
		gchar *b = g_strdup(device->type);
		gpointer b_start = b;
	
		do {
			if (*b == '|') *b = '\n';
			b++;
		} while(*b);
		b = b_start;
	
		detail_window_append_info(mainwindow->det_window, _("Type"),
					  b);
		g_free(b);
	}
}