Subversion Repositories Kolibri OS

Rev

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

Rev 6955 Rev 7049
1
/*
1
/*
2
SOFTWARE CENTER v2.8
2
SOFTWARE CENTER v2.8
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_lib.h"
11
#include "..\lib\obj\libio.h"
12
#include "..\lib\obj\libimg_lib.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
#include "..\lib\patterns\libimg_load_skin.h"
17
#include "..\lib\patterns\libimg_load_skin.h"
18
 
18
 
19
proc_info Form;
19
proc_info Form;
20
llist list;
20
llist list;
21
collection app_path_collection;
21
collection app_path_collection;
22
byte kolibrios_mounted;
22
byte kolibrios_mounted;
23
 
23
 
24
int window_width,
24
int window_width,
25
	window_height;
25
	window_height;
26
 
26
 
27
int list_pos, 
27
int list_pos, 
28
	row,
28
	row,
29
	col,
29
	col,
30
	default_icon;
30
	default_icon;
31
 
31
 
32
char window_title[128],
32
char window_title[128],
33
	 settings_ini_path[256] = "/sys/settings/";
33
	 settings_ini_path[256] = "/sys/settings/";
34
 
34
 
35
#define LIST_BACKGROUND_COLOR 0xF3F3F3
35
#define LIST_BACKGROUND_COLOR 0xF3F3F3
36
 
36
 
37
void load_config()
37
void load_config()
38
{
38
{
39
	ini_get_str stdcall (#settings_ini_path, "Config", "window_title", #window_title, sizeof(window_title), "Software widget");
39
	ini_get_str stdcall (#settings_ini_path, "Config", "window_title", #window_title, sizeof(window_title), "Software widget");
40
	ini_get_int stdcall (#settings_ini_path, "Config", "window_width", 690);
40
	ini_get_int stdcall (#settings_ini_path, "Config", "window_width", 690);
41
	window_width = EAX;
41
	window_width = EAX;
42
	ini_get_int stdcall (#settings_ini_path, "Config", "cell_w", 73);
42
	ini_get_int stdcall (#settings_ini_path, "Config", "cell_w", 73);
43
	list.item_w = EAX;
43
	list.item_w = EAX;
44
	ini_get_int stdcall (#settings_ini_path, "Config", "cell_h", 71);
44
	ini_get_int stdcall (#settings_ini_path, "Config", "cell_h", 71);
45
	list.item_h = EAX;
45
	list.item_h = EAX;
46
	ini_get_int stdcall (#settings_ini_path, "Config", "default_icon", 0);
46
	ini_get_int stdcall (#settings_ini_path, "Config", "default_icon", 0);
47
	default_icon = EAX;
47
	default_icon = EAX;
48
}
48
}
49
 
49
 
50
 
50
 
51
void main()
51
void main()
52
{   
52
{   
53
	dword id;
53
	dword id;
54
	kfont.init(DEFAULT_FONT);
54
	kfont.init(DEFAULT_FONT);
55
	load_dll(libio,  #libio_init,1);
55
	load_dll(libio,  #libio_init,1);
56
	load_dll(libimg, #libimg_init,1);
56
	load_dll(libimg, #libimg_init,1);
57
	load_dll(libini, #lib_init,1);
57
	load_dll(libini, #lib_init,1);
58
 
58
 
59
	Libimg_LoadImage(#skin, "/sys/icons32.png");
59
	Libimg_LoadImage(#skin, "/sys/icons32.png");
60
	Libimg_FillTransparent(skin.image, skin.w, skin.h, LIST_BACKGROUND_COLOR);
60
	Libimg_FillTransparent(skin.image, skin.w, skin.h, LIST_BACKGROUND_COLOR);
61
	kolibrios_mounted = dir_exists("/kolibrios");
61
	kolibrios_mounted = dir_exists("/kolibrios");
62
 
62
 
63
	if (param)
63
	if (param)
64
	{
64
	{
65
		strcpy(#settings_ini_path, #param);
65
		strcpy(#settings_ini_path, #param);
66
	}
66
	}
67
	else
67
	else
68
	{
68
	{
69
		strcat(#settings_ini_path, I_Path + strrchr(I_Path, '/'));
69
		strcat(#settings_ini_path, I_Path + strrchr(I_Path, '/'));
70
		strcat(#settings_ini_path, ".ini");		
70
		strcat(#settings_ini_path, ".ini");		
71
	}
71
	}
72
	
72
	
73
	load_config();
73
	load_config();
74
	list.cur_y = -1;
74
	list.cur_y = -1;
75
	list.y = 32;
75
	list.y = 32;
76
 
76
 
77
	DrawList();
77
	DrawList();
78
	window_height = row+1*list.item_h + list_pos + skin_height + 15;
78
	window_height = row+1*list.item_h + list_pos + skin_height + 15;
79
 
79
 
80
	loop() switch(WaitEvent())
80
	loop() switch(WaitEvent())
81
	{
81
	{
82
		// case evKey:
82
		// case evKey:
83
		// 	GetKeys();
83
		// 	GetKeys();
84
		// 	if (list.ProcessKey(key_scancode)) DrawList();
84
		// 	if (list.ProcessKey(key_scancode)) DrawList();
85
		// 	break;
85
		// 	break;
86
 
86
 
87
		case evButton:
87
		case evButton:
88
			id=GetButtonID();               
88
			id=GetButtonID();               
89
			if (id==1) ExitProcess();
89
			if (id==1) ExitProcess();
90
			if (id>=100) EventRunApp(id-100);
90
			if (id>=100) EventRunApp(id-100);
91
			break;
91
			break;
92
 
92
 
93
		case evReDraw:
93
		case evReDraw:
94
			system.color.get();
94
			system.color.get();
95
			DefineAndDrawWindow(screen.width-window_width/2,screen.height-window_height/2,window_width,window_height,0x74,system.color.work,"",0);
95
			DefineAndDrawWindow(screen.width-window_width/2,screen.height-window_height/2,window_width,window_height,0x74,system.color.work,"",0);
96
			GetProcessInfo(#Form, SelfInfo);
96
			GetProcessInfo(#Form, SelfInfo);
97
			if (Form.status_window>2) { DrawTitle(#window_title); break; } else DrawTitle("");
97
			if (Form.status_window>2) { DrawTitle(#window_title); break; } else DrawTitle("");
98
			draw_top_bar();
98
			draw_top_bar();
99
			DrawList();
99
			DrawList();
100
			DrawBar(0, row + 1 * list.item_h + list_pos, Form.cwidth, -row - 1 * list.item_h - list_pos + Form.cheight, LIST_BACKGROUND_COLOR);
100
			DrawBar(0, row + 1 * list.item_h + list_pos, Form.cwidth, -row - 1 * list.item_h - list_pos + Form.cheight, LIST_BACKGROUND_COLOR);
101
			break;
101
			break;
102
	}
102
	}
103
}
103
}
104
 
104
 
105
void DrawList() {
105
void DrawList() {
106
	list.count = 0;
106
	list.count = 0;
107
	row = -1;
107
	row = -1;
108
	app_path_collection.drop();
108
	app_path_collection.drop();
109
	list_pos = list.y;
109
	list_pos = list.y;
110
	list.column_max = window_width - 10 / list.item_w;
110
	list.column_max = window_width - 10 / list.item_w;
111
	ini_enum_sections stdcall (#settings_ini_path, #process_sections);
111
	ini_enum_sections stdcall (#settings_ini_path, #process_sections);
112
	list.visible = list.count;
112
	list.visible = list.count;
113
}
113
}
114
 
114
 
115
byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name)
115
byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name)
116
{
116
{
117
	int tmp,
117
	int tmp,
118
		icon_id,
118
		icon_id,
119
		icon_char_pos;
119
		icon_char_pos;
120
 
120
 
121
	//do not show items located in /kolibrios/ if this directory not mounted
121
	//do not show items located in /kolibrios/ if this directory not mounted
122
	if (!strncmp(key_value, "/kolibrios/", 11)) && (!kolibrios_mounted) return true;
122
	if (!strncmp(key_value, "/kolibrios/", 11)) && (!kolibrios_mounted) return true;
123
 
123
 
124
	if (col==list.column_max) {
124
	if (col==list.column_max) {
125
		row++;
125
		row++;
126
		col=0;
126
		col=0;
127
	}
127
	}
128
 
128
 
129
	if (col==0) DrawBar(0, row * list.item_h + list_pos, Form.cwidth, list.item_h, LIST_BACKGROUND_COLOR);
129
	if (col==0) DrawBar(0, row * list.item_h + list_pos, Form.cwidth, list.item_h, LIST_BACKGROUND_COLOR);
130
	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);
130
	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);
131
	tmp = list.item_w/2;
131
	tmp = list.item_w/2;
132
 
132
 
133
	icon_char_pos = strchr(key_value, ',');
133
	icon_char_pos = strchr(key_value, ',');
134
	if (icon_char_pos) icon_id = atoi(icon_char_pos+1); else icon_id = default_icon;
134
	if (icon_char_pos) icon_id = atoi(icon_char_pos+1); else icon_id = default_icon;
135
	img_draw stdcall(skin.image, col*list.item_w+tmp-10, row*list.item_h+5 + list_pos, 32, 32, 0, icon_id*32);
135
	img_draw stdcall(skin.image, col*list.item_w+tmp-10, row*list.item_h+5 + list_pos, 32, 32, 0, icon_id*32);
136
	if (icon_char_pos) ESBYTE[icon_char_pos] = '\0'; //delete icon from string
136
	if (icon_char_pos) ESBYTE[icon_char_pos] = '\0'; //delete icon from string
137
	app_path_collection.add(key_value);
137
	app_path_collection.add(key_value);
138
	//kfont.WriteIntoWindowCenter(col*list.item_w+7,row*list.item_h+47 + list_pos, list.item_w,0, LIST_BACKGROUND_COLOR, 0xDCDCDC, 12, key_name);
138
	//kfont.WriteIntoWindowCenter(col*list.item_w+7,row*list.item_h+47 + list_pos, list.item_w,0, LIST_BACKGROUND_COLOR, 0xDCDCDC, 12, key_name);
139
	kfont.WriteIntoWindowCenter(col*list.item_w+6,row*list.item_h+46 + list_pos, list.item_w,0, LIST_BACKGROUND_COLOR, 0x000000, 12, key_name);
139
	kfont.WriteIntoWindowCenter(col*list.item_w+6,row*list.item_h+46 + list_pos, list.item_w,0, LIST_BACKGROUND_COLOR, 0x000000, 12, key_name);
140
	if (list.cur_y == list.count) DrawWideRectangle(col*list.item_w+6, row*list.item_h + list_pos,list.item_w,list.item_h-5, 2, 0x0080FF);
140
	if (list.cur_y == list.count) DrawWideRectangle(col*list.item_w+6, row*list.item_h + list_pos,list.item_w,list.item_h-5, 2, 0x0080FF);
141
	list.count++;
141
	list.count++;
142
	col++;
142
	col++;
143
	return true;
143
	return true;
144
}
144
}
145
 
145
 
146
 
146
 
147
int old_row; //to detect empty sections
147
int old_row; //to detect empty sections
148
byte process_sections(dword sec_name, f_name)
148
byte process_sections(dword sec_name, f_name)
149
{
149
{
150
	int text_len;
150
	int text_len;
151
	if (!strcmp(sec_name, "Config")) return true;
151
	if (!strcmp(sec_name, "Config")) return true;
152
 
152
 
153
	if ((col==0) && (row==old_row)) 
153
	if ((col==0) && (row==old_row)) 
154
	{
154
	{
155
		list_pos -= 28;
155
		list_pos -= 28;
156
	}
156
	}
157
	else
157
	else
158
	{
158
	{
159
		row++;
159
		row++;
160
	}
160
	}
161
	col = 0;
161
	col = 0;
162
	old_row = row;
162
	old_row = row;
163
	DrawBar(0, row * list.item_h + list_pos, Form.cwidth , 29, LIST_BACKGROUND_COLOR);
163
	DrawBar(0, row * list.item_h + list_pos, Form.cwidth , 29, LIST_BACKGROUND_COLOR);
164
	text_len = kfont.WriteIntoWindow(10, row * list.item_h + 10 + list_pos, LIST_BACKGROUND_COLOR, 0, 15, sec_name);
164
	text_len = kfont.WriteIntoWindow(10, row * list.item_h + 10 + list_pos, LIST_BACKGROUND_COLOR, 0, 15, sec_name);
165
	DrawBar(text_len+20, row * list.item_h + list_pos + 20, Form.cwidth-text_len-20, 1, 0xDCDCDC);
165
	DrawBar(text_len+20, row * list.item_h + list_pos + 20, Form.cwidth-text_len-20, 1, 0xDCDCDC);
166
	DrawBar(text_len+20, row * list.item_h + list_pos + 21, Form.cwidth-text_len-20, 1, 0xFCFCFC);
166
	DrawBar(text_len+20, row * list.item_h + list_pos + 21, Form.cwidth-text_len-20, 1, 0xFCFCFC);
167
	list_pos += 29;
167
	list_pos += 29;
168
	ini_enum_keys stdcall (f_name, sec_name, #draw_icons_from_section);
168
	ini_enum_keys stdcall (f_name, sec_name, #draw_icons_from_section);
169
	return true;
169
	return true;
170
}
170
}
171
 
171
 
172
void draw_top_bar()
172
void draw_top_bar()
173
{
173
{
174
	DrawBar(0,0,Form.cwidth, list.y-2, system.color.work);
174
	DrawBar(0,0,Form.cwidth, list.y-2, system.color.work);
175
	DrawBar(0,list.y-2, Form.cwidth, 1, MixColors(system.color.work, system.color.work_graph, 180));
175
	DrawBar(0,list.y-2, Form.cwidth, 1, MixColors(system.color.work, system.color.work_graph, 180));
176
	DrawBar(0,list.y-1, Form.cwidth, 1, system.color.work_graph);
176
	DrawBar(0,list.y-1, Form.cwidth, 1, system.color.work_graph);
177
	kfont.WriteIntoWindowCenter(0,5, Form.cwidth, list.y, system.color.work, system.color.work_text, 16, #window_title);
177
	kfont.WriteIntoWindowCenter(0,5, Form.cwidth, list.y, system.color.work, system.color.work_text, 16, #window_title);
178
}
178
}
179
 
179
 
180
void EventRunApp(dword appid)
180
void EventRunApp(dword appid)
181
{
181
{
182
	dword app_path = app_path_collection.get(appid);
182
	dword app_path = app_path_collection.get(appid);
183
	
183
	
184
	dword param_pos = strchr(app_path, '|');
184
	dword param_pos = strchr(app_path, '|');
185
	if (param_pos) {
185
	if (param_pos) {
186
		ESBYTE[param_pos] = NULL;
186
		ESBYTE[param_pos] = NULL;
187
		param_pos++;
187
		param_pos++;
188
	}
188
	}
189
 
189
 
190
	if (file_exists(app_path))
190
	if (file_exists(app_path))
191
	{
191
	{
192
		io.run(app_path, param_pos); //0 or offset
192
		io.run(app_path, param_pos); //0 or offset
193
		if (param_pos) ESBYTE[param_pos - 1] = '|';
193
		if (param_pos) ESBYTE[param_pos - 1] = '|';
194
	}
194
	}
195
	else
195
	else
196
	{
196
	{
197
		notify("'Application not found' -E");
197
		notify("'Application not found' -E");
198
	}
198
	}
199
 
199
 
200
}
200
}
201
 
201
 
202
 
202
 
203
 
203
 
204
stop:
204
stop: