Subversion Repositories Kolibri OS

Rev

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