Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
4870 leency 1
/*
5424 leency 2
SOFTWARE CENTER v2.3
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
 
5409 leency 72
	Libimg_LoadImage(#skin, "/sys/iconstrp.png");
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++;
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, ',');
151
	if (icon_char_pos) icon_id = atoi(key_value + icon_char_pos); 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: