Subversion Repositories Kolibri OS

Rev

Rev 9461 | Rev 9467 | 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';
260
	if (EAX = strrchr(filename,'/')) filename += EAX;
261
 
262
	//save current item for tab change
263
	switch(tabs.active_tab) {
264
		CASE TAB_SKINS: active_skin = select_list.cur_y; BREAK;
265
		CASE TAB_WALLPAPERS: active_wallpaper = select_list.cur_y; BREAK;
266
		CASE TAB_SCREENSAVERS: active_screensaver = select_list.cur_y;
267
	}
6651 leency 268
 
9461 leency 269
	if (select_list.cur_y == i_abs)
4410 leency 270
	{
9461 leency 271
		DrawBar(select_list.x, draw_y, LIST_W, SELECT_LIST_ITEMH, sc.button);
9465 leency 272
		WriteText(select_list.x+12,draw_y+select_list.text_y,select_list.font_type,sc.button_text, filename);
4410 leency 273
	}
6651 leency 274
	else
275
	{
9461 leency 276
		DrawBar(select_list.x,draw_y,LIST_W, SELECT_LIST_ITEMH, 0xFFFfff);
9465 leency 277
		WriteText(select_list.x+12,draw_y+select_list.text_y,select_list.font_type,0, filename);
6651 leency 278
	}
4078 leency 279
}
280
 
6653 leency 281
void SelectList_LineChanged()
282
{
283
	EventApply();
284
}
285
 
9455 leency 286
dword GetRealKolibriosPath()
287
{
288
	char real_kolibrios_path[4096];
289
	SetCurDir("/kolibrios");
290
	GetCurDir(#real_kolibrios_path, sizeof(real_kolibrios_path));
291
	return #real_kolibrios_path;
292
}
293
 
9465 leency 294
void GetScreensaverIniSettings()
295
{
296
	ini.section = "screensaver";
297
	screensaver_timeout = ini.GetInt("timeout", 10);
298
	ini.GetString("available", #ss_available, sizeof(ss_available), 0);
299
}
300
 
6212 leency 301
//===================================================//
302
//                                                   //
303
//                     EVENTS                        //
304
//                                                   //
305
//===================================================//
4078 leency 306
 
7909 leency 307
void EventTabSkinsClick()
4085 leency 308
{
9455 leency 309
	miniprintf(#folder_path, "%s/res/skins", GetRealKolibriosPath());
9465 leency 310
	Open_Dir();
6212 leency 311
}
4078 leency 312
 
7909 leency 313
void EventTabWallpappersClick()
314
{
9455 leency 315
	if (opendir_path) {
316
		strcpy(#folder_path, #opendir_path);
317
	} else {
318
		miniprintf(#folder_path, "%s/res/wallpapers", GetRealKolibriosPath());
319
	}
9465 leency 320
	Open_Dir();
7909 leency 321
}
322
 
9453 leency 323
void EventTabScreensaverClick()
324
{
9465 leency 325
	dword j;
326
	char ssmas[sizeof(ss_available)];
327
	list.drop();
328
	select_list.ClearList();
329
 
330
	strcpy(#ssmas, #ss_available);
331
	do {
332
		j = strrchr(#ss_available, '|');
333
		miniprintf(#param, "/sys/%s", #ss_available + j);
334
		list.add(#param);
335
		ESBYTE[#ss_available + j - 1] = '\0';
336
		select_list.count++;
337
	} while (j);
338
 
339
	if (LIST_W) draw_window();
9453 leency 340
}
341
 
6212 leency 342
void EventDeleteFile()
343
{
9465 leency 344
	DeleteFile(#cur_file_path);
6212 leency 345
	Open_Dir();
346
	EventApply();
347
}
4078 leency 348
 
7353 leency 349
void EventSelectWallpFolder()
350
{
351
	OpenDialog_start stdcall (#o_dialog);
9455 leency 352
	if (o_dialog.status) EventTabWallpappersClick();
7353 leency 353
}
354
 
9465 leency 355
void EventSetWallpMode(dword _stretch, _titled, _auto)
7611 leency 356
{
9465 leency 357
	optionbox_stretch.checked = _stretch;
358
	optionbox_tiled.checked = _titled;
359
	optionbox_auto.checked = _auto;
7611 leency 360
	optionbox_tiled.redraw();
361
	optionbox_stretch.redraw();
9465 leency 362
	optionbox_auto.redraw();
7611 leency 363
	EventApply();
364
}
365
 
6212 leency 366
void EventApply()
367
{
9465 leency 368
	char kivparam[4096+10];
369
	dword file_name = list.get(select_list.cur_y);
370
	miniprintf(#cur_file_path,"%s/",#folder_path);
371
	strcat(#cur_file_path, list.get(select_list.cur_y));
9461 leency 372
	if (tabs.active_tab==TAB_SKINS)
6212 leency 373
	{
374
		SetSystemSkin(#cur_file_path);
7612 leency 375
		SelectList_Draw();
7551 leency 376
		strcpy(#cur_skin_path, #cur_file_path);
7612 leency 377
		EventUpdateDocky();
6212 leency 378
	}
9461 leency 379
	if (tabs.active_tab==TAB_WALLPAPERS)
6212 leency 380
	{
7551 leency 381
		SelectList_Draw();
9465 leency 382
		miniprintf(#kivparam, "\\S__%s", #cur_file_path);
383
		if (optionbox_tiled.checked) kivparam[1]='T';
384
		if (optionbox_auto.checked) {
385
			if (ESBYTE[file_name+1] == ' ') && (ESBYTE[file_name] == 'T') {
386
				kivparam[1]='T';
387
			}
388
		}
389
		RunProgram("/sys/media/kiv", #kivparam);
6212 leency 390
	}
9465 leency 391
	if (tabs.active_tab==TAB_SCREENSAVERS)
392
	{
393
		SelectList_Draw();
394
	}
6212 leency 395
}
4085 leency 396
 
7612 leency 397
void EventUpdateDocky()
398
{
399
	if (!update_docky.checked) return;
400
	KillProcessByName("@docky", MULTIPLE);
401
	RunProgram("/sys/@docky",NULL);
402
	pause(50);
9461 leency 403
	ActivateWindow_Self();
7612 leency 404
}
405
 
6212 leency 406
void EventOpenFile()
407
{
9461 leency 408
	if (tabs.active_tab==TAB_SKINS) RunProgram("/sys/skincfg", #cur_file_path);
409
	if (tabs.active_tab==TAB_WALLPAPERS) RunProgram("/sys/media/kiv", #cur_file_path);
9465 leency 410
	if (tabs.active_tab==TAB_SCREENSAVERS) RunProgram(list.get(select_list.cur_y), "@ss");
4085 leency 411
}
412
 
7551 leency 413
void EventExit()
414
{
9455 leency 415
	if (cur_skin_path) {
416
		ini.section = "style";
417
		ini.SetString("skin", #cur_skin_path, strlen(#cur_skin_path));
418
	}
7551 leency 419
	ExitProcess();
420
}
421
 
4078 leency 422
stop: