Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into windows
Browse files Browse the repository at this point in the history
  • Loading branch information
wimh committed Nov 14, 2011
2 parents e913888 + abee4da commit a3899d6
Show file tree
Hide file tree
Showing 34 changed files with 676 additions and 400 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ SparkleLib/windows/GlobalAssemblyInfo.cs
SparkleShare/sparkleshare
po/sparkleshare.pot
SparkleShare/Nautilus/sparkleshare-nautilus-extension.py
SparkleShare/Nautilus/sparkleshare-nautilus3-extension.py
gnome-doc-utils.make
/sparkleshare-*
data/plugins/*.xml
Expand Down
21 changes: 21 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
0.4.0 for Linux and Mac (Sun Nov 12 2011):
Hylke: It has been a while since the last release. Since so many
things changed, and it being (softly) incompatible with 0.2, I decided
to call it 0.4. Here are the most important improvements:

- Support OS X Lion
- Revamped "Add Hosted Project..." dialog
- First run tutorial
- Clicking notifications opens the event log
- Support for organisation/host plugins
- Adding empty folders now works
- More useful error reporting
- Progress bar on the initial sync, and a button to cancel
- Replace IRC by a custom protocol as the default notification system
- Many many fixes for crashes and bugs

Travis:
- Nautilus 3.x plugin
- Bugfixes


0.2.5 for Linux and Mac (Mon Jul 25 2011):

Hylke: Reimplement notes to be less buggy and backend independent. Polish
Expand Down
9 changes: 5 additions & 4 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Just double-click the SparkleShare bundle.

# Build on Mac

Install Xcode, the Mono Framework, MonoDevelop and the MonoMac plugin (you find it in Add-in Manager).
Install Xcode, the Mono Framework, MonoDevelop and the MonoMac plugin (you can find it in MonoDevelop => Add-in Manager).

You may need to adjust some environment variables to let the build environment tools find mono:

Expand All @@ -108,10 +108,11 @@ Start the first part of the build:
Now that you have compiled the libraries, open 'SparkleShare/Mac/SparkleShare.sln' in
MonoDevelop and start the build.

To create the SparkleShare.app, select Project from the menu bar
and click "Create Mac Installer..." Save the SparkleShare.app somewhere.
To create the SparkleShare.app, make sure the project is focused and select Project from the menu bar
and click "Create Mac Installer...". Make sure to select "Don't link assemblies".

Paste the contents of the following file in SparkleShare.app/Contents/MonoBundle/config:
Save the SparkleShare.app somewhere. Paste the contents of
the following file in SparkleShare.app/Contents/MonoBundle/config:
https://raw.github.com/gist/1aeffa61bac73fc08eca/0c0f09ef9e36864c35f34fd5e8bf4f99886be193/gistfile1.txt

Copy /Library/Frameworks/Mono.framework/Versions/Current/lib/libintl.dylib
Expand Down
32 changes: 19 additions & 13 deletions SparkleLib/Git/SparkleRepoGit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,31 @@ public SparkleRepoGit (string path, SparkleBackend backend) :
}


private string identifier = null;

public override string Identifier {
get {
if (string.IsNullOrEmpty (this.identifier)) {

// Because git computes a hash based on content,
// author, and timestamp; it is unique enough to
// use the hash of the first commit as an identifier
// for our folder
SparkleGit git = new SparkleGit (LocalPath, "rev-list --reverse HEAD");
git.Start ();
// Because git computes a hash based on content,
// author, and timestamp; it is unique enough to
// use the hash of the first commit as an identifier
// for our folder
SparkleGit git = new SparkleGit (LocalPath, "rev-list --reverse HEAD");
git.Start ();

// Reading the standard output HAS to go before
// WaitForExit, or it will hang forever on output > 4096 bytes
string output = git.StandardOutput.ReadToEnd ();
git.WaitForExit ();
// Reading the standard output HAS to go before
// WaitForExit, or it will hang forever on output > 4096 bytes
string output = git.StandardOutput.ReadToEnd ();
git.WaitForExit ();

if (output.Length < 40)
return null;
if (output.Length < 40)
return null;

this.identifier = output.Substring (0, 40);
}

return output.Substring (0, 40);
return this.identifier;
}
}

Expand Down
32 changes: 18 additions & 14 deletions SparkleLib/SparkleConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,15 @@ private void CreateInitialConfig ()
if (string.IsNullOrEmpty (user_name))
user_name = "Unknown";

TextWriter writer = new StreamWriter (FullPath);
string n = Environment.NewLine;

writer.Write ("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + n +
"<sparkleshare>" + n +
" <user>" + n +
" <name>" + user_name + "</name>" + n +
" <email>Unknown</email>" + n +
" </user>" + n +
"</sparkleshare>");
writer.Close ();
string n = Environment.NewLine;
File.WriteAllText (FullPath,
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + n +
"<sparkleshare>" + n +
" <user>" + n +
" <name>" + user_name + "</name>" + n +
" <email>Unknown</email>" + n +
" </user>" + n +
"</sparkleshare>");

SparkleHelpers.DebugInfo ("Config", "Created \"" + FullPath + "\"");
}
Expand Down Expand Up @@ -276,10 +274,16 @@ public List<string> HostsWithUsername {
List<string> hosts = new List<string> ();

foreach (XmlNode node_folder in SelectNodes ("/sparkleshare/folder")) {
Uri uri = new Uri (node_folder ["url"].InnerText);
try {
Uri uri = new Uri (node_folder ["url"].InnerText);

if (uri.UserInfo != "git" && !hosts.Contains (uri.UserInfo + "@" + uri.Host))
hosts.Add (uri.UserInfo + "@" + uri.Host);

if ("git" != uri.UserInfo && !hosts.Contains (uri.UserInfo + "@" + uri.Host))
hosts.Add (uri.UserInfo + "@" + uri.Host);
} catch (UriFormatException) {
SparkleHelpers.DebugInfo ("Config",
"Ignoring badly formatted URI: " + node_folder ["url"].InnerText);
}
}

return hosts;
Expand Down
121 changes: 88 additions & 33 deletions SparkleLib/SparkleListenerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@


using System;
using System.Collections;
using System.Collections.Generic;
using System.Timers;
using System.Linq;

namespace SparkleLib {

Expand Down Expand Up @@ -50,7 +52,7 @@ public static SparkleListenerBase CreateListener (string folder_name, string fol
// don't have your own. All data needed to connect is hashed and
// we don't store any personal information ever

uri = "tcp://204.62.14.135:1986"; // TODO: announcements.sparkleshare.org
uri = "tcp://notifications.sparkleshare.org:1986";
}

Uri announce_uri = new Uri (uri);
Expand Down Expand Up @@ -80,7 +82,7 @@ public static SparkleListenerBase CreateListener (string folder_name, string fol
listeners.Add (new SparkleListenerTcp (announce_uri, folder_identifier));
break;
}

SparkleHelpers.DebugInfo ("ListenerFactory", "Issued new listener for " + announce_uri);
return (SparkleListenerBase) listeners [listeners.Count - 1];
}
Expand All @@ -104,20 +106,21 @@ public abstract class SparkleListenerBase {
public event AnnouncementEventHandler Announcement;
public delegate void AnnouncementEventHandler (SparkleAnnouncement announcement);


public abstract void Connect ();
public abstract void Announce (SparkleAnnouncement announcent);
public abstract void AlsoListenTo (string folder_identifier);
public abstract bool IsConnected { get; }


protected List<string> channels = new List<string> ();
protected List<SparkleAnnouncement> queue_up = new List<SparkleAnnouncement> ();
protected List<SparkleAnnouncement> queue_down = new List<SparkleAnnouncement> ();
protected List<string> channels = new List<string> ();
protected Dictionary<string,List<SparkleAnnouncement>> recent_announcements = new Dictionary<string, List<SparkleAnnouncement>> ();
protected int max_recent_announcements = 10;
protected Dictionary<string, SparkleAnnouncement> queue_up = new Dictionary<string, SparkleAnnouncement> ();
protected Dictionary<string,SparkleAnnouncement> queue_down = new Dictionary<string, SparkleAnnouncement> ();
protected bool is_connecting;
protected Uri server;
protected Timer reconnect_timer = new Timer { Interval = 60 * 1000, Enabled = true };


public SparkleListenerBase (Uri server, string folder_identifier)
{
this.server = server;
Expand All @@ -133,30 +136,23 @@ public SparkleListenerBase (Uri server, string folder_identifier)

public void AnnounceBase (SparkleAnnouncement announcement)
{
if (IsConnected) {
SparkleHelpers.DebugInfo ("Listener",
"Announcing to " + announcement.FolderIdentifier + " on " + this.server);

Announce (announcement);
if (!this.IsRecentAnnounement (announcement)) {
if (IsConnected) {
SparkleHelpers.DebugInfo ("Listener",
"Announcing message " + announcement.Message + " to " + announcement.FolderIdentifier + " on " + this.server);

Announce (announcement);
this.AddRecentAnnouncement (announcement);
} else {
SparkleHelpers.DebugInfo ("Listener", "Can't send message to " + this.server + ". Queuing message");
this.queue_up [announcement.FolderIdentifier] = announcement;
}

} else {
SparkleHelpers.DebugInfo ("Listener", "Not connected to " + this.server + ". Queuing message");
this.queue_up.Add (announcement);
}
}


public string NextQueueDownMessage (string folder_identifier)
{
foreach (SparkleAnnouncement announcement in this.queue_down.GetRange (0, this.queue_down.Count)) {
if (announcement.FolderIdentifier.Equals (folder_identifier)) {
string message = announcement.Message;
this.queue_down.Remove (announcement);
return message;
}
SparkleHelpers.DebugInfo ("Listener",
"Already processed message " + announcement.Message + " to " + announcement.FolderIdentifier + " from " + this.server);
}

return null;
}


Expand All @@ -169,25 +165,27 @@ public void Reconnect ()

public void OnConnected ()
{
SparkleHelpers.DebugInfo ("Listener", "Connected to " + Server);
SparkleHelpers.DebugInfo ("Listener", "Listening for announcements on " + Server);

if (Connected != null)
Connected ();

if (this.queue_up.Count > 0) {
SparkleHelpers.DebugInfo ("Listener", "Delivering " + this.queue_up.Count + " queued messages...");

foreach (SparkleAnnouncement announcement in this.queue_up.GetRange(0, this.queue_up.Count)) {
foreach (KeyValuePair<string, SparkleAnnouncement> item in this.queue_up) {
SparkleAnnouncement announcement = item.Value;
AnnounceBase (announcement);
this.queue_up.Remove (announcement);
}

this.queue_down.Clear ();
}
}


public void OnDisconnected ()
{
SparkleHelpers.DebugInfo ("Listener", "Disonnected from " + Server);
SparkleHelpers.DebugInfo ("Listener", "Signal of " + Server + " lost");

if (Disconnected != null)
Disconnected ();
Expand All @@ -196,15 +194,71 @@ public void OnDisconnected ()

public void OnAnnouncement (SparkleAnnouncement announcement)
{
SparkleHelpers.DebugInfo ("Listener", "Got message from " + announcement.FolderIdentifier + " on " + this.server);
SparkleHelpers.DebugInfo ("Listener",
"Got message " + announcement.Message + " from " + announcement.FolderIdentifier + " on " + this.server);

this.queue_down.Add (announcement);
if (IsRecentAnnounement(announcement) ){
SparkleHelpers.DebugInfo ("Listener",
"Ignoring previously processed message " + announcement.Message +
" from " + announcement.FolderIdentifier + " on " + this.server);

return;
}

SparkleHelpers.DebugInfo ("Listener",
"Processing message " + announcement.Message + " from " + announcement.FolderIdentifier + " on " + this.server);

AddRecentAnnouncement (announcement);
this.queue_down [announcement.FolderIdentifier] = announcement;

if (Announcement != null)
Announcement (announcement);
}


private bool IsRecentAnnounement (SparkleAnnouncement announcement)
{
if (!HasRecentAnnouncements (announcement.FolderIdentifier)) {
return false;

} else {
foreach (SparkleAnnouncement recent_announcement in GetRecentAnnouncements (announcement.FolderIdentifier)) {
if (recent_announcement.Message.Equals (announcement.Message))
return true;
}

return false;
}
}


private List<SparkleAnnouncement> GetRecentAnnouncements (string folder_identifier)
{
if (!this.recent_announcements.ContainsKey (folder_identifier))
this.recent_announcements [folder_identifier] = new List<SparkleAnnouncement> ();

return (List<SparkleAnnouncement>) this.recent_announcements [folder_identifier];
}


private void AddRecentAnnouncement (SparkleAnnouncement announcement)
{
List<SparkleAnnouncement> recent_announcements = this.GetRecentAnnouncements (announcement.FolderIdentifier);

if (!IsRecentAnnounement (announcement))
recent_announcements.Add (announcement);

if (recent_announcements.Count > this.max_recent_announcements)
recent_announcements.RemoveRange (0, (recent_announcements.Count - this.max_recent_announcements));
}


private bool HasRecentAnnouncements (string folder_identifier)
{
return this.recent_announcements.ContainsKey (folder_identifier);
}


public virtual void Dispose ()
{
this.reconnect_timer.Dispose ();
Expand All @@ -225,3 +279,4 @@ public bool IsConnecting {
}
}
}

Loading

0 comments on commit a3899d6

Please sign in to comment.