Subversion Repositories Kolibri OS

Rev

Rev 9439 | Rev 9455 | 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
 
7660 leency 4
#define MEMSIZE 200*1024
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"
20
 
6212 leency 21
//===================================================//
22
//                                                   //
23
//                       DATA                        //
24
//                                                   //
25
//===================================================//
26
 
4085 leency 27
#ifdef LANG_RUS
6212 leency 28
	?define WINDOW_HEADER "Настройки оформления"
7353 leency 29
	?define T_SELECT_FOLDER "Выбрать папку"
7778 leency 30
	?define MENU_LIST "Открыть файл   |Enter\nУдалить файл     |Del"
7611 leency 31
	?define T_PICTURE_MODE " Положение картинки "
32
	?define T_CHECKBOX_STRETCH "Растянуть"
33
	?define T_CHECKBOX_TILED "Замостить"
7612 leency 34
	?define T_UPDATE_DOCK "Обновлять Dock-панель"
9453 leency 35
	char t_skins[] =       "   Стиль окон";
36
	char t_wallpapers[] =  "   Обои";
37
	char t_screensaver[] =  "   Скринсейвер";
4085 leency 38
#else
39
	?define WINDOW_HEADER "Appearance"
7611 leency 40
	?define T_SELECT_FOLDER "Select folder"
7778 leency 41
	?define MENU_LIST "Open file      |Enter\nDelete file      |Del"
7611 leency 42
	?define T_PICTURE_MODE " Picture Mode "
43
	?define T_CHECKBOX_STRETCH "Stretch"
44
	?define T_CHECKBOX_TILED "Tiled"
7612 leency 45
	?define T_UPDATE_DOCK "Update Dock"
9453 leency 46
	char t_skins[] =       "   Skins";
47
	char t_wallpapers[] =  "   Wallpapers";
48
	char t_screensaver[] =  "   Screensaver";
4085 leency 49
#endif
4078 leency 50
 
9453 leency 51
#define WIN_W 621
52
#define PANEL_H 58
7225 leency 53
#define LP 10 //LIST_PADDING
7594 leency 54
char skins_folder_path[4096];
55
char wallp_folder_path[4096];
4078 leency 56
 
9453 leency 57
signed int active_skin=-1, active_wallpaper=-1, active_screensaver=-1;
7353 leency 58
enum {
9453 leency 59
	BASE_TAB_BUTTON_ID=3,
60
	BTN_SELECT_WALLP_FOLDER=10,
61
	BTN_TEST_SCREENSAVER };
4078 leency 62
 
63
char folder_path[4096];
64
char cur_file_path[4096];
7551 leency 65
char cur_skin_path[4096];
4078 leency 66
char temp_filename[4096];
6096 leency 67
int files_mas[400];
4078 leency 68
 
9453 leency 69
_ini ini = { "/sys/settings/system.ini", "style" };
70
 
4078 leency 71
int cur;
72
 
73
proc_info Form;
7244 leency 74
block skp;
4078 leency 75
 
9453 leency 76
enum {SKINS, WALLPAPERS, SCREENSAVERS};
7225 leency 77
 
9453 leency 78
_tabs tabs = { -sizeof(t_skins)-sizeof(t_wallpapers)-sizeof(t_screensaver)-3*8+WIN_W
79
	 - TAB_PADDING / 2, LP, NULL, BASE_TAB_BUTTON_ID };
7909 leency 80
 
7612 leency 81
checkbox update_docky = { T_UPDATE_DOCK, false };
7244 leency 82
 
7353 leency 83
char default_dir[] = "/rd/1";
84
od_filter filter2 = { 8, "TXT\0\0" };
85
 
7611 leency 86
checkbox optionbox_stretch = { T_CHECKBOX_STRETCH, true };
87
checkbox optionbox_tiled = { T_CHECKBOX_TILED, false };
88
 
6212 leency 89
//===================================================//
90
//                                                   //
91
//                       CODE                        //
92
//                                                   //
93
//===================================================//
5548 leency 94
 
7594 leency 95
void GetRealFolderPathes()
96
{
9453 leency 97
	char real_kolibrios_path[4096];
7594 leency 98
	SetCurDir("/kolibrios");
9453 leency 99
	GetCurDir(#real_kolibrios_path, sizeof(real_kolibrios_path));
100
	miniprintf(#skins_folder_path, "%s/res/skins", #real_kolibrios_path);
101
	miniprintf(#wallp_folder_path, "%s/res/wallpapers", #real_kolibrios_path);
7594 leency 102
}
103
 
4078 leency 104
void main()
105
{
7909 leency 106
	int id;
4078 leency 107
 
7594 leency 108
	GetRealFolderPathes();
109
 
5626 leency 110
	load_dll(boxlib, #box_lib_init,0);
7533 leency 111
	load_dll(libini, #lib_init,1);
7353 leency 112
	load_dll(Proc_lib, #OpenDialog_init,0);
113
	o_dialog.type = 2; //select folder
114
	OpenDialog_init stdcall (#o_dialog);
115
 
9453 leency 116
	tabs.add(#t_skins, #EventTabSkinsClick);
117
	tabs.add(#t_wallpapers, #EventTabWallpappersClick);
118
	tabs.add(#t_screensaver, #EventTabScreensaverClick);
7909 leency 119
	tabs.draw_active_tab();
7353 leency 120
 
7551 leency 121
	SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
6096 leency 122
	loop() switch(WaitEvent())
4078 leency 123
	{
124
	  	case evMouse:
6653 leency 125
			SelectList_ProcessMouse();
4410 leency 126
 
7353 leency 127
			if (tabs.active_tab == SKINS) {
128
				edit_box_mouse stdcall (#edit_cmm);
129
				edit_box_mouse stdcall (#edit_st);
130
			}
131
 
7778 leency 132
	  		if (mouse.key&MOUSE_RIGHT) && (mouse.up)
133
	  		&&(select_list.MouseOver(mouse.x, mouse.y)) {
6651 leency 134
	  			select_list.ProcessMouse(mouse.x, mouse.y);
6653 leency 135
				SelectList_Draw();
7353 leency 136
				EventSetNewCurrent();
8020 leency 137
	  			open_lmenu(mouse.x, mouse.y, MENU_TOP_RIGHT, NULL, MENU_LIST);
6212 leency 138
	  		}
4078 leency 139
	  		break;
140
 
141
		case evButton:
142
			id=GetButtonID();
7551 leency 143
			if (id==1) EventExit();
7353 leency 144
			if (id==BTN_SELECT_WALLP_FOLDER) EventSelectWallpFolder();
7909 leency 145
			tabs.click(id);
7244 leency 146
			checkbox1.click(id);
7252 leency 147
			spinbox1.click(id);
7612 leency 148
			if (update_docky.click(id)) EventUpdateDocky();
7611 leency 149
			if (!optionbox_stretch.checked) && (optionbox_stretch.click(id)) EventSetWallpMode_Stretch();
150
			if (!optionbox_tiled.checked) && (optionbox_tiled.click(id)) EventSetWallpMode_Tiled();
4078 leency 151
			break;
152
 
153
		case evKey:
5706 leency 154
			GetKeys();
6651 leency 155
			if (select_list.ProcessKey(key_scancode)) EventApply();
6212 leency 156
			if (key_scancode==SCAN_CODE_ENTER) EventOpenFile();
157
			if (key_scancode==SCAN_CODE_DEL) EventDeleteFile();
9453 leency 158
			if (key_scancode==SCAN_CODE_TAB) {
159
				id = tabs.active_tab+1;
160
				if(id==3)id=0;
161
				tabs.click(id + tabs.base_id);
162
				draw_window();
163
				break;
164
			}
7349 leency 165
 
7506 leency 166
			if (! edit_cmm.flags & ed_focus) && (! edit_st.flags & ed_focus)
6651 leency 167
			for (id=select_list.cur_y+1; id
4078 leency 168
			{
6212 leency 169
				strcpy(#temp_filename, io.dir.position(files_mas[id]));
170
				if (temp_filename[0]==key_ascii) || (temp_filename[0]==key_ascii-32)
171
				{
6651 leency 172
					select_list.cur_y = id - 1;
173
					select_list.KeyDown();
6212 leency 174
					EventApply();
175
					break;
176
				}
4078 leency 177
			}
7349 leency 178
 
7353 leency 179
			if (tabs.active_tab == SKINS) {
180
				EAX = key_ascii << 8;
181
				edit_box_key stdcall (#edit_cmm);
182
				edit_box_key stdcall (#edit_st);
183
			}
4078 leency 184
			break;
185
 
7353 leency 186
		 case evReDraw:
187
			draw_window();
7778 leency 188
	 		EventHandleMenuClick();
4078 leency 189
   }
190
}
191
 
7353 leency 192
void draw_window()
193
{
7909 leency 194
	sc.get();
9453 leency 195
	DefineAndDrawWindow(screen.width-600/2,80,WIN_W+9,504+skin_height,0x34,sc.work,WINDOW_HEADER,0);
7353 leency 196
	GetProcessInfo(#Form, SelfInfo);
8946 leency 197
	IF (Form.status_window&ROLLED_UP) return;
7353 leency 198
	DrawWindowContent();
199
}
7244 leency 200
 
6212 leency 201
void DrawWindowContent()
202
{
203
	int id;
7225 leency 204
 
7806 leency 205
	sc.get();
7612 leency 206
 
9453 leency 207
	//tabs.w = Form.cwidth-LP-LP;
7909 leency 208
	tabs.draw();
9439 leency 209
	draw_icon_16w(tabs.x + TAB_PADDING, 15, 17);
9453 leency 210
	draw_icon_16w(sizeof(t_skins)-1*8 + TAB_PADDING + TAB_PADDING + tabs.x, 15, 6);
211
	draw_icon_16w(sizeof(t_wallpapers)+sizeof(t_skins)-2*8 + TAB_PADDING + TAB_PADDING + TAB_PADDING + tabs.x, 15, 61);
7225 leency 212
 
6651 leency 213
	id = select_list.cur_y;
9453 leency 214
	#define LIST_W 280
6653 leency 215
	SelectList_Init(
9453 leency 216
		LP + TAB_PADDING,
217
		PANEL_H,
218
		LIST_W,
219
		Form.cheight-LP-LP - TAB_PADDING - PANEL_H
6653 leency 220
		);
6651 leency 221
	select_list.cur_y = id;
7244 leency 222
 
223
	skp.set_size(
9453 leency 224
		LP + TAB_PADDING + LIST_W + TAB_PADDING + 30,
225
		PANEL_H,
226
		WIN_W  - 400,
7612 leency 227
		230 //select_list.h - 50 - 50
7244 leency 228
	);
229
 
6653 leency 230
	SelectList_Draw();
6662 leency 231
	SelectList_DrawBorder();
7244 leency 232
 
233
	if (tabs.active_tab == SKINS)
234
	{
9453 leency 235
		DrawFrame(skp.x, PANEL_H+5, skp.w, skp.h, " Components Preview ");
236
		DrawUiElementsPreview(skp.x+20, PANEL_H+5, skp.h);
237
		if (CheckProcessExists("@DOCKY")) update_docky.draw(skp.x, PANEL_H+250);
7244 leency 238
	}
7353 leency 239
	if (tabs.active_tab == WALLPAPERS)
240
	{
9453 leency 241
		DrawFrame(skp.x, PANEL_H+5, 180, 80, T_PICTURE_MODE);
242
		optionbox_stretch.draw(skp.x+14, PANEL_H+25);
243
		optionbox_tiled.draw(skp.x+14, PANEL_H+52);
244
		DrawStandartCaptButton(skp.x, PANEL_H+100, BTN_SELECT_WALLP_FOLDER, T_SELECT_FOLDER);
7353 leency 245
	}
9453 leency 246
	if (tabs.active_tab == SCREENSAVERS)
247
	{
248
		DrawStandartCaptButton(skp.x, PANEL_H, BTN_TEST_SCREENSAVER, "Test");
249
	}
6212 leency 250
}
251
 
4410 leency 252
 
6212 leency 253
void Open_Dir()
4078 leency 254
{
6212 leency 255
	int j;
6651 leency 256
	select_list.count = 0;
6212 leency 257
	if(io.dir.buffer)free(io.dir.buffer);
258
	io.dir.load(#folder_path,DIR_ONLYREAL);
259
	for (j=0; j
4410 leency 260
	{
6212 leency 261
		strcpy(#temp_filename, io.dir.position(j));
262
		strlwr(#temp_filename);
7353 leency 263
		if (tabs.active_tab==SKINS) {
264
			if (strcmpi(#temp_filename+strlen(#temp_filename)-4,".skn")!=0) continue;
265
		}
266
		if (tabs.active_tab==WALLPAPERS) {
267
			if (strcmpi(#temp_filename+strlen(#temp_filename)-4,".png")!=0)
268
			&& (strcmpi(#temp_filename+strlen(#temp_filename)-4,".jpg")!=0)
269
			&& (strcmpi(#temp_filename+strlen(#temp_filename)-5,".jpeg")!=0)
270
			&& (strcmpi(#temp_filename+strlen(#temp_filename)-4,".gif")!=0) continue;
271
		}
6651 leency 272
		cur = select_list.count;
6212 leency 273
		files_mas[cur]=j;
6651 leency 274
		select_list.count++;
4410 leency 275
	}
8261 leency 276
	Sort_by_Name(0, select_list.count-1);
6212 leency 277
}
278
 
8261 leency 279
void Sort_by_Name(int a, b) // for the first call: a = 0, b = sizeof(mas) - 1
280
{
281
	int j;
282
	int isn = a;
283
	if (a >= b) return;
284
	for (j = a; j <= b; j++) {
285
		if (strcmpi(io.dir.position(files_mas[j]), io.dir.position(files_mas[b]))<=0) {
286
			files_mas[isn] >< files_mas[j];
287
			isn++;
288
		}
289
	}
290
	Sort_by_Name(a, isn-2);
291
	Sort_by_Name(isn, b);
292
}
293
 
6653 leency 294
void SelectList_DrawLine(dword i)
6212 leency 295
{
8762 leency 296
	int yyy;
6212 leency 297
 
6651 leency 298
	cur = select_list.first + i;
299
	strcpy(#temp_filename, io.dir.position(files_mas[cur]));
300
	temp_filename[strlen(#temp_filename)-4] = 0;
301
	yyy = i*select_list.item_h+select_list.y;
302
 
303
	if (select_list.cur_y-select_list.first==i)
4410 leency 304
	{
7806 leency 305
		DrawBar(select_list.x, yyy, select_list.w, select_list.item_h, sc.button);
306
		WriteText(select_list.x+12,yyy+select_list.text_y,select_list.font_type,sc.button_text, #temp_filename);
4410 leency 307
	}
6651 leency 308
	else
309
	{
310
		DrawBar(select_list.x,yyy,select_list.w, select_list.item_h, 0xFFFfff);
311
		WriteText(select_list.x+12,yyy+select_list.text_y,select_list.font_type,0, #temp_filename);
312
	}
4078 leency 313
}
314
 
6653 leency 315
void SelectList_LineChanged()
316
{
317
	EventApply();
318
}
319
 
7960 leency 320
void ActivateTab(int _id)
321
{
322
	select_list.ClearList();
323
	Open_Dir();
324
	if (!select_list.count) notify("'No files were found' -E");
325
	select_list.cur_y = _id;
326
	if (select_list.cur_y>select_list.visible) select_list.first=select_list.cur_y;
327
	select_list.CheckDoesValuesOkey();
328
	if (select_list.w) draw_window();
329
}
330
 
6212 leency 331
//===================================================//
332
//                                                   //
333
//                     EVENTS                        //
334
//                                                   //
335
//===================================================//
4078 leency 336
 
7909 leency 337
void EventTabSkinsClick()
4085 leency 338
{
7909 leency 339
	active_wallpaper = select_list.cur_y;
340
	strcpy(#folder_path, #skins_folder_path);
7960 leency 341
	ActivateTab(active_skin);
6212 leency 342
}
4078 leency 343
 
7909 leency 344
void EventTabWallpappersClick()
345
{
346
	active_skin = select_list.cur_y;
347
	strcpy(#folder_path, #wallp_folder_path);
7960 leency 348
	ActivateTab(active_wallpaper);
7909 leency 349
}
350
 
9453 leency 351
void EventTabScreensaverClick()
352
{
353
	//strcpy(#folder_path, #wallp_folder_path);
354
	ActivateTab(active_screensaver);
355
}
356
 
6212 leency 357
void EventDeleteFile()
358
{
359
	io.del(#cur_file_path);
360
	Open_Dir();
361
	EventApply();
362
}
4078 leency 363
 
7353 leency 364
void EventSetNewCurrent()
365
{
366
	cur = select_list.cur_y;
9453 leency 367
	miniprintf(#cur_file_path,"%s/",#folder_path);
368
	strcat(#cur_file_path, io.dir.position(files_mas[cur]));
7353 leency 369
}
370
 
371
void EventSelectWallpFolder()
372
{
373
	OpenDialog_start stdcall (#o_dialog);
374
	if (o_dialog.status) {
375
		strcpy(#wallp_folder_path, #opendir_path);
7909 leency 376
		EventTabWallpappersClick();
7353 leency 377
	}
378
}
379
 
7611 leency 380
void EventSetWallpMode_Stretch()
381
{
382
	optionbox_tiled.checked = false;
383
	optionbox_tiled.redraw();
384
	EventApply();
385
}
386
 
387
void EventSetWallpMode_Tiled()
388
{
389
	optionbox_stretch.checked = false;
390
	optionbox_stretch.redraw();
391
	EventApply();
392
}
393
 
6212 leency 394
void EventApply()
395
{
7353 leency 396
	char kivpath[4096+10];
397
	EventSetNewCurrent();
6264 leency 398
	if (tabs.active_tab==SKINS)
6212 leency 399
	{
6651 leency 400
		cur = select_list.cur_y;
6212 leency 401
		SetSystemSkin(#cur_file_path);
7612 leency 402
		SelectList_Draw();
7551 leency 403
		strcpy(#cur_skin_path, #cur_file_path);
7612 leency 404
		EventUpdateDocky();
6212 leency 405
	}
6264 leency 406
	if (tabs.active_tab==WALLPAPERS)
6212 leency 407
	{
7551 leency 408
		SelectList_Draw();
9453 leency 409
		if (optionbox_stretch.checked) miniprintf(#kivpath, "\\S__%s", #cur_file_path);
410
		if (optionbox_tiled.checked) miniprintf(#kivpath, "\\T__%s", #cur_file_path);
7353 leency 411
		RunProgram("/sys/media/kiv", #kivpath);
6212 leency 412
	}
413
}
4085 leency 414
 
7612 leency 415
void EventUpdateDocky()
416
{
417
	if (!update_docky.checked) return;
418
	KillProcessByName("@docky", MULTIPLE);
419
	RunProgram("/sys/@docky",NULL);
420
	pause(50);
421
	ActivateWindow(GetProcessSlot(Form.ID));
422
}
423
 
6212 leency 424
void EventOpenFile()
425
{
6264 leency 426
	if (tabs.active_tab==SKINS) RunProgram("/sys/skincfg", #cur_file_path);
427
	if (tabs.active_tab==WALLPAPERS) RunProgram("/sys/media/kiv", #cur_file_path);
4085 leency 428
}
429
 
7551 leency 430
void EventExit()
431
{
7613 leency 432
	if (cur_skin_path) ini.SetString("skin", #cur_skin_path, strlen(#cur_skin_path));
7551 leency 433
	ExitProcess();
434
}
435
 
7778 leency 436
void EventHandleMenuClick()
437
{
438
	switch (get_menu_click())
439
	{
440
		case 1:
441
			EventOpenFile();
442
			break;
443
		case 2:
444
			EventDeleteFile();
445
			break;
446
	};
447
}
448
 
4078 leency 449
stop: