Subversion Repositories Kolibri OS

Rev

Rev 7647 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7647 Rev 7654
1
/*
1
/*
2
SOFTWARE CENTER v2.86
2
SOFTWARE CENTER v2.86
3
*/
3
*/
4
 
4
 
5
#define MEMSIZE 4096 * 15
5
#define MEMSIZE 4096 * 15
6
#include "..\lib\strings.h" 
6
#include "..\lib\strings.h" 
7
#include "..\lib\mem.h" 
7
#include "..\lib\mem.h" 
8
#include "..\lib\io.h"
8
#include "..\lib\io.h"
9
#include "..\lib\gui.h"
9
#include "..\lib\gui.h"
10
 
10
 
11
#include "..\lib\obj\libio.h"
11
#include "..\lib\obj\libio.h"
12
#include "..\lib\obj\libimg.h"
12
#include "..\lib\obj\libimg.h"
13
#include "..\lib\obj\libini.h"
13
#include "..\lib\obj\libini.h"
14
#include "..\lib\kfont.h"
14
#include "..\lib\kfont.h"
15
#include "..\lib\list_box.h"
15
#include "..\lib\list_box.h"
16
#include "..\lib\collection.h"
16
#include "..\lib\collection.h"
17
 
17
 
18
proc_info Form;
18
proc_info Form;
19
llist list;
19
llist list;
20
collection app_path_collection;
20
collection app_path_collection;
21
byte kolibrios_mounted;
21
byte kolibrios_mounted;
22
 
22
 
23
int window_width,
23
int window_width,
24
	window_height;
24
	window_height;
25
 
25
 
26
int list_pos, 
26
int list_pos, 
27
	row,
27
	row,
28
	col,
28
	col,
29
	default_icon;
29
	default_icon;
30
 
30
 
31
char window_title[128],
31
char window_title[128],
32
	 settings_ini_path[256] = "/sys/settings/";
32
	 settings_ini_path[256] = "/sys/settings/";
33
 
33
 
34
bool small_screen = false;
34
bool small_screen = false;
35
 
35
 
36
struct SW_COLORS 
36
struct SW_COLORS 
37
 {
37
 {
38
 	dword list_bg;
38
 	dword list_bg;
39
 	dword text;
39
 	dword text;
40
 	dword graph;
40
 	dword graph;
41
 	dword dark;
41
 	dword dark;
42
 	dword light;
42
 	dword light;
43
 } swc;
43
 } swc;
44
 
44
 
45
block ipos[128];
45
block ipos[128];
46
 
46
 
47
void load_config()
47
void load_config()
48
{
48
{
49
	ini_get_str stdcall (#settings_ini_path, "Config", "title", #window_title, sizeof(window_title), "Software widget");
49
	ini_get_str stdcall (#settings_ini_path, "Config", "title", #window_title, sizeof(window_title), "Software widget");
50
	ini_get_int stdcall (#settings_ini_path, "Config", "win_width", 690);
50
	ini_get_int stdcall (#settings_ini_path, "Config", "win_width", 690);
51
	window_width = EAX;
51
	window_width = EAX;
52
	ini_get_int stdcall (#settings_ini_path, "Config", "cell_w", 73);
52
	ini_get_int stdcall (#settings_ini_path, "Config", "cell_w", 73);
53
	list.item_w = EAX;
53
	list.item_w = EAX;
54
	ini_get_int stdcall (#settings_ini_path, "Config", "cell_h", 71);
54
	ini_get_int stdcall (#settings_ini_path, "Config", "cell_h", 71);
55
	list.item_h = EAX;
55
	list.item_h = EAX;
56
	ini_get_int stdcall (#settings_ini_path, "Config", "default_icon", 0);
56
	ini_get_int stdcall (#settings_ini_path, "Config", "default_icon", 2);
57
	default_icon = EAX;
57
	default_icon = EAX;
58
}
58
}
59
 
59
 
60
 
60
 
61
void main()
61
void main()
62
{   
62
{   
63
	dword id;
63
	dword id;
64
	kfont.init(DEFAULT_FONT);
64
	kfont.init(DEFAULT_FONT);
65
	load_dll(libio,  #libio_init,1);
65
	load_dll(libio,  #libio_init,1);
66
	load_dll(libimg, #libimg_init,1);
66
	load_dll(libimg, #libimg_init,1);
67
	load_dll(libini, #lib_init,1);
67
	load_dll(libini, #lib_init,1);
68
 
68
 
69
	kolibrios_mounted = dir_exists("/kolibrios");
69
	kolibrios_mounted = dir_exists("/kolibrios");
70
 
70
 
71
	if (param)
71
	if (param)
72
	{
72
	{
73
		strcpy(#settings_ini_path, #param);
73
		strcpy(#settings_ini_path, #param);
74
	}
74
	}
75
	else
75
	else
76
	{
76
	{
77
		strcat(#settings_ini_path, I_Path + strrchr(I_Path, '/'));
77
		strcat(#settings_ini_path, I_Path + strrchr(I_Path, '/'));
78
		strcat(#settings_ini_path, ".ini");		
78
		strcat(#settings_ini_path, ".ini");		
79
	}
79
	}
80
	
80
	
81
	load_config();
81
	load_config();
82
	list.cur_y = -1;
82
	list.cur_y = -1;
83
	list.y = 32;
83
	list.y = 32;
84
 
84
 
85
	DrawList();
85
	DrawList();
86
	window_height = row+1*list.item_h + list_pos + skin_height + 15;
86
	window_height = row+1*list.item_h + list_pos + skin_height + 15;
87
	if (window_height>screen.height) {
87
	if (window_height>screen.height) {
88
		window_width = screen.width;
88
		window_width = screen.width;
89
		list.item_h -= 5;
89
		list.item_h -= 5;
90
		window_height = row+1*list.item_h + list_pos + skin_height + 15;
90
		window_height = row+1*list.item_h + list_pos + skin_height + 15;
91
		small_screen = true;
91
		small_screen = true;
92
	}
92
	}
93
 
93
 
94
	loop() switch(WaitEvent())
94
	loop() switch(WaitEvent())
95
	{
95
	{
96
		case evKey:
96
		case evKey:
97
			GetKeys();
97
			GetKeys();
98
			if (SCAN_CODE_LEFT == key_scancode) key_scancode = SCAN_CODE_UP;
98
			if (SCAN_CODE_LEFT == key_scancode) key_scancode = SCAN_CODE_UP;
99
			if (SCAN_CODE_RIGHT == key_scancode) key_scancode = SCAN_CODE_DOWN;
99
			if (SCAN_CODE_RIGHT == key_scancode) key_scancode = SCAN_CODE_DOWN;
100
			if (list.ProcessKey(key_scancode)) DrawSelection();
100
			if (list.ProcessKey(key_scancode)) DrawSelection();
101
			if (SCAN_CODE_ENTER == key_scancode) EventRunApp(list.cur_y);
101
			if (SCAN_CODE_ENTER == key_scancode) EventRunApp(list.cur_y);
102
			break;
102
			break;
103
 
103
 
104
		case evButton:
104
		case evButton:
105
			id=GetButtonID();               
105
			id=GetButtonID();               
106
			if (id==1) ExitProcess();
106
			if (id==1) ExitProcess();
107
			if (id>=100) EventRunApp(id-100);
107
			if (id>=100) EventRunApp(id-100);
108
			break;
108
			break;
109
 
109
 
110
		case evReDraw:
110
		case evReDraw:
111
			SetAppColors();
111
			SetAppColors();
112
			DefineAndDrawWindow(screen.width-window_width/2,screen.height-window_height/2,window_width,window_height,0x74,system.color.work,"",0);
112
			DefineAndDrawWindow(screen.width-window_width/2,screen.height-window_height/2,window_width,window_height,0x74,system.color.work,"",0);
113
			GetProcessInfo(#Form, SelfInfo);
113
			GetProcessInfo(#Form, SelfInfo);
114
			if (Form.status_window>2) { 
114
			if (Form.status_window>2) { 
115
				DrawTitle(#window_title);
115
				DrawTitle(#window_title);
116
				break;
116
				break;
117
			}
117
			}
118
			if (small_screen) {
118
			if (small_screen) {
119
				DrawTitle(#window_title);
119
				DrawTitle(#window_title);
120
				list.y = 0;	
120
				list.y = 0;	
121
			} else {
121
			} else {
122
				DrawTitle(NULL); 
122
				DrawTitle(NULL); 
123
				draw_top_bar();
123
				draw_top_bar();
124
			}
124
			}
125
			DrawList();
125
			DrawList();
126
			DrawBar(0, row +1 * list.item_h + list_pos, Form.cwidth, -row - 1 * list.item_h - list_pos + Form.cheight, swc.list_bg);
126
			DrawBar(0, row +1 * list.item_h + list_pos, Form.cwidth, -row - 1 * list.item_h - list_pos + Form.cheight, swc.list_bg);
127
			DrawSelection();
127
			DrawSelection();
128
	}
128
	}
129
}
129
}
130
 
130
 
131
void SetAppColors()
131
void SetAppColors()
132
{
132
{
133
	dword bg_col, old_list_bg_color;
133
	dword bg_col, old_list_bg_color;
134
	system.color.get();
134
	system.color.get();
135
	old_list_bg_color = swc.list_bg;
135
	old_list_bg_color = swc.list_bg;
136
	bg_col = system.color.work;
136
	bg_col = system.color.work;
137
	if (GrayScaleImage(#bg_col,1,1)>=65) 
137
	if (GrayScaleImage(#bg_col,1,1)>=65) 
138
	{
138
	{
139
		//light colors
139
		//light colors
140
		swc.list_bg = 0xF3F3F3;
140
		swc.list_bg = 0xF3F3F3;
141
	 	swc.text = 0x000000;
141
	 	swc.text = 0x000000;
142
	 	swc.dark = 0xDCDCDC;
142
	 	swc.dark = 0xDCDCDC;
143
	 	swc.light = 0xFCFCFC;
143
	 	swc.light = 0xFCFCFC;
144
	} else {
144
	} else {
145
		//dark colors
145
		//dark colors
146
		swc.list_bg = system.color.work;
146
		swc.list_bg = system.color.work;
147
	 	swc.text = system.color.work_text;
147
	 	swc.text = system.color.work_text;
148
	 	swc.dark = system.color.work_dark;
148
	 	swc.dark = system.color.work_dark;
149
	 	swc.light = system.color.work_light;
149
	 	swc.light = system.color.work_light;
150
	}
150
	}
151
 
151
 
152
	if (swc.list_bg != old_list_bg_color)
152
	if (swc.list_bg != old_list_bg_color)
153
	{	
153
	{	
154
		Libimg_LoadImage(#skin, "/sys/icons32.png");
154
		Libimg_LoadImage(#skin, "/sys/icons32.png");
155
		Libimg_FillTransparent(skin.image, skin.w, skin.h, swc.list_bg);
155
		Libimg_FillTransparent(skin.image, skin.w, skin.h, swc.list_bg);
156
	}
156
	}
157
}
157
}
158
 
158
 
159
 
159
 
160
void DrawList() {
160
void DrawList() {
161
	list.count = 0;
161
	list.count = 0;
162
	row = -1;
162
	row = -1;
163
	app_path_collection.drop();
163
	app_path_collection.drop();
164
	list_pos = list.y;
164
	list_pos = list.y;
165
	list.column_max = window_width - 10 / list.item_w;
165
	list.column_max = window_width - 10 / list.item_w;
166
	ini_enum_sections stdcall (#settings_ini_path, #process_sections);
166
	ini_enum_sections stdcall (#settings_ini_path, #process_sections);
167
	list.visible = list.count;
167
	list.visible = list.count;
168
}
168
}
169
 
169
 
170
byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name)
170
byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name)
171
{
171
{
172
	int tmp,
172
	int tmp,
173
		icon_id,
173
		icon_id,
174
		icon_char_pos;
174
		icon_char_pos;
175
	int text_w;
175
	int text_w;
176
 
176
 
177
	//do not show items located in /kolibrios/ if this directory not mounted
177
	//do not show items located in /kolibrios/ if this directory not mounted
178
	if (!strncmp(key_value, "/kolibrios/", 11)) || (!strncmp(key_value, "/k/", 3))
178
	if (!strncmp(key_value, "/kolibrios/", 11)) || (!strncmp(key_value, "/k/", 3))
179
		if (!kolibrios_mounted) return true;
179
		if (!kolibrios_mounted) return true;
180
 
180
 
181
	if (col==list.column_max) {
181
	if (col==list.column_max) {
182
		row++;
182
		row++;
183
		col=0;
183
		col=0;
184
	}
184
	}
185
 
185
 
186
	if (col==0) DrawBar(0, row * list.item_h + list_pos, Form.cwidth, list.item_h, swc.list_bg);
186
	if (col==0) DrawBar(0, row * list.item_h + list_pos, Form.cwidth, list.item_h, swc.list_bg);
187
	DefineButton(col*list.item_w+6, row*list.item_h + list_pos,list.item_w,list.item_h-5,list.count + 100 + BT_HIDE,0);
187
	DefineButton(col*list.item_w+6, row*list.item_h + list_pos,list.item_w,list.item_h-5,list.count + 100 + BT_HIDE,0);
188
	tmp = list.item_w/2;
188
	tmp = list.item_w/2;
189
 
189
 
190
	icon_char_pos = strchr(key_value, ',');
190
	icon_char_pos = strchr(key_value, ',');
191
	if (icon_char_pos) icon_id = atoi(icon_char_pos+1); else icon_id = default_icon;
191
	if (icon_char_pos) icon_id = atoi(icon_char_pos+1); else icon_id = default_icon;
192
	img_draw stdcall(skin.image, col*list.item_w+tmp-10, row*list.item_h+5 + list_pos, 32, 32, 0, icon_id*32);
192
	img_draw stdcall(skin.image, col*list.item_w+tmp-10, row*list.item_h+5 + list_pos, 32, 32, 0, icon_id*32);
193
	if (icon_char_pos) ESBYTE[icon_char_pos] = '\0'; //delete icon from string
193
	if (icon_char_pos) ESBYTE[icon_char_pos] = '\0'; //delete icon from string
194
	app_path_collection.add(key_value);
194
	app_path_collection.add(key_value);
195
	//kfont.WriteIntoWindowCenter(col*list.item_w+7,row*list.item_h+47 + list_pos, list.item_w,0, swc.list_bg, swc.dark, 12, key_name);
195
	//kfont.WriteIntoWindowCenter(col*list.item_w+7,row*list.item_h+47 + list_pos, list.item_w,0, swc.list_bg, swc.dark, 12, key_name);
196
	text_w = kfont.WriteIntoWindowCenter(col*list.item_w+5,row*list.item_h+46 + list_pos, list.item_w,0, swc.list_bg, swc.text, 12, key_name);
196
	text_w = kfont.WriteIntoWindowCenter(col*list.item_w+5,row*list.item_h+46 + list_pos, list.item_w,0, swc.list_bg, swc.text, 12, key_name);
197
	ipos[list.count].x = list.item_w-text_w/2+calc(col*list.item_w)+5;
197
	ipos[list.count].x = list.item_w-text_w/2+calc(col*list.item_w)+5;
198
	ipos[list.count].y = row*list.item_h+46 + list_pos + 16;
198
	ipos[list.count].y = row*list.item_h+46 + list_pos + 16;
199
	ipos[list.count].w = text_w;
199
	ipos[list.count].w = text_w;
200
	list.count++;
200
	list.count++;
201
	col++;
201
	col++;
202
	return true;
202
	return true;
203
}
203
}
204
 
204
 
205
 
205
 
206
int old_row; //to detect empty sections
206
int old_row; //to detect empty sections
207
byte process_sections(dword sec_name, f_name)
207
byte process_sections(dword sec_name, f_name)
208
{
208
{
209
	int text_len;
209
	int text_len;
210
	if (!strcmp(sec_name, "Config")) return true;
210
	if (!strcmp(sec_name, "Config")) return true;
211
 
211
 
212
	if ((col==0) && (row==old_row)) 
212
	if ((col==0) && (row==old_row)) 
213
	{
213
	{
214
		list_pos -= 28;
214
		list_pos -= 28;
215
	}
215
	}
216
	else
216
	else
217
	{
217
	{
218
		row++;
218
		row++;
219
	}
219
	}
220
	col = 0;
220
	col = 0;
221
	old_row = row;
221
	old_row = row;
222
 
222
 
223
	if (!small_screen) {
223
	if (!small_screen) {
224
		DrawBar(0, row * list.item_h + list_pos, Form.cwidth , 29, swc.list_bg);
224
		DrawBar(0, row * list.item_h + list_pos, Form.cwidth , 29, swc.list_bg);
225
		text_len = kfont.WriteIntoWindow(10, row * list.item_h + 10 + list_pos, swc.list_bg, swc.text, 15, sec_name);
225
		text_len = kfont.WriteIntoWindow(10, row * list.item_h + 10 + list_pos, swc.list_bg, swc.text, 15, sec_name);
226
		DrawBar(text_len+20, row * list.item_h + list_pos + 20, Form.cwidth-text_len-20, 1, swc.dark);
226
		DrawBar(text_len+20, row * list.item_h + list_pos + 20, Form.cwidth-text_len-20, 1, swc.dark);
227
		DrawBar(text_len+20, row * list.item_h + list_pos + 21, Form.cwidth-text_len-20, 1, swc.light);
227
		DrawBar(text_len+20, row * list.item_h + list_pos + 21, Form.cwidth-text_len-20, 1, swc.light);
228
		list_pos += 29;		
228
		list_pos += 29;		
229
	}
229
	}
230
	ini_enum_keys stdcall (f_name, sec_name, #draw_icons_from_section);
230
	ini_enum_keys stdcall (f_name, sec_name, #draw_icons_from_section);
231
	return true;
231
	return true;
232
}
232
}
233
 
233
 
234
void draw_top_bar()
234
void draw_top_bar()
235
{
235
{
236
	DrawBar(0,0,Form.cwidth, list.y-2, system.color.work);
236
	DrawBar(0,0,Form.cwidth, list.y-2, system.color.work);
237
	DrawBar(0,list.y-2, Form.cwidth, 1, MixColors(system.color.work, system.color.work_graph, 180));
237
	DrawBar(0,list.y-2, Form.cwidth, 1, MixColors(system.color.work, system.color.work_graph, 180));
238
	DrawBar(0,list.y-1, Form.cwidth, 1, system.color.work_graph);
238
	DrawBar(0,list.y-1, Form.cwidth, 1, system.color.work_graph);
239
	kfont.WriteIntoWindowCenter(0,5, Form.cwidth, list.y, system.color.work, system.color.work_text, 16, #window_title);
239
	kfont.WriteIntoWindowCenter(0,5, Form.cwidth, list.y, system.color.work, system.color.work_text, 16, #window_title);
240
}
240
}
241
 
241
 
242
void EventRunApp(dword appid)
242
void EventRunApp(dword appid)
243
{
243
{
244
	char run_app_path[4096]=0;
244
	char run_app_path[4096]=0;
245
	dword app_path = app_path_collection.get(appid);
245
	dword app_path = app_path_collection.get(appid);
246
	dword param_pos = strchr(app_path, '|');
246
	dword param_pos = strchr(app_path, '|');
247
	if (param_pos) {
247
	if (param_pos) {
248
		ESBYTE[param_pos] = NULL;
248
		ESBYTE[param_pos] = NULL;
249
		param_pos++;
249
		param_pos++;
250
	}
250
	}
251
 
251
 
252
	// the next block is created to save some space in ramdisk{
252
	// the next block is created to save some space in ramdisk{
253
	//
253
	//
254
	// convert relative path to absolute      "calc"    => "/sys/calc"
254
	// convert relative path to absolute      "calc"    => "/sys/calc"
255
	// convert short kolibrios path to full   "/k/calc" => "/kolibrios/calc"
255
	// convert short kolibrios path to full   "/k/calc" => "/kolibrios/calc"
256
	// other copy => as is
256
	// other copy => as is
257
	if (ESBYTE[app_path]!='/') {
257
	if (ESBYTE[app_path]!='/') {
258
		strcpy(#run_app_path, "/sys/");
258
		strcpy(#run_app_path, "/sys/");
259
	}
259
	}
260
	else if (!strncmp(app_path, "/k/",3)) {
260
	else if (!strncmp(app_path, "/k/",3)) {
261
		strcpy(#run_app_path, "/kolibrios/");
261
		strcpy(#run_app_path, "/kolibrios/");
262
		app_path+=3;
262
		app_path+=3;
263
	}
263
	}
264
	strcat(#run_app_path, app_path);
264
	strcat(#run_app_path, app_path);
265
	// }end
265
	// }end
266
 
266
 
267
	if (file_exists(#run_app_path))
267
	if (file_exists(#run_app_path))
268
	{
268
	{
269
		io.run(#run_app_path, param_pos); //0 or offset
269
		io.run(#run_app_path, param_pos); //0 or offset
270
		if (param_pos) ESBYTE[param_pos - 1] = '|';
270
		if (param_pos) ESBYTE[param_pos - 1] = '|';
271
	}
271
	}
272
	else
272
	else
273
	{
273
	{
274
		notify("'Application not found' -E");
274
		notify("'Application not found' -E");
275
	}
275
	}
276
}
276
}
277
 
277
 
278
void DrawSelection()
278
void DrawSelection()
279
{
279
{
280
	int i;
280
	int i;
281
	dword col;
281
	dword col;
282
	for (i=0; i
282
	for (i=0; i
283
		if (i==list.cur_y) col=0x0080FF; else col=swc.list_bg;
283
		if (i==list.cur_y) col=0x0080FF; else col=swc.list_bg;
284
		DrawBar(ipos[i].x, ipos[i].y, ipos[i].w+2, 3, col);
284
		DrawBar(ipos[i].x, ipos[i].y, ipos[i].w+2, 3, col);
285
	}
285
	}
286
}
286
}
287
 
287
 
288
 
288
 
289
stop:
289
stop: