Subversion Repositories Kolibri OS

Rev

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