cleanup ugly path concatenations and add some comments
This commit is contained in:
parent
b859ae9983
commit
ea3babb755
|
@ -28,9 +28,10 @@ namespace SparkleShare {
|
||||||
|
|
||||||
public static bool ShowDebugInfo = true;
|
public static bool ShowDebugInfo = true;
|
||||||
|
|
||||||
|
// Get's the avatar for a specific email address and size
|
||||||
public static Gdk.Pixbuf GetAvatar (string Email, int Size) {
|
public static Gdk.Pixbuf GetAvatar (string Email, int Size) {
|
||||||
|
|
||||||
string AvatarPath = Path.Combine (SparklePaths.SparkleAvatarPath,
|
string AvatarPath = CombineMore (SparklePaths.SparkleAvatarPath,
|
||||||
Size + "x" + Size);
|
Size + "x" + Size);
|
||||||
|
|
||||||
if (!Directory.Exists (AvatarPath)) {
|
if (!Directory.Exists (AvatarPath)) {
|
||||||
|
@ -39,7 +40,7 @@ namespace SparkleShare {
|
||||||
"Created '" + AvatarPath + "'");
|
"Created '" + AvatarPath + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
string AvatarFilePath = AvatarPath + Email;
|
string AvatarFilePath = CombineMore (AvatarPath, Email);
|
||||||
|
|
||||||
if (File.Exists (AvatarFilePath))
|
if (File.Exists (AvatarFilePath))
|
||||||
return new Gdk.Pixbuf (AvatarFilePath);
|
return new Gdk.Pixbuf (AvatarFilePath);
|
||||||
|
@ -49,23 +50,25 @@ namespace SparkleShare {
|
||||||
WebClient WebClient = new WebClient ();
|
WebClient WebClient = new WebClient ();
|
||||||
Uri GravatarUri = new Uri ("http://www.gravatar.com/avatar/" +
|
Uri GravatarUri = new Uri ("http://www.gravatar.com/avatar/" +
|
||||||
GetMD5 (Email) + ".jpg?s=" + Size + "&d=404");
|
GetMD5 (Email) + ".jpg?s=" + Size + "&d=404");
|
||||||
// TODO: Clean paths
|
|
||||||
string TmpFile = SparklePaths.SparkleTmpPath + Email + Size;
|
string TmpFile =
|
||||||
|
CombineMore (SparklePaths.SparkleTmpPath, Email + Size);
|
||||||
|
|
||||||
if (!File.Exists (TmpFile)) {
|
if (!File.Exists (TmpFile)) {
|
||||||
|
|
||||||
WebClient.DownloadFileAsync (GravatarUri, TmpFile);
|
WebClient.DownloadFileAsync (GravatarUri, TmpFile);
|
||||||
WebClient.DownloadFileCompleted += delegate {
|
WebClient.DownloadFileCompleted += delegate {
|
||||||
File.Delete (AvatarPath + Email);
|
File.Delete (AvatarFilePath);
|
||||||
FileInfo TmpFileInfo = new FileInfo (TmpFile);
|
FileInfo TmpFileInfo = new FileInfo (TmpFile);
|
||||||
if (TmpFileInfo.Length > 255)
|
if (TmpFileInfo.Length > 255)
|
||||||
File.Move (TmpFile, AvatarPath + Email);
|
File.Move (TmpFile, AvatarFilePath);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (File.Exists (AvatarPath + Email))
|
// Fall back to a generic icon if there is no gravatar
|
||||||
return new Gdk.Pixbuf (AvatarPath + Email);
|
if (File.Exists (AvatarFilePath))
|
||||||
|
return new Gdk.Pixbuf (AvatarFilePath);
|
||||||
else
|
else
|
||||||
return GetIcon ("avatar-default", Size);
|
return GetIcon ("avatar-default", Size);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue