Subversion Repositories Kolibri OS

Rev

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

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