Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
4078 leency 1
//11.03.12 - start!
8261 leency 2
//ver 2.31
4078 leency 3
 
9465 leency 4
#define MEMSIZE 1024*70
7909 leency 5
#include "../lib/mem.h"
6
#include "../lib/strings.h"
7
#include "../lib/io.h"
8
#include "../lib/list_box.h"
9
#include "../lib/gui.h"
7353 leency 10
 
7909 leency 11
#include "../lib/obj/box_lib.h"
12
#include "../lib/obj/proc_lib.h"
13
#include "../lib/obj/libini.h"
7353 leency 14
 
7909 leency 15
#include "../lib/patterns/select_list.h"
16
#include "../lib/patterns/simple_open_dialog.h"
9453 leency 17
#include "../lib/patterns/restart_process.h"
4078 leency 18
 
7614 leency 19
#include "ui_elements_preview.h"
9455 leency 20
#include "const.h"
7614 leency 21
 
6212 leency 22
//===================================================//
23
//                                                   //
24
//                       DATA                        //
25
//                                                   //
26
//===================================================//
27
 
9469 leency 28
int active_skin, active_wallpaper, active_screensaver;
29
 
7353 leency 30
enum {
9453 leency 31
	BASE_TAB_BUTTON_ID=3,
32
	BTN_SELECT_WALLP_FOLDER=10,
33
	BTN_TEST_SCREENSAVER };
4078 leency 34
 
35
char folder_path[4096];
36
char cur_file_path[4096];
7551 leency 37
char cur_skin_path[4096];
9469 leency 38
char default_skin[4096];
39
char default_wallp[4096];
9465 leency 40
char ss_available[200];
4078 leency 41
 
9465 leency 42
int screensaver_timeout;
43
 
9453 leency 44
_tabs tabs = { -sizeof(t_skins)-sizeof(t_wallpapers)-sizeof(t_screensaver)-3*8+WIN_W
45
	 - TAB_PADDING / 2, LP, NULL, BASE_TAB_BUTTON_ID };
7909 leency 46
 
7612 leency 47
checkbox update_docky = { T_UPDATE_DOCK, false };
9469 leency 48
checkbox ss_in_on = { T_UPDATE_DOCK, false };
7244 leency 49
 
9465 leency 50
checkbox optionbox_stretch = { T_CHECKBOX_STRETCH, false };
7611 leency 51
checkbox optionbox_tiled = { T_CHECKBOX_TILED, false };
9465 leency 52
checkbox optionbox_auto = { T_CHECKBOX_AUTO, true };
7611 leency 53
 
9465 leency 54
collection list;
9461 leency 55
 
6212 leency 56
//===================================================//
57
//                                                   //
58
//                       CODE                        //
59
//                                                   //
60
//===================================================//
5548 leency 61
 
4078 leency 62
void main()
63
{
9461 leency 64
	int id, i;
5626 leency 65
	load_dll(boxlib, #box_lib_init,0);
7533 leency 66
	load_dll(libini, #lib_init,1);
7353 leency 67
	load_dll(Proc_lib, #OpenDialog_init,0);
68
	o_dialog.type = 2; //select folder
69
	OpenDialog_init stdcall (#o_dialog);
70
 
9469 leency 71
	GetIniSettings();
72
 
9453 leency 73
	tabs.add(#t_skins, #EventTabSkinsClick);
74
	tabs.add(#t_wallpapers, #EventTabWallpappersClick);
75
	tabs.add(#t_screensaver, #EventTabScreensaverClick);
7909 leency 76
	tabs.draw_active_tab();
7353 leency 77
 
7551 leency 78
	SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
6096 leency 79
	loop() switch(WaitEvent())
4078 leency 80
	{
81
	  	case evMouse:
6653 leency 82
			SelectList_ProcessMouse();
4078 leency 83
	  		break;
84
 
85
		case evButton:
86
			id=GetButtonID();
7551 leency 87
			if (id==1) EventExit();
7909 leency 88
			tabs.click(id);
9465 leency 89
			if (tabs.active_tab == TAB_SKINS) {
90
				checkbox1.click(id);
91
				spinbox1.click(id);
92
				if (update_docky.click(id)) EventUpdateDocky();
93
			}
94
			if (tabs.active_tab == TAB_WALLPAPERS) {
95
				if (id==BTN_SELECT_WALLP_FOLDER) EventSelectWallpFolder();
96
				if (optionbox_stretch.click(id)) EventSetWallpMode(1,0,0);
97
				if (optionbox_tiled.click(id)) EventSetWallpMode(0,1,0);
98
				if (optionbox_auto.click(id)) EventSetWallpMode(0,0,1);
99
			}
100
			if (tabs.active_tab == TAB_SCREENSAVERS) {
101
				if (id==BTN_TEST_SCREENSAVER) EventOpenFile();
102
			}
4078 leency 103
			break;
104
 
105
		case evKey:
5706 leency 106
			GetKeys();
6651 leency 107
			if (select_list.ProcessKey(key_scancode)) EventApply();
6212 leency 108
			if (key_scancode==SCAN_CODE_ENTER) EventOpenFile();
109
			if (key_scancode==SCAN_CODE_DEL) EventDeleteFile();
9453 leency 110
			if (key_scancode==SCAN_CODE_TAB) {
111
				id = tabs.active_tab+1;
112
				if(id==3)id=0;
113
				tabs.click(id + tabs.base_id);
114
				break;
115
			}
7349 leency 116
 
7506 leency 117
			if (! edit_cmm.flags & ed_focus) && (! edit_st.flags & ed_focus)
9461 leency 118
			for (i=select_list.cur_y+1; i
4078 leency 119
			{
9481 leency 120
				id = list.get(i) + strrchr(list.get(i), '/');
121
				if (ESBYTE[id]==key_ascii) || (ESBYTE[id]==key_ascii-32)
6212 leency 122
				{
9461 leency 123
					select_list.cur_y = i - 1;
6651 leency 124
					select_list.KeyDown();
6212 leency 125
					EventApply();
126
					break;
127
				}
4078 leency 128
			}
7349 leency 129
 
9461 leency 130
			if (tabs.active_tab == TAB_SKINS) {
131
				EAX = key_editbox;
7353 leency 132
				edit_box_key stdcall (#edit_cmm);
133
				edit_box_key stdcall (#edit_st);
134
			}
4078 leency 135
			break;
136
 
7353 leency 137
		 case evReDraw:
138
			draw_window();
4078 leency 139
   }
140
}
141
 
7353 leency 142
void draw_window()
143
{
7909 leency 144
	sc.get();
9461 leency 145
	DefineAndDrawWindow(screen.width-WIN_W-9/2,80,WIN_W+9,WIN_H+4+skin_height,0x34,sc.work,WINDOW_HEADER,0);
7353 leency 146
	DrawWindowContent();
147
}
7244 leency 148
 
6212 leency 149
void DrawWindowContent()
150
{
7806 leency 151
	sc.get();
7612 leency 152
 
7909 leency 153
	tabs.draw();
9455 leency 154
	draw_icon_16w(tabs.x + TAB_PADDING, LP+5, 17);
155
	draw_icon_16w(sizeof(t_skins)-1*8 + TAB_PADDING + TAB_PADDING + tabs.x, LP+5, 6);
156
	draw_icon_16w(sizeof(t_wallpapers)+sizeof(t_skins)-2*8 + TAB_PADDING + TAB_PADDING + TAB_PADDING + tabs.x, LP+5, 61);
7225 leency 157
 
9461 leency 158
	$push select_list.cur_y
6653 leency 159
	SelectList_Init(
9453 leency 160
		LP + TAB_PADDING,
161
		PANEL_H,
162
		LIST_W,
9461 leency 163
		WIN_H - LP - TAB_PADDING - PANEL_H
6653 leency 164
		);
9461 leency 165
	$pop select_list.cur_y
7244 leency 166
 
9461 leency 167
	DrawBar(RIGHTx, PANEL_H, RIGHTw, WIN_H-PANEL_H-LP, sc.work);
7244 leency 168
 
6653 leency 169
	SelectList_Draw();
6662 leency 170
	SelectList_DrawBorder();
7244 leency 171
 
9461 leency 172
	if (tabs.active_tab == TAB_SKINS)
7244 leency 173
	{
9461 leency 174
		DrawFrame(RIGHTx, PANEL_H+5, RIGHTw, RIGHTh, T_UI_PREVIEW);
175
		DrawUiElementsPreview(RIGHTx+20, PANEL_H+5, RIGHTh);
176
		if (CheckProcessExists("@DOCKY")) update_docky.draw(RIGHTx, PANEL_H+250);
7244 leency 177
	}
9461 leency 178
	if (tabs.active_tab == TAB_WALLPAPERS)
7353 leency 179
	{
9465 leency 180
		DrawFrame(RIGHTx, PANEL_H+5, 180, 105, T_PICTURE_MODE);
9461 leency 181
		optionbox_stretch.draw(RIGHTx+14, PANEL_H+25);
182
		optionbox_tiled.draw(RIGHTx+14, PANEL_H+52);
9465 leency 183
		optionbox_auto.draw(RIGHTx+14, PANEL_H+79);
184
		DrawStandartCaptButton(RIGHTx, PANEL_H+130, BTN_SELECT_WALLP_FOLDER, T_SELECT_FOLDER);
7353 leency 185
	}
9461 leency 186
	if (tabs.active_tab == TAB_SCREENSAVERS)
9453 leency 187
	{
9469 leency 188
		DrawStandartCaptButton(RIGHTx, PANEL_H, BTN_TEST_SCREENSAVER, T_SS_PREVIEW);
9453 leency 189
	}
6212 leency 190
}
191
 
9455 leency 192
bool strreqi(dword _left, _right)
193
{
9461 leency 194
	return strcmp(_left+strrchr(_left,'.'), _right);
9455 leency 195
}
4410 leency 196
 
9465 leency 197
dword files_mas[400];
6212 leency 198
void Open_Dir()
4078 leency 199
{
6212 leency 200
	int j;
9465 leency 201
	char fname[4096];
202
	select_list.ClearList();
6212 leency 203
	if(io.dir.buffer)free(io.dir.buffer);
204
	io.dir.load(#folder_path,DIR_ONLYREAL);
9469 leency 205
 
6212 leency 206
	for (j=0; j
4410 leency 207
	{
9465 leency 208
		strcpy(#fname, io.dir.position(j));
209
		strlwr(#fname);
9461 leency 210
		if (tabs.active_tab==TAB_SKINS) {
9465 leency 211
			if (strreqi(#fname,"skn")!=0) continue;
7353 leency 212
		}
9461 leency 213
		if (tabs.active_tab==TAB_WALLPAPERS) {
9465 leency 214
			if (strreqi(#fname,"png")!=0)
215
			&& (strreqi(#fname,"jpg")!=0)
216
			&& (strreqi(#fname,"jpeg")!=0)
217
			&& (strreqi(#fname,"bmp")!=0)
218
			&& (strreqi(#fname,"gif")!=0) continue;
7353 leency 219
		}
9465 leency 220
		ESDWORD[select_list.count*4 + #files_mas] = j;
6651 leency 221
		select_list.count++;
4410 leency 222
	}
8261 leency 223
	Sort_by_Name(0, select_list.count-1);
9469 leency 224
 
9465 leency 225
	list.drop();
9469 leency 226
	//save current item for tab change
227
	//add default item
228
	switch(tabs.active_tab) {
229
		CASE TAB_SKINS:
230
				select_list.cur_y = active_skin;
231
				select_list.count++;
232
				list.add(#default_skin);
233
				BREAK;
234
		CASE TAB_WALLPAPERS:
235
				select_list.cur_y = active_wallpaper;
236
				select_list.count++;
237
				list.add(#default_wallp);
238
				BREAK;
239
		CASE TAB_SCREENSAVERS:
240
				select_list.cur_y = active_screensaver;
241
	}
242
 
9465 leency 243
	for (j=0; j
9469 leency 244
		miniprintf(#param,"%s/",#folder_path);
245
		strcat(#param, io.dir.position(files_mas[j]));
246
		list.add(#param);
9465 leency 247
	}
9469 leency 248
 
9465 leency 249
	if (!select_list.count) notify(T_NO_FILES);
250
	if (select_list.cur_y>select_list.visible) select_list.first=select_list.cur_y;
251
	select_list.CheckDoesValuesOkey();
252
	if (LIST_W) draw_window();
6212 leency 253
}
254
 
8261 leency 255
void Sort_by_Name(int a, b) // for the first call: a = 0, b = sizeof(mas) - 1
256
{
257
	int j;
258
	int isn = a;
259
	if (a >= b) return;
260
	for (j = a; j <= b; j++) {
261
		if (strcmpi(io.dir.position(files_mas[j]), io.dir.position(files_mas[b]))<=0) {
262
			files_mas[isn] >< files_mas[j];
263
			isn++;
264
		}
265
	}
266
	Sort_by_Name(a, isn-2);
267
	Sort_by_Name(isn, b);
268
}
269
 
6653 leency 270
void SelectList_DrawLine(dword i)
6212 leency 271
{
9461 leency 272
	int draw_y = i*SELECT_LIST_ITEMH+PANEL_H;
273
	int i_abs = select_list.first + i;
9465 leency 274
	char filename_buf[4096];
275
	char* filename = #filename_buf;
6212 leency 276
 
9465 leency 277
	strcpy(filename, list.get(i_abs));
9469 leency 278
	if (EAX = strrchr(filename,'/')) filename += EAX;
279
	if (ESBYTE[filename]=='T') && (ESBYTE[filename+1]=='_') filename+=2;
9465 leency 280
	EAX = math.min(strrchr(filename,'.')-1, LIST_W - 24 / 8);
9469 leency 281
	if(EAX) ESBYTE[filename+EAX] = '\0';
9465 leency 282
 
283
	//save current item for tab change
284
	switch(tabs.active_tab) {
9469 leency 285
		CASE TAB_SKINS:
286
				active_skin = select_list.cur_y;
287
				if (!i_abs) filename = T_DEFAULT;
288
				BREAK;
289
		CASE TAB_WALLPAPERS:
290
				active_wallpaper = select_list.cur_y;
291
				if (!i_abs) filename = T_DEFAULT;
292
				BREAK;
293
		CASE TAB_SCREENSAVERS:
294
				active_screensaver = select_list.cur_y;
9465 leency 295
	}
6651 leency 296
 
9461 leency 297
	if (select_list.cur_y == i_abs)
4410 leency 298
	{
9461 leency 299
		DrawBar(select_list.x, draw_y, LIST_W, SELECT_LIST_ITEMH, sc.button);
9465 leency 300
		WriteText(select_list.x+12,draw_y+select_list.text_y,select_list.font_type,sc.button_text, filename);
4410 leency 301
	}
6651 leency 302
	else
303
	{
9461 leency 304
		DrawBar(select_list.x,draw_y,LIST_W, SELECT_LIST_ITEMH, 0xFFFfff);
9465 leency 305
		WriteText(select_list.x+12,draw_y+select_list.text_y,select_list.font_type,0, filename);
6651 leency 306
	}
4078 leency 307
}
308
 
6653 leency 309
void SelectList_LineChanged()
310
{
311
	EventApply();
312
}
313
 
9455 leency 314
dword GetRealKolibriosPath()
315
{
316
	char real_kolibrios_path[4096];
317
	SetCurDir("/kolibrios");
318
	GetCurDir(#real_kolibrios_path, sizeof(real_kolibrios_path));
319
	return #real_kolibrios_path;
320
}
321
 
9469 leency 322
void GetIniSettings()
9465 leency 323
{
324
	ini.section = "screensaver";
325
	screensaver_timeout = ini.GetInt("timeout", 10);
326
	ini.GetString("available", #ss_available, sizeof(ss_available), 0);
9469 leency 327
	ini.section = "style";
328
	ini.GetString("default_skin", #default_skin, sizeof(default_skin), 0);
329
	ini.GetString("default_wallp", #default_wallp, sizeof(default_wallp), 0);
9465 leency 330
}
331
 
6212 leency 332
//===================================================//
333
//                                                   //
334
//                     EVENTS                        //
335
//                                                   //
336
//===================================================//
4078 leency 337
 
7909 leency 338
void EventTabSkinsClick()
4085 leency 339
{
9455 leency 340
	miniprintf(#folder_path, "%s/res/skins", GetRealKolibriosPath());
9465 leency 341
	Open_Dir();
6212 leency 342
}
4078 leency 343
 
7909 leency 344
void EventTabWallpappersClick()
345
{
9455 leency 346
	if (opendir_path) {
347
		strcpy(#folder_path, #opendir_path);
348
	} else {
349
		miniprintf(#folder_path, "%s/res/wallpapers", GetRealKolibriosPath());
350
	}
9465 leency 351
	Open_Dir();
7909 leency 352
}
353
 
9453 leency 354
void EventTabScreensaverClick()
355
{
9465 leency 356
	dword j;
357
	char ssmas[sizeof(ss_available)];
358
	list.drop();
359
	select_list.ClearList();
360
 
9469 leency 361
	select_list.count++;
362
	list.add(T_NO_SS);
363
 
9465 leency 364
	strcpy(#ssmas, #ss_available);
365
	do {
9469 leency 366
		j = strrchr(#ssmas, '|');
367
		miniprintf(#param, "/sys/%s", #ssmas + j);
9465 leency 368
		list.add(#param);
9469 leency 369
		ESBYTE[#ssmas + j - 1] = '\0';
9465 leency 370
		select_list.count++;
371
	} while (j);
372
 
373
	if (LIST_W) draw_window();
9453 leency 374
}
375
 
6212 leency 376
void EventDeleteFile()
377
{
9469 leency 378
	if (select_list.cur_y) DeleteFile(#cur_file_path); //no not delete default
6212 leency 379
	Open_Dir();
380
	EventApply();
381
}
4078 leency 382
 
7353 leency 383
void EventSelectWallpFolder()
384
{
385
	OpenDialog_start stdcall (#o_dialog);
9455 leency 386
	if (o_dialog.status) EventTabWallpappersClick();
7353 leency 387
}
388
 
9465 leency 389
void EventSetWallpMode(dword _stretch, _titled, _auto)
7611 leency 390
{
9465 leency 391
	optionbox_stretch.checked = _stretch;
392
	optionbox_tiled.checked = _titled;
393
	optionbox_auto.checked = _auto;
7611 leency 394
	optionbox_tiled.redraw();
395
	optionbox_stretch.redraw();
9465 leency 396
	optionbox_auto.redraw();
7611 leency 397
	EventApply();
398
}
399
 
6212 leency 400
void EventApply()
401
{
9465 leency 402
	char kivparam[4096+10];
403
	dword file_name = list.get(select_list.cur_y);
9469 leency 404
	strcpy(#cur_file_path, list.get(select_list.cur_y));
9461 leency 405
	if (tabs.active_tab==TAB_SKINS)
6212 leency 406
	{
407
		SetSystemSkin(#cur_file_path);
7612 leency 408
		SelectList_Draw();
7551 leency 409
		strcpy(#cur_skin_path, #cur_file_path);
7612 leency 410
		EventUpdateDocky();
6212 leency 411
	}
9461 leency 412
	if (tabs.active_tab==TAB_WALLPAPERS)
6212 leency 413
	{
7551 leency 414
		SelectList_Draw();
9465 leency 415
		miniprintf(#kivparam, "\\S__%s", #cur_file_path);
9469 leency 416
		if (optionbox_tiled.checked) || (!select_list.cur_y) kivparam[1]='T';
9465 leency 417
		if (optionbox_auto.checked) {
9469 leency 418
			file_name += strrchr(file_name, '/');
419
			if (ESBYTE[file_name] == 'T') && (ESBYTE[file_name+1] == '_') {
9465 leency 420
				kivparam[1]='T';
421
			}
422
		}
423
		RunProgram("/sys/media/kiv", #kivparam);
6212 leency 424
	}
9465 leency 425
	if (tabs.active_tab==TAB_SCREENSAVERS)
426
	{
427
		SelectList_Draw();
428
	}
6212 leency 429
}
4085 leency 430
 
7612 leency 431
void EventUpdateDocky()
432
{
433
	if (!update_docky.checked) return;
434
	KillProcessByName("@docky", MULTIPLE);
435
	RunProgram("/sys/@docky",NULL);
436
	pause(50);
9461 leency 437
	ActivateWindow_Self();
7612 leency 438
}
439
 
6212 leency 440
void EventOpenFile()
441
{
9469 leency 442
	switch (tabs.active_tab) {
443
		case TAB_SKINS: RunProgram("/sys/skincfg", #cur_file_path); break;
444
		case TAB_WALLPAPERS: RunProgram("/sys/media/kiv", #cur_file_path); break;
445
		case TAB_SCREENSAVERS: if(select_list.cur_y) RunProgram(list.get(select_list.cur_y), "@ss");
446
	}
4085 leency 447
}
448
 
7551 leency 449
void EventExit()
450
{
9455 leency 451
	if (cur_skin_path) {
452
		ini.section = "style";
453
		ini.SetString("skin", #cur_skin_path, strlen(#cur_skin_path));
454
	}
7551 leency 455
	ExitProcess();
456
}
457
 
4078 leency 458
stop: