Subversion Repositories Kolibri OS

Rev

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