Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 9465 → Rev 9464

/programs/cmm/appearance/appearance.c
1,7 → 1,7
//11.03.12 - start!
//ver 2.31
 
#define MEMSIZE 1024*70
#define MEMSIZE 200*1024
#include "../lib/mem.h"
#include "../lib/strings.h"
#include "../lib/io.h"
34,20 → 34,21
char folder_path[4096];
char cur_file_path[4096];
char cur_skin_path[4096];
char ss_available[200];
int files_mas[400];
 
int screensaver_timeout;
 
_tabs tabs = { -sizeof(t_skins)-sizeof(t_wallpapers)-sizeof(t_screensaver)-3*8+WIN_W
- TAB_PADDING / 2, LP, NULL, BASE_TAB_BUTTON_ID };
 
checkbox update_docky = { T_UPDATE_DOCK, false };
 
checkbox optionbox_stretch = { T_CHECKBOX_STRETCH, false };
checkbox optionbox_stretch = { T_CHECKBOX_STRETCH, true };
checkbox optionbox_tiled = { T_CHECKBOX_TILED, false };
checkbox optionbox_auto = { T_CHECKBOX_AUTO, true };
 
collection list;
struct SCREENSAVER_SETTINGS {
int timeout;
char program[60];
char available[200];
} ss_settings;
 
//===================================================//
// //
69,8 → 70,6
tabs.add(#t_screensaver, #EventTabScreensaverClick);
tabs.draw_active_tab();
 
GetScreensaverIniSettings();
 
SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
loop() switch(WaitEvent())
{
81,21 → 80,13
case evButton:
id=GetButtonID();
if (id==1) EventExit();
if (id==BTN_SELECT_WALLP_FOLDER) EventSelectWallpFolder();
tabs.click(id);
if (tabs.active_tab == TAB_SKINS) {
checkbox1.click(id);
spinbox1.click(id);
if (update_docky.click(id)) EventUpdateDocky();
}
if (tabs.active_tab == TAB_WALLPAPERS) {
if (id==BTN_SELECT_WALLP_FOLDER) EventSelectWallpFolder();
if (optionbox_stretch.click(id)) EventSetWallpMode(1,0,0);
if (optionbox_tiled.click(id)) EventSetWallpMode(0,1,0);
if (optionbox_auto.click(id)) EventSetWallpMode(0,0,1);
}
if (tabs.active_tab == TAB_SCREENSAVERS) {
if (id==BTN_TEST_SCREENSAVER) EventOpenFile();
}
if (!optionbox_stretch.checked) && (optionbox_stretch.click(id)) EventSetWallpMode_Stretch();
if (!optionbox_tiled.checked) && (optionbox_tiled.click(id)) EventSetWallpMode_Tiled();
break;
case evKey:
107,6 → 98,7
id = tabs.active_tab+1;
if(id==3)id=0;
tabs.click(id + tabs.base_id);
DrawWindowContent();
break;
}
 
113,7 → 105,7
if (! edit_cmm.flags & ed_focus) && (! edit_st.flags & ed_focus)
for (i=select_list.cur_y+1; i<select_list.count; i++)
{
id = ESBYTE[list.get(i)];
id = ESBYTE[io.dir.position(files_mas[i])];
if (id==ESBYTE[EAX]) || (id==key_ascii-32)
{
select_list.cur_y = i - 1;
173,15 → 165,14
}
if (tabs.active_tab == TAB_WALLPAPERS)
{
DrawFrame(RIGHTx, PANEL_H+5, 180, 105, T_PICTURE_MODE);
DrawFrame(RIGHTx, PANEL_H+5, 180, 80, T_PICTURE_MODE);
optionbox_stretch.draw(RIGHTx+14, PANEL_H+25);
optionbox_tiled.draw(RIGHTx+14, PANEL_H+52);
optionbox_auto.draw(RIGHTx+14, PANEL_H+79);
DrawStandartCaptButton(RIGHTx, PANEL_H+130, BTN_SELECT_WALLP_FOLDER, T_SELECT_FOLDER);
DrawStandartCaptButton(RIGHTx, PANEL_H+100, BTN_SELECT_WALLP_FOLDER, T_SELECT_FOLDER);
}
if (tabs.active_tab == TAB_SCREENSAVERS)
{
DrawStandartCaptButton(RIGHTx, PANEL_H, BTN_TEST_SCREENSAVER, T_SCREENSAVER_PREVIEW);
DrawStandartCaptButton(RIGHTx, PANEL_H, BTN_TEST_SCREENSAVER, "Test");
}
}
 
190,47 → 181,32
return strcmp(_left+strrchr(_left,'.'), _right);
}
 
dword files_mas[400];
void Open_Dir()
{
int j;
char fname[4096];
select_list.ClearList();
char temp_filename[4096];
select_list.count = 0;
if(io.dir.buffer)free(io.dir.buffer);
io.dir.load(#folder_path,DIR_ONLYREAL);
for (j=0; j<io.dir.count; j++)
{
strcpy(#fname, io.dir.position(j));
strlwr(#fname);
strcpy(#temp_filename, io.dir.position(j));
strlwr(#temp_filename);
if (tabs.active_tab==TAB_SKINS) {
if (strreqi(#fname,"skn")!=0) continue;
if (strreqi(#temp_filename,"skn")!=0) continue;
}
if (tabs.active_tab==TAB_WALLPAPERS) {
if (strreqi(#fname,"png")!=0)
&& (strreqi(#fname,"jpg")!=0)
&& (strreqi(#fname,"jpeg")!=0)
&& (strreqi(#fname,"bmp")!=0)
&& (strreqi(#fname,"gif")!=0) continue;
if (strreqi(#temp_filename,"png")!=0)
&& (strreqi(#temp_filename,"jpg")!=0)
&& (strreqi(#temp_filename,"jpeg")!=0)
&& (strreqi(#temp_filename,"bmp")!=0)
&& (strreqi(#temp_filename,"gif")!=0) continue;
}
ESDWORD[select_list.count*4 + #files_mas] = j;
files_mas[calc(select_list.count)]=j;
select_list.count++;
}
Sort_by_Name(0, select_list.count-1);
list.drop();
for (j=0; j<select_list.count; j++) {
list.add(io.dir.position(files_mas[j]));
}
if (!select_list.count) notify(T_NO_FILES);
//save current item for tab change
switch(tabs.active_tab) {
CASE TAB_SKINS: select_list.cur_y = active_skin; BREAK;
CASE TAB_WALLPAPERS: select_list.cur_y = active_wallpaper; BREAK;
CASE TAB_SCREENSAVERS: select_list.cur_y = active_screensaver;
}
if (select_list.cur_y>select_list.visible) select_list.first=select_list.cur_y;
select_list.CheckDoesValuesOkey();
if (LIST_W) draw_window();
}
 
void Sort_by_Name(int a, b) // for the first call: a = 0, b = sizeof(mas) - 1
{
251,30 → 227,21
{
int draw_y = i*SELECT_LIST_ITEMH+PANEL_H;
int i_abs = select_list.first + i;
char filename_buf[4096];
char* filename = #filename_buf;
char filename[4096];
 
strcpy(filename, list.get(i_abs));
EAX = math.min(strrchr(filename,'.')-1, LIST_W - 24 / 8);
filename_buf[EAX] = '\0';
if (EAX = strrchr(filename,'/')) filename += EAX;
strcpy(#filename, io.dir.position(files_mas[i_abs]));
EAX = math.min(strrchr(#filename,'.')-1, LIST_W - 24 / 8);
filename[EAX] = '\0';
 
//save current item for tab change
switch(tabs.active_tab) {
CASE TAB_SKINS: active_skin = select_list.cur_y; BREAK;
CASE TAB_WALLPAPERS: active_wallpaper = select_list.cur_y; BREAK;
CASE TAB_SCREENSAVERS: active_screensaver = select_list.cur_y;
}
if (select_list.cur_y == i_abs)
{
DrawBar(select_list.x, draw_y, LIST_W, SELECT_LIST_ITEMH, sc.button);
WriteText(select_list.x+12,draw_y+select_list.text_y,select_list.font_type,sc.button_text, filename);
WriteText(select_list.x+12,draw_y+select_list.text_y,select_list.font_type,sc.button_text, #filename);
}
else
{
DrawBar(select_list.x,draw_y,LIST_W, SELECT_LIST_ITEMH, 0xFFFfff);
WriteText(select_list.x+12,draw_y+select_list.text_y,select_list.font_type,0, filename);
WriteText(select_list.x+12,draw_y+select_list.text_y,select_list.font_type,0, #filename);
}
}
 
283,6 → 250,17
EventApply();
}
 
void ActivateTab(int _id)
{
select_list.ClearList();
Open_Dir();
if (!select_list.count) notify(T_NO_FILES);
select_list.cur_y = _id;
if (select_list.cur_y>select_list.visible) select_list.first=select_list.cur_y;
select_list.CheckDoesValuesOkey();
if (LIST_W) DrawWindowContent();
}
 
dword GetRealKolibriosPath()
{
char real_kolibrios_path[4096];
291,13 → 269,6
return #real_kolibrios_path;
}
 
void GetScreensaverIniSettings()
{
ini.section = "screensaver";
screensaver_timeout = ini.GetInt("timeout", 10);
ini.GetString("available", #ss_available, sizeof(ss_available), 0);
}
 
//===================================================//
// //
// EVENTS //
306,46 → 277,44
 
void EventTabSkinsClick()
{
active_wallpaper = select_list.cur_y;
miniprintf(#folder_path, "%s/res/skins", GetRealKolibriosPath());
Open_Dir();
ActivateTab(active_skin);
}
 
void EventTabWallpappersClick()
{
active_skin = select_list.cur_y;
if (opendir_path) {
strcpy(#folder_path, #opendir_path);
} else {
miniprintf(#folder_path, "%s/res/wallpapers", GetRealKolibriosPath());
}
Open_Dir();
ActivateTab(active_wallpaper);
}
 
void EventTabScreensaverClick()
{
dword j;
char ssmas[sizeof(ss_available)];
list.drop();
select_list.ClearList();
 
strcpy(#ssmas, #ss_available);
do {
j = strrchr(#ss_available, '|');
miniprintf(#param, "/sys/%s", #ss_available + j);
list.add(#param);
ESBYTE[#ss_available + j - 1] = '\0';
select_list.count++;
} while (j);
 
if (LIST_W) draw_window();
ini.section = "screensaver";
ss_settings.timeout = ini.GetInt("timeout", 10);
ini.GetString("title", #ss_settings.program, sizeof(ss_settings.program), 0);
ini.GetString("available", #ss_settings.available, sizeof(ss_settings.available), 0);
ActivateTab(active_screensaver);
}
 
void EventDeleteFile()
{
DeleteFile(#cur_file_path);
io.del(#cur_file_path);
Open_Dir();
EventApply();
}
 
void EventSetNewCurrent()
{
miniprintf(#cur_file_path,"%s/",#folder_path);
strcat(#cur_file_path, io.dir.position(files_mas[calc(select_list.cur_y)]));
}
 
void EventSelectWallpFolder()
{
OpenDialog_start stdcall (#o_dialog);
352,23 → 321,24
if (o_dialog.status) EventTabWallpappersClick();
}
 
void EventSetWallpMode(dword _stretch, _titled, _auto)
void EventSetWallpMode_Stretch()
{
optionbox_stretch.checked = _stretch;
optionbox_tiled.checked = _titled;
optionbox_auto.checked = _auto;
optionbox_tiled.checked = false;
optionbox_tiled.redraw();
EventApply();
}
 
void EventSetWallpMode_Tiled()
{
optionbox_stretch.checked = false;
optionbox_stretch.redraw();
optionbox_auto.redraw();
EventApply();
}
 
void EventApply()
{
char kivparam[4096+10];
dword file_name = list.get(select_list.cur_y);
miniprintf(#cur_file_path,"%s/",#folder_path);
strcat(#cur_file_path, list.get(select_list.cur_y));
char kivpath[4096+10];
EventSetNewCurrent();
if (tabs.active_tab==TAB_SKINS)
{
SetSystemSkin(#cur_file_path);
379,20 → 349,11
if (tabs.active_tab==TAB_WALLPAPERS)
{
SelectList_Draw();
miniprintf(#kivparam, "\\S__%s", #cur_file_path);
if (optionbox_tiled.checked) kivparam[1]='T';
if (optionbox_auto.checked) {
if (ESBYTE[file_name+1] == ' ') && (ESBYTE[file_name] == 'T') {
kivparam[1]='T';
if (optionbox_stretch.checked) miniprintf(#kivpath, "\\S__%s", #cur_file_path);
if (optionbox_tiled.checked) miniprintf(#kivpath, "\\T__%s", #cur_file_path);
RunProgram("/sys/media/kiv", #kivpath);
}
}
RunProgram("/sys/media/kiv", #kivparam);
}
if (tabs.active_tab==TAB_SCREENSAVERS)
{
SelectList_Draw();
}
}
 
void EventUpdateDocky()
{
407,7 → 368,6
{
if (tabs.active_tab==TAB_SKINS) RunProgram("/sys/skincfg", #cur_file_path);
if (tabs.active_tab==TAB_WALLPAPERS) RunProgram("/sys/media/kiv", #cur_file_path);
if (tabs.active_tab==TAB_SCREENSAVERS) RunProgram(list.get(select_list.cur_y), "@ss");
}
 
void EventExit()