-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreference.php
705 lines (622 loc) · 25.8 KB
/
preference.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
<?php
/**
* @copyright Copyright (C) 2009, Вавилов Егор (Shecspi)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
* @link http://code.google.com/p/flight-files/ Домашняя страница проекта
*/
/**
* Отображает окно с настройками.
* @global array $_config
* @global array $lang
* @global resource $sqlite
* @global GtkWindow $main_window
*/
function preference()
{
global $_config, $lang, $sqlite, $main_window;
$window = new GtkWindow();
$window->set_type_hint(Gdk::WINDOW_TYPE_HINT_DIALOG);
$window->set_title($lang['preference']['title']);
$window->set_icon(GdkPixbuf::new_from_file(ICON_PROGRAM));
$window->set_position(Gtk::WIN_POS_CENTER);
$window->set_resizable(FALSE);
$window->set_modal(TRUE);
$window->set_transient_for($main_window);
$window->connect_simple('destroy', array('Gtk', 'main_quit'));
$notebook = new GtkNotebook();
$notebook->set_border_width(10);
/**
* Вкладка "Основные".
*/
$vbox = new GtkVBox;
$notebook->append_page($vbox, new GtkLabel($lang['preference']['general']));
// Показывать скрытые файлы
$hidden_files = new GtkCheckButton($lang['preference']['hidden_files']);
$hidden_files->set_tooltip_text($lang['preference']['hidden_files_hint']);
$hidden_files->set_alignment(0, 0);
$hidden_files->connect('toggled', 'check_button_write', 'hidden_files');
if ($_config['hidden_files'] == 'on')
{
$hidden_files->set_active(TRUE);
}
$vbox->pack_start($hidden_files, FALSE, FALSE);
// Подтверждение при удалении
$ask_delete = new GtkCheckButton($lang['preference']['ask_delete']);
$ask_delete->set_tooltip_text($lang['preference']['ask_delete_hint']);
$ask_delete->connect('toggled', 'check_button_write', 'ask_delete');
if ($_config['ask_delete'] == 'on')
{
$ask_delete->set_active(TRUE);
}
$vbox->pack_start($ask_delete, FALSE, FALSE);
// Подтверждение при закрытии
$ask_close = new GtkCheckButton($lang['preference']['ask_close']);
$ask_close->set_tooltip_text($lang['preference']['ask_close_hint']);
$ask_close->connect('toggled', 'check_button_write', 'ask_close');
if ($_config['ask_close'] == 'on')
{
$ask_close->set_active(TRUE);
}
$vbox->pack_start($ask_close, FALSE, FALSE);
// Разворачивать на весь экран
$maximize = new GtkCheckButton($lang['preference']['maximize']);
$maximize->set_tooltip_text($lang['preference']['maximize_hint']);
$maximize->connect('toggled', 'check_button_write', 'maximize');
if ($_config['maximize'] == 'on')
{
$maximize->set_active(TRUE);
}
$vbox->pack_start($maximize, FALSE, FALSE);
// Автообновление списка разделов
// $partbar_refresh = new GtkCheckButton($lang['preference']['partbar_refresh']);
// $partbar_refresh->set_tooltip_text($lang['preference']['partbar_refresh_hint']);
// $partbar_refresh->connect('toggled', 'check_button_write', 'partbar_refresh');
// if ($_config['partbar_refresh'] == 'on')
// {
// $partbar_refresh->set_active(TRUE);
// }
// $vbox->pack_start($partbar_refresh, FALSE, FALSE);
// Показывать иконку в трее
$status_icon = new GtkCheckButton($lang['preference']['status_icon']);
$status_icon->set_tooltip_text($lang['preference']['status_icon_hint']);
$status_icon->connect('toggled', 'check_button_write', 'status_icon');
if ($_config['status_icon'] == 'on')
{
$status_icon->set_active(TRUE);
}
$vbox->pack_start($status_icon, FALSE, FALSE);
$vbox->pack_start(new GtkHSeparator, FALSE, FALSE);
// Сохранять открытые директории
$save_folders = new GtkCheckButton($lang['preference']['save_folders']);
$save_folders->set_tooltip_text($lang['preference']['save_folders_hinr']);
if ($_config['save_folders'] == 'on')
{
$save_folders->set_active(TRUE);
}
$vbox->pack_start($save_folders, FALSE, FALSE);
// Начальная директоря для левой панели
$label_home_dir_left = new GtkLabel($lang['preference']['home_dir_left']);
$label_home_dir_left->set_alignment(0, 0);
$vbox->pack_start($label_home_dir_left, FALSE, FALSE);
$entry_left = new GtkEntry($_config['home_dir_left']);
$entry_left->connect('changed', 'change_value', 'home_dir_left');
$button = new GtkButton('...');
$button->set_tooltip_text($lang['preference']['change_home_dir']);
$button->connect_simple('clicked', 'select_file_window', $entry_left, 'folder');
$vbox->pack_start($hbox = new GtkHBox(), FALSE, FALSE);
$hbox->pack_start($entry_left, TRUE, TRUE);
$hbox->pack_start($button, FALSE, FALSE);
// Начальная директория для правой панели
$label_home_dir_right = new GtkLabel($lang['preference']['home_dir_right']);
$label_home_dir_right->set_alignment(0, 0);
$vbox->pack_start($label_home_dir_right, FALSE, FALSE);
$entry_right = new GtkEntry($_config['home_dir_right']);
$entry_right->connect('changed', 'change_value', 'home_dir_right');
$button = new GtkButton('...');
$button->set_tooltip_text($lang['preference']['change_home_dir']);
$button->connect_simple('clicked', 'select_file_window', $entry_right, 'folder');
$vbox->pack_start($hbox = new GtkHBox(), FALSE, FALSE);
$hbox->pack_start($entry_right, TRUE, TRUE);
$hbox->pack_start($button, FALSE, FALSE);
$save_folders->connect('toggled', 'check_button_write', 'save_folders');
// Язык программы
$label_lang = new GtkLabel($lang['preference']['lang']);
$label_lang->set_alignment(0, 0.5);
$combo = GtkComboBox::new_text();
$opendir = opendir(LANG_DIR);
$i = 0;
while (FALSE !== ($file = readdir($opendir)))
{
if ($file == '.' OR $file == '..')
{
continue;
}
$explode = explode('.', $file);
if ($explode[2] == 'php')
{
$combo->append_text($explode[0] .' (' . $explode[1] . ')');
if ($explode[0] . '.' . $explode[1] == $_config['language'])
{
$combo->set_active($i);
}
$i++;
}
}
closedir($opendir);
$combo->connect('changed', 'combo_write', 'language');
$vbox->pack_start(new GtkHSeparator, FALSE, FALSE);
$vbox->pack_start($hbox = new GtkHBox, FALSE, FALSE);
$hbox->pack_start($label_lang, TRUE, TRUE);
$hbox->pack_start($combo, TRUE, TRUE);
// Формат даты
$label_mtime = new GtkLabel($lang['prefernce']['mtime']);
$label_mtime->set_tooltip_text($lang['prefernce']['mtime_hint']);
$label_mtime->set_alignment(0, 0.5);
$entry_mtime = new GtkEntry($_config['mtime_format']);
$entry_mtime->set_tooltip_text($lang['prefernce']['mtime_hint']);
$entry_mtime->connect('changed', 'change_value', 'mtime_format');
$vbox->pack_start($hbox = new GtkHBox(), FALSE, FALSE);
$hbox->pack_start($label_mtime, TRUE, TRUE);
$hbox->pack_start($entry_mtime, TRUE, TRUE);
$vbox->pack_start(new GtkHSeparator, FALSE, FALSE);
// Экспорт настроек
$vbox->pack_start($hbox = new GtkHBox(), FALSE, FALSE);
$button = new GtkButton($lang['preference']['export_settings']);
$button->connect_simple('clicked', 'export_settings');
$hbox->pack_start($button, TRUE, TRUE);
// Импорт настроек
$button = new GtkButton($lang['preference']['import_settings']);
$button->connect_simple('clicked', 'import_settings', $window);
$hbox->pack_start($button, TRUE, TRUE);
/**
* Вкладка "Интерфейс".
*/
$vbox = new GtkVBox;
$notebook->append_page($vbox, new GtkLabel($lang['preference']['interface']));
// Icons theme
$label_theme = new GtkLabel($lang['preference']['change_icons_theme']);
$label_theme->set_alignment(0, 0.5);
$combo_theme = GtkComboBox::new_text();
$combo_theme->append_text('Silk');
$combo_theme->set_active(0);
$combo_theme->set_sensitive(FALSE);
$vbox->pack_start($hbox = new GtkHBox, FALSE, FALSE);
$hbox->pack_start($label_theme, TRUE, TRUE);
$hbox->pack_start($combo_theme, TRUE, TRUE);
$vbox->pack_start(new GtkHSeparator, FALSE, FALSE);
// Показывать линии между файлами
$view_lines_files = new GtkCheckButton($lang['preference']['view_lines_files']);
$view_lines_files->set_tooltip_text($lang['preference']['vlf_hint']);
$view_lines_files->connect('toggled', 'check_button_write', 'view_lines_files');
if ($_config['view_lines_files'] == 'on')
{
$view_lines_files->set_active(TRUE);
}
$vbox->pack_start($view_lines_files, FALSE, FALSE);
// Показывать линии между колонками
$view_lines_columns = new GtkCheckButton($lang['preference']['view_lines_columns']);
$view_lines_columns->set_tooltip_text($lang['preference']['vlc_hint']);
$view_lines_columns->connect('toggled', 'check_button_write', 'view_lines_columns');
if ($_config['view_lines_columns'] == 'on')
{
$view_lines_columns->set_active(TRUE);
}
$vbox->pack_start($view_lines_columns, FALSE, FALSE);
$vbox->pack_start(new GtkHSeparator, FALSE, FALSE);
// Тип панели инструментов
$label = new GtkLabel($lang['preference']['toolbar_style']);
$label->set_tooltip_text($lang['preference']['toolbar_style_hint']);
$label->set_alignment(0, 0.5);
$radio_icons = new GtkRadioButton(NULL, $lang['preference']['toolbar_icons']);
$radio_icons->set_tooltip_text($lang['preference']['toolbar_icons_hint']);
$radio_icons->connect_simple('toggled', 'toolbar_style', 'icons');
$radio_text = new GtkRadioButton($radio_icons, $lang['preference']['toolbar_text']);
$radio_text->set_tooltip_text($lang['preference']['toolbar_text_hint']);
$radio_text->connect_simple('toggled', 'toolbar_style', 'text');
$radio_both = new GtkRadioButton($radio_icons, $lang['preference']['toolbar_both']);
$radio_both->set_tooltip_text($lang['preference']['toolbar_both_hint']);
$radio_both->connect_simple('toggled', 'toolbar_style', 'both');
$radio = 'radio_' . $_config['toolbar_style'];
$$radio->set_active(TRUE);
$vbox->pack_start($label, FALSE, FALSE);
$vbox->pack_start($hbox = new GtkHBox(), FALSE, FALSE);
$hbox->pack_start($radio_icons, TRUE, TRUE);
$hbox->pack_start($radio_text, TRUE, TRUE);
$hbox->pack_start($radio_both, TRUE, TRUE);
$vbox->pack_start(new GtkHSeparator, FALSE, FALSE);
// Шрифт в списке
$label_text_list = new GtkLabel($lang['preference']['font_list']);
$label_text_list->modify_font(new PangoFontDescription('Bold'));
$label_text_list->set_alignment(0, 0);
$vbox->pack_start($label_text_list, FALSE, FALSE);
$check_text_list = new GtkCheckButton($lang['preference']['system_font']);
$vbox->pack_start($check_text_list, FALSE, FALSE);
$entry_font_select = new GtkEntry();
$entry_font_select->set_editable(FALSE);
$button_font_select = new GtkButton('...');
$button_font_select->set_tooltip_text($lang['preference']['change_font_hint']);
$button_font_select->connect_simple('clicked', 'select_font_window', $entry_font_select);
$check_text_list->connect('toggled', 'check_font', $entry_font_select, $button_font_select);
if (empty($_config['font_list']))
{
$check_text_list->set_active(TRUE);
$entry_font_select->set_sensitive(FALSE);
$button_font_select->set_sensitive(FALSE);
}
else
{
$check_text_list->set_active(FALSE);
$entry_font_select->set_sensitive(TRUE);
$button_font_select->set_sensitive(TRUE);
$entry_font_select->set_text($_config['font_list']);
}
$vbox->pack_start($hbox = new GtkHBox, FALSE, FALSE);
$hbox->pack_start($entry_font_select, TRUE, TRUE);
$hbox->pack_start($button_font_select, FALSE, FALSE);
/**
* Вкладка "Программы"
*/
$vbox = new GtkVBox();
$notebook->append_page($vbox, new GtkLabel($lang['preference']['program']));
// Сравнение файлов
$label_comparison = new GtkLabel();
$label_comparison->set_alignment(0, 0);
$label_comparison->set_markup('<b>' . $lang['preference']['comparison'] . '</b>');
$vbox->pack_start($label_comparison, FALSE, FALSE);
$entry_comparison = new GtkEntry($_config['comparison']);
$entry_comparison->connect('changed', 'change_value', 'comparison');
$btn_comparison = new GtkButton('...');
$btn_comparison->set_tooltip_text($lang['preference']['change_program_hint']);
$btn_comparison->connect_simple('clicked', 'select_file_window', $entry_comparison, 'file');
$vbox->pack_start($hbox_comparison = new GtkHBox(), FALSE, FALSE);
$hbox_comparison->pack_start($entry_comparison, TRUE, TRUE);
$hbox_comparison->pack_start($btn_comparison, FALSE, FALSE);
// Терминал
$label_terminal = new GtkLabel();
$label_terminal->set_alignment(0, 0);
$label_terminal->set_markup('<b>' . $lang['preference']['terminal'] . '</b>');
$vbox->pack_start($label_terminal, FALSE, FALSE);
$entry_terminal = new GtkEntry($_config['terminal']);
$entry_terminal->connect('changed', 'change_value', 'terminal');
$btn_terminal = new GtkButton('...');
$btn_terminal->set_tooltip_text($lang['preference']['change_program_hint']);
$btn_terminal->connect_simple('clicked', 'select_file_window', $entry_terminal, 'file');
$vbox->pack_start($hbox_terminal = new GtkHBox(), FALSE, FALSE);
$hbox_terminal->pack_start($entry_terminal, TRUE, TRUE);
$hbox_terminal->pack_start($btn_terminal, FALSE, FALSE);
$window->add($notebook);
$window->show_all();
Gtk::main();
}
/**
* Отображает диалог выбора файла для экспорта настроек и
* сохраняет текущие настройки в указанный файл.
* @global resource $sqlite
* @global array $lang
*/
function export_settings()
{
global $sqlite, $lang;
$dialog = new GtkFileChooserDialog(
$lang['preference']['export_settings_title'],
NULL,
Gtk::FILE_CHOOSER_ACTION_SAVE,
array(
Gtk::STOCK_OK, Gtk::RESPONSE_OK,
Gtk::STOCK_CANCEL, Gtk::RESPONSE_CANCEL
)
);
$dialog->set_modal(TRUE);
$dialog->set_icon(GdkPixbuf::new_from_file(ICON_PROGRAM));
$dialog->set_current_folder(HOME_DIR);
$dialog->set_current_name('settings.flight-files');
$filter = new GtkFileFilter();
$filter->add_pattern('*.flight-files');
$dialog->set_filter($filter);
$dialog->show_all();
$result = $dialog->run();
if ($result == Gtk::RESPONSE_OK)
{
$filename = $dialog->get_filename();
if (!empty($filename))
{
$explode = explode('.', basename($filename));
$count = count($explode);
$ext = $explode[$count - 1];
if ($count == 1 OR $ext != 'flight-files')
{
$filename .= '.flight-files';
}
$fopen = fopen($filename, 'w+');
fwrite($fopen, "<FlightFiles>\n");
fwrite($fopen, " <version>" . VERSION_PROGRAM . "</version>\n");
fwrite($fopen, " <preference>\n");
$query = sqlite_query($sqlite, "SELECT * FROM config");
while ($sfa = sqlite_fetch_array($query))
{
fwrite($fopen, ' <item key="' . strtolower($sfa['key']) . '">' . $sfa['value'] . "</item>\n");
}
fwrite($fopen, " </preference>\n</FlightFiles>");
fclose($fopen);
}
}
$dialog->destroy();
}
/**
* Импортирует настройки из файла в базу данных программы.
* @global resource $sqlite
* @global array $lang
* @param GtkWindow $window Окно настроек
*/
function import_settings($window)
{
global $sqlite, $lang;
$dialog = new GtkFileChooserDialog(
$lang['preference']['import_settings_title'],
NULL,
Gtk::FILE_CHOOSER_ACTION_OPEN,
array(
Gtk::STOCK_OK, Gtk::RESPONSE_OK,
Gtk::STOCK_CANCEL, Gtk::RESPONSE_CANCEL
)
);
$dialog->set_icon(GdkPixbuf::new_from_file(ICON_PROGRAM));
$dialog->set_modal(TRUE);
$dialog->set_current_folder(HOME_DIR);
$filter = new GtkFileFilter();
$filter->add_pattern('*.flight-files');
$dialog->set_filter($filter);
$dialog->show_all();
$result = $dialog->run();
if ($result == Gtk::RESPONSE_OK)
{
$filename = $dialog->get_filename();
if (!empty($filename))
{
$xml = new SimpleXMLElement(file_get_contents($filename));
// Предупреждаем пользователя, если версии не совпадают
if (VERSION_PROGRAM != $xml->version)
{
$dlg = new GtkDialog(
$lang['alert']['title'],
$dialog,
Gtk::DIALOG_MODAL,
array(
Gtk::STOCK_YES, Gtk::RESPONSE_YES,
Gtk::STOCK_NO, Gtk::RESPONSE_NO
)
);
$dlg->set_icon(GdkPixbuf::new_from_file(ICON_PROGRAM));
$dlg->set_has_separator(FALSE);
$label = new GtkLabel($lang['preference']['versions_not_match']);
$label->set_line_wrap(TRUE);
$hbox = new GtkHBox();
$hbox->pack_start($label, FALSE, FALSE, 20);
$dlg->vbox->add($hbox);
$dlg->show_all();
$result = $dlg->run();
if ($result != Gtk::RESPONSE_YES)
{
$dlg->destroy();
$dialog->destroy();
return FALSE;
}
$dlg->destroy();
}
foreach ($xml->preference->item as $item)
{
$key = strtoupper($item['key']);
sqlite_query($sqlite, "UPDATE config SET value = '$item' WHERE key = '$key'");
}
$dialog->destroy();
$window->destroy();
preference();
}
}
else
{
$dialog->destroy();
}
}
/**
* Изменяет настройки внешнего вида панели инструментов.
* @global resource $sqlite
* @global GtkToolBar $toolbar
* @param string $style Стиль панели инструментов
*/
function toolbar_style($style)
{
global $sqlite, $toolbar;
sqlite_query($sqlite, "UPDATE config SET value = '$style' WHERE key = 'TOOLBAR_STYLE'");
$toolbar->set_property('toolbar-style', $style);
}
/**
* Создаёт окно для выбора файла или папки в зависимости от $type.
* Адрес выбранного файла/папки устанавливается в $entry.
* @global array $lang
* @param GtkEntry $entry Поле ввода, соответствующее данной операции
* @param string $type Может иметь два значения: 'file' - для выбора файла, 'folder' - для выбора папки
*/
function select_file_window($entry, $type)
{
global $lang;
switch ($type)
{
case 'file':
$type = Gtk::FILE_CHOOSER_ACTION_OPEN;
$title = $lang['preference']['select_file'];
break;
case 'folder':
$type = Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER;
$title = $lang['preference']['select_folder'];
break;
}
$dialog = new GtkFileChooserDialog($title, NULL, $type);
$dialog->set_position(Gtk::WIN_POS_CENTER);
$dialog->set_icon(GdkPixbuf::new_from_file(ICON_PROGRAM));
$dialog->set_modal(TRUE);
$dialog->add_button($lang['preference']['button_ok'], Gtk::RESPONSE_OK);
$dialog->add_button($lang['preference']['button_cancel'], Gtk::RESPONSE_CANCEL);
$value = $entry->get_text();
if (!empty($value))
{
$dialog->set_filename($value);
}
$dialog->show_all();
$result = $dialog->run();
if ($result == Gtk::RESPONSE_OK)
{
$entry->set_text($dialog->get_filename());
}
$dialog->destroy();
}
/**
* Записывает в базу данных текст, находящийся
* в данный момент в поле ввода $entry.
* @global resource $sqlite
* @param GtkEntry $entry Поле ввода, соответствующее данной операции
* @param string $param Изменяемый параметр
*/
function change_value($entry, $param)
{
global $sqlite;
$format = $entry->get_text();
$format = sqlite_escape_string($format);
$param = strtoupper($param);
sqlite_query($sqlite, "UPDATE config SET value = '$format' WHERE key = '$param'");
change_dir('none', '', 'all');
}
/**
* Производит запись в базу данных при изменении активного элемента в списке GtkComboBox.
* @global resource $sqlite
* @global array $lang
* @param GtkComboBox $combo Список
* @param string $param Изменяемый параметр
*/
function combo_write($combo, $param)
{
global $sqlite, $lang;
$active = $combo->get_active_text();
$active = str_replace(' ', '.', $active);
$active = str_replace('(', '', $active);
$active = str_replace(')', '', $active);
$explode = explode('.', $active);
$active = $explode[0] . '.' . $explode[1];
$param = strtoupper($param);
sqlite_query($sqlite, "UPDATE config SET value = '$active' WHERE key = '$param'");
}
/**
* Производит запись в базу данных при изменении значения переключателя GtkCheckButton.
* @global resource $sqlite
* @global int $refresh_id_left
* @global int $refresh_id_right
* @global GtkStatusIcon $tray
* @param GtkCheckButton $check Флажок
* @param string $param Изменяемый параметр
*
*/
function check_button_write($check, $param)
{
global $sqlite, $refresh_id_left, $refresh_id_right, $tray;
$value = $check->get_active() ? 'on' : 'off';
$param = strtoupper($param);
sqlite_query($sqlite, "UPDATE config SET value = '$value' WHERE key = '$param'");
if ($param == 'STATUS_ICON')
{
if ($value == 'on')
{
$tray->set_visible(TRUE);
}
else
{
$tray->set_visible(FALSE);
}
}
if ($param == 'PARTBAR_REFRESH')
{
if ($value == 'on')
{
$refresh_id_left = Gtk::timeout_add(1000, 'partbar', 'left');
$refresh_id_right = Gtk::timeout_add(1000, 'partbar', 'right');
}
else
{
Gtk::timeout_remove($refresh_id_left);
Gtk::timeout_remove($refresh_id_right);
}
}
change_dir('none', '', TRUE);
}
/**
* Производит запись в базу данных при изменении значения радиокнопки GtkRadioButton.
* @global resource $sqlite
* @param string $param Изменяемый параметр
* @param string $value Новое значение параметра
*/
function radio_button_write($param, $value)
{
global $sqlite;
$param = strtoupper($param);
sqlite_query($sqlite, "UPDATE config SET value = '$value' WHERE key = '$param'");
change_dir('none');
}
/**
* Создаёт диалог GtkFontSelectionDialog и производит запись выбранного шрифта в базу данных.
* @global array $cell_renderer
* @global array $lang
* @global array $_config
* @global resource $sqlite
* @param GtkEntry $entry Поле ввода для названия шрифта
*/
function select_font_window($entry)
{
global $cell_renderer, $lang, $_config, $sqlite;
$dialog = new GtkFontSelectionDialog($lang['font']['title']);
$dialog->set_position(Gtk::WIN_POS_CENTER_ALWAYS);
$dialog->set_icon(GdkPixbuf::new_from_file(ICON_PROGRAM));
$dialog->set_modal(TRUE);
$dialog->set_preview_text($lang['font']['preview']);
if ($_config['font_list'])
{
$dialog->set_font_name($_config['font_list']);
}
$dialog->show_all();
$result = $dialog->run();
if ($result == Gtk::RESPONSE_OK OR $result == Gtk::RESPONSE_APPLY)
{
$font_name = $dialog->get_font_name();
$entry->set_text($font_name);
sqlite_query($sqlite, "UPDATE config SET value = '$font_name' WHERE key = 'FONT_LIST'");
$cell_renderer['left']->set_property('font', $font_name);
$cell_renderer['right']->set_property('font', $font_name);
change_dir('none', '', TRUE);
}
$dialog->destroy();
}
/**
* Сбрасывает значение шрифта.
* @global array $cell_renderer
* @global reosurce $sqlite
* @param GtkCheckButton $check Флажок "Использовать системный шрифт"
* @param GtkEntry $entry Поле ввода для названия шрифта
* @param GtkButton $button Кнопка "..."
*/
function check_font($check, $entry, $button)
{
global $cell_renderer, $sqlite;
if ($check->get_active() === FALSE)
{
$entry->set_sensitive(TRUE);
$button->set_sensitive(TRUE);
}
else
{
sqlite_query($sqlite, "UPDATE config SET value = '' WHERE key = 'FONT_LIST'");
$entry->set_sensitive(FALSE);
$button->set_sensitive(FALSE);
$entry->set_text('');
$cell_renderer['left']->set_property('font', '');
$cell_renderer['right']->set_property('font', '');
change_dir('none', '', TRUE);
}
}