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
|
/////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011-2015 by Simon Schneegans
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or (at
// your option) any later version.
//
// This program 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
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
/////////////////////////////////////////////////////////////////////////
namespace GnomePie {
/////////////////////////////////////////////////////////////////////////
/// An appindicator sitting in the panel. It owns the settings menu.
/////////////////////////////////////////////////////////////////////////
public class Indicator : GLib.Object {
/////////////////////////////////////////////////////////////////////
/// The internally used indicator.
/////////////////////////////////////////////////////////////////////
#if HAVE_APPINDICATOR
private AppIndicator.Indicator indicator { private get; private set; }
#else
private Gtk.StatusIcon indicator {private get; private set; }
private Gtk.Menu menu {private get; private set; }
#endif
/////////////////////////////////////////////////////////////////////
/// The Preferences Menu of Gnome-Pie.
/////////////////////////////////////////////////////////////////////
private PreferencesWindow prefs { private get; private set; }
/////////////////////////////////////////////////////////////////////
/// Returns true, when the indicator is currently visible.
/////////////////////////////////////////////////////////////////////
public bool active {
get {
#if HAVE_APPINDICATOR
return indicator.get_status() == AppIndicator.IndicatorStatus.ACTIVE;
#else
return indicator.get_visible();
#endif
}
set {
#if HAVE_APPINDICATOR
if (value) indicator.set_status(AppIndicator.IndicatorStatus.ACTIVE);
else indicator.set_status(AppIndicator.IndicatorStatus.PASSIVE);
#else
indicator.set_visible(value);
#endif
}
}
/////////////////////////////////////////////////////////////////////
/// C'tor, constructs a new Indicator, residing in the user's panel.
/////////////////////////////////////////////////////////////////////
public Indicator() {
string icon = "gnome-pie-symbolic";
var screen = (Gdk.X11.Screen)Gdk.Screen.get_default();
bool gnome_shell = false;
if (screen.get_window_manager_name() == "GNOME Shell") {
icon = "gnome-pie";
gnome_shell = true;
}
#if HAVE_APPINDICATOR
string path = "";
try {
path = GLib.Path.get_dirname(GLib.FileUtils.read_link("/proc/self/exe"))+"/resources";
} catch (GLib.FileError e) {
warning("Failed to get path of executable!");
}
if (gnome_shell) {
if (GLib.File.new_for_path(path).query_exists()) {
this.indicator = new AppIndicator.Indicator("Gnome-Pie", path + "/" + icon + ".svg",
AppIndicator.IndicatorCategory.APPLICATION_STATUS);
} else {
this.indicator = new AppIndicator.Indicator("Gnome-Pie", icon,
AppIndicator.IndicatorCategory.APPLICATION_STATUS);
}
} else {
this.indicator = new AppIndicator.Indicator.with_path("Gnome-Pie", icon,
AppIndicator.IndicatorCategory.APPLICATION_STATUS, path);
}
var menu = new Gtk.Menu();
#else
this.indicator = new Gtk.StatusIcon();
try {
var file = GLib.File.new_for_path(GLib.Path.build_filename(
GLib.Path.get_dirname(GLib.FileUtils.read_link("/proc/self/exe"))+"/resources",
icon + ".svg"
));
if (!file.query_exists())
this.indicator.set_from_icon_name(icon);
else
this.indicator.set_from_file(file.get_path());
} catch (GLib.FileError e) {
warning("Failed to get path of executable!");
this.indicator.set_from_icon_name(icon);
}
this.menu = new Gtk.Menu();
var menu = this.menu;
#endif
this.prefs = new PreferencesWindow();
// preferences item
var item = new Gtk.ImageMenuItem.with_mnemonic(_("_Preferences"));
item.activate.connect(() => {
this.prefs.show();
});
item.show();
menu.append(item);
// about item
item = new Gtk.ImageMenuItem.with_mnemonic(_("_About"));
item.show();
item.activate.connect(() => {
var about = new AboutWindow();
about.run();
about.destroy();
});
menu.append(item);
// separator
var sepa = new Gtk.SeparatorMenuItem();
sepa.show();
menu.append(sepa);
// quit item
item = new Gtk.ImageMenuItem.with_mnemonic(_("_Quit"));
item.activate.connect(()=>{
GLib.Application.get_default().release();
});
item.show();
menu.append(item);
#if HAVE_APPINDICATOR
this.indicator.set_menu(menu);
#else
this.indicator.popup_menu.connect((btn, time) => {
this.menu.popup(null, null, null, btn, time);
});
#endif
this.active = Config.global.show_indicator;
Config.global.notify["show-indicator"].connect((s, p) => {
this.active = Config.global.show_indicator;
});
}
/////////////////////////////////////////////////////////////////////
/// Shows the preferences menu.
/////////////////////////////////////////////////////////////////////
public void show_preferences() {
this.prefs.show();
}
}
}
|