Subversion Repositories Kolibri OS

Rev

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

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