Subversion Repositories Kolibri OS

Rev

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