/loggerouter/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/loggerouter/trunk
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
/*
   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.ActionButton : Gtk.Button {
// This whole class is cursed. :-)
  Gtk.Image icon;
  Gtk.Box box;
  Gtk.Label widget_label;

  string? exec_action;

  string _button_text;

  void run_action () {

    string[]? argv = null;
    string[] envp = Environ.get ();
    Pid pid;
    try {
      GLib.Shell.parse_argv (exec_action, out argv);

      GLib.Process.spawn_async (null,  argv, envp,
                                GLib.SpawnFlags.DO_NOT_REAP_CHILD | GLib.SpawnFlags.SEARCH_PATH_FROM_ENVP ,
                                null, out pid);
      
    } catch (GLib.SpawnError e) {
      LO.present_dialog ("ERROR: %s\n", e.message);
    } catch (GLib.ShellError e) {
      LO.present_dialog ("ERROR: %s\n", e.message);
    }
    app.try_quit ();
  }


  public ActionButton (ActionEntry action) {
    this.box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0) {
      homogeneous = false,
    };
    
    if (action.icon != null) {
      this.icon = new Gtk.Image () {
        vexpand = false,
        hexpand = false,
        pixel_size = 28,
        width_request = 28,
        height_request = 28,
      };
      string _icon_name;
      if (!action.icon_is_path) {
        icon.icon_name = action.icon;
      } else {
        _icon_name = strip_prelude_of_path (action.icon);
        this.icon.set_from_file (_icon_name);
      }
      box.append (icon);
    }

    if (action.text != null) {
      _button_text = action.text;
    } else {
      _button_text = action.group;
    }

    this.exec_action = action.exec;

    this.widget_label = new Gtk.Label (_button_text) {
      hexpand = true,
      vexpand = true,
      halign = Gtk.Align.CENTER,
      valign = Gtk.Align.CENTER,
      margin_end = 28,
    };
    box.append (widget_label);
    this.set_child (this.box);

    this.clicked.connect (() => {
      var timer = new LO.Timer (this._button_text, 15, (e) => {
        if (e == LO.Timer.ExitCode.OK) {
            this.run_action ();
        }
      });
      timer.set_transient_for (app.get_active_window ());
      timer.show ();
    });

  }

  construct {
    this.focusable = true;
  }

}