Subversion Repositories Kolibri OS

Rev

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

Rev 5981 Rev 5985
1
/*
1
/*
2
SOFTWARE CENTER v2.4
2
SOFTWARE CENTER v2.4
3
*/
3
*/
4
 
4
 
5
#define MEMSIZE 0x9000
5
#define MEMSIZE 0x9000
6
#include "..\lib\strings.h" 
6
#include "..\lib\strings.h" 
7
#include "..\lib\mem.h" 
7
#include "..\lib\mem.h" 
8
#include "..\lib\file_system.h"
8
#include "..\lib\file_system.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_lib.h"
12
#include "..\lib\obj\libimg_lib.h"
12
#include "..\lib\obj\libimg_lib.h"
13
#include "..\lib\obj\libini.h"
13
#include "..\lib\obj\libini.h"
14
#include "..\lib\font.h"
14
#include "..\lib\font.h"
15
#include "..\lib\patterns\libimg_load_skin.h"
15
#include "..\lib\patterns\libimg_load_skin.h"
16
 
16
 
17
proc_info Form;
17
proc_info Form;
18
 
18
 
19
byte kolibrios_mounted;
19
byte kolibrios_mounted;
20
 
20
 
21
int item_id_need_to_run=-1,
21
int item_id_need_to_run=-1,
22
    current_item_id;
22
    current_item_id;
23
 
23
 
24
int window_width,
24
int window_width,
25
    window_height;
25
    window_height;
26
 
26
 
27
int col_max,
27
int col_max,
28
    cell_w,
28
    cell_w,
29
    cell_h, 
29
    cell_h, 
30
    list_pos, 
30
    list_pos, 
31
    list_top,
31
    list_top,
32
    row,
32
    row,
33
    old_row, //to detect empty sections
33
    old_row, //to detect empty sections
34
    col,
34
    col,
35
    default_icon;
35
    default_icon;
36
 
36
 
37
char window_title[128],
37
char window_title[128],
38
     settings_ini_path[256] = "/sys/settings/";
38
     settings_ini_path[256] = "/sys/settings/";
39
 
39
 
40
#define LIST_BACKGROUND_COLOR 0xF3F3F3
40
#define LIST_BACKGROUND_COLOR 0xF3F3F3
41
 
41
 
42
void load_config()
42
void load_config()
43
{
43
{
44
	ini_get_str stdcall (#settings_ini_path, "Config", "window_title", #window_title, sizeof(window_title), "Software widget");
44
	ini_get_str stdcall (#settings_ini_path, "Config", "window_title", #window_title, sizeof(window_title), "Software widget");
45
	ini_get_int stdcall (#settings_ini_path, "Config", "window_width", 690);
45
	ini_get_int stdcall (#settings_ini_path, "Config", "window_width", 690);
46
	window_width = EAX;
46
	window_width = EAX;
47
	ini_get_int stdcall (#settings_ini_path, "Config", "window_height", 540);
47
	ini_get_int stdcall (#settings_ini_path, "Config", "window_height", 540);
48
	window_height = EAX;
48
	window_height = EAX;
49
	ini_get_int stdcall (#settings_ini_path, "Config", "cell_w", 66);
49
	ini_get_int stdcall (#settings_ini_path, "Config", "cell_w", 66);
50
	cell_w = EAX;
50
	cell_w = EAX;
51
	ini_get_int stdcall (#settings_ini_path, "Config", "cell_h", 64);
51
	ini_get_int stdcall (#settings_ini_path, "Config", "cell_h", 64);
52
	cell_h = EAX;
52
	cell_h = EAX;
53
	ini_get_int stdcall (#settings_ini_path, "Config", "default_icon", 0);
53
	ini_get_int stdcall (#settings_ini_path, "Config", "default_icon", 0);
54
	default_icon = EAX;
54
	default_icon = EAX;
55
}
55
}
56
 
56
 
57
 
57
 
58
void main()
58
void main()
59
{   
59
{   
60
	dword id, key;
60
	dword id, key;
61
	font.load("/sys/fonts/Tahoma.kf");
61
	font.load("/sys/fonts/Tahoma.kf");
62
	font.no_bg_copy = true;
-
 
63
	font.smooth = true;
62
	font.smooth = true;
64
	load_dll(libio,  #libio_init,1);
63
	load_dll(libio,  #libio_init,1);
65
	load_dll(libimg, #libimg_init,1);
64
	load_dll(libimg, #libimg_init,1);
66
	load_dll(libini, #lib_init,1);
65
	load_dll(libini, #lib_init,1);
67
 
66
 
68
	Libimg_LoadImage(#skin, "/sys/icons32.png");
67
	Libimg_LoadImage(#skin, "/sys/icons32.png");
69
	Libimg_FillTransparent(skin.image, skin.w, skin.h, LIST_BACKGROUND_COLOR);
68
	Libimg_FillTransparent(skin.image, skin.w, skin.h, LIST_BACKGROUND_COLOR);
70
 
69
 
71
	if (param)
70
	if (param)
72
	{
71
	{
73
		strcpy(#settings_ini_path, #param);
72
		strcpy(#settings_ini_path, #param);
74
	}
73
	}
75
	else
74
	else
76
	{
75
	{
77
		strcat(#settings_ini_path, #program_path + strrchr(#program_path, '/'));
76
		strcat(#settings_ini_path, #program_path + strrchr(#program_path, '/'));
78
		strcat(#settings_ini_path, ".ini");		
77
		strcat(#settings_ini_path, ".ini");		
79
	}
78
	}
80
	load_config();
79
	load_config();
81
 
80
 
82
	loop()
81
	loop()
83
	{
82
	{
84
      switch(WaitEvent())
83
      switch(WaitEvent())
85
      {
84
      {
86
         case evButton:
85
         case evButton:
87
            id=GetButtonID();               
86
            id=GetButtonID();               
88
            if (id==1) ExitProcess();
87
            if (id==1) ExitProcess();
89
            if (id>=100)
88
            if (id>=100)
90
            {
89
            {
91
            	item_id_need_to_run = id - 100;
90
            	item_id_need_to_run = id - 100;
92
            	current_item_id = 0;
91
            	current_item_id = 0;
93
            	ini_enum_sections stdcall (#settings_ini_path, #process_sections);
92
            	ini_enum_sections stdcall (#settings_ini_path, #process_sections);
94
            	item_id_need_to_run = -1;
93
            	item_id_need_to_run = -1;
95
            }
94
            }
96
			break;
95
			break;
97
 
96
 
98
         case evReDraw:
97
         case evReDraw:
99
			system.color.get();
98
			system.color.get();
100
			DefineAndDrawWindow(GetScreenWidth()-window_width/2,GetScreenHeight()-window_height/2,window_width,window_height,0x74,system.color.work,"");
99
			DefineAndDrawWindow(GetScreenWidth()-window_width/2,GetScreenHeight()-window_height/2,window_width,window_height,0x74,system.color.work,"");
101
			GetProcessInfo(#Form, SelfInfo);
100
			GetProcessInfo(#Form, SelfInfo);
102
			if (Form.status_window>2) { DrawTitle(#window_title); break; } else DrawTitle("");
101
			if (Form.status_window>2) { DrawTitle(#window_title); break; } else DrawTitle("");
103
			kolibrios_mounted = isdir("/kolibrios");
102
			kolibrios_mounted = isdir("/kolibrios");
104
			col_max = Form.cwidth - 10 / cell_w;
103
			col_max = Form.cwidth - 10 / cell_w;
105
			current_item_id = 0;
104
			current_item_id = 0;
106
			draw_top_bar();
105
			draw_top_bar();
107
			ini_enum_sections stdcall (#settings_ini_path, #process_sections);
106
			ini_enum_sections stdcall (#settings_ini_path, #process_sections);
108
			DrawBar(0, row + 1 * cell_h + list_pos, Form.cwidth, -row - 1 * cell_h - list_pos + Form.cheight, LIST_BACKGROUND_COLOR);
107
			DrawBar(0, row + 1 * cell_h + list_pos, Form.cwidth, -row - 1 * cell_h - list_pos + Form.cheight, LIST_BACKGROUND_COLOR);
109
			break;
108
			break;
110
      }
109
      }
111
	}
110
	}
112
}
111
}
113
 
112
 
114
byte search_for_id_need_to_run(dword key_value, key_name, sec_name, f_name)
113
byte search_for_id_need_to_run(dword key_value, key_name, sec_name, f_name)
115
{
114
{
116
	int icon_char_pos;
115
	int icon_char_pos;
117
	if (item_id_need_to_run == current_item_id)
116
	if (item_id_need_to_run == current_item_id)
118
	{
117
	{
119
		icon_char_pos = strchr(key_value, ',');
118
		icon_char_pos = strchr(key_value, ',');
120
		if (icon_char_pos) ESBYTE[icon_char_pos] = 0; //delete icon from string
119
		if (icon_char_pos) ESBYTE[icon_char_pos] = 0; //delete icon from string
121
		RunProgram(key_value, "");
120
		RunProgram(key_value, "");
122
	}
121
	}
123
	current_item_id++;
122
	current_item_id++;
124
	if (!strncmp(key_value, "/kolibrios/", 11)) && (!kolibrios_mounted) current_item_id--;
123
	if (!strncmp(key_value, "/kolibrios/", 11)) && (!kolibrios_mounted) current_item_id--;
125
	return true;
124
	return true;
126
}
125
}
127
 
126
 
128
 
127
 
129
byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name)
128
byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name)
130
{
129
{
131
	int tmp,
130
	int tmp,
132
	    icon_id,
131
	    icon_id,
133
	    icon_char_pos;
132
	    icon_char_pos;
134
 
133
 
135
	if (col==col_max) {
134
	if (col==col_max) {
136
		row++;
135
		row++;
137
		col=0;
136
		col=0;
138
	}
137
	}
139
 
138
 
140
	//do not show items located in /kolibrios/ if this directory not mounted
139
	//do not show items located in /kolibrios/ if this directory not mounted
141
	if (!strncmp(key_value, "/kolibrios/", 11)) && (!kolibrios_mounted) return true;
140
	if (!strncmp(key_value, "/kolibrios/", 11)) && (!kolibrios_mounted) return true;
142
 
141
 
143
	if (col==0) DrawBar(0, row * cell_h + list_pos, Form.cwidth, cell_h, LIST_BACKGROUND_COLOR);
142
	if (col==0) DrawBar(0, row * cell_h + list_pos, Form.cwidth, cell_h, LIST_BACKGROUND_COLOR);
144
	DefineButton(col*cell_w+6,row*cell_h + list_pos,cell_w,cell_h-5,current_item_id + 100 + BT_HIDE,0);
143
	DefineButton(col*cell_w+6,row*cell_h + list_pos,cell_w,cell_h-5,current_item_id + 100 + BT_HIDE,0);
145
	tmp = cell_w/2;
144
	tmp = cell_w/2;
146
 
145
 
147
	icon_char_pos = strchr(key_value, ',');
146
	icon_char_pos = strchr(key_value, ',');
148
	if (icon_char_pos) icon_id = atoi(icon_char_pos+1); else icon_id = default_icon;
147
	if (icon_char_pos) icon_id = atoi(icon_char_pos+1); else icon_id = default_icon;
149
	img_draw stdcall(skin.image, col*cell_w+tmp-10, row*cell_h+5 + list_pos, 32, 32, 0, icon_id*32);
148
	img_draw stdcall(skin.image, col*cell_w+tmp-10, row*cell_h+5 + list_pos, 32, 32, 0, icon_id*32);
150
	//WriteTextCenter(col*cell_w+7,row*cell_h+47 + list_pos,cell_w,0xDCDCDC,key_name);
149
	//WriteTextCenter(col*cell_w+7,row*cell_h+47 + list_pos,cell_w,0xDCDCDC,key_name);
151
	//WriteTextCenter(col*cell_w+6,row*cell_h+46 + list_pos,cell_w,0x000000,key_name);
150
	//WriteTextCenter(col*cell_w+6,row*cell_h+46 + list_pos,cell_w,0x000000,key_name);
152
	font.size = 12;
151
	font.size = 12;
153
	font.color = 0xDCDCDC;
152
	font.color = 0xDCDCDC;
154
	font.bold = false;
153
	font.bold = false;
155
	font.bg_color = LIST_BACKGROUND_COLOR;
154
	font.bg_color = LIST_BACKGROUND_COLOR;
156
	font.textcenter(col*cell_w+7,row*cell_h+47 + list_pos,cell_w,0,key_name);
155
	font.write_center(col*cell_w+7,row*cell_h+47 + list_pos,cell_w,0,key_name);
157
	font.show();
-
 
158
	font.color = 0;
156
	font.color = 0;
159
	font.textcenter(col*cell_w+6,row*cell_h+46 + list_pos,cell_w,0,key_name);
157
	font.write_center(col*cell_w+6,row*cell_h+46 + list_pos,cell_w,0,key_name);
160
	font.show();
-
 
161
	current_item_id++;
158
	current_item_id++;
162
	col++;
159
	col++;
163
	return true;
160
	return true;
164
}
161
}
165
 
162
 
166
 
163
 
167
byte process_sections(dword sec_name, f_name)
164
byte process_sections(dword sec_name, f_name)
168
{
165
{
169
	int text_len;
166
	int text_len;
170
	if (!strcmp(sec_name, "Config")) return true;
167
	if (!strcmp(sec_name, "Config")) return true;
171
 
168
 
172
	if (item_id_need_to_run!=-1)
169
	if (item_id_need_to_run!=-1)
173
	{
170
	{
174
		ini_enum_keys stdcall (f_name, sec_name, #search_for_id_need_to_run);
171
		ini_enum_keys stdcall (f_name, sec_name, #search_for_id_need_to_run);
175
	}
172
	}
176
	else
173
	else
177
	{
174
	{
178
		if ((col==0) && (row==old_row)) 
175
		if ((col==0) && (row==old_row)) 
179
		{
176
		{
180
			list_pos -= 28;
177
			list_pos -= 28;
181
		}
178
		}
182
		else
179
		else
183
		{
180
		{
184
			row++;
181
			row++;
185
		}
182
		}
186
		col = 0;
183
		col = 0;
187
		old_row = row;
184
		old_row = row;
188
		DrawBar(0, row * cell_h + list_pos, Form.cwidth , 29, LIST_BACKGROUND_COLOR);
185
		DrawBar(0, row * cell_h + list_pos, Form.cwidth , 29, LIST_BACKGROUND_COLOR);
189
		//WriteTextB(10, row * cell_h + 9 + list_pos, 0x90, 0x000000, sec_name);
186
		//WriteTextB(10, row * cell_h + 9 + list_pos, 0x90, 0x000000, sec_name);
190
		font.size=14;
187
		font.size=15;
191
		font.bold=true;
188
		font.bold=false;
192
		font.bg_color = LIST_BACKGROUND_COLOR;
189
		font.bg_color = LIST_BACKGROUND_COLOR;
193
		text_len = font.prepare(10, row * cell_h + 10 + list_pos,sec_name);
190
		text_len = font.write(10, row * cell_h + 10 + list_pos,sec_name);
194
		font.show();
-
 
195
		DrawBar(text_len+20, row * cell_h + list_pos + 20, Form.cwidth-text_len-20, 1, 0xDCDCDC);
191
		DrawBar(text_len+20, row * cell_h + list_pos + 20, Form.cwidth-text_len-20, 1, 0xDCDCDC);
196
		DrawBar(text_len+20, row * cell_h + list_pos + 21, Form.cwidth-text_len-20, 1, 0xFCFCFC);
192
		DrawBar(text_len+20, row * cell_h + list_pos + 21, Form.cwidth-text_len-20, 1, 0xFCFCFC);
197
		list_pos += 29;
193
		list_pos += 29;
198
		ini_enum_keys stdcall (f_name, sec_name, #draw_icons_from_section);
194
		ini_enum_keys stdcall (f_name, sec_name, #draw_icons_from_section);
199
	}
195
	}
200
	return true;
196
	return true;
201
}
197
}
202
 
198
 
203
void draw_top_bar()
199
void draw_top_bar()
204
{
200
{
205
	int top_position = 26;
201
	int top_position = 26;
206
	DrawBar(0,0,Form.cwidth, top_position-1, system.color.work);
202
	DrawBar(0,0,Form.cwidth, top_position-1, system.color.work);
207
	DrawBar(0,top_position-1, Form.cwidth, 1, system.color.work_graph);
203
	DrawBar(0,top_position-1, Form.cwidth, 1, system.color.work_graph);
208
	font.size = 17;
204
	font.size = 17;
209
	font.bold = false;
205
	font.bold = false;
210
	font.bg_color = system.color.work;
206
	font.bg_color = system.color.work;
211
	font.prepare(Form.cwidth-font.getsize(#window_title)/2,0,#window_title);
207
	font.write(Form.cwidth-font.getsize(#window_title)/2,0,#window_title);
212
	font.show();
-
 
213
	list_top = top_position;
208
	list_top = top_position;
214
	list_pos = list_top;
209
	list_pos = list_top;
215
	row = -1;
210
	row = -1;
216
}
211
}
217
 
212
 
218
 
213
 
219
 
214
 
220
stop:
215
stop: