Subversion Repositories Kolibri OS

Rev

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

Rev 5674 Rev 5775
1
/*
1
/*
2
SOFTWARE CENTER v2.32
2
SOFTWARE CENTER v2.32
3
*/
3
*/
4
 
4
 
5
#define MEMSIZE 0x5000
5
#define MEMSIZE 0x5000
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
 
14
 
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
 
-
 
42
libimg_image skin;
-
 
43
 
41
 
44
void load_config()
42
void load_config()
45
{
43
{
46
	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");
47
	ini_get_int stdcall (#settings_ini_path, "Config", "window_width", 690);
45
	ini_get_int stdcall (#settings_ini_path, "Config", "window_width", 690);
48
	window_width = EAX;
46
	window_width = EAX;
49
	ini_get_int stdcall (#settings_ini_path, "Config", "window_height", 540);
47
	ini_get_int stdcall (#settings_ini_path, "Config", "window_height", 540);
50
	window_height = EAX;
48
	window_height = EAX;
51
	ini_get_int stdcall (#settings_ini_path, "Config", "cell_w", 66);
49
	ini_get_int stdcall (#settings_ini_path, "Config", "cell_w", 66);
52
	cell_w = EAX;
50
	cell_w = EAX;
53
	ini_get_int stdcall (#settings_ini_path, "Config", "cell_h", 64);
51
	ini_get_int stdcall (#settings_ini_path, "Config", "cell_h", 64);
54
	cell_h = EAX;
52
	cell_h = EAX;
55
	ini_get_int stdcall (#settings_ini_path, "Config", "default_icon", 0);
53
	ini_get_int stdcall (#settings_ini_path, "Config", "default_icon", 0);
56
	default_icon = EAX;
54
	default_icon = EAX;
57
}
55
}
58
 
56
 
59
 
57
 
60
void main()
58
void main()
61
{   
59
{   
62
	dword id, key;
60
	dword id, key;
63
 
61
 
64
	load_dll(libio,  #libio_init,1);
62
	load_dll(libio,  #libio_init,1);
65
	load_dll(libimg, #libimg_init,1);
63
	load_dll(libimg, #libimg_init,1);
66
	load_dll(libini, #lib_init,1);
64
	load_dll(libini, #lib_init,1);
67
 
65
 
68
	Libimg_LoadImage(#skin, "/sys/icons32.png");
66
	Libimg_LoadImage(#skin, "/sys/icons32.png");
69
	Libimg_FillTransparent(skin.image, skin.w, skin.h, LIST_BACKGROUND_COLOR);
67
	Libimg_FillTransparent(skin.image, skin.w, skin.h, LIST_BACKGROUND_COLOR);
70
 
68
 
71
	if (param)
69
	if (param)
72
	{
70
	{
73
		strcpy(#settings_ini_path, #param);
71
		strcpy(#settings_ini_path, #param);
74
	}
72
	}
75
	else
73
	else
76
	{
74
	{
77
		strcat(#settings_ini_path, #program_path + strrchr(#program_path, '/'));
75
		strcat(#settings_ini_path, #program_path + strrchr(#program_path, '/'));
78
		strcat(#settings_ini_path, ".ini");		
76
		strcat(#settings_ini_path, ".ini");		
79
	}
77
	}
80
	load_config();
78
	load_config();
81
 
79
 
82
	loop()
80
	loop()
83
	{
81
	{
84
      switch(WaitEvent())
82
      switch(WaitEvent())
85
      {
83
      {
86
         case evButton:
84
         case evButton:
87
            id=GetButtonID();               
85
            id=GetButtonID();               
88
            if (id==1) ExitProcess();
86
            if (id==1) ExitProcess();
89
            if (id>=100)
87
            if (id>=100)
90
            {
88
            {
91
            	item_id_need_to_run = id - 100;
89
            	item_id_need_to_run = id - 100;
92
            	current_item_id = 0;
90
            	current_item_id = 0;
93
            	ini_enum_sections stdcall (#settings_ini_path, #process_sections);
91
            	ini_enum_sections stdcall (#settings_ini_path, #process_sections);
94
            	item_id_need_to_run = -1;
92
            	item_id_need_to_run = -1;
95
            }
93
            }
96
			break;
94
			break;
97
 
95
 
98
         case evReDraw:
96
         case evReDraw:
99
			system.color.get();
97
			system.color.get();
100
			DefineAndDrawWindow(GetScreenWidth()-window_width/2,GetScreenHeight()-window_height/2,window_width,window_height,0x74,system.color.work,"");
98
			DefineAndDrawWindow(GetScreenWidth()-window_width/2,GetScreenHeight()-window_height/2,window_width,window_height,0x74,system.color.work,"");
101
			GetProcessInfo(#Form, SelfInfo);
99
			GetProcessInfo(#Form, SelfInfo);
102
			if (Form.status_window>2) { DrawTitle(#window_title); break; } else DrawTitle("");
100
			if (Form.status_window>2) { DrawTitle(#window_title); break; } else DrawTitle("");
103
			kolibrios_mounted = isdir("/kolibrios");
101
			kolibrios_mounted = isdir("/kolibrios");
104
			col_max = Form.cwidth - 10 / cell_w;
102
			col_max = Form.cwidth - 10 / cell_w;
105
			current_item_id = 0;
103
			current_item_id = 0;
106
			draw_top_bar();
104
			draw_top_bar();
107
			ini_enum_sections stdcall (#settings_ini_path, #process_sections);
105
			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);
106
			DrawBar(0, row + 1 * cell_h + list_pos, Form.cwidth, -row - 1 * cell_h - list_pos + Form.cheight, LIST_BACKGROUND_COLOR);
109
			break;
107
			break;
110
      }
108
      }
111
	}
109
	}
112
}
110
}
113
 
111
 
114
byte search_for_id_need_to_run(dword key_value, key_name, sec_name, f_name)
112
byte search_for_id_need_to_run(dword key_value, key_name, sec_name, f_name)
115
{
113
{
116
	int icon_char_pos;
114
	int icon_char_pos;
117
	if (item_id_need_to_run == current_item_id)
115
	if (item_id_need_to_run == current_item_id)
118
	{
116
	{
119
		icon_char_pos = strchr(key_value, ',');
117
		icon_char_pos = strchr(key_value, ',');
120
		if (icon_char_pos) ESBYTE[icon_char_pos] = 0; //delete icon from string
118
		if (icon_char_pos) ESBYTE[icon_char_pos] = 0; //delete icon from string
121
		RunProgram(key_value, "");
119
		RunProgram(key_value, "");
122
	}
120
	}
123
	current_item_id++;
121
	current_item_id++;
124
	if (!strncmp(key_value, "/kolibrios/", 11)) && (!kolibrios_mounted) current_item_id--;
122
	if (!strncmp(key_value, "/kolibrios/", 11)) && (!kolibrios_mounted) current_item_id--;
125
	return true;
123
	return true;
126
}
124
}
127
 
125
 
128
 
126
 
129
byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name)
127
byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name)
130
{
128
{
131
	int tmp,
129
	int tmp,
132
	    icon_id,
130
	    icon_id,
133
	    icon_char_pos;
131
	    icon_char_pos;
134
 
132
 
135
	if (col==col_max) {
133
	if (col==col_max) {
136
		row++;
134
		row++;
137
		col=0;
135
		col=0;
138
	}
136
	}
139
 
137
 
140
	//do not show items located in /kolibrios/ if this directory not mounted
138
	//do not show items located in /kolibrios/ if this directory not mounted
141
	if (!strncmp(key_value, "/kolibrios/", 11)) && (!kolibrios_mounted) return true;
139
	if (!strncmp(key_value, "/kolibrios/", 11)) && (!kolibrios_mounted) return true;
142
 
140
 
143
	if (col==0) DrawBar(0, row * cell_h + list_pos, Form.cwidth, cell_h, LIST_BACKGROUND_COLOR);
141
	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);
142
	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;
143
	tmp = cell_w/2;
146
 
144
 
147
	icon_char_pos = strchr(key_value, ',');
145
	icon_char_pos = strchr(key_value, ',');
148
	if (icon_char_pos) icon_id = atoi(icon_char_pos+1); else icon_id = default_icon;
146
	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);
147
	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);
148
	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);
149
	WriteTextCenter(col*cell_w+6,row*cell_h+46 + list_pos,cell_w,0x000000,key_name);
152
	current_item_id++;
150
	current_item_id++;
153
	col++;
151
	col++;
154
	return true;
152
	return true;
155
}
153
}
156
 
154
 
157
 
155
 
158
byte process_sections(dword sec_name, f_name)
156
byte process_sections(dword sec_name, f_name)
159
{
157
{
160
	if (!strcmp(sec_name, "Config")) return true;
158
	if (!strcmp(sec_name, "Config")) return true;
161
 
159
 
162
	if (item_id_need_to_run!=-1)
160
	if (item_id_need_to_run!=-1)
163
	{
161
	{
164
		ini_enum_keys stdcall (f_name, sec_name, #search_for_id_need_to_run);
162
		ini_enum_keys stdcall (f_name, sec_name, #search_for_id_need_to_run);
165
	}
163
	}
166
	else
164
	else
167
	{
165
	{
168
		if ((col==0) && (row==old_row)) 
166
		if ((col==0) && (row==old_row)) 
169
		{
167
		{
170
			list_pos -= 20;
168
			list_pos -= 20;
171
		}
169
		}
172
		else
170
		else
173
		{
171
		{
174
			row++;
172
			row++;
175
		}
173
		}
176
		col = 0;
174
		col = 0;
177
		old_row = row;
175
		old_row = row;
178
		DrawBar(0, row * cell_h + list_pos, Form.cwidth , 20, LIST_BACKGROUND_COLOR);
176
		DrawBar(0, row * cell_h + list_pos, Form.cwidth , 20, LIST_BACKGROUND_COLOR);
179
		WriteTextB(10, row * cell_h + 9 + list_pos, 0x90, 0x000000, sec_name);
177
		WriteTextB(10, row * cell_h + 9 + list_pos, 0x90, 0x000000, sec_name);
180
		list_pos += 20;
178
		list_pos += 20;
181
		ini_enum_keys stdcall (f_name, sec_name, #draw_icons_from_section);
179
		ini_enum_keys stdcall (f_name, sec_name, #draw_icons_from_section);
182
	}
180
	}
183
	return true;
181
	return true;
184
}
182
}
185
 
183
 
186
void draw_top_bar()
184
void draw_top_bar()
187
{
185
{
188
	int top_position = 25;
186
	int top_position = 25;
189
	DrawBar(0,0,Form.cwidth, top_position-1, system.color.work);
187
	DrawBar(0,0,Form.cwidth, top_position-1, system.color.work);
190
	DrawBar(0,top_position-1, Form.cwidth, 1, system.color.work_graph);
188
	DrawBar(0,top_position-1, Form.cwidth, 1, system.color.work_graph);
191
	WriteTextB(Form.cwidth/2-70, 9, 0x90, system.color.work_text, #window_title);
189
	WriteTextB(Form.cwidth/2-70, 9, 0x90, system.color.work_text, #window_title);
192
	list_top = top_position;
190
	list_top = top_position;
193
	list_pos = list_top;
191
	list_pos = list_top;
194
	row = -1;
192
	row = -1;
195
}
193
}
196
 
194
 
197
 
195
 
198
 
196
 
199
stop:
197
stop: