Add controller for bubbles

This commit is contained in:
Hylke Bons 2011-07-04 03:37:35 +01:00
parent 8980daa265
commit 1d8867ce44
6 changed files with 107 additions and 80 deletions

View file

@ -1,58 +0,0 @@
// SparkleShare, a collaboration and sharing tool.
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
//
// 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/>.
using System;
using System.IO;
using MonoMac.AppKit;
using MonoMac.Foundation;
using MonoMac.Growl;
namespace SparkleShare {
public class SparkleBubble : NSObject {
public string ImagePath;
private string title;
private string subtext;
public SparkleBubble (string title, string subtext)
{
this.title = title;
this.subtext = subtext;
}
public void Show ()
{
InvokeOnMainThread (delegate {
if (ImagePath != null && File.Exists (ImagePath)) {
NSData image_data = NSData.FromFile (ImagePath);
GrowlApplicationBridge.Notify (this.title, this.subtext,
"Start", image_data, 0, false, null);
} else {
GrowlApplicationBridge.Notify (this.title, this.subtext,
"Start", null, 0, false, null);
}
});
}
}
}

View file

@ -0,0 +1,44 @@
// SparkleShare, a collaboration and sharing tool.
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
//
// 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/>.
using System;
namespace SparkleShare {
public class SparkleBubblesController {
public event ShowBubbleEventHandler ShowBubbleEvent;
public delegate void ShowBubbleEventHandler (string title, string subtext, string image_path);
public SparkleBubblesController ()
{
SparkleShare.Controller.ConflictNotificationRaised += delegate {
if (ShowBubbleEvent != null)
ShowBubbleEvent ("Ouch! Mid-air collision!",
"Don't worry, SparkleShare made a copy of each conflicting file.", null);
};
SparkleShare.Controller.NotificationRaised += delegate (string user_name, string user_email,
string message, string folder_path) {
if (ShowBubbleEvent != null)
ShowBubbleEvent (user_name, message,
SparkleShare.Controller.GetAvatar (user_email, 36));
};
}
}
}

View file

@ -0,0 +1,56 @@
// SparkleShare, a collaboration and sharing tool.
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
//
// 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/>.
using System;
using System.IO;
using MonoMac.AppKit;
using MonoMac.Foundation;
using MonoMac.Growl;
namespace SparkleShare {
public class SparkleBubbles : NSObject {
private SparkleBubblesController controller = new SparkleBubblesController ();
public SparkleBubbles ()
{
this.controller.ShowBubbleEvent += delegate(string title, string subtext, string image_path) {
InvokeOnMainThread (delegate {
if (!GrowlApplicationBridge.IsGrowlRunning ()) {
NSApplication.SharedApplication.RequestUserAttention (
NSRequestUserAttentionType.InformationalRequest);
return;
}
if (image_path != null && File.Exists (image_path)) {
NSData image_data = NSData.FromFile (image_path);
GrowlApplicationBridge.Notify (title, subtext,
"Start", image_data, 0, false, null);
} else {
GrowlApplicationBridge.Notify (title, subtext,
"Start", null, 0, false, null);
}
});
};
}
}
}

View file

@ -47,6 +47,7 @@ namespace SparkleShare {
public SparkleEventLog (IntPtr handle) : base (handle) { }
// TODO: Window needs to be made resizable
public SparkleEventLog () : base ()
{
Title = "Recent Events";
@ -67,8 +68,8 @@ namespace SparkleShare {
ContentView.AddSubview (Separator);
this.progress_indicator = new NSthis.progress_indicator () {
Style = NSthis.progress_indicatorStyle.Spinning,
this.progress_indicator = new NSProgressIndicator () {
Style = NSProgressIndicatorStyle.Spinning,
Frame = new RectangleF (this.web_view.Frame.Width / 2 - 10, this.web_view.Frame.Height / 2 + 10, 20, 20)
};
@ -167,10 +168,9 @@ namespace SparkleShare {
if (this.progress_indicator.Superview == ContentView)
this.progress_indicator.RemoveFromSuperview ();
// TODO: still causes some flashes
this.web_view.MainFrame.LoadHtmlString (html, new NSUrl (""));
ContentView.AddSubview (this.web_view);
Update ();
});
}));

View file

@ -87,11 +87,12 @@
</Compile>
<Compile Include="SparkleAbout.cs" />
<Compile Include="SparkleAlert.cs" />
<Compile Include="SparkleBubble.cs" />
<Compile Include="SparkleMacWatcher.cs" />
<Compile Include="SparkleEventLog.cs" />
<Compile Include="SparkleBadger.cs" />
<Compile Include="SparkleEventLogController.cs" />
<Compile Include="SparkleBubbleController.cs" />
<Compile Include="SparkleBubbles.cs" />
</ItemGroup>
<ItemGroup>
<Page Include="MainMenu.xib" />

View file

@ -104,28 +104,12 @@ namespace SparkleShare {
NSApplication.SharedApplication.DockTile.BadgeLabel =
(int.Parse (NSApplication.SharedApplication.DockTile.BadgeLabel) + 1).ToString ();
if (GrowlApplicationBridge.IsGrowlRunning ()) {
SparkleBubble bubble = new SparkleBubble (user_name, message) {
ImagePath = SparkleShare.Controller.GetAvatar (user_email, 36)
};
bubble.Show ();
} else {
NSApplication.SharedApplication.RequestUserAttention (
NSRequestUserAttentionType.InformationalRequest);
}
}
}
});
};
SparkleShare.Controller.ConflictNotificationRaised += delegate {
string title = "Ouch! Mid-air collision!";
string subtext = "Don't worry, SparkleShare made a copy of each conflicting file.";
new SparkleBubble (title, subtext).Show ();
};