avatars: save to buffer instead of file: less blinking of event log, simpler, so fewer bugs
This commit is contained in:
parent
b467b1937b
commit
350cdbad1f
|
@ -92,6 +92,7 @@ namespace SparkleLib {
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Remote changes found. (" + remote_revision + ")");
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Remote changes found. (" + remote_revision + ")");
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
// FetchNotes ();TODO
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,8 +114,8 @@ namespace SparkleShare {
|
||||||
bubble.Show ();
|
bubble.Show ();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
NSApplication.SharedApplication.RequestUserAttention
|
NSApplication.SharedApplication.RequestUserAttention (
|
||||||
(NSRequestUserAttentionType.InformationalRequest);
|
NSRequestUserAttentionType.InformationalRequest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -286,6 +286,7 @@ namespace SparkleShare {
|
||||||
public string GetHTMLLog (List<SparkleChangeSet> change_sets)
|
public string GetHTMLLog (List<SparkleChangeSet> change_sets)
|
||||||
{
|
{
|
||||||
List <ActivityDay> activity_days = new List <ActivityDay> ();
|
List <ActivityDay> activity_days = new List <ActivityDay> ();
|
||||||
|
List<string> emails = new List<string> ();
|
||||||
|
|
||||||
change_sets.Sort ((x, y) => (x.Timestamp.CompareTo (y.Timestamp)));
|
change_sets.Sort ((x, y) => (x.Timestamp.CompareTo (y.Timestamp)));
|
||||||
change_sets.Reverse ();
|
change_sets.Reverse ();
|
||||||
|
@ -294,7 +295,8 @@ namespace SparkleShare {
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
foreach (SparkleChangeSet change_set in change_sets) {
|
foreach (SparkleChangeSet change_set in change_sets) {
|
||||||
GetAvatar (change_set.UserEmail, 36);
|
if (!emails.Contains (change_set.UserEmail))
|
||||||
|
emails.Add (change_set.UserEmail);
|
||||||
|
|
||||||
bool change_set_inserted = false;
|
bool change_set_inserted = false;
|
||||||
foreach (ActivityDay stored_activity_day in activity_days) {
|
foreach (ActivityDay stored_activity_day in activity_days) {
|
||||||
|
@ -315,6 +317,10 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new Thread (new ThreadStart (delegate {
|
||||||
|
FetchAvatars (emails, 36);
|
||||||
|
})).Start ();
|
||||||
|
|
||||||
string event_log_html = EventLogHTML;
|
string event_log_html = EventLogHTML;
|
||||||
string day_entry_html = DayEntryHTML;
|
string day_entry_html = DayEntryHTML;
|
||||||
string event_entry_html = EventEntryHTML;
|
string event_entry_html = EventEntryHTML;
|
||||||
|
@ -837,63 +843,69 @@ namespace SparkleShare {
|
||||||
|
|
||||||
|
|
||||||
// Gets the avatar for a specific email address and size
|
// Gets the avatar for a specific email address and size
|
||||||
public string GetAvatar (string email, int size)
|
public void FetchAvatars (List<string> emails, int size)
|
||||||
{
|
{
|
||||||
string avatar_path = SparkleHelpers.CombineMore (SparklePaths.SparkleLocalIconPath,
|
List<string> old_avatars = new List<string> ();
|
||||||
size + "x" + size, "status");
|
bool avatar_fetched = false;
|
||||||
|
string avatar_path = SparkleHelpers.CombineMore (
|
||||||
|
SparklePaths.SparkleLocalIconPath, size + "x" + size, "status");
|
||||||
|
|
||||||
string avatar_file_path = Path.Combine (avatar_path, "avatar-" + email);
|
|
||||||
|
|
||||||
if (File.Exists (avatar_file_path)) {
|
|
||||||
FileInfo avatar_info = new FileInfo (avatar_file_path);
|
|
||||||
|
|
||||||
// Delete avatars older than a month and get a new one
|
|
||||||
if (avatar_info.CreationTime < DateTime.Now.AddMonths (-1)) {
|
|
||||||
avatar_info.Delete ();
|
|
||||||
return GetAvatar (email, size);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return avatar_file_path;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
if (!Directory.Exists (avatar_path)) {
|
if (!Directory.Exists (avatar_path)) {
|
||||||
Directory.CreateDirectory (avatar_path);
|
Directory.CreateDirectory (avatar_path);
|
||||||
SparkleHelpers.DebugInfo ("Config", "Created '" + avatar_path + "'");
|
SparkleHelpers.DebugInfo ("Config", "Created '" + avatar_path + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let's try to get the person's gravatar for next time
|
foreach (string email in emails) {
|
||||||
WebClient web_client = new WebClient ();
|
string avatar_file_path = Path.Combine (avatar_path, "avatar-" + email);
|
||||||
Uri uri = new Uri ("https://secure.gravatar.com/avatar/" + GetMD5 (email) +
|
|
||||||
".jpg?s=" + size + "&d=404");
|
|
||||||
|
|
||||||
string tmp_file_path = SparkleHelpers.CombineMore (SparklePaths.SparkleTmpPath, email + size);
|
if (File.Exists (avatar_file_path)) {
|
||||||
|
FileInfo avatar_info = new FileInfo (avatar_file_path);
|
||||||
|
|
||||||
if (!File.Exists (tmp_file_path)) {
|
// Delete avatars older than a month
|
||||||
web_client.DownloadFileAsync (uri, tmp_file_path);
|
if (avatar_info.CreationTime < DateTime.Now.AddMonths (-1)) {
|
||||||
|
avatar_info.Delete ();
|
||||||
|
old_avatars.Add (email);
|
||||||
|
}
|
||||||
|
|
||||||
web_client.DownloadFileCompleted += delegate {
|
} else {
|
||||||
if (File.Exists (avatar_file_path))
|
WebClient client = new WebClient ();
|
||||||
File.Delete (avatar_file_path);
|
string url = "http://gravatar.com/avatar/" + GetMD5 (email) +
|
||||||
|
".jpg?s=" + size + "&d=404";
|
||||||
|
|
||||||
FileInfo tmp_file_info = new FileInfo (tmp_file_path);
|
try {
|
||||||
|
// Fetch the avatar
|
||||||
|
byte [] buffer = client.DownloadData (url);
|
||||||
|
|
||||||
if (tmp_file_info.Length > 255)
|
// Write the avatar data to a
|
||||||
File.Move (tmp_file_path, avatar_file_path);
|
// if not empty
|
||||||
|
if (buffer.Length > 255) {
|
||||||
|
avatar_fetched = true;
|
||||||
|
File.WriteAllBytes (avatar_file_path, buffer);
|
||||||
|
SparkleHelpers.DebugInfo ("Controller", "Fetched gravatar for " + email);
|
||||||
|
}
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Controller", "Fetched gravatar: " + email);
|
} catch (WebException) {
|
||||||
|
SparkleHelpers.DebugInfo ("Controller", "Failed fetching gravatar for " + email);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (AvatarFetched != null)
|
// Fetch new versions of the avatars that we
|
||||||
|
// deleted because they were too old
|
||||||
|
if (old_avatars.Count > 0)
|
||||||
|
FetchAvatars (old_avatars, size);
|
||||||
|
|
||||||
|
if (AvatarFetched != null && avatar_fetched)
|
||||||
AvatarFetched ();
|
AvatarFetched ();
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fall back to a generic icon if there is no gravatar
|
|
||||||
if (File.Exists (avatar_file_path))
|
public string GetAvatar (string email, int size)
|
||||||
|
{
|
||||||
|
string avatar_file_path = SparkleHelpers.CombineMore (
|
||||||
|
SparklePaths.SparkleLocalIconPath, size + "x" + size, "status", "avatar-" + email);
|
||||||
|
|
||||||
return avatar_file_path;
|
return avatar_file_path;
|
||||||
else
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -79,12 +79,12 @@ namespace SparkleShare {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SparkleBubble bubble = new SparkleBubble (user_name, message);
|
SparkleBubble bubble = new SparkleBubble (user_name, message);
|
||||||
string avatar_file_path = SparkleShare.Controller.GetAvatar (user_email, 32);
|
string avatar_file_path = SparkleShare.Controller.GetAvatar (user_email, 36);
|
||||||
|
|
||||||
if (avatar_file_path != null)
|
if (avatar_file_path != null)
|
||||||
bubble.Icon = new Gdk.Pixbuf (avatar_file_path);
|
bubble.Icon = new Gdk.Pixbuf (avatar_file_path);
|
||||||
else
|
else
|
||||||
bubble.Icon = SparkleUIHelpers.GetIcon ("avatar-default", 32);
|
bubble.Icon = SparkleUIHelpers.GetIcon ("avatar-default", 36);
|
||||||
|
|
||||||
bubble.Show ();
|
bubble.Show ();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue