Subversion Repositories Kolibri OS

Rev

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