2
This file is part of LoggerOuter.
4
LoggerOuter is free software: you can redistribute it and/or modify it under the
5
terms of the GNU Lesser General Public License as published by the Free Software
6
Foundation, either version 3 of the License, or (at your option) any later
9
LoggerOuter is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
12
License for more details.
14
You should have received a copy of the GNU Lessel General Public License
15
along with LoggerOuter. If not, see <https://www.gnu.org/licenses/>.
18
public struct LO.ActionEntry {
19
string group; /*< The "[Group]" heading*/
20
string? text; /*< the "Text=foo bar" key*/
21
string exec; /*< the "Exec=baz buz" key*/
22
string? icon; /*< icon name or path. "Icon="*/
23
bool icon_is_path; /*< wether or not "icon" is a path or an icon name. */
25
public string to_string () {
26
string outstr = @"[$(group)]\nText=";
30
outstr += @"\nExec=$(exec)\n";
32
outstr += @"Icon=$(icon)\n";
36
outstr += @"# Icon is path: $(icon_is_path)\n";
41
public struct LO.Action {
42
Gee.ArrayList<LO.ActionEntry?> entries;
43
KeyFile? actions_key_file;
47
// Standard way of loadin settings file
48
public Action.from_xdg () {
49
actions_key_file = new KeyFile ();
52
actions_key_file.load_from_file (LO_XDG_ACTIONS_PATH, GLib.KeyFileFlags.NONE);
53
} catch (GLib.FileError e) {
54
string message = "ERROR: Could not load configuration file.\n" +
55
"Have you created one? See \"--help\" for more information.\n" +
56
@"Error: $(e.message)\n";
57
GLib.stderr.printf (message);
58
LO.prensent_dialog (message);
59
GLib.Process.exit (33);
60
} catch (GLib.KeyFileError e) {
61
string message = "ERROR: Could not load configuration file.\n" +
62
" ini file error.\n" +
63
@"Error: $(e.message)\n";
64
GLib.stderr.printf (message);
65
LO.prensent_dialog (message);
66
GLib.Process.exit (34);
72
// For use with --config_file
73
public Action.from_file (string actions_path) {
75
actions_key_file = new KeyFile ();
77
this.actions_file = LO.resolve_path (actions_path);
80
actions_key_file.load_from_file (actions_file, GLib.KeyFileFlags.NONE);
81
} catch (GLib.FileError e) {
82
string message = @"ERROR: Could not open file \"$(actions_file)\":\n" +
84
GLib.stderr.printf (message);
85
prensent_dialog (message);
86
GLib.Process.exit (37);
87
} catch (GLib.KeyFileError e) {
89
@"ERROR: Something went wrong whilst loading the key-file \"$(actions_file)\":\n" +
91
GLib.stderr.printf (message);
92
prensent_dialog (message);
93
GLib.Process.exit (38);
100
void parse_keyfile ()
101
requires (this.actions_key_file != null) {
102
/* The keyfile stucture is like this:
103
* Each action has it's own group, the groups name is the name of the action
105
* the key "exec" is used what is run when the button in pressed.
110
* Text=Logout session
113
string[] group_list = actions_key_file.get_groups ();
115
if (group_list.length < 1) { // No groups
116
string message = @"ERROR: The keyfile $(this.actions_file) is empty.\n" +
117
"Please add actions to the keyfile (ini-file).\n";
118
GLib.stderr.printf (message);
119
LO.prensent_dialog (message);
120
GLib.Process.exit (35);
123
entries = new Gee.ArrayList<LO.ActionEntry?> ();
125
foreach (string _group in group_list) {
126
string? _text = null;
127
string? _icon = null;
129
if (actions_key_file.has_key (_group, "Text")) {
130
_text = actions_key_file.get_string (_group, "Text");
132
string? _exec = actions_key_file.get_string (_group, "Exec");
133
if (actions_key_file.has_key (_group, "Icon")) {
134
_icon = actions_key_file.get_string (_group, "Icon");
136
bool _icon_is_path = false;
138
if (str_starts_with (_icon, "file://")) {
139
_icon_is_path = true;
142
var entry = LO.ActionEntry () {
147
icon_is_path = _icon_is_path
150
} catch (GLib.KeyFileError e) {
151
string message = "ERROR: An error has occurred whilst parsing the key-file:\n" +
152
@"Error: $(e.message)\n";
153
prensent_dialog (message);
154
stderr.printf (message);
155
GLib.Process.exit (36);
160
public Gee.ArrayList<LO.ActionEntry?>? get_entries () {
161
if (this.entries == null) {
162
GLib.stderr.printf ("ERROR: enteties list does not seem to be initialised!\n");