File: icons.c

package info (click to toggle)
gscanbus 0.7.1-1.1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 656 kB
  • ctags: 496
  • sloc: ansic: 2,862; sh: 330; makefile: 52
file content (178 lines) | stat: -rw-r--r-- 5,302 bytes parent folder | download | duplicates (3)
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/* $Id: icons.c,v 1.4 2001/07/11 10:53:51 ami Exp $
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include "icons.h"

GdkPixmap *xpm_unknown = NULL;
GdkPixmap *xpm_dvcr = NULL;
GdkPixmap *xpm_disk = NULL;
GdkPixmap *xpm_cpu = NULL;
GdkPixmap *xpm_cpu_linux = NULL;
GdkPixmap *xpm_cpu_apple = NULL;
GdkPixmap *xpm_cpu_windows = NULL;
GdkBitmap *xpm_unknown_mask;
GdkBitmap *xpm_dvcr_mask;
GdkPixmap *xpm_disk_mask;
GdkBitmap *xpm_cpu_mask;
GdkBitmap *xpm_cpu_linux_mask;
GdkBitmap *xpm_cpu_apple_mask;
GdkBitmap *xpm_cpu_windows_mask;
GdkWindow *xpm_window = NULL;

int chooseIconVendor(Rom_info *, GdkBitmap **, GdkBitmap **, char **);
int contains(char *, char *);

#if 0
/*
 * Initialize a GdkPixmap and corresponding mask from an xpm file. If the
 * pixmap was already loaded and the window has not changed, nothing is done.
 * If the pixmap was already loaded and the window has changed, the pixmap
 * will be reloaded.
 * IN:	xpm:		previously initialized pixmap if any
 *	xpm_mask:	previously initialized mask if any
 *	xpm_window:	the window previously used for pixmaps
 *	window:		the window to use now for pixmaps
 *	filename:	the filename of the xpm to load
 * OUT:	xpm:		the loaded pixmap
 *	xpm_mask:	the loaded mask
 */
void init_xpm(GdkPixmap **xpm, GdkBitmap **xpm_mask, GdkWindow *xpm_window,
	GdkWindow *window, char *filename) {
	if (xpm_window != window) {
		if (*xpm != NULL) gdk_pixmap_unref(*xpm);
		if (*xpm_mask != NULL) gdk_bitmap_unref(*xpm_mask);
	}
	if (*xpm == NULL || xpm_window != window) {
		*xpm = gdk_pixmap_create_from_xpm(
			window, xpm_mask, NULL, filename);
	}
}
#endif

/*
 * Initialize a GdkPixmap and corresponding mask from xpm data. If the
 * pixmap was already loaded and the window has not changed, nothing is done.
 * If the pixmap was already loaded and the window has changed, the pixmap
 * will be reloaded.
 * IN:	xpm:		previously initialized pixmap if any
 *	xpm_mask:	previously initialized mask if any
 *	xpm_window:	the window previously used for pixmaps
 *	window:		the window to use now for pixmaps
 *	data:		a pointer to the xpm data
 * OUT:	xpm:		the loaded pixmap
 *	xpm_mask:	the loaded mask
 */
void init_xpm_d(GdkPixmap **xpm, GdkBitmap **xpm_mask, GdkWindow *xpm_window,
	GdkWindow *window, char **xpm_data) {
	if (xpm_window != window) {
		if (*xpm != NULL) gdk_pixmap_unref(*xpm);
		if (*xpm_mask != NULL) gdk_bitmap_unref(*xpm_mask);
	}
	if (*xpm == NULL || xpm_window != window) {
		*xpm = gdk_pixmap_create_from_xpm_d(
			window, xpm_mask, NULL, xpm_data);
	}
}

void initIcons(GdkWindow *window) {

	init_xpm_d(&xpm_unknown, &xpm_unknown_mask, xpm_window, window, 
		gnome_question_xpm);
	init_xpm_d(&xpm_dvcr, &xpm_dvcr_mask, xpm_window, window,
		gnome_qeye_xpm);
	init_xpm_d(&xpm_disk, &xpm_disk_mask, xpm_window, window,
		gtcd_xpm);
	init_xpm_d(&xpm_cpu, &xpm_cpu_mask, xpm_window, window,
		gnome_term_xpm);
	init_xpm_d(&xpm_cpu_linux, &xpm_cpu_linux_mask, xpm_window, window,
		gnome_term_linux_xpm);
	init_xpm_d(&xpm_cpu_apple, &xpm_cpu_apple_mask, xpm_window, window,
		gnome_term_apple_xpm);
	init_xpm_d(&xpm_cpu_windows, &xpm_cpu_windows_mask, xpm_window, window,
		gnome_term_windows_xpm);

	xpm_window = window;

}

void chooseIcon(Rom_info *rom_info, GdkBitmap **xpm_node,
	GdkBitmap **xpm_node_mask, char **label) {

	switch(rom_info->node_type) {
		case NODE_TYPE_CONF_CAM:
		case NODE_TYPE_AVC:
			*xpm_node = xpm_dvcr;
			*xpm_node_mask = xpm_dvcr_mask;
			*label = "AV/C Device";
			break;
		case NODE_TYPE_SBP2:
			*xpm_node = xpm_disk;
			*xpm_node_mask = xpm_disk_mask;
			*label = "SBP2 Device";
			break;
		case NODE_TYPE_CPU:
			if (chooseIconVendor(rom_info,
				xpm_node, xpm_node_mask, label) < 0) {
				*xpm_node = xpm_cpu;
				*xpm_node_mask = xpm_cpu_mask;
			}
			break;
		default:
			if (chooseIconVendor(rom_info,
				xpm_node, xpm_node_mask, label) < 0) {
				*xpm_node = xpm_unknown;
				*xpm_node_mask = xpm_unknown_mask;
			}
			break;
	}

}

int chooseIconVendor(Rom_info *rom_info, GdkBitmap **xpm_node,
	GdkBitmap **xpm_node_mask, char **label) {

	if (contains(rom_info->vendor, "apple")) {
		*xpm_node = xpm_cpu_apple;
		*xpm_node_mask = xpm_cpu_apple_mask;
		*label = "MacOS";
	} else if (contains(rom_info->vendor, "microsoft")) {
		*xpm_node = xpm_cpu_windows;
		*xpm_node_mask = xpm_cpu_windows_mask;
		*label = "Windows";
	} else return -1;
	return 0;

}

int contains(char *s1, char *s2) {

	int i;
	int ls1, ls2;
	char *ps1 = s1;

	if (s1 == NULL || s2 == NULL) return 0;
	ls1 = strlen(s1);
	ls2 = strlen(s2);

	for(i=0; i<ls1-ls2; i++) {
		if (strncasecmp(ps1++,s2,ls2) == 0) return -1;
	}

	return 0;

}