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
|
/*
This file is part of LoggerOuter.
LoggerOuter is free software: you can redistribute it and/or modify it under the
terms of the GNU Lesser General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
LoggerOuter is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lessel General Public License
along with LoggerOuter. If not, see <https://www.gnu.org/licenses/>.
*/
public class LO.App : Gtk.Application {
LO.Action actions;
LO.Settings settings = LO.Settings.get_instance ();
public Gtk.Window? window;
Gtk.ListBox? list_box;
public bool can_quit = true;
public void try_quit () {
if (can_quit) {
app.quit ();
}
}
construct {
GLib.OptionEntry[] options = {
{"version", 'v', OptionFlags.NONE, OptionArg.NONE, null,
"Display version number.", null},
{"config", 0, OptionFlags.NONE, OptionArg.FILENAME, null,
"Path to configuration file." , "<path/to/config.ini>"},
{"actions", 0, OptionFlags.NONE, OptionArg.FILENAME, null,
"Path to actions file." , "<path/to/actions.ini>"},
{"help-actions", 0, OptionFlags.NONE, OptionArg.NONE, null,
"Print extra information about action configuration files.", null},
{"help-config", 0, OptionFlags.NONE, OptionArg.NONE, null,
"Print information on how to configure app specific things.", null},
{null, 0, 0, 0, null, null},
};
application_id = APP_NAME;
add_main_option_entries (options);
}
public override int handle_local_options (VariantDict options) {
if (options.contains ("version")) {
print (get_app_version ());
return 0;
}
if (options.contains ("help-actions")) {
print_actions_help ();
return 0;
}
if (options.contains ("help-config")) {
print_config_help ();
return 0;
}
if (options.contains ("actions")) {
opts.actions_path = options.lookup_value ("actions", null).get_bytestring ();
}
if (options.contains ("config")) {
opts.config_path = options.lookup_value ("config", null).get_bytestring ();
}
return -1; // Let the base class handle the rest.
}
public override void activate () {
window = new Gtk.ApplicationWindow (this) {
title = "LoggerOuter",
width_request = 500,
height_request = 500,
resizable = false,
};
var _action = new GLib.SimpleAction ("quit", null);
_action.activate.connect (() => {this.quit ();} );
this.add_action (_action);
this.set_accels_for_action ("app.quit", {"Escape","q",null});
if (opts.actions_path != null) {
actions = LO.Action.from_file (opts.actions_path);
} else {
actions = LO.Action.from_xdg ();
}
if (opts.config_path != null) {
settings.load_settings (opts.config_path);
} else {
settings.load_setting_from_xdg ();
}
list_box = new Gtk.ListBox () {
margin_top = 50,
margin_bottom = 50,
margin_start = 100,
margin_end = 100,
show_separators = true,
activate_on_single_click = true,
};
list_box.row_activated.connect ((row) => {
row.child.activate ();
});
if (opts.config_path != null) {
settings.load_settings (opts.config_path);
} else {
settings.load_setting_from_xdg ();
}
Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = settings.dark_theme;
add_buttons (actions.get_entries ());
window.set_child (list_box);
window.present ();
window.set_focus (list_box.get_selected_row ());
}
void add_buttons (Gee.ArrayList<LO.ActionEntry?> list) {
foreach (ActionEntry entry in list) {
var btn = new LO.ActionButton (entry);
this.list_box.append (btn);
}
}
void print_actions_help () {
string message = """
Help about how to configure actions for %s.
The standard locaton is "$XDG_USER_HOME/loggerouter/actions.ini", but
you can specify your own location using the --actions= option.
Each "group" in the ini file will be displayed like a button in the application,
and will take the name of the group. Thus it is of great importance that the group
is unique, as groups of the same name will be merged.
Each group must have an "Exec=" key.
There is an optional "Text=" key that can be set.
An optional "Icon=" key can be set. Normaly this uses the GTK icon handling mechanism,
but you can prefix with "file://" and the app will try to use that image intead.
An example of how this may work is as follows:
[logout]
Text=Logout session.
Exec=swaymsg exit
Icon=system-log-out-symbolic
""";
GLib.stdout.printf (message, opts.exec_name);
}
void print_config_help () {
string message = """
Help for how to configure %s.
The standard location is "$XDG_USER_HOME/loggerouter/config.ini", but
you can specify your own location using the --config= option.
The ini file has only one section: [Main]
Valid keys are:
DarkTheme= # Do you want to use a dark theme?
""";
GLib.stdout.printf (message, opts.exec_name);
}
}
|