Subversion Repositories Kolibri OS

Rev

Rev 7793 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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