[sparklediff] Use system colours for iconview and fix some bugs

This commit is contained in:
Hylke Bons 2010-07-15 12:22:32 +01:00
parent 0ede7daac5
commit 517afbfb77
5 changed files with 129 additions and 87 deletions

View file

@ -14,9 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// TODO: Hand cursor when hovering icon view items
// TODO: Use theme colours
using Gtk;
using Mono.Unix;
using System;
@ -39,11 +36,13 @@ namespace SparkleShare {
public IconView IconView;
public int Selected;
private ToggleButton ToggleButton;
public ToggleButton ToggleButton;
private Viewport Viewport;
private ListStore Store;
private Image Image;
private int Count;
private string SecondaryTextColor;
private string SelectedTextColor;
public RevisionView () : base (false, 0)
@ -52,6 +51,12 @@ namespace SparkleShare {
Count = 0;
Selected = 0;
TreeView treeview = new TreeView ();
SelectedTextColor = GdkColorToHex (treeview.Style.Foreground (StateType.Selected));
Window window = new Window ("");
SecondaryTextColor = GdkColorToHex (window.Style.Foreground (StateType.Insensitive));
ToggleButton = new ToggleButton ();
ToggleButton.Clicked += ToggleView;
ToggleButton.Relief = ReliefStyle.None;
@ -85,18 +90,37 @@ namespace SparkleShare {
public void ChangeSelection (object o, EventArgs args)
{
TreeIter iter;
Store.GetIter (out iter, new TreePath (GetSelected ().ToString ()));
string text = (string) Store.GetValue (iter, 1);
Store.SetValue (iter, 1, text.Replace (SelectedTextColor, SecondaryTextColor));
if (IconView.SelectedItems.Length > 0) {
TreeIter iter;
Store.GetIter (out iter, IconView.SelectedItems [0]);
SetSelected ((int) Store.GetValue (iter, 2));
text = (string) Store.GetValue (iter, 1);
text = text.Replace (SecondaryTextColor, SelectedTextColor);
Store.SetValue (iter, 1, text);
} else {
IconView.SelectPath (new TreePath (GetSelected ().ToString()));
}
}
// Converts a Gdk RGB color to a hex value.
// Example: from "rgb:0,0,0" to "#000000"
public string GdkColorToHex (Gdk.Color color)
{
return String.Format("#{0:X2}{1:X2}{2:X2}",
(int) Math.Truncate(color.Red / 256.00),
(int) Math.Truncate(color.Green / 256.00),
(int) Math.Truncate(color.Blue / 256.00));
}
@ -126,8 +150,8 @@ namespace SparkleShare {
string text = (string) Store.GetValue (iter, 1);
Gdk.Pixbuf pixbuf = (Gdk.Pixbuf) Store.GetValue (iter, 0);
Label label = new Label (text);
Label label = new Label (text.Replace (SelectedTextColor, SecondaryTextColor));
label.UseMarkup = true;
Arrow arrow_down = new Arrow (ArrowType.Down, ShadowType.None);
@ -152,14 +176,17 @@ namespace SparkleShare {
public void AddRow (Gdk.Pixbuf pixbuf, string header, string subtext)
{
Store.AppendValues (pixbuf, "<b>" + header + "</b>\n<span fgcolor='#777'>" + subtext + "</span>", Count);
Store.AppendValues (pixbuf, "<b>" + header + "</b>\n" +
"<span fgcolor='" + SecondaryTextColor + "'>" + subtext + "</span>",
Count);
IconView.Model = Store;
Count++;
}
// Toggles between a displayed image and a list of revisions
// Toggles between a displayed image and a list of revisions
public void ToggleView (object o, EventArgs args)
{

View file

@ -54,8 +54,7 @@ namespace SparkleShare {
DeleteEvent += Quit;
// TRANSLATORS: The parameter is a filename
Title = String.Format(_("Comparing Revisions of {0}"), file_name);
Title = file_name;
VBox layout_vertical = new VBox (false, 12);
@ -127,19 +126,30 @@ namespace SparkleShare {
HookUpViews ();
};
ViewLeft.ToggleButton.Clicked += delegate {
if (ViewLeft.ToggleButton.Active)
DetachViews ();
else
HookUpViews ();
};
ViewRight.ToggleButton.Clicked += delegate {
if (ViewLeft.ToggleButton.Active)
DetachViews ();
else
HookUpViews ();
};
layout_horizontal.PackStart (ViewLeft);
layout_horizontal.PackStart (ViewRight);
ResizeToViews ();
// Order time view according to the user's reading direction
if (Direction == Gtk.TextDirection.Rtl)
layout_horizontal.ReorderChild (ViewLeft, 1);
HookUpViews ();
HButtonBox dialog_buttons = new HButtonBox ();
@ -159,24 +169,9 @@ namespace SparkleShare {
Add (layout_vertical);
}
// Converts a UNIX timestamp to a more usable time object
public DateTime UnixTimestampToDateTime (int timestamp)
{
DateTime unix_epoch = new DateTime (1970, 1, 1, 0, 0, 0, 0);
return unix_epoch.AddSeconds (timestamp);
}
// Looks up an icon from the system's theme
public Gdk.Pixbuf GetIcon (string name, int size)
{
IconTheme icon_theme = new IconTheme ();
icon_theme.AppendSearchPath (System.IO.Path.Combine ("/usr/share/sparkleshare", "icons"));
return icon_theme.LoadIcon (name, size, IconLookupFlags.GenericFallback);
}
// Resizes the window so it will fit the content in the best possible way
private void ResizeToViews ()
{
@ -195,6 +190,7 @@ namespace SparkleShare {
}
// Hooks up two views so their scrollbars will be kept in sync
private void HookUpViews ()
{
@ -205,6 +201,18 @@ namespace SparkleShare {
ViewRight.ScrolledWindow.Vadjustment.ValueChanged += SyncViewsVertically;
}
// Detach the two views from each other so they don't try to sync anymore
private void DetachViews ()
{
ViewLeft.ScrolledWindow.Hadjustment.ValueChanged -= SyncViewsHorizontally;
ViewLeft.ScrolledWindow.Vadjustment.ValueChanged -= SyncViewsVertically;
ViewRight.ScrolledWindow.Hadjustment.ValueChanged -= SyncViewsHorizontally;
ViewRight.ScrolledWindow.Vadjustment.ValueChanged -= SyncViewsVertically;
}
// Keeps the two image views in sync horizontally
@ -244,6 +252,23 @@ namespace SparkleShare {
}
// Converts a UNIX timestamp to a more usable time object
public DateTime UnixTimestampToDateTime (int timestamp)
{
DateTime unix_epoch = new DateTime (1970, 1, 1, 0, 0, 0, 0);
return unix_epoch.AddSeconds (timestamp);
}
// Looks up an icon from the system's theme
public Gdk.Pixbuf GetIcon (string name, int size)
{
IconTheme icon_theme = new IconTheme ();
icon_theme.AppendSearchPath (System.IO.Path.Combine ("/usr/share/sparkleshare", "icons"));
return icon_theme.LoadIcon (name, size, IconLookupFlags.GenericFallback);
}
// Creates an MD5 hash of input
public static string GetMD5 (string s)
{
@ -255,12 +280,10 @@ namespace SparkleShare {
// TODO: Turn this into an avatar fetching library
// TODO: This should be included from SparkleHelpers, but I don't know how to do that
// Gets the avatar for a specific email address and size
public Gdk.Pixbuf GetAvatar (string Email, int Size)
{
UnixUserInfo UnixUserInfo = new UnixUserInfo (UnixEnvironment.UserName);
string HomePath = UnixUserInfo.HomeDirectory;
@ -271,7 +294,6 @@ namespace SparkleShare {
if (!Directory.Exists (AvatarPath)) {
Directory.CreateDirectory (AvatarPath);
// SparkleHelpers.DebugInfo ("Config", "Created '" + AvatarPath + "'");
}
string AvatarFilePath = CombineMore (AvatarPath, Email);
@ -295,7 +317,6 @@ namespace SparkleShare {
FileInfo TmpFileInfo = new FileInfo (TmpFile);
if (TmpFileInfo.Length > 255)
File.Move (TmpFile, AvatarFilePath);
Console.WriteLine ("AAAAAAA");
};
}
@ -310,6 +331,7 @@ namespace SparkleShare {
}
// Quits the program
private void Quit (object o, EventArgs args)
{

View file

@ -20,6 +20,7 @@ using SparkleShare;
using System;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
namespace SparkleShare {
@ -109,7 +110,7 @@ namespace SparkleShare {
HideAll ();
string RepoRemoteUrl = RemoteUrlCombo.Entry.Text;
RepoRemoteUrl = SparkleHelpers.SparkleToGitUrl (RepoRemoteUrl);
RepoRemoteUrl = SparkleToGitUrl (RepoRemoteUrl);
int SlashPos = RepoRemoteUrl.LastIndexOf ("/");
int ColumnPos = RepoRemoteUrl.LastIndexOf (":");
@ -212,12 +213,35 @@ namespace SparkleShare {
// Enables the Add button when the fields are
// filled in correctly
public void CheckFields (object o, EventArgs args) {
if (SparkleHelpers.IsGitUrl (RemoteUrlCombo.Entry.Text))
if (IsGitUrl (RemoteUrlCombo.Entry.Text))
AddButton.Sensitive = true;
else
AddButton.Sensitive = false;
}
// Convert the more human readable sparkle:// url to something Git can use.
// Example: sparkle://gitorious.org/sparkleshare ssh://git@gitorious.org/sparkleshare
public static string SparkleToGitUrl (string Url)
{
if (Url.StartsWith ("sparkle://"))
Url = Url.Replace ("sparkle://", "ssh://git@");
// Usually don't need the ".git" at the end.
// It looks ugly as a folder too.
if (Url.EndsWith (".git"))
Url = Url.Substring (0, Url.Length - 4);
return Url;
}
// Checks if a url is a valid git url
public static bool IsGitUrl (string Url)
{
return Regex.Match (Url, @"(.)+(/|:)(.)+").Success;
}
}
}

View file

@ -21,19 +21,13 @@ 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 string _ (string s)
{
return Catalog.GetString (s);
}
// Gets the avatar for a specific email address and size
public static Gdk.Pixbuf GetAvatar (string Email, int Size)
{
@ -89,28 +83,9 @@ namespace SparkleShare {
Byte[] encodedBytes = md5.ComputeHash (bytes);
return BitConverter.ToString (encodedBytes).ToLower ().Replace ("-", "");
}
// Convert the more human readable sparkle:// url to
// something Git can use
// Example: sparkle://gitorious.org/sparkleshare
// to ssh://git@gitorious.org/sparkleshare
public static string SparkleToGitUrl (string Url)
{
if (Url.StartsWith ("sparkle://"))
Url = Url.Replace ("sparkle://", "ssh://git@");
// Usually don't need the ".git" at the end.
// It looks ugly as a folder too.
if (Url.EndsWith (".git"))
Url = Url.Substring (0, Url.Length - 4);
return Url;
}
// Makes it possible to combine more than
// two paths at once.
// two paths at once
public static string CombineMore (params string [] Parts)
{
string NewPath = " ";
@ -130,13 +105,6 @@ namespace SparkleShare {
}
// Checks if a url is a valid git url
public static bool IsGitUrl (string Url)
{
return Regex.Match (Url, @"(.)+(/|:)(.)+").Success;
}
public static bool ShowDebugInfo = true;
@ -198,21 +166,6 @@ namespace SparkleShare {
}
// Checks for unicorns
public static void CheckForUnicorns (string s) {
s = s.ToLower ();
if (s.Contains ("unicorn") && (s.Contains (".png") || s.Contains (".jpg"))) {
string title = _("Hold your ponies!");
string subtext = _("SparkleShare is known to be insanely fast with \n" +
"pictures of unicorns. Please make sure your internets\n" +
"are upgraded to the latest version to avoid problems.");
SparkleBubble unicorn_bubble = new SparkleBubble (title, subtext);
unicorn_bubble.Show ();
}
}
}
}

View file

@ -179,7 +179,7 @@ namespace SparkleShare {
FetchTimer.Start ();
BufferTimer.Start ();
SparkleHelpers.CheckForUnicorns (Message);
CheckForUnicorns (Message);
}
@ -457,6 +457,22 @@ namespace SparkleShare {
}
// Checks for unicorns
public static void CheckForUnicorns (string s) {
s = s.ToLower ();
if (s.Contains ("unicorn") && (s.Contains (".png") || s.Contains (".jpg"))) {
string title = _("Hold your ponies!");
string subtext = _("SparkleShare is known to be insanely fast with \n" +
"pictures of unicorns. Please make sure your internets\n" +
"are upgraded to the latest version to avoid problems.");
SparkleBubble unicorn_bubble = new SparkleBubble (title, subtext);
unicorn_bubble.Show ();
}
}
}
}