Skip to content
API Documentation
BastionGuard™
MiscBox.vala
Go to the documentation of this file.
1/*
2 * MiscBox.vala
3 */
4
5using Gtk;
6using Gee;
7
13using TeeJee.System;
14using TeeJee.Misc;
15
16class MiscBox : Gtk.Box{
17
18 private Gtk.Window parent_window;
19 private bool restore_mode = false;
20
21 public MiscBox (Gtk.Window _parent_window, bool _restore_mode) {
22
23 log_debug("MiscBox: MiscBox()");
24 GLib.Object(orientation: Gtk.Orientation.VERTICAL, spacing: 6);
25 parent_window = _parent_window;
26 margin_top = 12;
27 margin_bottom = 12;
28 margin_start = 12;
29 margin_end = 12;
30 restore_mode = _restore_mode;
32 refresh();
33 log_debug("MiscBox: MiscBox(): exit");
34 }
35
36 private void init_date_format_option(Gtk.Box box){
37
38 log_debug("MiscBox: init_date_format_option()");
39 add_label_header(box, _("Date Format"), false);
40
41 var hbox = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 6);
42 box.append(hbox);
43
44 var combo = new Gtk.ComboBoxText();
45 combo.hexpand = true;
46 hbox.append(combo);
47
48 var entry = new Gtk.Entry();
49 entry.hexpand = true;
50 hbox.append(entry);
51
52 var now = new DateTime.local(2019, 8, 11, 20, 25, 43);
53 string[] formats = {
54 "",
55 "%Y-%m-%d %H:%M:%S",
56 "%Y-%m-%d %I:%M %p",
57 "%d %b %Y %I:%M %p",
58 "%Y %b %d, %I:%M %p",
59 "%c"
60 };
61
62 int active = 0;
63 for (int i = 0; i < formats.length; i++){
64 string fmt = formats[i];
65 string preview = (fmt.length == 0) ? _("Custom") : now.format(fmt);
66 combo.append_text(preview);
67 if (App.date_format == fmt){
68 active = i;
69 }
70 }
71 combo.active = active;
72
73 combo.changed.connect(() => {
74 int idx = combo.get_active();
75 if ((idx < 0) || (idx >= formats.length)){
76 return;
77 }
78 string fmt = (formats[idx].length > 0) ? formats[idx] : Main.date_format_default;
79 entry.text = fmt;
80 entry.sensitive = (formats[idx].length == 0);
81 App.date_format = fmt;
82 });
83
84 entry.text = App.date_format;
85 entry.sensitive = (combo.get_active() == 0);
86
87 entry.notify["has-focus"].connect(() => {
88 if (!entry.has_focus){
89 App.date_format = entry.text;
90 log_debug("saved date_format: %s".printf(App.date_format));
91 }
92 });
93
94 show();
95 log_debug("MiscBox: init_date_format_option(): exit");
96 }
97
98 public void refresh(){
99 show();
100 }
101}
Main App
#define _(s)
Definition Main.vala:39
string date_format
Definition Main.vala:130
const string date_format_default
Definition Main.vala:131
bool restore_mode
Definition MiscBox.vala:19
Gtk.Window parent_window
Definition MiscBox.vala:18
void init_date_format_option(Gtk.Box box)
Definition MiscBox.vala:36
MiscBox(Gtk.Window _parent_window, bool _restore_mode)
Definition MiscBox.vala:21
void refresh()
Definition MiscBox.vala:98
void log_debug(string message)