Subversion Repositories Kolibri OS

Rev

Rev 9455 | Rev 9465 | 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"
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];
6096 leency 37
int files_mas[400];
4078 leency 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 };
7244 leency 43
 
7611 leency 44
checkbox optionbox_stretch = { T_CHECKBOX_STRETCH, true };
45
checkbox optionbox_tiled = { T_CHECKBOX_TILED, false };
46
 
9461 leency 47
struct SCREENSAVER_SETTINGS {
48
	int timeout;
49
	char program[60];
50
	char available[200];
51
} ss_settings;
52
 
6212 leency 53
//===================================================//
54
//                                                   //
55
//                       CODE                        //
56
//                                                   //
57
//===================================================//
5548 leency 58
 
4078 leency 59
void main()
60
{
9461 leency 61
	int id, i;
5626 leency 62
	load_dll(boxlib, #box_lib_init,0);
7533 leency 63
	load_dll(libini, #lib_init,1);
7353 leency 64
	load_dll(Proc_lib, #OpenDialog_init,0);
65
	o_dialog.type = 2; //select folder
66
	OpenDialog_init stdcall (#o_dialog);
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();
7353 leency 83
			if (id==BTN_SELECT_WALLP_FOLDER) EventSelectWallpFolder();
7909 leency 84
			tabs.click(id);
7244 leency 85
			checkbox1.click(id);
7252 leency 86
			spinbox1.click(id);
7612 leency 87
			if (update_docky.click(id)) EventUpdateDocky();
7611 leency 88
			if (!optionbox_stretch.checked) && (optionbox_stretch.click(id)) EventSetWallpMode_Stretch();
89
			if (!optionbox_tiled.checked) && (optionbox_tiled.click(id)) EventSetWallpMode_Tiled();
4078 leency 90
			break;
91
 
92
		case evKey:
5706 leency 93
			GetKeys();
6651 leency 94
			if (select_list.ProcessKey(key_scancode)) EventApply();
6212 leency 95
			if (key_scancode==SCAN_CODE_ENTER) EventOpenFile();
96
			if (key_scancode==SCAN_CODE_DEL) EventDeleteFile();
9453 leency 97
			if (key_scancode==SCAN_CODE_TAB) {
98
				id = tabs.active_tab+1;
99
				if(id==3)id=0;
100
				tabs.click(id + tabs.base_id);
9455 leency 101
				DrawWindowContent();
9453 leency 102
				break;
103
			}
7349 leency 104
 
7506 leency 105
			if (! edit_cmm.flags & ed_focus) && (! edit_st.flags & ed_focus)
9461 leency 106
			for (i=select_list.cur_y+1; i
4078 leency 107
			{
9461 leency 108
				id = ESBYTE[io.dir.position(files_mas[i])];
109
				if (id==ESBYTE[EAX]) || (id==key_ascii-32)
6212 leency 110
				{
9461 leency 111
					select_list.cur_y = i - 1;
6651 leency 112
					select_list.KeyDown();
6212 leency 113
					EventApply();
114
					break;
115
				}
4078 leency 116
			}
7349 leency 117
 
9461 leency 118
			if (tabs.active_tab == TAB_SKINS) {
119
				EAX = key_editbox;
7353 leency 120
				edit_box_key stdcall (#edit_cmm);
121
				edit_box_key stdcall (#edit_st);
122
			}
4078 leency 123
			break;
124
 
7353 leency 125
		 case evReDraw:
126
			draw_window();
4078 leency 127
   }
128
}
129
 
7353 leency 130
void draw_window()
131
{
7909 leency 132
	sc.get();
9461 leency 133
	DefineAndDrawWindow(screen.width-WIN_W-9/2,80,WIN_W+9,WIN_H+4+skin_height,0x34,sc.work,WINDOW_HEADER,0);
7353 leency 134
	DrawWindowContent();
135
}
7244 leency 136
 
6212 leency 137
void DrawWindowContent()
138
{
7806 leency 139
	sc.get();
7612 leency 140
 
7909 leency 141
	tabs.draw();
9455 leency 142
	draw_icon_16w(tabs.x + TAB_PADDING, LP+5, 17);
143
	draw_icon_16w(sizeof(t_skins)-1*8 + TAB_PADDING + TAB_PADDING + tabs.x, LP+5, 6);
144
	draw_icon_16w(sizeof(t_wallpapers)+sizeof(t_skins)-2*8 + TAB_PADDING + TAB_PADDING + TAB_PADDING + tabs.x, LP+5, 61);
7225 leency 145
 
9461 leency 146
	$push select_list.cur_y
6653 leency 147
	SelectList_Init(
9453 leency 148
		LP + TAB_PADDING,
149
		PANEL_H,
150
		LIST_W,
9461 leency 151
		WIN_H - LP - TAB_PADDING - PANEL_H
6653 leency 152
		);
9461 leency 153
	$pop select_list.cur_y
7244 leency 154
 
9461 leency 155
	DrawBar(RIGHTx, PANEL_H, RIGHTw, WIN_H-PANEL_H-LP, sc.work);
7244 leency 156
 
6653 leency 157
	SelectList_Draw();
6662 leency 158
	SelectList_DrawBorder();
7244 leency 159
 
9461 leency 160
	if (tabs.active_tab == TAB_SKINS)
7244 leency 161
	{
9461 leency 162
		DrawFrame(RIGHTx, PANEL_H+5, RIGHTw, RIGHTh, T_UI_PREVIEW);
163
		DrawUiElementsPreview(RIGHTx+20, PANEL_H+5, RIGHTh);
164
		if (CheckProcessExists("@DOCKY")) update_docky.draw(RIGHTx, PANEL_H+250);
7244 leency 165
	}
9461 leency 166
	if (tabs.active_tab == TAB_WALLPAPERS)
7353 leency 167
	{
9461 leency 168
		DrawFrame(RIGHTx, PANEL_H+5, 180, 80, T_PICTURE_MODE);
169
		optionbox_stretch.draw(RIGHTx+14, PANEL_H+25);
170
		optionbox_tiled.draw(RIGHTx+14, PANEL_H+52);
171
		DrawStandartCaptButton(RIGHTx, PANEL_H+100, BTN_SELECT_WALLP_FOLDER, T_SELECT_FOLDER);
7353 leency 172
	}
9461 leency 173
	if (tabs.active_tab == TAB_SCREENSAVERS)
9453 leency 174
	{
9461 leency 175
		DrawStandartCaptButton(RIGHTx, PANEL_H, BTN_TEST_SCREENSAVER, "Test");
9453 leency 176
	}
6212 leency 177
}
178
 
9455 leency 179
bool strreqi(dword _left, _right)
180
{
9461 leency 181
	return strcmp(_left+strrchr(_left,'.'), _right);
9455 leency 182
}
4410 leency 183
 
6212 leency 184
void Open_Dir()
4078 leency 185
{
6212 leency 186
	int j;
9461 leency 187
	char temp_filename[4096];
6651 leency 188
	select_list.count = 0;
6212 leency 189
	if(io.dir.buffer)free(io.dir.buffer);
190
	io.dir.load(#folder_path,DIR_ONLYREAL);
191
	for (j=0; j
4410 leency 192
	{
6212 leency 193
		strcpy(#temp_filename, io.dir.position(j));
194
		strlwr(#temp_filename);
9461 leency 195
		if (tabs.active_tab==TAB_SKINS) {
196
			if (strreqi(#temp_filename,"skn")!=0) continue;
7353 leency 197
		}
9461 leency 198
		if (tabs.active_tab==TAB_WALLPAPERS) {
199
			if (strreqi(#temp_filename,"png")!=0)
200
			&& (strreqi(#temp_filename,"jpg")!=0)
201
			&& (strreqi(#temp_filename,"jpeg")!=0)
202
			&& (strreqi(#temp_filename,"bmp")!=0)
203
			&& (strreqi(#temp_filename,"gif")!=0) continue;
7353 leency 204
		}
9461 leency 205
		files_mas[calc(select_list.count)]=j;
6651 leency 206
		select_list.count++;
4410 leency 207
	}
8261 leency 208
	Sort_by_Name(0, select_list.count-1);
6212 leency 209
}
210
 
8261 leency 211
void Sort_by_Name(int a, b) // for the first call: a = 0, b = sizeof(mas) - 1
212
{
213
	int j;
214
	int isn = a;
215
	if (a >= b) return;
216
	for (j = a; j <= b; j++) {
217
		if (strcmpi(io.dir.position(files_mas[j]), io.dir.position(files_mas[b]))<=0) {
218
			files_mas[isn] >< files_mas[j];
219
			isn++;
220
		}
221
	}
222
	Sort_by_Name(a, isn-2);
223
	Sort_by_Name(isn, b);
224
}
225
 
6653 leency 226
void SelectList_DrawLine(dword i)
6212 leency 227
{
9461 leency 228
	int draw_y = i*SELECT_LIST_ITEMH+PANEL_H;
229
	int i_abs = select_list.first + i;
230
	char filename[4096];
6212 leency 231
 
9461 leency 232
	strcpy(#filename, io.dir.position(files_mas[i_abs]));
233
	EAX = math.min(strrchr(#filename,'.')-1, LIST_W - 24 / 8);
234
	filename[EAX] = '\0';
6651 leency 235
 
9461 leency 236
	if (select_list.cur_y == i_abs)
4410 leency 237
	{
9461 leency 238
		DrawBar(select_list.x, draw_y, LIST_W, SELECT_LIST_ITEMH, sc.button);
239
		WriteText(select_list.x+12,draw_y+select_list.text_y,select_list.font_type,sc.button_text, #filename);
4410 leency 240
	}
6651 leency 241
	else
242
	{
9461 leency 243
		DrawBar(select_list.x,draw_y,LIST_W, SELECT_LIST_ITEMH, 0xFFFfff);
244
		WriteText(select_list.x+12,draw_y+select_list.text_y,select_list.font_type,0, #filename);
6651 leency 245
	}
4078 leency 246
}
247
 
6653 leency 248
void SelectList_LineChanged()
249
{
250
	EventApply();
251
}
252
 
7960 leency 253
void ActivateTab(int _id)
254
{
255
	select_list.ClearList();
256
	Open_Dir();
9461 leency 257
	if (!select_list.count) notify(T_NO_FILES);
7960 leency 258
	select_list.cur_y = _id;
259
	if (select_list.cur_y>select_list.visible) select_list.first=select_list.cur_y;
260
	select_list.CheckDoesValuesOkey();
9461 leency 261
	if (LIST_W) DrawWindowContent();
7960 leency 262
}
263
 
9455 leency 264
dword GetRealKolibriosPath()
265
{
266
	char real_kolibrios_path[4096];
267
	SetCurDir("/kolibrios");
268
	GetCurDir(#real_kolibrios_path, sizeof(real_kolibrios_path));
269
	return #real_kolibrios_path;
270
}
271
 
6212 leency 272
//===================================================//
273
//                                                   //
274
//                     EVENTS                        //
275
//                                                   //
276
//===================================================//
4078 leency 277
 
7909 leency 278
void EventTabSkinsClick()
4085 leency 279
{
7909 leency 280
	active_wallpaper = select_list.cur_y;
9455 leency 281
	miniprintf(#folder_path, "%s/res/skins", GetRealKolibriosPath());
7960 leency 282
	ActivateTab(active_skin);
6212 leency 283
}
4078 leency 284
 
7909 leency 285
void EventTabWallpappersClick()
286
{
287
	active_skin = select_list.cur_y;
9455 leency 288
	if (opendir_path) {
289
		strcpy(#folder_path, #opendir_path);
290
	} else {
291
		miniprintf(#folder_path, "%s/res/wallpapers", GetRealKolibriosPath());
292
	}
7960 leency 293
	ActivateTab(active_wallpaper);
7909 leency 294
}
295
 
9453 leency 296
void EventTabScreensaverClick()
297
{
9461 leency 298
	ini.section = "screensaver";
299
	ss_settings.timeout = ini.GetInt("timeout", 10);
300
	ini.GetString("title", #ss_settings.program, sizeof(ss_settings.program), 0);
301
	ini.GetString("available", #ss_settings.available, sizeof(ss_settings.available), 0);
9453 leency 302
	ActivateTab(active_screensaver);
303
}
304
 
6212 leency 305
void EventDeleteFile()
306
{
307
	io.del(#cur_file_path);
308
	Open_Dir();
309
	EventApply();
310
}
4078 leency 311
 
7353 leency 312
void EventSetNewCurrent()
313
{
9453 leency 314
	miniprintf(#cur_file_path,"%s/",#folder_path);
9461 leency 315
	strcat(#cur_file_path, io.dir.position(files_mas[calc(select_list.cur_y)]));
7353 leency 316
}
317
 
318
void EventSelectWallpFolder()
319
{
320
	OpenDialog_start stdcall (#o_dialog);
9455 leency 321
	if (o_dialog.status) EventTabWallpappersClick();
7353 leency 322
}
323
 
7611 leency 324
void EventSetWallpMode_Stretch()
325
{
326
	optionbox_tiled.checked = false;
327
	optionbox_tiled.redraw();
328
	EventApply();
329
}
330
 
331
void EventSetWallpMode_Tiled()
332
{
333
	optionbox_stretch.checked = false;
334
	optionbox_stretch.redraw();
335
	EventApply();
336
}
337
 
6212 leency 338
void EventApply()
339
{
7353 leency 340
	char kivpath[4096+10];
341
	EventSetNewCurrent();
9461 leency 342
	if (tabs.active_tab==TAB_SKINS)
6212 leency 343
	{
344
		SetSystemSkin(#cur_file_path);
7612 leency 345
		SelectList_Draw();
7551 leency 346
		strcpy(#cur_skin_path, #cur_file_path);
7612 leency 347
		EventUpdateDocky();
6212 leency 348
	}
9461 leency 349
	if (tabs.active_tab==TAB_WALLPAPERS)
6212 leency 350
	{
7551 leency 351
		SelectList_Draw();
9453 leency 352
		if (optionbox_stretch.checked) miniprintf(#kivpath, "\\S__%s", #cur_file_path);
353
		if (optionbox_tiled.checked) miniprintf(#kivpath, "\\T__%s", #cur_file_path);
7353 leency 354
		RunProgram("/sys/media/kiv", #kivpath);
6212 leency 355
	}
356
}
4085 leency 357
 
7612 leency 358
void EventUpdateDocky()
359
{
360
	if (!update_docky.checked) return;
361
	KillProcessByName("@docky", MULTIPLE);
362
	RunProgram("/sys/@docky",NULL);
363
	pause(50);
9461 leency 364
	ActivateWindow_Self();
7612 leency 365
}
366
 
6212 leency 367
void EventOpenFile()
368
{
9461 leency 369
	if (tabs.active_tab==TAB_SKINS) RunProgram("/sys/skincfg", #cur_file_path);
370
	if (tabs.active_tab==TAB_WALLPAPERS) RunProgram("/sys/media/kiv", #cur_file_path);
4085 leency 371
}
372
 
7551 leency 373
void EventExit()
374
{
9455 leency 375
	if (cur_skin_path) {
376
		ini.section = "style";
377
		ini.SetString("skin", #cur_skin_path, strlen(#cur_skin_path));
378
	}
7551 leency 379
	ExitProcess();
380
}
381
 
4078 leency 382
stop: