2015-02-14 13:47:18 +01:00
|
|
|
/*
|
2019-04-18 11:38:01 +02:00
|
|
|
SOFTWARE CENTER v2.86
|
2015-02-14 13:47:18 +01:00
|
|
|
*/
|
|
|
|
|
2016-12-05 20:20:57 +01:00
|
|
|
#define MEMSIZE 4096 * 15
|
2015-02-14 13:47:18 +01:00
|
|
|
#include "..\lib\strings.h"
|
|
|
|
#include "..\lib\mem.h"
|
2016-02-19 14:34:31 +01:00
|
|
|
#include "..\lib\io.h"
|
2015-03-05 21:55:28 +01:00
|
|
|
#include "..\lib\gui.h"
|
2015-02-15 11:54:50 +01:00
|
|
|
|
2017-10-05 00:59:57 +02:00
|
|
|
#include "..\lib\obj\libio.h"
|
|
|
|
#include "..\lib\obj\libimg.h"
|
2015-03-05 21:55:28 +01:00
|
|
|
#include "..\lib\obj\libini.h"
|
2016-12-21 16:40:39 +01:00
|
|
|
#include "..\lib\kfont.h"
|
2016-01-24 22:16:08 +01:00
|
|
|
#include "..\lib\list_box.h"
|
|
|
|
#include "..\lib\collection.h"
|
2015-02-14 14:38:05 +01:00
|
|
|
|
2015-02-14 13:47:18 +01:00
|
|
|
proc_info Form;
|
2016-01-24 22:16:08 +01:00
|
|
|
llist list;
|
|
|
|
collection app_path_collection;
|
2020-04-06 17:22:12 +02:00
|
|
|
bool kolibrios_mounted;
|
2015-02-18 22:09:29 +01:00
|
|
|
|
2015-02-14 14:38:05 +01:00
|
|
|
int window_width,
|
2016-01-24 22:16:08 +01:00
|
|
|
window_height;
|
|
|
|
|
|
|
|
int list_pos,
|
|
|
|
row,
|
|
|
|
col,
|
|
|
|
default_icon;
|
2015-02-14 13:47:18 +01:00
|
|
|
|
2015-02-14 14:38:05 +01:00
|
|
|
char window_title[128],
|
2020-04-06 17:22:12 +02:00
|
|
|
settings_ini_path[256];
|
2015-02-14 13:47:18 +01:00
|
|
|
|
2019-03-13 01:02:58 +01:00
|
|
|
bool small_screen = false;
|
|
|
|
|
2019-04-18 11:38:01 +02:00
|
|
|
struct SW_COLORS
|
|
|
|
{
|
|
|
|
dword list_bg;
|
|
|
|
dword text;
|
|
|
|
dword graph;
|
|
|
|
dword dark;
|
|
|
|
dword light;
|
|
|
|
} swc;
|
2015-02-14 13:47:18 +01:00
|
|
|
|
2020-04-06 17:22:12 +02:00
|
|
|
block selection[128];
|
2018-10-21 00:56:14 +02:00
|
|
|
|
2020-04-06 17:22:12 +02:00
|
|
|
void load_ini_config(dword _ini_path)
|
2015-02-14 13:47:18 +01:00
|
|
|
{
|
2020-04-06 17:22:12 +02:00
|
|
|
_ini ini;
|
|
|
|
ini.path = _ini_path;
|
|
|
|
ini.section = "Config";
|
|
|
|
ini.GetString("title", #window_title, sizeof(window_title), "Software widget");
|
|
|
|
window_width = ini.GetInt("win_width", 690);
|
|
|
|
list.item_w = ini.GetInt("cell_w", 73);
|
|
|
|
list.item_h = ini.GetInt("cell_h", 71);
|
|
|
|
default_icon = ini.GetInt("default_icon", 2);
|
2015-02-14 13:47:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2016-01-24 22:16:08 +01:00
|
|
|
dword id;
|
2016-12-21 20:50:13 +01:00
|
|
|
kfont.init(DEFAULT_FONT);
|
2015-07-29 22:43:05 +02:00
|
|
|
load_dll(libio, #libio_init,1);
|
|
|
|
load_dll(libimg, #libimg_init,1);
|
|
|
|
load_dll(libini, #lib_init,1);
|
2015-02-15 11:54:50 +01:00
|
|
|
|
2016-02-19 01:33:21 +01:00
|
|
|
kolibrios_mounted = dir_exists("/kolibrios");
|
2015-02-14 13:47:18 +01:00
|
|
|
|
2020-04-06 17:22:12 +02:00
|
|
|
if (param) {
|
2015-02-15 03:39:54 +01:00
|
|
|
strcpy(#settings_ini_path, #param);
|
2020-04-06 17:22:12 +02:00
|
|
|
} else {
|
|
|
|
strcpy(#settings_ini_path, "/sys/settings/");
|
2016-11-21 21:25:00 +01:00
|
|
|
strcat(#settings_ini_path, I_Path + strrchr(I_Path, '/'));
|
2015-02-15 03:39:54 +01:00
|
|
|
strcat(#settings_ini_path, ".ini");
|
|
|
|
}
|
2016-01-24 22:16:08 +01:00
|
|
|
|
2020-04-06 17:22:12 +02:00
|
|
|
load_ini_config(#settings_ini_path);
|
2016-01-24 22:16:08 +01:00
|
|
|
list.cur_y = -1;
|
|
|
|
list.y = 32;
|
2015-02-14 13:47:18 +01:00
|
|
|
|
2016-01-24 22:16:08 +01:00
|
|
|
DrawList();
|
|
|
|
window_height = row+1*list.item_h + list_pos + skin_height + 15;
|
2019-03-13 01:02:58 +01:00
|
|
|
if (window_height>screen.height) {
|
|
|
|
window_width = screen.width;
|
|
|
|
list.item_h -= 5;
|
|
|
|
window_height = row+1*list.item_h + list_pos + skin_height + 15;
|
|
|
|
small_screen = true;
|
|
|
|
}
|
2016-01-24 22:16:08 +01:00
|
|
|
|
|
|
|
loop() switch(WaitEvent())
|
2015-02-14 13:47:18 +01:00
|
|
|
{
|
2018-10-21 00:56:14 +02:00
|
|
|
case evKey:
|
|
|
|
GetKeys();
|
|
|
|
if (SCAN_CODE_LEFT == key_scancode) key_scancode = SCAN_CODE_UP;
|
|
|
|
if (SCAN_CODE_RIGHT == key_scancode) key_scancode = SCAN_CODE_DOWN;
|
|
|
|
if (list.ProcessKey(key_scancode)) DrawSelection();
|
2020-04-06 17:22:12 +02:00
|
|
|
if (SCAN_CODE_ENTER == key_scancode) EventIconClick(list.cur_y);
|
2018-10-21 00:56:14 +02:00
|
|
|
break;
|
2016-01-24 22:16:08 +01:00
|
|
|
|
|
|
|
case evButton:
|
|
|
|
id=GetButtonID();
|
|
|
|
if (id==1) ExitProcess();
|
2020-04-06 17:22:12 +02:00
|
|
|
if (id>=100) EventIconClick(id-100);
|
2015-02-14 13:47:18 +01:00
|
|
|
break;
|
|
|
|
|
2016-01-24 22:16:08 +01:00
|
|
|
case evReDraw:
|
2019-04-18 11:38:01 +02:00
|
|
|
SetAppColors();
|
2016-11-23 12:37:13 +01:00
|
|
|
DefineAndDrawWindow(screen.width-window_width/2,screen.height-window_height/2,window_width,window_height,0x74,system.color.work,"",0);
|
2015-02-14 13:47:18 +01:00
|
|
|
GetProcessInfo(#Form, SelfInfo);
|
2019-03-13 01:02:58 +01:00
|
|
|
if (Form.status_window>2) {
|
|
|
|
DrawTitle(#window_title);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (small_screen) {
|
|
|
|
DrawTitle(#window_title);
|
|
|
|
list.y = 0;
|
|
|
|
} else {
|
|
|
|
DrawTitle(NULL);
|
2020-04-06 17:22:12 +02:00
|
|
|
DrawTopBar();
|
2019-03-13 01:02:58 +01:00
|
|
|
}
|
2016-01-24 22:16:08 +01:00
|
|
|
DrawList();
|
2019-04-18 11:38:01 +02:00
|
|
|
DrawBar(0, row +1 * list.item_h + list_pos, Form.cwidth, -row - 1 * list.item_h - list_pos + Form.cheight, swc.list_bg);
|
2019-03-13 01:02:58 +01:00
|
|
|
DrawSelection();
|
2015-02-14 13:47:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-18 11:38:01 +02:00
|
|
|
void SetAppColors()
|
|
|
|
{
|
|
|
|
dword bg_col, old_list_bg_color;
|
|
|
|
system.color.get();
|
|
|
|
old_list_bg_color = swc.list_bg;
|
|
|
|
bg_col = system.color.work;
|
2020-04-13 13:51:56 +02:00
|
|
|
if (skin_is_dark())
|
2019-04-18 11:38:01 +02:00
|
|
|
{
|
|
|
|
//dark colors
|
|
|
|
swc.list_bg = system.color.work;
|
|
|
|
swc.text = system.color.work_text;
|
|
|
|
swc.dark = system.color.work_dark;
|
|
|
|
swc.light = system.color.work_light;
|
2020-04-13 13:51:56 +02:00
|
|
|
} else {
|
|
|
|
//light colors
|
|
|
|
swc.list_bg = 0xF3F3F3;
|
|
|
|
swc.text = 0x000000;
|
|
|
|
swc.dark = 0xDCDCDC;
|
|
|
|
swc.light = 0xFCFCFC;
|
2019-04-18 11:38:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (swc.list_bg != old_list_bg_color)
|
|
|
|
{
|
|
|
|
Libimg_LoadImage(#skin, "/sys/icons32.png");
|
|
|
|
Libimg_FillTransparent(skin.image, skin.w, skin.h, swc.list_bg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-24 22:16:08 +01:00
|
|
|
void DrawList() {
|
|
|
|
list.count = 0;
|
|
|
|
row = -1;
|
|
|
|
app_path_collection.drop();
|
|
|
|
list_pos = list.y;
|
|
|
|
list.column_max = window_width - 10 / list.item_w;
|
|
|
|
ini_enum_sections stdcall (#settings_ini_path, #process_sections);
|
|
|
|
list.visible = list.count;
|
2015-02-14 13:47:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name)
|
|
|
|
{
|
2020-04-06 17:22:12 +02:00
|
|
|
int icon_id = default_icon,
|
2016-01-24 22:16:08 +01:00
|
|
|
icon_char_pos;
|
2020-04-06 17:22:12 +02:00
|
|
|
int space_pos;
|
|
|
|
|
|
|
|
dword icon_x, icon_y, text_x, text_y;
|
2015-02-14 13:47:18 +01:00
|
|
|
|
2016-02-11 02:18:47 +01:00
|
|
|
//do not show items located in /kolibrios/ if this directory not mounted
|
2018-10-01 21:41:32 +02:00
|
|
|
if (!strncmp(key_value, "/kolibrios/", 11)) || (!strncmp(key_value, "/k/", 3))
|
|
|
|
if (!kolibrios_mounted) return true;
|
2016-02-11 02:18:47 +01:00
|
|
|
|
2016-01-24 22:16:08 +01:00
|
|
|
if (col==list.column_max) {
|
2015-02-14 13:47:18 +01:00
|
|
|
row++;
|
|
|
|
col=0;
|
|
|
|
}
|
2015-02-18 22:09:29 +01:00
|
|
|
|
2019-04-18 11:38:01 +02:00
|
|
|
if (col==0) DrawBar(0, row * list.item_h + list_pos, Form.cwidth, list.item_h, swc.list_bg);
|
2020-04-06 17:22:12 +02:00
|
|
|
DefineButton(col*list.item_w+6, row*list.item_h + list_pos,list.item_w,list.item_h-3,list.count + 100 + BT_HIDE,0);
|
2015-02-14 14:38:05 +01:00
|
|
|
|
|
|
|
icon_char_pos = strchr(key_value, ',');
|
2020-04-06 17:22:12 +02:00
|
|
|
icon_x = col*list.item_w+calc(list.item_w/2)-10;
|
|
|
|
icon_y = row*list.item_h+5 + list_pos;
|
|
|
|
selection[list.count].x = icon_x-2;
|
|
|
|
selection[list.count].y = icon_y-2;
|
2016-01-24 22:16:08 +01:00
|
|
|
if (icon_char_pos) ESBYTE[icon_char_pos] = '\0'; //delete icon from string
|
|
|
|
app_path_collection.add(key_value);
|
2020-04-06 17:22:12 +02:00
|
|
|
|
|
|
|
text_x = col*list.item_w+5;
|
|
|
|
text_y = list.item_h - 40 / 2;
|
2020-04-15 15:44:21 +02:00
|
|
|
if (!strchr(key_name, ' ')) {//|| (kfont.getsize(key_name)+30<list.item_w) <== too slow
|
2020-04-06 17:22:12 +02:00
|
|
|
kfont.WriteIntoWindowCenter(text_x, row*list.item_h+46 + list_pos, list.item_w,0, swc.list_bg, swc.text, 12, key_name);
|
2020-04-15 15:44:21 +02:00
|
|
|
//WriteTextCenter(text_x, row*list.item_h+46 + list_pos+3, list.item_w, swc.text, key_name);
|
2020-04-06 17:22:12 +02:00
|
|
|
} else {
|
|
|
|
space_pos = strrchr(key_name, ' ');
|
|
|
|
ESBYTE[key_name+space_pos-1] = '\0';
|
|
|
|
kfont.WriteIntoWindowCenter(text_x, row*list.item_h+46 + list_pos - 2, list.item_w,0, swc.list_bg, swc.text, 12, key_name);
|
2020-04-15 15:44:21 +02:00
|
|
|
kfont.WriteIntoWindowCenter(text_x, row*list.item_h+46 + list_pos + 13, list.item_w,0, swc.list_bg, swc.text, 12, key_name+space_pos);
|
|
|
|
//WriteTextCenter(text_x, row*list.item_h+46 + list_pos, list.item_w, swc.text, key_name);
|
|
|
|
//WriteTextCenter(text_x, row*list.item_h+46 + list_pos + 10, list.item_w, swc.text, key_name+space_pos);
|
2020-04-06 17:22:12 +02:00
|
|
|
}
|
|
|
|
if (icon_char_pos) icon_id = atoi(icon_char_pos+1);
|
|
|
|
img_draw stdcall(skin.image, icon_x, icon_y, 32, 32, 0, icon_id*32);
|
2016-01-24 22:16:08 +01:00
|
|
|
list.count++;
|
2015-02-14 13:47:18 +01:00
|
|
|
col++;
|
2015-08-03 00:22:52 +02:00
|
|
|
return true;
|
2015-02-14 13:47:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-24 22:16:08 +01:00
|
|
|
int old_row; //to detect empty sections
|
2015-02-18 22:09:29 +01:00
|
|
|
byte process_sections(dword sec_name, f_name)
|
2015-02-14 13:47:18 +01:00
|
|
|
{
|
2015-09-07 16:50:42 +02:00
|
|
|
int text_len;
|
2015-08-03 00:22:52 +02:00
|
|
|
if (!strcmp(sec_name, "Config")) return true;
|
2015-02-14 13:47:18 +01:00
|
|
|
|
2016-01-24 22:16:08 +01:00
|
|
|
if ((col==0) && (row==old_row))
|
2015-02-14 13:47:18 +01:00
|
|
|
{
|
2016-01-24 22:16:08 +01:00
|
|
|
list_pos -= 28;
|
2015-02-14 13:47:18 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-01-24 22:16:08 +01:00
|
|
|
row++;
|
2015-02-14 13:47:18 +01:00
|
|
|
}
|
2016-01-24 22:16:08 +01:00
|
|
|
col = 0;
|
|
|
|
old_row = row;
|
2019-03-13 01:02:58 +01:00
|
|
|
|
|
|
|
if (!small_screen) {
|
2019-04-18 11:38:01 +02:00
|
|
|
DrawBar(0, row * list.item_h + list_pos, Form.cwidth , 29, swc.list_bg);
|
|
|
|
text_len = kfont.WriteIntoWindow(10, row * list.item_h + 10 + list_pos, swc.list_bg, swc.text, 15, sec_name);
|
|
|
|
DrawBar(text_len+20, row * list.item_h + list_pos + 20, Form.cwidth-text_len-20, 1, swc.dark);
|
|
|
|
DrawBar(text_len+20, row * list.item_h + list_pos + 21, Form.cwidth-text_len-20, 1, swc.light);
|
2019-03-13 01:02:58 +01:00
|
|
|
list_pos += 29;
|
|
|
|
}
|
2016-01-24 22:16:08 +01:00
|
|
|
ini_enum_keys stdcall (f_name, sec_name, #draw_icons_from_section);
|
2015-08-03 00:22:52 +02:00
|
|
|
return true;
|
2015-02-14 13:47:18 +01:00
|
|
|
}
|
|
|
|
|
2020-04-06 17:22:12 +02:00
|
|
|
void DrawTopBar()
|
2015-02-14 13:47:18 +01:00
|
|
|
{
|
2016-01-24 22:16:08 +01:00
|
|
|
DrawBar(0,0,Form.cwidth, list.y-2, system.color.work);
|
2016-02-09 02:48:21 +01:00
|
|
|
DrawBar(0,list.y-2, Form.cwidth, 1, MixColors(system.color.work, system.color.work_graph, 180));
|
2016-01-24 22:16:08 +01:00
|
|
|
DrawBar(0,list.y-1, Form.cwidth, 1, system.color.work_graph);
|
2016-12-21 20:50:13 +01:00
|
|
|
kfont.WriteIntoWindowCenter(0,5, Form.cwidth, list.y, system.color.work, system.color.work_text, 16, #window_title);
|
2015-02-14 13:47:18 +01:00
|
|
|
}
|
|
|
|
|
2020-04-06 17:22:12 +02:00
|
|
|
void EventIconClick(dword appid)
|
2016-02-19 14:34:31 +01:00
|
|
|
{
|
2018-10-01 21:41:32 +02:00
|
|
|
char run_app_path[4096]=0;
|
2017-09-06 18:55:37 +02:00
|
|
|
dword app_path = app_path_collection.get(appid);
|
|
|
|
dword param_pos = strchr(app_path, '|');
|
|
|
|
if (param_pos) {
|
|
|
|
ESBYTE[param_pos] = NULL;
|
|
|
|
param_pos++;
|
|
|
|
}
|
|
|
|
|
2018-10-01 21:41:32 +02:00
|
|
|
// the next block is created to save some space in ramdisk{
|
|
|
|
//
|
|
|
|
// convert relative path to absolute "calc" => "/sys/calc"
|
|
|
|
// convert short kolibrios path to full "/k/calc" => "/kolibrios/calc"
|
|
|
|
// other copy => as is
|
|
|
|
if (ESBYTE[app_path]!='/') {
|
|
|
|
strcpy(#run_app_path, "/sys/");
|
|
|
|
}
|
|
|
|
else if (!strncmp(app_path, "/k/",3)) {
|
|
|
|
strcpy(#run_app_path, "/kolibrios/");
|
|
|
|
app_path+=3;
|
|
|
|
}
|
|
|
|
strcat(#run_app_path, app_path);
|
|
|
|
// }end
|
|
|
|
|
2020-04-06 17:22:12 +02:00
|
|
|
if (file_exists(#run_app_path)) {
|
2018-10-01 21:41:32 +02:00
|
|
|
io.run(#run_app_path, param_pos); //0 or offset
|
2017-09-06 18:55:37 +02:00
|
|
|
if (param_pos) ESBYTE[param_pos - 1] = '|';
|
2020-04-06 17:22:12 +02:00
|
|
|
} else {
|
2016-02-19 14:34:31 +01:00
|
|
|
notify("'Application not found' -E");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-21 00:56:14 +02:00
|
|
|
void DrawSelection()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
dword col;
|
|
|
|
for (i=0; i<list.count; i++) {
|
2019-04-18 11:38:01 +02:00
|
|
|
if (i==list.cur_y) col=0x0080FF; else col=swc.list_bg;
|
2020-04-06 17:22:12 +02:00
|
|
|
DrawWideRectangle(selection[i].x, selection[i].y, 36, 36, 2, col);
|
2018-10-21 00:56:14 +02:00
|
|
|
}
|
|
|
|
}
|
2015-02-14 13:47:18 +01:00
|
|
|
|
|
|
|
|
|
|
|
stop:
|