add service icons to the autocomplete list

This commit is contained in:
Hylke Bons 2010-05-22 18:29:57 +01:00
parent 6afbd0dfc1
commit 15de00ae64
5 changed files with 129 additions and 7 deletions

View file

@ -52,19 +52,33 @@ namespace SparkleShare {
RemoteUrlCombo = new ComboBoxEntry ();
ListStore Defaults = new ListStore (typeof (string));
ListStore Defaults = new ListStore (typeof (string),
typeof (Gdk.Pixbuf));
Defaults.AppendValues ("ssh://git@github.com/");
Defaults.AppendValues ("ssh://git@git.gnome.org/");
Defaults.AppendValues ("ssh://git@fedorahosted.org/");
Defaults.AppendValues ("ssh://git@gitorious.org/");
RemoteUrlCombo.Entry.Completion = new EntryCompletion ();
CellRendererPixbuf CellRendererPixbuf = new CellRendererPixbuf ();
RemoteUrlCombo.Entry.Completion.Model = Defaults;
RemoteUrlCombo.Entry.Completion.PackStart (CellRendererPixbuf, false);
RemoteUrlCombo.Entry.Completion.AddAttribute (CellRendererPixbuf, "pixbuf", 1);
RemoteUrlCombo.Entry.Completion.InlineCompletion = true;
RemoteUrlCombo.Entry.Completion.PopupCompletion = true;;
RemoteUrlCombo.Entry.Completion.TextColumn = 0;
Defaults.AppendValues ("ssh://git@github.com/",
SparkleHelpers.GetIcon ("github", 16));
Defaults.AppendValues ("ssh://git@git.gnome.org/",
SparkleHelpers.GetIcon ("gnome", 16));
Defaults.AppendValues ("ssh://git@fedorahosted.org/",
SparkleHelpers.GetIcon ("fedorahosted", 16));
Defaults.AppendValues ("ssh://git@gitorious.org/",
null);
Label RemoteUrlExample = new Label (_("These usually look something like this:\n ") +
_("sparkle://sparkleshare.org/SparkleShare."));
_("git://git@gnome.org/project."));
RemoteUrlExample.UseMarkup = true;
RemoteUrlExample.SetAlignment (0, 0);

View file

@ -0,0 +1,108 @@
// SparkleShare, an instant update workflow to Git.
// 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 Gtk;
using System;
using System.IO;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
namespace SparkleShare {
public static class SparkleHelpers {
public static Gdk.Pixbuf GetAvatar (string Email, int Size) {
string AvatarPath = Path.Combine (SparklePaths.SparkleAvatarPath,
Size + "x" + Size);
if (!Directory.Exists (AvatarPath)) {
Directory.CreateDirectory (AvatarPath);
Console.WriteLine ("[Config] Created '" + AvatarPath + "'");
}
string AvatarFilePath = AvatarPath + Email;
if (File.Exists (AvatarFilePath))
return new Gdk.Pixbuf (AvatarFilePath);
else {
// Let's try to get the person's gravatar for next time
WebClient WebClient = new WebClient ();
Uri GravatarUri = new Uri ("http://www.gravatar.com/avatar/" +
GetMD5 (Email) + ".jpg?s=" + Size + "&d=404");
string TmpFile = SparklePaths.SparkleTmpPath + Email + Size;
if (!File.Exists (TmpFile)) {
WebClient.DownloadFileAsync (GravatarUri, TmpFile);
WebClient.DownloadFileCompleted += delegate {
File.Delete (AvatarPath + Email);
FileInfo TmpFileInfo = new FileInfo (TmpFile);
if (TmpFileInfo.Length > 255)
File.Move (TmpFile, AvatarPath + Email);
};
}
if (File.Exists (AvatarPath + Email))
return new Gdk.Pixbuf (AvatarPath + Email);
else
return GetIcon ("avatar-default", Size);
}
}
// Creates an MD5 hash
public static string GetMD5 (string s) {
MD5 md5 = new MD5CryptoServiceProvider ();
Byte[] Bytes = ASCIIEncoding.Default.GetBytes (s);
Byte[] EncodedBytes = md5.ComputeHash (Bytes);
return BitConverter.ToString(EncodedBytes).ToLower ().Replace ("-", "");
}
// Makes it possible to combine more than
// two paths at once.
public static string CombineMore (params string [] Parts) {
string NewPath = " ";
foreach (string Part in Parts)
NewPath = Path.Combine (NewPath, Part);
return NewPath;
}
public static IconTheme SparkleTheme = new IconTheme ();
// Looks up an icon from the system's theme
public static Gdk.Pixbuf GetIcon (string Name, int Size) {
SparkleTheme.AppendSearchPath
(CombineMore (SparklePaths.SparkleInstallPath, "icons"));
return SparkleTheme.LoadIcon (Name, Size,
IconLookupFlags.GenericFallback);
}
public static bool IsGitUrl (string Url) {
return Regex.Match (Url, @"[a-z]+://(.)+").Success;
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 747 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 440 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 650 B