Rebase on master
This commit is contained in:
commit
533dc91e8b
|
@ -963,6 +963,67 @@ namespace SparkleShare {
|
|||
}
|
||||
|
||||
|
||||
// Gets the avatar for a specific email address and size
|
||||
public string GetAvatar (string email, int size)
|
||||
{
|
||||
|
||||
string avatar_path = SparkleHelpers.CombineMore (SparklePaths.SparkleLocalIconPath,
|
||||
size + "x" + size, "status");
|
||||
|
||||
if (!Directory.Exists (avatar_path)) {
|
||||
|
||||
Directory.CreateDirectory (avatar_path);
|
||||
SparkleHelpers.DebugInfo ("Config", "Created '" + avatar_path + "'");
|
||||
|
||||
}
|
||||
|
||||
string avatar_file_path = SparkleHelpers.CombineMore (avatar_path, "avatar-" + email);
|
||||
|
||||
if (File.Exists (avatar_file_path)) {
|
||||
|
||||
return avatar_file_path;
|
||||
|
||||
} else {
|
||||
|
||||
// Let's try to get the person's gravatar for next time
|
||||
WebClient web_client = new WebClient ();
|
||||
Uri uri = new Uri ("http://www.gravatar.com/avatar/" + GetMD5 (email) +
|
||||
".jpg?s=" + size + "&d=404");
|
||||
|
||||
string tmp_file_path = SparkleHelpers.CombineMore (SparklePaths.SparkleTmpPath, email + size);
|
||||
|
||||
if (!File.Exists (tmp_file_path)) {
|
||||
|
||||
web_client.DownloadFileAsync (uri, tmp_file_path);
|
||||
|
||||
web_client.DownloadFileCompleted += delegate {
|
||||
|
||||
if (File.Exists (avatar_file_path))
|
||||
File.Delete (avatar_file_path);
|
||||
|
||||
FileInfo tmp_file_info = new FileInfo (tmp_file_path);
|
||||
|
||||
if (tmp_file_info.Length > 255)
|
||||
File.Move (tmp_file_path, avatar_file_path);
|
||||
|
||||
if (AvatarFetched != null)
|
||||
AvatarFetched ();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
// Fall back to a generic icon if there is no gravatar
|
||||
if (File.Exists (avatar_file_path))
|
||||
return avatar_file_path;
|
||||
else
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void FetchFolder (string url, string name)
|
||||
{
|
||||
|
||||
|
@ -1062,67 +1123,6 @@ namespace SparkleShare {
|
|||
}
|
||||
|
||||
|
||||
// Gets the avatar for a specific email address and size
|
||||
public string GetAvatar (string email, int size)
|
||||
{
|
||||
|
||||
string avatar_path = SparkleHelpers.CombineMore (SparklePaths.SparkleLocalIconPath,
|
||||
size + "x" + size, "status");
|
||||
|
||||
if (!Directory.Exists (avatar_path)) {
|
||||
|
||||
Directory.CreateDirectory (avatar_path);
|
||||
SparkleHelpers.DebugInfo ("Config", "Created '" + avatar_path + "'");
|
||||
|
||||
}
|
||||
|
||||
string avatar_file_path = SparkleHelpers.CombineMore (avatar_path, "avatar-" + email);
|
||||
|
||||
if (File.Exists (avatar_file_path)) {
|
||||
|
||||
return avatar_file_path;
|
||||
|
||||
} else {
|
||||
|
||||
// Let's try to get the person's gravatar for next time
|
||||
WebClient web_client = new WebClient ();
|
||||
Uri uri = new Uri ("http://www.gravatar.com/avatar/" + GetMD5 (email) +
|
||||
".jpg?s=" + size + "&d=404");
|
||||
|
||||
string tmp_file_path = SparkleHelpers.CombineMore (SparklePaths.SparkleTmpPath, email + size);
|
||||
|
||||
if (!File.Exists (tmp_file_path)) {
|
||||
|
||||
web_client.DownloadFileAsync (uri, tmp_file_path);
|
||||
|
||||
web_client.DownloadFileCompleted += delegate {
|
||||
|
||||
if (File.Exists (avatar_file_path))
|
||||
File.Delete (avatar_file_path);
|
||||
|
||||
FileInfo tmp_file_info = new FileInfo (tmp_file_path);
|
||||
|
||||
if (tmp_file_info.Length > 255)
|
||||
File.Move (tmp_file_path, avatar_file_path);
|
||||
|
||||
if (AvatarFetched != null)
|
||||
AvatarFetched ();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
// Fall back to a generic icon if there is no gravatar
|
||||
if (File.Exists (avatar_file_path))
|
||||
return avatar_file_path;
|
||||
else
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Creates an MD5 hash of input
|
||||
public static string GetMD5 (string s)
|
||||
{
|
||||
|
@ -1182,7 +1182,6 @@ namespace SparkleShare {
|
|||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue