3
This file is part of LoggerOuter.
5
LoggerOuter is free software: you can redistribute it and/or modify it under the
6
terms of the GNU Lesser General Public License as published by the Free Software
7
Foundation, either version 3 of the License, or (at your option) any later
10
LoggerOuter is distributed in the hope that it will be useful, but WITHOUT
11
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
13
License for more details.
15
You should have received a copy of the GNU Lessel General Public License
16
along with LoggerOuter. If not, see <https://www.gnu.org/licenses/>.
19
public class LO.App : Gtk.Application {
22
LO.Settings settings = LO.Settings.get_instance ();
23
public Gtk.Window? window;
24
Gtk.ListBox? list_box;
26
public bool can_quit = true;
28
public void try_quit () {
36
GLib.OptionEntry[] options = {
37
{"version", 'v', OptionFlags.NONE, OptionArg.NONE, null,
38
"Display version number.", null},
40
{"config", 0, OptionFlags.NONE, OptionArg.FILENAME, null,
41
"Path to configuration file." , "<path/to/config.ini>"},
43
{"actions", 0, OptionFlags.NONE, OptionArg.FILENAME, null,
44
"Path to actions file." , "<path/to/actions.ini>"},
46
{"help-actions", 0, OptionFlags.NONE, OptionArg.NONE, null,
47
"Print extra information about action configuration files.", null},
49
{"help-config", 0, OptionFlags.NONE, OptionArg.NONE, null,
50
"Print information on how to configure app specific things.", null},
52
{null, 0, 0, 0, null, null},
54
application_id = APP_NAME;
55
add_main_option_entries (options);
59
public override int handle_local_options (VariantDict options) {
60
if (options.contains ("version")) {
61
print (get_app_version ());
64
if (options.contains ("help-actions")) {
65
print_actions_help ();
69
if (options.contains ("help-config")) {
74
if (options.contains ("actions")) {
75
opts.actions_path = options.lookup_value ("actions", null).get_bytestring ();
78
if (options.contains ("config")) {
79
opts.config_path = options.lookup_value ("config", null).get_bytestring ();
82
return -1; // Let the base class handle the rest.
86
public override void activate () {
88
window = new Gtk.ApplicationWindow (this) {
89
title = "LoggerOuter",
95
var _action = new GLib.SimpleAction ("quit", null);
97
_action.activate.connect (() => {this.quit ();} );
98
this.add_action (_action);
99
this.set_accels_for_action ("app.quit", {"Escape","q",null});
101
if (opts.actions_path != null) {
102
actions = LO.Action.from_file (opts.actions_path);
104
actions = LO.Action.from_xdg ();
107
if (opts.config_path != null) {
108
settings.load_settings (opts.config_path);
110
settings.load_setting_from_xdg ();
113
list_box = new Gtk.ListBox () {
118
show_separators = true,
119
activate_on_single_click = true,
121
list_box.row_activated.connect ((row) => {
122
row.child.activate ();
125
if (opts.config_path != null) {
126
settings.load_settings (opts.config_path);
128
settings.load_setting_from_xdg ();
131
Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = settings.dark_theme;
133
add_buttons (actions.get_entries ());
135
window.set_child (list_box);
137
window.set_focus (list_box.get_selected_row ());
142
void add_buttons (Gee.ArrayList<LO.ActionEntry?> list) {
143
foreach (ActionEntry entry in list) {
144
var btn = new LO.ActionButton (entry);
145
this.list_box.append (btn);
149
void print_actions_help () {
151
Help about how to configure actions for %s.
153
The standard locaton is "$XDG_USER_HOME/loggerouter/actions.ini", but
154
you can specify your own location using the --actions= option.
156
Each "group" in the ini file will be displayed like a button in the application,
157
and will take the name of the group. Thus it is of great importance that the group
158
is unique, as groups of the same name will be merged.
160
Each group must have an "Exec=" key.
162
There is an optional "Text=" key that can be set.
164
An optional "Icon=" key can be set. Normaly this uses the GTK icon handling mechanism,
165
but you can prefix with "file://" and the app will try to use that image intead.
167
An example of how this may work is as follows:
171
Icon=system-log-out-symbolic
173
GLib.stdout.printf (message, opts.exec_name);
176
void print_config_help () {
178
Help for how to configure %s.
180
The standard location is "$XDG_USER_HOME/loggerouter/config.ini", but
181
you can specify your own location using the --config= option.
183
The ini file has only one section: [Main]
186
DarkTheme= # Do you want to use a dark theme?
188
GLib.stdout.printf (message, opts.exec_name);