make add dialog work kinda. restructure

This commit is contained in:
Hylke Bons 2010-05-06 01:17:00 +01:00
parent f48872da1d
commit d1d3304fde
7 changed files with 245 additions and 192 deletions

View file

@ -0,0 +1,90 @@
// 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 System;
using System.IO;
using System.Net;
using System.Security.Cryptography;
using System.Text;
namespace SparkleShare {
public static class SparkleHelpers {
public static string GetAvatarFileName (string Email, int Size) {
string AvatarPath = SparklePaths.SparkleAvatarsDir +
Size + "x" + Size + "/";
if (!Directory.Exists (AvatarPath)) {
Directory.CreateDirectory (AvatarPath);
Console.WriteLine ("[Config] Created '" + AvatarPath + "'");
}
string AvatarFile = AvatarPath + Email;
if (File.Exists (AvatarFile))
return AvatarFile;
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.SparkleTmpDir + 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);
};
}
string FallbackFileName = "/usr/share/icons/hicolor/" +
Size + "x" + Size +
"/status/avatar-default.png";
if (File.Exists (FallbackFileName))
return FallbackFileName;
else
return "/usr/share/icons/hicolor/16x16/status/avatar-default.png";
}
}
// Helper that 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 ("-", "");
}
}
}

View file

@ -0,0 +1,42 @@
// 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 System;
namespace SparkleShare {
public static class SparklePaths {
public static string SparkleTmpDir = "/tmp/sparkleshare";
public static string SparkleDir =
Environment.GetEnvironmentVariable("HOME") +
"/" + "SparkleShare/";
public static string SparkleConfigDir =
Environment.GetEnvironmentVariable("HOME") +
"/" + ".config/sparkleshare/";
public static string SparkleAvatarsDir =
Environment.GetEnvironmentVariable("HOME") +
"/" + ".config/sparkleshare/" +
"avatars/";
public static string SparkleIconsDir = "/usr/share/icons/hicolor/";
}
}

View file

@ -18,9 +18,6 @@ using Gtk;
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Timers;
@ -205,7 +202,8 @@ namespace SparkleShare {
Process.StartInfo.Arguments = "commit -m \"" + Message + "\"";
Process.Start();
ShowEventBubble (UserName + " " + Message,
GetAvatarFileName (UserEmail, 48), true);
SparkleHelpers.GetAvatarFileName (UserEmail, 48),
true);
}
// Fetches changes from the remote repo
@ -250,7 +248,8 @@ namespace SparkleShare {
string LastCommitUserName = Process.StandardOutput.ReadToEnd().Trim ();
ShowEventBubble (LastCommitUserName + " " + LastCommitMessage,
GetAvatarFileName (LastCommitEmail, 48), true);
SparkleHelpers.GetAvatarFileName (LastCommitEmail, 48),
true);
}
@ -390,70 +389,6 @@ namespace SparkleShare {
} );
}
public static string GetAvatarFileName (string Email, int Size) {
string AvatarPath = Environment.GetEnvironmentVariable("HOME") +
"/.config/sparkleshare/avatars/" +
Size + "x" + Size + "/";
if (!Directory.Exists (AvatarPath)) {
Directory.CreateDirectory (AvatarPath);
Console.WriteLine ("[Config] Created '" + AvatarPath + "'");
}
string AvatarFile = AvatarPath + Email;
if (File.Exists (AvatarFile))
return AvatarFile;
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 = "/tmp/" + 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);
};
}
string FallbackFileName = "/usr/share/icons/hicolor/" +
Size + "x" + Size +
"/status/avatar-default.png";
if (File.Exists (FallbackFileName))
return FallbackFileName;
else
return "/usr/share/icons/hicolor/16x16/status/avatar-default.png";
}
}
// Helper that 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 ("-", "");
}
}
}

View file

@ -27,6 +27,7 @@ namespace SparkleShare {
public static void Main (string [] args) {
// Check if git is installed
Process Process = new Process();
Process.StartInfo.RedirectStandardOutput = true;

View file

@ -38,5 +38,8 @@
<Compile Include="SparkleStatusIcon.cs" />
<Compile Include="SparkleWindow.cs" />
<Compile Include="SparkleBubble.cs" />
<Compile Include="SparkleSpinner.cs" />
<Compile Include="SparklePaths.cs" />
<Compile Include="SparkleHelpers.cs" />
</ItemGroup>
</Project>

View file

@ -15,6 +15,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using Gtk;
using System;
using System.Timers;
namespace SparkleShare {
@ -22,9 +23,9 @@ namespace SparkleShare {
// This is a close implementation of GtkSpinner
public class SparkleSpinner : Gdk.Pixbuf {
public int CycleDuration;
public int NumSteps;
public bool Active;
private int CycleDuration;
private int NumSteps;
private bool Active;
private Timer Timer;
private int CurrentStep;
@ -32,12 +33,23 @@ namespace SparkleShare {
public SparkleSpinner () : base ("") {
Timer = new Timer ();
CycleDuration = 1000;
Timer.Interval = 50;
Timer.Elapsed += delegate {
//
};
CurrentStep = 0;
NumSteps = 20;
Timer.Interval = CycleDuration / NumSteps;
Timer.Elapsed += delegate { NextImage (); };
Start ();
}
private void NextImage () {
Console.WriteLine (CurrentStep);
if (CurrentStep < NumSteps)
CurrentStep++;
else
CurrentStep = 0;
}
public bool IsActive () {
return Active;
}
public void Start () {

View file

@ -19,9 +19,6 @@ using SparkleShare;
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Timers;
@ -50,6 +47,7 @@ namespace SparkleShare {
"You don't have any " +
"folders set up yet.");
NoFoldersBubble.IconName = "folder-sparkleshare";
NoFoldersBubble.AddAction ("", "Set up a folder",
delegate { CreateAddDialog (); } );
@ -227,7 +225,7 @@ namespace SparkleShare {
Label Property1 = new Label ("Remote address:");
Property1.WidthRequest = 120;
Property1.SetAlignment (0, 0);
Property1.Xalign = 0;
Label Value1 = new Label
("<b>" + SparkleRepo.RemoteOriginUrl + "</b>");
@ -242,7 +240,7 @@ namespace SparkleShare {
Label Property2 = new Label ("Local path:");
Property2.WidthRequest = 120;
Property2.SetAlignment (0, 0);
Property2.Xalign = 0;
Label Value2 = new Label
("<b>" + SparkleRepo.LocalPath + "</b>");
@ -415,7 +413,8 @@ namespace SparkleShare {
if (UserName.Equals (SparkleRepo.UserName))
UserName += " (thats you!)";
string AvatarFileName = GetAvatarFileName (UserEmail, 32);
string AvatarFileName =
SparkleHelpers.GetAvatarFileName (UserEmail, 32);
// Actually add to the list
PeopleIter = PeopleStore.Prepend ();
@ -448,64 +447,96 @@ namespace SparkleShare {
public void CreateAddDialog () {
Window AddDialog = new Window ("");
AddDialog.SetPosition (WindowPosition.Center);
AddDialog.KeepAbove = true;
AddDialog.Modal = true;
AddDialog.TransientFor = this;
AddDialog.BorderWidth = 6;
AddDialog.IconName = "folder-sparkleshare";
Window AddDialog = new Window ("");
AddDialog.SetPosition (WindowPosition.Center);
AddDialog.Modal = true;
AddDialog.TransientFor = this;
AddDialog.BorderWidth = 6;
AddDialog.IconName = "folder-sparkleshare";
VBox VBox = new VBox (false, 0);
VBox VBox = new VBox (false, 0);
Label NameLabel = new Label ("Folder Name: ");
Entry NameEntry = new Entry ();
Label NameExample = new Label ("<span size='small'><i>Example: Project.</i></span>");
NameExample.UseMarkup = true;
NameExample.SetAlignment (0, 0);
NameLabel.Xalign = 1;
Label NameLabel = new Label ("Folder Name: ");
Entry NameEntry = new Entry ();
Label NameExample = new Label ("<span size='small'><i>Example: Project.</i></span>");
NameExample.UseMarkup = true;
NameExample.SetAlignment (0, 0);
NameLabel.Xalign = 1;
Label RemoteUrlLabel = new Label ("Remote address: ");
Label RemoteUrlLabel = new Label ("Remote address: ");
string [] DefaultUrls = new string [3] { "ssh://git@github.com/",
"ssh://git@git.gnome.org/",
"ssh://git@gitorious.org/" };
string [] DefaultUrls = new string [4] { "ssh://git@github.com/",
"ssh://git@git.gnome.org/",
"ssh://git@fedorahosted.org/",
"ssh://git@gitorious.org/" };
ComboBoxEntry RemoteUrlCombo = new ComboBoxEntry (DefaultUrls);
ComboBoxEntry RemoteUrlCombo = new ComboBoxEntry (DefaultUrls);
Label RemoteUrlExample = new Label ("<span size='small'><i>Example: ssh://git@github.com/.</i></span>");
RemoteUrlExample.UseMarkup = true;
RemoteUrlExample.SetAlignment (0, 0);
RemoteUrlLabel.Xalign = 1;
Label RemoteUrlExample = new Label ("<span size='small'><i>Example: ssh://git@github.com/.</i></span>");
RemoteUrlExample.UseMarkup = true;
RemoteUrlExample.SetAlignment (0, 0);
RemoteUrlLabel.Xalign = 1;
HButtonBox ButtonBox = new HButtonBox ();
ButtonBox.Layout = ButtonBoxStyle.End;
ButtonBox.Spacing = 6;
ButtonBox.BorderWidth = 6;
Button AddButton = new Button (Stock.Add);
Button CancelButton = new Button (Stock.Cancel);
CancelButton.Clicked += delegate {
AddDialog.Destroy ();
};
ButtonBox.Add (CancelButton);
ButtonBox.Add (AddButton);
HButtonBox ButtonBox = new HButtonBox ();
ButtonBox.Layout = ButtonBoxStyle.End;
ButtonBox.Spacing = 6;
ButtonBox.BorderWidth = 6;
Table Table = new Table(4, 2, false);
Table.RowSpacing = 6;
Table.BorderWidth = 6;
Table.Attach (NameLabel, 0, 1, 0, 1);
Button AddButton = new Button (Stock.Add);
Button CancelButton = new Button (Stock.Cancel);
CancelButton.Clicked += delegate {
AddDialog.Destroy ();
};
AddButton.Clicked += delegate {
AddDialog.Remove (AddDialog.Child);
AddDialog.Add (new Label ("Downloading files...\nPlease wait."));
AddDialog.ShowAll ();
string RepoRemoteUrl = RemoteUrlCombo.Entry.Text;
string RepoName = NameEntry.Text;
Process Process = new Process();
Process.EnableRaisingEvents = true;
Process.StartInfo.RedirectStandardOutput = true;
Process.StartInfo.UseShellExecute = false;
Process.StartInfo.FileName = "git";
Process.StartInfo.WorkingDirectory =
SparklePaths.SparkleTmpDir;
Process.StartInfo.Arguments = "clone " +
RepoRemoteUrl + " " +
RepoName;
Process.Start ();
Process.Exited += delegate {
Directory.Move (SparklePaths.SparkleTmpDir + RepoName,
SparklePaths.SparkleDir + "Sticky");
AddDialog.Destroy ();
};
};
ButtonBox.Add (CancelButton);
ButtonBox.Add (AddButton);
Table Table = new Table(4, 2, false);
Table.RowSpacing = 6;
Table.BorderWidth = 6;
Table.Attach (NameLabel, 0, 1, 0, 1);
Table.Attach (NameEntry, 1, 2, 0, 1);
Table.Attach (NameExample, 1, 2, 1, 2);
Table.Attach (RemoteUrlLabel, 0, 1, 3, 4);
Table.Attach (RemoteUrlCombo, 1, 2, 3, 4);
Table.Attach (RemoteUrlExample, 1, 2, 4, 5);
Table.Attach (NameEntry, 1, 2, 0, 1);
Table.Attach (NameExample, 1, 2, 1, 2);
Table.Attach (RemoteUrlLabel, 0, 1, 3, 4);
Table.Attach (RemoteUrlCombo, 1, 2, 3, 4);
Table.Attach (RemoteUrlExample, 1, 2, 4, 5);
VBox.PackStart (Table, false, false, 0);
VBox.PackStart (ButtonBox, false, false, 0);
VBox.PackStart (Table, false, false, 0);
VBox.PackStart (ButtonBox, false, false, 0);
AddDialog.Add (VBox);
AddDialog.ShowAll ();
AddDialog.Add (VBox);
AddDialog.ShowAll ();
}
@ -522,70 +553,9 @@ namespace SparkleShare {
}
public void Quit (object o, EventArgs args) {
File.Delete ("/tmp/sparkleshare/sparkleshare.pid");
File.Delete (SparklePaths.SparkleTmpDir + "sparkleshare.pid");
Application.Quit ();
}
public static string GetAvatarFileName (string Email, int Size) {
string AvatarPath = Environment.GetEnvironmentVariable("HOME") +
"/.config/sparkleshare/avatars/" +
Size + "x" + Size + "/";
if (!Directory.Exists (AvatarPath)) {
Directory.CreateDirectory (AvatarPath);
Console.WriteLine ("[Config] Created '" + AvatarPath + "'");
}
string AvatarFile = AvatarPath + Email;
if (File.Exists (AvatarFile))
return AvatarFile;
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 = "/tmp/" + 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);
};
}
string FallbackFileName = "/usr/share/icons/hicolor/" +
Size + "x" + Size +
"/status/avatar-default.png";
if (File.Exists (FallbackFileName))
return FallbackFileName;
else
return "/usr/share/icons/hicolor/16x16/status/avatar-default.png";
}
}
// Helper that 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 ("-", "");
}
}