Subversion Repositories Kolibri OS

Rev

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

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