Fix merge conflict in RevisionView.cs
This commit is contained in:
commit
f8b61f6543
|
@ -14,7 +14,11 @@
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// 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 Gtk;
|
||||||
|
using Mono.Unix;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace SparkleShare {
|
namespace SparkleShare {
|
||||||
|
@ -24,142 +28,224 @@ namespace SparkleShare {
|
||||||
public class RevisionView : VBox
|
public class RevisionView : VBox
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// Short alias for the translations
|
||||||
|
public static string _ (string s)
|
||||||
|
{
|
||||||
|
return Catalog.GetString (s);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public ScrolledWindow ScrolledWindow;
|
public ScrolledWindow ScrolledWindow;
|
||||||
public ComboBox ComboBox;
|
public IconView IconView;
|
||||||
public Button ButtonPrevious;
|
|
||||||
public Button ButtonNext;
|
|
||||||
|
|
||||||
private int ValueCount;
|
private ToggleButton ToggleButton;
|
||||||
|
private Viewport Viewport;
|
||||||
|
private ListStore Store;
|
||||||
private Image Image;
|
private Image Image;
|
||||||
|
private int Selected;
|
||||||
|
private int Count;
|
||||||
|
|
||||||
public RevisionView (string [] revisions) : base (false, 6)
|
|
||||||
|
public RevisionView () : base (false, 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
Image = new Image ();
|
Count = 0;
|
||||||
|
Selected = 0;
|
||||||
|
|
||||||
|
ToggleButton = new ToggleButton ();
|
||||||
|
ToggleButton.Clicked += ToggleView;
|
||||||
|
ToggleButton.Relief = ReliefStyle.None;
|
||||||
|
|
||||||
ScrolledWindow = new ScrolledWindow ();
|
ScrolledWindow = new ScrolledWindow ();
|
||||||
|
|
||||||
ScrolledWindow.AddWithViewport (Image);
|
Viewport = new Viewport ();
|
||||||
|
Viewport.Add (new Label (""));
|
||||||
|
|
||||||
HBox controls = new HBox (false, 3);
|
Store = new ListStore(typeof (Gdk.Pixbuf),
|
||||||
controls.BorderWidth = 0;
|
typeof (string),
|
||||||
|
typeof (int));
|
||||||
|
|
||||||
Arrow arrow_left = new Arrow (ArrowType.Left, ShadowType.None);
|
IconView = new IconView (Store);
|
||||||
ButtonPrevious = new Button ();
|
IconView.SelectionChanged += ChangeSelection;
|
||||||
ButtonPrevious.Add (arrow_left);
|
IconView.MarkupColumn = 1;
|
||||||
ButtonPrevious.Clicked += PreviousInComboBox;
|
IconView.Margin = 12;
|
||||||
ButtonPrevious.ExposeEvent += EqualizeSizes;
|
IconView.Orientation = Orientation.Horizontal;
|
||||||
|
IconView.PixbufColumn = 0;
|
||||||
|
IconView.Spacing = 12;
|
||||||
|
|
||||||
ValueCount = 0;
|
Image = new Image ();
|
||||||
|
|
||||||
ComboBox = ComboBox.NewText ();
|
ScrolledWindow.Add (Viewport);
|
||||||
|
|
||||||
foreach (string revision in revisions) {
|
|
||||||
ComboBox.AppendText (revision);
|
|
||||||
}
|
|
||||||
|
|
||||||
ComboBox.Active = 0;
|
|
||||||
|
|
||||||
ValueCount = revisions.Length;
|
|
||||||
|
|
||||||
Arrow arrow_right = new Arrow (ArrowType.Right, ShadowType.None);
|
|
||||||
ButtonNext = new Button ();
|
|
||||||
ButtonNext.Add (arrow_right);
|
|
||||||
ButtonNext.Clicked += NextInComboBox;
|
|
||||||
ButtonNext.ExposeEvent += EqualizeSizes;
|
|
||||||
|
|
||||||
controls.PackStart (ButtonPrevious, false, false, 0);
|
|
||||||
controls.PackStart (ButtonNext, false, false, 0);
|
|
||||||
controls.PackStart (new Label (""), true, false, 0);
|
|
||||||
controls.PackStart (ComboBox, false, false, 0);
|
|
||||||
|
|
||||||
PackStart (controls, false, false, 0);
|
|
||||||
PackStart (ScrolledWindow, true, true, 0);
|
PackStart (ScrolledWindow, true, true, 0);
|
||||||
|
|
||||||
Shown += delegate {
|
|
||||||
UpdateControls ();
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Equalizes the height and width of a button when exposed
|
// Changes the selection and enforces a policy of always having something selected
|
||||||
private void EqualizeSizes (object o, ExposeEventArgs args) {
|
public void ChangeSelection (object o, EventArgs args)
|
||||||
|
{
|
||||||
|
|
||||||
Button button = (Button) o;
|
if (IconView.SelectedItems.Length > 0) {
|
||||||
button.WidthRequest = button.Allocation.Height;
|
|
||||||
|
|
||||||
}
|
TreeIter iter;
|
||||||
|
Store.GetIter (out iter, IconView.SelectedItems [0]);
|
||||||
|
SetSelected ((int) Store.GetValue (iter, 2));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
public void NextInComboBox (object o, EventArgs args) {
|
IconView.SelectPath (new TreePath (GetSelected ().ToString()));
|
||||||
|
|
||||||
if (ComboBox.Active - 1 >= 0)
|
|
||||||
ComboBox.Active--;
|
|
||||||
|
|
||||||
// UpdateControls ();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void PreviousInComboBox (object o, EventArgs args) {
|
|
||||||
|
|
||||||
if (ComboBox.Active + 1 < ValueCount)
|
|
||||||
ComboBox.Active++;
|
|
||||||
|
|
||||||
// UpdateControls ();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Updates the buttons to be disabled or enabled when needed
|
|
||||||
public void UpdateControls () {
|
|
||||||
|
|
||||||
ButtonPrevious.State = StateType.Normal;
|
|
||||||
ButtonNext.State = StateType.Normal;
|
|
||||||
|
|
||||||
// TODO: Disable Next or Previous buttons when at the first or last value of the combobox
|
|
||||||
// I can't get this to work! >:(
|
|
||||||
|
|
||||||
if (ComboBox.Active == ValueCount - 1) {
|
|
||||||
ButtonPrevious.State = StateType.Insensitive;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ComboBox.Active == 0) {
|
}
|
||||||
ButtonNext.State = StateType.Insensitive;
|
|
||||||
|
|
||||||
|
// Makes sure everything is in place before showing the widget
|
||||||
|
new public void ShowAll ()
|
||||||
|
{
|
||||||
|
|
||||||
|
if (Children.Length == 2) {
|
||||||
|
|
||||||
|
ToggleButton = (ToggleButton) Children [0];
|
||||||
|
ToggleButton.Remove (ToggleButton.Child);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
ToggleButton = new ToggleButton ();
|
||||||
|
ToggleButton.Relief = ReliefStyle.None;
|
||||||
|
ToggleButton.Clicked += ToggleView;
|
||||||
|
PackStart (ToggleButton, false, false, 6);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HBox layout_horizontal = new HBox (false, 12);
|
||||||
|
layout_horizontal.BorderWidth = 6;
|
||||||
|
|
||||||
|
TreeIter iter;
|
||||||
|
Store.GetIter (out iter, new TreePath (GetSelected ().ToString()));
|
||||||
|
|
||||||
|
string text = (string) Store.GetValue (iter, 1);
|
||||||
|
Gdk.Pixbuf pixbuf = (Gdk.Pixbuf) Store.GetValue (iter, 0);
|
||||||
|
|
||||||
|
Label label = new Label (text);
|
||||||
|
label.UseMarkup = true;
|
||||||
|
|
||||||
|
Arrow arrow_down = new Arrow (ArrowType.Down, ShadowType.None);
|
||||||
|
|
||||||
|
layout_horizontal.PackStart (new Image (pixbuf), false, false, 0);
|
||||||
|
layout_horizontal.PackStart (label, false, false, 0);
|
||||||
|
layout_horizontal.PackStart (new Label (""), true, true, 0);
|
||||||
|
layout_horizontal.PackStart (arrow_down, false, false, 0);
|
||||||
|
|
||||||
|
ToggleButton.Add (layout_horizontal);
|
||||||
|
ReorderChild (ToggleButton, 0);
|
||||||
|
|
||||||
|
TreePath path = new TreePath (Selected.ToString());
|
||||||
|
IconView.SelectPath (path);
|
||||||
|
|
||||||
|
base.ShowAll ();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Adds a revision to the combobox
|
||||||
|
public void AddRow (Gdk.Pixbuf pixbuf, string header, string subtext)
|
||||||
|
{
|
||||||
|
|
||||||
|
Store.AppendValues (pixbuf, "<b>" + header + "</b>\n<span fgcolor='#777'>" + subtext + "</span>", Count);
|
||||||
|
IconView.Model = Store;
|
||||||
|
Count++;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Toggles between a displayed image and a list of revisions
|
||||||
|
public void ToggleView (object o, EventArgs args)
|
||||||
|
{
|
||||||
|
|
||||||
|
Viewport.Remove (Viewport.Child);
|
||||||
|
|
||||||
|
if (ToggleButton.Active) {
|
||||||
|
|
||||||
|
Viewport.Add (IconView);
|
||||||
|
TreePath path = new TreePath (GetSelected ().ToString());
|
||||||
|
|
||||||
|
IconView.ScrollToPath (path, (float) 0.5, (float) 0.5);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
Viewport.Add (Image);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ShowAll ();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Changes the image that is viewed
|
// Changes the image that is viewed
|
||||||
public void SetImage (Image image) {
|
public void SetImage (Image image)
|
||||||
|
{
|
||||||
|
|
||||||
Image = image;
|
Image = image;
|
||||||
Remove (ScrolledWindow);
|
Viewport.Remove (Viewport.Child);
|
||||||
ScrolledWindow = new ScrolledWindow ();
|
Viewport.Add (Image);
|
||||||
ScrolledWindow.AddWithViewport (Image);
|
ToggleButton.Active = false;
|
||||||
Add (ScrolledWindow);
|
|
||||||
ShowAll ();
|
ShowAll ();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Returns the image that is currently viewed
|
||||||
public Image GetImage ()
|
public Image GetImage ()
|
||||||
{
|
{
|
||||||
return Image;
|
return Image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Selects an item by number
|
||||||
|
public bool SetSelected (int i)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (i > -1 && i <= Count) {
|
||||||
|
Selected = i;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Returns the number of the currently selected item
|
||||||
|
public int GetSelected ()
|
||||||
|
{
|
||||||
|
return Selected;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Derived class for the image view on the left
|
// Derived class for the image view on the left
|
||||||
public class LeftRevisionView : RevisionView {
|
public class LeftRevisionView : RevisionView
|
||||||
|
{
|
||||||
|
|
||||||
public LeftRevisionView (string [] revisions) : base (revisions) {
|
public LeftRevisionView () : base ()
|
||||||
|
{
|
||||||
|
|
||||||
ComboBox.Active = 1;
|
// Select the second revision
|
||||||
|
SetSelected (1);
|
||||||
|
|
||||||
|
// Take reading direction for time into account
|
||||||
if (Direction == Gtk.TextDirection.Ltr)
|
if (Direction == Gtk.TextDirection.Ltr)
|
||||||
ScrolledWindow.Placement = CornerType.TopRight;
|
ScrolledWindow.Placement = CornerType.TopRight;
|
||||||
else
|
else
|
||||||
|
@ -171,12 +257,15 @@ namespace SparkleShare {
|
||||||
|
|
||||||
|
|
||||||
// Derived class for the image view on the right
|
// Derived class for the image view on the right
|
||||||
public class RightRevisionView : RevisionView {
|
public class RightRevisionView : RevisionView
|
||||||
|
{
|
||||||
|
|
||||||
public RightRevisionView (string [] revisions) : base (revisions) {
|
public RightRevisionView () : base ()
|
||||||
|
{
|
||||||
|
|
||||||
ComboBox.Active = 0;
|
SetSelected (0);
|
||||||
|
|
||||||
|
// Take reading direction for time into account
|
||||||
if (Direction == Gtk.TextDirection.Ltr)
|
if (Direction == Gtk.TextDirection.Ltr)
|
||||||
ScrolledWindow.Placement = CornerType.TopLeft;
|
ScrolledWindow.Placement = CornerType.TopLeft;
|
||||||
else
|
else
|
||||||
|
@ -186,5 +275,4 @@ namespace SparkleShare {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,11 @@ using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
using System.IO;
|
||||||
|
using System.Net;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace SparkleShare {
|
namespace SparkleShare {
|
||||||
|
|
||||||
// The main window for SparkleDiff
|
// The main window for SparkleDiff
|
||||||
|
@ -54,7 +59,7 @@ namespace SparkleShare {
|
||||||
|
|
||||||
VBox layout_vertical = new VBox (false, 12);
|
VBox layout_vertical = new VBox (false, 12);
|
||||||
|
|
||||||
HBox layout_horizontal = new HBox (false, 12);
|
HBox layout_horizontal = new HBox (true, 6);
|
||||||
|
|
||||||
Process process = new Process ();
|
Process process = new Process ();
|
||||||
process.EnableRaisingEvents = true;
|
process.EnableRaisingEvents = true;
|
||||||
|
@ -63,9 +68,12 @@ namespace SparkleShare {
|
||||||
|
|
||||||
process.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName (file_path);
|
process.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName (file_path);
|
||||||
process.StartInfo.FileName = "git";
|
process.StartInfo.FileName = "git";
|
||||||
process.StartInfo.Arguments = "log --format=\"%ct\t%an\" " + file_name;
|
process.StartInfo.Arguments = "log --format=\"%ct\t%an\t%ae\" " + file_name;
|
||||||
process.Start ();
|
process.Start ();
|
||||||
|
|
||||||
|
ViewLeft = new LeftRevisionView ();
|
||||||
|
ViewRight = new RightRevisionView ();
|
||||||
|
|
||||||
string output = process.StandardOutput.ReadToEnd ();
|
string output = process.StandardOutput.ReadToEnd ();
|
||||||
string [] revisions_info = Regex.Split (output.Trim (), "\n");
|
string [] revisions_info = Regex.Split (output.Trim (), "\n");
|
||||||
|
|
||||||
|
@ -76,59 +84,54 @@ namespace SparkleShare {
|
||||||
|
|
||||||
int timestamp = int.Parse (parts [0]);
|
int timestamp = int.Parse (parts [0]);
|
||||||
string author = parts [1];
|
string author = parts [1];
|
||||||
|
string email = parts [2];
|
||||||
|
|
||||||
|
string date;
|
||||||
|
// TRANSLATORS: This is a format specifier according to System.Globalization.DateTimeFormatInfo
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
revisions_info [i] = _("Current Revision") + "\t" + author;
|
date = "Latest Revision";
|
||||||
else
|
else
|
||||||
|
date = String.Format (_("{0} at {1}"),
|
||||||
|
UnixTimestampToDateTime (timestamp).ToString (_("ddd MMM d, yyyy")),
|
||||||
|
UnixTimestampToDateTime (timestamp).ToString (_("H:mm")));
|
||||||
|
|
||||||
// TRANSLATORS: This is a format specifier according to System.Globalization.DateTimeFormatInfo
|
ViewLeft.AddRow (GetAvatar (email, 32), author, date);
|
||||||
revisions_info [i] = UnixTimestampToDateTime (timestamp).ToString (_("d MMM\tH:mm")) +
|
ViewRight.AddRow (GetAvatar (email, 32), author, date);
|
||||||
"\t" + author;
|
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ViewLeft = new LeftRevisionView (revisions_info);
|
|
||||||
ViewRight = new RightRevisionView (revisions_info);
|
|
||||||
|
|
||||||
ViewLeft.SetImage (new RevisionImage (file_path, Revisions [1]));
|
ViewLeft.SetImage (new RevisionImage (file_path, Revisions [1]));
|
||||||
ViewRight.SetImage (new RevisionImage (file_path, Revisions [0]));
|
ViewRight.SetImage (new RevisionImage (file_path, Revisions [0]));
|
||||||
|
|
||||||
|
ViewLeft.IconView.SelectionChanged += delegate {
|
||||||
|
|
||||||
|
ViewLeft.SetImage (new RevisionImage (file_path, Revisions [ViewLeft.GetSelected ()]));
|
||||||
|
|
||||||
|
ViewLeft.ScrolledWindow.Hadjustment = ViewRight.ScrolledWindow.Hadjustment;
|
||||||
|
ViewLeft.ScrolledWindow.Vadjustment = ViewRight.ScrolledWindow.Vadjustment;
|
||||||
|
|
||||||
|
HookUpViews ();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
ViewRight.IconView.SelectionChanged += delegate {
|
||||||
|
|
||||||
|
ViewRight.SetImage (new RevisionImage (file_path, Revisions [ViewRight.GetSelected ()]));
|
||||||
|
|
||||||
|
ViewRight.ScrolledWindow.Hadjustment = ViewLeft.ScrolledWindow.Hadjustment;
|
||||||
|
ViewRight.ScrolledWindow.Vadjustment = ViewLeft.ScrolledWindow.Vadjustment;
|
||||||
|
|
||||||
|
HookUpViews ();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
layout_horizontal.PackStart (ViewLeft);
|
layout_horizontal.PackStart (ViewLeft);
|
||||||
layout_horizontal.PackStart (ViewRight);
|
layout_horizontal.PackStart (ViewRight);
|
||||||
|
|
||||||
|
|
||||||
ViewLeft.ComboBox.Changed += delegate {
|
|
||||||
|
|
||||||
RevisionImage revision_image;
|
|
||||||
revision_image = new RevisionImage (file_path, Revisions [ViewLeft.ComboBox.Active]);
|
|
||||||
ViewLeft.SetImage (revision_image);
|
|
||||||
|
|
||||||
HookUpViews ();
|
|
||||||
|
|
||||||
ViewLeft.ScrolledWindow.Hadjustment = ViewRight.ScrolledWindow.Hadjustment;
|
|
||||||
ViewLeft.ScrolledWindow.Vadjustment = ViewRight.ScrolledWindow.Vadjustment;
|
|
||||||
|
|
||||||
ViewLeft.UpdateControls ();
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
ViewRight.ComboBox.Changed += delegate {
|
|
||||||
|
|
||||||
RevisionImage revision_image;
|
|
||||||
revision_image = new RevisionImage (file_path, Revisions [ViewRight.ComboBox.Active]);
|
|
||||||
ViewRight.SetImage (revision_image);
|
|
||||||
|
|
||||||
HookUpViews ();
|
|
||||||
|
|
||||||
ViewRight.ScrolledWindow.Hadjustment = ViewLeft.ScrolledWindow.Hadjustment;
|
|
||||||
ViewRight.ScrolledWindow.Vadjustment = ViewLeft.ScrolledWindow.Vadjustment;
|
|
||||||
|
|
||||||
ViewRight.UpdateControls ();
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
ResizeToViews ();
|
ResizeToViews ();
|
||||||
|
|
||||||
|
@ -157,6 +160,22 @@ 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void ResizeToViews ()
|
private void ResizeToViews ()
|
||||||
{
|
{
|
||||||
|
@ -216,14 +235,80 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Converts a UNIX timestamp to a more usable time object
|
public string CombineMore (params string [] Parts)
|
||||||
public DateTime UnixTimestampToDateTime (int timestamp)
|
|
||||||
{
|
{
|
||||||
DateTime unix_epoch = new DateTime (1970, 1, 1, 0, 0, 0, 0);
|
string NewPath = " ";
|
||||||
return unix_epoch.AddSeconds (timestamp);
|
foreach (string Part in Parts)
|
||||||
|
NewPath = System.IO.Path.Combine (NewPath, Part);
|
||||||
|
return NewPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Creates an MD5 hash of input
|
||||||
|
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 ("-", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
string SparkleLocalIconPath = CombineMore (HomePath + "/.icons", "sparkleshare");
|
||||||
|
|
||||||
|
string AvatarPath = CombineMore (SparkleLocalIconPath, Size + "x" + Size, "status");
|
||||||
|
|
||||||
|
if (!Directory.Exists (AvatarPath)) {
|
||||||
|
Directory.CreateDirectory (AvatarPath);
|
||||||
|
// SparkleHelpers.DebugInfo ("Config", "Created '" + AvatarPath + "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
string AvatarFilePath = CombineMore (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 = CombineMore ("/home/hbons/dsfdsf.jpg");
|
||||||
|
|
||||||
|
if (!File.Exists (TmpFile)) {
|
||||||
|
|
||||||
|
WebClient.DownloadFileAsync (GravatarUri, TmpFile);
|
||||||
|
WebClient.DownloadFileCompleted += delegate {
|
||||||
|
// File.Delete (AvatarFilePath);
|
||||||
|
FileInfo TmpFileInfo = new FileInfo (TmpFile);
|
||||||
|
if (TmpFileInfo.Length > 255)
|
||||||
|
File.Move (TmpFile, AvatarFilePath);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fall back to a generic icon if there is no gravatar
|
||||||
|
if (File.Exists (AvatarFilePath))
|
||||||
|
return new Gdk.Pixbuf (AvatarFilePath);
|
||||||
|
else
|
||||||
|
return GetIcon ("avatar-default", Size);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Quits the program
|
// Quits the program
|
||||||
private void Quit (object o, EventArgs args)
|
private void Quit (object o, EventArgs args)
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,6 +12,7 @@ Defines.cs \
|
||||||
SparkleBubble.cs \
|
SparkleBubble.cs \
|
||||||
SparkleDialog.cs \
|
SparkleDialog.cs \
|
||||||
SparkleHelpers.cs \
|
SparkleHelpers.cs \
|
||||||
|
SparkleIntro.cs \
|
||||||
SparklePaths.cs \
|
SparklePaths.cs \
|
||||||
SparklePlatform.cs \
|
SparklePlatform.cs \
|
||||||
SparkleRepo.cs \
|
SparkleRepo.cs \
|
||||||
|
|
|
@ -34,18 +34,18 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Get's the avatar for a specific email address and size
|
// Gets 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 = CombineMore (SparklePaths.SparkleAvatarPath, Size + "x" + Size);
|
string AvatarPath = CombineMore (SparklePaths.SparkleLocalIconPath, Size + "x" + Size, "status");
|
||||||
|
|
||||||
if (!Directory.Exists (AvatarPath)) {
|
if (!Directory.Exists (AvatarPath)) {
|
||||||
Directory.CreateDirectory (AvatarPath);
|
Directory.CreateDirectory (AvatarPath);
|
||||||
SparkleHelpers.DebugInfo ("Config", "Created '" + AvatarPath + "'");
|
SparkleHelpers.DebugInfo ("Config", "Created '" + AvatarPath + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
string AvatarFilePath = CombineMore (AvatarPath, Email);
|
string AvatarFilePath = CombineMore (AvatarPath, "avatar-" + Email);
|
||||||
|
|
||||||
if (File.Exists (AvatarFilePath))
|
if (File.Exists (AvatarFilePath))
|
||||||
return new Gdk.Pixbuf (AvatarFilePath);
|
return new Gdk.Pixbuf (AvatarFilePath);
|
||||||
|
@ -85,9 +85,9 @@ namespace SparkleShare {
|
||||||
public static string GetMD5 (string s)
|
public static string GetMD5 (string s)
|
||||||
{
|
{
|
||||||
MD5 md5 = new MD5CryptoServiceProvider ();
|
MD5 md5 = new MD5CryptoServiceProvider ();
|
||||||
Byte[] Bytes = ASCIIEncoding.Default.GetBytes (s);
|
Byte[] bytes = ASCIIEncoding.Default.GetBytes (s);
|
||||||
Byte[] EncodedBytes = md5.ComputeHash (Bytes);
|
Byte[] encodedBytes = md5.ComputeHash (bytes);
|
||||||
return BitConverter.ToString (EncodedBytes).ToLower ().Replace ("-", "");
|
return BitConverter.ToString (encodedBytes).ToLower ().Replace ("-", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -124,7 +124,8 @@ namespace SparkleShare {
|
||||||
public static Gdk.Pixbuf GetIcon (string Name, int Size)
|
public static Gdk.Pixbuf GetIcon (string Name, int Size)
|
||||||
{
|
{
|
||||||
IconTheme IconTheme = new IconTheme ();
|
IconTheme IconTheme = new IconTheme ();
|
||||||
IconTheme.AppendSearchPath (CombineMore (SparklePaths.SparkleInstallPath, "icons"));
|
IconTheme.AppendSearchPath (SparklePaths.SparkleIconPath);
|
||||||
|
IconTheme.AppendSearchPath (SparklePaths.SparkleLocalIconPath);
|
||||||
return IconTheme.LoadIcon (Name, Size, IconLookupFlags.GenericFallback);
|
return IconTheme.LoadIcon (Name, Size, IconLookupFlags.GenericFallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
137
SparkleShare/SparkleIntro.cs
Normal file
137
SparkleShare/SparkleIntro.cs
Normal file
|
@ -0,0 +1,137 @@
|
||||||
|
// 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 Mono.Unix;
|
||||||
|
using SparkleShare;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Timers;
|
||||||
|
|
||||||
|
namespace SparkleShare {
|
||||||
|
|
||||||
|
public class SparkleIntro : Window
|
||||||
|
{
|
||||||
|
|
||||||
|
// Short alias for the translations
|
||||||
|
public static string _ (string s)
|
||||||
|
{
|
||||||
|
return Catalog.GetString (s);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SparkleIntro () : base ("")
|
||||||
|
{
|
||||||
|
|
||||||
|
BorderWidth = 0;
|
||||||
|
SetSizeRequest (600, 400);
|
||||||
|
Resizable = false;
|
||||||
|
IconName = "folder-sparkleshare";
|
||||||
|
|
||||||
|
WindowPosition = WindowPosition.Center;
|
||||||
|
|
||||||
|
HBox layout_horizontal = new HBox (false, 6);
|
||||||
|
|
||||||
|
Image side_splash = new Image ("/home/hbons/github/SparkleShare/data/side-splash.png");
|
||||||
|
|
||||||
|
layout_horizontal.PackStart (side_splash, false, false, 0);
|
||||||
|
|
||||||
|
VBox wrapper = new VBox (false, 0);
|
||||||
|
|
||||||
|
VBox layout_vertical = new VBox (false, 0);
|
||||||
|
|
||||||
|
Label introduction = new Label ("<span size='xx-large'><b>Welcome to SparkleShare!</b></span>");
|
||||||
|
introduction.UseMarkup = true;
|
||||||
|
introduction.Xalign = 0;
|
||||||
|
|
||||||
|
Label information = new Label ("Before we can create a SparkleShare folder on this \n" +
|
||||||
|
"computer, we need a few bits of information from you.");
|
||||||
|
information.Xalign = 0;
|
||||||
|
|
||||||
|
|
||||||
|
Entry name_entry = new Entry ("");
|
||||||
|
Label name_label = new Label (_("<b>Full Name:</b>"));
|
||||||
|
|
||||||
|
UnixUserInfo unix_user_info = new UnixUserInfo (UnixEnvironment.UserName);
|
||||||
|
|
||||||
|
name_entry.Text = unix_user_info.RealName;
|
||||||
|
name_label.UseMarkup = true;
|
||||||
|
name_label.Xalign = 0;
|
||||||
|
|
||||||
|
|
||||||
|
Table table = new Table (6, 2, true);
|
||||||
|
table.RowSpacing = 6;
|
||||||
|
|
||||||
|
|
||||||
|
Entry email_entry = new Entry ("");
|
||||||
|
Label email_label = new Label (_("<b>Email:</b>"));
|
||||||
|
email_label.UseMarkup = true;
|
||||||
|
email_label.Xalign = 0;
|
||||||
|
|
||||||
|
Entry server_entry = new Entry ("ssh://gitorious.org/sparkleshare");
|
||||||
|
Label server_label = new Label (_("<b>Folder Address:</b>"));
|
||||||
|
server_label.UseMarkup = true;
|
||||||
|
server_label.Xalign = 0;
|
||||||
|
server_label.Sensitive = false;
|
||||||
|
server_entry.Sensitive = false;
|
||||||
|
|
||||||
|
CheckButton check_button = new CheckButton ("I already have an existing folder on a SparkleShare server");
|
||||||
|
check_button.Clicked += delegate {
|
||||||
|
if (check_button.Active) {
|
||||||
|
server_label.Sensitive = true;
|
||||||
|
server_entry.Sensitive = true;
|
||||||
|
server_entry.HasFocus = true;
|
||||||
|
} else {
|
||||||
|
server_label.Sensitive = false;
|
||||||
|
server_entry.Sensitive = false;
|
||||||
|
}
|
||||||
|
ShowAll ();
|
||||||
|
};
|
||||||
|
|
||||||
|
table.Attach (name_label, 0, 1, 0, 1);
|
||||||
|
table.Attach (name_entry, 1, 2, 0, 1);
|
||||||
|
table.Attach (email_label, 0, 1, 1, 2);
|
||||||
|
table.Attach (email_entry, 1, 2, 1, 2);
|
||||||
|
table.Attach (check_button, 0, 2, 3, 4);
|
||||||
|
table.Attach (server_label, 0, 1, 4, 5);
|
||||||
|
table.Attach (server_entry, 1, 2, 4, 5);
|
||||||
|
|
||||||
|
HButtonBox controls = new HButtonBox ();
|
||||||
|
controls.Layout = ButtonBoxStyle.End;
|
||||||
|
Button done_button = new Button ("Next");
|
||||||
|
controls.Add (done_button);
|
||||||
|
|
||||||
|
layout_vertical.PackStart (introduction, false, false, 0);
|
||||||
|
layout_vertical.PackStart (information, false, false, 21);
|
||||||
|
layout_vertical.PackStart (new Label (""), false, false, 0);
|
||||||
|
layout_vertical.PackStart (table, false, false, 0);
|
||||||
|
|
||||||
|
wrapper.PackStart (layout_vertical, true, true, 0);
|
||||||
|
layout_vertical.BorderWidth = 30;
|
||||||
|
controls.BorderWidth = 12;
|
||||||
|
wrapper.PackStart (controls, false, true, 0);
|
||||||
|
layout_horizontal.PackStart (wrapper, true, true, 0);
|
||||||
|
|
||||||
|
Add (layout_horizontal);
|
||||||
|
ShowAll ();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -33,25 +33,13 @@ namespace SparkleShare {
|
||||||
|
|
||||||
public static string SparkleConfigPath = SparkleHelpers.CombineMore (HomePath, ".config", "sparkleshare");
|
public static string SparkleConfigPath = SparkleHelpers.CombineMore (HomePath, ".config", "sparkleshare");
|
||||||
|
|
||||||
public static string SparkleInstallPath = SparkleHelpers.CombineMore (Defines.PREFIX,
|
public static string SparkleInstallPath = SparkleHelpers.CombineMore (Defines.PREFIX, "sparkleshare");
|
||||||
|
|
||||||
|
public static string SparkleLocalIconPath = SparkleHelpers.CombineMore (HomePath, ".icons", "sparkleshare");
|
||||||
|
|
||||||
|
public static string SparkleIconPath = SparkleHelpers.CombineMore (Defines.PREFIX,
|
||||||
"sparkleshare", "icons", "hicolor");
|
"sparkleshare", "icons", "hicolor");
|
||||||
|
|
||||||
public static string SparkleAvatarPath {
|
|
||||||
|
|
||||||
get {
|
|
||||||
|
|
||||||
string XDG_CACHE_HOME = Environment.GetEnvironmentVariable ("XDG_CACHE_HOME");
|
|
||||||
|
|
||||||
if (XDG_CACHE_HOME != null)
|
|
||||||
return Path.Combine (XDG_CACHE_HOME, "sparkleshare");
|
|
||||||
else
|
|
||||||
return SparkleHelpers.CombineMore (HomePath, ".cache", "sparkleshare");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string SparkleIconPath = SparkleHelpers.CombineMore ("usr", "share", "icons", "hicolor");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,7 +137,8 @@ namespace SparkleShare {
|
||||||
// Don't create the window and status
|
// Don't create the window and status
|
||||||
// icon when --disable-gui was given
|
// icon when --disable-gui was given
|
||||||
if (!HideUI) {
|
if (!HideUI) {
|
||||||
|
SparkleIntro intro = new SparkleIntro ();
|
||||||
|
intro.ShowAll ();
|
||||||
// Show a notification if there are no folders yet
|
// Show a notification if there are no folders yet
|
||||||
if (SparkleShare.Repositories.Length == 0) {
|
if (SparkleShare.Repositories.Length == 0) {
|
||||||
|
|
||||||
|
@ -193,7 +194,7 @@ namespace SparkleShare {
|
||||||
|
|
||||||
// Create place to store configuration user's home folder
|
// Create place to store configuration user's home folder
|
||||||
string ConfigPath = SparklePaths.SparkleConfigPath;
|
string ConfigPath = SparklePaths.SparkleConfigPath;
|
||||||
string AvatarPath = SparklePaths.SparkleAvatarPath;
|
string LocalIconPath = SparklePaths.SparkleLocalIconPath;
|
||||||
|
|
||||||
if (!Directory.Exists (ConfigPath)) {
|
if (!Directory.Exists (ConfigPath)) {
|
||||||
|
|
||||||
|
@ -201,8 +202,8 @@ namespace SparkleShare {
|
||||||
SparkleHelpers.DebugInfo ("Config", "Created '" + ConfigPath + "'");
|
SparkleHelpers.DebugInfo ("Config", "Created '" + ConfigPath + "'");
|
||||||
|
|
||||||
// Create a place to store the avatars
|
// Create a place to store the avatars
|
||||||
Directory.CreateDirectory (AvatarPath);
|
Directory.CreateDirectory (LocalIconPath);
|
||||||
SparkleHelpers.DebugInfo ("Config", "Created '" + AvatarPath + "'");
|
SparkleHelpers.DebugInfo ("Config", "Created '" + LocalIconPath + "'");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ namespace SparkleShare {
|
||||||
BorderWidth = 12;
|
BorderWidth = 12;
|
||||||
|
|
||||||
// TRANSLATORS: {0} is a folder name, and {1} is a server address
|
// TRANSLATORS: {0} is a folder name, and {1} is a server address
|
||||||
Title = String.Format(_("‘{0}’ on {1}"), SparkleRepo.Name,
|
Title = String.Format(_("Recent Events in ‘{0}’ on {1}"), SparkleRepo.Name,
|
||||||
SparkleRepo.RemoteOriginUrl);
|
SparkleRepo.RemoteOriginUrl);
|
||||||
IconName = "folder";
|
IconName = "folder";
|
||||||
|
|
||||||
|
@ -232,6 +232,7 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
|
|
||||||
ScrolledWindow = new ScrolledWindow ();
|
ScrolledWindow = new ScrolledWindow ();
|
||||||
|
ScrolledWindow.ShadowType = ShadowType.None;
|
||||||
ScrolledWindow.AddWithViewport (layout_vertical);
|
ScrolledWindow.AddWithViewport (layout_vertical);
|
||||||
|
|
||||||
return ScrolledWindow;
|
return ScrolledWindow;
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
# after adding files here.
|
# after adding files here.
|
||||||
[encoding: UTF-8]
|
[encoding: UTF-8]
|
||||||
SparkleDiff/SparkleDiff.cs
|
SparkleDiff/SparkleDiff.cs
|
||||||
|
SparkleDiff/SparkleDiffWindow.cs
|
||||||
SparkleShare/SparkleBubble.cs
|
SparkleShare/SparkleBubble.cs
|
||||||
SparkleShare/SparkleDialog.cs
|
SparkleShare/SparkleDialog.cs
|
||||||
SparkleShare/SparkleHelpers.cs
|
SparkleShare/SparkleHelpers.cs
|
||||||
|
|
Loading…
Reference in a new issue