summaryrefslogtreecommitdiff
path: root/src/utils.vala
blob: 7999f620e962033c890d97500d6a3b95e4d1901e (plain) (blame)
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
namespace JadupcSupport
{
	namespace utils
	{
		internal string get_message_icon(Gtk.MessageType type)
		{
			switch (type) {
			case ERROR:
				return "dialog-error";
			case INFO:
				return "dialog-information";
			case QUESTION:
				return "dialog-question";
			case WARNING:
				return "dialog-warning";
			default:
				return "image-missing";
			}
		}

// This function takes a visible Gtk Widget and recursively realizes
// the childrens as Gtk whines on key event if even one
// ((great)grand)children widget is not realized...
		internal void realize_all(Gtk.Container container)
		{
			if (!container.get_realized())
				container.realize();

			container.foreach((widget) => {
				if (widget is Gtk.Container) realize_all(widget as Gtk.Container);
				else if (!widget.get_realized()) widget.realize();
			});
		}

		internal string strret(int ret, string[] retstrs = {})
		{
			if (0 < ret <= 64 && !(ret == 11 || ret == 28 || 3 <= ret <= 8) || 128 < ret < 256)
				return strsignal(ret - ((128 < ret < 256)?128:0));
			else if (ret % 256 == 0)
				return _("Process returned %d").printf(ret / 256);
			return _("Exit status - %d (unknown)").printf(ret);
		}
	}
}