Subversion Repositories Kolibri OS

Rev

Rev 9465 | Rev 9469 | 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
 
9453 leency 28
signed int active_skin=-1, active_wallpaper=-1, active_screensaver=-1;
7353 leency 29
enum {
9453 leency 30
	BASE_TAB_BUTTON_ID=3,
31
	BTN_SELECT_WALLP_FOLDER=10,
32
	BTN_TEST_SCREENSAVER };
4078 leency 33
 
34
char folder_path[4096];
35
char cur_file_path[4096];
7551 leency 36
char cur_skin_path[4096];
9465 leency 37
char ss_available[200];
4078 leency 38
 
9465 leency 39
int screensaver_timeout;
40
 
9453 leency 41
_tabs tabs = { -sizeof(t_skins)-sizeof(t_wallpapers)-sizeof(t_screensaver)-3*8+WIN_W
42
	 - TAB_PADDING / 2, LP, NULL, BASE_TAB_BUTTON_ID };
7909 leency 43
 
7612 leency 44
checkbox update_docky = { T_UPDATE_DOCK, false };
7244 leency 45
 
9465 leency 46
checkbox optionbox_stretch = { T_CHECKBOX_STRETCH, false };
7611 leency 47
checkbox optionbox_tiled = { T_CHECKBOX_TILED, false };
9465 leency 48
checkbox optionbox_auto = { T_CHECKBOX_AUTO, true };
7611 leency 49
 
9465 leency 50
collection list;
9461 leency 51
 
6212 leency 52
//===================================================//
53
//                                                   //
54
//                       CODE                        //
55
//                                                   //
56
//===================================================//
5548 leency 57
 
4078 leency 58
void main()
59
{
9461 leency 60
	int id, i;
5626 leency 61
	load_dll(boxlib, #box_lib_init,0);
7533 leency 62
	load_dll(libini, #lib_init,1);
7353 leency 63
	load_dll(Proc_lib, #OpenDialog_init,0);
64
	o_dialog.type = 2; //select folder
65
	OpenDialog_init stdcall (#o_dialog);
66
 
9453 leency 67
	tabs.add(#t_skins, #EventTabSkinsClick);
68
	tabs.add(#t_wallpapers, #EventTabWallpappersClick);
69
	tabs.add(#t_screensaver, #EventTabScreensaverClick);
7909 leency 70
	tabs.draw_active_tab();
7353 leency 71
 
9465 leency 72
	GetScreensaverIniSettings();
73
 
7551 leency 74
	SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
6096 leency 75
	loop() switch(WaitEvent())
4078 leency 76
	{
77
	  	case evMouse:
6653 leency 78
			SelectList_ProcessMouse();
4078 leency 79
	  		break;
80
 
81
		case evButton:
82
			id=GetButtonID();
7551 leency 83
			if (id==1) EventExit();
7909 leency 84
			tabs.click(id);
9465 leency 85
			if (tabs.active_tab == TAB_SKINS) {
86
				checkbox1.click(id);
87
				spinbox1.click(id);
88
				if (update_docky.click(id)) EventUpdateDocky();
89
			}
90
			if (tabs.active_tab == TAB_WALLPAPERS) {
91
				if (id==BTN_SELECT_WALLP_FOLDER) EventSelectWallpFolder();
92
				if (optionbox_stretch.click(id)) EventSetWallpMode(1,0,0);
93
				if (optionbox_tiled.click(id)) EventSetWallpMode(0,1,0);
94
				if (optionbox_auto.click(id)) EventSetWallpMode(0,0,1);
95
			}
96
			if (tabs.active_tab == TAB_SCREENSAVERS) {
97
				if (id==BTN_TEST_SCREENSAVER) EventOpenFile();
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
			{
9465 leency 116
				id = ESBYTE[list.get(i)];
9461 leency 117
				if (id==ESBYTE[EAX]) || (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
	{
9465 leency 184
		DrawStandartCaptButton(RIGHTx, PANEL_H, BTN_TEST_SCREENSAVER, T_SCREENSAVER_PREVIEW);
9453 leency 185
	}
6212 leency 186
}
187
 
9455 leency 188
bool strreqi(dword _left, _right)
189
{
9461 leency 190
	return strcmp(_left+strrchr(_left,'.'), _right);
9455 leency 191
}
4410 leency 192
 
9465 leency 193
dword files_mas[400];
6212 leency 194
void Open_Dir()
4078 leency 195
{
6212 leency 196
	int j;
9465 leency 197
	char fname[4096];
198
	select_list.ClearList();
6212 leency 199
	if(io.dir.buffer)free(io.dir.buffer);
200
	io.dir.load(#folder_path,DIR_ONLYREAL);
201
	for (j=0; j
4410 leency 202
	{
9465 leency 203
		strcpy(#fname, io.dir.position(j));
204
		strlwr(#fname);
9461 leency 205
		if (tabs.active_tab==TAB_SKINS) {
9465 leency 206
			if (strreqi(#fname,"skn")!=0) continue;
7353 leency 207
		}
9461 leency 208
		if (tabs.active_tab==TAB_WALLPAPERS) {
9465 leency 209
			if (strreqi(#fname,"png")!=0)
210
			&& (strreqi(#fname,"jpg")!=0)
211
			&& (strreqi(#fname,"jpeg")!=0)
212
			&& (strreqi(#fname,"bmp")!=0)
213
			&& (strreqi(#fname,"gif")!=0) continue;
7353 leency 214
		}
9465 leency 215
		ESDWORD[select_list.count*4 + #files_mas] = j;
6651 leency 216
		select_list.count++;
4410 leency 217
	}
8261 leency 218
	Sort_by_Name(0, select_list.count-1);
9465 leency 219
	list.drop();
220
	for (j=0; j
221
		list.add(io.dir.position(files_mas[j]));
222
	}
223
	if (!select_list.count) notify(T_NO_FILES);
224
	//save current item for tab change
225
	switch(tabs.active_tab) {
226
		CASE TAB_SKINS: select_list.cur_y = active_skin; BREAK;
227
		CASE TAB_WALLPAPERS: select_list.cur_y = active_wallpaper; BREAK;
228
		CASE TAB_SCREENSAVERS: select_list.cur_y = active_screensaver;
229
	}
230
	if (select_list.cur_y>select_list.visible) select_list.first=select_list.cur_y;
231
	select_list.CheckDoesValuesOkey();
232
	if (LIST_W) draw_window();
6212 leency 233
}
234
 
8261 leency 235
void Sort_by_Name(int a, b) // for the first call: a = 0, b = sizeof(mas) - 1
236
{
237
	int j;
238
	int isn = a;
239
	if (a >= b) return;
240
	for (j = a; j <= b; j++) {
241
		if (strcmpi(io.dir.position(files_mas[j]), io.dir.position(files_mas[b]))<=0) {
242
			files_mas[isn] >< files_mas[j];
243
			isn++;
244
		}
245
	}
246
	Sort_by_Name(a, isn-2);
247
	Sort_by_Name(isn, b);
248
}
249
 
6653 leency 250
void SelectList_DrawLine(dword i)
6212 leency 251
{
9461 leency 252
	int draw_y = i*SELECT_LIST_ITEMH+PANEL_H;
253
	int i_abs = select_list.first + i;
9465 leency 254
	char filename_buf[4096];
255
	char* filename = #filename_buf;
6212 leency 256
 
9465 leency 257
	strcpy(filename, list.get(i_abs));
258
	EAX = math.min(strrchr(filename,'.')-1, LIST_W - 24 / 8);
259
	filename_buf[EAX] = '\0';
9467 leency 260
	if (filename_buf[0]=='T') && (filename_buf[1]=='_') filename+=2;
9465 leency 261
	if (EAX = strrchr(filename,'/')) filename += EAX;
262
 
263
	//save current item for tab change
264
	switch(tabs.active_tab) {
265
		CASE TAB_SKINS: active_skin = select_list.cur_y; BREAK;
266
		CASE TAB_WALLPAPERS: active_wallpaper = select_list.cur_y; BREAK;
267
		CASE TAB_SCREENSAVERS: active_screensaver = select_list.cur_y;
268
	}
6651 leency 269
 
9461 leency 270
	if (select_list.cur_y == i_abs)
4410 leency 271
	{
9461 leency 272
		DrawBar(select_list.x, draw_y, LIST_W, SELECT_LIST_ITEMH, sc.button);
9465 leency 273
		WriteText(select_list.x+12,draw_y+select_list.text_y,select_list.font_type,sc.button_text, filename);
4410 leency 274
	}
6651 leency 275
	else
276
	{
9461 leency 277
		DrawBar(select_list.x,draw_y,LIST_W, SELECT_LIST_ITEMH, 0xFFFfff);
9465 leency 278
		WriteText(select_list.x+12,draw_y+select_list.text_y,select_list.font_type,0, filename);
6651 leency 279
	}
4078 leency 280
}
281
 
6653 leency 282
void SelectList_LineChanged()
283
{
284
	EventApply();
285
}
286
 
9455 leency 287
dword GetRealKolibriosPath()
288
{
289
	char real_kolibrios_path[4096];
290
	SetCurDir("/kolibrios");
291
	GetCurDir(#real_kolibrios_path, sizeof(real_kolibrios_path));
292
	return #real_kolibrios_path;
293
}
294
 
9465 leency 295
void GetScreensaverIniSettings()
296
{
297
	ini.section = "screensaver";
298
	screensaver_timeout = ini.GetInt("timeout", 10);
299
	ini.GetString("available", #ss_available, sizeof(ss_available), 0);
300
}
301
 
6212 leency 302
//===================================================//
303
//                                                   //
304
//                     EVENTS                        //
305
//                                                   //
306
//===================================================//
4078 leency 307
 
7909 leency 308
void EventTabSkinsClick()
4085 leency 309
{
9455 leency 310
	miniprintf(#folder_path, "%s/res/skins", GetRealKolibriosPath());
9465 leency 311
	Open_Dir();
6212 leency 312
}
4078 leency 313
 
7909 leency 314
void EventTabWallpappersClick()
315
{
9455 leency 316
	if (opendir_path) {
317
		strcpy(#folder_path, #opendir_path);
318
	} else {
319
		miniprintf(#folder_path, "%s/res/wallpapers", GetRealKolibriosPath());
320
	}
9465 leency 321
	Open_Dir();
7909 leency 322
}
323
 
9453 leency 324
void EventTabScreensaverClick()
325
{
9465 leency 326
	dword j;
327
	char ssmas[sizeof(ss_available)];
328
	list.drop();
329
	select_list.ClearList();
330
 
331
	strcpy(#ssmas, #ss_available);
332
	do {
333
		j = strrchr(#ss_available, '|');
334
		miniprintf(#param, "/sys/%s", #ss_available + j);
335
		list.add(#param);
336
		ESBYTE[#ss_available + j - 1] = '\0';
337
		select_list.count++;
338
	} while (j);
339
 
340
	if (LIST_W) draw_window();
9453 leency 341
}
342
 
6212 leency 343
void EventDeleteFile()
344
{
9465 leency 345
	DeleteFile(#cur_file_path);
6212 leency 346
	Open_Dir();
347
	EventApply();
348
}
4078 leency 349
 
7353 leency 350
void EventSelectWallpFolder()
351
{
352
	OpenDialog_start stdcall (#o_dialog);
9455 leency 353
	if (o_dialog.status) EventTabWallpappersClick();
7353 leency 354
}
355
 
9465 leency 356
void EventSetWallpMode(dword _stretch, _titled, _auto)
7611 leency 357
{
9465 leency 358
	optionbox_stretch.checked = _stretch;
359
	optionbox_tiled.checked = _titled;
360
	optionbox_auto.checked = _auto;
7611 leency 361
	optionbox_tiled.redraw();
362
	optionbox_stretch.redraw();
9465 leency 363
	optionbox_auto.redraw();
7611 leency 364
	EventApply();
365
}
366
 
6212 leency 367
void EventApply()
368
{
9465 leency 369
	char kivparam[4096+10];
370
	dword file_name = list.get(select_list.cur_y);
371
	miniprintf(#cur_file_path,"%s/",#folder_path);
372
	strcat(#cur_file_path, list.get(select_list.cur_y));
9461 leency 373
	if (tabs.active_tab==TAB_SKINS)
6212 leency 374
	{
375
		SetSystemSkin(#cur_file_path);
7612 leency 376
		SelectList_Draw();
7551 leency 377
		strcpy(#cur_skin_path, #cur_file_path);
7612 leency 378
		EventUpdateDocky();
6212 leency 379
	}
9461 leency 380
	if (tabs.active_tab==TAB_WALLPAPERS)
6212 leency 381
	{
7551 leency 382
		SelectList_Draw();
9465 leency 383
		miniprintf(#kivparam, "\\S__%s", #cur_file_path);
384
		if (optionbox_tiled.checked) kivparam[1]='T';
385
		if (optionbox_auto.checked) {
9467 leency 386
			if (ESBYTE[file_name+1] == '_') && (ESBYTE[file_name] == 'T') {
9465 leency 387
				kivparam[1]='T';
388
			}
389
		}
390
		RunProgram("/sys/media/kiv", #kivparam);
6212 leency 391
	}
9465 leency 392
	if (tabs.active_tab==TAB_SCREENSAVERS)
393
	{
394
		SelectList_Draw();
395
	}
6212 leency 396
}
4085 leency 397
 
7612 leency 398
void EventUpdateDocky()
399
{
400
	if (!update_docky.checked) return;
401
	KillProcessByName("@docky", MULTIPLE);
402
	RunProgram("/sys/@docky",NULL);
403
	pause(50);
9461 leency 404
	ActivateWindow_Self();
7612 leency 405
}
406
 
6212 leency 407
void EventOpenFile()
408
{
9461 leency 409
	if (tabs.active_tab==TAB_SKINS) RunProgram("/sys/skincfg", #cur_file_path);
410
	if (tabs.active_tab==TAB_WALLPAPERS) RunProgram("/sys/media/kiv", #cur_file_path);
9465 leency 411
	if (tabs.active_tab==TAB_SCREENSAVERS) RunProgram(list.get(select_list.cur_y), "@ss");
4085 leency 412
}
413
 
7551 leency 414
void EventExit()
415
{
9455 leency 416
	if (cur_skin_path) {
417
		ini.section = "style";
418
		ini.SetString("skin", #cur_skin_path, strlen(#cur_skin_path));
419
	}
7551 leency 420
	ExitProcess();
421
}
422
 
4078 leency 423
stop: