3
* GNOME Do is the legal property of its developers. Please refer to the
4
* COPYRIGHT file distributed with this
7
* This program is free software: you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation, either version 3 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program. If not, see <http://www.gnu.org/licenses/>.
31
/// Provides a notification area icon for GNOME Do allowing easy
32
/// access to menus, and a way for GNOME Do to alert users of status changes.
34
public class NotificationIcon : StatusIcon
36
private const int IconSize = 32;
37
private bool updates_available;
38
private Pixbuf normal_icon = IconProvider.PixbufFromIconName
39
("gnome-run", IconSize);
40
private Pixbuf update_icon = IconProvider.PixbufFromIconName
41
("software-update-available", IconSize);
43
public NotificationIcon()
45
FromPixbuf = normal_icon;
46
Tooltip = Catalog.GetString ("Summon GNOME Do with " +
47
Do.Preferences.SummonKeyBinding);
48
Activate += new EventHandler (OnActivateSummonDo);
49
PopupMenu += new PopupMenuHandler (OnTrayIconPopup);
51
if (Do.Preferences.StatusIconVisible)
56
updates_available = false;
57
Addins.NotificationBridge.MessageRequested += SendNotification;
67
if (!updates_available)
72
/// Sets some properties when new plugin updates are available
74
public void NotifyUpdatesAvailable ()
77
Activate -= OnActivateSummonDo;
78
Activate += OnActivateStartUpdates;
79
FromPixbuf = update_icon;
80
if (!updates_available)
81
SendNotification ("GNOME Do",
82
"Updated plugins are available. Click here to update.",
83
"software-update-available");
84
updates_available = true;
87
public static void SendNotification (string message)
89
SendNotification ("GNOME Do", message, null);
92
public static void SendNotification (string title, string message)
94
SendNotification (title, message, null);
97
public static void SendNotification (string title, string message, string icon)
99
Do.NotificationIcon.Show ();
100
GLib.Timeout.Add (1000, delegate {
101
Gtk.Application.Invoke (delegate {
102
ShowNotification (title, message, icon);
108
private static void ShowNotification (string title, string message, string icon)
113
Do.NotificationIcon.GetLocationOnScreen (
114
out screen, out x, out y);
118
msg = new Notification ();
119
} catch (Exception e) {
120
Log.Error ("Could not show notification: " + e.Message);
123
msg.Closed += new EventHandler (OnNotificationClosed);
127
msg.Icon = IconProvider.PixbufFromIconName (icon,
129
msg.Timeout = message.Length / 10 * 1000;
130
if (msg.Timeout > 10000) msg.Timeout = 10000;
131
if (msg.Timeout < 5000) msg.Timeout = 5000;
132
msg.SetGeometryHints (screen, x, y);
136
public void GetLocationOnScreen (out Gdk.Screen screen, out int x, out int y)
139
Gtk.Orientation orien;
141
GetGeometry (out screen, out area, out orien);
142
x = area.X + area.Width / 2;
143
y = area.Y + area.Height - 5;
146
protected void OnActivateSummonDo (object sender, EventArgs args)
148
if (!Do.Controller.IsSummoned)
149
Do.Controller.Summon ();
152
protected void OnActivateStartUpdates (object sender, EventArgs args)
155
PluginManager.InstallAvailableUpdates (true);
156
Activate -= OnActivateStartUpdates;
157
updates_available = false;
158
Pixbuf = normal_icon;
159
SendNotification ("Plugins successfully updated. " +
160
"Please restart GNOME Do.");
161
} catch (Exception e) {
162
Log.Error ("{0}: {1}", e.GetType (), e.Message);
163
//I removed these due to a bug in Mono.Addins, once that bug
164
//is fixed i will reinstate user error reporting.
165
//Log.Debug (e.StackTrace);
166
//SendNotification ("Plugin update failed.");
168
if (!Do.Preferences.StatusIconVisible)
172
protected void OnTrayIconPopup (object o, EventArgs args)
176
StatusIcon.PositionMenu (MainMenu.Instance, out x, out y, out push_in, Handle);
177
MainMenu.Instance.PopupAtPosition (x, y);
180
private static void OnNotificationClosed (object sender, EventArgs args)
182
if (!Do.Preferences.StatusIconVisible)
183
Do.NotificationIcon.Hide ();